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:net.oneandone.maven.plugins.prerelease.core.Descriptor.java

License:Apache License

/** @return this */
public Descriptor check(World world, MavenProject mavenProject, boolean allowSnapshots,
        boolean allowPrereleaseSnapshots) throws TagAlreadyExists, VersioningProblem, CannotDeterminTagBase,
        MissingScmTag, CannotBumpVersion, MissingDeveloperConnection {
    List<String> problems;
    MavenProject parent;//w ww . ja  va  2 s.co m

    problems = new ArrayList<>();
    checkSnapshot("project", mavenProject.getVersion(), problems);
    parent = mavenProject.getParent();
    if (parent != null) {
        checkRelease("project parent", parent.getVersion(), problems);
    }
    for (Dependency dependency : mavenProject.getDependencies()) {
        checkRelease(dependency.getGroupId() + ":" + dependency.getArtifactId(), dependency.getVersion(),
                problems);
    }
    for (Artifact artifact : mavenProject.getPluginArtifacts()) {
        if (allowPrereleaseSnapshots && "net.oneandone.maven.plugins".equals(artifact.getGroupId())
                && "prerelease".equals(artifact.getArtifactId())) {
            // skip for integration tests
        } else {
            checkRelease(artifact.getGroupId() + ":" + artifact.getArtifactId(), artifact.getVersion(),
                    problems);
        }
    }
    if (problems.size() > 0 && !allowSnapshots) {
        throw new VersioningProblem(problems);
    }
    if (Subversion.exists(world.getTemp(), svnTag)) {
        throw new TagAlreadyExists(svnTag);
    }
    return this;
}

From source file:net.oneandone.maven.plugins.prerelease.core.Descriptor.java

License:Apache License

public static String releaseVersion(MavenProject project) {
    return Strings.removeRight(project.getVersion(), "-SNAPSHOT");
}

From source file:net.oneandone.pommes.cli.Environment.java

License:Apache License

public String lookup(String name) throws IOException {
    MavenProject p;
    FileNode here;//from   w  w w  . j  a  va 2 s  .  co m
    Point point;

    switch (name) {
    case "svn":
        here = (FileNode) world.getWorking();
        point = fstab().pointOpt(here);
        if (point == null) {
            throw new IllegalArgumentException("no mount point for directory " + here.getAbsolute());
        }
        return point.svnurl(here);
    case "gav":
        p = project();
        return p.getGroupId() + ":" + p.getArtifactId() + ":" + p.getVersion();
    case "ga":
        p = project();
        return p.getGroupId() + ":" + p.getArtifactId();
    default:
        return null;
    }
}

From source file:net.oneandone.pommes.model.Pom.java

License:Apache License

public static Pom forProject(String origin, MavenProject project) {
    Pom result;//from   w  ww. ja v a 2 s .  c  o  m

    result = new Pom(origin, new GAV(project.getGroupId(), project.getArtifactId(), project.getVersion()));
    for (Dependency dependency : project.getDependencies()) {
        result.dependencies.add(GAV.forDependency(dependency));
    }
    return result;
}

From source file:net.oneki.maven.plugins.helper.ArtifactHelper.java

License:Apache License

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

From source file:net.sf.buildbox.maven.contentcheck.LicenseShowMojo.java

License:Open Source License

/**
 * @see net.sf.buildbox.maven.contentcheck.AbstractArchiveContentMojo#doExecute()
 *///from www.java  2s  .  c  o m
@Override
protected void doExecute() throws IOException, MojoExecutionException, MojoFailureException {
    List<MavenProject> mavenProjectForDependencies = getMavenProjectForDependencies();

    DefaultIntrospector introspector = new DefaultIntrospector(getLog(), isIgnoreVendorArchives(),
            getVendorId(), getManifestVendorEntry(), getCheckFilesPattern());
    introspector.readArchive(getArchive());

    Set<String> archiveEntries = new LinkedHashSet<String>(introspector.getArchiveEntries());
    Map<String, List<License>> entries = new LinkedHashMap<String, List<License>>();

    Map<String, List<License>> additionalLicenseInformation = new LinkedHashMap<String, List<License>>();
    if (licenseMappingFile != null && licenseMappingFile.exists()) {
        //read additional license information
        LicenseMappingParser licenseMappingParser = new LicenseMappingParser(getLog(), licenseMappingFile);
        additionalLicenseInformation.putAll(licenseMappingParser.parseLicenseMappingFile());
    }

    getLog().info("Comparing the archive content with Maven project artifacts");
    for (String archiveEntry : archiveEntries) {
        List<License> licenses = null; //these licenses will be associated with the given archive entry

        for (MavenProject mavenProject : mavenProjectForDependencies) {
            mavenProject.getGroupId();
            String artifactId = mavenProject.getArtifactId();
            String version = mavenProject.getVersion();
            String jarName = artifactId + "-" + version + ".jar"; //guess jar name
            if (archiveEntry.endsWith(jarName)) {
                @SuppressWarnings("unchecked")
                List<License> _licenses = mavenProject.getLicenses();
                licenses = _licenses == null || _licenses.size() == 0 ? null : _licenses;
                break;
            }
        }

        List<License> licensesMappingFile = additionalLicenseInformation
                .get(stripJARNameFromPath(archiveEntry));

        if (licenses == null && licensesMappingFile == null) {//misising license information
            getLog().debug(String.format(
                    "Cannot resolve license information for archive entry %s neither from the POM file nor the file for license mapping",
                    archiveEntry));
            //archive entry must be present even if there is no a matching Maven Project
            entries.put(archiveEntry, Collections.<License>emptyList());
        } else if (licenses != null && licensesMappingFile != null) {//licenses specified in both - POM and license mapping file
            getLog().warn(String.format(
                    "The license information for file %s are defined in the POM file and also in the file for license mapping. Using license information from the the file for license mapping.",
                    archiveEntry));
            entries.put(archiveEntry, licensesMappingFile); //mapping manually specified licenses precedes licenses from POM
        } else if (licenses != null) {//license information in POM
            entries.put(archiveEntry, licenses);//license
        } else {
            //license information in mapping file
            //put additional license information to the object that holds this information
            entries.put(archiveEntry, licensesMappingFile);
        }
    }

    LicenseOutput logOutput = new LogOutput(getLog());
    logOutput.output(entries);

    if (csvOutput) {
        CsvOutput csvOutput = new CsvOutput(getLog(), csvOutputFile);
        csvOutput.output(entries);
    }
}

From source file:net.timandersen.StopTimer.java

License:Apache License

public void execute() throws MojoExecutionException {
    try {//from  w ww. ja  va  2 s . c  o m
        String computername = InetAddress.getLocalHost().getHostName();
        MavenProject proj = (MavenProject) getPluginContext().get("project");
        long elapsedTime = Stopwatch.elapsedTime();
        String reportUrlWithParams = reportUrl + "/" + computername + "/" + proj.getName() + "/"
                + proj.getVersion() + "/" + elapsedTime;

        getLog().info("##### Stopping timer! Elapsed Time (" + elapsedTime + " ms)");
        getLog().info(reportUrlWithParams);

        if (reportUrl != null && !reportUrl.equals("")) {
            new HttpClient().executeMethod(new GetMethod(reportUrlWithParams));
        }

    } catch (Exception e) {
        getLog().error("Exception caught =" + e.getMessage());
    }
}

From source file:net.ubos.tools.pacmanpkgmavenplugin.PacmanPkgMavenPlugin.java

License:Open Source License

/**
 * {@inheritDoc}//from w w w  . ja v a2  s.  c o m
 * 
 * @throws MojoExecutionException
 */
@Override
public void execute() throws MojoExecutionException {
    MavenProject project = (MavenProject) getPluginContext().get("project");
    String packaging = project.getPackaging();

    if (!"jar".equals(packaging) && !"ear".equals(packaging) && !"war".equals(packaging)) {
        return;
    }

    getLog().info("Generating PKGBUILD @ " + project.getName());

    // pull stuff out of MavenProject
    String artifactId = project.getArtifactId();
    String version = project.getVersion();
    String url = project.getUrl();
    String description = project.getDescription();
    Set<Artifact> dependencies = project.getDependencyArtifacts();
    File artifactFile = project.getArtifact().getFile();

    if (artifactFile == null || !artifactFile.exists()) {
        throw new MojoExecutionException("pacmanpkg must be executed as part of a build, not standalone,"
                + " otherwise it can't find the main JAR file");
    }
    // translate to PKGBUILD fields
    String pkgname = artifactId;
    String pkgver = version.replaceAll("-SNAPSHOT", "a"); // alpha
    String pkgdesc = "A Java package available on UBOS";
    if (description != null) {
        if (description.length() > 64) {
            pkgdesc = description.substring(0, 64) + "...";
        } else {
            pkgdesc = description;
        }
    }

    ArrayList<String> depends = new ArrayList<>(dependencies.size());
    for (Artifact a : dependencies) {
        if (!"test".equals(a.getScope())) {
            depends.add(a.getArtifactId());
        }
    }
    // write to PKGBUILD
    try {
        File baseDir = project.getBasedir();
        File pkgBuild = new File(baseDir, "target/PKGBUILD");
        PrintWriter out = new PrintWriter(pkgBuild);

        getLog().debug("Writing PKGBUILD to " + pkgBuild.getAbsolutePath());

        out.println("#");
        out.println(" * Automatically generated by pacman-pkg-maven-plugin; do not modify.");
        out.println("#");

        out.println();

        out.println("pkgname=" + pkgname);
        out.println("pkgver=" + pkgver);
        out.println("pkgrel=" + pkgrel);
        out.println("pkgdesc='" + pkgdesc + "'");
        out.println("arch=('any')");
        out.println("url='" + url + "'");
        out.println("license=('" + license + "')");

        out.print("depends=(");
        String sep = "";
        for (String d : depends) {
            out.print(sep);
            sep = ",";
            out.print("'");
            out.print(d);
            out.print("'");
        }
        out.println(")");

        out.println();

        out.println("package() (");
        out.println("   mkdir -p ${pkgdir}/usr/share/java");
        out.println("   install -m644 ${startdir}/" + artifactFile.getName() + " ${pkgdir}/usr/share/java/");
        out.println(")");

        out.close();

    } catch (IOException ex) {
        throw new MojoExecutionException("Failed to write target/PKGBUILD", ex);
    }
}

From source file:net.wasdev.wlp.maven.plugins.applications.InstallAppMojoSupport.java

License:Open Source License

private String getWarFileName(MavenProject project) {
    String name = project.getBuild().getFinalName() + "." + project.getPackaging();
    if (project.getPackaging().equals("liberty-assembly")) {
        name = project.getBuild().getFinalName() + ".war";
    }/* w w  w . j  a  v  a  2  s. co m*/
    if (stripVersion) {
        name = stripVersionFromName(name, project.getVersion());
    }
    return name;
}

From source file:nl.mpi.tla.version.controller.VersionControlCheck.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException {
    final VcsVersionChecker versionChecker;
    try {/*  w  w  w.j a v a2  s.  c  o  m*/
        switch (VcsType.valueOf(vcsType)) {
        case git:
            versionChecker = new GitVersionChecker(new CommandRunnerImpl());
            break;
        case svn:
            versionChecker = new SvnVersionChecker(new CommandRunnerImpl());
            break;
        default:
            throw new MojoExecutionException("Unknown version control system: " + vcsType);
        }
    } catch (IllegalArgumentException exception) {
        throw new MojoExecutionException("Unknown version control system: " + vcsType + "\nValid options are: "
                + VcsType.git.name() + " or " + VcsType.svn.name());
    }
    if (verbose) {
        logger.info("VersionControlCheck");
        logger.info("project: " + project);
        logger.info("majorVersion: " + majorVersion);
        logger.info("minorVersion: " + minorVersion);
        logger.info("buildType: " + buildType);
        logger.info("outputDirectory: " + outputDirectory);
        logger.info("projectDirectory :" + projectDirectory);
    }
    for (MavenProject reactorProject : mavenProjects) {
        final String artifactId = reactorProject.getArtifactId();
        final String moduleVersion = reactorProject.getVersion();
        final String groupId = reactorProject.getGroupId();
        logger.info("Checking version numbers for " + artifactId);
        if (verbose) {
            logger.info("artifactId: " + artifactId);
            logger.info("moduleVersion: " + moduleVersion);
            logger.info("moduleDir :" + reactorProject.getBasedir());
        }
        //                for (MavenProject dependencyProject : reactorProject.getDependencies()) {
        //                    logger.info("dependencyProject:" + dependencyProject.getArtifactId());
        //                }
        final String expectedVersion;
        final String buildVersionString;
        final File moduleDirectory = reactorProject.getBasedir();
        if (allowSnapshots && moduleVersion.contains("SNAPSHOT")) {
            expectedVersion = majorVersion + "." + minorVersion + "-" + buildType + "-SNAPSHOT";
            buildVersionString = "-1"; //"SNAPSHOT"; it will be nice to have snapshot here but we need to update some of the unit tests first
        } else if ((modulesWithShortVersion != null && modulesWithShortVersion.contains(artifactId))
                || (moduleWithShortVersion != null && moduleWithShortVersion.equals(artifactId))) {
            expectedVersion = majorVersion + "." + minorVersion;
            buildVersionString = "-1";
        } else {
            logger.info("getting build number");
            int buildVersion = versionChecker.getBuildNumber(verbose, moduleDirectory, ".");
            logger.info(artifactId + ".buildVersion: " + Integer.toString(buildVersion));
            expectedVersion = majorVersion + "." + minorVersion + "." + buildVersion + "-" + buildType;
            buildVersionString = Integer.toString(buildVersion);
        }
        if (!expectedVersion.equals(moduleVersion)) {
            logger.error("Expecting version number: " + expectedVersion);
            logger.error("But found: " + moduleVersion);
            logger.error("Artifact: " + artifactId);
            throw new MojoExecutionException("The build numbers to not match for '" + artifactId + "': '"
                    + expectedVersion + "' vs '" + moduleVersion + "'");
        }
        // get the last commit date
        logger.info("getting lastCommitDate");
        final String lastCommitDate = versionChecker.getLastCommitDate(verbose, moduleDirectory, ".");
        logger.info(".lastCommitDate:" + lastCommitDate);
        // construct the compile date
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
        Date date = new Date();
        final String buildDate = dateFormat.format(date);
        // setting the maven properties
        final String versionPropertyName = groupId + "." + artifactId + ".moduleVersion";
        logger.info("Setting property '" + versionPropertyName + "' to '" + expectedVersion + "'");
        reactorProject.getProperties().setProperty(versionPropertyName, expectedVersion);
        reactorProject.getProperties().setProperty(propertiesPrefix + ".majorVersion", majorVersion);
        reactorProject.getProperties().setProperty(propertiesPrefix + ".minorVersion", minorVersion);
        reactorProject.getProperties().setProperty(propertiesPrefix + ".buildVersion", buildVersionString);
        reactorProject.getProperties().setProperty(propertiesPrefix + ".lastCommitDate", lastCommitDate);
        reactorProject.getProperties().setProperty(propertiesPrefix + ".buildDate", buildDate);
    }
}