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:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java

License:Open Source License

private static void rebuildModuleHierarchy(Properties properties, Map<MavenProject, Properties> propsByModule,
        MavenProject current, String prefix) throws IOException {
    Properties currentProps = propsByModule.get(current);
    if (currentProps == null) {
        throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE);
    }//from  www.ja va2s  .  c  om
    for (Map.Entry<Object, Object> prop : currentProps.entrySet()) {
        properties.put(prefix + prop.getKey(), prop.getValue());
    }
    propsByModule.remove(current);
    List<String> moduleIds = new ArrayList<>();
    for (String modulePathStr : current.getModules()) {
        File modulePath = new File(current.getBasedir(), modulePathStr);
        MavenProject module = findMavenProject(modulePath, propsByModule.keySet());
        if (module != null) {
            String moduleId = module.getGroupId() + ":" + module.getArtifactId();
            rebuildModuleHierarchy(properties, propsByModule, module, prefix + moduleId + ".");
            moduleIds.add(moduleId);
        }
    }
    if (!moduleIds.isEmpty()) {
        properties.put(prefix + "sonar.modules", StringUtils.join(moduleIds, SEPARATOR));
    }
}

From source file:org.sonatype.flexmojos.war.CopyMojo.java

License:Apache License

private List<Artifact> getRuntimeLocalesDependencies(MavenProject artifactProject) {
    String[] runtimeLocales = CompileConfigurationLoader.getCompilerPluginSettings(artifactProject,
            "runtimeLocales");
    if (runtimeLocales == null || runtimeLocales.length == 0) {
        return Collections.emptyList();
    }/*from w  w w. java 2s . c  o  m*/

    List<Artifact> artifacts = new ArrayList<Artifact>();
    for (String locale : runtimeLocales) {
        artifacts.add(artifactFactory.createArtifactWithClassifier(artifactProject.getGroupId(),
                artifactProject.getArtifactId(), artifactProject.getVersion(), SWF, locale));
    }
    return artifacts;
}

From source file:org.sonatype.m2e.webby.internal.build.WebbyBuildParticipant.java

License:Open Source License

private void addConfigurationError(MavenProject mvnProject, String msg) {
    File pomFile = mvnProject.getFile();

    int line = 0;
    int column = 0;
    InputLocation location = new WarConfigurationExtractor().getConfigurationLocation(mvnProject);
    if (location != null && location.getSource() != null) {
        String modelId = mvnProject.getGroupId() + ":" + mvnProject.getArtifactId() + ':'
                + mvnProject.getVersion();
        if (location.getSource().getModelId().equals(modelId)) {
            line = location.getLineNumber();
            column = location.getColumnNumber();
        }/*www.  j a va2 s.  c om*/
    }

    BuildContext buildContext = getBuildContext();
    buildContext.addMessage(pomFile, line, column, msg, BuildContext.SEVERITY_ERROR, null);
}

From source file:org.sonatype.nexus.maven.staging.AbstractStagingMojo.java

License:Open Source License

protected String getRootProjectGav() {
    final MavenProject rootProject = getFirstProjectWithThisPluginDefined();
    if (rootProject != null) {
        return rootProject.getGroupId() + ":" + rootProject.getArtifactId() + ":" + rootProject.getVersion();
    } else {//w w  w.j  a v  a  2 s .  co m
        return "unknown";
    }
}

From source file:org.sonatype.nexus.plugin.deploy.AbstractDeployMojo.java

License:Open Source License

protected String beforeUpload() throws ArtifactDeploymentException {
    if (deployUrl != null) {
        getLog().info("Performing normal upload against URL: " + deployUrl);
        return deployUrl;
    } else if (nexusUrl != null) {
        try {//  w w w. j  a va2 s.  c o m
            getLog().info("Initiating staging against Nexus on URL " + nexusUrl);
            createStageClient();

            final MavenProject currentProject = mavenSession.getCurrentProject();

            // if profile is not "targeted", perform a match and save the result
            if (StringUtils.isBlank(stagingProfileId)) {
                stagingProfileId = stageClient.getStageProfileForUser(currentProject.getGroupId(),
                        currentProject.getArtifactId(), currentProject.getVersion());
                getLog().info("Using staging profile ID \"" + stagingProfileId + "\" (matched by Nexus).");
            } else {
                getLog().info("Using staging profile ID \"" + stagingProfileId + "\" (configured by user).");
            }

            if (StringUtils.isBlank(stagingRepositoryId)) {
                stagingRepositoryId = stageClient.startRepository(stagingProfileId,
                        "Started by nexus-maven-plugin", tags);
                // store the one just created for us, as it means we need to "babysit" it (close or drop, depending
                // on outcome)
                createdStagingRepositoryId = stagingRepositoryId;
                if (tags != null && !tags.isEmpty()) {
                    getLog().info("Created staging repository with ID \"" + stagingRepositoryId
                            + "\", applied tags: " + tags);
                } else {
                    getLog().info("Created staging repository with ID \"" + stagingRepositoryId + "\".");
                }

            } else {
                createdStagingRepositoryId = null;
                getLog().info("Using preconfigured staging repository with ID \"" + stagingRepositoryId
                        + "\" (we are NOT managing it)."); // we will not close it! This might be created by some
                                                                                                                                                   // other automated component
            }

            return concat(nexusUrl, "/service/local/staging/deployByRepositoryId", stagingRepositoryId);
        } catch (RESTLightClientException e) {
            throw new ArtifactDeploymentException("Error before upload while managing staging repository!", e);
        }
    } else {
        throw new ArtifactDeploymentException("No deploy URL set, nor Nexus BaseURL given!");
    }
}

From source file:org.sourcepit.b2.internal.maven.MavenModulePropertiesFactory.java

License:Apache License

public PropertiesSource createModuleProperties(MavenSession mavenSession, final MavenProject project) {
    final PropertiesMap propertiesMap = B2ModelBuildingRequest.newDefaultProperties();

    propertiesMap.put("b2.moduleNameSpace", project.getGroupId());

    final String mavenVersion = project.getVersion();
    final String osgiVersion = VersionUtils.toBundleVersion(mavenVersion);
    putModuleVersions(propertiesMap, osgiVersion);

    propertiesMap.putMap(project.getProperties());
    propertiesMap.putMap(mavenSession.getSystemProperties());
    propertiesMap.putMap(mavenSession.getUserProperties());

    final List<ValueSource> valueSources = new ArrayList<ValueSource>();

    final List<String> prefixes = new ArrayList<String>();
    prefixes.add("pom");
    prefixes.add("project");
    valueSources.add(ValueSourceUtils.newPrefixedValueSource(prefixes, project));
    valueSources.add(ValueSourceUtils.newPrefixedValueSource("session", mavenSession));

    final Settings settings = mavenSession.getSettings();
    if (settings != null) {
        valueSources.add(ValueSourceUtils.newPrefixedValueSource("settings", settings));
        valueSources/*from w w w  .  j  av a2  s .c  om*/
                .add(ValueSourceUtils.newSingleValueSource("localRepository", settings.getLocalRepository()));
    }

    return new AbstractPropertiesSource() {
        public String get(String key) {
            if ("module.id".equals(key) && !isPropertyDefinedOnProject(key)) {
                return null;
            }
            final String value = propertiesMap.get(key);
            if (value != null) {
                return value;
            }
            for (ValueSource valueSource : valueSources) {
                final Object oValue = valueSource.getValue(key);
                if (oValue != null) {
                    return oValue.toString();
                }
            }
            return null;
        }

        private boolean isPropertyDefinedOnProject(String key) {
            return project.getOriginalModel().getProperties().containsKey(key);
        }
    };
}

From source file:org.sourcepit.b2.maven.core.B2MavenBridge.java

License:Apache License

public static URI toArtifactURI(MavenProject project, String type, String classifier) {
    final StringBuilder sb = new StringBuilder();
    sb.append(project.getGroupId());
    sb.append("/");
    sb.append(project.getArtifactId());//w ww  .j  a  v  a 2s  .  c  o m
    sb.append("/");
    sb.append(type);
    if (classifier != null && classifier.length() > 0) {
        sb.append("/");
        sb.append(classifier);
    }
    sb.append("/");
    sb.append(project.getVersion());
    return URI.createURI("gav:/" + sb.toString());
}

From source file:org.sourcepit.b2.release.B2ReleaseHelper.java

License:Apache License

private String determineNewMavenVersion(ReleaseDescriptor releaseDescriptor, MavenProject mavenProject,
        boolean release) {
    @SuppressWarnings("unchecked")
    final Map<String, String> versionMap = release ? releaseDescriptor.getReleaseVersions()
            : releaseDescriptor.getDevelopmentVersions();
    String projectId = ArtifactUtils.versionlessKey(mavenProject.getGroupId(), mavenProject.getArtifactId());
    String mavenVersion = versionMap.get(projectId);
    if (mavenVersion == null) {
        final MavenProject moduleProject = determineModuleMavenProject(mavenProject);
        projectId = ArtifactUtils.versionlessKey(moduleProject.getGroupId(), moduleProject.getArtifactId());
        mavenVersion = versionMap.get(projectId);
    }/* w ww. ja  va  2  s .c o m*/
    return mavenVersion;
}

From source file:org.sourcepit.common.maven.core.MavenProjectUtils.java

License:Apache License

public static String getProjectReferenceId(@NotNull MavenProject project) {
    return getProjectReferenceId(project.getGroupId(), project.getArtifactId(), project.getVersion());
}

From source file:org.sourcepit.common.maven.core.MavenProjectUtils.java

License:Apache License

public static org.sourcepit.common.maven.model.MavenProject toMavenProject(
        @NotNull org.apache.maven.project.MavenProject mavenProject) {
    final org.sourcepit.common.maven.model.MavenProject mProject = MavenModelFactory.eINSTANCE
            .createMavenProject();//from ww w .  ja v  a2  s .  com
    mProject.setGroupId(mavenProject.getGroupId());
    mProject.setArtifactId(mavenProject.getArtifactId());
    mProject.setVersion(mavenProject.getVersion());
    if (mavenProject.getPackaging() != null
            && !ObjectUtils.equals(mProject.getPackaging(), mavenProject.getPackaging())) {
        mProject.setPackaging(mavenProject.getPackaging());
    }
    mProject.setPomFile(mavenProject.getFile());
    mProject.setOutputDirectory(MavenProjectUtils.getOutputDir(mavenProject));
    mProject.setTestOutputDirectory(MavenProjectUtils.getTestOutputDir(mavenProject));
    return mProject;
}