Java Code Examples for org.apache.maven.artifact.versioning.ArtifactVersion#getQualifier()

The following examples show how to use org.apache.maven.artifact.versioning.ArtifactVersion#getQualifier() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArtifactRetriever.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static boolean isReleased(ArtifactVersion version) {
  String qualifier = version.getQualifier();
  if (version.getMajorVersion() <= 0) {
    return false;
  } else if (Strings.isNullOrEmpty(qualifier)) {
    return true; 
  } else if ("final".equalsIgnoreCase(qualifier.toLowerCase(Locale.US))) {
    return true; 
  }
  
  return false;
}
 
Example 2
Source File: PropertyVersions.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
private ArtifactVersion getLowerBound(VersionsHelper helper,
        String currentVersion, int segment)
{
    ArtifactVersion version = helper.createArtifactVersion(currentVersion);
    int segmentCount = getVersionComparator().getSegmentCount(version);
    if (segment < 0 || segment > segmentCount)
    {
        throw new InvalidSegmentException(segment, segmentCount,
                currentVersion);
    }

    StringBuilder newVersion = new StringBuilder();
    newVersion.append(segment >= 0 ? version.getMajorVersion() : 0);
    if (segmentCount > 0)
    {
        newVersion.append(".")
                .append(segment >= 1 ? version.getMinorVersion() : 0);
    }
    if (segmentCount > 1)
    {
        newVersion.append(".")
                .append(segment >= 2 ? version.getIncrementalVersion() : 0);
    }
    if (segmentCount > 2)
    {
        if (version.getQualifier() != null)
        {
            newVersion.append("-")
                    .append(segment >= 3 ? version.getQualifier() : "0");
        } else
        {
            newVersion.append("-")
                    .append(segment >= 3 ? version.getBuildNumber() : "0");
        }
    }
    return helper.createArtifactVersion(newVersion.toString());
}
 
Example 3
Source File: JApiCmpMojo.java    From japicmp with Apache License 2.0 5 votes vote down vote up
private void filterSnapshots(List versions) {
	for (Iterator versionIterator = versions.iterator(); versionIterator.hasNext(); ) {
		ArtifactVersion version = (ArtifactVersion) versionIterator.next();
		String qualifier = version.getQualifier();
		if (qualifier != null && qualifier.endsWith("SNAPSHOT")) {
			versionIterator.remove();
		}
	}
}
 
Example 4
Source File: MavenVersionComparator.java    From versions-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected int innerGetSegmentCount( ArtifactVersion v )
{
    // if the version does not match the maven rules, then we have only one segment
    // i.e. the qualifier
    if ( v.getBuildNumber() != 0 )
    {
        // the version was successfully parsed, and we have a build number
        // have to have four segments
        return 4;
    }
    if ( ( v.getMajorVersion() != 0 || v.getMinorVersion() != 0 || v.getIncrementalVersion() != 0 )
        && v.getQualifier() != null )
    {
        // the version was successfully parsed, and we have a qualifier
        // have to have four segments
        return 4;
    }
    final String version = v.toString();
    if ( version.indexOf( '-' ) != -1 )
    {
        // the version has parts and was not parsed successfully
        // have to have one segment
        return version.equals( v.getQualifier() ) ? 1 : 4;
    }
    if ( version.indexOf( '.' ) != -1 )
    {
        // the version has parts and was not parsed successfully
        // have to have one segment
        return version.equals( v.getQualifier() ) ? 1 : 3;
    }
    if ( StringUtils.isEmpty( version ) )
    {
        return 3;
    }
    try
    {
        Integer.parseInt( version );
        return 3;
    }
    catch ( NumberFormatException e )
    {
        return 1;
    }
}
 
Example 5
Source File: MavenVersionComparator.java    From versions-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected ArtifactVersion innerIncrementSegment( ArtifactVersion v, int segment )
{
    int segmentCount = innerGetSegmentCount( v );
    if ( segment < 0 || segment >= segmentCount )
    {
        throw new InvalidSegmentException( segment, segmentCount, v.toString() );
    }
    String version = v.toString();
    if ( segmentCount == 1 )
    {
        // only the qualifier
        version = VersionComparators.alphaNumIncrement( version );
        return new DefaultArtifactVersion( version );
    }
    else
    {
        int major = v.getMajorVersion();
        int minor = v.getMinorVersion();
        int incremental = v.getIncrementalVersion();
        int build = v.getBuildNumber();
        String qualifier = v.getQualifier();

        int minorIndex = version.indexOf( '.' );
        boolean haveMinor = minorIndex != -1;
        int incrementalIndex = haveMinor ? version.indexOf( '.', minorIndex + 1 ) : -1;
        boolean haveIncremental = incrementalIndex != -1;
        int buildIndex = version.indexOf( '-' );
        boolean haveBuild = buildIndex != -1 && qualifier == null;
        boolean haveQualifier = buildIndex != -1 && qualifier != null;

        switch ( segment )
        {
            case 0:
                major++;
                minor = 0;
                incremental = 0;
                build = 0;
                qualifier = null;
                break;
            case 1:
                minor++;
                incremental = 0;
                build = 0;
                if ( haveQualifier && qualifier.endsWith( "SNAPSHOT" ) )
                {
                    qualifier = "SNAPSHOT";
                }
                break;
            case 2:
                incremental++;
                build = 0;
                qualifier = null;
                break;
            case 3:
                if ( haveQualifier )
                {
                    qualifier = qualifierIncrement( qualifier );
                }
                else
                {
                    build++;
                }
                break;
        }
        StringBuilder result = new StringBuilder();
        result.append( major );
        if ( haveMinor || minor > 0 || incremental > 0 )
        {
            result.append( '.' );
            result.append( minor );
        }
        if ( haveIncremental || incremental > 0 )
        {
            result.append( '.' );
            result.append( incremental );
        }
        if ( haveQualifier && qualifier != null )
        {
            result.append( '-' );
            result.append( qualifier );
        }
        else if ( haveBuild || build > 0 )
        {
            result.append( '-' );
            result.append( build );
        }
        return new DefaultArtifactVersion( result.toString() );
    }
}