Example usage for org.apache.maven.artifact.versioning ArtifactVersion getMinorVersion

List of usage examples for org.apache.maven.artifact.versioning ArtifactVersion getMinorVersion

Introduction

In this page you can find the example usage for org.apache.maven.artifact.versioning ArtifactVersion getMinorVersion.

Prototype

int getMinorVersion();

Source Link

Usage

From source file:com.alibaba.citrus.maven.eclipse.base.ide.IdeUtils.java

License:Apache License

/**
 * Extracts the version of the first matching artifact in the given list.
 * <p/>// w  w  w .j  a  v  a  2s. c  o  m
 * The {@code len} parameter indicated what to to return:
 * <ul>
 * <li><strong>1</strong> indicated <code>major</code> version</li>
 * <li><strong>3</strong> indicated <code>major dot minor</code> version</li>
 * <li><strong>5 and above</strong> indicates <code>major dot minor dot incremental</code> version
 * </ul>
 *
 * @param artifactIds artifact names to compare against for extracting version
 * @param artifacts   Set of artifacts for our project
 * @param len         expected length of the version sub-string
 */
public static String getArtifactVersion(String[] artifactIds, List dependencies, int len) {
    String version = null;
    ArtifactVersion artifactVersion = getArtifactVersion(artifactIds, dependencies);
    if (artifactVersion != null) {
        StringBuffer versionBuffer = new StringBuffer();
        if (len >= 1) {
            versionBuffer.append(artifactVersion.getMajorVersion());
        }
        if (len >= 2) {
            versionBuffer.append('.');
        }
        if (len >= 3) {
            versionBuffer.append(artifactVersion.getMinorVersion());
        }
        if (len >= 4) {
            versionBuffer.append('.');
        }
        if (len >= 5) {
            versionBuffer.append(artifactVersion.getIncrementalVersion());
        }
        version = versionBuffer.toString();
    }
    return version;
}

From source file:com.aquent.mojo.delivery.RemoteVersionMojo.java

License:Open Source License

@SuppressWarnings("unchecked")
public void execute() {
    defineVersionProperty("version", 0);
    defineVersionProperty("majorVersion", 0);
    defineVersionProperty("minorVersion", 0);
    defineVersionProperty("incrementalVersion", 0);
    try {// ww  w. j av  a 2 s .c  o m
        Artifact artifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), "",
                "", "");
        RepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact);
        repositoryMetadataManager.resolveAlways(metadata, localRepository, getRemoteRepository());
        if (metadata.getMetadata() != null && metadata.getMetadata().getVersioning() != null) {
            List<String> allVersions = metadata.getMetadata().getVersioning().getVersions();
            ArtifactVersion foundVersion = null;
            for (String version : allVersions) {
                ArtifactVersion artifactVersion = new DefaultArtifactVersion(version);
                if (foundVersion == null || artifactVersion.compareTo(foundVersion) > 0) {
                    foundVersion = artifactVersion;
                }
            }
            if (foundVersion != null) {
                defineVersionProperty("version", foundVersion.toString());
                defineVersionProperty("majorVersion", foundVersion.getMajorVersion());
                defineVersionProperty("minorVersion", foundVersion.getMinorVersion());
                defineVersionProperty("incrementalVersion", foundVersion.getIncrementalVersion());
            }
        }
    } catch (RepositoryMetadataResolutionException ex) {
        getLog().warn(ex.toString());
    }
}

From source file:com.ebay.osgi.maven.compiler.osgi.BundleUtil.java

License:Apache License

/**
 * Convert the maven version into OSGi version
 * @param mavenVersion//from   w  ww  . j  av a2  s  .c  om
 * @return
 */
static String osgiVersion(String mavenVersion) {
    ArtifactVersion ver = new OSGIArtifactVersion(mavenVersion);
    String qualifer = ver.getQualifier();
    if (qualifer != null) {
        StringBuffer buf = new StringBuffer(qualifer);
        for (int i = 0; i < buf.length(); i++) {
            char c = buf.charAt(i);
            if (Character.isLetterOrDigit(c) || c == '-' || c == '_') {
                // Keep as-is
            } else {
                buf.setCharAt(i, '_');
            }
        }
        qualifer = buf.toString();
    }
    Version osgiVersion = new Version(ver.getMajorVersion(), ver.getMinorVersion(), ver.getIncrementalVersion(),
            qualifer);
    String version = osgiVersion.toString();
    return version;
}

From source file:com.ebay.osgi.maven.compiler.osgi.OSGIArtifactVersion.java

License:Apache License

public int compareTo(Object o) {
    ArtifactVersion otherVersion = (ArtifactVersion) o;

    int result = getMajorVersion() - otherVersion.getMajorVersion();
    if (result == 0) {
        result = getMinorVersion() - otherVersion.getMinorVersion();
    }/*from ww w  .j  a  va2 s  .com*/
    if (result == 0) {
        result = getIncrementalVersion() - otherVersion.getIncrementalVersion();
    }
    if (result == 0) {
        if (this.qualifier != null) {
            String otherQualifier = otherVersion.getQualifier();

            if (otherQualifier != null) {
                if ((this.qualifier.length() > otherQualifier.length())
                        && this.qualifier.startsWith(otherQualifier)) {
                    // here, the longer one that otherwise match is
                    // considered older
                    result = -1;
                } else if ((this.qualifier.length() < otherQualifier.length())
                        && otherQualifier.startsWith(this.qualifier)) {
                    // here, the longer one that otherwise match is
                    // considered older
                    result = 1;
                } else {
                    result = this.qualifier.compareTo(otherQualifier);
                }
            } else {
                // otherVersion has no qualifier but we do - that's newer
                result = -1;
            }
        } else if (otherVersion.getQualifier() != null) {
            // otherVersion has a qualifier but we don't, we're newer
            result = 1;
        } else {
            result = getBuildNumber() - otherVersion.getBuildNumber();
        }
    }
    return result;
}

From source file:com.github.paulmoloney.maven.plugins.enforcer.RuleJavaVersionToolchainAware.java

License:Apache License

/** 
* This particular rule determines if the specified Java compiler version referenced in the toolchains.xml is an appropriate version
* @see org.apache.maven.enforcer.rule.api.EnforcerRule&#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper)
*/// w w w  .j a  v  a2 s.c om
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
    try {
        super.init(helper);
        try {
            compilerManager = (CompilerManager) helper.getComponent(CompilerManager.class);
        } catch (ComponentLookupException e) {
            throw new MojoExecutionException("Unable to retrieve component", e);
        }
        if (null == compilerId || "".equals(compilerId)) {
            compilerId = "javac";
        }
        if (null == compilerArgument || "".equals(compilerArgument)) {
            compilerArgument = "-version";
        }
        /*try
        {
            compilerId = (String) helper.evaluate("maven.compiler.compilerId");
        }
        catch (ExpressionEvaluationException e)
        {
            throw new MojoExecutionException ("Unable to determine compiler id", e);
        }*/
    } catch (MojoExecutionException e) {
        throw new EnforcerRuleException("Error initialising mojo", e);
    }
    String java_version;
    final Log log = helper.getLog();

    log.debug("Using compiler id'" + getCompilerId() + "'.");

    try {
        getCompilerManager().getCompiler(getCompilerId());
    } catch (NoSuchCompilerException e) {
        throw new EnforcerRuleException("No compiler with id: '" + e.getCompilerId() + "'.");
    }

    try {
        Toolchain tc = findToolChain("jdk", helper, null);
        if (tc != null) {
            executable = tc.findTool(getCompilerId());
        }
    } catch (MojoExecutionException e) {
        throw new EnforcerRuleException("", e);
    }

    if (null == executable && isFallBackAllowed()) {
        executable = findToolExecutable(getCompilerId() + getExecutableExtension(), log, "java.home",
                new String[] { "../bin", "bin", "../sh" }, new String[] { "JDK_HOME", "JAVA_HOME" },
                new String[] { "bin", "sh" });
    }

    if (null == executable || "".equals(executable.trim())) {
        throw new EnforcerRuleException("No valid executable found, aborting");
    }
    setProcess(process);
    java_version = runToolAndRetrieveVersion(process, log);

    String clean_java_version = normalizeJDKVersion(java_version);
    log.debug("Normalized Java Version: " + clean_java_version);

    ArtifactVersion detectedJdkVersion = new DefaultArtifactVersion(clean_java_version);
    log.debug("Parsed Version: Major: " + detectedJdkVersion.getMajorVersion() + " Minor: "
            + detectedJdkVersion.getMinorVersion() + " Incremental: "
            + detectedJdkVersion.getIncrementalVersion() + " Build: " + detectedJdkVersion.getBuildNumber()
            + "Qualifier: " + detectedJdkVersion.getQualifier());

    log.debug("Rule requires: " + version);
    enforceVersion(log, "JDK", getVersion(), detectedJdkVersion);
}

From source file:com.github.peterjanes.node.NpmVersionMojo.java

License:Apache License

/**
 *
 * @throws MojoExecutionException if anything unexpected happens.
 *///from   w  w w .j  a v  a2  s .  c o m
public void execute() throws MojoExecutionException {
    String projectVersion = mavenProject.getVersion();
    ArtifactVersion artifactVersion = new DefaultArtifactVersion(projectVersion);
    String npmVersion = String.format("%s.%s.%s", artifactVersion.getMajorVersion(),
            artifactVersion.getMinorVersion(), artifactVersion.getIncrementalVersion());
    if (projectVersion.endsWith("-SNAPSHOT")) {
        npmVersion = npmVersion
                + String.format("-%s", new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
    }
    mavenProject.getProperties().put("node.project.version", npmVersion);
}

From source file:com.insightfullogic.release.MoveToReleaseMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    if (processProperties) {
        bumpProperties();/*from w  w  w . ja va 2  s.c o  m*/
    }

    executeStandardUpdateGoals();

    ArtifactVersion artifactVersion = new Version(project.getVersion());
    Version newVersion = new Version(artifactVersion.getMajorVersion(), artifactVersion.getMinorVersion(),
            artifactVersion.getIncrementalVersion(), artifactVersion.getBuildNumber(), null);
    writeVersion(newVersion);

}

From source file:com.insightfullogic.release.MoveToSnapshotMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    if (!isRootProject()) {
        return;// w  w w .  j  a va 2  s.c  om
    }

    ArtifactVersion artifactVersion = new Version(project.getVersion());
    Version newVersion = new Version(artifactVersion.getMajorVersion(), artifactVersion.getMinorVersion(),
            artifactVersion.getIncrementalVersion() + 1, artifactVersion.getBuildNumber(), "SNAPSHOT");
    writeVersion(newVersion);
}

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

License:Apache License

public void execute() throws MojoExecutionException {
    getLog().debug("Generate SWID Tag...");

    // prepare mandatory elements
    ArtifactVersion artifactVersion = getArtifactVersion();
    prepareMandatoryElements();//from   ww w.j a v  a  2s  .  c  o  m

    // prepare SWID Tag processor
    SwidProcessor processor = new DefaultSwidProcessor();
    ((DefaultSwidProcessor) processor).setEntitlementRequiredIndicator(entitlement_required)
            .setProductTitle(product_title)
            .setProductVersion(product_version, artifactVersion.getMajorVersion(),
                    artifactVersion.getMinorVersion(), artifactVersion.getIncrementalVersion(),
                    artifactVersion.getBuildNumber())
            .setSoftwareCreator(software_creator.getName(), software_creator.getRegid())
            .setSoftwareLicensor(software_licensor.getName(), software_licensor.getRegid())
            .setSoftwareId(software_id.getUnique_id(), software_id.getTag_creator_regid())
            .setTagCreator(tag_creator.getName(), tag_creator.getRegid());

    // create builder and pass processor as build param
    SwidBuilder builder = new SwidBuilder();
    SoftwareIdentificationTagComplexType swidTag = builder.build(processor);

    // output resulting object
    final String fileName = SwidUtils.generateSwidFileName(software_creator.getRegid(),
            software_id.getUnique_id(), product_version, extension);
    if (!outputDirectory.exists()) {
        if (!outputDirectory.mkdirs()) {
            throw new MojoExecutionException("Cannot create directory '" + outputDirectory.toString() + "'");
        }
    }
    File swidFile = new File(outputDirectory, fileName);
    SwidWriter writer = new SwidWriter();
    writer.write(swidTag, swidFile);
}

From source file:com.photon.maven.plugins.android.standalonemojos.ManifestUpdateMojo.java

License:Apache License

public void updateManifest(File manifestFile) throws IOException, ParserConfigurationException, SAXException,
        TransformerException, MojoFailureException {
    Document doc = readManifest(manifestFile);

    Element manifestElement = doc.getDocumentElement();

    boolean dirty = false;

    if (StringUtils.isEmpty(parsedVersionName)) { // default to ${project.version}
        parsedVersionName = project.getVersion();
    }//w  w w.  jav  a  2 s  .c  o  m

    Attr versionNameAttrib = manifestElement.getAttributeNode(ATTR_VERSION_NAME);

    if (versionNameAttrib == null || !StringUtils.equals(parsedVersionName, versionNameAttrib.getValue())) {
        getLog().info("Setting " + ATTR_VERSION_NAME + " to " + parsedVersionName);
        manifestElement.setAttribute(ATTR_VERSION_NAME, parsedVersionName);
        dirty = true;
    }

    if ((parsedVersionCodeAutoIncrement && parsedVersionCode != null)
            || (parsedVersionCodeUpdateFromVersion && parsedVersionCode != null)
            || (parsedVersionCodeAutoIncrement && parsedVersionCodeUpdateFromVersion)) {
        throw new MojoFailureException("versionCodeAutoIncrement, versionCodeUpdateFromVersion and versionCode "
                + "are mutual exclusive. They cannot be specified at the same time. "
                + "Please specify either versionCodeAutoIncrement, versionCodeUpdateFromVersion or versionCode!");
    }

    if (parsedVersionCodeAutoIncrement) {
        Attr versionCode = manifestElement.getAttributeNode(ATTR_VERSION_CODE);
        int currentVersionCode = 0;
        if (versionCode != null) {
            currentVersionCode = NumberUtils.toInt(versionCode.getValue(), 0);
        }
        currentVersionCode++;
        manifestElement.setAttribute(ATTR_VERSION_CODE, String.valueOf(currentVersionCode));
        dirty = true;
    }

    if (parsedVersionCodeUpdateFromVersion) {
        String verString = project.getVersion();
        getLog().debug("Generating versionCode for " + verString);
        ArtifactVersion artifactVersion = new DefaultArtifactVersion(verString);
        String verCode = Integer.toString(artifactVersion.getMajorVersion())
                + Integer.toString(artifactVersion.getMinorVersion())
                + Integer.toString(artifactVersion.getIncrementalVersion());
        getLog().info("Setting " + ATTR_VERSION_CODE + " to " + verCode);
        manifestElement.setAttribute(ATTR_VERSION_CODE, verCode);
        dirty = true;
    }

    if (parsedVersionCode != null) {
        Attr versionCodeAttr = manifestElement.getAttributeNode(ATTR_VERSION_CODE);
        int currentVersionCode = 0;
        if (versionCodeAttr != null) {
            currentVersionCode = NumberUtils.toInt(versionCodeAttr.getValue(), 0);
        }
        if (currentVersionCode != parsedVersionCode) {
            getLog().info("Setting " + ATTR_VERSION_CODE + " to " + parsedVersionCode);
            manifestElement.setAttribute(ATTR_VERSION_CODE, String.valueOf(parsedVersionCode));
            dirty = true;
        }
    }

    if (!StringUtils.isEmpty(parsedSharedUserId)) {
        Attr sharedUserIdAttrib = manifestElement.getAttributeNode(ATTR_SHARED_USER_ID);

        if (sharedUserIdAttrib == null
                || !StringUtils.equals(parsedSharedUserId, sharedUserIdAttrib.getValue())) {
            getLog().info("Setting " + ATTR_SHARED_USER_ID + " to " + parsedSharedUserId);
            manifestElement.setAttribute(ATTR_SHARED_USER_ID, parsedSharedUserId);
            dirty = true;
        }
    }

    if (parsedDebuggable != null) {
        NodeList appElems = manifestElement.getElementsByTagName(ELEM_APPLICATION);

        // Update all application nodes. Not sure whether there will ever be more than one.
        for (int i = 0; i < appElems.getLength(); ++i) {
            Node node = appElems.item(i);
            getLog().info("Testing if node " + node.getNodeName() + " is application");
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element element = (Element) node;
                Attr debuggableAttrib = element.getAttributeNode(ATTR_DEBUGGABLE);
                if (debuggableAttrib == null
                        || parsedDebuggable != BooleanUtils.toBoolean(debuggableAttrib.getValue())) {
                    getLog().info("Setting " + ATTR_DEBUGGABLE + " to " + parsedDebuggable);
                    element.setAttribute(ATTR_DEBUGGABLE, String.valueOf(parsedDebuggable));
                    dirty = true;
                }
            }
        }
    }

    if (dirty) {
        if (!manifestFile.delete()) {
            getLog().warn("Could not remove old " + manifestFile);
        }
        getLog().info("Made changes to manifest file, updating " + manifestFile);
        writeManifest(manifestFile, doc);
    } else {
        getLog().info("No changes found to write to manifest file");
    }
}