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.sonatype.m2e.mavenarchiver.internal.AbstractMavenArchiverConfigurator.java

License:Open Source License

/**
 * Checks if the MANIFEST.MF needs to be regenerated. That is if :
 * <ul><li>it doesn't already exist</li>
 * <li>the maven project configuration changed</li>
 * <li>the maven project dependencies changed</li>
 * </ul> //  w w w .ja  va 2  s . co  m
 * Implementations can override this method to add pre-conditions.
 * @param manifest the MANIFEST.MF file to control
 * @param oldFacade the old maven facade project configuration
 * @param newFacade the new maven facade project configuration
 * @param monitor the progress monitor
 * @return true if the MANIFEST.MF needs to be regenerated
 */
protected boolean needsNewManifest(IFile manifest, IMavenProjectFacade oldFacade, IMavenProjectFacade newFacade,
        IProgressMonitor monitor) {

    if (!manifest.exists()) {
        return true;
    }
    //Can't compare to a previous state, so assuming it's unchanged
    //This situation actually occurs during incremental builds, 
    //when called from the buildParticipant
    if (oldFacade == null || oldFacade.getMavenProject() == null) {
        return false;
    }

    MavenProject newProject = newFacade.getMavenProject();
    MavenProject oldProject = oldFacade.getMavenProject();

    //Assume Sets of artifacts are actually ordered
    if (dependenciesChanged(
            oldProject.getArtifacts() == null ? null : new ArrayList<Artifact>(oldProject.getArtifacts()),
            newProject.getArtifacts() == null ? null : new ArrayList<Artifact>(newProject.getArtifacts()))) {
        return true;
    }

    Xpp3Dom oldArchiveConfig = getArchiveConfiguration(oldProject);
    Xpp3Dom newArchiveConfig = getArchiveConfiguration(newProject);

    if (newArchiveConfig != null && !newArchiveConfig.equals(oldArchiveConfig) || oldArchiveConfig != null) {
        return true;
    }

    //Name always not null
    if (!newProject.getName().equals(oldProject.getName())) {
        return true;
    }

    String oldOrganizationName = oldProject.getOrganization() == null ? null
            : oldProject.getOrganization().getName();
    String newOrganizationName = newProject.getOrganization() == null ? null
            : newProject.getOrganization().getName();

    if (newOrganizationName != null && !newOrganizationName.equals(oldOrganizationName)
            || oldOrganizationName != null && newOrganizationName == null) {
        return true;
    }
    return false;
}

From source file:org.sonatype.maven.shell.maven.internal.ExecutionEventLogger.java

License:Open Source License

@Override
public void sessionStarted(final ExecutionEvent event) {
    ensureThreadNotInterrupted();// ww  w.ja  v a2  s  .c om

    if (logger.isInfoEnabled() && event.getSession().getProjects().size() > 1) {
        logger.info(chars('-', lineLength));
        logger.info("Reactor Build Order:"); // TODO: i18n
        logger.info("");

        for (MavenProject project : event.getSession().getProjects()) {
            logger.info(project.getName());
        }
    }
}

From source file:org.sonatype.maven.shell.maven.internal.ExecutionEventLogger.java

License:Open Source License

private void logReactorSummary(final MavenSession session) {
    logger.info(chars('-', lineLength));
    logger.info("Reactor Summary:"); // TODO: i18n
    logger.info("");

    MavenExecutionResult result = session.getResult();

    for (MavenProject project : session.getProjects()) {
        StringBuilder buff = new StringBuilder(128);

        buff.append(project.getName());

        buff.append(' ');
        while (buff.length() < lineLength - 21) {
            buff.append('.');
        }//from www.  jav  a 2 s .co  m
        buff.append(' ');

        BuildSummary buildSummary = result.getBuildSummary(project);

        if (buildSummary == null) {
            buff.append("SKIPPED"); // TODO: i18n
        } else if (buildSummary instanceof BuildSuccess) {
            buff.append("SUCCESS ["); // TODO: i18n
            buff.append(getFormattedTime(buildSummary.getTime()));
            buff.append("]");
        } else if (buildSummary instanceof BuildFailure) {
            buff.append("FAILURE ["); // TODO: i18n
            buff.append(getFormattedTime(buildSummary.getTime()));
            buff.append("]");
        }

        logger.info(buff.toString());
    }

    logger.info("");
}

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

License:Apache License

public void beforeBuild(MavenSession bootSession, final MavenProject bootProject, MavenSession actualSession) {
    LOGGER.info("");
    LOGGER.info("------------------------------------------------------------------------");
    LOGGER.info("Bootstrapping " + bootProject.getName() + " " + bootProject.getVersion());
    LOGGER.info("------------------------------------------------------------------------");

    final List<File> projectDirs = new ArrayList<File>();
    for (MavenProject project : bootSession.getProjects()) {
        projectDirs.add(project.getBasedir());
    }/*w w  w .  j a  v  a2  s. com*/

    final int idx = bootSession.getProjects().indexOf(bootProject);
    checkState(idx > -1);

    final B2Request b2Request = b2RequestFactory.newRequest(projectDirs, idx);

    final AbstractModule module = b2LifecycleRunner.prepareNext(projectDirs, idx, b2Request);
    bootProject.setContextValue(AbstractModule.class.getName(), module);
    bootProject.setContextValue(ModuleDirectory.class.getName(), b2Request.getModuleDirectory());
}

From source file:org.sourcepit.maven.bootstrap.core.AbstractBootstrapper.java

License:Apache License

public void executionStarted(MavenSession actualSession, MavenExecutionRequest executionRequest)
        throws MavenExecutionException {
    final MavenSession bootSession = createBootSession(actualSession);

    final List<File> descriptors = getProjectDescriptors(bootSession);
    if (descriptors.isEmpty()) {
        logger.info("Skipping bootstrapper " + extensionKey + ". No projects found.");
        return;// w ww  . ja va  2  s .co  m
    }

    mapSessions(actualSession, bootSession);

    logger.info("Executing bootstrapper " + extensionKey + "...");

    plexusContainer.getContainerRealm().getWorld().addListener(importEnforcer);

    final MavenSession oldSession = legacySupport.getSession();
    try {
        legacySupport.setSession(bootSession);
        setupBootSession(bootSession, descriptors);

        final List<MavenProject> projects = bootSession.getProjects();
        if (projects.size() > 1) {
            logger.info("");
            logger.info("------------------------------------------------------------------------");
            logger.info("Bootstrapper Build Order:");
            logger.info("");
            for (MavenProject project : projects) {
                logger.info(project.getName());
            }
        }

        performBootSession(bootSession);
        adjustActualSession(bootSession, actualSession);

        logger.info("");
        logger.info("------------------------------------------------------------------------");
        logger.info("Finished bootstrapper " + extensionKey);
    } finally {
        legacySupport.setSession(oldSession);
    }
}

From source file:org.universAAL.support.directives.checks.MavenCoordinateCheck.java

License:Apache License

/** {@inheritDoc} */
public boolean check(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {

    String artifactIdMatchString = mavenProject.getProperties().getProperty(ARTIFACT_ID_MATCH_PROP,
            DEFAULT_MATCH);//from   w  w  w. ja va2  s. c  om
    String groupIdMatchString = mavenProject.getProperties().getProperty(GROUP_ID_MATCH_PROP, DEFAULT_MATCH);
    String nameMatchString = mavenProject.getProperties().getProperty(NAME_MATCH_PROP, DEFAULT_MATCH);
    String versionMatchString = mavenProject.getProperties().getProperty(VERSION_MATCH_PROP, DEFAULT_MATCH);

    Pattern pAId = Pattern.compile(artifactIdMatchString);
    Pattern pGId = Pattern.compile(groupIdMatchString);
    Pattern pVer = Pattern.compile(versionMatchString);
    Pattern pNam = Pattern.compile(nameMatchString);

    Matcher mAId = pAId.matcher(mavenProject.getArtifactId());
    Matcher mGId = pGId.matcher(mavenProject.getGroupId());
    Matcher mVer = pVer.matcher(mavenProject.getVersion());
    Matcher mNam = pNam.matcher(mavenProject.getName());

    StringBuffer message = new StringBuffer();

    if (!mAId.find()) {
        message.append("ArtifactId: " + mavenProject.getArtifactId() + DOES_NOT_MATCH_CONVENTION
                + artifactIdMatchString + "\n");
    }
    if (!mGId.find()) {
        message.append("GroupId: " + mavenProject.getGroupId() + DOES_NOT_MATCH_CONVENTION + groupIdMatchString
                + "\n");
    }
    if (!mVer.find()) {
        message.append("Version: " + mavenProject.getVersion() + DOES_NOT_MATCH_CONVENTION + versionMatchString
                + "\n");
    }
    if (!mNam.find()) {
        message.append("Artifact Name: " + mavenProject.getName() + DOES_NOT_MATCH_CONVENTION + nameMatchString
                + "\n");
    }

    if (message.length() > 0) {
        throw new MojoFailureException(message.toString());
    }
    Model pomFileModel = null;
    try {
        pomFileModel = PomWriter.readPOMFile(mavenProject);
    } catch (Exception e) {
    }

    if (!mavenProject.getPackaging().equals("pom") && pomFileModel != null
            && (pomFileModel.getProperties().containsKey(ARTIFACT_ID_MATCH_PROP)
                    || pomFileModel.getProperties().containsKey(GROUP_ID_MATCH_PROP)
                    || pomFileModel.getProperties().containsKey(VERSION_MATCH_PROP)
                    || pomFileModel.getProperties().containsKey(NAME_MATCH_PROP))) {
        throw new MojoFailureException("This project has declared naming conventions when it shoudln't.\n"
                + "This is probably an attempt to skip this directive, SHAME ON YOU!");
    }

    return true;
}

From source file:org.wildfly.swarm.plugin.bom.BomBuilder.java

License:Apache License

static String generateBOM(final MavenProject rootProject, final String template,
        final Collection<DependencyMetadata> bomItems) {

    return template
            .replace("#{dependencies}",
                    String.join("\n", bomItems.stream().map(BomBuilder::pomGav).collect(Collectors.toList())))
            .replace("#{bom-artifactId}", rootProject.getArtifactId())
            .replace("#{bom-name}", rootProject.getName())
            .replace("#{bom-description}", rootProject.getDescription());

}

From source file:org.wisdom.maven.utils.MavenUtils.java

License:Apache License

/**
 * Gets the default set of properties for the given project.
 *
 * @param currentProject the project/*from   w w w .j a v  a 2s. com*/
 * @return the set of properties, containing default bundle packaging instructions.
 */
public static Properties getDefaultProperties(MavenProject currentProject) {
    Properties properties = new Properties();
    String bsn = DefaultMaven2OsgiConverter.getBundleSymbolicName(currentProject.getArtifact());

    // Setup defaults
    properties.put(MAVEN_SYMBOLICNAME, bsn);
    properties.put("bundle.file.name",
            DefaultMaven2OsgiConverter.getBundleFileName(currentProject.getArtifact()));
    properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn);
    properties.put(Analyzer.IMPORT_PACKAGE, "*");
    properties.put(Analyzer.BUNDLE_VERSION, DefaultMaven2OsgiConverter.getVersion(currentProject.getVersion()));

    header(properties, Analyzer.BUNDLE_DESCRIPTION, currentProject.getDescription());
    StringBuilder licenseText = printLicenses(currentProject.getLicenses());
    if (licenseText != null) {
        header(properties, Analyzer.BUNDLE_LICENSE, licenseText);
    }
    header(properties, Analyzer.BUNDLE_NAME, currentProject.getName());

    if (currentProject.getOrganization() != null) {
        if (currentProject.getOrganization().getName() != null) {
            String organizationName = currentProject.getOrganization().getName();
            header(properties, Analyzer.BUNDLE_VENDOR, organizationName);
            properties.put("project.organization.name", organizationName);
            properties.put("pom.organization.name", organizationName);
        }
        if (currentProject.getOrganization().getUrl() != null) {
            String organizationUrl = currentProject.getOrganization().getUrl();
            header(properties, Analyzer.BUNDLE_DOCURL, organizationUrl);
            properties.put("project.organization.url", organizationUrl);
            properties.put("pom.organization.url", organizationUrl);
        }
    }

    properties.putAll(currentProject.getModel().getProperties());

    for (String s : currentProject.getFilters()) {
        File filterFile = new File(s);
        if (filterFile.isFile()) {
            properties.putAll(PropertyUtils.loadProperties(filterFile));
        }
    }

    properties.putAll(getProperties(currentProject.getModel(), "project.build."));
    properties.putAll(getProperties(currentProject.getModel(), "pom."));
    properties.putAll(getProperties(currentProject.getModel(), "project."));

    properties.put("project.baseDir", currentProject.getBasedir().getAbsolutePath());
    properties.put("project.build.directory", currentProject.getBuild().getDirectory());
    properties.put("project.build.outputdirectory", currentProject.getBuild().getOutputDirectory());

    properties.put("project.source.roots", getArray(currentProject.getCompileSourceRoots()));
    properties.put("project.testSource.roots", getArray(currentProject.getTestCompileSourceRoots()));

    properties.put("project.resources", toString(currentProject.getResources()));
    properties.put("project.testResources", toString(currentProject.getTestResources()));

    return properties;
}

From source file:pl.project13.maven.git.GitCommitIdMojo.java

License:Open Source License

private void appendPropertiesToReactorProjects(@NotNull Properties properties) {
    for (MavenProject mavenProject : reactorProjects) {
        Properties mavenProperties = mavenProject.getProperties();

        log(mavenProject.getName(), "] project", mavenProject.getName());

        for (Object key : properties.keySet()) {
            mavenProperties.put(key, properties.get(key));
        }/*from www. j ava 2s. co  m*/
    }
}

From source file:se.natusoft.tools.codelicmgr.MojoUtils.java

License:Open Source License

/**
 * This will take config values that are not specified or specified as blank and
 * look for that information elsewhere in the maven project and if found, update
 * the configuration with that information.
 * <p>//  w  w  w . j  av  a2  s  .c  om
 * The reason for this is to minimize duplication of information in the pom. Some
 * of the information managed by CodeLicenseManager is also available as standard
 * information in a pom and is used by site:site to generate documentation.
 *
 * @param project The CLM project config.
 * @param mavenProject Maven project info from pom.
 */
public static ProjectConfig updateConfigFromMavenProject(ProjectConfig project, MavenProject mavenProject) {
    // Project
    if (project == null) { // Will be null if no <project> tag is specified!
        project = new ProjectConfig();
    }
    if (isEmpty(project.getName())) {
        project.setName(getFirstNonEmpty(mavenProject.getName(), mavenProject.getArtifactId()));
    }
    if (isEmpty(project.getDescription())) {
        project.setDescription(mavenProject.getDescription());
    }

    // License
    LicenseConfig licenseConf = project.getLicense();
    if (licenseConf == null) {
        licenseConf = new LicenseConfig();
        project.setLicense(licenseConf);
    }
    if (licenseConf.getType() == null) {
        List<org.apache.maven.model.License> lics = mavenProject.getLicenses();
        if (lics != null && lics.size() >= 1) {
            org.apache.maven.model.License lic = lics.get(0);

            String licName = getLicenseName(lic.getName().replaceAll("-", " "));
            if (licName.trim().length() > 0) {
                licenseConf.setType(licName);
            }

            String licVer = getLicenseVersion(lic.getName().replaceAll("-", " "));
            if (licVer.trim().length() > 0) {
                licenseConf.setVersion(licVer);
            }
        }
    }

    // Copyright
    if (project.getCopyrights().getCopyrights().size() == 0) {
        CopyrightConfig copyrightConf = new CopyrightConfig();
        copyrightConf.setHolder(mavenProject.getOrganization().getName());
        copyrightConf.setYear(mavenProject.getInceptionYear());
        project.getCopyrights().addCopyright(copyrightConf);
    }

    return project;
}