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.codehaus.mojo.unix.maven.plugin.MavenProjectWrapper.java

License:Open Source License

public static MavenProjectWrapper mavenProjectWrapper(final MavenProject project, MavenSession session) {
    SortedMap<String, String> properties = new TreeMap<String, String>();

    // This is perhaps not ideal. Maven uses reflection to dynamically extract properties from the project
    // when interpolating each file. This uses a static list that doesn't contain the project.* properties, except
    // the new we hard-code support for.
    ////from   ww w  . ja  va2s  .  c o  m
    // The user can work around this like this:
    // <properties>
    //   <project.build.directory>${project.build.directory}</project.build.directory>
    // </properties>
    //
    // If this has to change, the properties has to be a F<String, String> and interpolation tokens ("${" and "}")
    // has to be defined. Doable but too painful for now.
    properties.putAll(toMap(session.getSystemProperties()));
    properties.putAll(toMap(session.getUserProperties()));
    properties.putAll(toMap(project.getProperties()));
    properties.put("project.groupId", project.getGroupId());
    properties.put("project.artifactId", project.getArtifactId());
    properties.put("project.version", project.getVersion());

    return new MavenProjectWrapper(project.getGroupId(), project.getArtifactId(), project.getVersion(),
            project.getArtifact(), project.getName(), project.getDescription(), project.getBasedir(),
            new File(project.getBuild().getDirectory()), new LocalDateTime(), project.getArtifacts(),
            project.getLicenses(), new ArtifactMap(project.getArtifacts()), unmodifiableSortedMap(properties));
}

From source file:org.commonjava.emb.boot.log.EventLogger.java

License:Apache License

public void sessionStarted(final ExecutionEvent event) {
    if (logger.isInfoEnabled() && event.getSession().getProjects().size() > 1) {
        logger.info(chars('-', LINE_LENGTH));

        logger.info("Reactor Build Order:");

        logger.info("");

        for (final MavenProject project : event.getSession().getProjects()) {
            logger.info(project.getName());
        }/*from   w  w w.j  a  v a 2 s. c  o  m*/
    }
}

From source file:org.commonjava.emb.boot.log.EventLogger.java

License:Apache License

private void logReactorSummary(final MavenSession session) {
    logger.info(chars('-', LINE_LENGTH));

    logger.info("Reactor Summary:");

    logger.info("");

    final MavenExecutionResult result = session.getResult();

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

        buffer.append(project.getName());

        buffer.append(' ');
        while (buffer.length() < LINE_LENGTH - 21) {
            buffer.append('.');
        }//from w  w  w .  j av  a 2 s. c o  m
        buffer.append(' ');

        final BuildSummary buildSummary = result.getBuildSummary(project);

        if (buildSummary == null) {
            buffer.append("SKIPPED");
        } else if (buildSummary instanceof BuildSuccess) {
            buffer.append("SUCCESS [");
            buffer.append(getFormattedTime(buildSummary.getTime()));
            buffer.append("]");
        } else if (buildSummary instanceof BuildFailure) {
            buffer.append("FAILURE [");
            buffer.append(getFormattedTime(buildSummary.getTime()));
            buffer.append("]");
        }

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

From source file:org.ebayopensource.turmeric.maven.banrefs.reports.XmlReport.java

License:Open Source License

public XmlReport(Console console, MavenProject project, File outputFile) throws IOException {
    this.console = console;
    this.entryCount = 0;
    this.errorCount = 0;
    this.writer = new FileWriter(outputFile);
    this.out = new PrintWriter(writer);
    this.out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    this.out.printf("<banned-references-report module-root=\"%s\" module-name=\"%s\">%n",
            XmlUtil.escaped(project.getBasedir().getAbsolutePath()), XmlUtil.escaped(project.getName()));
}

From source file:org.ebayopensource.turmeric.maven.config.reports.XmlReport.java

License:Open Source License

public XmlReport(Console console, MavenProject project, File outputFile) throws IOException {
    super(console);
    this.writer = new FileWriter(outputFile);
    this.out = new PrintWriter(writer);
    this.out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    this.out.printf("<config-validation-report module-root=\"%s\" module-name=\"%s\">%n",
            XmlUtil.escaped(project.getBasedir().getAbsolutePath()), XmlUtil.escaped(project.getName()));
}

From source file:org.ebayopensource.turmeric.maven.license.reports.XmlReport.java

License:Open Source License

public XmlReport(Console console, MavenProject project, File outputFile) throws IOException {
    this.console = console;
    this.entryCount = 0;
    this.passCount = 0;
    this.violationCount = 0;
    this.failureCount = 0;
    this.writer = new FileWriter(outputFile);
    this.out = new PrintWriter(writer);
    this.out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    this.out.printf("<license-report module-root=\"%s\" module-name=\"%s\">%n",
            XmlUtil.escaped(project.getBasedir().getAbsolutePath()), XmlUtil.escaped(project.getName()));
}

From source file:org.eclipse.virgo.ide.bundlor.internal.core.maven.MavenPropertiesSource.java

License:Open Source License

public Properties getProperties() {
    try {/*  ww  w.  j  a  va 2  s . com*/
        IMavenProjectRegistry registry = MavenPlugin.getMavenProjectRegistry();
        IMavenProjectFacade facade = registry.create(this.project, new NullProgressMonitor());
        if (facade != null) {
            MavenProject mavenProj = facade.getMavenProject(new NullProgressMonitor());
            Properties props = mavenProj.getProperties();

            // add in some special maven properties
            addPropertyIfNotNull(props, "project.artifactId", mavenProj.getArtifactId()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "project.groupId", mavenProj.getGroupId()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "project.description", mavenProj.getDescription()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "project.name", mavenProj.getName()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "project.version", mavenProj.getVersion()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "pom.artifactId", mavenProj.getArtifactId()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "pom.groupId", mavenProj.getGroupId()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "pom.description", mavenProj.getDescription()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "pom.name", mavenProj.getName()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "pom.version", mavenProj.getVersion()); //$NON-NLS-1$

            return props;
        }
    } catch (CoreException e) {
        // this exception will be reported later on as the properties can't be reported.
    }
    return EMPTY_STANDARD;
}

From source file:org.gephi.maven.BuildMetadata.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    String gephiVersion = (String) project.getProperties().get("gephi.version");
    if (gephiVersion == null) {
        throw new MojoExecutionException("The 'gephi.version' property should be defined");
    }//  ww  w  .  ja v  a2 s .c  om
    getLog().debug("Building metadata for 'gephi.version=" + gephiVersion + "'");

    if (reactorProjects != null && reactorProjects.size() > 0) {
        getLog().debug("Found " + reactorProjects.size() + " projects in reactor");
        List<MavenProject> modules = new ArrayList<MavenProject>();
        for (MavenProject proj : reactorProjects) {
            if (proj.getPackaging().equals("nbm")) {
                String gephiVersionModule = proj.getProperties().getProperty("gephi.version");

                if (gephiVersionModule.equals(gephiVersion)) {
                    getLog().debug("Found 'nbm' project '" + proj.getName() + "' with artifactId="
                            + proj.getArtifactId() + " and groupId=" + proj.getGroupId());
                    modules.add(proj);
                } else {
                    getLog().debug("Ignored project '" + proj.getName() + "' based on 'gephi.version' value '"
                            + gephiVersionModule + "'");
                }
            }
        }

        ManifestUtils manifestUtils = new ManifestUtils(sourceManifestFile, getLog());

        // Get all modules with dependencies
        Map<MavenProject, List<MavenProject>> tree = ModuleUtils.getModulesTree(modules, getLog());

        //Download previous file
        File pluginsJsonFile = new File(outputDirectory, "plugins.json");
        try {
            URL url = new URL(metadataUrl + "plugins.json");
            URLConnection connection = url.openConnection();
            connection.setRequestProperty("User-Agent",
                    "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
            connection.connect();
            InputStream stream = connection.getInputStream();
            ReadableByteChannel rbc = Channels.newChannel(stream);
            FileOutputStream fos = new FileOutputStream(pluginsJsonFile);
            long read = fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
            rbc.close();
            stream.close();
            getLog().debug("Read " + read + "bytes from url '" + url + "' and write to '"
                    + pluginsJsonFile.getAbsolutePath() + "'");
        } catch (Exception e) {
            throw new MojoExecutionException("Error while downloading previous 'plugins.json'", e);
        }

        // Init json
        PluginsMetadata pluginsMetadata;
        Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
        if (pluginsJsonFile.exists()) {
            try {
                FileReader reader = new FileReader(pluginsJsonFile);
                pluginsMetadata = gson.fromJson(reader, PluginsMetadata.class);
                reader.close();
                getLog().debug("Read previous plugins.json file");
            } catch (JsonSyntaxException e) {
                throw new MojoExecutionException("Error while reading previous 'plugins.json'", e);
            } catch (JsonIOException e) {
                throw new MojoExecutionException("Error while reading previous 'plugins.json'", e);
            } catch (IOException e) {
                throw new MojoExecutionException("Error while reading previous 'plugins.json'", e);
            }
        } else {
            pluginsMetadata = new PluginsMetadata();
            pluginsMetadata.plugins = new ArrayList<PluginMetadata>();
            getLog().debug("Create plugins.json");
        }

        // Build metadata
        for (Map.Entry<MavenProject, List<MavenProject>> entry : tree.entrySet()) {
            MavenProject topPlugin = entry.getKey();
            PluginMetadata pm = new PluginMetadata();
            pm.id = topPlugin.getArtifactId();

            // Find previous
            boolean foundPrevious = false;
            for (PluginMetadata oldPm : pluginsMetadata.plugins) {
                if (oldPm.id.equals(pm.id)) {
                    pm = oldPm;
                    foundPrevious = true;
                    getLog().debug("Found matching plugin id=" + pm.id + " in previous plugins.json");
                    break;
                }
            }

            manifestUtils.readManifestMetadata(topPlugin, pm);
            pm.license = MetadataUtils.getLicenseName(topPlugin);
            pm.authors = MetadataUtils.getAuthors(topPlugin);
            pm.last_update = dateFormat.format(new Date());
            pm.readme = MetadataUtils.getReadme(topPlugin, getLog());
            pm.images = ScreenshotUtils.copyScreenshots(topPlugin,
                    new File(outputDirectory, "imgs" + File.separator + pm.id), "imgs" + "/" + pm.id + "/",
                    getLog());
            pm.homepage = MetadataUtils.getHomepage(topPlugin);
            pm.sourcecode = MetadataUtils.getSourceCode(topPlugin, getLog());

            if (pm.versions == null) {
                pm.versions = new HashMap<String, Version>();
            }
            Version v = new Version();
            v.last_update = dateFormat.format(new Date());
            v.url = gephiVersion + "/" + ModuleUtils.getModuleDownloadPath(entry.getKey(), entry.getValue(),
                    new File(outputDirectory, gephiVersion), getLog());
            pm.versions.put(gephiVersion, v);

            if (!foundPrevious) {
                pluginsMetadata.plugins.add(pm);
            }
        }

        String json = gson.toJson(pluginsMetadata);

        // Write json file
        try {
            FileWriter writer = new FileWriter(pluginsJsonFile);
            writer.append(json);
            writer.close();
        } catch (IOException ex) {
            throw new MojoExecutionException("Error while writing plugins.json file", ex);
        }
    } else {
        throw new MojoExecutionException("The project should be a reactor project");
    }
}

From source file:org.gephi.maven.CreateAutoUpdate.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    String gephiVersion = (String) project.getProperties().get("gephi.version");
    if (gephiVersion == null) {
        throw new MojoExecutionException("The 'gephi.version' property should be defined");
    }//  w w w. ja  va 2s .c o m

    File outputFolder = new File(outputDirectory, gephiVersion);
    if (outputFolder.mkdirs()) {
        getLog().debug("Folder '" + outputFolder.getAbsolutePath() + "' created.");
    }

    if (reactorProjects != null && reactorProjects.size() > 0) {
        Project antProject = registerNbmAntTasks();

        for (MavenProject proj : reactorProjects) {
            if (proj.getPackaging().equals("nbm")) {
                File moduleDir = proj.getFile().getParentFile();
                if (moduleDir != null && moduleDir.exists()) {
                    File targetDir = new File(moduleDir, "target");
                    if (targetDir.exists()) {
                        String gephiVersionModule = proj.getProperties().getProperty("gephi.version");
                        if (gephiVersionModule == null) {
                            throw new MojoExecutionException(
                                    "The 'gephi.version' property should be defined in project '"
                                            + proj.getName() + "'");
                        }
                        if (gephiVersionModule.equals(gephiVersion)) {
                            File[] nbmsFiles = targetDir.listFiles(new FilenameFilter() {
                                @Override
                                public boolean accept(File dir, String name) {
                                    return !name.startsWith(".") && name.endsWith(".nbm");
                                }
                            });
                            for (File nbmFile : nbmsFiles) {
                                try {
                                    FileUtils.copyFileToDirectory(nbmFile, outputFolder);
                                } catch (IOException ex) {
                                    getLog().error(
                                            "Error while copying nbm file '" + nbmFile.getAbsolutePath() + "'",
                                            ex);
                                }
                                getLog().info("Copying  '" + nbmFile + "' to '" + outputFolder.getAbsolutePath()
                                        + "'");
                            }
                        } else {
                            getLog().warn("The NBM of module '" + proj.getName()
                                    + "' has been ignored because its 'gephi.version' is '" + gephiVersionModule
                                    + "' while '" + gephiVersion + "' is expected");
                        }
                    } else {
                        getLog().error(
                                "The module target dir for project '" + proj.getName() + "' doesn't exists");
                    }
                } else {
                    getLog().error("The module dir for project '" + proj.getName() + "' doesn't exists");
                }
            }
        }

        // Create updates.xml
        String fileName = "updates.xml";
        MakeUpdateDesc descTask = (MakeUpdateDesc) antProject.createTask("updatedist");
        File xmlFile = new File(outputFolder, fileName);
        descTask.setDesc(xmlFile);
        FileSet fs = new FileSet();
        fs.setDir(outputFolder);
        fs.createInclude().setName("**/*.nbm");
        descTask.addFileset(fs);
        try {
            descTask.execute();
        } catch (BuildException ex) {
            throw new MojoExecutionException("Cannot create autoupdate site xml file", ex);
        }
        getLog().info("Generated autoupdate site content at " + outputFolder.getAbsolutePath());

        // Create compressed version of updates.xml
        try {
            GZipArchiver gz = new GZipArchiver();
            gz.addFile(xmlFile, fileName);
            File gzipped = new File(outputFolder, fileName + ".gz");
            gz.setDestFile(gzipped);
            gz.createArchive();
        } catch (ArchiverException ex) {
            throw new MojoExecutionException("Cannot create gzipped version of the update site xml file.", ex);
        } catch (IOException ex) {
            throw new MojoExecutionException("Cannot create gzipped version of the update site xml file.", ex);
        }
        getLog().info("Generated compressed autoupdate site content at " + outputFolder.getAbsolutePath());
    } else {
        throw new MojoExecutionException("This should be executed on the reactor project");
    }
}

From source file:org.gephi.maven.ManifestUtils.java

License:Apache License

/**
 * Check that the given project has the <em>AutoUpdate-Show-In-Client</em>
 * entry set to <em>false</em> in its manifest.
 *
 * @param proj project//from  w ww . jav a2 s .co  m
 * @throws MojoExecutionException if an error occurs
 */
protected void checkManifestShowClientFalse(MavenProject proj) throws MojoExecutionException {
    Manifest manifest = getManifest(proj);

    Manifest.Section mainSection = manifest.getMainSection();
    String showInClient = mainSection.getAttributeValue("AutoUpdate-Show-In-Client");
    if (showInClient == null || showInClient.isEmpty() || !showInClient.equals("false")) {
        throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName()
                + "' should contain a 'AutoUpdate-Show-In-Client' entry set at 'false'");
    }
}