Example usage for org.apache.maven.artifact DefaultArtifact setFile

List of usage examples for org.apache.maven.artifact DefaultArtifact setFile

Introduction

In this page you can find the example usage for org.apache.maven.artifact DefaultArtifact setFile.

Prototype

public void setFile(File file) 

Source Link

Usage

From source file:com.github.born2snipe.maven.plugin.idea.BaseMojoTestCase.java

License:Apache License

protected void addProjectDependency(String definition) {
    String[] parts = definition.split(":");
    File file = new File(mavenRepoDir, parts[1] + "-" + parts[2] + ".jar");
    DefaultArtifactHandler artifactHandler = new DefaultArtifactHandler();
    artifactHandler.setAddedToClasspath(true);
    DefaultArtifact artifact = new DefaultArtifact(parts[0], parts[1], parts[2], "compile", "jar", "main",
            artifactHandler);/*www.  j  a  v  a2 s.  c o m*/
    artifact.setFile(file);
    writeFile(file, definition);
    mavenProject.getArtifacts().add(artifact);
}

From source file:io.sundr.maven.AbstractSundrioMojo.java

License:Apache License

Artifact createArtifact(File file, String groupId, String artifactId, String version, String scope, String type,
        String classifier) {//from  ww  w  .ja  v a2  s. co m
    DefaultArtifact artifact = new DefaultArtifact(groupId, artifactId, version, scope, type, classifier,
            artifactHandler);
    artifact.setFile(file);
    artifact.setResolved(true);
    return artifact;
}

From source file:org.codehaus.mojo.natives.plugin.NativeLinkMojo.java

License:Open Source License

/**
 * /*from ww  w .j av a 2  s  .com*/
 */
private void attachPrimaryArtifact() {
    Artifact artifact = this.project.getArtifact();

    if (null == this.classifier) {
        artifact.setFile(new File(this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName()
                + "." + this.project.getArtifact().getArtifactHandler().getExtension()));
    } else {
        //install primary artifact as a classifier

        DefaultArtifact clone = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(),
                artifact.getVersionRange().cloneOf(), artifact.getScope(), artifact.getType(), classifier,
                artifact.getArtifactHandler(), artifact.isOptional());

        clone.setRelease(artifact.isRelease());
        clone.setResolvedVersion(artifact.getVersion());
        clone.setResolved(artifact.isResolved());
        clone.setFile(artifact.getFile());

        if (artifact.getAvailableVersions() != null) {
            clone.setAvailableVersions(new ArrayList(artifact.getAvailableVersions()));
        }

        clone.setBaseVersion(artifact.getBaseVersion());
        clone.setDependencyFilter(artifact.getDependencyFilter());

        if (artifact.getDependencyTrail() != null) {
            clone.setDependencyTrail(new ArrayList(artifact.getDependencyTrail()));
        }

        clone.setDownloadUrl(artifact.getDownloadUrl());
        clone.setRepository(artifact.getRepository());

        clone.setFile(new File(this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "."
                + this.project.getArtifact().getArtifactHandler().getExtension()));

        project.setArtifact(clone);
    }
}

From source file:org.eclipse.tycho.plugins.p2.P2MetadataMojo.java

License:Open Source License

private static DefaultArtifact createP2Artifact(ArtifactFacade projectDefaultArtifact, String extension,
        String classifier, String p2ArtifactFileName, File targetDir) {
    DefaultArtifact p2Artifact = new DefaultArtifact(projectDefaultArtifact.getGroupId(),
            projectDefaultArtifact.getArtifactId(), projectDefaultArtifact.getVersion(), null, extension,
            classifier, null);/*from  w  w w .  ja va  2  s  .co  m*/
    p2Artifact.setFile(new File(targetDir, p2ArtifactFileName));
    return p2Artifact;
}

From source file:org.fluidity.deployment.maven.DependenciesSupportImpl.java

License:Apache License

@Override
public void saveArtifact(final MavenProject project, final File file, final String finalName,
        final String classifier, final String packaging, final Logger log) throws MojoExecutionException {
    final boolean unclassified = classifier == null || classifier.isEmpty();
    final String outputName = unclassified ? String.format("%s.%s", finalName, packaging)
            : String.format("%s-%s.%s", finalName, classifier, packaging);

    final File outputFile = new File(outputName);
    final String outputPath = outputFile.getAbsolutePath();

    final Artifact artifact = project.getArtifact();
    assert artifact != null;

    final File artifactFile = artifact.getFile();

    if (artifactFile != null && artifactFile.getAbsolutePath().equals(outputPath)) {
        log.info(String.format("Replacing %s: %s", packaging, artifactFile.getAbsolutePath()));

        if (!artifactFile.delete()) {
            throw new MojoExecutionException(String.format("Could not delete %s", artifactFile));
        }/*from ww  w . ja  v  a  2 s .c  o m*/

        if (!file.renameTo(artifactFile)) {
            throw new MojoExecutionException(String.format("Could not create %s", artifactFile));
        }
    } else {
        boolean replacing = false;

        for (final Artifact attached : project.getAttachedArtifacts()) {
            if (attached.getFile().getAbsolutePath().equals(outputPath)) {
                replacing = true;
                break;
            }
        }

        log.info(String.format("%s %s: %s", replacing ? "Replacing" : "Saving", packaging, outputPath));

        if (outputFile.exists() && !outputFile.delete()) {
            throw new MojoExecutionException(String.format("Could not delete %s", outputFile));
        }

        if (!file.renameTo(outputFile)) {
            throw new MojoExecutionException(String.format("Could not create %s", outputFile));
        }

        if (!replacing) {
            final DefaultArtifact attachment = new DefaultArtifact(project.getGroupId(),
                    project.getArtifactId(), project.getVersion(), artifact.getScope(), packaging, classifier,
                    artifact.getArtifactHandler());
            attachment.setFile(outputFile);

            project.addAttachedArtifact(attachment);
        }
    }
}

From source file:org.heneveld.maven.license_audit.AbstractLicensingMojo.java

protected DefaultArtifact newMavenArtifact(Artifact da) {
    DefaultArtifact result = new org.apache.maven.artifact.DefaultArtifact(da.getGroupId(), da.getArtifactId(),
            da.getVersion(), null, da.getExtension(), da.getClassifier(), artifactHandler);
    result.setFile(da.getFile());
    return result;
}

From source file:org.jfrog.build.extractor.maven.BuildInfoRecorder.java

License:Apache License

/**
 * Merge the dependencies taken from the MavenProject object with those
 * collected inside the resolvedArtifacts collection.
 *
 * @param projectDependencies The artifacts taken from the MavenProject
 *                            object.// w  ww.  ja v a  2  s .  c  o  m
 */
private void mergeProjectDependencies(Set<Artifact> projectDependencies) {
    // Go over all the artifacts taken from the MavenProject object, and replace their equals method, so that we are
    // able to merge them together with the artifacts inside the resolvedArtifacts set:
    Set<Artifact> dependecies = Sets.newHashSet();
    for (Artifact artifact : projectDependencies) {
        String classifier = artifact.getClassifier();
        classifier = classifier == null ? "" : classifier;
        DefaultArtifact art = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(),
                artifact.getVersion(), artifact.getScope(), artifact.getType(), classifier,
                artifact.getArtifactHandler());

        art.setFile(artifact.getFile());
        dependecies.add(art);
    }

    // Now we merge the artifacts from the two collections. In case an artifact is included in both collections, we'd like to keep
    // the one that was taken from the MavenProject, because of the scope it has.
    // The merge is done only if the client is configured to do so.
    Set<Artifact> moduleDependencies = currentModuleDependencies.get();
    Set<Artifact> tempSet = Sets.newHashSet(moduleDependencies);
    moduleDependencies.clear();
    moduleDependencies.addAll(dependecies);
    moduleDependencies.addAll(tempSet);
    if (conf.publisher.isRecordAllDependencies()) {
        moduleDependencies.addAll(resolvedArtifacts);
    }
}

From source file:org.kohsuke.maven.pgp.PgpMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    if (skip)//  w w  w. j av a  2  s.  com
        return;

    // capture the attached artifacts to sign before we start attaching our own stuff
    List<Artifact> attached = new ArrayList<Artifact>((List<Artifact>) project.getAttachedArtifacts());

    PGPSecretKey secretKey = loadSecretKey();
    Signer signer = new Signer(secretKey, loadPassPhrase(secretKey).toCharArray());

    if (!"pom".equals(project.getPackaging()))
        sign(signer, project.getArtifact());

    {// sign POM
        File pomToSign = new File(project.getBuild().getDirectory(),
                project.getBuild().getFinalName() + ".pom");

        try {
            FileUtils.copyFile(project.getFile(), pomToSign);
        } catch (IOException e) {
            throw new MojoExecutionException("Error copying POM for signing.", e);
        }

        getLog().debug("Generating signature for " + pomToSign);

        // fake just enough Artifact for the sign method
        DefaultArtifact a = new DefaultArtifact(project.getGroupId(), project.getArtifactId(),
                VersionRange.createFromVersion(project.getVersion()), null, "pom", null,
                new DefaultArtifactHandler("pom"));
        a.setFile(pomToSign);

        sign(signer, a);
    }

    for (Artifact a : attached)
        sign(signer, a);
}

From source file:org.sonatype.nexus.pluginbundle.maven.ClasspathUtils.java

License:Open Source License

private static Artifact formatArtifactFromKey(final String key, final Properties artifacts) {
    Pattern p = Pattern.compile("([^: ]+):([^: ]+)(:([^: ]*)(:([^: ]+))?)?:([^: ]+)");
    Matcher m = p.matcher(key);//from   ww w. j  a  v a  2  s  .c  o m
    if (!m.matches()) {
        throw new IllegalArgumentException("Bad artifact coordinates " + key
                + ", expected format is <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>");
    }
    String groupId = m.group(1);
    String artifactId = m.group(2);
    String extension = m.group(4);
    extension = (extension == null || extension.length() < 1) ? "jar" : extension;
    String classifier = m.group(6);
    classifier = (classifier == null || classifier.length() < 1) ? "" : classifier;
    String version = m.group(7);
    final DefaultArtifact result = new DefaultArtifact(groupId, artifactId, version, null, extension,
            classifier, null);
    result.setFile(new File(artifacts.getProperty(key)));
    return result;
}

From source file:org.sourcepit.common.maven.artifact.ArtifactFactory.java

License:Apache License

public Artifact createArtifact(final Artifact artifact, String classifier, String type, String localPath) {
    classifier = isNullOrEmpty(classifier) ? null : classifier;

    final String scope = localPath == null ? null : org.apache.maven.artifact.Artifact.SCOPE_SYSTEM;

    final ArtifactHandler handler = artifactHandlers.get(type);

    final DefaultArtifact legacyArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(),
            artifact.getVersion(), scope, type, classifier, handler);

    if (localPath != null) {
        legacyArtifact.setFile(new File(localPath));
    }/*from ww  w  . j ava  2s.c o m*/

    return toArtifact(legacyArtifact);
}