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

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

Introduction

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

Prototype

public Artifact getArtifact() 

Source Link

Usage

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

License:Apache License

private Set<Artifact> getReactorArtifacts() {
    Set<Artifact> reactorArtifacts = new LinkedHashSet<Artifact>();
    for (MavenProject project : reactorProjects) {
        reactorArtifacts.add(project.getArtifact());
    }//from  w  ww.  j  a  v  a2 s.  c o  m
    return reactorArtifacts;
}

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

License:Apache License

/**
 * Returns the generated {@link org.apache.maven.project.MavenProject} to build.
 * This version of the project contains all the stuff needed for building (parents, profiles, properties etc).
 *
 * @param project The source {@link org.apache.maven.project.MavenProject}.
 * @param config  The {@link io.sundr.maven.BomConfig}.
 * @return The build {@link org.apache.maven.project.MavenProject}.
 *//*ww w .j  av a2 s.c o m*/
private static MavenProject toBuild(MavenProject project, BomConfig config) {
    File outputDir = new File(project.getBuild().getOutputDirectory());
    File bomDir = new File(outputDir, config.getArtifactId());
    File generatedBom = new File(bomDir, BOM_NAME);

    MavenProject toBuild = project.clone();
    //we want to avoid recursive "generate-bom".
    toBuild.setExecutionRoot(false);
    toBuild.setFile(generatedBom);
    toBuild.getModel().setPomFile(generatedBom);
    toBuild.setModelVersion(project.getModelVersion());

    toBuild.setArtifact(new DefaultArtifact(project.getGroupId(), config.getArtifactId(), project.getVersion(),
            project.getArtifact().getScope(), project.getArtifact().getType(),
            project.getArtifact().getClassifier(), project.getArtifact().getArtifactHandler()));

    toBuild.setParent(project.getParent());
    toBuild.getModel().setParent(project.getModel().getParent());

    toBuild.setGroupId(project.getGroupId());
    toBuild.setArtifactId(config.getArtifactId());
    toBuild.setVersion(project.getVersion());
    toBuild.setPackaging("pom");
    toBuild.setName(config.getName());
    toBuild.setDescription(config.getDescription());

    toBuild.setUrl(project.getUrl());
    toBuild.setLicenses(project.getLicenses());
    toBuild.setScm(project.getScm());
    toBuild.setDevelopers(project.getDevelopers());
    toBuild.setDistributionManagement(project.getDistributionManagement());
    toBuild.getModel().setProfiles(project.getModel().getProfiles());

    //We want to avoid having the generated stuff wiped.
    toBuild.getProperties().put("clean.skip", "true");
    toBuild.getModel().getBuild().setDirectory(bomDir.getAbsolutePath());
    toBuild.getModel().getBuild().setOutputDirectory(new File(bomDir, "target").getAbsolutePath());
    for (String key : config.getProperties().stringPropertyNames()) {
        toBuild.getProperties().put(key, config.getProperties().getProperty(key));
    }
    return toBuild;
}

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

License:Apache License

/**
 * Returns all the session/reactor artifacts topologically sorted.
 *
 * @return//  ww w.jav  a 2  s .  co m
 */
private Set<Artifact> getSessionArtifacts() {
    Set<Artifact> result = new LinkedHashSet<Artifact>();
    for (MavenProject p : getSession().getProjectDependencyGraph().getSortedProjects()) {
        result.add(p.getArtifact());
    }
    return result;
}

From source file:io.takari.maven.plugins.Deploy.java

License:Open Source License

private void installProject(MavenProject project) throws MojoExecutionException {

    DeployRequest deployRequest = new DeployRequest();

    if ("pom".equals(project.getPackaging())) {
        ////  ww  w .  j a va  2s  .  c  o  m
        // POM-project primary artifact
        //
        Artifact artifact = AetherUtils.toArtifact(project.getArtifact());
        artifact = artifact.setFile(project.getFile());
        deployRequest.addArtifact(artifact);

    } else {
        //
        // Primary artifact
        //
        Artifact artifact = AetherUtils.toArtifact(project.getArtifact());
        deployRequest.addArtifact(artifact);

        //
        // POM
        //
        Artifact pomArtifact = new SubArtifact(artifact, "", "pom");
        pomArtifact = pomArtifact.setFile(project.getFile());
        deployRequest.addArtifact(pomArtifact);
    }

    //
    // Attached artifacts
    //
    for (org.apache.maven.artifact.Artifact attachedArtifact : project.getAttachedArtifacts()) {
        deployRequest.addArtifact(AetherUtils.toArtifact(attachedArtifact));
    }

    deployRequest.setRepository(remoteRepository(project));

    try {
        repositorySystem.deploy(repositorySystemSession, deployRequest);
    } catch (DeploymentException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:io.takari.maven.plugins.Install.java

License:Open Source License

private void installProject(MavenProject project) throws MojoExecutionException {

    InstallRequest installRequest = new InstallRequest();

    if ("pom".equals(project.getPackaging())) {
        ////from w w  w .ja  v  a  2s.  c om
        // POM-project primary artifact
        //
        Artifact artifact = AetherUtils.toArtifact(project.getArtifact());
        artifact = artifact.setFile(project.getFile());
        installRequest.addArtifact(artifact);

    } else {
        //
        // Primary artifact
        //
        Artifact artifact = AetherUtils.toArtifact(project.getArtifact());
        installRequest.addArtifact(artifact);

        //
        // POM
        //
        Artifact pomArtifact = new SubArtifact(artifact, "", "pom");
        pomArtifact = pomArtifact.setFile(project.getFile());
        installRequest.addArtifact(pomArtifact);
    }

    //
    // Attached artifacts
    //
    for (org.apache.maven.artifact.Artifact attachedArtifact : project.getAttachedArtifacts()) {
        installRequest.addArtifact(AetherUtils.toArtifact(attachedArtifact));
    }

    try {
        repositorySystem.install(repositorySystemSession, installRequest);
    } catch (InstallationException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:io.takari.maven.workspace.GenerationsWorkspaceReader.java

License:Apache License

private Artifact findMatchingArtifact(MavenProject project, Artifact requestedArtifact) {
    String versionlessId = ArtifactIdUtils.toVersionlessId(requestedArtifact);
    Artifact mainArtifact = RepositoryUtils.toArtifact(project.getArtifact());
    if (versionlessId.equals(ArtifactIdUtils.toVersionlessId(mainArtifact))) {
        return mainArtifact;
    }/*from w ww.j  av  a2 s .  co m*/
    for (Artifact attachedArtifact : RepositoryUtils.toArtifacts(project.getAttachedArtifacts())) {
        if (attachedArtifactComparison(requestedArtifact, attachedArtifact)) {
            return attachedArtifact;
        }
    }
    return null;
}

From source file:ljpf.maven.MakePluginMojo.java

License:Apache License

protected void createAssembly(Assembly assembly, boolean attach)
        throws MojoFailureException, MojoExecutionException {
    try {//from w ww  . j  a va2 s  .  co  m
        final String fullName = AssemblyFormatUtils.getDistributionName(assembly, this);

        List<String> effectiveFormats = assembly.getFormats();

        if (effectiveFormats == null || effectiveFormats.size() == 0) {
            throw new MojoFailureException(
                    "No formats specified in the execution parameters or the assembly descriptor.");
        }

        for (final String format : effectiveFormats) {
            final File destFile = assemblyArchiver.createArchive(assembly, fullName, format, this, true,
                    getMergeManifestMode());

            final MavenProject project = getProject();
            final String type = project.getArtifact().getType();

            if (attach && destFile.isFile()) {
                if (isAssemblyIdAppended()) {
                    projectHelper.attachArtifact(project, format, assembly.getId(), destFile);
                } else if (!"pom".equals(type) && format.equals(type)) {
                    final File existingFile = project.getArtifact().getFile();
                    if ((existingFile != null) && existingFile.exists()) {
                        getLog().warn("Replacing pre-existing project main-artifact file: " + existingFile
                                + "\nwith assembly file: " + destFile);
                    }

                    project.getArtifact().setFile(destFile);
                } else {
                    projectHelper.attachArtifact(project, format, null, destFile);
                }
            } else if (attach) {
                getLog().warn("Assembly file: " + destFile + " is not a regular file (it may be a directory). "
                        + "It cannot be attached to the project build for installation or " + "deployment.");
            }
        }
    } catch (final ArchiveCreationException e) {
        throw new MojoExecutionException("Failed to create assembly: " + e.getMessage(), e);
    } catch (final AssemblyFormattingException e) {
        throw new MojoExecutionException("Failed to create assembly: " + e.getMessage(), e);
    } catch (final InvalidAssemblerConfigurationException e) {
        throw new MojoFailureException(assembly, "Assembly is incorrectly configured: " + assembly.getId(),
                "Assembly: " + assembly.getId() + " is not configured correctly: " + e.getMessage());
    }
}

From source file:mx.interware.maven.plugin.HookMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {

    System.out.println(" >> My Param: " + myparam);

    for (MavenProject project : reactorProjects) {
        Artifact artifact = project.getArtifact();
        System.out.println(" >> Deploy this file:" + getLocalRepoFile(artifact));
    }//w w w  .  j a  va 2 s .  c om

}

From source file:net.hasor.maven.ExecJavaMojo.java

License:Apache License

/**
 * Resolve the executable dependencies for the specified project
 * /*from   ww  w  . j a va  2s  .  c  o m*/
 * @param executablePomArtifact the project's POM
 * @return a set of Artifacts
 * @throws MojoExecutionException if a failure happens
 */
private Set<Artifact> resolveExecutableDependencies(Artifact executablePomArtifact)
        throws MojoExecutionException {
    Set<Artifact> executableDependencies;
    try {
        MavenProject executableProject = this.projectBuilder.buildFromRepository(executablePomArtifact,
                this.remoteRepositories, this.localRepository);
        // get all of the dependencies for the executable project
        List<Dependency> dependencies = executableProject.getDependencies();
        // make Artifacts of all the dependencies
        Set<Artifact> dependencyArtifacts = MavenMetadataSource.createArtifacts(this.artifactFactory,
                dependencies, null, null, null);
        // not forgetting the Artifact of the project itself
        dependencyArtifacts.add(executableProject.getArtifact());
        // resolve all dependencies transitively to obtain a comprehensive list of assemblies
        ArtifactResolutionResult result = artifactResolver.resolveTransitively(dependencyArtifacts,
                executablePomArtifact, Collections.emptyMap(), this.localRepository, this.remoteRepositories,
                metadataSource, null, Collections.emptyList());
        executableDependencies = result.getArtifacts();
    } catch (Exception ex) {
        throw new MojoExecutionException("Encountered problems resolving dependencies of the executable "
                + "in preparation for its execution.", ex);
    }
    return executableDependencies;
}

From source file:net.java.jpatch.maven.PatchMojo.java

License:Apache License

/**
 * Creates the patch.//  www. j a v  a2s . c o  m
 * 
 * @exception  MojoExecutionException if the method fails.
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    // Create new patch artifact
    Artifact patchArtifact = createNewPatchArtifact();

    // Creates release directory.
    File releaseDirectory = setupReleaseDirectory();

    // Setup release
    Properties releaseProperties = loadReleaseProperties();

    // Load project for the patch
    List<MavenProject> mavenProjects = loadMavenProjectsForPatch(releaseProperties, patchArtifact);

    // Check project
    if (mavenProjects == null || mavenProjects.isEmpty()) {
        getLog().warn("The list of maven projects is empty! Nothing to build");
    } else {

        // Create patch directory
        File outputDirectory = createTargetDirectory(patchArtifact.getVersion());

        // Exclude directory and files
        if (excludesFromPatch == null) {
            excludesFromPatch = new ArrayList<String>();
        }
        excludesFromPatch.addAll(Arrays.asList(DEFAULT_EXCLUDE_PATH));
        Set<String> exclude = new HashSet<String>(excludesFromPatch);

        // Removes the directory and files
        if (removesFromPatch == null) {
            removesFromPatch = new ArrayList<String>();
            removesFromPatch.addAll(Arrays.asList(DEFAULT_REMOVE_PATH));
        }
        Set<String> remove = new HashSet<String>(removesFromPatch);

        // Copy and unpack the project in the patch directory
        for (MavenProject project : mavenProjects) {
            Artifact artifact = project.getArtifact();
            resolveArtifactFromLocalRepository(artifact);
            File libDir = unpackArtifactFile(outputDirectory, artifact.getFile());

            // Remove same files frtom the patch
            File releaseLib = new File(releaseDirectory, libDir.getName());
            removeNoChangedFiles(releaseLib, libDir, exclude, remove);
        }

        // Create patch for the release.
        createPatch(outputDirectory, patchArtifact);
    }
}