Merge pull request #23899 from dmatej/mvn-annotation-processing

Fixed maven compiler annotation processing
diff --git a/appserver/jdbc/jdbc-ra/jdbc40/pom.xml b/appserver/jdbc/jdbc-ra/jdbc40/pom.xml
index abb4865..5fcfac4 100644
--- a/appserver/jdbc/jdbc-ra/jdbc40/pom.xml
+++ b/appserver/jdbc/jdbc-ra/jdbc40/pom.xml
@@ -54,12 +54,5 @@
                 </excludes>
             </resource>
         </resources>
-        <plugins>
-            <plugin><!--
-                  Use JDBC 4.0 API regardless of which JDK we are building with.
-                -->
-                <artifactId>maven-compiler-plugin</artifactId>
-            </plugin>
-        </plugins>
     </build>
 </project>
diff --git a/appserver/pom.xml b/appserver/pom.xml
index 41db196..4755055 100644
--- a/appserver/pom.xml
+++ b/appserver/pom.xml
@@ -662,13 +662,6 @@
         </pluginManagement>
         <plugins>
             <plugin>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <configuration>
-                    <source>11</source>
-                    <target>11</target>
-                </configuration>
-            </plugin>
-            <plugin>
                 <groupId>org.glassfish.build</groupId>
                 <artifactId>spec-version-maven-plugin</artifactId>
                 <version>2.1</version>
diff --git a/appserver/tests/appserv-tests/util/reportbuilder/pom.xml b/appserver/tests/appserv-tests/util/reportbuilder/pom.xml
index 68857b3..bc0cdac 100644
--- a/appserver/tests/appserv-tests/util/reportbuilder/pom.xml
+++ b/appserver/tests/appserv-tests/util/reportbuilder/pom.xml
@@ -21,18 +21,17 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
     <parent>
-        <groupId>org.eclipse.ee4j</groupId>
-        <artifactId>project</artifactId>
-        <version>1.0</version>
+        <groupId>org.glassfish.main.tests</groupId>
+        <artifactId>ant-tests</artifactId>
+        <version>6.2.6-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.glassfish.devtests</groupId>
-        <version>4.0-SNAPSHOT</version>
     <artifactId>report-builder</artifactId>
     <packaging>jar</packaging>
     <name>report-builder</name>
     <build>
-        <finalName>${artifactId}</finalName>
+        <finalName>${project.artifactId}</finalName>
         <defaultGoal>install</defaultGoal>
         <plugins>
             <plugin>
@@ -42,7 +41,7 @@
                         <phase>install</phase>
                         <configuration>
                             <tasks>
-                                <copy file="target/${artifactId}.jar" tofile="../../lib/reportbuilder.jar"/>
+                                <copy file="target/${project.artifactId}.jar" tofile="../../lib/reportbuilder.jar"/>
                             </tasks>
                         </configuration>
                         <goals>
diff --git a/appserver/tests/gftest.sh b/appserver/tests/gftest.sh
index 7957205..2fcb499 100755
--- a/appserver/tests/gftest.sh
+++ b/appserver/tests/gftest.sh
@@ -54,8 +54,11 @@
   fi
   echo "Removing old glassfish directory: ${S1AS_HOME}";
   rm -rf "${S1AS_HOME}";
+  if [ -z "${MVN_EXTRA}" ]; then
+    export MVN_EXTRA="";
+  fi
   if [ -z "${GF_VERSION}" ]; then
-    export GF_VERSION="$(mvn help:evaluate -f \"${APS_HOME}/pom.xml\" -Dexpression=project.version -q -DforceStdout)"
+    export GF_VERSION="$(mvn help:evaluate -f \"${APS_HOME}/pom.xml\" -Dexpression=project.version -q -DforceStdout ${MVN_EXTRA})"
   fi
   if [ -z "${MVN_REPOSITORY}" ]; then
     export MVN_REPOSITORY="${HOME}/.m2/repository";
diff --git a/appserver/tests/quicklook/pom.xml b/appserver/tests/quicklook/pom.xml
index 95189c3..5e055a8 100644
--- a/appserver/tests/quicklook/pom.xml
+++ b/appserver/tests/quicklook/pom.xml
@@ -22,7 +22,7 @@
     <parent>
         <groupId>org.eclipse.ee4j</groupId>
         <artifactId>project</artifactId>
-        <version>1.0</version>
+        <version>1.0.7</version>
         <relativePath/>
     </parent>
     <groupId>org.glassfish.quicklook</groupId>
diff --git a/docs/pom.xml b/docs/pom.xml
index ff95d02..413089b 100644
--- a/docs/pom.xml
+++ b/docs/pom.xml
@@ -70,7 +70,6 @@
         <plugins>
             <plugin>
                 <artifactId>maven-enforcer-plugin</artifactId>
-                <version>3.0.0</version>
                 <executions>
                     <execution>
                         <id>enforce-versions</id>
diff --git a/nucleus/admin/rest/rest-service/pom.xml b/nucleus/admin/rest/rest-service/pom.xml
index ade651e..ea57da6 100644
--- a/nucleus/admin/rest/rest-service/pom.xml
+++ b/nucleus/admin/rest/rest-service/pom.xml
@@ -33,6 +33,7 @@
     <description>Rest Interface for GlassFish Management and Monitoring</description>
 
     <dependencies>
+
         <dependency>
             <groupId>org.glassfish.hk2</groupId>
             <artifactId>hk2</artifactId>
@@ -145,19 +146,6 @@
 
     <build>
         <plugins>
-            <plugin><!-- The services directory must be processed after compilation,
-                     it would be used in compilation otherwise and the build would fail  -->
-                <artifactId>maven-resources-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>default-resources</id>
-                        <phase>process-classes</phase>
-                        <goals>
-                            <goal>resources</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
             <!-- Test classes from this module are used elsewhere -->
             <plugin>
                 <artifactId>maven-jar-plugin</artifactId>
diff --git a/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/annotation/processor/RestModelExtensionProcessor.java b/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/annotation/processor/RestModelExtensionProcessor.java
index 89ab470..64a332c 100644
--- a/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/annotation/processor/RestModelExtensionProcessor.java
+++ b/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/annotation/processor/RestModelExtensionProcessor.java
@@ -1,4 +1,5 @@
 /*
+ * Copyright (c) 2022 Contributors to the Eclipse Foundation
  * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -23,9 +24,9 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import javax.annotation.processing.AbstractProcessor;
 import javax.annotation.processing.Filer;
-import javax.annotation.processing.Messager;
 import javax.annotation.processing.RoundEnvironment;
 import javax.annotation.processing.SupportedAnnotationTypes;
 import javax.lang.model.SourceVersion;
@@ -33,57 +34,49 @@
 import javax.lang.model.element.TypeElement;
 import javax.tools.Diagnostic.Kind;
 import javax.tools.FileObject;
-import javax.tools.StandardLocation;
+
 import org.glassfish.admin.rest.composite.RestModelExtension;
 
-/**
- * Hello world!
- *
- */
+import static javax.tools.StandardLocation.CLASS_OUTPUT;
+
+
 @SupportedAnnotationTypes("org.glassfish.admin.rest.composite.RestModelExtension")
 public class RestModelExtensionProcessor extends AbstractProcessor {
     @Override
-    public boolean process(Set<? extends TypeElement> elements, RoundEnvironment env) {
-        Messager messager = processingEnv.getMessager();
-        BufferedWriter bw = null;
+    public boolean process(final Set<? extends TypeElement> elements, final RoundEnvironment env) {
         try {
-            Map<String, List<String>> classes = new HashMap<String, List<String>>();
-
-            for (TypeElement te : elements) {
-                for (Element e : env.getElementsAnnotatedWith(te)) {
-                    final RestModelExtension annotation = e.getAnnotation(RestModelExtension.class);
+            final Map<String, List<String>> classes = new HashMap<>();
+            for (final TypeElement typeElement : elements) {
+                for (final Element element : env.getElementsAnnotatedWith(typeElement)) {
+                    final RestModelExtension annotation = element.getAnnotation(RestModelExtension.class);
                     final String parent = annotation.parent();
                     List<String> list = classes.get(parent);
                     if (list == null) {
-                        list = new ArrayList<String>();
+                        list = new ArrayList<>();
                         classes.put(parent, list);
                     }
-                    list.add(e.toString());
+                    list.add(element.toString());
                 }
             }
-
-            if (!classes.isEmpty()) {
-                final Filer filer = processingEnv.getFiler();
-                FileObject fo = filer.createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/restmodelextensions");
-                bw = new BufferedWriter(fo.openWriter());
+            if (classes.isEmpty()) {
+                return true;
+            }
+            final Filer filer = processingEnv.getFiler();
+            final FileObject file = filer.createResource(CLASS_OUTPUT, "", "META-INF/restmodelextensions");
+            try (BufferedWriter bw = new BufferedWriter(file.openWriter())) {
                 // parent model:model extension
-                for (Map.Entry<String, List<String>> entry : classes.entrySet()) {
+                for (final Map.Entry<String, List<String>> entry : classes.entrySet()) {
                     final String key = entry.getKey();
-                    for (String ext : entry.getValue()) {
-                        bw.write(key + ":" + ext + "\n");
+                    for (final String ext : entry.getValue()) {
+                        bw.write(key);
+                        bw.write(":");
+                        bw.write(ext);
+                        bw.write('\n');
                     }
                 }
-                bw.close();
             }
-        } catch (IOException ex) {
-            messager.printMessage(Kind.ERROR, ex.getLocalizedMessage());
-            if (bw != null) {
-                try {
-                    bw.close();
-                } catch (Exception e) {
-
-                }
-            }
+        } catch (final IOException ex) {
+            processingEnv.getMessager().printMessage(Kind.ERROR, ex.getLocalizedMessage());
         }
 
         return true;
diff --git a/nucleus/parent/pom.xml b/nucleus/parent/pom.xml
index 256b172..36adcc7 100644
--- a/nucleus/parent/pom.xml
+++ b/nucleus/parent/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.eclipse.ee4j</groupId>
         <artifactId>project</artifactId>
-        <version>1.0.6</version>
+        <version>1.0.7</version>
         <relativePath />
     </parent>
 
@@ -701,6 +701,28 @@
                             <testExclude>**/.ade_path/**</testExclude>
                         </testExcludes>
                     </configuration>
+                    <executions>
+                        <execution>
+                            <id>default-compile</id>
+                            <phase>compile</phase>
+                            <goals>
+                                <goal>compile</goal>
+                            </goals>
+                            <configuration>
+                                <proc>none</proc>
+                            </configuration>
+                        </execution>
+                        <execution>
+                            <id>process-annotations</id>
+                            <phase>process-classes</phase>
+                            <goals>
+                                <goal>compile</goal>
+                            </goals>
+                            <configuration>
+                                <proc>only</proc>
+                            </configuration>
+                        </execution>
+                    </executions>
                 </plugin>
                 <plugin>
                     <artifactId>maven-dependency-plugin</artifactId>
@@ -933,7 +955,6 @@
         <plugins>
             <plugin>
                 <artifactId>maven-enforcer-plugin</artifactId>
-                <version>3.0.0</version>
                 <executions>
                     <execution>
                         <id>enforce-maven</id>
diff --git a/pom.xml b/pom.xml
index 272c634..4d76f95 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.eclipse.ee4j</groupId>
         <artifactId>project</artifactId>
-        <version>1.0.6</version>
+        <version>1.0.7</version>
     </parent>
 
     <groupId>org.glassfish.main</groupId>
@@ -73,7 +73,6 @@
         <plugins>
             <plugin>
                 <artifactId>maven-enforcer-plugin</artifactId>
-                <version>3.0.0</version>
                 <executions>
                     <execution>
                         <id>enforce-maven</id>
@@ -134,9 +133,9 @@
                 <module>appserver</module>
                 <module>nucleus/hk2/config-generator</module>
                 <module>docs</module>
-                <module>appserver/admingui/devtests</module>
                 <module>appserver/extras/embedded/common</module>
-                <module>nucleus/tests</module>
+                <module>appserver/tests/appserv-tests/util/reportbuilder</module>
+                <module>appserver/tests/tck</module>
             </modules>
         </profile>