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

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

Introduction

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

Prototype

public String getArtifactId() 

Source Link

Usage

From source file:hudson.gridmaven.PomInfo.java

License:Open Source License

public PomInfo(MavenProject project, PomInfo parent, String relPath) {
    this.name = new ModuleName(project);
    this.version = project.getVersion();
    this.displayName = project.getName();
    this.defaultGoal = project.getDefaultGoal();
    this.relativePath = relPath;
    this.parent = parent;
    if (parent != null)
        parent.children.add(name);/*from  w ww .  ja v  a  2  s.co m*/

    for (Dependency dep : (List<Dependency>) project.getDependencies())
        dependencies.add(new ModuleDependency(dep));

    MavenProject parentProject = project.getParent();
    if (parentProject != null)
        dependencies.add(new ModuleDependency(parentProject));
    if (parent != null)
        dependencies.add(parent.asDependency());

    addPluginsAsDependencies(project.getBuildPlugins(), dependencies);
    addReportPluginsAsDependencies(project.getReportPlugins(), dependencies);

    List<Extension> extensions = project.getBuildExtensions();
    if (extensions != null)
        for (Extension ext : extensions)
            dependencies.add(new ModuleDependency(ext));

    // when the parent POM uses a plugin and builds a plugin at the same time,
    // the plugin module ends up depending on itself
    dependencies.remove(asDependency());

    CiManagement ciMgmt = project.getCiManagement();
    if ((ciMgmt != null) && (ciMgmt.getSystem() == null || ciMgmt.getSystem().equals("hudson"))) {
        Notifier mailNotifier = null;
        for (Notifier n : (List<Notifier>) ciMgmt.getNotifiers()) {
            if (n.getType().equals("mail")) {
                mailNotifier = n;
                break;
            }
        }
        this.mailNotifier = mailNotifier;
    } else
        this.mailNotifier = null;

    this.groupId = project.getGroupId();
    this.artifactId = project.getArtifactId();
    this.packaging = project.getPackaging();
}

From source file:hudson.gridmaven.reporters.MavenArtifactArchiver.java

License:Open Source License

public boolean postBuild(MavenBuildProxy build, MavenProject pom, final BuildListener listener)
        throws InterruptedException, IOException {
    // artifacts that are known to Maven.
    Set<File> mavenArtifacts = new HashSet<File>();

    if (pom.getFile() != null) {// goals like 'clean' runs without loading POM, apparently.
        // record POM
        final MavenArtifact pomArtifact = new MavenArtifact(pom.getGroupId(), pom.getArtifactId(),
                pom.getVersion(), null, "pom", pom.getFile().getName(),
                Util.getDigestOf(new FileInputStream(pom.getFile())));

        final String repositoryUrl = pom.getDistributionManagementArtifactRepository() == null ? null
                : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getUrl());
        final String repositoryId = pom.getDistributionManagementArtifactRepository() == null ? null
                : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getId());

        mavenArtifacts.add(pom.getFile());
        pomArtifact.archive(build, pom.getFile(), listener);

        // record main artifact (if packaging is POM, this doesn't exist)
        final MavenArtifact mainArtifact = MavenArtifact.create(pom.getArtifact());
        if (mainArtifact != null) {
            File f = pom.getArtifact().getFile();
            mavenArtifacts.add(f);/*w  ww  . ja va2  s .c o m*/
            mainArtifact.archive(build, f, listener);
        }

        // record attached artifacts
        final List<MavenArtifact> attachedArtifacts = new ArrayList<MavenArtifact>();
        for (Artifact a : pom.getAttachedArtifacts()) {
            MavenArtifact ma = MavenArtifact.create(a);
            if (ma != null) {
                mavenArtifacts.add(a.getFile());
                ma.archive(build, a.getFile(), listener);
                attachedArtifacts.add(ma);
            }
        }

        // record the action
        build.executeAsync(new MavenBuildProxy.BuildCallable<Void, IOException>() {
            private static final long serialVersionUID = -7955474564875700905L;

            public Void call(MavenBuild build) throws IOException, InterruptedException {
                // if a build forks lifecycles, this method can be called multiple times
                List<MavenArtifactRecord> old = build.getActions(MavenArtifactRecord.class);
                if (!old.isEmpty())
                    build.getActions().removeAll(old);

                MavenArtifactRecord mar = new MavenArtifactRecord(build, pomArtifact, mainArtifact,
                        attachedArtifacts, repositoryUrl, repositoryId);
                build.addAction(mar);

                // TODO kutzi: why are the fingerprints recorded here?
                // I thought that is the job of MavenFingerprinter
                mar.recordFingerprints();

                return null;
            }
        });
    }

    // do we have any assembly artifacts?
    //        System.out.println("Considering "+assemblies+" at "+MavenArtifactArchiver.this);
    //        new Exception().fillInStackTrace().printStackTrace();
    if (assemblies != null) {
        for (File assembly : assemblies) {
            if (mavenArtifacts.contains(assembly))
                continue; // looks like this is already archived
            if (build.isArchivingDisabled()) {
                listener.getLogger().println("[JENKINS] Archiving disabled - not archiving " + assembly);
            } else {
                FilePath target = build.getArtifactsDir().child(assembly.getName());
                listener.getLogger().println("[JENKINS] Archiving " + assembly + " to " + target);
                new FilePath(assembly).copyTo(target);
                // TODO: fingerprint
            }
        }
    }

    return true;
}

From source file:hudson.gridmaven.reporters.MavenFingerprinter.java

License:Open Source License

/**
 * Mojos perform different dependency resolution, so we need to check this for each mojo.
 *//*from   w w  w .  j av  a2 s  .c  o m*/
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener,
        Throwable error) throws InterruptedException, IOException {
    // TODO (kutzi, 2011/09/06): it should be perfectly safe to move all these records to the
    // postBuild method as artifacts should only be added by mojos, but never removed/modified.
    record(pom.getArtifacts(), used);
    record(pom.getArtifact(), produced);
    record(pom.getAttachedArtifacts(), produced);
    record(pom.getGroupId() + ":" + pom.getArtifactId(), pom.getFile(), produced);

    return true;
}

From source file:hudson.gridmaven.reporters.MavenFingerprinter.java

License:Open Source License

private void recordParents(MavenBuildProxy build, MavenProject pom) throws IOException, InterruptedException {
    MavenProject parent = pom.getParent();
    while (parent != null) {
        File parentFile = parent.getFile();

        if (parentFile == null) {
            // Parent artifact contains no actual file, so we resolve against
            // the local repository
            ArtifactRepository localRepository = getLocalRepository(build.getMavenBuildInformation(), parent,
                    pom);// w w w. ja  v  a 2s  .c o m
            if (localRepository != null) {
                Artifact parentArtifact = getArtifact(parent);
                // Don't use ArtifactRepository.find(), for compatibility with Maven 2.x
                if (parentArtifact != null) {
                    parentFile = new File(localRepository.getBasedir(), localRepository.pathOf(parentArtifact));
                }
            }
        }

        if (parentFile != null) {
            // we need to include the artifact Id for poms as well, otherwise a
            // project with the same groupId would override its parent's
            // fingerprint
            record(parent.getGroupId() + ":" + parent.getArtifactId(), parentFile, used);
        }
        parent = parent.getParent();
    }
}

From source file:hudson.gridmaven.reporters.MavenFingerprinter.java

License:Open Source License

private Artifact getArtifact(MavenProject parent) {
    Artifact art = parent.getArtifact();
    if (art == null) {
        // happens for Maven 2.x
        DefaultArtifactHandler artifactHandler = new DefaultArtifactHandler("pom");
        art = new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(),
                VersionRange.createFromVersion(parent.getVersion()), null, "pom", "", artifactHandler);
    }//ww  w .  j av  a  2  s . c o  m
    return art;
}

From source file:hudson.gridmaven.reporters.MavenSiteArchiver.java

License:Open Source License

/**
 * In multi module builds pomBaseDir of the parent project is the same as parent build module root.
 *
 * @param build/*from   www .ja  va2  s.  c o  m*/
 * @param pom
 *
 * @return the relative path component to copy sites of multi module builds.
 * @throws IOException
 * @throws InterruptedException 
 */
private String getModuleName(MavenBuildProxy build, MavenProject pom) throws IOException, InterruptedException {
    String moduleRoot = build.execute(new BuildCallable<String, IOException>() {
        private static final long serialVersionUID = 1L;

        //@Override
        public String call(MavenBuild mavenBuild) throws IOException, InterruptedException {
            MavenModuleSetBuild moduleSetBuild = mavenBuild.getModuleSetBuild();
            if (moduleSetBuild == null) {
                throw new IOException("Parent build not found!");
            }
            return moduleSetBuild.getModuleRoot().getRemote();
        }
    });
    final File pomBaseDir = pom.getBasedir();
    final File remoteWorkspaceDir = new File(moduleRoot);
    if (pomBaseDir.equals(remoteWorkspaceDir)) {
        return "";
    } else {
        return pom.getArtifactId();
    }
}

From source file:hudson.gridmaven.util.ExecutionEventLogger.java

License:Apache License

private void append(StringBuilder buffer, MavenProject project) {
    buffer.append(" @ ").append(project.getArtifactId());
}

From source file:hudson.maven.ReactorReader.java

License:Apache License

public ReactorReader(Map<String, MavenProject> reactorProjects, File workspaceRoot) {
    projectsByGAV = reactorProjects;/*from   w  ww.  j a v  a  2s .c o m*/
    this.workspaceRoot = workspaceRoot;
    projectsByGA = new HashMap<String, List<MavenProject>>(reactorProjects.size() * 2);
    for (MavenProject project : reactorProjects.values()) {
        String key = ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId());

        List<MavenProject> projects = projectsByGA.get(key);

        if (projects == null) {
            projects = new ArrayList<MavenProject>(1);
            projectsByGA.put(key, projects);
        }

        projects.add(project);
    }

    repository = new WorkspaceRepository("reactor", new HashSet<String>(projectsByGAV.keySet()));
}

From source file:hudson.maven.ReactorReader.java

License:Apache License

/**
 * Tries to resolve the specified artifact from the artifacts of the given project.
 * /*from  w w w. ja v a  2  s  . c  o 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))) {
        mainArtifact.setFile(new File(workspaceRoot, project.getArtifactId()));
        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))) {
                attachedArtifact.setFile(new File(workspaceRoot, project.getArtifactId()));
                return attachedArtifact;
            }
        }
    }

    return null;
}

From source file:hudson.maven.ReactorReader.java

License:Apache License

public void addProject(MavenProject mavenProject) {
    String key = mavenProject.getGroupId() + ':' + mavenProject.getArtifactId();
    this.projectsByGA.put(key, Arrays.asList(mavenProject));

    String projectKey = mavenProject.getGroupId() + ':' + mavenProject.getArtifactId() + ':'
            + mavenProject.getVersion();

    this.projectsByGAV.put(projectKey, mavenProject);
}