This is an automated email from the ASF dual-hosted git repository.

veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git


The following commit(s) were added to refs/heads/master by this push:
     new 93cd3dfd6 Enforce consistent code formatting
93cd3dfd6 is described below

commit 93cd3dfd61da43c7cea7dec2bd59b6dd35e110b0
Author: Andreas Veithen <andreas.veit...@gmail.com>
AuthorDate: Mon Apr 25 23:45:19 2022 +0100

    Enforce consistent code formatting
---
 .../org/apache/axiom/weaver/maven/WeaveMojo.java   | 53 ++++++++++++++--------
 .../GetDataHandlerBridgeMethodInjector.java        | 24 ++++++++--
 .../axiom/buildutils/classes/PostProcessMojo.java  | 18 +++++---
 .../axiom/buildutils/sources/PostProcessMojo.java  | 44 +++++++++++++-----
 .../axiom/buildutils/sources/SourceExtractor.java  |  2 +-
 buildutils/pom.xml                                 | 11 +++++
 .../axiomxml/AxiomXmlResourceTransformer.java      | 24 ++++++----
 .../axiom/buildutils/shade/axiomxml/DOMUtils.java  |  8 ++--
 8 files changed, 127 insertions(+), 57 deletions(-)

diff --git 
a/buildutils/axiom-weaver-maven-plugin/src/main/java/org/apache/axiom/weaver/maven/WeaveMojo.java
 
b/buildutils/axiom-weaver-maven-plugin/src/main/java/org/apache/axiom/weaver/maven/WeaveMojo.java
index c1fea1b4d..7b03b7c16 100644
--- 
a/buildutils/axiom-weaver-maven-plugin/src/main/java/org/apache/axiom/weaver/maven/WeaveMojo.java
+++ 
b/buildutils/axiom-weaver-maven-plugin/src/main/java/org/apache/axiom/weaver/maven/WeaveMojo.java
@@ -40,36 +40,48 @@ import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
 import org.apache.maven.project.MavenProject;
 
-@Mojo(name="weave", defaultPhase=LifecyclePhase.PROCESS_CLASSES, 
requiresDependencyResolution=ResolutionScope.COMPILE)
+@Mojo(
+        name = "weave",
+        defaultPhase = LifecyclePhase.PROCESS_CLASSES,
+        requiresDependencyResolution = ResolutionScope.COMPILE)
 public final class WeaveMojo extends AbstractMojo {
-    @Parameter(property="project", required=true, readonly=true)
+    @Parameter(property = "project", required = true, readonly = true)
     private MavenProject project;
 
-    @Parameter(required=true)
+    @Parameter(required = true)
     private PackageMapping[] packageMappings;
 
-    @Parameter(required=true)
+    @Parameter(required = true)
     private String[] weavablePackages;
 
-    @Parameter(required=true)
+    @Parameter(required = true)
     private String[] interfaces;
 
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
         URLClassLoader classLoader = createClassLoader();
         try {
-            Weaver weaver = new Weaver(classLoader, new 
ImplementationClassNameMapper() {
-                @Override
-                public String getImplementationClassName(Class<?> iface) {
-                    String packageName = iface.getPackage().getName();
-                    for (PackageMapping packageMapping : packageMappings) {
-                        if 
(packageName.equals(packageMapping.getInterfacePackage())) {
-                            return packageMapping.getOutputPackage() + "." + 
iface.getSimpleName() + "Impl";
-                        }
-                    }
-                    throw new WeaverException("No package mapping defined for 
package " + packageName);
-                }
-            });
+            Weaver weaver =
+                    new Weaver(
+                            classLoader,
+                            new ImplementationClassNameMapper() {
+                                @Override
+                                public String 
getImplementationClassName(Class<?> iface) {
+                                    String packageName = 
iface.getPackage().getName();
+                                    for (PackageMapping packageMapping : 
packageMappings) {
+                                        if (packageName.equals(
+                                                
packageMapping.getInterfacePackage())) {
+                                            return 
packageMapping.getOutputPackage()
+                                                    + "."
+                                                    + iface.getSimpleName()
+                                                    + "Impl";
+                                        }
+                                    }
+                                    throw new WeaverException(
+                                            "No package mapping defined for 
package "
+                                                    + packageName);
+                                }
+                            });
             for (String packageName : weavablePackages) {
                 weaver.loadWeavablePackage(packageName);
             }
@@ -81,7 +93,10 @@ public final class WeaveMojo extends AbstractMojo {
                 }
             }
             for (ClassDefinition classDefinition : weaver.generate()) {
-                File outputFile = new 
File(project.getBuild().getOutputDirectory(), classDefinition.getClassName() + 
".class");
+                File outputFile =
+                        new File(
+                                project.getBuild().getOutputDirectory(),
+                                classDefinition.getClassName() + ".class");
                 outputFile.getParentFile().mkdirs();
                 try (FileOutputStream out = new FileOutputStream(outputFile)) {
                     out.write(classDefinition.toByteArray());
@@ -106,7 +121,7 @@ public final class WeaveMojo extends AbstractMojo {
             throw new MojoExecutionException("Failed to get copile classpath 
elements", ex);
         }
         URL[] urls = new URL[paths.size()];
-        int i=0;
+        int i = 0;
         for (String path : paths) {
             try {
                 urls[i++] = new File(path).toURI().toURL();
diff --git 
a/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/classes/GetDataHandlerBridgeMethodInjector.java
 
b/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/classes/GetDataHandlerBridgeMethodInjector.java
index 7a196dcea..9684f0d45 100644
--- 
a/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/classes/GetDataHandlerBridgeMethodInjector.java
+++ 
b/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/classes/GetDataHandlerBridgeMethodInjector.java
@@ -34,16 +34,30 @@ final class GetDataHandlerBridgeMethodInjector extends 
ClassVisitor {
     }
 
     @Override
-    public void visit(int version, int access, String name, String signature, 
String superName, String[] interfaces) {
+    public void visit(
+            int version,
+            int access,
+            String name,
+            String signature,
+            String superName,
+            String[] interfaces) {
         super.visit(version, access, name, signature, superName, interfaces);
         className = name;
     }
 
     @Override
-    public MethodVisitor visitMethod(int access, String name, String desc, 
String signature, String[] exceptions) {
+    public MethodVisitor visitMethod(
+            int access, String name, String desc, String signature, String[] 
exceptions) {
         if (name.equals("getDataHandler")) {
             if (desc.equals("()Ljavax/activation/DataHandler;")) {
-                MethodVisitor mv = super.visitMethod((access | 
Opcodes.ACC_BRIDGE | Opcodes.ACC_SYNTHETIC) & ~Opcodes.ACC_FINAL, name, 
"()Ljava/lang/Object;", null, exceptions);
+                MethodVisitor mv =
+                        super.visitMethod(
+                                (access | Opcodes.ACC_BRIDGE | 
Opcodes.ACC_SYNTHETIC)
+                                        & ~Opcodes.ACC_FINAL,
+                                name,
+                                "()Ljava/lang/Object;",
+                                null,
+                                exceptions);
                 if ((access & Opcodes.ACC_ABSTRACT) == 0) {
                     mv.visitCode();
                     mv.visitVarInsn(Opcodes.ALOAD, 0);
@@ -53,11 +67,11 @@ final class GetDataHandlerBridgeMethodInjector extends 
ClassVisitor {
                     mv.visitEnd();
                 }
             } else if ((access & Opcodes.ACC_BRIDGE) != 0 && 
desc.equals("()Ljava/lang/Object;")) {
-                // Skip any existing bridge method so that the transformation 
is idempotent. That's important when rebuilding without cleaning.
+                // Skip any existing bridge method so that the transformation 
is idempotent. That's
+                // important when rebuilding without cleaning.
                 return null;
             }
         }
         return super.visitMethod(access, name, desc, signature, exceptions);
     }
-
 }
diff --git 
a/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/classes/PostProcessMojo.java
 
b/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/classes/PostProcessMojo.java
index 9938bdedd..f7683c5bd 100644
--- 
a/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/classes/PostProcessMojo.java
+++ 
b/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/classes/PostProcessMojo.java
@@ -36,9 +36,9 @@ import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.ClassWriter;
 
-@Mojo(name="post-process-classes", defaultPhase=LifecyclePhase.PROCESS_CLASSES)
+@Mojo(name = "post-process-classes", defaultPhase = 
LifecyclePhase.PROCESS_CLASSES)
 public class PostProcessMojo extends AbstractMojo {
-    @Parameter(property="project.build.outputDirectory", required=true, 
readonly=true)
+    @Parameter(property = "project.build.outputDirectory", required = true, 
readonly = true)
     private File classesDir;
 
     @Override
@@ -47,7 +47,7 @@ public class PostProcessMojo extends AbstractMojo {
             return;
         }
         DirectoryScanner ds = new DirectoryScanner();
-        ds.setIncludes(new String[] { "**/*.class" });
+        ds.setIncludes(new String[] {"**/*.class"});
         ds.setBasedir(classesDir);
         ds.scan();
         for (String relativePath : ds.getIncludedFiles()) {
@@ -60,8 +60,10 @@ public class PostProcessMojo extends AbstractMojo {
                     classWriter = new ClassWriter(classReader, 0);
                     ClassVisitor classVisitor = classWriter;
                     if (relativePath.equals("org/apache/axiom/om/OMText.class")
-                            || 
relativePath.equals("org/apache/axiom/om/impl/llom/AxiomCharacterDataNodeImpl.class")
-                            || 
relativePath.equals("org/apache/axiom/om/impl/dom/DOMTextNodeImpl.class")) {
+                            || relativePath.equals(
+                                    
"org/apache/axiom/om/impl/llom/AxiomCharacterDataNodeImpl.class")
+                            || relativePath.equals(
+                                    
"org/apache/axiom/om/impl/dom/DOMTextNodeImpl.class")) {
                         classVisitor = new 
GetDataHandlerBridgeMethodInjector(classVisitor);
                     }
                     classReader.accept(classVisitor, 0);
@@ -69,7 +71,8 @@ public class PostProcessMojo extends AbstractMojo {
                     in.close();
                 }
             } catch (IOException ex) {
-                throw new MojoExecutionException("Failed to read " + 
relativePath + ": " + ex.getMessage(), ex);
+                throw new MojoExecutionException(
+                        "Failed to read " + relativePath + ": " + 
ex.getMessage(), ex);
             }
             try {
                 OutputStream out = new FileOutputStream(file);
@@ -79,7 +82,8 @@ public class PostProcessMojo extends AbstractMojo {
                     out.close();
                 }
             } catch (IOException ex) {
-                throw new MojoExecutionException("Failed to write " + 
relativePath + ": " + ex.getMessage(), ex);
+                throw new MojoExecutionException(
+                        "Failed to write " + relativePath + ": " + 
ex.getMessage(), ex);
             }
         }
     }
diff --git 
a/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/PostProcessMojo.java
 
b/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/PostProcessMojo.java
index 542e2a945..a98aedc45 100644
--- 
a/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/PostProcessMojo.java
+++ 
b/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/PostProcessMojo.java
@@ -47,16 +47,18 @@ import 
org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverExcepti
 import org.apache.maven.shared.utils.io.IOUtil;
 import org.objectweb.asm.ClassReader;
 
-@Mojo(name="post-process-sources-jar", defaultPhase=LifecyclePhase.PACKAGE, 
requiresDependencyResolution=ResolutionScope.COMPILE_PLUS_RUNTIME)
+@Mojo(
+        name = "post-process-sources-jar",
+        defaultPhase = LifecyclePhase.PACKAGE,
+        requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
 public class PostProcessMojo extends AbstractMojo {
-    @Parameter(property="project", readonly=true, required=true)
+    @Parameter(property = "project", readonly = true, required = true)
     private MavenProject project;
 
-    @Parameter(property="session", readonly=true, required=true)
+    @Parameter(property = "session", readonly = true, required = true)
     private MavenSession session;
 
-    @Component
-    private ArtifactResolver artifactResolver;
+    @Component private ArtifactResolver artifactResolver;
 
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
@@ -64,20 +66,32 @@ public class PostProcessMojo extends AbstractMojo {
             return;
         }
         Set<String> sources = new HashSet<>();
-        try (JarInputStream in = new JarInputStream(new 
FileInputStream(project.getArtifact().getFile()))) {
+        try (JarInputStream in =
+                new JarInputStream(new 
FileInputStream(project.getArtifact().getFile()))) {
             JarEntry entry;
             while ((entry = in.getNextJarEntry()) != null) {
                 String name = entry.getName();
                 if (name.endsWith(".class")) {
-                    new ClassReader(in).accept(new SourceExtractor(sources, 
name.substring(0, name.lastIndexOf('/')+1)), ClassReader.SKIP_CODE);
+                    new ClassReader(in)
+                            .accept(
+                                    new SourceExtractor(
+                                            sources, name.substring(0, 
name.lastIndexOf('/') + 1)),
+                                    ClassReader.SKIP_CODE);
                 }
             }
         } catch (IOException ex) {
             throw new MojoExecutionException("Error reading jar: " + 
ex.getMessage(), ex);
         }
-        File sourcesJar = new File(project.getBuild().getDirectory(), 
project.getBuild().getFinalName() + "-sources.jar");
-        File postProcessedSourcesJar = new 
File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + 
"-post-processed-sources.jar");
-        try (JarOutputStream out = new JarOutputStream(new 
FileOutputStream(postProcessedSourcesJar))) {
+        File sourcesJar =
+                new File(
+                        project.getBuild().getDirectory(),
+                        project.getBuild().getFinalName() + "-sources.jar");
+        File postProcessedSourcesJar =
+                new File(
+                        project.getBuild().getDirectory(),
+                        project.getBuild().getFinalName() + 
"-post-processed-sources.jar");
+        try (JarOutputStream out =
+                new JarOutputStream(new 
FileOutputStream(postProcessedSourcesJar))) {
             processSourceJar(sourcesJar, sources, true, out);
             ArtifactFilter filter = new 
ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
             for (Artifact artifact : project.getArtifacts()) {
@@ -93,7 +107,11 @@ public class PostProcessMojo extends AbstractMojo {
                     coordinate.setClassifier("sources");
                     Artifact resolvedArtifact;
                     try {
-                        resolvedArtifact = 
artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), 
coordinate).getArtifact();
+                        resolvedArtifact =
+                                artifactResolver
+                                        .resolveArtifact(
+                                                
session.getProjectBuildingRequest(), coordinate)
+                                        .getArtifact();
                     } catch (ArtifactResolverException ex) {
                         getLog().warn("Could not get sources for " + artifact);
                         continue;
@@ -110,7 +128,9 @@ public class PostProcessMojo extends AbstractMojo {
         postProcessedSourcesJar.renameTo(sourcesJar);
     }
 
-    private void processSourceJar(File file, Set<String> sources, boolean 
includeAll, JarOutputStream out) throws MojoExecutionException {
+    private void processSourceJar(
+            File file, Set<String> sources, boolean includeAll, 
JarOutputStream out)
+            throws MojoExecutionException {
         try (JarInputStream in = new JarInputStream(new 
FileInputStream(file))) {
             JarEntry entry;
             while ((entry = in.getNextJarEntry()) != null) {
diff --git 
a/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/SourceExtractor.java
 
b/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/SourceExtractor.java
index d6078d916..817f14f81 100644
--- 
a/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/SourceExtractor.java
+++ 
b/buildutils/buildutils-maven-plugin/src/main/java/org/apache/axiom/buildutils/sources/SourceExtractor.java
@@ -26,7 +26,7 @@ import org.objectweb.asm.Opcodes;
 final class SourceExtractor extends ClassVisitor {
     private final Set<String> sources;
     private final String parentPath;
-    
+
     SourceExtractor(Set<String> sources, String parentPath) {
         super(Opcodes.ASM9);
         this.sources = sources;
diff --git a/buildutils/pom.xml b/buildutils/pom.xml
index 07b9f0605..8d66efb13 100644
--- a/buildutils/pom.xml
+++ b/buildutils/pom.xml
@@ -80,6 +80,17 @@
                     <includeClasses>false</includeClasses>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>com.github.veithen.maven</groupId>
+                <artifactId>java-format-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>check</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
 </project>
diff --git 
a/buildutils/shade-axiom-xml/src/main/java/org/apache/axiom/buildutils/shade/axiomxml/AxiomXmlResourceTransformer.java
 
b/buildutils/shade-axiom-xml/src/main/java/org/apache/axiom/buildutils/shade/axiomxml/AxiomXmlResourceTransformer.java
index a24284a0f..90670f001 100644
--- 
a/buildutils/shade-axiom-xml/src/main/java/org/apache/axiom/buildutils/shade/axiomxml/AxiomXmlResourceTransformer.java
+++ 
b/buildutils/shade-axiom-xml/src/main/java/org/apache/axiom/buildutils/shade/axiomxml/AxiomXmlResourceTransformer.java
@@ -31,12 +31,10 @@ import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-/**
- * Merges {@code META-INF/axiom.xml} files.
- */
+/** Merges {@code META-INF/axiom.xml} files. */
 public class AxiomXmlResourceTransformer implements ResourceTransformer {
     private static final String AXIOM_XML = "META-INF/axiom.xml";
-    
+
     private Document mergedAxiomXml;
 
     @Override
@@ -50,12 +48,14 @@ public class AxiomXmlResourceTransformer implements 
ResourceTransformer {
     }
 
     @Override
-    public void processResource(String resource, InputStream is, 
List<Relocator> relocators) throws IOException {
+    public void processResource(String resource, InputStream is, 
List<Relocator> relocators)
+            throws IOException {
         Document axiomXml = DOMUtils.parse(is);
         is.close();
-        NodeList implementations = 
axiomXml.getElementsByTagNameNS("http://ws.apache.org/axiom/";, 
"implementation");
-        for (int i=0; i<implementations.getLength(); i++) {
-            Element implementation = (Element)implementations.item(i);
+        NodeList implementations =
+                axiomXml.getElementsByTagNameNS("http://ws.apache.org/axiom/";, 
"implementation");
+        for (int i = 0; i < implementations.getLength(); i++) {
+            Element implementation = (Element) implementations.item(i);
             String loader = implementation.getAttributeNS(null, "loader");
             for (Relocator relocator : relocators) {
                 if (relocator.canRelocateClass(loader)) {
@@ -67,8 +67,12 @@ public class AxiomXmlResourceTransformer implements 
ResourceTransformer {
         if (mergedAxiomXml == null) {
             mergedAxiomXml = axiomXml;
         } else {
-            for (Node node = axiomXml.getDocumentElement().getFirstChild(); 
node != null; node = node.getNextSibling()) {
-                
mergedAxiomXml.getDocumentElement().appendChild(mergedAxiomXml.importNode(node, 
true));
+            for (Node node = axiomXml.getDocumentElement().getFirstChild();
+                    node != null;
+                    node = node.getNextSibling()) {
+                mergedAxiomXml
+                        .getDocumentElement()
+                        .appendChild(mergedAxiomXml.importNode(node, true));
             }
         }
     }
diff --git 
a/buildutils/shade-axiom-xml/src/main/java/org/apache/axiom/buildutils/shade/axiomxml/DOMUtils.java
 
b/buildutils/shade-axiom-xml/src/main/java/org/apache/axiom/buildutils/shade/axiomxml/DOMUtils.java
index 2406e1579..be4f43b3e 100644
--- 
a/buildutils/shade-axiom-xml/src/main/java/org/apache/axiom/buildutils/shade/axiomxml/DOMUtils.java
+++ 
b/buildutils/shade-axiom-xml/src/main/java/org/apache/axiom/buildutils/shade/axiomxml/DOMUtils.java
@@ -34,7 +34,7 @@ import org.xml.sax.SAXException;
 
 public final class DOMUtils {
     private DOMUtils() {}
-    
+
     public static Document parse(InputStream is) throws IOException {
         try {
             DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
@@ -46,10 +46,12 @@ public final class DOMUtils {
             throw toIOException(ex);
         }
     }
-    
+
     public static void serialize(Document document, OutputStream os) throws 
IOException {
         try {
-            TransformerFactory.newInstance().newTransformer().transform(new 
DOMSource(document), new StreamResult(os));
+            TransformerFactory.newInstance()
+                    .newTransformer()
+                    .transform(new DOMSource(document), new StreamResult(os));
         } catch (TransformerException ex) {
             throw toIOException(ex);
         }

Reply via email to