|
19 | 19 | import static org.junit.Assert.assertNull; |
20 | 20 | import static org.junit.Assert.assertTrue; |
21 | 21 |
|
| 22 | +import java.io.File; |
22 | 23 | import java.net.URI; |
23 | 24 | import java.util.Arrays; |
24 | 25 | import java.util.List; |
|
28 | 29 | import java.util.jar.Attributes; |
29 | 30 |
|
30 | 31 | import org.eclipse.core.runtime.IStatus; |
| 32 | +import org.eclipse.equinox.frameworkadmin.BundleInfo; |
31 | 33 | import org.eclipse.osgi.util.ManifestElement; |
32 | 34 | import org.eclipse.pde.core.target.ITargetLocation; |
33 | 35 | import org.eclipse.pde.core.target.TargetBundle; |
|
37 | 39 | import org.osgi.framework.Version; |
38 | 40 | import org.osgi.framework.VersionRange; |
39 | 41 |
|
| 42 | +import aQute.bnd.osgi.Jar; |
| 43 | + |
40 | 44 | public class OSGiMetadataGenerationTest extends AbstractMavenTargetTest { |
41 | 45 |
|
42 | 46 | @Test |
@@ -286,6 +290,44 @@ public void testNonOSGiArtifact_missingArtifactGenerate_defaultInstructions() th |
286 | 290 | assertNull(sourceAttributes.getValue(Constants.DYNAMICIMPORT_PACKAGE)); |
287 | 291 | } |
288 | 292 |
|
| 293 | + @Test |
| 294 | + public void testConditionalPackage() throws Exception { |
| 295 | + ITargetLocation target = resolveMavenTarget( |
| 296 | + """ |
| 297 | + <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="false" label="Maven-archetype" missingManifest="generate" type="Maven"> |
| 298 | + <dependencies> |
| 299 | + <dependency> |
| 300 | + <groupId>org.apache.maven.archetype</groupId> |
| 301 | + <artifactId>archetype-common</artifactId> |
| 302 | + <version>3.3.1</version> |
| 303 | + <type>jar</type> |
| 304 | + </dependency> |
| 305 | + </dependencies> |
| 306 | + <instructions><![CDATA[ |
| 307 | + Bundle-Name: Bundle in Test from artifact ${mvnGroupId}:${mvnArtifactId}:${mvnVersion}:${mvnClassifier} |
| 308 | + version: ${version_cleanup;${mvnVersion}} |
| 309 | + Bundle-SymbolicName: m2e.custom.test.wrapped.${mvnArtifactId} |
| 310 | + Bundle-Version: ${version} |
| 311 | + Import-Package: * |
| 312 | + Export-Package: org.apache.maven.archetype;version="${version}";-noimport:=true |
| 313 | + -conditionalpackage: org.apache.commons.* |
| 314 | + ]]></instructions> |
| 315 | + </location> |
| 316 | + """); |
| 317 | + assertStatusOk(getTargetStatus(target)); |
| 318 | + TargetBundle[] bundles = target.getBundles(); |
| 319 | + for (TargetBundle bundle : bundles) { |
| 320 | + BundleInfo bundleInfo = bundle.getBundleInfo(); |
| 321 | + File file = new File(bundleInfo.getLocation()); |
| 322 | + try (Jar jar = new Jar(file)) { |
| 323 | + Set<String> resources = jar.getResources().keySet(); |
| 324 | + assertTrue("Conditional package org.apache.commons.* not included.", |
| 325 | + resources.stream().anyMatch(s -> s.startsWith("org/apache/commons/"))); |
| 326 | + } |
| 327 | + ; |
| 328 | + } |
| 329 | + } |
| 330 | + |
289 | 331 | @Test |
290 | 332 | public void testNonOSGiArtifact_missingArtifactGenerate_customInstructions() throws Exception { |
291 | 333 | ITargetLocation target = resolveMavenTarget( |
|
0 commit comments