Example usage for org.apache.maven.artifact Artifact SNAPSHOT_VERSION

List of usage examples for org.apache.maven.artifact Artifact SNAPSHOT_VERSION

Introduction

In this page you can find the example usage for org.apache.maven.artifact Artifact SNAPSHOT_VERSION.

Prototype

String SNAPSHOT_VERSION

To view the source code for org.apache.maven.artifact Artifact SNAPSHOT_VERSION.

Click Source Link

Usage

From source file:com.amashchenko.maven.plugin.gitflow.GitFlowFeatureStartMojo.java

License:Apache License

/** {@inheritDoc} */
@Override//from w  w  w. j  a v  a2s . c o m
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        // set git flow configuration
        initGitFlowConfig();

        // check uncommitted changes
        checkUncommittedChanges();

        String featureName = null;
        try {
            while (StringUtils.isBlank(featureName)) {
                featureName = prompter
                        .prompt("What is a name of feature branch? " + gitFlowConfig.getFeatureBranchPrefix());
            }
        } catch (PrompterException e) {
            getLog().error(e);
        }

        featureName = StringUtils.deleteWhitespace(featureName);

        // git for-each-ref refs/heads/feature/...
        final String featureBranch = executeGitCommandReturn("for-each-ref",
                "refs/heads/" + gitFlowConfig.getFeatureBranchPrefix() + featureName);

        if (StringUtils.isNotBlank(featureBranch)) {
            throw new MojoFailureException(
                    "Feature branch with that name already exists. Cannot start feature.");
        }

        // git checkout -b ... develop
        gitCreateAndCheckout(gitFlowConfig.getFeatureBranchPrefix() + featureName,
                gitFlowConfig.getDevelopmentBranch());

        if (!skipFeatureVersion) {
            // get current project version from pom
            final String currentVersion = getCurrentProjectVersion();

            String version = null;
            try {
                final DefaultVersionInfo versionInfo = new DefaultVersionInfo(currentVersion);
                version = versionInfo.getReleaseVersionString() + "-" + featureName + "-"
                        + Artifact.SNAPSHOT_VERSION;
            } catch (VersionParseException e) {
                if (getLog().isDebugEnabled()) {
                    getLog().debug(e);
                }
            }

            if (StringUtils.isNotBlank(version)) {
                // mvn versions:set -DnewVersion=...
                // -DgenerateBackupPoms=false
                mvnSetVersions(version);

                // git commit -a -m updating poms for feature branch
                gitCommit("updating poms for feature branch");
            }
        }

        if (installProject) {
            // mvn clean install
            mvnCleanInstall();
        }
    } catch (CommandLineException e) {
        getLog().error(e);
    }
}

From source file:com.amashchenko.maven.plugin.gitflow.GitFlowReleaseMojo.java

License:Apache License

/** {@inheritDoc} */
@Override//from ww w.ja v a2 s.c  om
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        // set git flow configuration
        initGitFlowConfig();

        // check uncommitted changes
        checkUncommittedChanges();

        // git for-each-ref --count=1 refs/heads/release/*
        final String releaseBranch = gitFindBranches(gitFlowConfig.getReleaseBranchPrefix(), true);

        if (StringUtils.isNotBlank(releaseBranch)) {
            throw new MojoFailureException("Release branch already exists. Cannot start release.");
        }

        if (fetchRemote) {
            // checkout from remote if doesn't exist
            gitFetchRemoteAndCreate(gitFlowConfig.getDevelopmentBranch());

            // fetch and check remote
            gitFetchRemoteAndCompare(gitFlowConfig.getDevelopmentBranch());

            if (notSameProdDevName()) {
                // checkout from remote if doesn't exist
                gitFetchRemoteAndCreate(gitFlowConfig.getProductionBranch());

                // fetch and check remote
                gitFetchRemoteAndCompare(gitFlowConfig.getProductionBranch());
            }
        }

        // need to be in develop to check snapshots and to get correct
        // project version
        // git checkout develop
        gitCheckout(gitFlowConfig.getDevelopmentBranch());

        // check snapshots dependencies
        if (!allowSnapshots) {
            checkSnapshotDependencies();
        }

        if (!skipTestProject) {
            // mvn clean test
            mvnCleanTest();
        }

        // get current project version from pom
        final String currentVersion = getCurrentProjectVersion();

        String defaultVersion = null;
        if (tychoBuild) {
            defaultVersion = currentVersion;
        } else {
            // get default release version
            defaultVersion = new GitFlowVersionInfo(currentVersion).getReleaseVersionString();
        }

        if (defaultVersion == null) {
            throw new MojoFailureException("Cannot get default project version.");
        }

        String version = null;
        if (settings.isInteractiveMode()) {
            try {
                while (version == null) {
                    version = prompter.prompt("What is release version? [" + defaultVersion + "]");

                    if (!"".equals(version)
                            && (!GitFlowVersionInfo.isValidVersion(version) || !validBranchName(version))) {
                        getLog().info("The version is not valid.");
                        version = null;
                    }
                }
            } catch (PrompterException e) {
                getLog().error(e);
            }
        } else {
            version = releaseVersion;
        }

        if (StringUtils.isBlank(version)) {
            version = defaultVersion;
        }

        // execute if version changed
        if (!version.equals(currentVersion)) {
            // mvn set version
            mvnSetVersions(version);

            // git commit -a -m updating versions for release
            gitCommit(commitMessages.getReleaseStartMessage());
        }

        if (notSameProdDevName()) {
            // git checkout master
            gitCheckout(gitFlowConfig.getProductionBranch());

            gitMerge(gitFlowConfig.getDevelopmentBranch(), releaseRebase, releaseMergeNoFF, releaseMergeFFOnly);
        }

        String tagVersion = null;

        if (!skipTag) {
            if (tychoBuild && ArtifactUtils.isSnapshot(version)) {
                version = version.replace("-" + Artifact.SNAPSHOT_VERSION, "");
            }
            tagVersion = gitFlowConfig.getVersionTagPrefix() + version;

            // git tag -a ...

            gitTag(tagVersion, commitMessages.getTagReleaseMessage());
        }

        if (notSameProdDevName()) {
            // git checkout develop
            gitCheckout(gitFlowConfig.getDevelopmentBranch());
        }

        // get next snapshot version
        final String nextSnapshotVersion = new GitFlowVersionInfo(version).nextSnapshotVersion();

        if (StringUtils.isBlank(nextSnapshotVersion)) {
            throw new MojoFailureException("Next snapshot version is blank.");
        }

        // mvn set version
        mvnSetVersions(nextSnapshotVersion);

        // git commit -a -m updating for next development version
        gitCommit(commitMessages.getReleaseFinishMessage());

        if (installProject) {
            // mvn clean install
            mvnCleanInstall();
        }

        if (pushRemote) {
            gitPush(gitFlowConfig.getProductionBranch(), !skipTag);
            if (notSameProdDevName()) {
                gitPush(gitFlowConfig.getDevelopmentBranch(), !skipTag);
            }
        }
        if (!skipTag && !skipMvnDeploy) {
            mvnDeploy(tagVersion);
        }
    } catch (CommandLineException e) {
        getLog().error(e);
    } catch (VersionParseException e) {
        getLog().error(e);
    }
}

From source file:com.amashchenko.maven.plugin.gitflow.GitFlowVersionInfo.java

License:Apache License

/**
 * Gets version with appended feature name.
 * /*from  ww w  .j a v a2 s .  c  o  m*/
 * @param featureName
 *            Feature name to append.
 * @return Version with appended feature name.
 */
public String featureVersion(final String featureName) {
    String version = toString();
    if (featureName != null) {
        version = getReleaseVersionString() + "-" + featureName
                + (isSnapshot() ? "-" + Artifact.SNAPSHOT_VERSION : "");
    }
    return version;
}

From source file:com.labs64.mojo.swid.GenerateMojo.java

License:Apache License

private ArtifactVersion getArtifactVersion() {
    if (ArtifactUtils.isSnapshot(product_version)) {
        product_version = StringUtils.substring(product_version, 0,
                product_version.length() - Artifact.SNAPSHOT_VERSION.length() - 1);
    }/*from w w  w.  ja va  2  s.c o m*/
    return new DefaultArtifactVersion(product_version);
}

From source file:it.netsw.maven.buildhelper.ParseVersionMojo.java

License:Open Source License

/**
 * Parse a version String and add the components to a properties object.
 *
 * @param version the version to parse// w  w w  .j  a va2s .c o  m
 */
public void parseVersion(String version) {
    ArtifactVersion artifactVersion = new DefaultArtifactVersion(version);

    ArtifactVersion releaseVersion = artifactVersion;
    if (ArtifactUtils.isSnapshot(version)) {
        // work around for MBUILDHELPER-69
        releaseVersion = new DefaultArtifactVersion(
                StringUtils.substring(version, 0, version.length() - Artifact.SNAPSHOT_VERSION.length() - 1));
    }

    if (version.equals(artifactVersion.getQualifier())) {
        // This means the version parsing failed, so try osgi format.
        getLog().debug("The version is not in the regular format, will try OSGi format instead");
        artifactVersion = new OsgiArtifactVersion(version);
    }

    defineVersionProperty("majorVersion", artifactVersion.getMajorVersion());
    defineVersionProperty("minorVersion", artifactVersion.getMinorVersion());
    defineVersionProperty("incrementalVersion", artifactVersion.getIncrementalVersion());
    defineVersionProperty("nextMajorVersion", artifactVersion.getMajorVersion() + 1);
    defineVersionProperty("nextMinorVersion", artifactVersion.getMinorVersion() + 1);
    defineVersionProperty("nextIncrementalVersion", artifactVersion.getIncrementalVersion() + 1);

    String qualifier = artifactVersion.getQualifier();
    if (qualifier == null) {
        qualifier = "";
    }
    defineVersionProperty("qualifier", qualifier);

    defineVersionProperty("buildNumber", releaseVersion.getBuildNumber()); // see MBUILDHELPER-69
    defineVersionProperty("nextBuildNumber", releaseVersion.getBuildNumber() + 1);
    // Replace the first instance of "-" to create an osgi compatible version string.
    String osgiVersion = getOsgiVersion(artifactVersion);
    defineVersionProperty("osgiVersion", osgiVersion);
}

From source file:org.codehaus.mojo.buildhelper.ParseVersionMojo.java

License:Open Source License

/**
 * Parse a version String and add the components to a properties object.
 *
 * @param version the version to parse/*w ww .j  a v  a2s  . c  o m*/
 */
public void parseVersion(String version) {
    ArtifactVersion artifactVersion = new DefaultArtifactVersion(version);

    ArtifactVersion releaseVersion = artifactVersion;
    if (ArtifactUtils.isSnapshot(version)) {
        // work around for MBUILDHELPER-69
        releaseVersion = new DefaultArtifactVersion(
                StringUtils.substring(version, 0, version.length() - Artifact.SNAPSHOT_VERSION.length() - 1));
    }

    if (version.equals(artifactVersion.getQualifier())) {
        // This means the version parsing failed, so try osgi format.
        getLog().debug("The version is not in the regular format, will try OSGi format instead");
        artifactVersion = new OsgiArtifactVersion(version);
    }

    defineVersionProperty("majorVersion", artifactVersion.getMajorVersion());
    defineVersionProperty("minorVersion", artifactVersion.getMinorVersion());
    defineVersionProperty("incrementalVersion", artifactVersion.getIncrementalVersion());
    defineVersionProperty("nextMajorVersion", artifactVersion.getMajorVersion() + 1);
    defineVersionProperty("nextMinorVersion", artifactVersion.getMinorVersion() + 1);
    defineVersionProperty("nextIncrementalVersion", artifactVersion.getIncrementalVersion() + 1);

    String qualifier = artifactVersion.getQualifier();
    if (qualifier == null) {
        qualifier = "";
    }
    defineVersionProperty("qualifier", qualifier);

    defineVersionProperty("buildNumber", releaseVersion.getBuildNumber()); // see MBUILDHELPER-69

    // Replace the first instance of "-" to create an osgi compatible version string.
    String osgiVersion = getOsgiVersion(artifactVersion);
    defineVersionProperty("osgiVersion", osgiVersion);
}

From source file:org.codehaus.mojo.license.api.DefaultThirdPartyTool.java

License:Open Source License

/**
 * {@inheritDoc}/*  ww w . jav a 2 s  . c  o m*/
 */
public SortedProperties loadUnsafeMapping(LicenseMap licenseMap, SortedMap<String, MavenProject> artifactCache,
        String encoding, File missingFile) throws IOException {
    Map<String, MavenProject> snapshots = new HashMap<String, MavenProject>();

    //find snapshot dependencies
    for (Map.Entry<String, MavenProject> entry : artifactCache.entrySet()) {
        MavenProject mavenProject = entry.getValue();
        if (mavenProject.getVersion().endsWith(Artifact.SNAPSHOT_VERSION)) {
            snapshots.put(entry.getKey(), mavenProject);
        }
    }

    for (Map.Entry<String, MavenProject> snapshot : snapshots.entrySet()) {
        // remove invalid entries, which contain timestamps in key
        artifactCache.remove(snapshot.getKey());
        // put corrected keys/entries into artifact cache
        MavenProject mavenProject = snapshot.getValue();

        String id = MojoHelper.getArtifactId(mavenProject.getArtifact());
        artifactCache.put(id, mavenProject);

    }
    SortedSet<MavenProject> unsafeDependencies = getProjectsWithNoLicense(licenseMap, false);

    SortedProperties unsafeMappings = new SortedProperties(encoding);

    if (missingFile.exists()) {
        // there is some unsafe dependencies

        getLogger().info("Load missing file " + missingFile);

        // load the missing file
        unsafeMappings.load(missingFile);
    }

    // get from the missing file, all unknown dependencies
    List<String> unknownDependenciesId = new ArrayList<String>();

    // coming from maven-license-plugin, we used the full g/a/v/c/t. Now we remove classifier and type
    // since GAV is good enough to qualify a license of any artifact of it...
    Map<String, String> migrateKeys = migrateMissingFileKeys(unsafeMappings.keySet());

    for (Object o : migrateKeys.keySet()) {
        String id = (String) o;
        String migratedId = migrateKeys.get(id);

        MavenProject project = artifactCache.get(migratedId);
        if (project == null) {
            // now we are sure this is a unknown dependency
            unknownDependenciesId.add(id);
        } else {
            if (!id.equals(migratedId)) {

                // migrates id to migratedId
                getLogger().info("Migrates [" + id + "] to [" + migratedId + "] in the missing file.");
                Object value = unsafeMappings.get(id);
                unsafeMappings.remove(id);
                unsafeMappings.put(migratedId, value);
            }
        }
    }

    if (!unknownDependenciesId.isEmpty()) {

        // there is some unknown dependencies in the missing file, remove them
        for (String id : unknownDependenciesId) {
            getLogger().warn(
                    "dependency [" + id + "] does not exist in project, remove it from the missing file.");
            unsafeMappings.remove(id);
        }

        unknownDependenciesId.clear();
    }

    // push back loaded dependencies
    for (Object o : unsafeMappings.keySet()) {
        String id = (String) o;

        MavenProject project = artifactCache.get(id);
        if (project == null) {
            getLogger().warn("dependency [" + id + "] does not exist in project.");
            continue;
        }

        String license = (String) unsafeMappings.get(id);

        String[] licenses = StringUtils.split(license, '|');

        if (ArrayUtils.isEmpty(licenses)) {

            // empty license means not fill, skip it
            continue;
        }

        // add license in map
        addLicense(licenseMap, project, licenses);

        // remove unknown license
        unsafeDependencies.remove(project);
    }

    if (unsafeDependencies.isEmpty()) {

        // no more unknown license in map
        licenseMap.remove(LicenseMap.UNKNOWN_LICENSE_MESSAGE);
    } else {

        // add a "with no value license" for missing dependencies
        for (MavenProject project : unsafeDependencies) {
            String id = MojoHelper.getArtifactId(project.getArtifact());
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("dependency [" + id + "] has no license, add it in the missing file.");
            }
            unsafeMappings.setProperty(id, "");
        }
    }
    return unsafeMappings;
}

From source file:org.eclipse.tycho.buildversion.BuildQualifierMojo.java

License:Open Source License

private String getUnqualifiedVersion() {
    String version = project.getArtifact().getVersion();
    if (version.endsWith("-" + Artifact.SNAPSHOT_VERSION)) {
        version = version.substring(0, version.length() - Artifact.SNAPSHOT_VERSION.length() - 1);
    }/*  ww w .  java2s .  c  o  m*/
    return version;
}

From source file:org.eclipse.tycho.pomgenerator.GeneratePomsMojo.java

License:Open Source License

private static String toMavenVersion(String osgiVersion) {
    if (osgiVersion.endsWith(".qualifier")) {
        return osgiVersion.substring(0, osgiVersion.length() - ".qualifier".length()) + "-"
                + Artifact.SNAPSHOT_VERSION;
    } else {//from   w ww  .  j  av a 2s . co m
        return osgiVersion;
    }
}

From source file:org.jfrog.jade.plugins.natives.plugin.AbstractNativeMojo.java

License:Open Source License

protected String getVersionName(String version) {
    if (versionNameNoSnapshot && version.endsWith(Artifact.SNAPSHOT_VERSION)) {
        version = version.substring(0, version.length() - 1 - Artifact.SNAPSHOT_VERSION.length());
    }/*from  w w w . j av  a  2  s. c  o m*/
    return version;
}