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

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

Introduction

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

Prototype

public String getArtifactId() 

Source Link

Usage

From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.pom.AbstractPOMGenerator.java

License:Apache License

protected void generateDeployPOM(MavenProject project) throws MojoExecutionException {
    File outputFile = getOutputFile();
    File templateFile = getTemplateFile();
    getLog().info(templateFile.getAbsolutePath());
    InputStream builtinTemplateFile = getBuiltinTemplateFile();

    getLog().info(getGenerationMessage() + "'" + outputFile.getAbsolutePath() + "'");

    try {/*from w  w  w.j  a va  2 s.c  o m*/
        outputFile.getParentFile().mkdirs();
        outputFile.createNewFile();
        if (templateFile != null && templateFile.exists() && !getTemplateMerge()) {
            FileUtils.copyFile(templateFile, outputFile); // if a template deploy POM exists and we don't want to merge with built-in one: use it
        } else {
            // otherwise : use the one included in the plugin
            FileOutputStream fos = new FileOutputStream(outputFile);
            IOUtils.copy(builtinTemplateFile, fos);
        }
    } catch (IOException e) {
        throw new MojoExecutionException(getFailureMessage());
    }

    try {
        Model model = POMManager.getModelFromPOM(outputFile, this.getLog());
        if (templateFile != null && templateFile.exists() && getTemplateMerge()) {
            model = POMManager.mergeModelFromPOM(templateFile, model, this.getLog()); // if a template deploy POM exists and we want to merge with built-in one: merge it
        }

        model.setGroupId(project.getGroupId());
        model.setArtifactId(project.getArtifactId());
        model.setVersion(project.getVersion());

        Properties originalProperties = getProject().getProperties();
        for (String property : originalProperties.stringPropertyNames()) {
            if (property != null && property.startsWith(deploymentPropertyPrefix)) {
                model.getProperties().put(property.substring(deploymentPropertyPrefix.length()),
                        originalProperties.getProperty(property));
            }
            if (property != null && deploymentProperties.contains(property)) {
                model.getProperties().put(property, originalProperties.getProperty(property));
            }
        }

        model = updateModel(model, project);

        POMManager.writeModelToPOM(model, outputFile, getLog());

        attachFile(outputFile);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.pom.GenerateRootDeploymentPOM.java

License:Apache License

private MavenProject isProjectActive(Model model, List<MavenProject> activeProjects) {
    for (MavenProject mavenProject : activeProjects) {
        String packageSkipProperty = mavenProject.getProperties().getProperty("bw.package.skip");
        boolean packageSkip = packageSkipProperty != null && packageSkipProperty.equals("true");
        if ((mavenProject.getGroupId().equals(model.getGroupId()) || (model.getGroupId() == null)) && // == null in case of [inherited] value
                mavenProject.getArtifactId().equals(model.getArtifactId())
                && (mavenProject.getVersion().equals(model.getVersion()) || (model.getVersion() == null)) && // == null in case of [inherited] value
                !packageSkip) {/*from  www  .java2  s.c o  m*/
            return mavenProject;
        }
    }
    return null;
}

From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.pom.GenerateRootDeploymentPOM.java

License:Apache License

@Override
protected Model updateModel(Model model, MavenProject project) throws MojoExecutionException {
    model.setArtifactId(project.getArtifactId() + getArtifactSuffix());
    model.setPackaging("pom");

    updatePluginVersion(model);/*from  w w  w.  j ava 2 s  .c o  m*/

    try {
        model = addModules(model, project);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getLocalizedMessage(), e);
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException(e.getLocalizedMessage(), e);
    }

    return model;
}

From source file:fr.paris.lutece.maven.xdoc2md.XDoc2MarkdownMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    getLog().info("Create or update file README.md from src/site/xdoc/index.xml");

    MavenProject project = (MavenProject) getPluginContext().get("project");
    String strBaseDir = project.getBasedir().getAbsolutePath();
    getLog().info("Basedir :" + strBaseDir);

    String strInput = strBaseDir + File.separator + "src/site/xdoc/index.xml";
    String strOutput = strBaseDir + File.separator + "README.md";
    transform(project.getArtifactId(), strInput, strOutput);
}

From source file:fr.xebia.maven.plugin.mindmap.MindmapMojo.java

License:Apache License

private void generateMindMapXML(MavenProject mavenProject, DependencyNode rootNode)
        throws MojoExecutionException {
    FileWriter fw = null;/*from   w  ww .  j  av a2 s  .  c  o  m*/

    try {
        Properties p = new Properties();
        p.setProperty("resource.loader", "class");
        p.setProperty("class.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

        //  first, get and initialize an engine
        VelocityEngine ve = new VelocityEngine();
        ve.init(p);

        //  next, get the Template
        Template freePlaneTemplate = ve.getTemplate("MindMapTemplate.vm");

        // create a context and add data
        VelocityContext context = new VelocityContext();

        context.put("artifactId", mavenProject.getArtifactId());
        context.put("sorter", new SortTool());
        context.put("rootNode", rootNode);
        context.put("date", new SimpleDateFormat("dd/MM/yy HH:mm").format(Calendar.getInstance().getTime()));

        context.put("groupIdsFilteringREGEXMatch",
                groupIdsFilteringREGEXMatch != null ? groupIdsFilteringREGEXMatch : "");

        context.put("creationTS", Calendar.getInstance().getTimeInMillis());

        // now render the template
        fw = new FileWriter("./" + mavenProject.getGroupId() + "_" + mavenProject.getArtifactId() + "_"
                + mavenProject.getVersion() + ".mm");

        // write the mindmap xml to disc
        freePlaneTemplate.merge(context, fw);
    } catch (Exception e) {
        throw new MojoExecutionException("Unable to generate mind map.", e);
    } finally {
        if (fw != null) {
            try {
                fw.close();
            } catch (IOException e) {
                getLog().warn("Unable to properly close stream.", e);
            }
        }
    }
}

From source file:governance.plugin.GovernanceMojo.java

License:Apache License

public void process(File file) throws MojoExecutionException {
    if (file.isFile() && file.getName().equals("pom.xml")) {
        pomFileCount++;// www.  j a  va2  s .c o m
        getLog().debug("Processing " + file.getAbsoluteFile());

        Model model = PomParser.parse(file);
        if (model == null) {
            throw new MojoExecutionException("Error while processing  " + file.getAbsoluteFile());
        }

        // Creating a module representing the artifact generated by pom file
        MavenProject project = new MavenProject(model);
        moduleCreator
                .create(new String[] { project.getArtifactId(), project.getVersion(), file.getAbsolutePath() });

        String moduleAbsolutPath = moduleCreator.getAbsoluteArtifactResourcePath(
                new String[] { project.getArtifactId(), project.getVersion() });

        // Creating dependency artifacts to represent dependencies of the module
        List<Dependency> dependencies = project.getDependencies();
        for (Dependency dependency : dependencies) {
            dependencyCreator.create(new String[] { dependency.getGroupId(), dependency.getArtifactId(),
                    dependency.getVersion() });

            String dependencyAbsolutePath = dependencyCreator.getAbsoluteArtifactResourcePath(
                    new String[] { dependency.getGroupId(), dependency.getArtifactId() });

            // Adding association for each dependency with the module
            addAssociation(moduleAbsolutPath, dependencyAbsolutePath, "depends");
        }
    }
}

From source file:governance.plugin.ServiceGovernanceMojo.java

License:Apache License

public void linkServiceWithModule(Map<String, String> parameters, File file) throws MojoExecutionException {

    File currentPOM = findNearestPOMFile(file);
    if (currentPOM == null) {
        throw new MojoExecutionException(
                "Cannot find a POM related to this module. [file=" + file.getAbsolutePath() + "]");
    }// ww w.j  a v  a 2s  .co m

    Model model = PomParser.parse(currentPOM);
    if (model == null) {
        throw new MojoExecutionException("Error while processing  " + currentPOM.getAbsoluteFile());
    }

    // Creating a module representing the artifact generated by pom file
    MavenProject project = new MavenProject(model);

    String moduleAbsolutPath = moduleCreator
            .getAbsoluteArtifactResourcePath(new String[] { project.getArtifactId(), project.getVersion() });

    String dependencyAbsolutePath = serviceCreator.getAbsoluteArtifactResourcePath(
            new String[] { parameters.get("name"), parameters.get("namespace") });

    if (!artifactCreatorUtil.isArtifactExisting(moduleAbsolutPath)) {
        moduleCreator.create(
                new String[] { project.getArtifactId(), project.getVersion(), currentPOM.getAbsolutePath() });
    }

    //Adding association for each service with the module
    addAssociation(moduleAbsolutPath, dependencyAbsolutePath, "depends");
    addAssociation(dependencyAbsolutePath, moduleAbsolutPath, "usedBy");
}

From source file:governance.plugin.WebAppGovernanceMojo.java

License:Apache License

public void linkServiceWithModule(Map<String, String> parameters, File file) throws MojoExecutionException {

    File currentPOM = findNearestPOMFile(file);
    if (currentPOM == null) {
        throw new MojoExecutionException(
                "Cannot find a POM related to this module. [file=" + file.getAbsolutePath() + "]");
    }/*ww w  .  ja v a 2 s.  c  o m*/

    Model model = PomParser.parse(currentPOM);
    if (model == null) {
        throw new MojoExecutionException("Error while processing  " + currentPOM.getAbsoluteFile());
    }

    // Creating a module representing the artifact generated by pom file
    MavenProject project = new MavenProject(model);

    String moduleAbsolutPath = moduleCreator
            .getAbsoluteArtifactResourcePath(new String[] { project.getArtifactId(), project.getVersion() });

    String dependencyAbsolutePath = webApplicationCreator.getAbsoluteArtifactResourcePath(
            new String[] { parameters.get("name"), parameters.get("namespace") });

    if (!artifactCreatorUtil.isArtifactExisting(moduleAbsolutPath)) {
        moduleCreator.create(
                new String[] { project.getArtifactId(), project.getVersion(), currentPOM.getAbsolutePath() });
    }

    //Adding association for each service with the module
    addAssociation(moduleAbsolutPath, dependencyAbsolutePath, "depends");
    addAssociation(dependencyAbsolutePath, moduleAbsolutPath, "usedBy");
}

From source file:hudson.gridmaven.ModuleDependency.java

License:Open Source License

public ModuleDependency(MavenProject project) {
    this(project.getGroupId(), project.getArtifactId(), project.getVersion());
}

From source file:hudson.gridmaven.ModuleName.java

License:Open Source License

public ModuleName(MavenProject project) {
    this(project.getGroupId(), project.getArtifactId());
}