Search in sources :

Example 1 with DependencyNode

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();
    }
}
Also used : HashMap(java.util.HashMap) DefaultProjectBuilderConfiguration(org.apache.maven.project.DefaultProjectBuilderConfiguration) DependencyGraphBuilder(org.apache.maven.shared.dependency.graph.DependencyGraphBuilder) Builder(aQute.bnd.osgi.Builder) ArrayList(java.util.ArrayList) Resource(org.apache.maven.model.Resource) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Properties(java.util.Properties) Manifest(java.util.jar.Manifest) Verifier(aQute.bnd.osgi.Verifier) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) ProjectBuilderConfiguration(org.apache.maven.project.ProjectBuilderConfiguration) DefaultProjectBuilderConfiguration(org.apache.maven.project.DefaultProjectBuilderConfiguration) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) ArrayList(java.util.ArrayList) List(java.util.List) Clause(org.apache.felix.utils.manifest.Clause) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 2 with DependencyNode

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) MavenProject(org.apache.maven.project.MavenProject) HashMap(java.util.HashMap) DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) Builder(aQute.bnd.osgi.Builder) DependencyGraphBuilder(org.apache.maven.shared.dependency.graph.DependencyGraphBuilder) Properties(java.util.Properties) Manifest(java.util.jar.Manifest) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 3 with DependencyNode

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) MavenProject(org.apache.maven.project.MavenProject) HashMap(java.util.HashMap) DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) Builder(aQute.bnd.osgi.Builder) DependencyGraphBuilder(org.apache.maven.shared.dependency.graph.DependencyGraphBuilder) Properties(java.util.Properties) Manifest(java.util.jar.Manifest) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 4 with DependencyNode

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");
}
Also used : MavenProject(org.apache.maven.project.MavenProject) HashMap(java.util.HashMap) DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) Builder(aQute.bnd.osgi.Builder) DependencyGraphBuilder(org.apache.maven.shared.dependency.graph.DependencyGraphBuilder) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) File(java.io.File)

Example 5 with DependencyNode

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) MavenProject(org.apache.maven.project.MavenProject) HashMap(java.util.HashMap) DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) Builder(aQute.bnd.osgi.Builder) DependencyGraphBuilder(org.apache.maven.shared.dependency.graph.DependencyGraphBuilder) Properties(java.util.Properties) Manifest(java.util.jar.Manifest) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

DependencyNode (org.apache.maven.shared.dependency.graph.DependencyNode)23 MavenProject (org.apache.maven.project.MavenProject)9 Artifact (org.apache.maven.artifact.Artifact)8 DependencyGraphBuilder (org.apache.maven.shared.dependency.graph.DependencyGraphBuilder)8 Builder (aQute.bnd.osgi.Builder)7 HashMap (java.util.HashMap)7 Properties (java.util.Properties)7 LinkedHashSet (java.util.LinkedHashSet)6 Map (java.util.Map)6 Manifest (java.util.jar.Manifest)6 File (java.io.File)5 Set (java.util.Set)5 TreeMap (java.util.TreeMap)5 ArrayList (java.util.ArrayList)4 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)3 IOException (java.io.IOException)2 List (java.util.List)2 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)2 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)2 AndArtifactFilter (org.apache.maven.artifact.resolver.filter.AndArtifactFilter)2