List of usage examples for org.apache.maven.artifact.versioning ArtifactVersion getMajorVersion
int getMajorVersion();
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/>//from w ww. j a va2 s. 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 {//w w w .j a va2s .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 ww w . j a v a2 s . c o m*/ * @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 w w w .ja v a 2 s. co 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) */// w ww. j a va 2 s . c o 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.github.peterjanes.node.NpmVersionMojo.java
License:Apache License
/** * * @throws MojoExecutionException if anything unexpected happens. *///from www. 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.google.code.configprocessor.ConfigProcessorMojo.java
License:Apache License
/** * {@inheritDoc}// w ww.j av a 2 s .com */ public void execute() throws MojoExecutionException { LogAdapter logAdapter = new LogMaven(getLog()); if (skip) { logAdapter.info("Skipping config processing"); } else { try { FileResolver fileResolver = new MavenFileResolver(mavenProject, artifactFactory, artifactResolver, localRepository, remoteRepositories, logAdapter); ConfigProcessor processor = new ConfigProcessor(encoding, indentSize, lineWidth, namespaceContexts, mavenProject.getBasedir(), outputDirectory, useOutputDirectory, logAdapter, fileResolver, parserFeatures, failOnMissingXpath); processor.init(); // issue 35 - Specificproperties in maven doesn't work ArtifactVersion mavenVersion = runtime.getApplicationVersion(); if (specificProperties != null && mavenVersion.getMajorVersion() > 2) { throw new MojoExecutionException( "specificProperties are not supported anymore by Maven, please specify them in the properties section of your pom.xml file"); } Properties additionalProperties = loadIfPossible(specificProperties, logAdapter); for (Transformation transformation : transformations) { MavenExpressionResolver resolver = getExpressionResolver(transformation.isReplacePlaceholders(), additionalProperties); processor.execute(resolver, transformation); } } catch (Exception e) { throw new MojoExecutionException("Error during config processing", e); } } }
From source file:com.insightfullogic.release.MoveToReleaseMojo.java
License:Apache License
public void execute() throws MojoExecutionException { if (processProperties) { bumpProperties();/*from w ww . j ava2 s . com*/ } 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;//from w w w .ja 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 a 2s. com // 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); }