use of org.apache.maven.shared.dependency.graph.DependencyNode in project felix by apache.
the class BlueprintComponentTest method test.
protected void test(String mode) throws Exception {
MavenProjectStub project = new MavenProjectStub() {
private final List resources = new ArrayList();
@Override
public void addResource(Resource resource) {
resources.add(resource);
}
@Override
public List getResources() {
return resources;
}
@Override
public File getBasedir() {
return new File("target/tmp/basedir");
}
};
project.setGroupId("group");
project.setArtifactId("artifact");
project.setVersion("1.1.0.0");
VersionRange versionRange = VersionRange.createFromVersion(project.getVersion());
ArtifactHandler artifactHandler = new DefaultArtifactHandler("jar");
Artifact artifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), versionRange, null, "jar", null, artifactHandler);
project.setArtifact(artifact);
ProjectBuilderConfiguration projectBuilderConfiguration = new DefaultProjectBuilderConfiguration();
projectBuilderConfiguration.setLocalRepository(null);
project.setProjectBuilderConfiguration(projectBuilderConfiguration);
Resource r = new Resource();
r.setDirectory(new File("src/test/resources").getAbsoluteFile().getCanonicalPath());
r.setIncludes(Arrays.asList("**/*.*"));
project.addResource(r);
project.addCompileSourceRoot(new File("src/test/resources").getAbsoluteFile().getCanonicalPath());
ManifestPlugin plugin = new ManifestPlugin();
plugin.setBuildDirectory("target/tmp/basedir/target");
plugin.setOutputDirectory(new File("target/tmp/basedir/target/classes"));
setVariableValueToObject(plugin, "m_dependencyGraphBuilder", lookup(DependencyGraphBuilder.class.getName(), "default"));
Map instructions = new HashMap();
instructions.put("service_mode", mode);
instructions.put("Test", "Foo");
instructions.put("nsh_interface", "foo.bar.Namespace");
instructions.put("nsh_namespace", "ns");
instructions.put("Export-Service", "p7.Foo;mk=mv");
instructions.put("Import-Service", "org.osgi.service.cm.ConfigurationAdmin;availability:=optional");
Properties props = new Properties();
DependencyNode dependencyGraph = plugin.buildDependencyGraph(project);
Builder builder = plugin.buildOSGiBundle(project, dependencyGraph, instructions, props, plugin.getClasspath(project, dependencyGraph));
Manifest manifest = builder.getJar().getManifest();
String impSvc = manifest.getMainAttributes().getValue(Constants.IMPORT_SERVICE);
if ("service".equals(mode)) {
String expSvc = manifest.getMainAttributes().getValue(Constants.EXPORT_SERVICE);
assertNotNull(expSvc);
assertTrue(expSvc.contains("beanRef.Foo;osgi.service.blueprint.compname=myBean"));
} else {
String prvCap = manifest.getMainAttributes().getValue(Constants.PROVIDE_CAPABILITY);
assertNotNull(prvCap);
assertTrue(prvCap.contains("osgi.service;effective:=active;objectClass=\"beanRef.Foo\";osgi.service.blueprint.compname=myBean"));
}
assertNotNull(impSvc);
String impPkg = manifest.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
List<String> pkgs = Create.list();
for (Clause clause : Parser.parseHeader(impPkg)) {
pkgs.add(clause.getName());
}
for (int i = 1; i <= 14; i++) {
assertTrue(pkgs.contains("p" + i));
}
try (Verifier verifier = new Verifier(builder)) {
verifier.verify();
}
}
use of org.apache.maven.shared.dependency.graph.DependencyNode in project felix by apache.
the class BundlePluginTest method testEmbedDependencyDuplicateKeys.
public void testEmbedDependencyDuplicateKeys() throws Exception {
ArtifactStubFactory artifactFactory = new ArtifactStubFactory(plugin.getOutputDirectory(), true);
Set artifacts = new LinkedHashSet();
artifacts.addAll(artifactFactory.getClassifiedArtifacts());
artifacts.addAll(artifactFactory.getScopedArtifacts());
artifacts.addAll(artifactFactory.getTypedArtifacts());
MavenProject project = getMavenProjectStub();
project.setDependencyArtifacts(artifacts);
Map instructions = new HashMap();
instructions.put(DependencyEmbedder.EMBED_DEPENDENCY, "c;type=jar,c;type=sources");
Properties props = new Properties();
DependencyNode dependencyGraph = plugin.buildDependencyGraph(project);
Builder builder = plugin.buildOSGiBundle(project, dependencyGraph, instructions, props, plugin.getClasspath(project, dependencyGraph));
Manifest manifest = builder.getJar().getManifest();
String bcp = manifest.getMainAttributes().getValue(Constants.BUNDLE_CLASSPATH);
assertEquals(".," + "c-1.0-three.jar," + "c-1.0.sources", bcp);
String eas = manifest.getMainAttributes().getValue("Embedded-Artifacts");
assertEquals("c-1.0-three.jar;g=\"g\";a=\"c\";v=\"1.0\";c=\"three\"," + "c-1.0.sources;g=\"g\";a=\"c\";v=\"1.0\"", eas);
}
use of org.apache.maven.shared.dependency.graph.DependencyNode in project felix by apache.
the class BundlePluginTest method testEmbedDependencyPositiveClauses.
public void testEmbedDependencyPositiveClauses() throws Exception {
ArtifactStubFactory artifactFactory = new ArtifactStubFactory(plugin.getOutputDirectory(), true);
Set artifacts = new LinkedHashSet();
artifacts.addAll(artifactFactory.getClassifiedArtifacts());
artifacts.addAll(artifactFactory.getScopedArtifacts());
artifacts.addAll(artifactFactory.getTypedArtifacts());
MavenProject project = getMavenProjectStub();
project.setDependencyArtifacts(artifacts);
Map instructions = new HashMap();
instructions.put(DependencyEmbedder.EMBED_DEPENDENCY, "*;classifier=;type=jar;scope=compile," + "*;classifier=;type=jar;scope=runtime");
Properties props = new Properties();
DependencyNode dependencyGraph = plugin.buildDependencyGraph(project);
Builder builder = plugin.buildOSGiBundle(project, dependencyGraph, instructions, props, plugin.getClasspath(project, dependencyGraph));
Manifest manifest = builder.getJar().getManifest();
String bcp = manifest.getMainAttributes().getValue(Constants.BUNDLE_CLASSPATH);
assertEquals(".," + "compile-1.0.jar,b-1.0.jar,runtime-1.0.jar", bcp);
String eas = manifest.getMainAttributes().getValue("Embedded-Artifacts");
assertEquals("compile-1.0.jar;g=\"g\";a=\"compile\";v=\"1.0\"," + "b-1.0.jar;g=\"g\";a=\"b\";v=\"1.0\"," + "runtime-1.0.jar;g=\"g\";a=\"runtime\";v=\"1.0\"", eas);
}
use of org.apache.maven.shared.dependency.graph.DependencyNode in project felix by apache.
the class BundlePluginTest method testPropertySanitizing.
public void testPropertySanitizing() throws Exception {
MavenProject project = getMavenProjectStub();
Properties props = new Properties();
props.put(new File("A"), new File("B"));
props.put(new int[4], new HashMap(2));
props.put(Arrays.asList(1, "two", 3.0), new float[5]);
props.put("A", new File("B"));
props.put("4", new HashMap(2));
props.put("1, two, 3.0", new char[5]);
DependencyNode dependencyGraph = plugin.buildDependencyGraph(project);
Builder builder = plugin.getOSGiBuilder(project, new HashMap(), props, plugin.getClasspath(project, dependencyGraph));
File file = new File(getBasedir(), "target" + File.separatorChar + "test.props");
builder.getProperties().store(new FileOutputStream(file), "TEST");
}
use of org.apache.maven.shared.dependency.graph.DependencyNode in project felix by apache.
the class BundlePluginTest method testEmbedDependencyMissingPositiveKey.
public void testEmbedDependencyMissingPositiveKey() throws Exception {
ArtifactStubFactory artifactFactory = new ArtifactStubFactory(plugin.getOutputDirectory(), true);
Set artifacts = new LinkedHashSet();
artifacts.addAll(artifactFactory.getClassifiedArtifacts());
artifacts.addAll(artifactFactory.getScopedArtifacts());
artifacts.addAll(artifactFactory.getTypedArtifacts());
MavenProject project = getMavenProjectStub();
project.setDependencyArtifacts(artifacts);
Map instructions = new HashMap();
instructions.put(DependencyEmbedder.EMBED_DEPENDENCY, "artifactId=a|b");
Properties props = new Properties();
DependencyNode dependencyGraph = plugin.buildDependencyGraph(project);
Builder builder = plugin.buildOSGiBundle(project, dependencyGraph, instructions, props, plugin.getClasspath(project, dependencyGraph));
Manifest manifest = builder.getJar().getManifest();
String bcp = manifest.getMainAttributes().getValue(Constants.BUNDLE_CLASSPATH);
assertEquals(".," + "a-1.0-one.jar," + "b-1.0-two.jar," + "a-1.0.war," + "b-1.0.jar", bcp);
String eas = manifest.getMainAttributes().getValue("Embedded-Artifacts");
assertEquals("a-1.0-one.jar;g=\"g\";a=\"a\";v=\"1.0\";c=\"one\"," + "b-1.0-two.jar;g=\"g\";a=\"b\";v=\"1.0\";c=\"two\"," + "a-1.0.war;g=\"g\";a=\"a\";v=\"1.0\"," + "b-1.0.jar;g=\"g\";a=\"b\";v=\"1.0\"", eas);
}
Aggregations