Skip to content

Commit 290c9f4

Browse files
committed
reuse doSnapshot method in P2Export + test
this allows to that the features use the same versioning qualifier logic as the normal bundles Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
1 parent f90f5b0 commit 290c9f4

File tree

7 files changed

+41
-38
lines changed

7 files changed

+41
-38
lines changed

biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -470,38 +470,12 @@ public void analyze() throws Exception {
470470
String version = getProperty(BUNDLE_VERSION);
471471
if (version != null) {
472472
version = cleanupVersion(version);
473-
version = doSnapshot(version);
473+
version = doSnapshot(version, getProperty(Constants.SNAPSHOT));
474474
setProperty(BUNDLE_VERSION, version);
475475
}
476476
}
477477

478-
private String doSnapshot(String version) {
479-
String snapshot = getProperty(SNAPSHOT);
480-
if (snapshot == null) {
481-
return version;
482-
}
483-
if (snapshot.isEmpty()) {
484-
snapshot = null;
485-
}
486-
Version v = Version.parseVersion(version);
487-
String q = v.getQualifier();
488-
if (q == null) {
489-
return version;
490-
}
491-
if (q.equals("SNAPSHOT")) {
492-
q = snapshot;
493-
} else if (q.endsWith("-SNAPSHOT")) {
494-
int end = q.length() - "SNAPSHOT".length();
495-
if (snapshot == null) {
496-
q = q.substring(0, end - 1);
497-
} else {
498-
q = q.substring(0, end) + snapshot;
499-
}
500-
} else {
501-
return version;
502-
}
503-
return new Version(v.getMajor(), v.getMinor(), v.getMicro(), q).toString();
504-
}
478+
505479

506480
public void cleanupVersion(Packages packages, String defaultVersion) {
507481
cleanupVersion(packages, defaultVersion, "external");
@@ -2267,6 +2241,33 @@ private static boolean isIdentical(Resource a, Resource b) {
22672241
}
22682242
}
22692243

2244+
public static String doSnapshot(String version, String snapshot) {
2245+
2246+
if (snapshot == null) {
2247+
return version;
2248+
}
2249+
if (snapshot.isEmpty()) {
2250+
snapshot = null;
2251+
}
2252+
Version v = Version.parseVersion(version);
2253+
String q = v.getQualifier();
2254+
if (q == null) {
2255+
return version;
2256+
}
2257+
if (q.equals("SNAPSHOT")) {
2258+
q = snapshot;
2259+
} else if (q.endsWith("-SNAPSHOT")) {
2260+
int end = q.length() - "SNAPSHOT".length();
2261+
if (snapshot == null) {
2262+
q = q.substring(0, end - 1);
2263+
} else {
2264+
q = q.substring(0, end) + snapshot;
2265+
}
2266+
} else {
2267+
return version;
2268+
}
2269+
return new Version(v.getMajor(), v.getMinor(), v.getMicro(), q).toString();
2270+
}
22702271

22712272

22722273
}

biz.aQute.repository/src/aQute/p2/export/P2Export.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ private BundleId getFeatureId(Processor definition) {
959959
}
960960
}
961961

962+
version = Builder.doSnapshot(version, definition.get(Constants.SNAPSHOT));
962963
return getBundleId(featureName, version);
963964
}
964965

biz.aQute.repository/test/aQute/p2/export/P2PublisherTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,29 @@ void testBasic() throws Exception {
5555
Jar content = new Jar("content.jar", jar.getResource("content.jar")
5656
.openInputStream());
5757
Jar featureMain = new Jar("feature.jar",
58-
jar.getResource("features/bndtools.main.feature_7.0.0.0000-SNAPSHOT.jar")
58+
jar.getResource("features/bndtools.main.feature_7.0.0.0000-RC1.jar")
5959
.openInputStream());
6060
Jar featurePde = new Jar("feature.jar",
61-
jar.getResource("features/bndtools.pde.feature_7.0.0.0000-SNAPSHOT.jar")
61+
jar.getResource("features/bndtools.pde.feature_7.0.0.0000-RC1.jar")
6262
.openInputStream())) {
6363

6464
Resource metainf = jar.getResource("META-INF/MANIFEST.MF");
6565
assertNotNull(metainf);
6666
// notice the timestamp portion 0000 which should be in
6767
// MANIFEST.MF
68-
assertEquals("7.0.0.0000-SNAPSHOT", jar.getManifest()
68+
assertEquals("7.0.0.0000-RC1", jar.getManifest()
6969
.getMainAttributes()
7070
.getValue(Constants.BUNDLE_VERSION));
7171

7272
// but in pom.properties we want just
73-
// 7.0.0-SNAPSHOT (without the timestamp 0000 portion)
73+
// 7.0.0-RC1(without the timestamp 0000 portion)
7474
Resource pomproperties = jar.getResource("META-INF/maven/org.bndtools/org.bndtools.p2/pom.properties");
7575
assertNotNull(pomproperties);
7676
try (InputStream is = pomproperties.openInputStream()) {
7777
String pomprops = new String(is.readAllBytes());
7878
assertThat(pomprops).contains("groupId=org.bndtools");
7979
assertThat(pomprops).contains("artifactId=org.bndtools.p2");
80-
assertThat(pomprops).contains("version=7.0.0-SNAPSHOT");
80+
assertThat(pomprops).contains("version=7.0.0-RC1");
8181
}
8282

8383
InputStream xmlArtifactsIs = artifacts.getResource("artifacts.xml")

biz.aQute.repository/testdata/p2-publish/ws-1/cnf/build.bnd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
locations ='${fileuri;${workspace}/cnf/repo/index.xml}'; \
44
name ='P2'
55

6-
Bundle-Version 800
6+
-snapshot: RC1
7+
base.version: 7.0.0.0000
8+
Bundle-Version: ${base.version}-SNAPSHOT
79

810

911
-groupid: org.bndtools

biz.aQute.repository/testdata/p2-publish/ws-1/p1/expected-feature.main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<feature id="bndtools.main.feature" version="7.0.0.0000-SNAPSHOT" label="Bndtools" provider-name="bnd">
1+
<feature id="bndtools.main.feature" version="7.0.0.0000-RC1" label="Bndtools" provider-name="bnd">
22
<description url="https://bnd.bndtools.org/"><![CDATA[OSGi Development Tools for Eclipse based on bnd.]]></description>
33
<copyright><![CDATA[Copyright bndtools]]></copyright>
44
<license url="https://opensource.org/licenses/Apache-2.0"><![CDATA[SPDX-License-Identifier: (Apache-2.0 OR EPL-2.0)

biz.aQute.repository/testdata/p2-publish/ws-1/p1/expected-feature.pde.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<feature id="bndtools.pde.feature" version="7.0.0.0000-SNAPSHOT" label="Bndtools PDE" provider-name="bnd">
1+
<feature id="bndtools.pde.feature" version="7.0.0.0000-RC1" label="Bndtools PDE" provider-name="bnd">
22
<description url="https://bnd.bndtools.org/"><![CDATA[PDE integration for Bndtools]]></description>
33
<copyright><![CDATA[Copyright bndtools]]></copyright>
44
<license url="https://opensource.org/licenses/Apache-2.0"><![CDATA[Simple license description]]></license>
@@ -7,7 +7,7 @@
77
<discovery url="https://bndtools.jfrog.io/bndtools/update-latest" label="Bndtools Update Site"/>
88
</url>
99
<requires>
10-
<import feature="bndtools.main.feature.feature.group" version="7.0.0.0000-SNAPSHOT" match="perfect"/>
10+
<import feature="bndtools.main.feature.feature.group" version="7.0.0.0000-RC1" match="perfect"/>
1111
<import feature="org.eclipse.pde.feature.group" version="3.14.1300" match="equivalent"/>
1212
</requires>
1313
<plugin id="bndtools.pde" version="[7.0.0.202306291715-SNAPSHOT,7.0.0.202306291715-SNAPSHOT]" unpack="false"/>

biz.aQute.repository/testdata/p2-publish/ws-1/p1/features.bnd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Bundle-SymbolicName: org.bndtools.p2
2-
Bundle-Version 7.0.0.0000-SNAPSHOT
32
Bundle-License: \
43
ASL-2.0;\
54
file="license.txt";\

0 commit comments

Comments
 (0)