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.gephi.maven.ManifestUtils.java

License:Apache License

protected void readManifestMetadata(MavenProject proj, PluginMetadata metadata) throws MojoExecutionException {
    Manifest manifest = getManifest(proj);

    // Read branding attributes
    Manifest.Section mainSection = manifest.getMainSection();
    String brandingName = mainSection.getAttributeValue("OpenIDE-Module-Name");
    String brandingShortDescription = mainSection.getAttributeValue("OpenIDE-Module-Short-Description");
    String brandingLongDescrption = mainSection.getAttributeValue("OpenIDE-Module-Long-Description");
    String brandingDisplayCategory = mainSection.getAttributeValue("OpenIDE-Module-Display-Category");

    //Read localized
    if (mainSection.getAttribute("OpenIDE-Module-Localizing-Bundle") != null) {
        File folder = proj.getBasedir();
        String path = mainSection.getAttributeValue("OpenIDE-Module-Localizing-Bundle");
        File bundlerFile = new File(folder, "src" + File.separator + "main" + File.separator + "resources");
        if (!bundlerFile.exists()) {
            throw new MojoExecutionException(
                    "The 'src/main/resources' folder can't be found in '" + folder.getAbsolutePath() + "'");
        }//from ww  w  .  ja v  a 2  s  .com
        bundlerFile = new File(bundlerFile, path.replace('/', File.separatorChar));
        if (!bundlerFile.exists()) {
            throw new MojoExecutionException("The '" + path + "' file can't be found");
        }
        Properties prop = new Properties();
        FileReader bundleReader = null;
        try {
            bundleReader = new FileReader(bundlerFile);
            prop.load(bundleReader);
            brandingName = prop.getProperty("OpenIDE-Module-Name", brandingName);
            brandingDisplayCategory = prop.getProperty("OpenIDE-Module-Display-Category",
                    brandingDisplayCategory);
            brandingShortDescription = prop.getProperty("OpenIDE-Module-Short-Description",
                    brandingShortDescription);
            brandingLongDescrption = prop.getProperty("OpenIDE-Module-Long-Description",
                    brandingLongDescrption);
        } catch (IOException e) {
            throw new MojoExecutionException("Error while reading '" + bundlerFile.getAbsolutePath() + "'", e);
        } finally {
            if (bundleReader != null) {
                try {
                    bundleReader.close();
                } catch (IOException ex) {
                }
            }
        }
    }

    if (brandingName == null || brandingName.isEmpty()) {
        throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName()
                + "' should contain a 'OpenIDE-Module-Name' entry");
    }
    if (brandingShortDescription == null || brandingShortDescription.isEmpty()) {
        throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName()
                + "' should contain a 'OpenIDE-Module-Short-Description' entry");
    }
    if (brandingLongDescrption == null || brandingLongDescrption.isEmpty()) {
        throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName()
                + "' should contain a 'OpenIDE-Module-Long-Description' entry");
    }
    if (brandingDisplayCategory == null || brandingDisplayCategory.isEmpty()) {
        throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName()
                + "' should contain a 'OpenIDE-Module-Display-Category' entry");
    }

    if (!validateCategory(brandingDisplayCategory)) {
        throw new MojoExecutionException("The manifest entry 'OpenIDE-Module-Display-Category' is '"
                + brandingDisplayCategory + "' but should be one of the following values: "
                + Arrays.toString(CATEGORIES).replace("[", "").replace("]", ""));
    }

    metadata.name = brandingName;
    metadata.short_description = brandingShortDescription;
    metadata.long_description = brandingLongDescrption;
    metadata.category = brandingDisplayCategory;
}

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

License:Apache License

/**
 * Find and return the Manifest for the given project.
 *
 * @param proj project/*from   w w w . j a va  2 s .c  o m*/
 * @return manifest
 * @throws MojoExecutionException if an error occurs
 */
protected Manifest getManifest(MavenProject proj) throws MojoExecutionException {
    // Read project manifest file
    File manifestFile = new File(proj.getBasedir(), sourceManifestFile);
    if (!manifestFile.exists()) {
        throw new MojoExecutionException("Cannot locate a manifest.mf file at " + manifestFile.getAbsolutePath()
                + " for project " + proj.getName());
    }

    // Check validity
    ExamineManifest examinator = new ExamineManifest(log);
    examinator.setManifestFile(manifestFile);
    examinator.checkFile();

    // Read manifest
    Manifest manifest = null;
    Reader reader = null;
    try {
        reader = new InputStreamReader(new FileInputStream(manifestFile));
        manifest = new Manifest(reader);
    } catch (IOException exc) {
        throw new MojoExecutionException("Error reading manifest at " + manifestFile, exc);
    } catch (ManifestException ex) {
        throw new MojoExecutionException("Error reading manifest at " + manifestFile, ex);
    } finally {
        IOUtil.close(reader);
    }
    return manifest;
}

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

License:Apache License

/**
 * Lookup and return the content of the README.md file for this plugin.
 *
 * @param project project//ww  w .  j  a  va2 s .  c  om
 * @param log log
 * @return content of REDME.md file or null if not found
 */
protected static String getReadme(MavenProject project, Log log) {
    File readmePath = new File(project.getBasedir(), "README.md");
    if (readmePath.exists()) {
        log.debug("README.md file has been found: '" + readmePath.getAbsolutePath() + "'");
        try {
            StringBuilder builder = new StringBuilder();
            LineNumberReader fileReader = new LineNumberReader(new FileReader(readmePath));
            String line;
            while ((line = fileReader.readLine()) != null) {
                builder.append(line);
                builder.append("\n");
            }
            log.info("File README.md with " + builder.length() + " characters has been attached to project '"
                    + project.getName() + "'");
            return builder.toString();
        } catch (IOException ex) {
            log.error("Error while reading README.md file", ex);
        }
    }
    return null;
}

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

License:Apache License

/**
 * Investigate modules dependencies and return a map where keys are
 * top-level modules and values are all modules that it depends on plus the
 * key module.// w  ww  . ja  va  2 s .co m
 *
 * @param modules list of modules
 * @param log log
 * @return map that represents the tree of modules
 */
protected static Map<MavenProject, List<MavenProject>> getModulesTree(List<MavenProject> modules, Log log) {
    Map<MavenProject, List<MavenProject>> result = new LinkedHashMap<MavenProject, List<MavenProject>>();
    for (MavenProject proj : modules) {
        List<Dependency> dependencies = proj.getDependencies();
        log.debug("Investigating the " + dependencies.size() + " dependencies of project '" + proj.getName()
                + "'");

        // Init
        List<MavenProject> deps = new ArrayList<MavenProject>();
        deps.add(proj);
        result.put(proj, deps);

        // Add all module-based dependencies
        for (Dependency d : dependencies) {
            for (MavenProject projDependency : modules) {
                if (projDependency != proj && projDependency.getArtifactId().equals(d.getArtifactId())
                        && projDependency.getGroupId().equals(d.getGroupId())
                        && projDependency.getVersion().equals(d.getVersion())) {
                    log.debug("Found a dependency that matches another module '" + proj.getName() + "' -> '"
                            + projDependency.getName() + "'");
                    deps.add(projDependency);
                }
            }
        }
    }

    // Remove modules that are entirely dependencies of others
    List<MavenProject> toBeRemoved = new ArrayList<MavenProject>();
    for (MavenProject proj : modules) {
        List<MavenProject> projDeps = result.get(proj);
        for (MavenProject proj2 : modules) {
            if (proj != proj2) {
                if (result.get(proj2).containsAll(projDeps)) {
                    log.debug("Remove '" + proj.getName()
                            + "' from list of top modules because is a dependency of '" + proj2.getName()
                            + "'");
                    toBeRemoved.add(proj);
                    break;
                }
            }
        }
    }
    for (MavenProject mp : toBeRemoved) {
        result.remove(mp);
    }

    return result;
}

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

License:Apache License

protected static String getModuleDownloadPath(MavenProject topPlugin, List<MavenProject> modules,
        File directory, Log log) throws MojoExecutionException {
    File dest;//  w  w w .ja va 2  s.c  o  m
    if (modules.size() > 1) {
        dest = new File(directory, topPlugin.getArtifactId() + "-" + topPlugin.getVersion() + ".zip");
        log.debug("The plugin '" + topPlugin + "' is a suite, creating zip archive at '"
                + dest.getAbsolutePath() + "'");

        // Verify files exist and add to archive
        try {
            ZipArchiver archiver = new ZipArchiver();
            for (MavenProject module : modules) {

                File f = new File(directory, module.getArtifactId() + "-" + module.getVersion() + ".nbm");
                if (!f.exists()) {
                    throw new MojoExecutionException(
                            "The NBM file '" + f.getAbsolutePath() + "' can't be found");
                }
                archiver.addFile(f, f.getName());
                log.debug("  Add file '" + f.getAbsolutePath() + "' to the archive");
            }
            archiver.setCompress(false);
            archiver.setDestFile(dest);
            archiver.setForced(true);
            archiver.createArchive();
            log.info("Created ZIP archive for project '" + topPlugin.getName() + "' at '"
                    + dest.getAbsolutePath() + "'");
        } catch (IOException ex) {
            throw new MojoExecutionException(
                    "Something went wrong with the creation of the ZIP archive for project '"
                            + topPlugin.getName() + "'",
                    ex);
        } catch (ArchiverException ex) {
            throw new MojoExecutionException(
                    "Something went wrong with the creation of the ZIP archive for project '"
                            + topPlugin.getName() + "'",
                    ex);
        }
    } else {
        dest = new File(directory, topPlugin.getArtifactId() + "-" + topPlugin.getVersion() + ".nbm");
        log.debug("The plugin is not a suite, return nbm file '" + dest.getAbsolutePath() + "'");
    }
    return dest.getName();
}

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

License:Apache License

protected static List<Image> copyScreenshots(MavenProject mavenProject, File outputFolder, String urlPrefix,
        Log log) throws MojoExecutionException {
    File folder = new File(mavenProject.getBasedir(), "src/img");
    if (folder.exists()) {
        log.debug("Folder '" + folder.getAbsolutePath() + "' exists");

        // List images in folder
        File[] files = folder.listFiles(new FilenameFilter() {
            @Override/* w ww.j ava2s .  co m*/
            public boolean accept(File dir, String name) {
                return !name.startsWith(".") && (name.endsWith(".png") || name.endsWith(".jpg")
                        || name.endsWith(".jpeg") || name.endsWith(".gif")) && !name.contains(THUMBNAIL_SUFFIX);
            }
        });

        // Sort files alphabetically
        Arrays.sort(files, new Comparator<File>() {
            @Override
            public int compare(File f1, File f2) {
                return f1.getName().compareTo(f2.getName());
            }
        });
        log.debug(files.length + " images found in source folder");

        // Create dest folder
        if (outputFolder.mkdirs()) {
            log.debug("Output folder '" + outputFolder.getAbsolutePath() + "' was created");
        }

        List<Image> images = new ArrayList<Image>();
        for (File file : files) {
            if (file.getName().contains(" ")) {
                throw new MojoExecutionException("Image file '" + file.getAbsolutePath()
                        + "' contains spaces. Please rename image and try again");
            }
            // Read original file and copy to dest folder
            String fileName = file.getName().substring(0, file.getName().lastIndexOf(".")) + ".png";
            File imageDestFile = new File(outputFolder, fileName);
            try {
                Thumbnails.of(file).outputFormat("png").outputQuality(0.90).resizer(Resizers.NULL).scale(1.0)
                        .toFile(imageDestFile);
            } catch (IOException ex) {
                log.error("Can't copy image file from '" + file.getAbsolutePath() + "' to '"
                        + imageDestFile.getAbsolutePath() + "'", ex);
            }

            Image image = new Image();
            image.image = urlPrefix + fileName;
            images.add(image);

            // Thumbnail path
            String thumFileName = file.getName().substring(0, file.getName().lastIndexOf("."))
                    + THUMBNAIL_SUFFIX + ".png";
            File thumbFile = new File(outputFolder, thumFileName);
            if (!thumbFile.exists()) {
                // Thumbnail creation
                try {
                    Thumbnails.of(file).outputFormat("png").outputQuality(0.90).size(140, 140)
                            .crop(Positions.CENTER).toFile(thumbFile);
                    log.debug("Created thumbnail in file '" + thumbFile.getAbsolutePath() + "'");
                    image.thumbnail = urlPrefix + thumFileName;
                } catch (IOException ex) {
                    log.error("Can't create thumbnail for image file '" + file.getAbsolutePath() + "'", ex);
                }
            }

            log.info("Attached image '" + file.getName() + "' to plugin " + mavenProject.getName());
        }
        return images;
    } else {
        log.debug("Folder '" + folder.getAbsolutePath() + "' was not found");
    }
    return null;
}

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

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    manifestUtils = new ManifestUtils(sourceManifestFile, getLog());
    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")) {
                getLog().debug("Found 'nbm' project '" + proj.getName() + "' with artifactId="
                        + proj.getArtifactId() + " and groupId=" + proj.getGroupId());
                modules.add(proj);/*from   w ww .  ja v a 2s  .  c  om*/
            }
        }

        if (modules.isEmpty()) {
            throw new MojoExecutionException(
                    "No 'nbm' modules have been detected, make sure to add folders to <modules> into pom");
        } else if (modules.size() == 1) {
            // Unique NBM module
            executeSingleModuleProject(modules.get(0));
        } else {
            executeMultiModuleProject(modules);
        }
    } else {
        throw new MojoExecutionException("The project should be a reactor project");
    }
}

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

License:Apache License

private void executeSingleModuleProject(MavenProject moduleProject)
        throws MojoExecutionException, MojoFailureException {
    getLog().info("Unique module found: '" + moduleProject.getName() + "'");
    checkGephiVersion(moduleProject);/*from   ww  w. j a  v a2 s .c om*/
    checkMetadata(moduleProject);
}

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

License:Apache License

private void executeMultiModuleProject(List<MavenProject> projects)
        throws MojoExecutionException, MojoFailureException {
    // Multiple NBM modules
    Map<MavenProject, List<MavenProject>> tree = ModuleUtils.getModulesTree(projects, getLog());
    if (tree.isEmpty()) {
        throw new MojoExecutionException(
                "Multiple modules have been found but no suite detected, make sure one of the module has dependencies on the others");
    } else if (tree.size() > 1) {
        throw new MojoExecutionException("Multiple module suites have been found, this is not supported");
    }//w w  w.  j a va 2  s  . c  o m
    Map.Entry<MavenProject, List<MavenProject>> entry = tree.entrySet().iterator().next();
    List<MavenProject> children = entry.getValue();
    checkSameGephiVersion(children);

    children.remove(entry.getKey());
    getLog().info("Suite of modules found: '" + entry.getKey().getName() + "'");
    for (MavenProject child : children) {
        getLog().info("   '" + child.getName() + "' is a dependency");
    }
    for (MavenProject child : children) {
        checkGephiVersion(child);
        manifestUtils.checkManifestShowClientFalse(child);
    }
    checkGephiVersion(entry.getKey());
    checkMetadata(entry.getKey());
}

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

License:Apache License

private void checkMetadata(MavenProject moduleProject) throws MojoExecutionException {
    if (MetadataUtils.getLicenseName(moduleProject) == null) {
        throw new MojoExecutionException("The 'licenseName' configuration should be set for the project '"
                + moduleProject.getName()
                + "'. This can be added to the configuration of the 'nbm-maven-plugin' plugin. In addition, a 'licenseFile' can be specified, relative to the module's root folder.");
    }/*w w w  . j ava 2s . c o m*/
    if (MetadataUtils.getAuthors(moduleProject) == null) {
        throw new MojoExecutionException("The 'author' configuration should be set fot the project '"
                + moduleProject.getName()
                + "'. This can be added to the configuration of the 'nbm-maven-plugin' plugin. Multiple authors can be specificed, separated by a comma.");
    }

    manifestUtils.readManifestMetadata(moduleProject, new PluginMetadata());
}