Skip to content
Merged
Show file tree
Hide file tree
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 May 30, 2023
abac003
Fixes
gnodet Feb 27, 2024
f228ca0
Allow sorting JDKs + fixes following review
gnodet Feb 28, 2024
99dd2b9
Fix exception handling in mojos
gnodet Feb 28, 2024
1cd938c
Support selecting toolchain based on environment variable
gnodet Feb 28, 2024
9a8895f
Fix inverted matching tests
gnodet Feb 28, 2024
7b623f7
Merge branch 'master' into discovered-toolchains
gnodet Feb 28, 2024
9698324
Merge remote-tracking branch 'origin/master' into discovered-toolchains
gnodet Feb 28, 2024
6d4f251
Remove useless log
gnodet Feb 28, 2024
5a585f0
Clean error messages
gnodet Feb 28, 2024
1d31b41
Restrict cache access to the 3 methods, cache always logs at debug level
gnodet Feb 28, 2024
53dddc6
Disable test on jdk 8
gnodet Feb 28, 2024
eba1a9f
Add some site doc
gnodet Feb 28, 2024
a0f733a
Add support for windows' scoop installer
gnodet Mar 1, 2024
540802f
Merge remote-tracking branch 'origin/master' into discovered-toolchains
gnodet Mar 1, 2024
f3b0b29
Fixes from review
gnodet Mar 1, 2024
0e85805
Check the currently selected version of any Scoop package
mthmulders Mar 4, 2024
afea2b2
Avoid using hardcoded file separator
gnodet Mar 6, 2024
2a21af1
For now, add all scoop children paths as possible install dirs
gnodet Mar 6, 2024
05efc33
Merge remote-tracking branch 'origin/master' into discovered-toolchains
gnodet Mar 6, 2024
450b405
Cache found JDK in the singleton
gnodet Mar 7, 2024
8576b79
Code style
gnodet Mar 7, 2024
f0978ce
Fix current JDK toolchain discovery
gnodet Mar 16, 2024
16d4562
Make the isLts check more robust
gnodet Mar 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ under the License.
<artifactId>maven-plugin-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -114,5 +136,11 @@ under the License.
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
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()));
}
}
}
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)) {
new MavenToolchainsXpp3Writer().write(writer, toolchains);
}
} else {
StringWriter writer = new StringWriter();
new MavenToolchainsXpp3Writer().write(writer, toolchains);
System.out.println(writer);
}
} catch (IOException e) {
throw new MojoFailureException("Unable to generate toolchains.xml", e);
}
}
}
Loading