5 update sourceversion to allow later java versions (#6)

* dynamically set supportedSourceVersion

* pom cleanup

* update dependencies

* add javadoc

* remove .gitlab-ci.yml

* set version in parent pom

* javadoc update
This commit is contained in:
Hari Nair
2025-01-23 10:35:49 -05:00
committed by GitHub
parent f0d08eb764
commit 7a18516e22
9 changed files with 118 additions and 186 deletions

View File

@@ -1,73 +0,0 @@
stages:
- build
- verify
- document
- deploy
variables:
JAVA_HOME: "/usr/lib/jvm/java-17-openjdk-amd64" # Sets Java version to run (see /opt for details)
VERSION_COMMIT: "GitLab CI Versioning Commit" # Commit text for version update
VERSION_BRANCH: "update_version" # Branch used to merge version update commit
# Sets the artifact cache to a local directory within build area
MAVEN_CLI_OPTS: "-Dmaven.repo.local=.m2/repository --batch-mode -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN"
#Workflow rules that filters across the entire pipeline. Cleaner than -o ci.skip since there won't be a "skipped" pipeline.
workflow:
rules:
# If user is not the runner, branch is the default branch, and the pipeline source is a push
- if: '$GITLAB_USER_LOGIN != $RUNNER_USER_LOGIN && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push"'
when: always
# if the first statement fails, never succeed
- when: never
# Cache the artifact repository (not the target directory, as that causes old classes that are deleted to persist, and be deployed when they shouldn't be).
cache:
paths:
- .m2/repository/
maven build:
stage: build
script:
# --- Checks if code compiles
- mvn $MAVEN_CLI_OPTS clean compile
maven verify:
stage: verify
script:
# -fn indicates that it should never fail, this allows artifacts to be built even when unit tests fail to execute successfully
- mvn $MAVEN_CLI_OPTS clean verify
# instruct gitlab to capture the test reports
# test reporting to be handled in gitlab requires:
# sudo gitlab-rails console
# irb(main):001:0> Feature.enable(:junit_pipeline_view,Project.find(84))
artifacts:
reports:
junit:
- target/surefire-reports/TEST-*.xml
- target/failsafe-reports/TEST-*.xml
# Allows a this job to fail, and the pipeline will continue
allow_failure: true
maven document:
stage: document
script:
- mvn $MAVEN_CLI_OPTS clean -DadditionalJOption=-Xdoclint:none javadoc:aggregate-jar
maven deploy:
stage: deploy
script:
# --- set version to last commit date+hash
- UPDATED_VERSION=$(git log -1 --format=%cd --date=format:%Y.%m.%d)-$CI_COMMIT_SHORT_SHA
- echo updated deployment version to $UPDATED_VERSION
# --- Set the update version in the pom file(s)
- mvn $MAVEN_CLI_OPTS versions:set -q -DnewVersion=${UPDATED_VERSION}
# --- Deploy to artifactory
# Again, -fn might be necessary here if artifacts are to be deployed even when unit tests fail
# -DskipTests will not execute unit tests, this should allow the artifact to be deployed if unit tests fail in the previous stage
# -Dmaven.test.skip=true will also stop the unit tests from being compiled--which potentially would speed this up
# -Dmaven.javadoc.failOnError=false instructs this to proceed even if javadoc generation fails
- mvn $MAVEN_CLI_OPTS -DskipTests -Dmaven.javadoc.failOnError=false clean deploy
when: manual

View File

@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>jackfruit-parent</artifactId>
<groupId>edu.jhuapl.ses</groupId>
<version>1.0.1-SNAPSHOT</version>
<version>${revision}</version>
</parent>
<artifactId>jackfruit-demo</artifactId>
@@ -15,19 +14,11 @@
<name>jackfruit-demo</name>
<description>Java Annotations Configuration library demo code</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<!-- skip site generation for demo package -->
<maven-site-plugin.skip>true</maven-site-plugin.skip>
</properties>
<dependencies>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>edu.jhuapl.ses</groupId>
@@ -37,8 +28,12 @@
</dependencies>
<build>
<plugins>
</plugins>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>jackfruit-parent</artifactId>
<groupId>edu.jhuapl.ses</groupId>
<version>1.0.1-SNAPSHOT</version>
<version>${revision}</version>
</parent>
<artifactId>jackfruit</artifactId>
@@ -23,13 +22,10 @@
<properties>
<package>jackfruit</package>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<auto-service.version>1.1.1</auto-service.version>
<commons-configuration2.version>2.9.0</commons-configuration2.version>
<log4j-version>2.20.0</log4j-version>
<immutables.version>2.9.3</immutables.version>
<commons-configuration2.version>2.11.0</commons-configuration2.version>
<log4j-version>2.24.3</log4j-version>
<immutables.version>2.10.1</immutables.version>
<maven-site-plugin.skip>false</maven-site-plugin.skip>
</properties>
@@ -74,7 +70,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<version>3.5.0</version>
<executions>
<execution>
<phase>generate-sources</phase>

View File

@@ -9,7 +9,7 @@ cd "$(dirname "$0")"
version=$1
date=$(date -u +"%y.%m.%d")
date=$(date -u +"%Y-%b-%d %H:%M:%S %Z")
mkdir -p "$(dirname "$srcFile")"

View File

@@ -2,8 +2,8 @@
package jackfruit;
public class JackfruitVersion {
public final static String version = "1.0.1-SNAPSHOT";
public final static String version = "1.1.0-SNAPSHOT";
public final static String packageName = "jackfruit";
public final static String dateString = "23.12.21";
public final static String dateString = "2025-Jan-16 18:37:27 UTC";
}

View File

@@ -20,7 +20,6 @@ package jackfruit.processor;
* #L%
*/
import jackfruit.annotations.Parser;
import java.util.List;
import java.util.Optional;
import javax.lang.model.type.TypeMirror;

View File

@@ -34,18 +34,18 @@ import org.apache.commons.configuration2.PropertiesConfigurationLayout;
public interface ConfigFactory<T> {
/**
* @return This returns an object of type T with default values.
* @return an object of type T with default values.
*/
T getTemplate();
/**
* @param config configuration to turn into an object of type T
* @param config configuration to translate to an object of type T
* @return an object of type T from the supplied Apache Commons {@link Configuration}.
*/
T fromConfig(Configuration config);
/**
* @param t object to convert to a configuration
* @param t object to translate to a configuration
* @param layout used for formatting the returned PropertiesConfiguration
* @return an Apache Commons {@link PropertiesConfiguration} from the supplied object T.
*/

View File

@@ -43,6 +43,7 @@ import javax.lang.model.util.Types;
import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.PropertiesConfigurationLayout;
/**
* Useful references for writing an annotation processor:
@@ -58,11 +59,21 @@ import org.apache.commons.configuration2.Configuration;
*
* @author Hari.Nair@jhuapl.edu
*/
@SupportedSourceVersion(SourceVersion.RELEASE_17)
@SupportedAnnotationTypes("jackfruit.annotations.Jackfruit")
@AutoService(Processor.class)
public class ConfigProcessor extends AbstractProcessor {
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
}
@Override
public SourceVersion getSupportedSourceVersion() {
// Dynamically return the latest version available
return SourceVersion.latest();
}
private List<Class<? extends Annotation>> supportedMethodAnnotations;
private Messager messager;
@@ -255,7 +266,7 @@ public class ConfigProcessor extends AbstractProcessor {
}
} catch (IOException e1) {
messager.printMessage(Diagnostic.Kind.ERROR, e1.getLocalizedMessage());
e1.printStackTrace();
return false;
}
}
return true;
@@ -264,7 +275,7 @@ public class ConfigProcessor extends AbstractProcessor {
/**
* @param e annotated method
* @param defaultValues default values for annotations - could be from a parent class
* @return annotation values
* @return annotation values for this method
*/
private AnnotationBundle buildAnnotationBundle(
ExecutableElement e, AnnotationBundle defaultValues) {
@@ -291,9 +302,8 @@ public class ConfigProcessor extends AbstractProcessor {
// these are the parameter types for a generic class
List<? extends TypeMirror> args = ((DeclaredType) returnType).getTypeArguments();
typeArgs.addAll(args);
} else if (erasure.getKind().isPrimitive()) {
// no type arguments here
} else {
} else if (!erasure.getKind().isPrimitive()) {
// There is a type argument here
processingEnv
.getMessager()
.printMessage(
@@ -346,13 +356,15 @@ public class ConfigProcessor extends AbstractProcessor {
}
/**
* Build the method to generate an Apache Commons {@link Configuration} from an object
* Create the {@link ConfigFactory#toConfig(Object, PropertiesConfigurationLayout)} method.
*
* @param tvn
* @param m
* @param annotationsMap
* @param prefixMemberName
* @return
* @param tvn the type variable name representing the generic type of the object being processed.
* @param m the method being processed.
* @param annotationsMap a map containing methods and associated metadata.
* @param includedMap a map containing classes to be added from an {@link Include} annotation.
* @param prefixMemberName a string representing the prefix when generating configuration keys.
* @return a {@link MethodSpec} instance representing the generated method for converting an
* object to an Apache Commons {@link Configuration}.
*/
private MethodSpec buildToConfig(
TypeVariableName tvn,
@@ -393,7 +405,7 @@ public class ConfigProcessor extends AbstractProcessor {
needBlank = false;
}
TypeMirror parser = null;
TypeMirror parser;
String parserName = null;
if (ab.parserClass().isPresent()) {
parser = ab.parserClass().get();
@@ -482,12 +494,12 @@ public class ConfigProcessor extends AbstractProcessor {
}
/**
* Create a method that returns a template object, populated by the default values
* Create the {@link ConfigFactory#getTemplate()} method.
*
* @param tvn
* @param m
* @param annotationsMap
* @return
* @param tvn the type variable name representing the generic type of the object being processed.
* @param m the method being processed.
* @param annotationsMap a map containing methods and associated metadata.
* @return a {@link MethodSpec} that returns a template object, populated by the default values.
*/
private MethodSpec buildGetTemplate(
TypeVariableName tvn,
@@ -533,7 +545,7 @@ public class ConfigProcessor extends AbstractProcessor {
.returns(TypeName.get(method.getReturnType()))
.addJavadoc(bundle.comment());
TypeMirror parser = null;
TypeMirror parser;
String parserName = null;
if (bundle.parserClass().isPresent()) {
parser = bundle.parserClass().get();
@@ -607,13 +619,14 @@ public class ConfigProcessor extends AbstractProcessor {
}
/**
* Create a method to create a configuration from the object
* Create the {@link ConfigFactory#fromConfig(Configuration)} method.
*
* @param tvn
* @param m
* @param annotationsMap
* @param prefix
* @return
* @param tvn the type variable name representing the generic type of the object being processed.
* @param m the method being processed.
* @param annotationsMap a map containing methods and associated metadata.
* @param includedMap a map containing classes to be added from an {@link Include} annotation.
* @return a {@link MethodSpec} instance representing the generated method for converting an
* Apache Commons {@link Configuration} to an object.
*/
private MethodSpec buildFromConfig(
TypeVariableName tvn,
@@ -664,7 +677,7 @@ public class ConfigProcessor extends AbstractProcessor {
.addStatement("throw new $T($S + key)", RuntimeException.class, "No such key ")
.endControlFlow();
TypeMirror parser = null;
TypeMirror parser;
String parserName = null;
if (bundle.parserClass().isPresent()) {
parser = bundle.parserClass().get();
@@ -744,12 +757,12 @@ public class ConfigProcessor extends AbstractProcessor {
}
/**
* Create a method for each member that allows it to be replaced.
* Create the "with" methods of the factory class.
*
* @param tvn
* @param annotationsMap
* @param prefixMemberName
* @return
* @param tvn the type variable name representing the generic type of the object being processed.
* @param annotationsMap a map containing methods and associated metadata.
* @param prefixMemberName a string representing the prefix when generating configuration keys.
* @return A list of methods that allow the user to change values.
*/
private List<MethodSpec> buildWithMethods(
TypeVariableName tvn,
@@ -794,7 +807,7 @@ public class ConfigProcessor extends AbstractProcessor {
AnnotationBundle ab = annotationsMap.get(method);
String key = ab.key();
TypeMirror parser = null;
TypeMirror parser;
String parserName = null;
if (ab.parserClass().isPresent()) {
parser = ab.parserClass().get();

102
pom.xml
View File

@@ -1,18 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.jhuapl.ses</groupId>
<artifactId>jackfruit-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>${revision}</version>
<packaging>pom</packaging>
<name>jackfruit-parent</name>
<description>Jackfruit processes annotations on Java interfaces and abstract classes to generate code that can read and write Apache Configuration files.</description>
<description>Jackfruit processes annotations on Java interfaces and abstract classes to generate code that can read and write Apache Configuration files.</description>
<url>https://github.com/JHUAPL/Jackfruit</url>
<properties>
<revision>1.1.2-SNAPSHOT</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
<!-- only do site generation for jackfruit package, skip for demo -->
<maven-site-plugin.skip>true</maven-site-plugin.skip>
</properties>
<inceptionYear>2023</inceptionYear>
<organization>
<name>Johns Hopkins University Applied Physics Laboratory</name>
@@ -28,11 +35,11 @@
<developers>
<developer>
<id>HariNairJHUAPL</id>
<name>Hari Nair</name>
<email>Hari.Nair@jhuapl.edu</email>
<organization>JHUAPL</organization>
<organizationUrl>https://www.jhuapl.edu/</organizationUrl>
<id>HariNairJHUAPL</id>
<name>Hari Nair</name>
<email>Hari.Nair@jhuapl.edu</email>
<organization>JHUAPL</organization>
<organizationUrl>https://www.jhuapl.edu/</organizationUrl>
</developer>
</developers>
@@ -46,19 +53,11 @@
<!-- publish to maven central -->
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<!-- only do site generation for jackfruit package -->
<maven-site-plugin.skip>true</maven-site-plugin.skip>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
@@ -77,7 +76,17 @@
https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.3.1</version>
<version>3.4.0</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<compilerArgs>
<arg>-proc:full</arg>
</compilerArgs>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<!-- default lifecycle, jar packaging: see
https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
@@ -85,49 +94,42 @@
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<version>3.5.2</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.1</version>
<version>3.1.3</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
<version>3.1.3</version>
</plugin>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version>
<version>3.11.2</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugin>
<!-- site lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>4.0.0-M9</version>
<version>4.0.0-M16</version>
<configuration>
<skip>${maven-site-plugin.skip}</skip>
</configuration>
@@ -135,13 +137,13 @@
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.4.5</version>
<version>3.8.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>2.2.0</version>
<version>2.5.0</version>
<configuration>
<licenseName>apache_v2</licenseName>
</configuration>
@@ -163,7 +165,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
@@ -177,12 +179,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.4.0</version>
<version>3.5.0</version>
<executions>
<execution>
<id>enforce-maven</id>
@@ -192,7 +194,7 @@
<configuration>
<rules>
<requireMavenVersion>
<version>3.5.4</version>
<version>3.6.3</version>
</requireMavenVersion>
</rules>
</configuration>
@@ -203,7 +205,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.7</version>
<executions>
<execution>
<id>sign-artifacts</id>
@@ -224,7 +226,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<version>1.7.0</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>