-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-39134: [Java] Create module info compiler plugin #39135
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bf1e446
Add and integrate the module-info compiler plugin
jduo 5c74cad
Fix JDK8 compile issue with module-info-compiler and attempt to fix a…
jduo c7fdeba
Fix JDK8 issue with use of Path.of
jduo 98f67a1
Skip the maven-dependency-plugin analyze check due to false positive
jduo f919002
Fix non-inherited version
jduo c38ae19
Do not use dependency analyze when compiling plugins
jduo 9b488b4
Exclude module-info.java from compilation
jduo f40b643
Exclude module-info.java files from checkstyle
jduo aa8b778
Add skip parameter and logging to module info compiler plugin
jduo dea90f9
Add ability to add module-info.java to test code
jduo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- 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. --> | ||
| <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"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.apache.arrow.maven.plugins</groupId> | ||
| <artifactId>arrow-maven-plugins</artifactId> | ||
| <version>15.0.0-SNAPSHOT</version> | ||
| </parent> | ||
| <artifactId>module-info-compiler-maven-plugin</artifactId> | ||
| <packaging>maven-plugin</packaging> | ||
|
|
||
| <name>Module Info Compiler Maven Plugin</name> | ||
|
|
||
| <url>https://arrow.apache.org</url> | ||
|
|
||
| <prerequisites> | ||
| <maven>${maven.version}</maven> | ||
| </prerequisites> | ||
|
|
||
| <properties> | ||
| <maven.version>3.3.9</maven.version> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.glavo</groupId> | ||
| <artifactId>module-info-compiler</artifactId> | ||
| <version>2.0</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.maven</groupId> | ||
| <artifactId>maven-plugin-api</artifactId> | ||
| <version>${maven.version}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.maven</groupId> | ||
| <artifactId>maven-core</artifactId> | ||
| <version>${maven.version}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.maven</groupId> | ||
| <artifactId>maven-artifact</artifactId> | ||
| <version>${maven.version}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.maven</groupId> | ||
| <artifactId>maven-model</artifactId> | ||
| <version>${maven.version}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.maven.plugin-tools</groupId> | ||
| <artifactId>maven-plugin-annotations</artifactId> | ||
| <version>3.6.0</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
| <plugins> | ||
| <plugin> | ||
| <artifactId>maven-clean-plugin</artifactId> | ||
| <version>3.1.0</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-plugin-plugin</artifactId> | ||
| <version>3.6.0</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
| <version>3.0.2</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-install-plugin</artifactId> | ||
| <version>2.5.2</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-deploy-plugin</artifactId> | ||
| <version>2.8.2</version> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-invoker-plugin</artifactId> | ||
| <version>3.1.0</version> | ||
| </plugin> | ||
| </plugins> | ||
| </pluginManagement> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-plugin-plugin</artifactId> | ||
| <version>3.6.0</version> | ||
| <configuration> | ||
| <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> | ||
| </configuration> | ||
| <executions> | ||
| <execution> | ||
| <id>mojo-descriptor</id> | ||
| <goals> | ||
| <goal>descriptor</goal> | ||
| </goals> | ||
| </execution> | ||
| <execution> | ||
| <id>help-goal</id> | ||
| <goals> | ||
| <goal>helpmojo</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
|
|
||
| </project> | ||
92 changes: 92 additions & 0 deletions
92
...ven-plugin/src/main/java/org/apache/arrow/maven/plugins/BaseModuleInfoCompilerPlugin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<String> 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<File> 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<File> findFirstModuleInfo(List<String> 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(); | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
...r-maven-plugin/src/main/java/org/apache/arrow/maven/plugins/ModuleInfoCompilerPlugin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<String> 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<String> getSourceRoots() { | ||
| return compileSourceRoots; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean skip() { | ||
| return skip; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getOutputDirectory() { | ||
| return project.getBuild().getOutputDirectory(); | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
...ven-plugin/src/main/java/org/apache/arrow/maven/plugins/ModuleInfoTestCompilerPlugin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<String> getSourceRoots() { | ||
| return project.getTestCompileSourceRoots(); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean skip() { | ||
| return skip; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getOutputDirectory() { | ||
| return project.getBuild().getTestOutputDirectory(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we want to avoid the defaults/are these inconsistent with the global config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was generated by the maven plugin archetype I used.