diff --git a/java/maven/module-info-compiler-maven-plugin/pom.xml b/java/maven/module-info-compiler-maven-plugin/pom.xml new file mode 100644 index 00000000000..ce598fc7f0f --- /dev/null +++ b/java/maven/module-info-compiler-maven-plugin/pom.xml @@ -0,0 +1,130 @@ + + + + 4.0.0 + + org.apache.arrow.maven.plugins + arrow-maven-plugins + 15.0.0-SNAPSHOT + + module-info-compiler-maven-plugin + maven-plugin + + Module Info Compiler Maven Plugin + + https://arrow.apache.org + + + ${maven.version} + + + + 3.3.9 + + + + + org.glavo + module-info-compiler + 2.0 + + + org.apache.maven + maven-plugin-api + ${maven.version} + provided + + + org.apache.maven + maven-core + ${maven.version} + provided + + + org.apache.maven + maven-artifact + ${maven.version} + provided + + + org.apache.maven + maven-model + ${maven.version} + provided + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.6.0 + provided + + + + + + + + maven-clean-plugin + 3.1.0 + + + maven-plugin-plugin + 3.6.0 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + maven-invoker-plugin + 3.1.0 + + + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.6.0 + + true + + + + mojo-descriptor + + descriptor + + + + help-goal + + helpmojo + + + + + + + + + \ No newline at end of file diff --git a/java/maven/module-info-compiler-maven-plugin/src/main/java/org/apache/arrow/maven/plugins/BaseModuleInfoCompilerPlugin.java b/java/maven/module-info-compiler-maven-plugin/src/main/java/org/apache/arrow/maven/plugins/BaseModuleInfoCompilerPlugin.java new file mode 100644 index 00000000000..37cbf5d7e77 --- /dev/null +++ b/java/maven/module-info-compiler-maven-plugin/src/main/java/org/apache/arrow/maven/plugins/BaseModuleInfoCompilerPlugin.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.arrow.maven.plugins; + +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.Optional; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.glavo.mic.ModuleInfoCompiler; + +/** + * Compiles the first module-info.java file in the project purely syntactically. + */ +public abstract class BaseModuleInfoCompilerPlugin extends AbstractMojo { + protected abstract List getSourceRoots(); + + protected abstract boolean skip(); + + protected abstract String getOutputDirectory(); + + @Override + public void execute() throws MojoExecutionException { + if (skip()) { + getLog().info("Skipping module-info-compiler-maven-plugin"); + return; + } + + Optional moduleInfoFile = findFirstModuleInfo(getSourceRoots()); + if (moduleInfoFile.isPresent()) { + // The compiled module-info.class file goes into target/classes/module-info/main + Path outputDir = Paths.get(getOutputDirectory()); + + outputDir.toFile().mkdirs(); + Path targetPath = outputDir.resolve("module-info.class"); + + // Invoke the compiler, + ModuleInfoCompiler compiler = new ModuleInfoCompiler(); + try (Reader reader = new InputStreamReader(Files.newInputStream(moduleInfoFile.get().toPath()), + StandardCharsets.UTF_8); + OutputStream output = Files.newOutputStream(targetPath)) { + compiler.compile(reader, output); + getLog().info("Successfully wrote module-info.class file."); + } catch (IOException ex) { + throw new MojoExecutionException("Error compiling module-info.java", ex); + } + } else { + getLog().info("No module-info.java file found. module-info.class file was not generated."); + } + } + + /** + * Finds the first module-info.java file in the set of source directories. + */ + private Optional findFirstModuleInfo(List sourceDirectories) { + if (sourceDirectories == null) { + return Optional.empty(); + } + + return sourceDirectories.stream().map(Paths::get) + .map(sourcePath -> + sourcePath.toFile().listFiles(file -> + file.getName().equals("module-info.java"))) + .filter(matchingFiles -> matchingFiles != null && matchingFiles.length != 0) + .map(matchingFiles -> matchingFiles[0]) + .findAny(); + } +} diff --git a/java/maven/module-info-compiler-maven-plugin/src/main/java/org/apache/arrow/maven/plugins/ModuleInfoCompilerPlugin.java b/java/maven/module-info-compiler-maven-plugin/src/main/java/org/apache/arrow/maven/plugins/ModuleInfoCompilerPlugin.java new file mode 100644 index 00000000000..31df6372925 --- /dev/null +++ b/java/maven/module-info-compiler-maven-plugin/src/main/java/org/apache/arrow/maven/plugins/ModuleInfoCompilerPlugin.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.arrow.maven.plugins; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +/** + * A maven plugin for compiler module-info files in main code with JDK8. + */ +@Mojo(name = "compile", defaultPhase = LifecyclePhase.COMPILE) +public class ModuleInfoCompilerPlugin extends BaseModuleInfoCompilerPlugin { + + @Parameter(defaultValue = "${project.compileSourceRoots}", property = "compileSourceRoots", + required = true) + private final List compileSourceRoots = new ArrayList<>(); + + @Parameter(defaultValue = "false", property = "skip", required = false) + private boolean skip = false; + + @Parameter(defaultValue = "${project}", readonly = true, required = true) + private MavenProject project; + + @Override + protected List getSourceRoots() { + return compileSourceRoots; + } + + @Override + protected boolean skip() { + return skip; + } + + @Override + protected String getOutputDirectory() { + return project.getBuild().getOutputDirectory(); + } +} diff --git a/java/maven/module-info-compiler-maven-plugin/src/main/java/org/apache/arrow/maven/plugins/ModuleInfoTestCompilerPlugin.java b/java/maven/module-info-compiler-maven-plugin/src/main/java/org/apache/arrow/maven/plugins/ModuleInfoTestCompilerPlugin.java new file mode 100644 index 00000000000..4705506ac53 --- /dev/null +++ b/java/maven/module-info-compiler-maven-plugin/src/main/java/org/apache/arrow/maven/plugins/ModuleInfoTestCompilerPlugin.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.arrow.maven.plugins; + +import java.util.List; + +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +/** + * A maven plugin for compiler module-info files in unit tests with JDK8. + */ +@Mojo(name = "testCompile", defaultPhase = LifecyclePhase.TEST_COMPILE) +public class ModuleInfoTestCompilerPlugin extends BaseModuleInfoCompilerPlugin { + + @Parameter(defaultValue = "false", property = "skip", required = false) + private boolean skip = false; + + @Parameter(defaultValue = "${project}", readonly = true, required = true) + private MavenProject project; + + @Override + protected List getSourceRoots() { + return project.getTestCompileSourceRoots(); + } + + @Override + protected boolean skip() { + return skip; + } + + @Override + protected String getOutputDirectory() { + return project.getBuild().getTestOutputDirectory(); + } +} diff --git a/java/maven/pom.xml b/java/maven/pom.xml new file mode 100644 index 00000000000..86ac402732b --- /dev/null +++ b/java/maven/pom.xml @@ -0,0 +1,287 @@ + + + + 4.0.0 + + org.apache.arrow.maven.plugins + arrow-maven-plugins + 15.0.0-SNAPSHOT + Arrow Maven Plugins + pom + + + module-info-compiler-maven-plugin + + + + true + + + + + + org.apache.rat + apache-rat-plugin + + + rat-checks + validate + + check + + + + + false + + **/dependency-reduced-pom.xml + **/*.log + **/*.css + **/*.js + **/*.md + **/*.eps + **/*.json + **/*.seq + **/*.parquet + **/*.sql + **/arrow-git.properties + **/*.csv + **/*.csvh + **/*.csvh-test + **/*.tsv + **/*.txt + **/*.ssv + **/arrow-*.conf + **/.buildpath + **/*.proto + **/*.fmpp + **/target/** + **/*.tdd + **/*.project + **/TAGS + **/*.checkstyle + **/.classpath + **/.factorypath + **/.settings/** + .*/** + **/*.patch + **/*.pb.cc + **/*.pb.h + **/*.linux + **/client/build/** + **/*.tbl + **/*.iml + **/flight.properties + **/*.idea/** + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + **/logging.properties + **/logback-test.xml + **/logback.out.xml + **/logback.xml + + + true + + true + true + + + org.apache.arrow + ${username} + https://arrow.apache.org/ + + + + + + + test-jar + + + true + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + + UTF-8 + + + + org.apache.maven.plugins + maven-compiler-plugin + + UTF-8 + 1.8 + 1.8 + 2048m + false + true + + + + maven-enforcer-plugin + + + validate_java_and_maven_version + verify + + enforce + + false + + + + [3.3.0,4) + + + + + + avoid_bad_dependencies + verify + + enforce + + + + + + commons-logging + javax.servlet:servlet-api + org.mortbay.jetty:servlet-api + org.mortbay.jetty:servlet-api-2.5 + log4j:log4j + + + + + + + + + pl.project13.maven + git-commit-id-plugin + 4.0.5 + + + for-jars + true + + revision + + + target/classes/arrow-git.properties + + + + for-source-tarball + + revision + + false + + ./arrow-git.properties + + + + + + dd.MM.yyyy '@' HH:mm:ss z + false + false + true + false + + false + false + 7 + -dirty + true + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.1.0 + + + com.puppycrawl.tools + checkstyle + 8.19 + + + org.slf4j + jcl-over-slf4j + 1.7.5 + + + + + validate + validate + + check + + + + + ../dev/checkstyle/checkstyle.xml + ../dev/checkstyle/checkstyle.license + ../dev/checkstyle/suppressions.xml + true + UTF-8 + true + ${checkstyle.failOnViolation} + ${checkstyle.failOnViolation} + warning + xml + html + ${project.build.directory}/test/checkstyle-errors.xml + false + + + + org.cyclonedx + cyclonedx-maven-plugin + 2.7.10 + + + package + + makeBom + + + + + + + + diff --git a/java/pom.xml b/java/pom.xml index cb1aecb1d21..86eb428ebd5 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -321,6 +321,7 @@ + **/module-info.java dev/checkstyle/checkstyle.xml dev/checkstyle/checkstyle.license dev/checkstyle/suppressions.xml @@ -371,6 +372,24 @@ + + org.apache.arrow.maven.plugins + module-info-compiler-maven-plugin + + + default-compile + + compile + + + + default-testCompile + + testCompile + + + + @@ -400,6 +419,8 @@ maven-compiler-plugin ${maven-compiler-plugin.version} + **/module-info.java + **/module-info.java false @@ -546,6 +567,11 @@ + + org.apache.arrow.maven.plugins + module-info-compiler-maven-plugin + ${project.version} + @@ -735,6 +761,7 @@ + maven bom format memory @@ -1236,7 +1263,6 @@ -