Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed maven compiler annotation processing #23899

Merged
merged 5 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions appserver/jdbc/jdbc-ra/jdbc40/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
7 changes: 0 additions & 7 deletions appserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -661,13 +661,6 @@
</plugins>
</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>
Expand Down
11 changes: 5 additions & 6 deletions appserver/tests/appserv-tests/util/reportbuilder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
5 changes: 4 additions & 1 deletion appserver/tests/gftest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ if [ ! -z "${JENKINS_HOME}" ] ; then
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";
Expand Down
2 changes: 1 addition & 1 deletion appserver/tests/quicklook/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>enforce-versions</id>
Expand Down
14 changes: 1 addition & 13 deletions nucleus/admin/rest/rest-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<description>Rest Interface for GlassFish Management and Monitoring</description>

<dependencies>

<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2</artifactId>
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,67 +24,59 @@
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;
import javax.lang.model.element.Element;
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;
Expand Down
25 changes: 23 additions & 2 deletions nucleus/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -933,7 +955,6 @@
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>enforce-maven</id>
Expand Down
7 changes: 3 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -73,7 +73,6 @@
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>enforce-maven</id>
Expand Down Expand Up @@ -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>

Expand Down