-
Notifications
You must be signed in to change notification settings - Fork 29
[MTOOLCHAINS-49] Automatic discovery of JDK toolchains #14
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
24 commits
Select commit
Hold shift + click to select a range
101cfec
JDK Toolchains discovery mojos
gnodet abac003
Fixes
gnodet f228ca0
Allow sorting JDKs + fixes following review
gnodet 99dd2b9
Fix exception handling in mojos
gnodet 1cd938c
Support selecting toolchain based on environment variable
gnodet 9a8895f
Fix inverted matching tests
gnodet 7b623f7
Merge branch 'master' into discovered-toolchains
gnodet 9698324
Merge remote-tracking branch 'origin/master' into discovered-toolchains
gnodet 6d4f251
Remove useless log
gnodet 5a585f0
Clean error messages
gnodet 1d31b41
Restrict cache access to the 3 methods, cache always logs at debug level
gnodet 53dddc6
Disable test on jdk 8
gnodet eba1a9f
Add some site doc
gnodet a0f733a
Add support for windows' scoop installer
gnodet 540802f
Merge remote-tracking branch 'origin/master' into discovered-toolchains
gnodet f3b0b29
Fixes from review
gnodet 0e85805
Check the currently selected version of any Scoop package
mthmulders afea2b2
Avoid using hardcoded file separator
gnodet 2a21af1
For now, add all scoop children paths as possible install dirs
gnodet 05efc33
Merge remote-tracking branch 'origin/master' into discovered-toolchains
gnodet 450b405
Cache found JDK in the singleton
gnodet 8576b79
Code style
gnodet f0978ce
Fix current JDK toolchain discovery
gnodet 16d4562
Make the isLts check more robust
gnodet 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
75 changes: 75 additions & 0 deletions
75
src/main/java/org/apache/maven/plugins/toolchain/jdk/DisplayDiscoveredJdkToolchainsMojo.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,75 @@ | ||
| /* | ||
| * 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.maven.plugins.toolchain.jdk; | ||
|
|
||
| import javax.inject.Inject; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.apache.maven.plugin.AbstractMojo; | ||
| import org.apache.maven.plugins.annotations.Mojo; | ||
| import org.apache.maven.plugins.annotations.Parameter; | ||
| import org.apache.maven.toolchain.model.PersistedToolchains; | ||
| import org.apache.maven.toolchain.model.ToolchainModel; | ||
| import org.codehaus.plexus.util.xml.Xpp3Dom; | ||
|
|
||
| import static java.util.Comparator.comparing; | ||
| import static org.apache.maven.plugins.toolchain.jdk.ToolchainDiscoverer.SORTED_PROVIDES; | ||
|
|
||
| /** | ||
| * Discover the JDK toolchains and print them to the console. | ||
| */ | ||
| @Mojo(name = "display-discovered-jdk-toolchains", requiresProject = false) | ||
| public class DisplayDiscoveredJdkToolchainsMojo extends AbstractMojo { | ||
|
|
||
| /** | ||
| * Comparator used to sort JDK toolchains for selection. | ||
| * This property is a comma separated list of values which may contains: | ||
| * <ul> | ||
| * <li>{@code lts}: prefer JDK with LTS version</li> | ||
| * <li>{@code current}: prefer the current JDK</li> | ||
| * <li>{@code env}: prefer JDKs defined using {@code JAVA\{xx\}_HOME} environment variables</li> | ||
| * <li>{@code version}: prefer JDK with higher versions</li> | ||
| * <li>{@code vendor}: order JDK by vendor name (usually as a last comparator to ensure a stable order)</li> | ||
| * </ul> | ||
| */ | ||
| @Parameter(property = "toolchain.jdk.comparator", defaultValue = "lts,current,env,version,vendor") | ||
| String comparator; | ||
|
|
||
| /** | ||
| * Toolchain discoverer | ||
| */ | ||
| @Inject | ||
| ToolchainDiscoverer discoverer; | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| PersistedToolchains toolchains = discoverer.discoverToolchains(comparator); | ||
| List<ToolchainModel> models = toolchains.getToolchains(); | ||
| getLog().info("Discovered " + models.size() + " JDK toolchains:"); | ||
| for (ToolchainModel model : models) { | ||
| getLog().info(" - " | ||
| + ((Xpp3Dom) model.getConfiguration()).getChild("jdkHome").getValue()); | ||
| getLog().info(" provides:"); | ||
| model.getProvides().entrySet().stream() | ||
| .sorted(comparing(e -> SORTED_PROVIDES.indexOf(e.getKey().toString()))) | ||
| .forEach(e -> getLog().info(" " + e.getKey() + ": " + e.getValue())); | ||
| } | ||
| } | ||
| } | ||
75 changes: 75 additions & 0 deletions
75
src/main/java/org/apache/maven/plugins/toolchain/jdk/GenerateJdkToolchainsXmlMojo.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,75 @@ | ||
| /* | ||
| * 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.maven.plugins.toolchain.jdk; | ||
|
|
||
| import javax.inject.Inject; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.StringWriter; | ||
| import java.io.Writer; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
|
|
||
| import org.apache.maven.plugin.AbstractMojo; | ||
| import org.apache.maven.plugin.MojoFailureException; | ||
| import org.apache.maven.plugins.annotations.Mojo; | ||
| import org.apache.maven.plugins.annotations.Parameter; | ||
| import org.apache.maven.toolchain.model.PersistedToolchains; | ||
| import org.apache.maven.toolchain.model.io.xpp3.MavenToolchainsXpp3Writer; | ||
|
|
||
| /** | ||
| * Run the JDK toolchain discovery mechanism and generates a toolchains XML. | ||
| */ | ||
| @Mojo(name = "generate-jdk-toolchains-xml", requiresProject = false) | ||
| public class GenerateJdkToolchainsXmlMojo extends AbstractMojo { | ||
|
|
||
| /** | ||
| * The path and name pf the toolchain XML file that will be generated. | ||
| * If not provided, the XML will be written to the standard output. | ||
| */ | ||
| @Parameter(property = "toolchain.file") | ||
| String file; | ||
|
|
||
| /** | ||
| * Toolchain discoverer | ||
| */ | ||
| @Inject | ||
| ToolchainDiscoverer discoverer; | ||
|
|
||
| @Override | ||
| public void execute() throws MojoFailureException { | ||
| try { | ||
| PersistedToolchains toolchains = discoverer.discoverToolchains(); | ||
| if (file != null) { | ||
| Path file = Paths.get(this.file).toAbsolutePath(); | ||
| Files.createDirectories(file.getParent()); | ||
| try (Writer writer = Files.newBufferedWriter(file)) { | ||
elharo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| new MavenToolchainsXpp3Writer().write(writer, toolchains); | ||
| } | ||
| } else { | ||
| StringWriter writer = new StringWriter(); | ||
| new MavenToolchainsXpp3Writer().write(writer, toolchains); | ||
| System.out.println(writer); | ||
elharo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } catch (IOException e) { | ||
| throw new MojoFailureException("Unable to generate toolchains.xml", e); | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.