Skip to content

Commit

Permalink
Add EE.getRelease() method
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi committed Aug 24, 2022
1 parent 74b8924 commit 124db32
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
43 changes: 43 additions & 0 deletions biz.aQute.bndlib.tests/test/test/model/EETest.java
Original file line number Diff line number Diff line change
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}")
@ArgumentsSource(EEsArgumentsProvider.class)
@DisplayName("Validate each EEs has valid release target")
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());
break;
case JavaSE_1_6 :
assertEquals(6, ee.getReleaseTarget()
.getAsInt());
break;
case JavaSE_1_7 :
assertEquals(7, ee.getReleaseTarget()
.getAsInt());
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());
break;

default :
assertEquals(ee.getCapabilityVersion()
.getMajor(),
ee.getReleaseTarget()
.getAsInt());
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
Original file line number Diff line number Diff line change
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) {
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@Version("4.1.0")
@Version("4.2.0")
package aQute.bnd.build.model;

import org.osgi.annotation.versioning.Version;

0 comments on commit 124db32

Please sign in to comment.