hk2
  1. hk2
  2. HK2-125

osgiversion-maven-plugin sets property value to 0.0.0 for a maven version=12.1.3.332

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.2.0
    • Fix Version/s: 2.2.0
    • Component/s: None
    • Labels:
      None

      Description

      When using a maven version = ww.x.y.z[z*], the osgiversion maven plugin set a property to 0.0.0.
      This is not an expected behavior as the property is used then to version export/import in-house packages.

      Looking at SemanticVersioning.pdf

          A version can consist of maximum 4 parts: major, minor, micro, and qualifier. The syntax is:
           version ::= <major> [ '.' <minor> [ '.' <micro> [ '.' <qualifier> ]]]
      

      configuration of the plugin is the following:

                      <configuration>
                          <dropVersionComponent>qualifier</dropVersionComponent>
                          <versionPropertyName>project.osgi.version</versionPropertyName>
                      </configuration>
      

        Activity

        Hide
        Romain Grécourt added a comment -

        The following diff has been reviewed by Mason and pushed.

        diff --git a/hk2/osgiversion-maven-plugin/src/main/java/com/sun/enterprise/module/maven/OsgiVersionMojo.java b/hk2/osgiversion-maven-plugin/src/main/java/com/sun/enterprise/module/maven/OsgiVersionMojo.java
        index bb8cc39..a93f001 100644
        --- a/hk2/osgiversion-maven-plugin/src/main/java/com/sun/enterprise/module/maven/OsgiVersionMojo.java
        +++ b/hk2/osgiversion-maven-plugin/src/main/java/com/sun/enterprise/module/maven/OsgiVersionMojo.java
        @@ -1,7 +1,7 @@
         /*
          * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
          *
        - * Copyright (c) 2007-2011 Oracle and/or its affiliates. All rights reserved.
        + * Copyright (c) 2007-2013 Oracle and/or its affiliates. All rights reserved.
          *
          * The contents of this file are subject to the terms of either the GNU
          * General Public License Version 2 only ("GPL") or the Common Development
        @@ -40,12 +40,11 @@
         
         package com.sun.enterprise.module.maven;
         
        +import org.glassfish.hk2.maven.Version;
         import org.apache.maven.plugin.AbstractMojo;
         import org.apache.maven.plugin.MojoExecutionException;
         import org.apache.maven.plugin.MojoFailureException;
         import org.apache.maven.project.MavenProject;
        -import org.apache.maven.shared.osgi.Maven2OsgiConverter;
        -import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
         
         /**
          * Converts the project version into the OSGi format and
        @@ -69,7 +68,7 @@ public class OsgiVersionMojo extends AbstractMojo {
              * @readonly
              */
             protected MavenProject project;
        -
        +    
             /**
              * Flag used to determine what components of the version will be used
              * in OSGi version.
        @@ -87,55 +86,17 @@ public class OsgiVersionMojo extends AbstractMojo {
              * major, minor and micro portions will be used.
              * @parameter
              */
        -    protected String dropVersionComponent;
        +    protected Version.COMPONENT dropVersionComponent;
         
             /**
              * @parameter default-value="project.osgi.version"
              */
             protected String versionPropertyName;
         
        -    private enum VERSION_COMPONENT {major, minor, micro, qualifier};
        -
        -    /**
        -     * @component
        -     */
        -    protected Maven2OsgiConverter converter;
        -
        +    @Override
             public void execute() throws MojoExecutionException, MojoFailureException {
        -        DefaultArtifactVersion projectVersion =
        -                new DefaultArtifactVersion(project.getVersion());
        -        VERSION_COMPONENT compToDrop = dropVersionComponent == null ?
        -                null : VERSION_COMPONENT.valueOf(dropVersionComponent);
        -
        -        DefaultArtifactVersion newVersion = projectVersion;
        -        if (compToDrop != null) {
        -            switch (compToDrop) {
        -                case major: {
        -                    newVersion = new DefaultArtifactVersion("0.0.0");
        -                    break;
        -                }
        -                case minor: {
        -                    final int major = projectVersion.getMajorVersion();
        -                    newVersion = new DefaultArtifactVersion(major +"");
        -                    break;
        -                }
        -                case micro: {
        -                    final int major = projectVersion.getMajorVersion();
        -                    final int minor = projectVersion.getMinorVersion();
        -                    newVersion = new DefaultArtifactVersion(major + "." + minor);
        -                    break;
        -                }
        -                case qualifier: {
        -                    final int major = projectVersion.getMajorVersion();
        -                    final int minor = projectVersion.getMinorVersion();
        -                    final int micro = projectVersion.getIncrementalVersion();
        -                    newVersion = new DefaultArtifactVersion(major + "." + minor + "." + micro);
        -                    break;
        -                }
        -            }
        -        }
        -        String v = converter.getVersion(newVersion.toString());
        -
        +        Version projectVersion = new Version(project.getVersion());
        +        String v = projectVersion.convertToOsgi(dropVersionComponent);
                 getLog().debug("OSGi Version for "+project.getVersion()+" is "+v);
                 getLog().debug("It is set in project property called "+ versionPropertyName);
                 project.getProperties().put(versionPropertyName,v);
        diff --git a/hk2/osgiversion-maven-plugin/src/main/java/org/glassfish/hk2/maven/Version.java b/hk2/osgiversion-maven-plugin/src/main/java/org/glassfish/hk2/maven/Version.java
        new file mode 100644
        index 0000000..5b9cd84
        --- /dev/null
        +++ b/hk2/osgiversion-maven-plugin/src/main/java/org/glassfish/hk2/maven/Version.java
        @@ -0,0 +1,167 @@
        +/*
        + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
        + *
        + * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
        + *
        + * The contents of this file are subject to the terms of either the GNU
        + * General Public License Version 2 only ("GPL") or the Common Development
        + * and Distribution License("CDDL") (collectively, the "License").  You
        + * may not use this file except in compliance with the License.  You can
        + * obtain a copy of the License at
        + * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
        + * or packager/legal/LICENSE.txt.  See the License for the specific
        + * language governing permissions and limitations under the License.
        + *
        + * When distributing the software, include this License Header Notice in each
        + * file and include the License file at packager/legal/LICENSE.txt.
        + *
        + * GPL Classpath Exception:
        + * Oracle designates this particular file as subject to the "Classpath"
        + * exception as provided by Oracle in the GPL Version 2 section of the License
        + * file that accompanied this code.
        + *
        + * Modifications:
        + * If applicable, add the following below the License Header, with the fields
        + * enclosed by brackets [] replaced by your own identifying information:
        + * "Portions Copyright [year] [name of copyright owner]"
        + *
        + * Contributor(s):
        + * If you wish your version of this file to be governed by only the CDDL or
        + * only the GPL Version 2, indicate your decision by adding "[Contributor]
        + * elects to include this software in this distribution under the [CDDL or GPL
        + * Version 2] license."  If you don't indicate a single choice of license, a
        + * recipient has the option to distribute your version of this file under
        + * either the CDDL, the GPL Version 2 or to extend the choice of license to
        + * its licensees as provided above.  However, if you add GPL Version 2 code
        + * and therefore, elected the GPL Version 2 license, then the option applies
        + * only if the new code is made subject to such option by the copyright
        + * holder.
        + */
        +package org.glassfish.hk2.maven;
        +
        +import java.util.Arrays;
        +import java.util.Collections;
        +import java.util.List;
        +import java.util.regex.Matcher;
        +import java.util.regex.Pattern;
        +import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter;
        +import org.apache.maven.shared.osgi.Maven2OsgiConverter;
        +import org.codehaus.plexus.util.StringUtils;
        +
        +/**
        + *
        + * @author Romain Grecourt
        + */
        +public class Version {
        +
        +    public enum COMPONENT {
        +        major,
        +        minor,
        +        micro,
        +        qualifier
        +    };
        +    
        +    private static final int DIGITS_INDEX = 1;
        +    public static final Pattern STANDARD_PATTERN = Pattern.compile(
        +            "^((?:\\d+\\.)*\\d+)" // digit(s) and '.' repeated - followed by digit (version digits 1.22.0, etc)
        +            + "([-_])?" // optional - or _  (annotation separator)
        +            + "([a-zA-Z]*)" // alpha characters (looking for annotation - alpha, beta, RC, etc.)
        +            + "([-_])?" // optional - or _  (annotation revision separator)
        +            + "(\\d*)" // digits  (any digits after rc or beta is an annotation revision)
        +            + "(?:([-_])?(.*?))?$");  // - or _ followed everything else (build specifier)
        +    String orig;
        +    int major = 0;
        +    int minor = 0;
        +    int incremental = 0;
        +    String qualifier = "";
        +
        +    public Version(String v) {
        +        orig = v;
        +        List<String> digits = parseDigits(v);
        +        major = getDigit(digits, 0);
        +        minor = getDigit(digits, 1);
        +        incremental = getDigit(digits, 2);
        +        if(orig.contains("-")){
        +            qualifier = orig.substring(orig.indexOf('-')+1);
        +        }
        +    }
        +
        +    private static int getDigit(List<String> digits, int idx) {
        +        if (digits.size() >= idx + 1
        +                && digits.get(idx) != null
        +                && !digits.get(idx).isEmpty()) {
        +            return Integer.parseInt(digits.get(idx));
        +        }
        +        return 0;
        +    }
        +
        +    private List<String> parseDigits(String vStr) {
        +        Matcher m = STANDARD_PATTERN.matcher(vStr);
        +        if (m.matches()) {
        +            return Arrays.asList(StringUtils.split(
        +                    m.group(DIGITS_INDEX),
        +                    "."));
        +        }
        +        return Collections.EMPTY_LIST;
        +    }
        +
        +    public int getMajorVersion() {
        +        return major;
        +    }
        +
        +    public int getMinorVersion() {
        +        return minor;
        +    }
        +
        +    public int getIncrementalVersion() {
        +        return incremental;
        +    }
        +    
        +    public String getQualifier(){
        +        return qualifier;
        +    }
        +
        +    private static String formatString4Osgi(String s){
        +        return s.replaceAll("-", "_").replaceAll("\\.", "_");
        +    }
        +    
        +    public String convertToOsgi(COMPONENT comToDrop) {
        +        Maven2OsgiConverter converter = new DefaultMaven2OsgiConverter();
        +
        +        if (comToDrop != null) {
        +            switch (comToDrop) {
        +                case major: {
        +                    return converter.getVersion("0.0.0");
        +                }
        +                case minor: {
        +                    return converter.getVersion(String.valueOf(getMajorVersion()));
        +                }
        +                case micro: {
        +                    return converter.getVersion(String.format("%s.%s",
        +                            getMajorVersion(),
        +                            getMinorVersion()));
        +                }
        +                case qualifier: {
        +                    return converter.getVersion(String.format("%s.%s.%s",
        +                            getMajorVersion(),
        +                            getMinorVersion(),
        +                            getIncrementalVersion()));
        +                }
        +            }
        +        }
        +        
        +        // init version major.minor.micro
        +        String version = String.format("%s.%s.%s",
        +                getMajorVersion(),
        +                getMinorVersion(),
        +                getIncrementalVersion());
        +        
        +        // if there is a qualifier, add it
        +        if(!getQualifier().isEmpty()){
        +            version = String.format("%s.%s",
        +                    version,
        +                    formatString4Osgi(getQualifier()));
        +        }
        +        return converter.getVersion(version);
        +    }
        +}
        diff --git a/hk2/osgiversion-maven-plugin/src/test/java/org/glassfish/hk2/maven/VersionTest.java b/hk2/osgiversion-maven-plugin/src/test/java/org/glassfish/hk2/maven/VersionTest.java
        new file mode 100644
        index 0000000..8802fbe
        --- /dev/null
        +++ b/hk2/osgiversion-maven-plugin/src/test/java/org/glassfish/hk2/maven/VersionTest.java
        @@ -0,0 +1,71 @@
        +/*
        + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
        + *
        + * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
        + *
        + * The contents of this file are subject to the terms of either the GNU
        + * General Public License Version 2 only ("GPL") or the Common Development
        + * and Distribution License("CDDL") (collectively, the "License").  You
        + * may not use this file except in compliance with the License.  You can
        + * obtain a copy of the License at
        + * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
        + * or packager/legal/LICENSE.txt.  See the License for the specific
        + * language governing permissions and limitations under the License.
        + *
        + * When distributing the software, include this License Header Notice in each
        + * file and include the License file at packager/legal/LICENSE.txt.
        + *
        + * GPL Classpath Exception:
        + * Oracle designates this particular file as subject to the "Classpath"
        + * exception as provided by Oracle in the GPL Version 2 section of the License
        + * file that accompanied this code.
        + *
        + * Modifications:
        + * If applicable, add the following below the License Header, with the fields
        + * enclosed by brackets [] replaced by your own identifying information:
        + * "Portions Copyright [year] [name of copyright owner]"
        + *
        + * Contributor(s):
        + * If you wish your version of this file to be governed by only the CDDL or
        + * only the GPL Version 2, indicate your decision by adding "[Contributor]
        + * elects to include this software in this distribution under the [CDDL or GPL
        + * Version 2] license."  If you don't indicate a single choice of license, a
        + * recipient has the option to distribute your version of this file under
        + * either the CDDL, the GPL Version 2 or to extend the choice of license to
        + * its licensees as provided above.  However, if you add GPL Version 2 code
        + * and therefore, elected the GPL Version 2 license, then the option applies
        + * only if the new code is made subject to such option by the copyright
        + * holder.
        + */
        +package org.glassfish.hk2.maven;
        +
        +import junit.framework.Assert;
        +import org.junit.Test;
        +
        +/**
        + *
        + * @author Romain Grecourt
        + */
        +public class VersionTest {
        +    
        +    public static void doTest(
        +            String orig,
        +            Version.COMPONENT compToDrop,
        +            String expected) {
        +
        +        String actual = new Version(orig).convertToOsgi(compToDrop);
        +        Assert.assertEquals(
        +                String.format("orig=%s ; compToDrop=%s ; expected=%s ; actual=%s", orig, String.valueOf(compToDrop), expected, actual),
        +                expected,
        +                actual);
        +    }
        +    
        +    @Test
        +    public void simpleTests(){
        +        doTest("4.0.1-SNAPSHOT",Version.COMPONENT.qualifier,"4.0.1");
        +        doTest("12.1.3.339",Version.COMPONENT.qualifier,"12.1.3");
        +        doTest("12.1.3.339",null,"12.1.3");
        +        doTest("12.1.3.0.0-130717.3355",null,"12.1.3.130717_3355");
        +        doTest("12.1.3.0.0-130717.3355",Version.COMPONENT.qualifier,"12.1.3");
        +    }
        +}
        
        Show
        Romain Grécourt added a comment - The following diff has been reviewed by Mason and pushed. diff --git a/hk2/osgiversion-maven-plugin/src/main/java/com/sun/enterprise/module/maven/OsgiVersionMojo.java b/hk2/osgiversion-maven-plugin/src/main/java/com/sun/enterprise/module/maven/OsgiVersionMojo.java index bb8cc39..a93f001 100644 --- a/hk2/osgiversion-maven-plugin/src/main/java/com/sun/enterprise/module/maven/OsgiVersionMojo.java +++ b/hk2/osgiversion-maven-plugin/src/main/java/com/sun/enterprise/module/maven/OsgiVersionMojo.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2007-2011 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007-2013 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -40,12 +40,11 @@ package com.sun.enterprise.module.maven; +import org.glassfish.hk2.maven.Version; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; -import org.apache.maven.shared.osgi.Maven2OsgiConverter; -import org.apache.maven.artifact.versioning.DefaultArtifactVersion; /** * Converts the project version into the OSGi format and @@ -69,7 +68,7 @@ public class OsgiVersionMojo extends AbstractMojo { * @readonly */ protected MavenProject project; - + /** * Flag used to determine what components of the version will be used * in OSGi version. @@ -87,55 +86,17 @@ public class OsgiVersionMojo extends AbstractMojo { * major, minor and micro portions will be used. * @parameter */ - protected String dropVersionComponent; + protected Version.COMPONENT dropVersionComponent; /** * @parameter default-value="project.osgi.version" */ protected String versionPropertyName; - private enum VERSION_COMPONENT {major, minor, micro, qualifier}; - - /** - * @component - */ - protected Maven2OsgiConverter converter; - + @Override public void execute() throws MojoExecutionException, MojoFailureException { - DefaultArtifactVersion projectVersion = - new DefaultArtifactVersion(project.getVersion()); - VERSION_COMPONENT compToDrop = dropVersionComponent == null ? - null : VERSION_COMPONENT.valueOf(dropVersionComponent); - - DefaultArtifactVersion newVersion = projectVersion; - if (compToDrop != null) { - switch (compToDrop) { - case major: { - newVersion = new DefaultArtifactVersion("0.0.0"); - break; - } - case minor: { - final int major = projectVersion.getMajorVersion(); - newVersion = new DefaultArtifactVersion(major +""); - break; - } - case micro: { - final int major = projectVersion.getMajorVersion(); - final int minor = projectVersion.getMinorVersion(); - newVersion = new DefaultArtifactVersion(major + "." + minor); - break; - } - case qualifier: { - final int major = projectVersion.getMajorVersion(); - final int minor = projectVersion.getMinorVersion(); - final int micro = projectVersion.getIncrementalVersion(); - newVersion = new DefaultArtifactVersion(major + "." + minor + "." + micro); - break; - } - } - } - String v = converter.getVersion(newVersion.toString()); - + Version projectVersion = new Version(project.getVersion()); + String v = projectVersion.convertToOsgi(dropVersionComponent); getLog().debug("OSGi Version for "+project.getVersion()+" is "+v); getLog().debug("It is set in project property called "+ versionPropertyName); project.getProperties().put(versionPropertyName,v); diff --git a/hk2/osgiversion-maven-plugin/src/main/java/org/glassfish/hk2/maven/Version.java b/hk2/osgiversion-maven-plugin/src/main/java/org/glassfish/hk2/maven/Version.java new file mode 100644 index 0000000..5b9cd84 --- /dev/null +++ b/hk2/osgiversion-maven-plugin/src/main/java/org/glassfish/hk2/maven/Version.java @@ -0,0 +1,167 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html + * or packager/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at packager/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package org.glassfish.hk2.maven; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter; +import org.apache.maven.shared.osgi.Maven2OsgiConverter; +import org.codehaus.plexus.util.StringUtils; + +/** + * + * @author Romain Grecourt + */ +public class Version { + + public enum COMPONENT { + major, + minor, + micro, + qualifier + }; + + private static final int DIGITS_INDEX = 1; + public static final Pattern STANDARD_PATTERN = Pattern.compile( + "^((?:\\d+\\.)*\\d+)" // digit(s) and '.' repeated - followed by digit (version digits 1.22.0, etc) + + "([-_])?" // optional - or _ (annotation separator) + + "([a-zA-Z]*)" // alpha characters (looking for annotation - alpha, beta, RC, etc.) + + "([-_])?" // optional - or _ (annotation revision separator) + + "(\\d*)" // digits (any digits after rc or beta is an annotation revision) + + "(?:([-_])?(.*?))?$"); // - or _ followed everything else (build specifier) + String orig; + int major = 0; + int minor = 0; + int incremental = 0; + String qualifier = ""; + + public Version(String v) { + orig = v; + List<String> digits = parseDigits(v); + major = getDigit(digits, 0); + minor = getDigit(digits, 1); + incremental = getDigit(digits, 2); + if(orig.contains("-")){ + qualifier = orig.substring(orig.indexOf('-')+1); + } + } + + private static int getDigit(List<String> digits, int idx) { + if (digits.size() >= idx + 1 + && digits.get(idx) != null + && !digits.get(idx).isEmpty()) { + return Integer.parseInt(digits.get(idx)); + } + return 0; + } + + private List<String> parseDigits(String vStr) { + Matcher m = STANDARD_PATTERN.matcher(vStr); + if (m.matches()) { + return Arrays.asList(StringUtils.split( + m.group(DIGITS_INDEX), + ".")); + } + return Collections.EMPTY_LIST; + } + + public int getMajorVersion() { + return major; + } + + public int getMinorVersion() { + return minor; + } + + public int getIncrementalVersion() { + return incremental; + } + + public String getQualifier(){ + return qualifier; + } + + private static String formatString4Osgi(String s){ + return s.replaceAll("-", "_").replaceAll("\\.", "_"); + } + + public String convertToOsgi(COMPONENT comToDrop) { + Maven2OsgiConverter converter = new DefaultMaven2OsgiConverter(); + + if (comToDrop != null) { + switch (comToDrop) { + case major: { + return converter.getVersion("0.0.0"); + } + case minor: { + return converter.getVersion(String.valueOf(getMajorVersion())); + } + case micro: { + return converter.getVersion(String.format("%s.%s", + getMajorVersion(), + getMinorVersion())); + } + case qualifier: { + return converter.getVersion(String.format("%s.%s.%s", + getMajorVersion(), + getMinorVersion(), + getIncrementalVersion())); + } + } + } + + // init version major.minor.micro + String version = String.format("%s.%s.%s", + getMajorVersion(), + getMinorVersion(), + getIncrementalVersion()); + + // if there is a qualifier, add it + if(!getQualifier().isEmpty()){ + version = String.format("%s.%s", + version, + formatString4Osgi(getQualifier())); + } + return converter.getVersion(version); + } +} diff --git a/hk2/osgiversion-maven-plugin/src/test/java/org/glassfish/hk2/maven/VersionTest.java b/hk2/osgiversion-maven-plugin/src/test/java/org/glassfish/hk2/maven/VersionTest.java new file mode 100644 index 0000000..8802fbe --- /dev/null +++ b/hk2/osgiversion-maven-plugin/src/test/java/org/glassfish/hk2/maven/VersionTest.java @@ -0,0 +1,71 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html + * or packager/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at packager/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package org.glassfish.hk2.maven; + +import junit.framework.Assert; +import org.junit.Test; + +/** + * + * @author Romain Grecourt + */ +public class VersionTest { + + public static void doTest( + String orig, + Version.COMPONENT compToDrop, + String expected) { + + String actual = new Version(orig).convertToOsgi(compToDrop); + Assert.assertEquals( + String.format("orig=%s ; compToDrop=%s ; expected=%s ; actual=%s", orig, String.valueOf(compToDrop), expected, actual), + expected, + actual); + } + + @Test + public void simpleTests(){ + doTest("4.0.1-SNAPSHOT",Version.COMPONENT.qualifier,"4.0.1"); + doTest("12.1.3.339",Version.COMPONENT.qualifier,"12.1.3"); + doTest("12.1.3.339",null,"12.1.3"); + doTest("12.1.3.0.0-130717.3355",null,"12.1.3.130717_3355"); + doTest("12.1.3.0.0-130717.3355",Version.COMPONENT.qualifier,"12.1.3"); + } +}

          People

          • Assignee:
            Romain Grécourt
            Reporter:
            Romain Grécourt
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: