Example usage for org.apache.maven.artifact ArtifactUtils isSnapshot

List of usage examples for org.apache.maven.artifact ArtifactUtils isSnapshot

Introduction

In this page you can find the example usage for org.apache.maven.artifact ArtifactUtils isSnapshot.

Prototype

public static boolean isSnapshot(String version) 

Source Link

Usage

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

License:Apache License

/** {@inheritDoc} */
@Override/*from  w ww. j  a  v a2  s. c o  m*/
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.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 .j  av  a2  s . c om
    return new DefaultArtifactVersion(product_version);
}

From source file:com.maestrodev.plugins.collabnet.FrsDeployMojo.java

License:Apache License

private void verifyConfiguration() throws MojoFailureException {
    if (teamForgeServerId != null) {
        AuthenticationInfo authenticationInfo = wagonManager.getAuthenticationInfo(teamForgeServerId);
        if (authenticationInfo == null) {
            getLog().info("No credentials found for server '" + teamForgeServerId + "' found in settings.xml");
        } else {//from ww  w. j  av  a  2  s .c o m
            teamForgeUsername = authenticationInfo.getUserName();
            teamForgePassword = authenticationInfo.getPassword();

            getLog().debug("Using credentials from settings for user = " + teamForgeUsername);
        }
    }

    if (teamForgeUsername == null) {
        throw new MojoFailureException("TeamForge username must be specified");
    }
    if (teamForgePassword == null) {
        throw new MojoFailureException("TeamForge password must be specified");
    }

    boolean snapshot = ArtifactUtils.isSnapshot(projectArtifact.getVersion());
    if (overwrite == null) {
        overwrite = snapshot;
        getLog().debug("Setting overwrite flag to: " + overwrite);
    }

    if (releaseStatus == null) {
        releaseStatus = snapshot ? "pending" : "active";
        getLog().debug("Using release status: " + releaseStatus);
    }
}

From source file:com.redhat.tools.nexus.audit.serial.store.AbstractAuditStore.java

License:Open Source License

private Gav resolveSnapshotsInGav(final String repoId, final Gav src, final boolean resolveExistingSnapshot)
        throws AuditStoreException {
    Gav gav = src;/*from  ww w. java2 s  .co m*/

    if (resolveExistingSnapshot && ArtifactUtils.isSnapshot(gav.getVersion())) {
        final Artifact a = artifactFactory.createArtifactWithClassifier(gav.getGroupId(), gav.getArtifactId(),
                gav.getVersion(), gav.getExtension(), gav.getClassifier());

        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Resolving snapshot version in: '%s'", a.getId()));
        }
        final SnapshotArtifactRepositoryMetadata m = new SnapshotArtifactRepositoryMetadata(a);

        final String mPath = repoLayout.pathOfRemoteRepositoryMetadata(m);
        final File mappingFile = getMetadataFile(repoId, mPath);

        Reader reader = null;
        String version = null;
        try {
            reader = ReaderFactory.newXmlReader(mappingFile);

            final MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();

            final Metadata metadata = mappingReader.read(reader, false);
            if (metadata != null && metadata.getVersioning() != null) {
                final Versioning versioning = metadata.getVersioning();
                final Snapshot snapshot = versioning.getSnapshot();

                if (snapshot != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(
                                String.format("found snapshot metadata. timestamp: '%s'; build-number: '%s'",
                                        snapshot.getTimestamp(), snapshot.getBuildNumber()));
                    }

                    Long timestamp = gav.getSnapshotTimeStamp();
                    Integer buildnumber = gav.getSnapshotBuildNumber();

                    if (snapshot.getTimestamp() != null) {
                        try {
                            timestamp = Long.valueOf(new SimpleDateFormat(TIMESTAMP_FORMAT)
                                    .parse(snapshot.getTimestamp()).getTime());
                            buildnumber = snapshot.getBuildNumber();
                        } catch (final ParseException e) {
                            throw new AuditStoreException("Cannot parse snapshot timestamp from metadata: '%s'",
                                    e, snapshot.getTimestamp());
                        }

                        final StringBuilder sb = new StringBuilder();
                        sb.append(metadata.getVersion().substring(0, metadata.getVersion().indexOf("SNAPSHOT")))
                                .append(snapshot.getTimestamp()).append("-").append(snapshot.getBuildNumber());

                        version = sb.toString();

                        if (logger.isDebugEnabled()) {
                            logger.debug(String.format("resolved snapshot to: '%s'", version));
                        }

                        gav = new Gav(gav.getGroupId(), gav.getArtifactId(), version, gav.getClassifier(),
                                gav.getExtension(), buildnumber, timestamp, null, true, false, null, false,
                                null);
                    }
                }
            }
        } catch (final FileNotFoundException e) {
            throw new AuditStoreException("Cannot read metadata from '" + mappingFile + "'", e);
        } catch (final IOException e) {
            throw new AuditStoreException("Cannot read metadata from '" + mappingFile + "': " + e.getMessage(),
                    e);
        } catch (final XmlPullParserException e) {
            throw new AuditStoreException("Cannot read metadata from '" + mappingFile + "': " + e.getMessage(),
                    e);
        } catch (final IllegalArtifactCoordinateException e) {
            throw new AuditStoreException(
                    "Invalid artifact coordinate. Error: %s\nGroup-Id: %s\nArtifact-Id: %s"
                            + "\nVersion: %s\nClassifier: %s\nExtension: %s",
                    e, e.getMessage(), gav.getGroupId(), gav.getArtifactId(), version, gav.getClassifier(),
                    gav.getExtension());
        } finally {
            IOUtil.close(reader);
        }
    }

    return gav;
}

From source file:com.sap.prd.mobile.ios.mios.XCodePrepareBuildManager.java

License:Apache License

private void provideThinLib(final File source, MavenProject project, final String xcodeConfiguration,
        final String sdk, final Artifact primaryArtifact) throws IOException {

    final File target = new File(
            FolderLayout.getFolderForExtractedLibsWithGA(project, xcodeConfiguration, sdk,
                    primaryArtifact.getGroupId(), primaryArtifact.getArtifactId()),
            getArchiveFileName(primaryArtifact));

    if (ArtifactUtils.isSnapshot(primaryArtifact.getVersion()) || !useSymbolicLinks()) {
        FileUtils.copyFile(source, target);
    } else {//from w w w .  ja v  a  2 s  .  c  o m
        com.sap.prd.mobile.ios.mios.FileUtils.createSymbolicLink(source, target);
    }
}

From source file:com.sap.prd.mobile.ios.mios.XCodePrepareBuildManager.java

License:Apache License

private void provideFatLib(File source, MavenProject project, final String xcodeConfiguration,
        final Artifact primaryArtifact, Set<String> sdks) throws IOException {

    final File target = new File(
            FolderLayout.getFolderForExtractedFatLibsWithGA(project, xcodeConfiguration,
                    primaryArtifact.getGroupId(), primaryArtifact.getArtifactId()),
            getArchiveFileName(primaryArtifact));

    if (ArtifactUtils.isSnapshot(primaryArtifact.getVersion()) || !useSymbolicLinks()) {
        FileUtils.copyFile(source, target);
    } else {// w  ww .ja  v a  2  s. com
        com.sap.prd.mobile.ios.mios.FileUtils.createSymbolicLink(source, target);
    }

    final FatLibAnalyzer lipoHelper = new FatLibAnalyzer(target);

    //
    // TODO improve hard coded strings for iphoneos and iphonesimulator below
    //
    if (sdks.contains("iphoneos")) {
        if (!lipoHelper.containsArmv())
            LOGGER.warning(
                    "Fat library '" + lipoHelper.getFatLibrary() + "' does not contain a library for armv*.");
        else
            LOGGER.info("Fat library '" + lipoHelper.getFatLibrary() + "'contains a library for armv*.");
    } else if (sdks.contains("iphonesimulator")) {
        if (!lipoHelper.containsI386())
            LOGGER.warning(
                    "Fat library '" + lipoHelper.getFatLibrary() + "' does not contain a library for i386.");
        else
            LOGGER.info("Fat library '" + lipoHelper.getFatLibrary() + "'contains a library for i386.");
    }
}

From source file:fr.paris.lutece.maven.AssemblySiteMojo.java

License:Open Source License

private void assemblySite() throws MojoExecutionException {
    // Explode the webapp in the temporary directory
    explodeWebapp(explodedDirectory);/*from   w w w  . j  a  va2 s .c om*/
    explodeConfigurationFiles(explodedDirectory);

    // put the timestamp in the assembly name
    if (ArtifactUtils.isSnapshot(project.getVersion())) {
        DateFormat utcDateFormatter = new SimpleDateFormat(utcTimestampPattern);
        String newVersion = utcDateFormatter.format(new Date());
        finalName = StringUtils.replace(finalName, SNAPSHOT_PATTERN, newVersion);
    }

    // Make a war from the exploded directory
    File warFile = new File(outputDirectory, finalName + ".war");

    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(warFile);
    archive.setForced(forceCreation);

    try {
        if (explodedDirectory.exists()) {
            archiver.getArchiver().addDirectory(explodedDirectory, PACKAGE_WEBAPP_INCLUDES,
                    PACKAGE_WEBAPP_RESOURCES_EXCLUDES);
        }

        archiver.createArchive(project, archive);
    } catch (Exception e) {
        throw new MojoExecutionException("Error assembling WAR", e);
    }
}

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//from   w w  w  . j  a  v a  2  s  . 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:it.netsw.maven.buildhelper.ReleasedVersionMojo.java

License:Open Source License

@SuppressWarnings("unchecked")
public void execute() {
    org.apache.maven.artifact.Artifact artifact = artifactFactory.createArtifact(getProject().getGroupId(),
            getProject().getArtifactId(), "", "", "");
    try {//  w  w w .  j  ava 2s . c  om
        ArtifactVersion releasedVersion = null;
        List<ArtifactVersion> versions = artifactMetadataSource.retrieveAvailableVersions(artifact,
                localRepository, remoteArtifactRepositories);
        for (ArtifactVersion version : versions) {
            if (!ArtifactUtils.isSnapshot(version.toString())
                    && (releasedVersion == null || version.compareTo(releasedVersion) > 0)) {
                releasedVersion = version;
            }
        }

        if (releasedVersion != null) {
            // Use ArtifactVersion.toString(), the major, minor and incrementalVersion return all an int.
            String releasedVersionValue = releasedVersion.toString();

            // This would not always reflect the expected version.
            int dashIndex = releasedVersionValue.indexOf('-');
            if (dashIndex >= 0) {
                releasedVersionValue = releasedVersionValue.substring(0, dashIndex);
            }

            defineVersionProperty("version", releasedVersionValue);
            defineVersionProperty("majorVersion", releasedVersion.getMajorVersion());
            defineVersionProperty("minorVersion", releasedVersion.getMinorVersion());
            defineVersionProperty("incrementalVersion", releasedVersion.getIncrementalVersion());
        }

    } catch (ArtifactMetadataRetrievalException e) {
        if (getLog().isWarnEnabled()) {
            getLog().warn("Failed to retrieve artifacts metadata, cannot resolve the released version");
        }
    }
}

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//from w  w w.  j  a v a 2  s.com
 */
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);
}