Skip to content
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

[SUREFIRE-2245] Upgrade to Parent 42 and Maven 3.6.3 #737

Merged
merged 1 commit into from
Jun 4, 2024
Merged
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
2 changes: 1 addition & 1 deletion maven-failsafe-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-shadefire</artifactId>
<version>3.2.2</version>
<version>3.2.5</version>
<!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
</dependency>
</dependencies>
Expand Down
9 changes: 4 additions & 5 deletions maven-surefire-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
<!-- tha same version as in Maven 3.2.5 -->
<version>1.0.0.v20140518</version>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
<version>${resolverVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
Expand Down Expand Up @@ -154,7 +153,7 @@
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-shadefire</artifactId>
<version>3.2.2</version>
<version>3.2.5</version>
<!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.util.ArrayList;
Expand Down Expand Up @@ -139,8 +138,6 @@
import static org.apache.maven.surefire.api.booter.ProviderParameterNames.INCLUDE_JUNIT5_ENGINES_PROP;
import static org.apache.maven.surefire.api.suite.RunResult.failure;
import static org.apache.maven.surefire.api.suite.RunResult.noTestsRun;
import static org.apache.maven.surefire.api.util.ReflectionUtils.invokeMethodWithArray;
import static org.apache.maven.surefire.api.util.ReflectionUtils.tryGetMethod;
import static org.apache.maven.surefire.booter.Classpath.emptyClasspath;
import static org.apache.maven.surefire.booter.SystemUtils.endsWithJavaPath;
import static org.apache.maven.surefire.booter.SystemUtils.isBuiltInJava9AtLeast;
Expand Down Expand Up @@ -935,31 +932,17 @@ protected final PluginConsoleLogger getConsoleLogger() {
return consoleLogger;
}

private static <T extends ToolchainManager> Toolchain getToolchainMaven33x(
Class<T> toolchainManagerType, T toolchainManager, MavenSession session, Map<String, String> toolchainArgs)
throws MojoFailureException {
Method getToolchainsMethod =
tryGetMethod(toolchainManagerType, "getToolchains", MavenSession.class, String.class, Map.class);
if (getToolchainsMethod != null) {
//noinspection unchecked
List<Toolchain> tcs =
invokeMethodWithArray(toolchainManager, getToolchainsMethod, session, "jdk", toolchainArgs);
if (tcs.isEmpty()) {
throw new MojoFailureException(
"Requested toolchain specification did not match any configured toolchain: " + toolchainArgs);
}
return tcs.get(0);
}
return null;
}

// TODO remove the part with ToolchainManager lookup once we depend on
// 3.0.9 (have it as prerequisite). Define as regular component field then.
private Toolchain getToolchain() throws MojoFailureException {
Toolchain tc = null;

if (getJdkToolchain() != null) {
tc = getToolchainMaven33x(ToolchainManager.class, getToolchainManager(), getSession(), getJdkToolchain());
List<Toolchain> tcs = getToolchainManager().getToolchains(getSession(), "jdk", getJdkToolchain());
if (tcs.isEmpty()) {
throw new MojoFailureException(
"Requested toolchain specification did not match any configured toolchain: "
+ getJdkToolchain());
}
tc = tcs.get(0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guys, please check wether this is correct logically...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks similar to reflection way

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but simply hides code complexity. It is has no further use. I wouldn't necessarily delete it.

}

if (tc == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.maven.toolchain.ToolchainManager;
import org.apache.maven.toolchain.java.DefaultJavaToolChain;
import org.codehaus.plexus.logging.Logger;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand All @@ -42,17 +43,14 @@
import org.powermock.modules.junit4.PowerMockRunner;

import static java.io.File.separatorChar;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static junit.framework.TestCase.assertNull;
import static org.apache.maven.surefire.booter.SystemUtils.toJdkHomeFromJre;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.powermock.reflect.Whitebox.invokeMethod;

Expand All @@ -67,28 +65,18 @@ public class AbstractSurefireMojoToolchainsTest {
public final ExpectedException e = ExpectedException.none();

/**
* Ensure that we use the toolchain found by getToolchainMaven33x()
* Ensure that we use the toolchain found by getToolchain()
* when the jdkToolchain parameter is set.
*/
@Test
public void shouldCallMaven33xMethodWhenSpecSet() throws Exception {
public void shouldCallMethodWhenSpecSet() throws Exception {
AbstractSurefireMojoTest.Mojo mojo = new AbstractSurefireMojoTest.Mojo();
Toolchain expectedFromMaven33Method = mock(Toolchain.class);
MockToolchainManager toolchainManager = new MockToolchainManager(null, null);
Toolchain expectedMethod = mock(Toolchain.class);
MockToolchainManager toolchainManager = new MockToolchainManager(expectedMethod, null);
mojo.setToolchainManager(toolchainManager);
mojo.setJdkToolchain(singletonMap("version", "1.8"));

mockStatic(AbstractSurefireMojo.class);
when(
AbstractSurefireMojo.class,
"getToolchainMaven33x",
ToolchainManager.class,
toolchainManager,
mojo.getSession(),
mojo.getJdkToolchain())
.thenReturn(expectedFromMaven33Method);
Toolchain actual = invokeMethod(mojo, "getToolchain");
assertThat(actual).isSameAs(expectedFromMaven33Method);
assertThat(actual).isSameAs(expectedMethod);
}

/**
Expand All @@ -106,39 +94,19 @@ public void shouldFallthroughToBuildContextWhenNoSpecSet() throws Exception {
assertThat(actual).isSameAs(expectedFromContext);
}

@Test
public void shouldReturnNoToolchainInMaven32() throws Exception {
Toolchain toolchain = invokeMethod(
AbstractSurefireMojo.class,
"getToolchainMaven33x",
MockToolchainManagerMaven32.class,
new MockToolchainManagerMaven32(null),
mock(MavenSession.class),
emptyMap());
assertNull(toolchain);
}

// TODO Is this still required?
@Test(expected = MojoFailureException.class)
public void shouldThrowMaven33xToolchain() throws Exception {
invokeMethod(
AbstractSurefireMojo.class,
"getToolchainMaven33x",
MockToolchainManager.class,
new MockToolchainManager(null, null),
mock(MavenSession.class),
emptyMap());
@Ignore
public void shouldThrowToolchain() throws Exception {
invokeMethod(AbstractSurefireMojo.class, "getToolchain");
}

// TODO Is this still required?
@Test
public void shouldGetMaven33xToolchain() throws Exception {
@Ignore
public void shouldGetToolchain() throws Exception {
Toolchain expected = mock(Toolchain.class);
Toolchain actual = invokeMethod(
AbstractSurefireMojo.class,
"getToolchainMaven33x",
MockToolchainManager.class,
new MockToolchainManager(expected, null),
mock(MavenSession.class),
emptyMap());
Toolchain actual = invokeMethod(AbstractSurefireMojo.class, "getToolchain");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have disabled a few tests because they do not work, but I believe that they are redundant now because we don't use any reflection. I am inclined to delete all disabled ones. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete it


assertThat(actual).isSameAs(expected);
}
Expand Down Expand Up @@ -257,34 +225,24 @@ public void shouldFailWithWrongJvmExecPath() throws Exception {
/**
* Mocks a ToolchainManager
*/
public static final class MockToolchainManager extends MockToolchainManagerMaven32 {
public static final class MockToolchainManager implements ToolchainManager {

private final Toolchain specToolchain;
private final Toolchain buildContextToolchain;

public MockToolchainManager(Toolchain specToolchain, Toolchain buildContextToolchain) {
super(buildContextToolchain);
this.specToolchain = specToolchain;
}

public List<Toolchain> getToolchains(MavenSession session, String type, Map<String, String> requirements) {
return specToolchain == null ? Collections.<Toolchain>emptyList() : singletonList(specToolchain);
}
}

/**
* Mocks an older version that does not implement getToolchains()
* returns provided toolchain
*/
public static class MockToolchainManagerMaven32 implements ToolchainManager {

private final Toolchain buildContextToolchain;

public MockToolchainManagerMaven32(Toolchain buildContextToolchain) {
this.buildContextToolchain = buildContextToolchain;
}

@Override
public Toolchain getToolchainFromBuildContext(String type, MavenSession context) {
return buildContextToolchain;
}

@Override
public List<Toolchain> getToolchains(MavenSession session, String type, Map<String, String> requirements) {
return specToolchain == null ? Collections.<Toolchain>emptyList() : singletonList(specToolchain);
}
}
}
2 changes: 1 addition & 1 deletion maven-surefire-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-shadefire</artifactId>
<version>3.2.2</version>
<version>3.2.5</version>
<!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
</dependency>
</dependencies>
Expand Down
21 changes: 10 additions & 11 deletions maven-surefire-report-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@

<properties>
<doxiaVersion>1.12.0</doxiaVersion>
<aetherVersion>1.0.0.v20140518</aetherVersion>
</properties>

<dependencies>
Expand Down Expand Up @@ -124,21 +123,21 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-impl</artifactId>
<version>${aetherVersion}</version>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-impl</artifactId>
<version>${resolverVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>${aetherVersion}</version>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
<version>${resolverVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-wagon</artifactId>
<version>${aetherVersion}</version>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-wagon</artifactId>
<version>${resolverVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -187,7 +186,7 @@
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-shadefire</artifactId>
<version>3.2.2</version>
<version>3.2.5</version>
<!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
</dependency>
</dependencies>
Expand Down
9 changes: 5 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven-parent</artifactId>
<version>41</version>
<version>42</version>
</parent>

<groupId>org.apache.maven.surefire</groupId>
Expand Down Expand Up @@ -88,7 +88,8 @@

<properties>
<javaVersion>8</javaVersion>
<mavenVersion>3.2.5</mavenVersion>
<mavenVersion>3.6.3</mavenVersion>
<resolverVersion>1.4.1</resolverVersion>
<commonsLang3Version>3.14.0</commonsLang3Version>
<commonsCompress>1.26.1</commonsCompress>
<commonsIoVersion>2.16.1</commonsIoVersion>
Expand Down Expand Up @@ -358,7 +359,7 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.2</version>
<version>3.2.5</version>
<!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
<configuration>
<!-- NOTE: Be sure to isolate the Surefire version under test from the version running the tests! -->
Expand Down Expand Up @@ -505,7 +506,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.2.2</version>
<version>3.2.5</version>
<!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
</plugin>
</plugins>
Expand Down
2 changes: 1 addition & 1 deletion surefire-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-shadefire</artifactId>
<version>3.2.2</version>
<version>3.2.5</version>
<!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion surefire-booter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-shadefire</artifactId>
<version>3.2.2</version>
<version>3.2.5</version>
<!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion surefire-extensions-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-shadefire</artifactId>
<version>3.2.2</version>
<version>3.2.5</version>
<!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion surefire-grouper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-shadefire</artifactId>
<version>3.2.2</version>
<version>3.2.5</version>
<!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
</dependency>
</dependencies>
Expand Down
Loading
Loading