List of usage examples for org.apache.maven.artifact.versioning ArtifactVersion getBuildNumber
int getBuildNumber();
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(); }/*w ww .j a v a 2s. c o m*/ 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) *///from ww w . j a v a 2 s .co m 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.insightfullogic.release.MoveToReleaseMojo.java
License:Apache License
public void execute() throws MojoExecutionException { if (processProperties) { bumpProperties();/* w w w. j a v a 2s . c om*/ } 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 v a 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 w w w . j a v a2s.co 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.sun.enterprise.module.maven.VersionTranslator.java
License:Open Source License
/** * Translates Maven Version String to OSGi Version String * @param mvs//from www . ja va 2s. co m * @return a OSGi version string */ public static String MavenToOSGi(String mvs) { try { ArtifactVersion mv = new DefaultArtifactVersion(mvs); int major = mv.getMajorVersion(); int minor = mv.getMinorVersion(); int micro = mv.getIncrementalVersion(); // 0 is never a valid build number String qualifier = mv.getBuildNumber() != 0 ? Integer.toString(mv.getBuildNumber()) : mv.getQualifier(); logger.logp(Level.INFO, "VersionTranslator", "MavenToOSGi", "qualifier = {0}", qualifier); Version ov = qualifier == null ? new Version(major, minor, micro) : new Version(major, minor, micro, qualifier); logger.logp(Level.INFO, "VersionTranslator", "MavenToOSGi", "{0} -> {1}", new Object[] { mvs, ov }); return ov.toString(); } catch (RuntimeException e) { logger.logp(Level.INFO, "VersionTranslator", "MavenToOSGi", "Following exception was raised " + "while translating Maven version {0} to OSGi version: {1}", new Object[] { mvs, e }); throw 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 ww.j a va 2s . 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 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.ParseVersionMojo.java
License:Open Source License
/** * Make an osgi compatible version String from an ArtifactVersion * /*from w w w . ja v a 2 s . c o m*/ * @param version The artifact version. * @return The OSGi version as string. */ public String getOsgiVersion(ArtifactVersion version) { if (version.toString().equals(version.getQualifier())) { return version.toString(); } StringBuffer osgiVersion = new StringBuffer(); osgiVersion.append(version.getMajorVersion()); osgiVersion.append("." + version.getMinorVersion()); osgiVersion.append("." + version.getIncrementalVersion()); if (version.getQualifier() != null || version.getBuildNumber() != 0) { osgiVersion.append("."); if (version.getQualifier() != null) { osgiVersion.append(version.getQualifier()); } if (version.getBuildNumber() != 0) { osgiVersion.append(version.getBuildNumber()); } } return osgiVersion.toString(); }
From source file:org.apache.sling.maven.bundlesupport.BundleDeployMojo.java
License:Apache License
@Override protected File fixBundleVersion(File jarFile) throws MojoExecutionException { // if this is a snapshot, replace "SNAPSHOT" with the date generated // by the maven deploy plugin if (this.project.getVersion().indexOf("SNAPSHOT") > 0) { // create new version string by replacing all '-' with '.' String newVersion = this.project.getArtifact().getVersion(); int firstPos = newVersion.indexOf('-') + 1; int pos = 0; while (pos != -1) { pos = newVersion.indexOf('-'); if (pos != -1) { newVersion = newVersion.substring(0, pos) + '.' + newVersion.substring(pos + 1); }//from w w w . j a v a2s .co m } // now remove all dots after the third one pos = newVersion.indexOf('.', firstPos); while (pos != -1) { newVersion = newVersion.substring(0, pos) + newVersion.substring(pos + 1); pos = newVersion.indexOf('.', pos + 1); } return changeVersion(jarFile, project.getVersion(), newVersion); } // if this is a final release append "final" try { final ArtifactVersion v = this.project.getArtifact().getSelectedVersion(); if (v.getBuildNumber() == 0 && v.getQualifier() == null) { final String newVersion = this.project.getArtifact().getVersion() + ".FINAL"; return changeVersion(jarFile, project.getVersion(), newVersion); } } catch (OverConstrainedVersionException ocve) { // we ignore this and don't append "final"! } // just return the file in case of some issues return jarFile; }
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 a2s . co 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); }