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.sourcepit.tpmp.AbstractTargetPlatformMojo.java

License:Apache License

protected Artifact createPlatformArtifact(MavenProject project) {
    final Artifact platformArtifact = repositorySystem.createArtifactWithClassifier(project.getGroupId(),
            project.getArtifactId(), project.getVersion(), "zip", classifier);
    return platformArtifact;
}

From source file:org.sourcepit.tpmp.AbstractTargetPlatformMojo.java

License:Apache License

protected String getFinalName(MavenProject project) {
    String finalName = project.getBuild().getFinalName();
    if (finalName == null) {
        finalName = project.getArtifactId() + "-" + project.getVersion();
    }// w  w w  .  j a v a  2s.  co  m
    return finalName;
}

From source file:org.springframework.ide.eclipse.maven.legacy.internal.core.GoogleProjectConfigurator.java

License:Open Source License

/**
 * {@inheritDoc}// ww  w  . j  av  a 2 s  .co  m
 */
@Override
protected void doConfigure(final MavenProject mavenProject, IProject project,
        ProjectConfigurationRequest request, final IProgressMonitor monitor) throws CoreException {

    final IMaven maven = MavenPlugin.getDefault().getMaven();

    configureNature(project, mavenProject, GAE_NATURE_ID, true, new NatureCallbackAdapter() {

        @Override
        public void beforeAddingNature() {
            try {
                DefaultMavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
                executionRequest.setBaseDirectory(mavenProject.getBasedir());
                executionRequest.setLocalRepository(maven.getLocalRepository());
                executionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories());
                executionRequest.setPluginArtifactRepositories(mavenProject.getPluginArtifactRepositories());
                executionRequest.setPom(mavenProject.getFile());
                executionRequest.setGoals(GAE_UNPACK_GOAL);

                MavenExecutionResult result = maven.execute(executionRequest, monitor);
                if (result.hasExceptions()) {
                    MavenCorePlugin.getDefault().getLog()
                            .log(new Status(IStatus.ERROR, MavenCorePlugin.NON_LEGACY_PLUGIN_ID,
                                    "Error configuring project", result.getExceptions().get(0)));
                }
            } catch (CoreException e) {
                MavenCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                        MavenCorePlugin.NON_LEGACY_PLUGIN_ID, "Error configuring project", e));
            }
        }
    }, monitor);

    if (configureNature(project, mavenProject, GWT_NATURE_ID, true, new NatureCallbackAdapter() {

        @Override
        public void beforeAddingNature() {

            // Get the GWT version from the project pom
            String gwtVersion = null;
            List<Dependency> dependencies = mavenProject.getDependencies();
            for (Dependency dependency : dependencies) {
                if (GWT_GROUP_ID.equals(dependency.getGroupId())
                        && ("gwt-user".equals(dependency.getArtifactId())
                                || "gwt-servlet".equals(dependency.getArtifactId()))) {
                    gwtVersion = dependency.getVersion();
                    break;
                }
            }

            // Check that the pom.xml has GWT dependencies
            if (StringUtils.hasLength(gwtVersion)) {
                try {
                    // Download and install the gwt-dev.jar into the local repository
                    maven.resolve(GWT_GROUP_ID, "gwt-dev", gwtVersion, "jar", null,
                            mavenProject.getRemoteArtifactRepositories(), monitor);
                } catch (CoreException e) {
                    MavenCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                            MavenCorePlugin.NON_LEGACY_PLUGIN_ID, "Error configuring project", e));
                }
            }
        }
    }, monitor)) {

        try {
            // Add GWT Web Application configuration parameters
            IEclipsePreferences prefs = SpringCorePreferences
                    .getProjectPreferences(project, "com.google.gdt.eclipse.core").getProjectPreferences();
            prefs.put("warSrcDir", "src/main/webapp");
            prefs.putBoolean("warSrcDirIsOutput", false);

            String artifactId = mavenProject.getArtifactId();
            String version = mavenProject.getVersion();
            IPath location = SpringCoreUtils.getProjectLocation(project);
            if (location != null && artifactId != null && version != null) {
                prefs.put("lastWarOutDir", location.append("target").append(artifactId + "-" + version).toFile()
                        .getAbsolutePath());
            }

            prefs.flush();
        } catch (BackingStoreException e) {
            MavenCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                    MavenCorePlugin.NON_LEGACY_PLUGIN_ID, "Error configuring project", e));
        }
    }
}

From source file:org.srcdeps.mvn.plugin.SrcdepsInitMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    super.execute();

    org.srcdeps.core.GavSet.Builder gavSetBuilder = GavSet.builder() //
            .includes(includes) //
            .excludes(excludes);//from  w  ww .  ja  va  2 s  .c o m
    if (excludeSnapshots) {
        gavSetBuilder.excludeSnapshots();
    }
    this.gavSet = gavSetBuilder.build();

    log.info("Using includes and excludes [{}]", gavSet);

    log.info("Supported SCMs: {}", scms);

    if (skip || !multiModuleRootDir.equals(session.getCurrentProject().getBasedir())) {
        log.info(getClass().getSimpleName() + " skipped");
    } else {

        Configuration.Builder config = Configuration.builder() //
                .configModelVersion(Configuration.getLatestConfigModelVersion()).commentBefore("") //
                .commentBefore("srcdeps.yaml - the srcdeps configuration file") //
                .commentBefore("") //
                .commentBefore(
                        "The full srcdeps.yaml reference can be found under https://github.com/srcdeps/srcdeps-core/tree/master/doc/srcdeps.yaml") //
                .commentBefore("") //
                .commentBefore("This file was generated by the following command:") //
                .commentBefore("") //
                .commentBefore("    mvn org.srcdeps.mvn:srcdeps-maven-plugin:init") //
                .commentBefore("") //
        ;

        ScmRepositoryIndex index = new ScmRepositoryIndex(session, repoSession, repositorySystem,
                projectBuilder, scms);
        log.debug("Going over [{}] reactor projects", reactorProjects.size());
        /* first add the reactor projects to seenGas so that they get ignored */
        for (MavenProject project : reactorProjects) {
            index.ignoreGav(project.getGroupId(), project.getArtifactId(), project.getVersion());
        }

        for (MavenProject project : reactorProjects) {

            final List<Dependency> dependencies = project.getDependencies();

            log.info("Project [{}] has [{}] dependencies", project.getArtifactId(),
                    dependencies == null ? 0 : dependencies.size());

            if (dependencies != null) {
                for (Dependency dependency : dependencies) {

                    final String g = dependency.getGroupId();
                    final String a = dependency.getArtifactId();
                    final String v = dependency.getVersion();
                    if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) {
                        /* Ignore system scope */
                        index.addGav(g, a, v, failOnUnresolvable);
                    }
                }
            }

            final DependencyManagement dependencyManagement = project.getDependencyManagement();
            if (dependencyManagement != null) {
                final List<Dependency> managedDeps = dependencyManagement.getDependencies();
                if (managedDeps != null) {
                    for (Dependency dependency : managedDeps) {
                        final String g = dependency.getGroupId();
                        final String a = dependency.getArtifactId();
                        final String v = dependency.getVersion();
                        if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) {
                            /* Ignore system scope */
                            index.addGav(g, a, v, false);
                        }
                    }
                }
            }

            MavenProject parent = project.getParent();
            if (parent != null) {
                final String g = parent.getGroupId();
                final String a = parent.getArtifactId();
                final String v = parent.getVersion();
                if (gavSet.contains(g, a, v)) {
                    index.addGav(g, a, v, failOnUnresolvable);
                }
            }
        }

        Map<String, Builder> repos = index.createSortedScmRepositoryMap();
        if (repos.size() == 0) {
            /* add some dummy repo so that we do not write an empty srcdeps.yaml file */
            ScmRepository.Builder dummyRepo = ScmRepository.builder() //
                    .commentBefore(
                            "FIXME: srcdeps-maven-plugin could not authomatically identify any SCM URLs for dependencies in this project") //
                    .commentBefore(
                            "       and has added this dummy repository only as a starting point for you to proceed manually") //
                    .id("org.my-group") //
                    .selector("org.my-group") //
                    .url("git:https://github.com/my-org/my-project.git") //
            ;
            repos.put(dummyRepo.getName(), dummyRepo);
        }

        config //
                .repositories(repos) //
                .accept(new OverrideVisitor(System.getProperties())) //
                .accept(new DefaultsAndInheritanceVisitor()) //
        ;

        final Path srcdepsYamlPath = multiModuleRootDir.toPath().resolve("srcdeps.yaml");
        try {
            YamlWriterConfiguration yamlWriterConfiguration = YamlWriterConfiguration.builder().build();
            try (Writer out = Files.newBufferedWriter(srcdepsYamlPath, Charset.forName(encoding))) {
                config.accept(new YamlWriterVisitor(out, yamlWriterConfiguration));
            }
        } catch (IOException e) {
            throw new MojoExecutionException(String.format("Could not write [%s]", srcdepsYamlPath), e);
        }
    }

}

From source file:org.talend.components.api.service.internal.ComponentServiceImpl.java

License:Open Source License

public Set<Dependency> getArtifactsDependencies(MavenProject project, MavenBooter booter,
        String... excludedScopes)
        throws DependencyCollectionException, org.eclipse.aether.resolution.DependencyResolutionException {
    DefaultArtifact pomArtifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(),
            project.getPackaging(), null, project.getVersion());
    // check the cache if we already have computed the dependencies for this pom.
    if (dependenciesCache.containsKey(pomArtifact)) {
        return dependenciesCache.get(pomArtifact);
    }//www.j  a  va 2s  .  c o  m
    RepositorySystem repoSystem = booter.newRepositorySystem();
    DefaultRepositorySystemSession repoSession = booter.newRepositorySystemSession(repoSystem);
    DependencySelector depFilter = new AndDependencySelector(
            new ScopeDependencySelector(null, Arrays.asList(excludedScopes)), new OptionalDependencySelector(),
            new ExclusionDependencySelector());
    repoSession.setDependencySelector(depFilter);

    List<RemoteRepository> remoteRepos = booter.getRemoteRepositoriesWithAuthentification(repoSystem,
            repoSession);

    CollectRequest collectRequest = new CollectRequest(new Dependency(pomArtifact, "runtime"), remoteRepos);
    // collectRequest.setRequestContext(scope);
    CollectResult collectResult = repoSystem.collectDependencies(repoSession, collectRequest);
    DependencyNode root = collectResult.getRoot();
    Set<Dependency> ret = new HashSet<>();
    ret.add(root.getDependency());
    flattenDeps(root, ret);
    dependenciesCache.put(pomArtifact, ret);
    return ret;
}

From source file:org.universAAL.support.directives.api.AbstractCheckMojo.java

License:Apache License

/**
 * Check whether the project is at snapshot version
 * @param mp The {@link MavenProject} descriptor
 * @return True if the version contains SNAPSHOT
 *///from   w w w  .ja v  a 2 s .  c om
static public boolean isSnapshot(MavenProject mp) {
    return mp.getVersion().contains("SNAPSHOT");
}

From source file:org.universAAL.support.directives.checks.DependencyManagementCheckFix.java

License:Apache License

private Map<DependencyID, String> getActualVersions(MavenProject mavenProject2) {
    TreeMap<DependencyID, String> versionMap = new TreeMap<DependencyID, String>();
    boolean containsSubPOMProjects = includesPOMSubProjects(mavenProject2);
    for (MavenProject mavenProject : reactorProjects) {
        if (mavenProject.getVersion() != null
                && (!mavenProject.getPackaging().equals("pom") || containsSubPOMProjects)) {
            // Check if its a pom, add it if not!
            versionMap.put(new DependencyID(mavenProject.getGroupId(), mavenProject.getArtifactId()),
                    mavenProject.getVersion());
            getLog().debug("added to ActualVersions: " + mavenProject.getGroupId() + ":"
                    + mavenProject.getArtifactId() + ":" + mavenProject.getVersion());
        }//from ww w  .j  a v a  2 s . com
    }
    return versionMap;
}

From source file:org.universAAL.support.directives.checks.MavenCoordinateCheck.java

License:Apache License

/** {@inheritDoc} */
public boolean check(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {

    String artifactIdMatchString = mavenProject.getProperties().getProperty(ARTIFACT_ID_MATCH_PROP,
            DEFAULT_MATCH);/*  w w  w . j a  v a  2s.com*/
    String groupIdMatchString = mavenProject.getProperties().getProperty(GROUP_ID_MATCH_PROP, DEFAULT_MATCH);
    String nameMatchString = mavenProject.getProperties().getProperty(NAME_MATCH_PROP, DEFAULT_MATCH);
    String versionMatchString = mavenProject.getProperties().getProperty(VERSION_MATCH_PROP, DEFAULT_MATCH);

    Pattern pAId = Pattern.compile(artifactIdMatchString);
    Pattern pGId = Pattern.compile(groupIdMatchString);
    Pattern pVer = Pattern.compile(versionMatchString);
    Pattern pNam = Pattern.compile(nameMatchString);

    Matcher mAId = pAId.matcher(mavenProject.getArtifactId());
    Matcher mGId = pGId.matcher(mavenProject.getGroupId());
    Matcher mVer = pVer.matcher(mavenProject.getVersion());
    Matcher mNam = pNam.matcher(mavenProject.getName());

    StringBuffer message = new StringBuffer();

    if (!mAId.find()) {
        message.append("ArtifactId: " + mavenProject.getArtifactId() + DOES_NOT_MATCH_CONVENTION
                + artifactIdMatchString + "\n");
    }
    if (!mGId.find()) {
        message.append("GroupId: " + mavenProject.getGroupId() + DOES_NOT_MATCH_CONVENTION + groupIdMatchString
                + "\n");
    }
    if (!mVer.find()) {
        message.append("Version: " + mavenProject.getVersion() + DOES_NOT_MATCH_CONVENTION + versionMatchString
                + "\n");
    }
    if (!mNam.find()) {
        message.append("Artifact Name: " + mavenProject.getName() + DOES_NOT_MATCH_CONVENTION + nameMatchString
                + "\n");
    }

    if (message.length() > 0) {
        throw new MojoFailureException(message.toString());
    }
    Model pomFileModel = null;
    try {
        pomFileModel = PomWriter.readPOMFile(mavenProject);
    } catch (Exception e) {
    }

    if (!mavenProject.getPackaging().equals("pom") && pomFileModel != null
            && (pomFileModel.getProperties().containsKey(ARTIFACT_ID_MATCH_PROP)
                    || pomFileModel.getProperties().containsKey(GROUP_ID_MATCH_PROP)
                    || pomFileModel.getProperties().containsKey(VERSION_MATCH_PROP)
                    || pomFileModel.getProperties().containsKey(NAME_MATCH_PROP))) {
        throw new MojoFailureException("This project has declared naming conventions when it shoudln't.\n"
                + "This is probably an attempt to skip this directive, SHAME ON YOU!");
    }

    return true;
}

From source file:org.universAAL.support.directives.procedures.ChangeVersionProcedure.java

License:Apache License

/** {@inheritDoc} */
public void execute(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {
    try {//from ww w.ja  v  a  2s  .  c om
        log.info("Changing version from: " + mavenProject.getVersion() + " to: " + newVersion);
        new PomWriter(this, mavenProject).fix();
    } catch (Exception e) {
        throw new MojoExecutionException("unable to fix Version");
    }
}

From source file:org.universAAL.support.directives.procedures.IncreaseVersionProcedure.java

License:Apache License

/** {@inheritDoc} */
public void execute(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {
    new ChangeVersionProcedure(nextDevelopmentVersion(mavenProject.getVersion())).execute(mavenProject, log);

}