forked from moditect/moditect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create GenerateModulesList Mojo and class
- Loading branch information
1 parent
45c954f
commit c206bde
Showing
7 changed files
with
214 additions
and
10 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
core/src/main/java/org/moditect/commands/GenerateModuleList.java
This file contains 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,37 @@ | ||
/** | ||
* Copyright 2017 - 2018 The ModiTect authors | ||
* | ||
* Licensed 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.moditect.commands; | ||
|
||
import org.moditect.model.Version; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Set; | ||
|
||
public class GenerateModuleList { | ||
|
||
private final Version jvmVersion; | ||
private final Set<Path> dependencies; | ||
|
||
public GenerateModuleList(Version jvmVersion, Set<Path> dependencies) { | ||
this.jvmVersion = jvmVersion; | ||
this.dependencies = dependencies; | ||
} | ||
|
||
public void run() { | ||
System.out.println("Creating module list for " + target + " and " + dependencies); | ||
} | ||
|
||
} |
This file contains 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,63 @@ | ||
/** | ||
* Copyright 2017 - 2018 The ModiTect authors | ||
* | ||
* Licensed 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.moditect.model; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Simplified version of Runtime.Version (which requires Java 9+). | ||
*/ | ||
public class Version { | ||
|
||
private final int feature; | ||
|
||
private Version(int feature) { | ||
this.feature = feature; | ||
} | ||
|
||
public static Version valueOf(int feature) { | ||
return new Version(feature); | ||
} | ||
|
||
public static Version valueOf(Object feature) { | ||
return new Version(Integer.parseInt(String.valueOf(feature))); | ||
} | ||
|
||
public int feature() { | ||
return feature; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (!(o instanceof Version)) | ||
return false; | ||
Version version = (Version) o; | ||
return feature == version.feature; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(feature); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Version " + feature; | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
73 changes: 73 additions & 0 deletions
73
maven-plugin/src/main/java/org/moditect/mavenplugin/modulelist/GenerateModuleListMojo.java
This file contains 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,73 @@ | ||
/** | ||
* Copyright 2017 - 2018 The ModiTect authors | ||
* | ||
* Licensed 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.moditect.mavenplugin.modulelist; | ||
|
||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
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.plugins.annotations.ResolutionScope; | ||
import org.apache.maven.project.MavenProject; | ||
import org.moditect.commands.GenerateModuleList; | ||
import org.moditect.mavenplugin.util.DependencyHelper; | ||
import org.moditect.model.Version; | ||
|
||
@Mojo(name = "list-application-image-modules", | ||
defaultPhase = LifecyclePhase.PACKAGE, | ||
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME | ||
) | ||
public class GenerateModuleListMojo extends AbstractMojo { | ||
|
||
@Parameter(defaultValue = "${project}", readonly = true) | ||
protected MavenProject project; | ||
|
||
@Parameter(property = "moditect.jvmVersion") | ||
private Integer jvmVersion; | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException { | ||
GenerateModuleList generateModuleList = new GenerateModuleList( | ||
determineJvmVersion(), | ||
DependencyHelper.getDirectAndTransitiveDependencies(project) | ||
); | ||
try { | ||
generateModuleList.run(); | ||
} catch (RuntimeException ex) { | ||
getLog().error(ex); | ||
throw new MojoExecutionException("Error generating module list", ex); | ||
} | ||
} | ||
|
||
private Version determineJvmVersion() { | ||
if (jvmVersion != null) { | ||
return Version.valueOf(jvmVersion); | ||
} | ||
|
||
Object rawVersion = project.getProperties().get("maven.compiler.release"); | ||
if (rawVersion != null) { | ||
return Version.valueOf(rawVersion); | ||
} | ||
|
||
rawVersion = project.getProperties().get("maven.compiler.target"); | ||
if (rawVersion != null) { | ||
return Version.valueOf(rawVersion); | ||
} | ||
|
||
throw new IllegalStateException("Couldn't determine target version, please specify the 'targetVersion' configuration property"); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
maven-plugin/src/main/java/org/moditect/mavenplugin/util/DependencyHelper.java
This file contains 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,33 @@ | ||
/** | ||
* Copyright 2017 - 2018 The ModiTect authors | ||
* | ||
* Licensed 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.moditect.mavenplugin.util; | ||
|
||
import org.apache.maven.project.MavenProject; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class DependencyHelper { | ||
|
||
public static Set<Path> getDirectAndTransitiveDependencies(MavenProject project) { | ||
return project.getArtifacts() | ||
.stream() | ||
.map(a -> a.getFile().toPath()) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
} |