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

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

Introduction

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

Prototype

public String getName() 

Source Link

Usage

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

License:Apache License

private boolean buildPlanEqual(List<MavenProject> newPlan, List<MavenProject> oldPlan) {
    if (newPlan.size() != oldPlan.size()) {
        return false;
    }//from w  ww  . j  ava  2s . com
    int seq = 0;
    for (Iterator<MavenProject> i = newPlan.iterator(), j = oldPlan.iterator(); i.hasNext() && j.hasNext();) {
        MavenProject left = i.next();
        MavenProject right = j.next();
        getLog().debug("[" + (seq++) + "] = " + left.equals(right) + (left == right ? " same" : " diff") + " : "
                + left.getName() + "[" + left.getDependencies().size() + "], " + right.getName() + "["
                + right.getDependencies().size() + "]");
        if (!left.equals(right)) {
            return false;
        }
        if (left.getDependencies().size() != right.getDependencies().size()) {
            getLog().info("Dependency tree of " + left.getId() + " has been modified");
        }
    }
    return true;
}

From source file:org.jvnet.hudson.maven3.listeners.MavenProjectInfo.java

License:Apache License

public MavenProjectInfo(MavenProject mavenProject) {
    this.displayName = mavenProject.getName();
    this.groupId = mavenProject.getGroupId();
    this.artifactId = mavenProject.getArtifactId();
    this.version = mavenProject.getVersion();
}

From source file:org.kaazing.license.maven.plugin.VerifyNotice.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    Set<MavenProject> dependenciesMavenProject = new TreeSet<MavenProject>(new MavenProjectComparator());
    loadAllDepenencyProject(dependenciesMavenProject, getProject());
    List<MavenProject> dependenciesMavenProjectList = new ArrayList<MavenProject>(dependenciesMavenProject);
    StringBuilder sb = new StringBuilder();
    for (MavenProject dependencyProj : dependenciesMavenProjectList) {

        String version = dependencyProj.getVersion();
        String[] versions = version.split("\\.");
        // attempt to just get major minor version of dependency
        if (versions.length == 1) {
            version = versions[0];//from   w ww. ja  v a2  s. com
        } else if (versions.length >= 2) {
            version = versions[0] + "." + versions[1];
        }
        sb.append(String.format("This product depends on %s %s\n\n", dependencyProj.getName(), version));

        // add license to notice
        List<License> licenses = getLicenses(dependencyProj);
        if (licenses.size() > 0) {
            // if have license add them
            for (License license : licenses) {
                sb.append(formatLicense(license.getUrl(), license.getName()));
            }
        } else {
            // else attempt adding license from hints
            ProjectDescription description = getProjectDescriptionFromHints(dependencyProj);
            if (description != null) {
                sb.append(formatLicense(description.getLicenseUrl(), description.getLicenseName()));
            } else if (!strict) {
                sb.append("\tLicense is not included in maven artifact, look at homepage for license\t\n");
            } else {
                throw new MojoFailureException("Artifact " + dependencyProj.getArtifactId() + " with name \""
                        + dependencyProj.getName() + "\""
                        + " does not have a license in pom, include it in plugin configuration");
            }
        }

        // add homepage to notice
        String homePage = dependencyProj.getUrl();
        if (homePage != null) {
            sb.append(String.format("\tHomepage:\t%s\n", homePage));
        } else {
            ProjectDescription description = getProjectDescriptionFromHints(dependencyProj);
            if (description != null) {
                sb.append(String.format("\tHomepage:\t%s\n", description.getHomePage()));
            } else if (!strict) {
                sb.append(
                        "Home page is not included in maven artifact, and thus couldn't be referenced here\n");
            } else {
                throw new MojoFailureException("Artifact " + dependencyProj.getArtifactId()
                        + " does not have a homepage in pom, include it in plugin configuration");
            }
        }

        // add new line for formatting
        sb.append("\n");
    }
    if (modifiedCode != null && !modifiedCode.isEmpty()) {
        Collections.sort(modifiedCode, new ProjectDescriptionComparator());
        for (ProjectDescription modifiedCodeInstance : modifiedCode) {
            sb.append(format("This product contains a modified version of %s %s\n\n",
                    modifiedCodeInstance.getProjectName(), modifiedCodeInstance.getVersion()));
            sb.append(format("\tLicense:\t%s (%s)\n", modifiedCodeInstance.getLicenseName(),
                    modifiedCodeInstance.getLicenseUrl()));
            sb.append(format("\tHomepage:\t%s\n\n", modifiedCodeInstance.getHomePage()));
        }
    }

    // If there are dependencies or modified code, write it to the output file
    if (!(dependenciesMavenProjectList.isEmpty() && (modifiedCode == null || modifiedCode.isEmpty()))) {
        new File(new File(noticeOutput).getParent()).mkdirs();
        try (PrintWriter out = new PrintWriter(noticeOutput)) {
            out.write(sb.toString());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            throw new MojoFailureException("Failed to save notice to output file ", e);
        }
    }

    // If matching with existing, attempt match
    if (matchWithExisting) {
        try {
            boolean cmp = compareFilesLineByLine(notice, noticeOutput);
            if (!cmp) {
                throw new MojoFailureException(notice + " does not equal generated " + noticeOutput);
            }
        } catch (IOException e) {
            e.printStackTrace();
            throw new MojoFailureException("Failed to compare notice files", e);
        }
    }

}

From source file:org.kaazing.license.maven.plugin.VerifyNotice.java

License:Open Source License

private ProjectDescription getProjectDescriptionFromHints(MavenProject dependencyProj) {
    ProjectDescription result = null;//from ww w .ja va  2s.c  o  m
    if (!(projectHints == null || projectHints.isEmpty())) {
        for (ProjectDescription description : projectHints) {
            if (description.getProjectName().equalsIgnoreCase(dependencyProj.getName())) {
                result = description;
                break;
            }
        }
    }
    return result;
}

From source file:org.kloeckner.maven.plugin.util.VersionRangeUtils.java

License:Apache License

public static String rewriteParent(MavenProject project, Element rootElement, Namespace namespace,
        Map<String, String> mappedVersions, Map<String, String> originalVersions)
        throws MojoExecutionException {
    String parentVersion = null;/*from   ww  w  .jav a2 s  .  c o  m*/
    if (project.hasParent()) {
        Element parentElement = rootElement.getChild("parent", namespace);
        Element versionElement = parentElement.getChild("version", namespace);
        MavenProject parent = project.getParent();
        String key = ArtifactUtils.versionlessKey(parent.getGroupId(), parent.getArtifactId());
        parentVersion = mappedVersions.get(key);
        //         if (parentVersion == null) {
        //            //MRELEASE-317
        //            parentVersion = getResolvedSnapshotVersion(key, resolvedSnapshotDependencies);
        //         }
        if (parentVersion == null) {
            if (parent.getVersion().equals(originalVersions.get(key))) {
                throw new MojoExecutionException(
                        "Version for parent '" + parent.getName() + "' was not mapped");
            }
        } else {
            rewriteValue(versionElement, parentVersion);
        }
    }
    return parentVersion;
}

From source file:org.kloeckner.maven.plugin.util.VersionRangeUtils.java

License:Apache License

public static void rewriteVersion(Element rootElement, Namespace namespace, Map<String, String> mappedVersions,
        String projectId, MavenProject project, String parentVersion) throws MojoExecutionException {
    Element versionElement = rootElement.getChild("version", namespace);
    String version = mappedVersions.get(projectId);
    if (version == null) {
        throw new MojoExecutionException("Version for '" + project.getName() + "' was not mapped");
    }//from  ww  w .ja va 2s.c o  m

    if (versionElement == null) {
        if (!version.equals(parentVersion)) {
            // we will add this after artifactId, since it was missing but different from the inherited version
            Element artifactIdElement = rootElement.getChild("artifactId", namespace);
            int index = rootElement.indexOf(artifactIdElement);

            versionElement = new Element("version", namespace);
            versionElement.setText(version);
            rootElement.addContent(index + 1, new Text("\n  "));
            rootElement.addContent(index + 2, versionElement);
        }
    } else {
        rewriteValue(versionElement, version);
    }
}

From source file:org.linuxstuff.mojo.licensing.CheckMojo.java

protected LicensingReport generateReport(MavenProject project) {

    LicensingReport aReport = new LicensingReport();

    Collection<MavenProject> projects = getProjectDependencies(project);
    for (MavenProject mavenProject : projects) {

        ArtifactWithLicenses entry = new ArtifactWithLicenses();

        entry.setArtifactId(mavenProject.getId());
        entry.setName(mavenProject.getName());

        Set<String> licenses = collectLicensesForMavenProject(mavenProject);

        if (licenses.isEmpty()) {
            getLog().warn("Licensing: The artifact " + mavenProject.getId() + " has no license specified.");
            aReport.addMissingLicense(entry);
        } else {//ww w.j a  v  a2  s  . co m
            for (String license : licenses) {
                entry.addLicense(license);
            }

            if (isDisliked(mavenProject)) {
                getLog().warn("Licensing: The artifact " + mavenProject.getId()
                        + " is only under a disliked license.");
                aReport.addDislikedArtifact(entry);
            } else {
                aReport.addLicensedArtifact(entry);
            }

        }

    }

    return aReport;
}

From source file:org.objectstyle.woproject.maven2.javamonitor.JavaMonitorDeployMojo.java

License:Open Source License

/**
 * Generates the site structure using the project hiearchy (project and its
 * modules) or using the distributionManagement elements from the pom.xml.
 *
 * @param project//from w  w  w  . j a  va  2  s  .c o m
 * @param ignoreMissingSiteUrl
 * @return the structure relative path
 * @throws MojoFailureException
 *             if any
 */
protected static String getStructure(MavenProject project, boolean ignoreMissingSiteUrl)
        throws MojoFailureException {
    if (project.getDistributionManagement() == null) {
        String hierarchy = project.getArtifactId();

        MavenProject parent = project.getParent();
        while (parent != null) {
            hierarchy = parent.getArtifactId() + "/" + hierarchy;
            parent = parent.getParent();
        }

        return hierarchy;
    }

    Site site = project.getDistributionManagement().getSite();
    if (site == null) {
        if (!ignoreMissingSiteUrl) {
            throw new MojoFailureException(
                    "Missing site information in the distribution management element in the project: '"
                            + project.getName() + "'.");
        }

        return null;
    }

    if (StringUtils.isEmpty(site.getUrl())) {
        if (!ignoreMissingSiteUrl) {
            throw new MojoFailureException("The URL in the site is missing in the project descriptor.");
        }

        return null;
    }

    Repository repository = new Repository(site.getId(), site.getUrl());
    StringBuffer hierarchy = new StringBuffer(1024);
    hierarchy.append(repository.getHost());
    if (!StringUtils.isEmpty(repository.getBasedir())) {
        if (!repository.getBasedir().startsWith("/")) {
            hierarchy.append('/');
        }
        hierarchy.append(repository.getBasedir());
    }

    return hierarchy.toString().replaceAll("[\\:\\?\\*]", "");
}

From source file:org.openspaces.maven.plugin.RunPUMojo.java

License:Apache License

/**
 * Prepares and executes the PU.//  w  w w  . j  a  v  a2  s.c  o m
 *
 * @throws MojoExecutionException
 * @throws MojoFailureException
 */
private void executePU(MavenProject project) throws MojoExecutionException, MojoFailureException {
    if (project == null || !project.getPackaging().equalsIgnoreCase("jar")) {
        throw new MojoExecutionException("The processing unit project '"
                + (project == null ? "unknown" : project.getName()) + "' must be of type jar (packaging=jar).");
    }

    // run the PU
    PluginLog.getLog().info("Running processing unit: " + project.getBuild().getFinalName());

    // resolve the classpath for the execution of the processing unit
    List classpath = null;
    ClassLoader classLoader = null;
    try {
        String[] includeScopes = Utils.convertCommaSeparatedListToArray(scopes);
        classpath = Utils.resolveExecutionClasspath(project, includeScopes, true, reactorProjects,
                dependencyTreeBuilder, metadataSource, artifactCollector, artifactResolver, artifactFactory,
                localRepository, remoteRepositories);
        PluginLog.getLog().info("Processing unit [" + project.getName() + "] classpath: " + classpath);
        classLoader = Utils.createClassLoader(classpath, null);
    } catch (Exception e1) {
        throw new MojoExecutionException("Failed to resolve the processing unit's  classpath", e1);
    }

    // set groups
    if (groups != null && !groups.trim().equals("")) {
        SystemInfo.singleton().lookup().setGroups(groups);
    }

    // set locators
    if (locators != null && !locators.trim().equals("")) {
        SystemInfo.singleton().lookup().setLocators(locators);
    }

    // execute the processing unit in the new class loader 
    ContainerRunnable conatinerRunnable = new ContainerRunnable(
            "org.openspaces.pu.container.integrated.IntegratedProcessingUnitContainer",
            createAttributesArray());
    Thread thread = new Thread(conatinerRunnable,
            "Processing Unit [" + project.getBuild().getFinalName() + "]");
    thread.setContextClassLoader(classLoader);
    thread.start();
    while (!conatinerRunnable.hasStarted()) {
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
        }
    }
    if (conatinerRunnable.getException() != null) {
        Utils.throwMissingLicenseException(conatinerRunnable.getException(), localRepository);
        throw new MojoExecutionException(
                "Failed to start processing unit [" + project.getBuild().getFinalName() + "]",
                conatinerRunnable.getException());
    }
    containers.add(thread);
}

From source file:org.openspaces.maven.plugin.RunStandalonePUMojo.java

License:Apache License

/**
 * Prepares and executes the PU.//from  ww  w .  j a  v a 2s.  co  m
 *
 * @throws MojoExecutionException
 * @throws MojoFailureException
 */
private void executePU(MavenProject project) throws MojoExecutionException, MojoFailureException {
    if (project == null || !project.getPackaging().equalsIgnoreCase("jar")) {
        throw new MojoExecutionException("The processing unit project '"
                + (project == null ? "unknown" : project.getName()) + "' must be of type jar (packaging=jar).");
    }

    // resolve the classpath for the execution of the processing unit
    List<URL> classpath;
    ClassLoader classLoader;
    try {
        String[] includeScopes = Utils.convertCommaSeparatedListToArray(scopes);
        classpath = Utils.resolveExecutionClasspath(project, includeScopes, false, reactorProjects,
                dependencyTreeBuilder, metadataSource, artifactCollector, artifactResolver, artifactFactory,
                localRepository, remoteRepositories);
        PluginLog.getLog().info("Processing unit [" + project.getName() + "] classpath: " + classpath);
        classLoader = Utils.createClassLoader(classpath, null);
    } catch (Exception e1) {
        throw new MojoExecutionException("Failed to resolve the processing unit's classpath", e1);
    }

    if (groups != null && !groups.trim().equals("")) {
        SystemInfo.singleton().lookup().setGroups(groups);
    }
    if (locators != null && !locators.trim().equals("")) {
        SystemInfo.singleton().lookup().setLocators(locators);
    }

    // run the PU
    PluginLog.getLog().info("Running processing unit: " + project.getBuild().getFinalName());

    ContainerRunnable conatinerRunnable = new ContainerRunnable(
            "org.openspaces.pu.container.standalone.StandaloneProcessingUnitContainer",
            createAttributesArray(Utils.getProcessingUnitJar((project))));
    Thread thread = new Thread(conatinerRunnable,
            "Processing Unit [" + project.getBuild().getFinalName() + "]");
    thread.setContextClassLoader(classLoader);
    thread.start();
    while (!conatinerRunnable.hasStarted()) {
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
        }
    }
    if (conatinerRunnable.getException() != null) {
        Utils.throwMissingLicenseException(conatinerRunnable.getException(), localRepository);
        throw new MojoExecutionException(
                "Failed to start processing unit [" + project.getBuild().getFinalName() + "]",
                conatinerRunnable.getException());
    }
    containers.add(thread);
}