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

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

Introduction

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

Prototype

String getQualifier();

Source Link

Usage

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  w  w.  ja  va 2  s.co 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 .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 ww . jav a2  s  . com
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.sun.enterprise.module.maven.VersionTranslator.java

License:Open Source License

/**
 * Translates Maven Version String to OSGi Version String
 * @param mvs/*ww  w .j  a  v a 2  s  .c o 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/*w  ww. j  a  va2  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.ParseVersionMojo.java

License:Open Source License

/**
 * Make an osgi compatible version String from an ArtifactVersion
 * /*from ww w  . ja va 2s . c  om*/
 * @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.felix.bundleplugin.baseline.AbstractBaselinePlugin.java

License:Apache License

private void filterSnapshots(List<ArtifactVersion> versions) {
    for (Iterator<ArtifactVersion> versionIterator = versions.iterator(); versionIterator.hasNext();) {
        ArtifactVersion version = versionIterator.next();
        if (version.getQualifier() != null && version.getQualifier().endsWith("SNAPSHOT")) {
            versionIterator.remove();//from   w  w  w. jav  a  2 s .co  m
        }
    }
}

From source file:org.apache.geronimo.mavenplugins.car.ArchiveCarMojo.java

License:Apache License

/**
 * Generates the configuration archive./*from  w w  w.  j  a va 2  s  .  c  om*/
 */
private File createArchive() throws MojoExecutionException {
    File archiveFile = getArchiveFile(outputDirectory, finalName, null);

    GeronimoArchiver archiver = new GeronimoArchiver(archiverManager);
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(archiveFile);

    try {
        // Incldue the generated artifact contents
        File artifactDirectory = this.getArtifactInRepositoryDir();

        if (artifactDirectory.exists()) {
            archiver.getArchiver().addDirectory(artifactDirectory);
        }

        // Include the optional classes.resources
        if (classesDirectory.isDirectory()) {
            archiver.getArchiver().addDirectory(classesDirectory);
        }

        if (resourcesDir.isDirectory()) {
            archiver.getArchiver().addDirectory(resourcesDir);
        }

        //
        // HACK: Include legal files here for sanity
        //

        //
        // NOTE: Would be nice to share this with the copy-legal-files mojo
        //
        String[] includes = { "LICENSE.txt", "LICENSE",

                "NOTICE.txt", "NOTICE", "DISCLAIMER.txt", "DISCLAIMER" };

        archiver.getArchiver().addDirectory(baseDirectory, "META-INF/", includes, new String[0]);

        //For no plan car, do nothing
        if (artifactDirectory.exists()) {

            File mfFile = new File(artifactDirectory, "META-INF/MANIFEST.MF");
            if (mfFile.exists()) {
                FilesetManifestConfig mergeFilesetManifestConfig = new FilesetManifestConfig();
                mergeFilesetManifestConfig.setValue("merge");
                archiver.getArchiver().setFilesetmanifest(mergeFilesetManifestConfig);
            } else {
                //File configFile = new File(new File(getArtifactInRepositoryDir(), "META-INF"), "imports.txt");
                File importsTxtFile = new File(artifactDirectory, "META-INF/imports.txt");
                if (importsTxtFile.exists()) {
                    StringBuilder imports = new StringBuilder("org.apache.geronimo.kernel.osgi,");
                    if (boot) {
                        archive.addManifestEntry(Constants.BUNDLE_ACTIVATOR, BootActivator.class.getName());
                        imports.append("org.apache.geronimo.system.osgi,");
                    } else {
                        archive.addManifestEntry(Constants.BUNDLE_ACTIVATOR,
                                ConfigurationActivator.class.getName());
                    }
                    archive.addManifestEntry(Constants.BUNDLE_NAME, project.getName());
                    archive.addManifestEntry(Constants.BUNDLE_VENDOR, project.getOrganization().getName());
                    ArtifactVersion version = project.getArtifact().getSelectedVersion();
                    String versionString = "" + version.getMajorVersion() + "." + version.getMinorVersion()
                            + "." + version.getIncrementalVersion();
                    if (version.getQualifier() != null) {
                        versionString += "." + version.getQualifier();
                    }
                    archive.addManifestEntry(Constants.BUNDLE_VERSION, versionString);
                    archive.addManifestEntry(Constants.BUNDLE_MANIFESTVERSION, "2");
                    archive.addManifestEntry(Constants.BUNDLE_DESCRIPTION, project.getDescription());
                    // NB, no constant for this one
                    archive.addManifestEntry("Bundle-License",
                            ((License) project.getLicenses().get(0)).getUrl());
                    archive.addManifestEntry(Constants.BUNDLE_DOCURL, project.getUrl());
                    archive.addManifestEntry(Constants.BUNDLE_SYMBOLICNAME,
                            project.getGroupId() + "." + project.getArtifactId());
                    Reader in = new InputStreamReader(new FileInputStream(importsTxtFile));
                    char[] buf = new char[1024];
                    try {
                        int i;
                        while ((i = in.read(buf)) > 0) {
                            imports.append(buf, 0, i);
                        }
                    } finally {
                        in.close();
                    }
                    // do we have any additional processing directives?
                    if (instructions != null) {
                        String explicitImports = (String) instructions.get(Constants.IMPORT_PACKAGE);
                        // if there is an Import-Package instructions, then add these imports to the
                        // list
                        if (explicitImports != null) {
                            // if specified on multiple lines, remove the line-ends.
                            explicitImports = explicitImports.replaceAll("[\r\n]", "");
                            imports.append(',');
                            imports.append(explicitImports);
                        }
                        String requiredBundles = (String) instructions.get(Constants.REQUIRE_BUNDLE);
                        if (requiredBundles != null) {
                            requiredBundles = requiredBundles.replaceAll("[\r\n]", "");
                            archive.addManifestEntry(Constants.REQUIRE_BUNDLE, requiredBundles);
                        }
                    }
                    archive.addManifestEntry(Constants.IMPORT_PACKAGE, imports.toString());
                    archive.addManifestEntry(Constants.DYNAMICIMPORT_PACKAGE, "*");
                }
            }
        }

        if (classpath != null) {
            archive.addManifestEntry("Class-Path", getClassPath());
        }

        archiver.createArchive(project, archive);

        return archiveFile;
    } catch (Exception e) {
        throw new MojoExecutionException("Failed to create archive", e);
    } finally {
        archiver.cleanup();
    }
}

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   ww w.j  ava 2 s .  c  o 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.apache.tuscany.maven.plugin.surefire.OSGiSurefirePlugin.java

License:Apache License

/**
 * Convert the maven version into OSGi version 
 * @param mavenVersion/*from  w  ww.j  a  va2 s .c  o m*/
 * @return
 */
static String osgiVersion(String mavenVersion) {
    ArtifactVersion ver = new DefaultArtifactVersion(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;
}