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 1 commit
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
43 changes: 43 additions & 0 deletions biz.aQute.bndlib.tests/test/test/model/EETest.java
Expand Up @@ -2,6 +2,8 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;
import java.util.stream.Stream;
Expand Down Expand Up @@ -90,6 +92,47 @@ public void checkEEHasCompatible(EE ee) throws Exception {
assertThat(compatible).isNotEmpty();
}

@ParameterizedTest(name = "Validate valid release target foe EEs exist for {arguments}")
laeubi marked this conversation as resolved.
Show resolved Hide resolved
@ArgumentsSource(EEsArgumentsProvider.class)
@DisplayName("Validate each EEs has valid release target")
laeubi marked this conversation as resolved.
Show resolved Hide resolved
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 :
assertTrue(ee.getReleaseTarget()
.isEmpty());
laeubi marked this conversation as resolved.
Show resolved Hide resolved
break;
case JavaSE_1_6 :
assertEquals(6, ee.getReleaseTarget()
.getAsInt());
laeubi marked this conversation as resolved.
Show resolved Hide resolved
break;
case JavaSE_1_7 :
assertEquals(7, ee.getReleaseTarget()
.getAsInt());
laeubi marked this conversation as resolved.
Show resolved Hide resolved
break;
case JavaSE_1_8 :
case JavaSE_compact1_1_8 :
case JavaSE_compact2_1_8 :
case JavaSE_compact3_1_8 :
assertEquals(8, ee.getReleaseTarget()
.getAsInt());
laeubi marked this conversation as resolved.
Show resolved Hide resolved
break;

default :
assertEquals(ee.getCapabilityVersion()
.getMajor(),
ee.getReleaseTarget()
.getAsInt());
laeubi marked this conversation as resolved.
Show resolved Hide resolved
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 > 8) {
laeubi marked this conversation as resolved.
Show resolved Hide resolved
laeubi marked this conversation as resolved.
Show resolved Hide resolved
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;