summaryrefslogtreecommitdiffstats
path: root/maven-plugins/trunk/maven-eclipse-compiler
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-26 18:13:31 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-26 18:13:31 +0000
commite62a5ee21ef5124d3a50893fa8ee7dce7eefea57 (patch)
treee83cdd9dd6a3f0b7b35bec117ea6b33ac56c6deb /maven-plugins/trunk/maven-eclipse-compiler
parent6fcc7fb8f40fc01cc37cb99b637c1f7e39d3af07 (diff)
Minor fix to tolerate - in the maven version id
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@758783 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'maven-plugins/trunk/maven-eclipse-compiler')
-rw-r--r--maven-plugins/trunk/maven-eclipse-compiler/src/main/java/org/apache/tuscany/maven/compiler/osgi/BundleUtil.java72
-rw-r--r--maven-plugins/trunk/maven-eclipse-compiler/src/main/java/org/apache/tuscany/maven/compiler/osgi/OSGIArtifactVersion.java219
2 files changed, 255 insertions, 36 deletions
diff --git a/maven-plugins/trunk/maven-eclipse-compiler/src/main/java/org/apache/tuscany/maven/compiler/osgi/BundleUtil.java b/maven-plugins/trunk/maven-eclipse-compiler/src/main/java/org/apache/tuscany/maven/compiler/osgi/BundleUtil.java
index ea4b3b6dff..c77991041c 100644
--- a/maven-plugins/trunk/maven-eclipse-compiler/src/main/java/org/apache/tuscany/maven/compiler/osgi/BundleUtil.java
+++ b/maven-plugins/trunk/maven-eclipse-compiler/src/main/java/org/apache/tuscany/maven/compiler/osgi/BundleUtil.java
@@ -6,15 +6,15 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
*/
package org.apache.tuscany.maven.compiler.osgi;
@@ -50,7 +50,6 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.maven.artifact.versioning.ArtifactVersion;
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.eclipse.osgi.framework.internal.core.Constants;
import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
import org.eclipse.osgi.util.ManifestElement;
@@ -65,7 +64,7 @@ public final class BundleUtil {
/**
* Returns the name of a bundle, or null if the given file is not a bundle.
- *
+ *
* @param file
* @return
* @throws IOException
@@ -129,19 +128,19 @@ public final class BundleUtil {
Set<File> jars = new HashSet<File>();
jars.add(file);
String name = file.getName();
- manifest = libraryManifest(jars, name, name, jarVersion(name), null);
+ manifest = libraryManifest(jars, name, name, getOSGiVersion(name), null);
}
return manifest;
}
/**
* Generate a Bundle manifest for a set of JAR files.
- *
+ *
* @param jarFiles
* @param name
* @param symbolicName
* @param version
- * @param dir
+ * @param dir
* @return
* @throws IllegalStateException
*/
@@ -211,7 +210,7 @@ public final class BundleUtil {
/**
* Write a bundle manifest.
- *
+ *
* @param manifest
* @param out
* @throws IOException
@@ -233,7 +232,7 @@ public final class BundleUtil {
/**
* Add packages to be exported out of a JAR file.
- *
+ *
* @param jarFile
* @param packages
* @throws IOException
@@ -249,7 +248,7 @@ public final class BundleUtil {
/**
* Write manifest attributes.
- *
+ *
* @param attributes
* @param key
* @param dos
@@ -278,7 +277,7 @@ public final class BundleUtil {
/**
* Strip an OSGi export, only retain the package name and version.
- *
+ *
* @param export
* @return
*/
@@ -303,7 +302,7 @@ public final class BundleUtil {
/**
* Add all the packages out of a JAR.
- *
+ *
* @param jarFile
* @param packages
* @param version
@@ -344,7 +343,7 @@ public final class BundleUtil {
/**
* Add the packages exported by a bundle.
- *
+ *
* @param file
* @param packages
* @return
@@ -409,43 +408,44 @@ public final class BundleUtil {
}
}
}
-
+
/**
* starting with -, then some digits, then . or - or _, then some digits again
- *
+ *
*/
private static Pattern pattern = Pattern.compile("-(\\d)+((\\.|-|_)(\\d)+)*");
/**
* Returns the version number to use for the given JAR file.
- *
+ *
* @param fileName
* @return
*/
- static String jarVersion(String fileName) {
+ static String getOSGiVersion(String fileName) {
String name = fileName;
int index = name.lastIndexOf('.');
if (index != -1) {
// Trim the extension
name = name.substring(0, index);
}
-
+
Matcher matcher = pattern.matcher(name);
String version = "0.0.0";
if (matcher.find()) {
version = matcher.group();
version = version.substring(1);
+
}
- return version;
+ return osgiVersion(version);
}
/**
- * Convert the maven version into OSGi version
+ * Convert the maven version into OSGi version
* @param mavenVersion
* @return
*/
static String osgiVersion(String mavenVersion) {
- ArtifactVersion ver = new DefaultArtifactVersion(mavenVersion);
+ ArtifactVersion ver = new OSGIArtifactVersion(mavenVersion);
String qualifer = ver.getQualifier();
if (qualifer != null) {
StringBuffer buf = new StringBuffer(qualifer);
@@ -464,10 +464,10 @@ public final class BundleUtil {
String version = osgiVersion.toString();
return version;
}
-
- private static String J2SE = "J2SE-";
- private static String JAVASE = "JavaSE-";
- private static String PROFILE_EXT = ".profile";
+
+ private static String J2SE = "J2SE-";
+ private static String JAVASE = "JavaSE-";
+ private static String PROFILE_EXT = ".profile";
public static void loadVMProfile(Properties properties) {
Properties profileProps = findVMProfile(properties);
@@ -510,26 +510,26 @@ public final class BundleUtil {
if (j2meConfig != null && j2meConfig.length() > 0 && j2meProfiles != null && j2meProfiles.length() > 0) {
// save the vmProfile based off of the config and profile
// use the last profile; assuming that is the highest one
- String[] j2meProfileList = ManifestElement.getArrayFromList(j2meProfiles, " ");
+ String[] j2meProfileList = ManifestElement.getArrayFromList(j2meProfiles, " ");
if (j2meProfileList != null && j2meProfileList.length > 0)
vmProfile = j2meConfig + '_' + j2meProfileList[j2meProfileList.length - 1];
} else {
// No J2ME properties; use J2SE properties
// Note that the CDC spec appears not to require VM implementations to set the
- // javax.microedition properties!! So we will try to fall back to the
+ // javax.microedition properties!! So we will try to fall back to the
// java.specification.name property, but this is pretty ridiculous!!
- String javaSpecVersion = properties.getProperty("java.specification.version");
+ String javaSpecVersion = properties.getProperty("java.specification.version");
// set the profile and EE based off of the java.specification.version
// TODO We assume J2ME Foundation and J2SE here. need to support other profiles J2EE ...
if (javaSpecVersion != null) {
- StringTokenizer st = new StringTokenizer(javaSpecVersion, " _-");
+ StringTokenizer st = new StringTokenizer(javaSpecVersion, " _-");
javaSpecVersion = st.nextToken();
- String javaSpecName = properties.getProperty("java.specification.name");
- if ("J2ME Foundation Specification".equals(javaSpecName))
+ String javaSpecName = properties.getProperty("java.specification.name");
+ if ("J2ME Foundation Specification".equals(javaSpecName))
vmProfile = "CDC-" + javaSpecVersion + "_Foundation-" + javaSpecVersion; //$NON-NLS-2$
else {
// look for JavaSE if 1.6 or greater; otherwise look for J2SE
- Version v16 = new Version("1.6");
+ Version v16 = new Version("1.6");
javaEdition = J2SE;
try {
javaVersion = new Version(javaSpecVersion);
@@ -562,7 +562,7 @@ public final class BundleUtil {
}
if (url == null)
// the profile url is still null then use the osgi min profile in OSGi by default
- url = findInSystemBundle("OSGi_Minimum-1.1.profile");
+ url = findInSystemBundle("OSGi_Minimum-1.1.profile");
if (url != null) {
InputStream in = null;
try {
@@ -585,7 +585,7 @@ public final class BundleUtil {
result.put(Constants.OSGI_JAVA_PROFILE_NAME, vmProfile.replace('_', '/'));
else
// last resort; default to the absolute minimum profile name for the framework
- result.put(Constants.OSGI_JAVA_PROFILE_NAME, "OSGi/Minimum-1.1");
+ result.put(Constants.OSGI_JAVA_PROFILE_NAME, "OSGi/Minimum-1.1");
return result;
}
@@ -603,7 +603,7 @@ public final class BundleUtil {
URL result = null;
int minor = javaVersion.getMinor();
do {
- result = findInSystemBundle(javaEdition + javaVersion.getMajor() + "." + minor + PROFILE_EXT);
+ result = findInSystemBundle(javaEdition + javaVersion.getMajor() + "." + minor + PROFILE_EXT);
minor = minor - 1;
} while (result == null && minor > 0);
return result;
diff --git a/maven-plugins/trunk/maven-eclipse-compiler/src/main/java/org/apache/tuscany/maven/compiler/osgi/OSGIArtifactVersion.java b/maven-plugins/trunk/maven-eclipse-compiler/src/main/java/org/apache/tuscany/maven/compiler/osgi/OSGIArtifactVersion.java
new file mode 100644
index 0000000000..58b27293f9
--- /dev/null
+++ b/maven-plugins/trunk/maven-eclipse-compiler/src/main/java/org/apache/tuscany/maven/compiler/osgi/OSGIArtifactVersion.java
@@ -0,0 +1,219 @@
+package org.apache.tuscany.maven.compiler.osgi;
+
+/*
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.StringTokenizer;
+
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+
+public class OSGIArtifactVersion implements ArtifactVersion {
+ private Integer buildNumber;
+
+ private Integer incrementalVersion;
+
+ private Integer majorVersion;
+
+ private Integer minorVersion;
+
+ private String qualifier;
+
+ private String unparsed;
+
+ public OSGIArtifactVersion(String version) {
+ parseVersion(version);
+ }
+
+ public int compareTo(Object o) {
+ ArtifactVersion otherVersion = (ArtifactVersion)o;
+
+ int result = getMajorVersion() - otherVersion.getMajorVersion();
+ if (result == 0) {
+ result = getMinorVersion() - otherVersion.getMinorVersion();
+ }
+ 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;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+
+ if (false == (other instanceof ArtifactVersion)) {
+ return false;
+ }
+
+ return 0 == compareTo(other);
+ }
+
+ public int getBuildNumber() {
+ return this.buildNumber != null ? this.buildNumber.intValue() : 0;
+ }
+
+ public int getIncrementalVersion() {
+ return this.incrementalVersion != null ? this.incrementalVersion.intValue() : 0;
+ }
+
+ public int getMajorVersion() {
+ return this.majorVersion != null ? this.majorVersion.intValue() : 0;
+ }
+
+ public int getMinorVersion() {
+ return this.minorVersion != null ? this.minorVersion.intValue() : 0;
+ }
+
+ public String getQualifier() {
+ return this.qualifier;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 1229;
+
+ result = 1223 * result + getMajorVersion();
+ result = 1223 * result + getMinorVersion();
+ result = 1223 * result + getIncrementalVersion();
+ result = 1223 * result + getBuildNumber();
+
+ if (null != getQualifier()) {
+ result = 1223 * result + getQualifier().hashCode();
+ }
+
+ return result;
+ }
+
+ public final void parseVersion(String version) {
+ this.unparsed = version;
+
+ int index = version.indexOf("-");
+
+ String part1;
+ String part2 = null;
+
+ if (index < 0) {
+ part1 = version;
+ } else {
+ part1 = version.substring(0, index);
+ part2 = version.substring(index + 1);
+ }
+
+ if (part2 != null) {
+ try {
+ if ((part2.length() == 1) || !part2.startsWith("0")) {
+ this.buildNumber = Integer.valueOf(part2);
+ } else {
+ this.qualifier = part2;
+ }
+ } catch (NumberFormatException e) {
+ this.qualifier = part2;
+ }
+ }
+
+ if ((part1.indexOf(".") < 0) && !part1.startsWith("0")) {
+ try {
+ this.majorVersion = Integer.valueOf(part1);
+ } catch (NumberFormatException e) {
+ // qualifier is the whole version, including "-"
+ this.qualifier = version;
+ this.buildNumber = null;
+ }
+ } else {
+ StringTokenizer tok = new StringTokenizer(part1, ".");
+
+ String s;
+
+ if (tok.hasMoreTokens()) {
+ s = tok.nextToken();
+ try {
+ this.majorVersion = Integer.valueOf(s);
+
+ if (tok.hasMoreTokens()) {
+ s = tok.nextToken();
+ try {
+ this.minorVersion = Integer.valueOf(s);
+ if (tok.hasMoreTokens()) {
+
+ s = tok.nextToken();
+ try {
+ this.incrementalVersion = Integer.valueOf(s);
+
+ } catch (NumberFormatException e) {
+ this.qualifier = s;
+ }
+ }
+ } catch (NumberFormatException e) {
+ this.qualifier = s;
+ }
+ }
+ } catch (NumberFormatException e) {
+ this.qualifier = s;
+ }
+ }
+
+ if (tok.hasMoreTokens()) {
+ StringBuffer qualifier = new StringBuffer(this.qualifier != null ? this.qualifier : "");
+ qualifier.append(tok.nextToken());
+ while (tok.hasMoreTokens()) {
+ qualifier.append("_");
+ qualifier.append(tok.nextToken());
+ }
+
+ this.qualifier = qualifier.toString();
+ }
+
+ }
+ }
+
+ @Override
+ public String toString() {
+ return this.unparsed;
+ }
+}