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

Fixed #421 - EnabledForMavenVersion/DisabledForMavenVersion handling … #422

Merged
merged 1 commit into from
Dec 24, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
:issue-413: https://github.com/khmarbaise/maven-it-extension/issues/413[Fixed #413]
:issue-414: https://github.com/khmarbaise/maven-it-extension/issues/414[Fixed #414]
:issue-417: https://github.com/khmarbaise/maven-it-extension/issues/417[Fixed #417]
:issue-421: https://github.com/khmarbaise/maven-it-extension/issues/421[Fixed #421]
:issue-??: https://github.com/khmarbaise/maven-it-extension/issues/??[Fixed #??]

:release_0_13_0: https://github.com/khmarbaise/maven-it-extension/milestone/13
Expand All @@ -87,6 +88,12 @@
get `deprecated warnings` during the compilation.
* {issue-379} - Deprecated `@MavenDebug`; Replace the usage with `@MavenVerbose`.
`@MavenDebug` will be removed with release 0.14.0.
* {issue-421} - Deprecated the `MavenVersion#UNKNOWN`. If you have used it somewhere you will get a deprecation WARNING
during compilation. That should be replaced with `MavenVersion#ANY`. (Usually you shouldn't have used
that anyway). `MavenVersion#UNKNOWN` will be removed with release 0.14.0.
Also all Maven Version for `M3_0_5` up to `M3_5_4` have been marked deprecated to indicate that those
versions are very old and shouldn't be used anymore; Not even in tests (You should upgrade your Maven
version)

*Reporter of this release*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@

import com.soebes.itf.jupiter.extension.MavenJupiterExtension;
import com.soebes.itf.jupiter.extension.MavenProfile;
import com.soebes.itf.jupiter.extension.MavenProject;
import com.soebes.itf.jupiter.extension.MavenTest;
import com.soebes.itf.jupiter.extension.condition.EnabledForMavenVersion;
import com.soebes.itf.jupiter.maven.MavenExecutionResult;
import org.junit.jupiter.api.Nested;

import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat;
import static com.soebes.itf.jupiter.extension.MavenVersion.M3_9;
import static com.soebes.itf.jupiter.extension.MavenVersion.M4_0;

@MavenJupiterExtension
class ProfileIT {
Expand Down Expand Up @@ -87,13 +92,28 @@ void profile_1_2_3(MavenExecutionResult result) {
.warn().containsExactly("Message for Profile 1", "Message for Profile 2", "Message for Profile 3");
}

@MavenTest
@Nested
@MavenProject
@MavenProfile("unknown-profile")
void unknown_profile(MavenExecutionResult result) {
assertThat(result)
.isSuccessful()
.out()
.warn().contains("The requested profile \"unknown-profile\" could not be activated because it does not exist.");
class UnknownProfile {
@MavenTest
@EnabledForMavenVersion(value = {M3_9})
void unknown_profile_maven_3_9(MavenExecutionResult result) {
assertThat(result)
.isSuccessful()
.out()
.warn()
.contains("The requested profile \"unknown-profile\" could not be activated because it does not exist.");
}
@MavenTest
@EnabledForMavenVersion(value = {M4_0})
void unknown_profile_maven_4_0(MavenExecutionResult result) {
assertThat(result)
.isFailure()
.out()
.error()
.contains("The requested profiles [unknown-profile] could not be activated or deactivated because they do not exist. -> [Help 1]");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

import org.apiguardian.api.API;

import java.util.stream.Stream;

import static com.soebes.itf.jupiter.extension.MavenVersionComparator.of;
import static com.soebes.itf.jupiter.extension.Preconditions.requireNotEmpty;
import static com.soebes.itf.jupiter.extension.Preconditions.requireNotNull;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
Expand All @@ -32,125 +31,135 @@
*/
@API(status = EXPERIMENTAL, since = "0.1.0")
public enum MavenVersion {
UNKNOWN("UNKOWN"), //TODO: Need to reconsider?
/**
* @deprecated Please use {@link #ANY} instead. Will be removed with Release 0.14.0
*/
@Deprecated
UNKNOWN(of()),
/**
* Represent any Maven version.
*/
ANY(of()),
/**
* Apache Maven Version 3.0.X
* Do not use those, because Maven 3.0.X is very old!
* Do not use them anymore, because Maven 3.0.X is very old!
*/
@Deprecated
M3_0("3.0"),
M3_0(of(3,0)),
@Deprecated
M3_0_5("3.0.5"),
M3_0_5(of(3,0,5)),
/**
* Apache Maven Version 3.2.X
* Apache Maven Version 3.1.X
* Do not use them anymore, because Maven 3.0.X is very old!
*/
@Deprecated
M3_1("3.1"),
M3_1(of(3,1)),
@Deprecated
M3_1_0("3.1.0"),
M3_1_0(of(3,1,0)),
@Deprecated
M3_1_1("3.1.1"),
M3_1_1(of(3,1,1)),
/**
* Apache Maven Version 3.2.X
* Do not use them anymore, because Maven 3.0.X is very old!
*/
@Deprecated
M3_2("3.2"),
M3_2(of(3,2)),
@Deprecated
M3_2_1("3.2.1"),
M3_2_1(of(3,2,1)),
@Deprecated
M3_2_2("3.2.2"),
M3_2_2(of(3,2,2)),
@Deprecated
M3_2_3("3.2.3"),
M3_2_3(of(3,2,3)),
@Deprecated
M3_2_5("3.2.5"),
M3_2_5(of(3,2,5)),
/**
* Apache Maven Version 3.3.X
* Do not use them anymore, because Maven 3.0.X is very old!
*/
@Deprecated
M3_3("3.3"),
M3_3(of(3,3)),
@Deprecated
M3_3_1("3.3.1"),
M3_3_1(of(3,3,1)),
@Deprecated
M3_3_3("3.3.3"),
M3_3_3(of(3,3,3)),
@Deprecated
M3_3_9("3.3.9"),
M3_3_9(of(3,3,9)),
/**
* Apache Maven Version 3.5.X
* Do not use them anymore, because Maven 3.0.X is very old!
*/
@Deprecated
M3_5("3.5"),
M3_5(of(3,5)),
@Deprecated
M3_5_0("3.5.0"),
M3_5_0(of(3,5,0)),
@Deprecated
M3_5_2("3.5.2"),
M3_5_2(of(3,5,2)),
@Deprecated
M3_5_3("3.5.3"),
M3_5_3(of(3,5,3)),
@Deprecated
M3_5_4("3.5.4"),
M3_5_4(of(3,5,4)),
/**
* Apache Maven Version 3.6.X
* Do not use them anymore, because Maven 3.0.X is very old!
*/
M3_6("3.6"),
M3_6_0("3.6.0"),
M3_6_1("3.6.1"),
M3_6_2("3.6.2"),
M3_6_3("3.6.3"),
M3_6(of(3,6)),
M3_6_0(of(3,6,0)),
M3_6_1(of(3,6,1)),
M3_6_2(of(3,6,2)),
M3_6_3(of(3,6,3)),
/**
* Apache Maven Version 3.8.X
*/
M3_8("3.8"),
M3_8_1("3.8.1"),
M3_8_2("3.8.2"),
M3_8_3("3.8.3"),
M3_8_4("3.8.4"),
M3_8_5("3.8.5"),
M3_8_6("3.8.6"),
M3_8_7("3.8.7"),
M3_8_8("3.8.8"),
M3_8(of(3,8)),
M3_8_1(of(3,8,1)),
M3_8_2(of(3,8,2)),
M3_8_3(of(3,8,3)),
M3_8_4(of(3,8,4)),
M3_8_5(of(3,8,5)),
M3_8_6(of(3,8,6)),
M3_8_7(of(3,8,7)),
M3_8_8(of(3,8,8)),
/**
* Apache Maven Version 3.9.X
*/
M3_9("3.9"),
M3_9_0("3.9.0"),
M3_9_1("3.9.1"),
M3_9_2("3.9.2"),
M3_9_3("3.9.3"),
M3_9_4("3.9.4"),
M3_9_5("3.9.5"),
M3_9_6("3.9.6"),
M3_9(of(3,9)),
M3_9_0(of(3,9,0)),
M3_9_1(of(3,9,1)),
M3_9_2(of(3,9,2)),
M3_9_3(of(3,9,3)),
M3_9_4(of(3,9,4)),
M3_9_5(of(3,9,5)),
M3_9_6(of(3,9,6)),
/**
* Apache Maven Version 4.0.X
*/
M4_0("4.0"),
M4_0_0("4.0.0"),
M4_0_1("4.0.1");
M4_0(of(4,0)),
M4_0_0(of(4,0,0)),
M4_0_1(of(4,0,1));

private static final MavenVersion CURRENT_MAVEN_VERSION = determineCurrentVersion();
private static final MavenVersionComparator CURRENT_MAVEN_VERSION = determineCurrentVersion();

private final String versionString;
private final MavenVersionComparator versionComparator;

MavenVersion(String versionString) {
this.versionString = versionString;
MavenVersion(MavenVersionComparator versionComparator) {
this.versionComparator = versionComparator;
}

private static MavenVersion determineCurrentVersion() {
private static MavenVersionComparator determineCurrentVersion() {
String currentVersion = requireNotNull(System.getProperty("maven.version"), "JVM system property 'maven.version' is empty.");
requireNotEmpty(currentVersion, "JVM system property 'maven.version' is empty. The maven version can not being detected.");
return Stream.of(values())
.filter(mavenVersion -> mavenVersion.getVersionString().equals(currentVersion))
.findFirst()
.orElseGet(() -> MavenVersion.UNKNOWN);
return MavenVersionParser.parseVersion(currentVersion);
}

/**
* @return {@code true} if <em>this</em> {@link MavenVersion} is known to be the Maven version for the currently being
* executed Maven version.
*/
public boolean isCurrentVersion() {
return this == CURRENT_MAVEN_VERSION;
return this.getVersion().compareTo(CURRENT_MAVEN_VERSION) == 0;
}

public String getVersionString() {
return versionString;
public MavenVersionComparator getVersion() {
return versionComparator;
}
}
Loading