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

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

Introduction

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

Prototype

public String getPackaging() 

Source Link

Usage

From source file:org.fedoraproject.tycho.TychoBootstrapMojo.java

License:Open Source License

public boolean isExcluded(MavenProject proj) {
    return proj.getArtifactId().contains("surefire") || proj.getPackaging().equals("eclipse-test-plugin");
}

From source file:org.fusesource.ide.projecttemplates.maven.CamelProjectConfigurator.java

License:Open Source License

private void installDefaultFacets(IProject project, MavenProject mavenProject, IFacetedProject fproj,
        IProgressMonitor monitor) throws CoreException {
    String camelVersion = getCamelVersion(mavenProject);
    if (camelVersion != null) {
        IFacetedProjectWorkingCopy fpwc = fproj.createWorkingCopy();

        // adjust facets we install based on the packaging type we find
        installFacet(fproj, fpwc, javaFacet, javaFacet.getLatestVersion());
        installFacet(fproj, fpwc, m2eFacet, m2eFacet.getLatestVersion());
        if (mavenProject.getPackaging() != null) {
            String packaging = mavenProject.getPackaging();
            if (WAR_PACKAGE.equalsIgnoreCase(packaging)) {
                installFacet(fproj, fpwc, webFacet, javaFacet.getLatestVersion());
            } else if (BUNDLE_PACKAGE.equalsIgnoreCase(packaging) || JAR_PACKAGE.equalsIgnoreCase(packaging)) {
                installFacet(fproj, fpwc, utilFacet, utilFacet.getLatestVersion());
            }//from  w  w w. j  av  a 2s. c o  m
        }
        installCamelFacet(fproj, fpwc, camelVersion, monitor);
        fpwc.commitChanges(monitor);
        configureNature(project, mavenProject, monitor);
        updateMavenProject(project);
    }
}

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");
    }/*from ww w .  j a v a 2 s .co  m*/
    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.  j  a v a2  s. c  om*/

    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.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  w  w .j ava 2s.c o m*/
            }
        }

        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.hudsonci.maven.eventspy_30.MavenProjectConverter.java

License:Open Source License

public static MavenCoordinatesDTO asCoordinates(final MavenProject mavenProject) {
    checkNotNull(mavenProject);/*from   w  w  w  .  ja v a2  s.co m*/

    // Assume groupId, artifactId and version are never null.
    return new MavenCoordinatesDTO().withGroupId(mavenProject.getGroupId())
            .withArtifactId(mavenProject.getArtifactId()).withType(nullSafeString(mavenProject.getPackaging()))
            .withVersion(mavenProject.getVersion()).normalize();
}

From source file:org.impalaframework.maven.plugin.MojoUtils.java

License:Apache License

public static boolean checkConditionFromPropertyAndPackaging(MavenProject project, String propertyName,
        String packagingName, Log log) {

    final Properties properties = project.getProperties();
    String moduleJarProperty = properties.getProperty(propertyName);

    if (moduleJarProperty != null && moduleJarProperty.length() > 0) {
        final boolean parseBoolean = Boolean.parseBoolean(moduleJarProperty);
        if (!parseBoolean) {
            log.debug("Not supporting " + project.getArtifactId() + " as it has set the '" + propertyName
                    + "' property to false");
            return false;
        }//from w  w  w .j a v  a2s .com

        return parseBoolean;
    }

    final boolean isJar = packagingName.equals(project.getPackaging());

    if (!isJar) {
        log.debug("Not supporting " + project.getArtifactId() + " as it does not use '" + packagingName
                + "' packaging");
        return false;
    }

    return true;
}

From source file:org.javagems.core.maven.DebianMojo.java

License:Apache License

/**
 * Copy properties from the maven project to the ant project.
 *
 * @param mavenProject/* w  ww .j av a 2s  .c  o m*/
 * @param antProject
 */
public void copyProperties(MavenProject mavenProject, Project antProject) {
    Properties mavenProps = mavenProject.getProperties();
    Iterator iter = mavenProps.keySet().iterator();
    while (iter.hasNext()) {
        String key = (String) iter.next();
        antProject.setProperty(key, mavenProps.getProperty(key));
    }

    // Set the POM file as the ant.file for the tasks run directly in Maven.
    antProject.setProperty("ant.file", mavenProject.getFile().getAbsolutePath());

    // Add some of the common maven properties
    getLog().debug("Setting properties with prefix: " + propertyPrefix);
    antProject.setProperty((propertyPrefix + "project.groupId"), mavenProject.getGroupId());
    antProject.setProperty((propertyPrefix + "project.artifactId"), mavenProject.getArtifactId());
    antProject.setProperty((propertyPrefix + "project.name"), mavenProject.getName());
    if (mavenProject.getDescription() != null) {
        antProject.setProperty((propertyPrefix + "project.description"), mavenProject.getDescription());
    }
    antProject.setProperty((propertyPrefix + "project.version"), mavenProject.getVersion());
    antProject.setProperty((propertyPrefix + "project.packaging"), mavenProject.getPackaging());
    antProject.setProperty((propertyPrefix + "project.build.directory"),
            mavenProject.getBuild().getDirectory());
    antProject.setProperty((propertyPrefix + "project.build.outputDirectory"),
            mavenProject.getBuild().getOutputDirectory());
    antProject.setProperty((propertyPrefix + "project.build.testOutputDirectory"),
            mavenProject.getBuild().getTestOutputDirectory());
    antProject.setProperty((propertyPrefix + "project.build.sourceDirectory"),
            mavenProject.getBuild().getSourceDirectory());
    antProject.setProperty((propertyPrefix + "project.build.testSourceDirectory"),
            mavenProject.getBuild().getTestSourceDirectory());
    antProject.setProperty((propertyPrefix + "localRepository"), localRepository.toString());
    antProject.setProperty((propertyPrefix + "settings.localRepository"), localRepository.getBasedir());

    // Add properties for depenedency artifacts
    Set depArtifacts = mavenProject.getArtifacts();
    for (Iterator it = depArtifacts.iterator(); it.hasNext();) {
        Artifact artifact = (Artifact) it.next();

        String propName = artifact.getDependencyConflictId();

        antProject.setProperty(propertyPrefix + propName, artifact.getFile().getPath());
    }

    // Add a property containing the list of versions for the mapper
    StringBuffer versionsBuffer = new StringBuffer();
    for (Iterator it = depArtifacts.iterator(); it.hasNext();) {
        Artifact artifact = (Artifact) it.next();

        versionsBuffer.append(artifact.getVersion() + File.pathSeparator);
    }
    antProject.setProperty(versionsPropertyName, versionsBuffer.toString());
}

From source file:org.jboss.ce.mvns2i.MavenUtils.java

License:Open Source License

private void recurse(ProjectBuilder projectBuilder, ProjectBuildingRequest request, Checker checker,
        File parentDir, String path, MavenProject project) throws Exception {
    String packaging = project.getPackaging();
    if ("pom".equals(packaging)) {
        List<String> modules = project.getModules();
        for (String module : modules) {
            File moduleDir = new File(parentDir, module);
            File modulePomFile = new File(moduleDir, "pom.xml");
            MavenProject subProject = projectBuilder.build(modulePomFile, request).getProject();
            String newPath = (path.length() > 0) ? path + "/" + module : module;
            recurse(projectBuilder, request, checker, moduleDir, newPath, subProject);
        }/* www  .  j  ava2  s  .  co  m*/
    } else {
        checker.addType(packaging, path);
    }
}

From source file:org.jboss.maven.plugins.qstools.checkers.FinalNameChecker.java

License:Apache License

@Override
public void checkProject(MavenProject project, Document doc, Map<String, List<Violation>> results)
        throws Exception {
    String packaging = project.getPackaging();
    String expectedFinalName = getConfigurationProvider().getQuickstartsRules(project.getGroupId())
            .getFinalNamePatterns().get(packaging);
    Node finalNameNode = (Node) getxPath().evaluate("//finalName", doc, XPathConstants.NODE);
    String declaredFinalName = finalNameNode == null ? project.getBuild().getFinalName()
            : finalNameNode.getTextContent();
    if (expectedFinalName != null && !expectedFinalName.equals(declaredFinalName)) {
        int lineNumber = finalNameNode == null ? 0 : XMLUtil.getLineNumberFromNode(finalNameNode);
        addViolation(project.getFile(), results, lineNumber,
                ("File doesn't contain <finalName>" + expectedFinalName + "</finalName>"));
    }//from  w w  w  . j  a v a 2  s.c  om
}