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

Add EE.getReleaseTarget() method #5358

Merged
merged 2 commits into from Aug 25, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions biz.aQute.bndlib.tests/test/test/model/EETest.java
Expand Up @@ -90,6 +90,41 @@ public void checkEEHasCompatible(EE ee) throws Exception {
assertThat(compatible).isNotEmpty();
}

@ParameterizedTest(name = "Validate release target for {arguments}")
@ArgumentsSource(EEsArgumentsProvider.class)
@DisplayName("Validate release target for each EE")
public void checkEEHasValidRelease(EE ee) throws Exception {
switch (ee) {
case OSGI_Minimum_1_0 :
case OSGI_Minimum_1_1 :
case OSGI_Minimum_1_2 :
case J2SE_1_2 :
case J2SE_1_3 :
case J2SE_1_4 :
case J2SE_1_5 :
case JRE_1_1 :
assertThat(ee.getReleaseTarget()).isEmpty();
break;
case JavaSE_1_6 :
assertThat(ee.getReleaseTarget()).hasValue(6);
break;
case JavaSE_1_7 :
assertThat(ee.getReleaseTarget()).hasValue(7);
break;
case JavaSE_1_8 :
case JavaSE_compact1_1_8 :
case JavaSE_compact2_1_8 :
case JavaSE_compact3_1_8 :
assertThat(ee.getReleaseTarget()).hasValue(8);
break;

default :
assertThat(ee.getReleaseTarget()).hasValue(ee.getCapabilityVersion()
.getMajor());
break;
}
}

@ParameterizedTest(name = "Validate Packages exist for {arguments}")
@ArgumentsSource(EEsArgumentsProvider.class)
@DisplayName("Validate Packages exist for each EE")
Expand Down
16 changes: 16 additions & 0 deletions biz.aQute.bndlib/src/aQute/bnd/build/model/EE.java
Expand Up @@ -6,6 +6,7 @@
import java.util.Collections;
import java.util.EnumSet;
import java.util.Optional;
import java.util.OptionalInt;

import aQute.bnd.exceptions.Exceptions;
import aQute.bnd.header.Parameters;
Expand Down Expand Up @@ -145,6 +146,21 @@ public Version getCapabilityVersion() {
return capabilityVersion;
}

/**
* @return the java release target corresponding to this EE
*/
public OptionalInt getReleaseTarget() {
Version version = getCapabilityVersion();
int major = version.getMajor();
if (major > 1) {
return OptionalInt.of(major);
}
if (major == 1 && version.getMinor() > 5) {
return OptionalInt.of(version.getMinor());
}
return OptionalInt.empty();
}

public static Optional<EE> highestFromTargetVersion(String targetVersion) {
Version version = Optional.of(targetVersion)
.map(Analyzer::cleanupVersion)
Expand Down
@@ -1,4 +1,4 @@
@Version("4.1.0")
@Version("4.2.0")
package aQute.bnd.build.model;

import org.osgi.annotation.versioning.Version;