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

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

Introduction

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

Prototype

public String getVersion() 

Source Link

Usage

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 2s  . c om*/
        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 {//from   w ww.  jav  a  2s . 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.B2BootstrapParticipant.java

License:Apache License

public void beforeBuild(MavenSession bootSession, final MavenProject bootProject, MavenSession actualSession) {
    LOGGER.info("");
    LOGGER.info("------------------------------------------------------------------------");
    LOGGER.info("Bootstrapping " + bootProject.getName() + " " + bootProject.getVersion());
    LOGGER.info("------------------------------------------------------------------------");

    final List<File> projectDirs = new ArrayList<File>();
    for (MavenProject project : bootSession.getProjects()) {
        projectDirs.add(project.getBasedir());
    }//from  w w  w.  j  a  v  a  2  s.  c  o m

    final int idx = bootSession.getProjects().indexOf(bootProject);
    checkState(idx > -1);

    final B2Request b2Request = b2RequestFactory.newRequest(projectDirs, idx);

    final AbstractModule module = b2LifecycleRunner.prepareNext(projectDirs, idx, b2Request);
    bootProject.setContextValue(AbstractModule.class.getName(), module);
    bootProject.setContextValue(ModuleDirectory.class.getName(), b2Request.getModuleDirectory());
}

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 ww w.j a  v  a  2s  . co  m
                .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());/*from  ww  w .j a  v  a 2s  . com*/
    sb.append("/");
    sb.append(project.getArtifactId());
    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.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  w ww. j ava  2  s .  c  o m*/
    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;
}

From source file:org.sourcepit.maven.bootstrap.core.AbstractBootstrapper.java

License:Apache License

private Map<String, MavenProject> getProjectMap(List<MavenProject> projects)
        throws org.apache.maven.DuplicateProjectException {
    Map<String, MavenProject> index = new LinkedHashMap<String, MavenProject>();
    Map<String, List<File>> collisions = new LinkedHashMap<String, List<File>>();

    for (MavenProject project : projects) {
        String projectId = ArtifactUtils.key(project.getGroupId(), project.getArtifactId(),
                project.getVersion());

        MavenProject collision = index.get(projectId);

        if (collision == null) {
            index.put(projectId, project);
        } else {//from  ww  w . j ava  2  s  .  c o m
            List<File> pomFiles = collisions.get(projectId);

            if (pomFiles == null) {
                pomFiles = new ArrayList<File>(Arrays.asList(collision.getFile(), project.getFile()));
                collisions.put(projectId, pomFiles);
            } else {
                pomFiles.add(project.getFile());
            }
        }
    }

    if (!collisions.isEmpty()) {
        throw new org.apache.maven.DuplicateProjectException("Two or more projects in the reactor"
                + " have the same identifier, please make sure that <groupId>:<artifactId>:<version>"
                + " is unique for each project: " + collisions, collisions);
    }

    return index;
}

From source file:org.sourcepit.maven.bootstrap.internal.core.ReactorReader.java

License:Apache License

public List<String> findVersions(Artifact artifact) {
    String key = ArtifactUtils.versionlessKey(artifact.getGroupId(), artifact.getArtifactId());

    List<MavenProject> projects = projectsByGA.get(key);
    if (projects == null || projects.isEmpty()) {
        return Collections.emptyList();
    }/*www  . j a v  a 2 s  .co m*/

    List<String> versions = new ArrayList<String>();

    for (MavenProject project : projects) {
        if (find(project, artifact) != null) {
            versions.add(project.getVersion());
        }
    }

    return Collections.unmodifiableList(versions);
}

From source file:org.sourcepit.tools.mojo.DeployCopiedArtifactMojo.java

License:Apache License

ArtifactRepository getDeploymentRepository(MavenProject project, String altDeploymentRepository,
        String altReleaseDeploymentRepository, String altSnapshotDeploymentRepository)
        throws MojoExecutionException, MojoFailureException {
    ArtifactRepository repo = null;/*from w  w  w  . j  a  v a2s.c o  m*/

    String altDeploymentRepo;
    if (ArtifactUtils.isSnapshot(project.getVersion()) && altSnapshotDeploymentRepository != null) {
        altDeploymentRepo = altSnapshotDeploymentRepository;
    } else if (!ArtifactUtils.isSnapshot(project.getVersion()) && altReleaseDeploymentRepository != null) {
        altDeploymentRepo = altReleaseDeploymentRepository;
    } else {
        altDeploymentRepo = altDeploymentRepository;
    }

    if (altDeploymentRepo != null) {
        getLog().info("Using alternate deployment repository " + altDeploymentRepo);

        Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher(altDeploymentRepo);

        if (!matcher.matches()) {
            throw new MojoFailureException(altDeploymentRepo, "Invalid syntax for repository.",
                    "Invalid syntax for alternative repository. Use \"id::layout::url\".");
        } else {
            String id = matcher.group(1).trim();
            String layout = matcher.group(2).trim();
            String url = matcher.group(3).trim();

            ArtifactRepositoryLayout repoLayout = getLayout(layout);

            repo = repositoryFactory.createDeploymentArtifactRepository(id, url, repoLayout, true);
        }
    }

    if (repo == null) {
        repo = project.getDistributionManagementArtifactRepository();
    }

    if (repo == null) {
        String msg = "Deployment failed: repository element was not specified in the POM inside"
                + " distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter";

        throw new MojoExecutionException(msg);
    }

    return repo;
}