Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;

Check warning on line 29 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 29 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 29 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-25-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 29 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-8-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 29 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 29 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 29 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-8-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand All @@ -46,11 +46,9 @@
configurator = "toolchains-requirement-configurator",
threadSafe = true)
public class ToolchainMojo extends AbstractMojo {
private static final Object LOCK = new Object();

/**
*/
@Component

Check warning on line 51 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 51 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 51 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-25-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 51 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-8-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 51 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 51 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 51 in src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-8-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated
private ToolchainManagerPrivate toolchainManagerPrivate;

/**
Expand Down Expand Up @@ -144,9 +142,7 @@
getLog().info("Found matching toolchain for type " + type + ": " + tc);

// store matching toolchain to build context
synchronized (LOCK) {
toolchainManagerPrivate.storeToolchainToBuildContext(tc, session);
}
toolchainManagerPrivate.storeToolchainToBuildContext(tc, session);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 java.lang.reflect.Method;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.apache.maven.plugins.toolchain.jdk.ToolchainDiscoverer.VERSION;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class SelectJdkToolchainMojoTest {

private static Method matchesMethod;

@BeforeAll
static void setUp() throws Exception {
matchesMethod =
SelectJdkToolchainMojo.class.getDeclaredMethod("matches", String.class, String.class, String.class);
matchesMethod.setAccessible(true);
}

private boolean invokeMatches(String key, String reqVal, String tcVal) throws Exception {
return (boolean) matchesMethod.invoke(new SelectJdkToolchainMojo(), key, reqVal, tcVal);
}

@Test
void versionRangeShouldMatchToolchainVersion() throws Exception {
// reqVal is the user's requirement (e.g., version range), tcVal is the toolchain's provided version
assertTrue(invokeMatches(VERSION, "[11,17)", "11.0.1"));
}

@Test
void exactVersionShouldMatchToolchainVersion() throws Exception {
assertTrue(invokeMatches(VERSION, "11.0.1", "11.0.1"));
}

@Test
void versionRangeShouldRejectToolchainVersionOutsideRange() throws Exception {
assertFalse(invokeMatches(VERSION, "[11,17)", "17.0.1"));
}
}
Loading