Search in sources :

Example 1 with DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact 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 DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact in project felix by apache.

the class BundleAllPluginTest method testNoReBundling.

public void testNoReBundling() throws Exception {
    File testFile = getTestFile("target/test-classes/org.apache.maven.maven-model_1.0.0.0.jar");
    if (testFile.exists()) {
        testFile.delete();
    }
    VersionRange versionRange = VersionRange.createFromVersion("1.0.0.0");
    ArtifactHandler artifactHandler = new DefaultArtifactHandler("jar");
    Artifact artifact = new DefaultArtifact("group", "artifact", versionRange, null, "jar", null, artifactHandler);
    MavenProject project = getMavenProjectStub();
    project.setGroupId(artifact.getGroupId());
    project.setArtifactId(artifact.getArtifactId());
    project.setVersion(artifact.getVersion());
    project.setArtifact(artifact);
    project.setArtifacts(Collections.EMPTY_SET);
    project.setDependencyArtifacts(Collections.EMPTY_SET);
    File bundleFile = getTestFile("src/test/resources/org.apache.maven.maven-model_2.1.0.SNAPSHOT.jar");
    artifact.setFile(bundleFile);
    BundleInfo bundleInfo = plugin.bundle(project);
    Map exports = bundleInfo.getExportedPackages();
    String[] packages = new String[] { "org.apache.maven.model.io.jdom", "org.apache.maven.model" };
    for (int i = 0; i < packages.length; i++) {
        assertTrue("Bundle info does not contain a package that it is  exported in the manifest: " + packages[i], exports.containsKey(packages[i]));
    }
    assertFalse("Bundle info contains a package that it is not exported in the manifest", exports.containsKey("org.apache.maven.model.io.xpp3"));
}
Also used : DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) MavenProject(org.apache.maven.project.MavenProject) VersionRange(org.apache.maven.artifact.versioning.VersionRange) File(java.io.File) Map(java.util.Map) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 3 with DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact in project kotlin by JetBrains.

the class ExecuteKotlinScriptMojo method getDependencyFile.

private File getDependencyFile(ComponentDependency dep) {
    ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(dep.getType());
    Artifact artifact = new DefaultArtifact(dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), null, dep.getType(), null, artifactHandler);
    return getArtifactFile(artifact);
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 4 with DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact in project kotlin by JetBrains.

the class ExecuteKotlinScriptMojo method getDependencyFile.

private File getDependencyFile(Dependency dep) {
    ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(dep.getType());
    Artifact artifact = new DefaultArtifact(dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), null, dep.getType(), null, artifactHandler);
    return getArtifactFile(artifact);
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 5 with DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact in project maven-dependency-plugin by apache.

the class TestSourcesMarkerFileHandler method setUp.

protected void setUp() throws Exception {
    super.setUp();
    ArtifactHandler ah = new DefaultArtifactHandler();
    VersionRange vr = VersionRange.createFromVersion("1.1");
    Artifact artifact = new DefaultArtifact("test", "1", vr, Artifact.SCOPE_COMPILE, "jar", "", ah, false);
    artifacts.add(artifact);
    artifact = new DefaultArtifact("test", "2", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false);
    artifacts.add(artifact);
    artifact = new DefaultArtifact("test", "3", vr, Artifact.SCOPE_TEST, "sources", "", ah, false);
    artifacts.add(artifact);
    artifact = new DefaultArtifact("test", "4", vr, Artifact.SCOPE_RUNTIME, "zip", "", ah, false);
    artifacts.add(artifact);
    // pick random output location
    Random a = new Random();
    outputFolder = new File("target/markers" + a.nextLong() + "/");
    outputFolder.delete();
    assertFalse(outputFolder.exists());
}
Also used : DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) Random(java.util.Random) VersionRange(org.apache.maven.artifact.versioning.VersionRange) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Aggregations

DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)53 Artifact (org.apache.maven.artifact.Artifact)37 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)28 File (java.io.File)26 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)22 VersionRange (org.apache.maven.artifact.versioning.VersionRange)17 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)10 DefaultArtifactHandlerStub (org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub)10 MavenProject (org.apache.maven.project.MavenProject)10 MavenProjectResourcesStub (org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub)7 ArrayList (java.util.ArrayList)4 Random (java.util.Random)4 InputStream (java.io.InputStream)3 List (java.util.List)3 Map (java.util.Map)3 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2