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

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

Introduction

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

Prototype

public String getGroupId() 

Source Link

Usage

From source file:fr.brouillard.oss.jgitver.GAV.java

License:Apache License

/**
 * Builds a GAV object from the given MavenProject object.
 * //from w ww .ja va 2 s .co  m
 * @param project the project to extract info from
 * @return a new GAV object
 */
public static GAV from(MavenProject project) {
    return new GAV(project.getGroupId(), project.getArtifactId(), project.getVersion());
}

From source file:fr.fastconnect.factory.tibco.bw.maven.BWLifecycleParticipant.java

License:Apache License

private List<MavenProject> prepareProjects(List<MavenProject> projects, MavenSession session)
        throws MavenExecutionException {
    List<MavenProject> result = new ArrayList<MavenProject>();

    ProjectBuildingRequest projectBuildingRequest = session.getProjectBuildingRequest();

    for (MavenProject mavenProject : projects) {
        logger.debug("project: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId());

        List<String> oldActiveProfileIds = projectBuildingRequest.getActiveProfileIds();
        try {//from ww  w .  j  a  v a 2 s.c om
            List<String> activeProfileIds = activateProfilesWithProperties(mavenProject, oldActiveProfileIds);
            if (activeProfileIds.size() != oldActiveProfileIds.size()) {
                projectBuildingRequest.setActiveProfileIds(activeProfileIds);
                if (mavenProject.getFile() != null) {
                    List<File> files = new ArrayList<File>();
                    files.add(mavenProject.getFile());
                    List<ProjectBuildingResult> results = null;
                    try {
                        results = projectBuilder.build(files, true, projectBuildingRequest);
                    } catch (ProjectBuildingException e) {
                    }

                    for (ProjectBuildingResult projectBuildingResult : results) {
                        mavenProject = projectBuildingResult.getProject();
                    }
                }
            }
        } finally {
            projectBuildingRequest.setActiveProfileIds(oldActiveProfileIds);
        }

        if (mavenProject.getPackaging().startsWith(AbstractBWMojo.BWEAR_TYPE)
                || "true".equals(propertiesManager.getPropertyValue("enableBWLifecycle"))) {
            addTIBCODependenciesToPlugin(mavenProject, logger);
        }
        result.add(mavenProject);
    }

    return result;
}

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 {//  www.  j a v a2s .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) {/* ww w. j  a  va2s  .  co m*/
            return mavenProject;
        }
    }
    return null;
}

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  w w  . j a va 2  s. c om

    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: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());
}

From source file:hudson.gridmaven.PomInfo.java

License:Open Source License

public PomInfo(MavenProject project, PomInfo parent, String relPath) {
    this.name = new ModuleName(project);
    this.version = project.getVersion();
    this.displayName = project.getName();
    this.defaultGoal = project.getDefaultGoal();
    this.relativePath = relPath;
    this.parent = parent;
    if (parent != null)
        parent.children.add(name);//from w  w  w  .j  av a 2s  .c o m

    for (Dependency dep : (List<Dependency>) project.getDependencies())
        dependencies.add(new ModuleDependency(dep));

    MavenProject parentProject = project.getParent();
    if (parentProject != null)
        dependencies.add(new ModuleDependency(parentProject));
    if (parent != null)
        dependencies.add(parent.asDependency());

    addPluginsAsDependencies(project.getBuildPlugins(), dependencies);
    addReportPluginsAsDependencies(project.getReportPlugins(), dependencies);

    List<Extension> extensions = project.getBuildExtensions();
    if (extensions != null)
        for (Extension ext : extensions)
            dependencies.add(new ModuleDependency(ext));

    // when the parent POM uses a plugin and builds a plugin at the same time,
    // the plugin module ends up depending on itself
    dependencies.remove(asDependency());

    CiManagement ciMgmt = project.getCiManagement();
    if ((ciMgmt != null) && (ciMgmt.getSystem() == null || ciMgmt.getSystem().equals("hudson"))) {
        Notifier mailNotifier = null;
        for (Notifier n : (List<Notifier>) ciMgmt.getNotifiers()) {
            if (n.getType().equals("mail")) {
                mailNotifier = n;
                break;
            }
        }
        this.mailNotifier = mailNotifier;
    } else
        this.mailNotifier = null;

    this.groupId = project.getGroupId();
    this.artifactId = project.getArtifactId();
    this.packaging = project.getPackaging();
}

From source file:hudson.gridmaven.reporters.MavenArtifactArchiver.java

License:Open Source License

public boolean postBuild(MavenBuildProxy build, MavenProject pom, final BuildListener listener)
        throws InterruptedException, IOException {
    // artifacts that are known to Maven.
    Set<File> mavenArtifacts = new HashSet<File>();

    if (pom.getFile() != null) {// goals like 'clean' runs without loading POM, apparently.
        // record POM
        final MavenArtifact pomArtifact = new MavenArtifact(pom.getGroupId(), pom.getArtifactId(),
                pom.getVersion(), null, "pom", pom.getFile().getName(),
                Util.getDigestOf(new FileInputStream(pom.getFile())));

        final String repositoryUrl = pom.getDistributionManagementArtifactRepository() == null ? null
                : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getUrl());
        final String repositoryId = pom.getDistributionManagementArtifactRepository() == null ? null
                : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getId());

        mavenArtifacts.add(pom.getFile());
        pomArtifact.archive(build, pom.getFile(), listener);

        // record main artifact (if packaging is POM, this doesn't exist)
        final MavenArtifact mainArtifact = MavenArtifact.create(pom.getArtifact());
        if (mainArtifact != null) {
            File f = pom.getArtifact().getFile();
            mavenArtifacts.add(f);//from www .java2 s  .  c  o m
            mainArtifact.archive(build, f, listener);
        }

        // record attached artifacts
        final List<MavenArtifact> attachedArtifacts = new ArrayList<MavenArtifact>();
        for (Artifact a : pom.getAttachedArtifacts()) {
            MavenArtifact ma = MavenArtifact.create(a);
            if (ma != null) {
                mavenArtifacts.add(a.getFile());
                ma.archive(build, a.getFile(), listener);
                attachedArtifacts.add(ma);
            }
        }

        // record the action
        build.executeAsync(new MavenBuildProxy.BuildCallable<Void, IOException>() {
            private static final long serialVersionUID = -7955474564875700905L;

            public Void call(MavenBuild build) throws IOException, InterruptedException {
                // if a build forks lifecycles, this method can be called multiple times
                List<MavenArtifactRecord> old = build.getActions(MavenArtifactRecord.class);
                if (!old.isEmpty())
                    build.getActions().removeAll(old);

                MavenArtifactRecord mar = new MavenArtifactRecord(build, pomArtifact, mainArtifact,
                        attachedArtifacts, repositoryUrl, repositoryId);
                build.addAction(mar);

                // TODO kutzi: why are the fingerprints recorded here?
                // I thought that is the job of MavenFingerprinter
                mar.recordFingerprints();

                return null;
            }
        });
    }

    // do we have any assembly artifacts?
    //        System.out.println("Considering "+assemblies+" at "+MavenArtifactArchiver.this);
    //        new Exception().fillInStackTrace().printStackTrace();
    if (assemblies != null) {
        for (File assembly : assemblies) {
            if (mavenArtifacts.contains(assembly))
                continue; // looks like this is already archived
            if (build.isArchivingDisabled()) {
                listener.getLogger().println("[JENKINS] Archiving disabled - not archiving " + assembly);
            } else {
                FilePath target = build.getArtifactsDir().child(assembly.getName());
                listener.getLogger().println("[JENKINS] Archiving " + assembly + " to " + target);
                new FilePath(assembly).copyTo(target);
                // TODO: fingerprint
            }
        }
    }

    return true;
}

From source file:hudson.gridmaven.reporters.MavenFingerprinter.java

License:Open Source License

/**
 * Mojos perform different dependency resolution, so we need to check this for each mojo.
 *///from w  ww  . j  av  a2 s  . c  o  m
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener,
        Throwable error) throws InterruptedException, IOException {
    // TODO (kutzi, 2011/09/06): it should be perfectly safe to move all these records to the
    // postBuild method as artifacts should only be added by mojos, but never removed/modified.
    record(pom.getArtifacts(), used);
    record(pom.getArtifact(), produced);
    record(pom.getAttachedArtifacts(), produced);
    record(pom.getGroupId() + ":" + pom.getArtifactId(), pom.getFile(), produced);

    return true;
}