Search in sources :

Example 46 with Artifact

use of org.apache.maven.artifact.Artifact in project aries by apache.

the class EbaMojo method writeApplicationManifest.

private void writeApplicationManifest(String fileName) throws MojoExecutionException {
    try {
        // TODO: add support for dependency version ranges. Need to pick
        // them up from the pom and convert them to OSGi version ranges.
        FileUtils.fileAppend(fileName, MANIFEST_VERSION + ": " + "1" + "\n");
        FileUtils.fileAppend(fileName, APPLICATION_MANIFESTVERSION + ": " + "1" + "\n");
        FileUtils.fileAppend(fileName, APPLICATION_SYMBOLICNAME + ": " + getApplicationSymbolicName(project.getArtifact()) + "\n");
        FileUtils.fileAppend(fileName, APPLICATION_VERSION + ": " + getApplicationVersion() + "\n");
        FileUtils.fileAppend(fileName, APPLICATION_NAME + ": " + project.getName() + "\n");
        FileUtils.fileAppend(fileName, APPLICATION_DESCRIPTION + ": " + project.getDescription() + "\n");
        // Write the APPLICATION-CONTENT
        // TODO: check that the dependencies are bundles (currently, the converter
        // will throw an exception)
        Set<Artifact> artifacts;
        if (useTransitiveDependencies) {
            artifacts = project.getArtifacts();
        } else {
            artifacts = project.getDependencyArtifacts();
        }
        artifacts = selectArtifacts(artifacts);
        Iterator<Artifact> iter = artifacts.iterator();
        FileUtils.fileAppend(fileName, APPLICATION_CONTENT + ": ");
        if (iter.hasNext()) {
            Artifact artifact = iter.next();
            FileUtils.fileAppend(fileName, maven2OsgiConverter.getBundleSymbolicName(artifact) + ";version=\"" + Analyzer.cleanupVersion(artifact.getVersion()) + //						+ maven2OsgiConverter.getVersion(artifact.getVersion())
            "\"");
        }
        while (iter.hasNext()) {
            Artifact artifact = iter.next();
            FileUtils.fileAppend(fileName, ",\n " + maven2OsgiConverter.getBundleSymbolicName(artifact) + ";version=\"" + Analyzer.cleanupVersion(artifact.getVersion()) + //						+ maven2OsgiConverter.getVersion(artifact.getVersion())
            "\"");
        }
        FileUtils.fileAppend(fileName, "\n");
        // Add any service imports or exports
        if (instructions.containsKey(APPLICATION_EXPORTSERVICE)) {
            FileUtils.fileAppend(fileName, APPLICATION_EXPORTSERVICE + ": " + instructions.get(APPLICATION_EXPORTSERVICE) + "\n");
        }
        if (instructions.containsKey(APPLICATION_IMPORTSERVICE)) {
            FileUtils.fileAppend(fileName, APPLICATION_IMPORTSERVICE + ": " + instructions.get(APPLICATION_IMPORTSERVICE) + "\n");
        }
        if (instructions.containsKey(APPLICATION_USEBUNDLE)) {
            FileUtils.fileAppend(fileName, APPLICATION_USEBUNDLE + ": " + instructions.get(APPLICATION_USEBUNDLE) + "\n");
        }
    // Add any use bundle entry
    } catch (Exception e) {
        throw new MojoExecutionException("Error writing dependencies into APPLICATION.MF", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException)

Example 47 with Artifact

use of org.apache.maven.artifact.Artifact in project aries by apache.

the class EbaMavenProjectStub method getArtifact.

public Artifact getArtifact() {
    Artifact artifact = new EbaArtifactStub();
    artifact.setGroupId(getGroupId());
    artifact.setArtifactId(getArtifactId());
    artifact.setVersion(getVersion());
    return artifact;
}
Also used : Artifact(org.apache.maven.artifact.Artifact)

Example 48 with Artifact

use of org.apache.maven.artifact.Artifact in project aries by apache.

the class EsaMavenProjectStub method createArtifact.

protected Artifact createArtifact(String groupId, String artifactId, String version, String type, boolean optional) {
    Artifact artifact = new EsaArtifactStub();
    artifact.setGroupId(groupId);
    artifact.setArtifactId(artifactId);
    artifact.setVersion(version);
    artifact.setOptional(optional);
    artifact.setFile(new File(getBasedir() + "/src/test/remote-repo/" + artifact.getGroupId().replace('.', '/') + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + type));
    return artifact;
}
Also used : File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 49 with Artifact

use of org.apache.maven.artifact.Artifact in project aries by apache.

the class EsaMavenProjectStub9 method getArtifacts.

public Set getArtifacts() {
    try {
        Set artifacts = new HashSet();
        artifacts.add(createArtifact("org.apache.maven.test", "maven-artifact01", "1.0-SNAPSHOT", false));
        Artifact artifact02 = createArtifact("org.apache.maven.test", "maven-artifact02", "1.0-SNAPSHOT", false);
        artifact02.setVersionRange(VersionRange.createFromVersionSpec("[1.3, 2.5)"));
        artifacts.add(artifact02);
        artifacts.add(createArtifact("org.apache.maven.test", "maven-artifact03", "1.1-SNAPSHOT", false));
        artifacts.add(createArtifact("org.apache.maven.test", "maven-artifact04", "1.2-SNAPSHOT", "esa", true));
        return artifacts;
    } catch (InvalidVersionSpecificationException e) {
        throw new RuntimeException(e);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) Artifact(org.apache.maven.artifact.Artifact) HashSet(java.util.HashSet)

Example 50 with Artifact

use of org.apache.maven.artifact.Artifact in project asterixdb by apache.

the class LicenseMojo method gatherProjectDependencies.

private void gatherProjectDependencies(MavenProject project, Map<MavenProject, List<Pair<String, String>>> dependencyLicenseMap, Map<String, MavenProject> dependencyGavMap) throws ProjectBuildingException {
    final Set dependencyArtifacts = project.getArtifacts();
    if (dependencyArtifacts != null) {
        for (Object depArtifactObj : dependencyArtifacts) {
            final Artifact depArtifact = (Artifact) depArtifactObj;
            if (!excludedScopes.contains(depArtifact.getScope())) {
                MavenProject dep = resolveDependency(depArtifact);
                dep.setArtifact(depArtifact);
                dependencyGavMap.put(toGav(dep), dep);
                List<Pair<String, String>> licenseUrls = new ArrayList<>();
                for (Object license : dep.getLicenses()) {
                    final License license1 = (License) license;
                    String url = license1.getUrl() != null ? license1.getUrl() : (license1.getName() != null ? license1.getName() : "LICENSE_EMPTY_NAME_URL");
                    licenseUrls.add(new ImmutablePair<>(url, license1.getName()));
                }
                dependencyLicenseMap.put(dep, licenseUrls);
            }
        }
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) License(org.apache.maven.model.License) Artifact(org.apache.maven.artifact.Artifact) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)450 File (java.io.File)175 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)92 ArrayList (java.util.ArrayList)91 MavenProject (org.apache.maven.project.MavenProject)63 IOException (java.io.IOException)50 HashSet (java.util.HashSet)42 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)32 LinkedHashSet (java.util.LinkedHashSet)29 MojoFailureException (org.apache.maven.plugin.MojoFailureException)24 HashMap (java.util.HashMap)22 Set (java.util.Set)22 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)22 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)21 URL (java.net.URL)20 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)20 Test (org.junit.Test)20 MalformedURLException (java.net.MalformedURLException)18 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)17 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)16