Example usage for org.apache.maven.project MavenProject getAttachedArtifacts

List of usage examples for org.apache.maven.project MavenProject getAttachedArtifacts

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getAttachedArtifacts.

Prototype

public List<Artifact> getAttachedArtifacts() 

Source Link

Usage

From source file:org.hudsonci.maven.eventspy_30.handler.ProjectLogger.java

License:Open Source License

public static void log(MavenProject project, String where) {
    if (disabled)
        return;//from www.  j av a 2 s.  co  m

    log.debug("MavenProject ({}) artifacts @ {}:", project.getId(), where);
    logArtifactContents("artifacts", project.getArtifacts());
    logArtifactContents("attachedArtifacts", project.getAttachedArtifacts());
    logArtifactContents("dependencyArtifacts", project.getDependencyArtifacts());
    logArtifactContents("extensionArtifacts", project.getExtensionArtifacts());
    logArtifactContents("pluginArtifacts", project.getPluginArtifacts());

    for (Artifact artifact : project.getPluginArtifacts()) {
        if (artifact instanceof PluginArtifact) {
            List<Dependency> dependencies = ((PluginArtifact) artifact).getDependencies();

            Integer maybeSize = (dependencies == null ? null : dependencies.size());
            log.debug("  {} " + "pluginDependencies" + ": {}", maybeSize, dependencies);
        }
    }
}

From source file:org.jenkinsci.plugins.pipeline.maven.eventspy.handler.ProjectSucceededExecutionHandler.java

License:Open Source License

@Override
protected void addDetails(ExecutionEvent executionEvent, Xpp3Dom element) {
    super.addDetails(executionEvent, element);
    MavenProject project = executionEvent.getProject();

    Artifact artifact = project.getArtifact();
    if (artifact == null) {

    } else {//  w w w .  ja  v a  2s.  co  m
        Xpp3Dom artifactElt = newElement("artifact", artifact);
        File file = artifact.getFile();
        try {
            artifactElt.addChild(newElement("file", file == null ? null : file.getCanonicalPath()));
        } catch (IOException e) {
            throw new RuntimeIOException(e);
        }
        element.addChild(artifactElt);
    }

    Xpp3Dom attachedArtifactsElt = new Xpp3Dom("attachedArtifacts");
    element.addChild(attachedArtifactsElt);
    for (Artifact attachedArtifact : project.getAttachedArtifacts()) {
        Xpp3Dom artifactElt = newElement("artifact", attachedArtifact);
        File file = attachedArtifact.getFile();
        try {
            artifactElt.addChild(newElement("file", file == null ? null : file.getCanonicalPath()));
        } catch (IOException e) {
            throw new RuntimeIOException(e);
        }
        attachedArtifactsElt.addChild(artifactElt);
    }

}

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

License:Apache License

private void extractModuleAttachedArtifacts(MavenProject project, Set<Artifact> artifacts) {
    List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
    if (attachedArtifacts != null) {
        for (Artifact attachedArtifact : attachedArtifacts) {
            artifacts.add(attachedArtifact);
        }//  w  ww  .  ja v  a2 s  .c  o  m
    }
}

From source file:org.jfrog.jade.plugins.natives.plugin.NativeCompileMojo.java

License:Open Source License

/**
 * Add include path from the list of dependant artifacts
 *
 * @param filter// w  w  w .ja  va  2s . co  m
 * @throws MojoExecutionException
 */
private void addDependantIncludePath(ArtifactFilter filter) throws MojoExecutionException {
    Collection<Artifact> allArtifacts = getProject().getArtifacts();

    if (allArtifacts == null || allArtifacts.isEmpty()) {
        return;
    }

    // If no sources nothing to do?
    if (this.sources == null) {
        return;
    }

    for (Artifact artifact : allArtifacts) {
        if (filter.include(artifact)) {
            MavenProject reactorProject = findInReactorList(artifact);
            if (reactorProject != null) {
                List<Artifact> attachedArtifacts = reactorProject.getAttachedArtifacts();
                for (Artifact attachedArtifact : attachedArtifacts) {
                    if (attachedArtifact.getClassifier() != null
                            && attachedArtifact.getClassifier().equals(INCLUDE_CLASSIFIER)) {
                        addIncludeDirectory(
                                extractIncludeZipFile(attachedArtifact, attachedArtifact.getFile()));
                        break;
                    }
                }
            } else {
                addIncludeDirectory(findAndExtractInclude(artifact));
            }
        }
    }
}

From source file:org.jszip.maven.RunMojo.java

License:Apache License

private void injectMissingArtifacts(MavenProject destination, MavenProject source) {
    if (destination.getArtifact().getFile() == null && source.getArtifact().getFile() != null) {
        getLog().info("Pushing primary artifact from forked execution into current execution");
        destination.getArtifact().setFile(source.getArtifact().getFile());
    }//from   ww  w.  j  a  v a2  s  .c om
    for (Artifact executedArtifact : source.getAttachedArtifacts()) {
        String executedArtifactId = (executedArtifact.getClassifier() == null ? "."
                : "-" + executedArtifact.getClassifier() + ".") + executedArtifact.getType();
        if (StringUtils.equals(executedArtifact.getGroupId(), destination.getGroupId())
                && StringUtils.equals(executedArtifact.getArtifactId(), destination.getArtifactId())
                && StringUtils.equals(executedArtifact.getVersion(), destination.getVersion())) {
            boolean found = false;
            for (Artifact artifact : destination.getAttachedArtifacts()) {
                if (StringUtils.equals(artifact.getGroupId(), destination.getGroupId())
                        && StringUtils.equals(artifact.getArtifactId(), destination.getArtifactId())
                        && StringUtils.equals(artifact.getVersion(), destination.getVersion())
                        && StringUtils.equals(artifact.getClassifier(), executedArtifact.getClassifier())
                        && StringUtils.equals(artifact.getType(), executedArtifact.getType())) {
                    if (artifact.getFile() == null) {
                        getLog().info("Pushing " + executedArtifactId
                                + " artifact from forked execution into current execution");
                        artifact.setFile(executedArtifact.getFile());
                    }
                    found = true;
                }
            }
            if (!found) {
                getLog().info("Attaching " + executedArtifactId
                        + " artifact from forked execution into current execution");
                projectHelper.attachArtifact(destination, executedArtifact.getType(),
                        executedArtifact.getClassifier(), executedArtifact.getFile());
            }
        }
    }
}

From source file:org.m1theo.apt.repo.utils.Utils.java

License:Open Source License

/**
 * Collects all artifacts of the given type.
 * /*from  w w w  .j a v a2s.  co m*/
 * @param project The maven project which should be used.
 * @param type The file type which should be collected.
 * @return A collection of all artifacts with the given type.
 */
@SuppressWarnings("unchecked")
public static Collection<Artifact> getAllArtifacts4Type(MavenProject project, String type, Boolean aggregate) {
    final Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
    List<MavenProject> modules = new ArrayList<MavenProject>();
    modules.add(project);
    List<MavenProject> collectedProjects = project.getCollectedProjects();
    if (collectedProjects != null) {
        modules.addAll(collectedProjects);
    }
    for (MavenProject module : modules) {
        addDebArtifact(module.getArtifact(), artifacts, type);
        for (Object artifact : module.getArtifacts()) {
            if (artifact instanceof Artifact) {
                addDebArtifact((Artifact) artifact, artifacts, type);
            }
        }
        for (Object artifact : module.getAttachedArtifacts()) {
            if (artifact instanceof Artifact) {
                addDebArtifact((Artifact) artifact, artifacts, type);
            }
        }
    }
    if (project.hasParent() && aggregate) {
        artifacts.addAll(getAllArtifacts4Type(project.getParent(), type, aggregate));
    }
    return artifacts;
}

From source file:org.sourcepit.b2.internal.maven.MavenB2LifecycleParticipant.java

License:Apache License

private void processAttachments(MavenProject wrapperProject, File pomFile) {
    final List<Artifact> attachedArtifacts = wrapperProject.getAttachedArtifacts();
    if (attachedArtifacts == null) {
        return;//from  www  . ja va 2 s.com
    }

    Xpp3Dom artifactsNode = new Xpp3Dom("artifacts");
    for (Artifact artifact : attachedArtifacts) {
        Xpp3Dom artifactNode = new Xpp3Dom("artifact");

        if (artifact.getClassifier() != null) {
            Xpp3Dom classifierNode = new Xpp3Dom("classifier");
            classifierNode.setValue(artifact.getClassifier());
            artifactNode.addChild(classifierNode);
        }

        Xpp3Dom typeNode = new Xpp3Dom("type");
        typeNode.setValue(artifact.getType());
        artifactNode.addChild(typeNode);

        Xpp3Dom fileNode = new Xpp3Dom("file");
        fileNode.setValue(artifact.getFile().getAbsolutePath());
        artifactNode.addChild(fileNode);

        artifactsNode.addChild(artifactNode);
    }

    Xpp3Dom configNode = new Xpp3Dom("configuration");
    configNode.addChild(artifactsNode);

    PluginExecution exec = new PluginExecution();
    exec.setId("b2-attach-artifatcs");
    exec.setPhase("initialize");
    exec.getGoals().add("attach-artifact");
    exec.setConfiguration(configNode);

    Plugin plugin = new Plugin();
    plugin.setGroupId("org.codehaus.mojo");
    plugin.setArtifactId("build-helper-maven-plugin");
    plugin.setVersion("1.7");
    plugin.getExecutions().add(exec);
    plugin.setInherited(false);

    Build build = new Build();
    build.getPlugins().add(plugin);

    Model model = new Model();
    model.setBuild(build);

    final Model moduleModel;
    try {
        moduleModel = new DefaultModelReader().read(pomFile, null);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    new ModelTemplateMerger().merge(moduleModel, model, false, null);
    try {
        new DefaultModelWriter().write(pomFile, null, moduleModel);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.sourcepit.maven.bootstrap.internal.core.ReactorReader.java

License:Apache License

/**
 * Tries to resolve the specified artifact from the artifacts of the given project.
 * /*from w  ww  .j  a  v  a  2s .  co  m*/
 * @param project The project to try to resolve the artifact from, must not be <code>null</code>.
 * @param requestedArtifact The artifact to resolve, must not be <code>null</code>.
 * @return The matching artifact from the project or <code>null</code> if not found.
 */
private org.apache.maven.artifact.Artifact findMatchingArtifact(MavenProject project,
        Artifact requestedArtifact) {
    String requestedRepositoryConflictId = getConflictId(requestedArtifact);

    org.apache.maven.artifact.Artifact mainArtifact = project.getArtifact();
    if (requestedRepositoryConflictId.equals(getConflictId(mainArtifact))) {
        return mainArtifact;
    }

    Collection<org.apache.maven.artifact.Artifact> attachedArtifacts = project.getAttachedArtifacts();
    if (attachedArtifacts != null && !attachedArtifacts.isEmpty()) {
        for (org.apache.maven.artifact.Artifact attachedArtifact : attachedArtifacts) {
            if (requestedRepositoryConflictId.equals(getConflictId(attachedArtifact))) {
                return attachedArtifact;
            }
        }
    }

    return null;
}

From source file:org.sourcepit.osgifier.maven.InjectManifestMojo.java

License:Apache License

private static Artifact getAttachedArtifact(MavenProject project, String classifier) {
    if (classifier == null) {
        return project.getArtifact();
    } else {/*from w  ww .  j a v  a2 s .  c o  m*/
        for (Artifact artifact : project.getAttachedArtifacts()) {
            if (classifier.equals(artifact.getClassifier())) {
                return artifact;
            }
        }
    }
    return null;
}

From source file:org.vafer.jdeb.maven.DebMojo.java

License:Apache License

/**
 * Main entry point/*www . j a v  a 2 s  .  c o  m*/
 *
 * @throws MojoExecutionException on error
 */
@Override
public void execute() throws MojoExecutionException {

    final MavenProject project = getProject();

    if (skip) {
        getLog().info("skipping as configured (skip)");
        return;
    }

    if (skipPOMs && isPOM()) {
        getLog().info("skipping because artifact is a pom (skipPOMs)");
        return;
    }

    if (skipSubmodules && isSubmodule()) {
        getLog().info("skipping submodule (skipSubmodules)");
        return;
    }

    setData(dataSet);

    console = new MojoConsole(getLog(), verbose);

    initializeSignProperties();

    final VariableResolver resolver = initializeVariableResolver(new HashMap<String, String>());

    final File debFile = new File(Utils.replaceVariables(resolver, deb, openReplaceToken, closeReplaceToken));
    final File controlDirFile = new File(
            Utils.replaceVariables(resolver, controlDir, openReplaceToken, closeReplaceToken));
    final File installDirFile = new File(
            Utils.replaceVariables(resolver, installDir, openReplaceToken, closeReplaceToken));
    final File changesInFile = new File(
            Utils.replaceVariables(resolver, changesIn, openReplaceToken, closeReplaceToken));
    final File changesOutFile = new File(
            Utils.replaceVariables(resolver, changesOut, openReplaceToken, closeReplaceToken));
    final File changesSaveFile = new File(
            Utils.replaceVariables(resolver, changesSave, openReplaceToken, closeReplaceToken));
    final File keyringFile = keyring == null ? null
            : new File(Utils.replaceVariables(resolver, keyring, openReplaceToken, closeReplaceToken));

    // if there are no producers defined we try to use the artifacts
    if (dataProducers.isEmpty()) {

        if (hasMainArtifact()) {
            Set<Artifact> artifacts = new HashSet<Artifact>();

            artifacts.add(project.getArtifact());

            @SuppressWarnings("unchecked")
            final Set<Artifact> projectArtifacts = project.getArtifacts();

            for (Artifact artifact : projectArtifacts) {
                artifacts.add(artifact);
            }

            @SuppressWarnings("unchecked")
            final List<Artifact> attachedArtifacts = project.getAttachedArtifacts();

            for (Artifact artifact : attachedArtifacts) {
                artifacts.add(artifact);
            }

            for (Artifact artifact : artifacts) {
                final File file = artifact.getFile();
                if (file != null) {
                    dataProducers.add(new DataProducer() {
                        @Override
                        public void produce(final DataConsumer receiver) {
                            try {
                                final File path = new File(installDirFile.getPath(), file.getName());
                                final String entryName = path.getPath();

                                final boolean symbolicLink = SymlinkUtils.isSymbolicLink(path);
                                final TarArchiveEntry e;
                                if (symbolicLink) {
                                    e = new TarArchiveEntry(entryName, TarConstants.LF_SYMLINK);
                                    e.setLinkName(SymlinkUtils.readSymbolicLink(path));
                                } else {
                                    e = new TarArchiveEntry(entryName, true);
                                }

                                e.setUserId(0);
                                e.setGroupId(0);
                                e.setUserName("root");
                                e.setGroupName("root");
                                e.setMode(TarEntry.DEFAULT_FILE_MODE);
                                e.setSize(file.length());

                                receiver.onEachFile(new FileInputStream(file), e);
                            } catch (Exception e) {
                                getLog().error(e);
                            }
                        }
                    });
                } else {
                    getLog().error("No file for artifact " + artifact);
                }
            }
        }
    }

    try {
        DebMaker debMaker = new DebMaker(console, dataProducers, conffileProducers);
        debMaker.setDeb(debFile);
        debMaker.setControl(controlDirFile);
        debMaker.setPackage(getProject().getArtifactId());
        debMaker.setDescription(getProject().getDescription());
        debMaker.setHomepage(getProject().getUrl());
        debMaker.setChangesIn(changesInFile);
        debMaker.setChangesOut(changesOutFile);
        debMaker.setChangesSave(changesSaveFile);
        debMaker.setCompression(compression);
        debMaker.setKeyring(keyringFile);
        debMaker.setKey(key);
        debMaker.setPassphrase(passphrase);
        debMaker.setSignPackage(signPackage);
        debMaker.setSignMethod(signMethod);
        debMaker.setSignRole(signRole);
        debMaker.setResolver(resolver);
        debMaker.setOpenReplaceToken(openReplaceToken);
        debMaker.setCloseReplaceToken(closeReplaceToken);
        debMaker.validate();
        debMaker.makeDeb();

        // Always attach unless explicitly set to false
        if ("true".equalsIgnoreCase(attach)) {
            console.info("Attaching created debian package " + debFile);
            if (!isType()) {
                projectHelper.attachArtifact(project, type, classifier, debFile);
            } else {
                project.getArtifact().setFile(debFile);
            }
        }

    } catch (PackagingException e) {
        getLog().error("Failed to create debian package " + debFile, e);
        throw new MojoExecutionException("Failed to create debian package " + debFile, e);
    }

    if (!isBlank(propertyPrefix)) {
        project.getProperties().put(propertyPrefix + "version", getProjectVersion());
        project.getProperties().put(propertyPrefix + "deb", debFile.getAbsolutePath());
        project.getProperties().put(propertyPrefix + "deb.name", debFile.getName());
        project.getProperties().put(propertyPrefix + "changes", changesOutFile.getAbsolutePath());
        project.getProperties().put(propertyPrefix + "changes.name", changesOutFile.getName());
        project.getProperties().put(propertyPrefix + "changes.txt", changesSaveFile.getAbsolutePath());
        project.getProperties().put(propertyPrefix + "changes.txt.name", changesSaveFile.getName());
    }

}