Skip to content

Commit 6f68c1b

Browse files
author
Martin Weber
authored
Issue #249: sanitize existing source bundle manifest (#266)
* Issue #249: sanitize existing source bundle manifest Change-Id: Ie8d16185942228b730b0e143ea551918ed2614b6
1 parent 88f2a3e commit 6f68c1b

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/main/java/org/reficio/p2/bundler/impl/AquteBundler.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import java.io.File;
3333
import java.io.IOException;
34+
import java.util.Arrays;
3435
import java.util.jar.Attributes;
3536
import java.util.jar.Manifest;
3637

@@ -63,6 +64,7 @@ public AquteBundler(boolean pedantic, boolean ignoreBndErrors) {
6364
this.pedantic = pedantic;
6465
}
6566

67+
@Override
6668
public void execute(ArtifactBundlerRequest request, ArtifactBundlerInstructions instructions) {
6769
log().info("Executing Bundler:");
6870
try {
@@ -173,6 +175,7 @@ private Manifest getManifest(Jar jar) throws Exception {
173175
}
174176

175177
private void decorateSourceManifest(Manifest manifest, String name, String refrencedBundleSymbolicName, String symbolicName, String version) {
178+
sanitizeSourceManifest(manifest);
176179
Attributes attributes = manifest.getMainAttributes();
177180
attributes.putValue(Analyzer.BUNDLE_SYMBOLICNAME, symbolicName);
178181
attributes.putValue(ECLIPSE_SOURCE_BUNDLE, refrencedBundleSymbolicName + ";version=\"" + version + "\";roots:=\".\"");
@@ -186,6 +189,19 @@ private void decorateSourceManifest(Manifest manifest, String name, String refre
186189
attributes.putValue(AquteHelper.TOOL_KEY, AquteHelper.TOOL);
187190
}
188191

192+
/**
193+
* Removes the bundle manifest headers that incorrectly cause a source bundle being
194+
* resolved instead of its corresponding classes bundle.
195+
*/
196+
private void sanitizeSourceManifest(Manifest manifest) {
197+
Attributes attributes = manifest.getMainAttributes();
198+
if (!attributes.isEmpty()) {
199+
// note that header is of type Attributes.Name, hence we call header.toString()
200+
attributes.keySet().removeIf(header -> Arrays.asList(Analyzer.EXPORT_PACKAGE,
201+
Analyzer.EXPORT_SERVICE, Analyzer.PROVIDE_CAPABILITY ).contains(header.toString()));
202+
}
203+
}
204+
189205
private Logger log() {
190206
return Logger.getLog();
191207
}

src/test/integration/source-it/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
<source>true</source>
6262
<transitive>false</transitive>
6363
</artifact>
64+
65+
<artifact>
66+
<id>org.jboss.spec.javax.annotation:jboss-annotations-api_1.3_spec:2.0.1.Final</id>
67+
<source>true</source>
68+
<transitive>false</transitive>
69+
</artifact>
6470
</artifacts>
6571
</configuration>
6672

src/test/integration/source-it/validate.groovy

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import org.reficio.p2.utils.TestUtils as Util;
2727
// verify target
2828
File target = new File(basedir, 'target/repository/plugins')
2929
assert target.exists()
30-
assert target.listFiles().size() == 2
30+
assert target.listFiles().size() == 4
3131

3232
// verify number of artifacts
3333
def files = target.listFiles().collect { it.name }
@@ -51,3 +51,13 @@ assert Util.tool(source) == "p2-maven-plugin (reficio.org)"
5151
assert Util.eclipseSourceBundle(source) ==
5252
"org.mockito.mockito-core;version=\"1.9.0\";roots:=\".\"";
5353

54+
// verify that broken source bundle manifest gets sanitized
55+
sourceName = "org.jboss.spec.javax.annotation.jboss-annotations-api_1.3_spec.source_2.0.1.Final.jar"
56+
assert files.contains(sourceName)
57+
58+
Jar sourceSan = new Jar(new File(target, sourceName));
59+
assert Util.symbolicName(sourceSan) == "org.jboss.spec.javax.annotation.jboss-annotations-api_1.3_spec.source"
60+
assert Util.eclipseSourceBundle(sourceSan) != null
61+
assert Util.attr(sourceSan, "Export-Package") == null
62+
assert Util.attr(sourceSan, "Export-Service") == null
63+
assert Util.attr(sourceSan, "Provide-Capability") == null

0 commit comments

Comments
 (0)