Author: rfeng
Date: Thu Oct 23 23:42:51 2008
New Revision: 707562
URL: http://svn.apache.org/viewvc?rev=707562&view=rev
Log:
Derive the OSGi version from maven version
Removed:
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/
Modified:
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ThirdPartyBundleBuildMojo.java
Modified:
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java?rev=707562&r1=707561&r2=707562&view=diff
==============================================================================
---
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
(original)
+++
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
Thu Oct 23 23:42:51 2008
@@ -38,11 +38,13 @@
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
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.osgi.framework.Version;
+
/**
* Common functions used by the plugin.
*
@@ -103,7 +105,7 @@
StringBuffer classpath = new StringBuffer();
Set<String> exportedPackages = new HashSet<String>();
for (File jarFile : jarFiles) {
- addPackages(jarFile, exportedPackages);
+ addPackages(jarFile, exportedPackages, version);
if (dir != null) {
classpath.append(dir).append("/");
}
@@ -184,10 +186,10 @@
* @param packages
* @throws IOException
*/
- private static void addPackages(File jarFile, Set<String> packages) throws
IOException {
+ private static void addPackages(File jarFile, Set<String> packages, String
version) throws IOException {
if (getBundleSymbolicName(jarFile) == null) {
- String version = ";version=" + version(jarFile.getPath());
- addAllPackages(jarFile, packages, version);
+ String ver = ";version=" + version;
+ addAllPackages(jarFile, packages, ver);
} else {
addExportedPackages(jarFile, packages);
}
@@ -356,33 +358,29 @@
}
}
- static private Pattern pattern = Pattern.compile("-([0-9.]+)");
- static private Pattern pattern2 = Pattern.compile("_([0-9.]+)");
-
/**
- * Derive a bundle version from the given JAR file name.
- *
- * @param jarFile
+ * Convert the maven version into OSGi version
+ * @param mavenVersion
* @return
*/
- static String version(String jarFile) {
- String version = "1.0.0";
- boolean found = false;
- Matcher matcher = pattern2.matcher(jarFile);
- if (matcher.find()) {
- found = true;
- } else {
- matcher = pattern.matcher(jarFile);
- found = matcher.find();
- }
- if (found) {
- version = matcher.group();
- if (version.endsWith(".")) {
- version = version.substring(1, version.length() - 1);
- } else {
- version = version.substring(1);
+ 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;
}
Modified:
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java?rev=707562&r1=707561&r2=707562&view=diff
==============================================================================
---
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java
(original)
+++
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java
Thu Oct 23 23:42:51 2008
@@ -46,7 +46,7 @@
* @description Generate a modules directory containing OSGi bundles for all
the project's module dependencies.
*/
public class ModuleBundlesBuildMojo extends AbstractMojo {
-
+
/**
* The project to create a distribution for.
*
@@ -62,7 +62,7 @@
* @parameter
*/
private File targetDirectory;
-
+
/**
* Directories containing artifacts to exclude.
*
@@ -92,6 +92,12 @@
private boolean generateTargetPlatform;
/**
+ * A list of Eclipse features to be added to the target definition
+ * @parameter
+ */
+ private String[] eclipseFeatures;
+
+ /**
* Set to true to generate a plugin.xml.
*
* @parameter
@@ -102,7 +108,7 @@
Log log = getLog();
try {
-
+
// Create the target directory
File root;
if (targetDirectory == null) {
@@ -111,9 +117,9 @@
root = targetDirectory;
}
root.mkdirs();
-
+
// Build sets of exclude directories and included/excluded/groupids
- Set<String> excludedFileNames = new HashSet<String>();
+ Set<String> excludedFileNames = new HashSet<String>();
if (excludeDirectories != null) {
for (File f: excludeDirectories) {
if (f.isDirectory()) {
@@ -131,7 +137,7 @@
}
Set<String> excludedGroupIds = new HashSet<String>();
if (excludeGroupIds != null) {
- for (String g: excludeGroupIds) {
+ for (String g : excludeGroupIds) {
excludedGroupIds.add(g);
}
}
@@ -142,18 +148,19 @@
Artifact artifact = (Artifact)o;
// Only consider Compile and Runtime dependencies
- if (!(Artifact.SCOPE_COMPILE.equals(artifact.getScope()) ||
Artifact.SCOPE_RUNTIME.equals(artifact.getScope()))) {
+ if (!(Artifact.SCOPE_COMPILE.equals(artifact.getScope()) ||
Artifact.SCOPE_RUNTIME.equals(artifact
+ .getScope()))) {
if (log.isDebugEnabled()) {
log.debug("Skipping artifact: " + artifact);
}
continue;
}
-
+
// Only consider JAR and WAR files
if (!"jar".equals(artifact.getType()) &&
!"war".equals(artifact.getType())) {
continue;
}
-
+
// Exclude artifact if its groupId is excluded or if it's not
included
if (excludedGroupIds.contains(artifact.getGroupId())) {
log.debug("Artifact groupId is excluded: " + artifact);
@@ -171,11 +178,11 @@
log.warn("Artifact doesn't exist: " + artifact);
continue;
}
-
+
if (log.isDebugEnabled()) {
log.debug("Processing artifact: " + artifact);
}
-
+
// Get the bundle name if the artifact is an OSGi bundle
String bundleName = null;
try {
@@ -183,9 +190,9 @@
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
-
+
if (bundleName != null) {
-
+
// Exclude artifact if its file name is excluded
if (excludedFileNames.contains(artifactFile.getName())) {
log.debug("Artifact file is excluded: " + artifact);
@@ -196,9 +203,9 @@
log.info("Adding OSGi bundle artifact: " + artifact);
copyFile(artifactFile, root);
bundleSymbolicNames.add(bundleName);
-
+
} else if ("war".equals(artifact.getType())) {
-
+
// Exclude artifact if its file name is excluded
if (excludedFileNames.contains(artifactFile.getName())) {
log.debug("Artifact file is excluded: " + artifact);
@@ -209,9 +216,9 @@
log.info("Adding WAR artifact: " + artifact);
copyFile(artifactFile, root);
bundleSymbolicNames.add(bundleName);
-
+
} else {
-
+
File dir = new File(root,
artifactFile.getName().substring(0, artifactFile.getName().length() - 4));
// Exclude artifact if its file name is excluded
@@ -222,12 +229,13 @@
// Create a bundle directory for a non-OSGi JAR
log.info("Adding JAR artifact: " + artifact);
- String version =
BundleUtil.version(artifactFile.getPath());
+ String version =
BundleUtil.osgiVersion(artifact.getVersion());
Set<File> jarFiles = new HashSet<File>();
jarFiles.add(artifactFile);
- String symbolicName = (artifact.getGroupId() + "." +
artifact.getArtifactId()).replace('-', '.');
- Manifest mf = BundleUtil.libraryManifest(jarFiles,
symbolicName + "_" + version, symbolicName, version, null);
+ String symbolicName = (artifact.getGroupId() + "." +
artifact.getArtifactId());
+ Manifest mf =
+ BundleUtil.libraryManifest(jarFiles, symbolicName,
symbolicName, version, null);
File file = new File(dir, "META-INF");
file.mkdirs();
file = new File(file, "MANIFEST.MF");
@@ -239,15 +247,15 @@
bundleSymbolicNames.add(symbolicName);
}
}
-
+
// Generate a PDE target
if (generateTargetPlatform) {
File target = new File(project.getBasedir(), "tuscany.target");
FileOutputStream targetFile = new FileOutputStream(target);
- writeTarget(new PrintStream(targetFile), bundleSymbolicNames);
+ writeTarget(new PrintStream(targetFile), bundleSymbolicNames,
eclipseFeatures);
targetFile.close();
}
-
+
// Generate a plugin.xml referencing the PDE target
if (generatePlugin) {
File pluginxml = new File(project.getBasedir(), "plugin.xml");
@@ -279,13 +287,14 @@
out.close();
}
- private static void writeTarget(PrintStream ps, Set<String> ids) {
+ private static void writeTarget(PrintStream ps, Set<String> ids, String[]
features) {
ps.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
ps.println("<?pde version=\"3.2\"?>");
ps.println("<target name=\"Apache Tuscany Eclipse Target\">");
- ps.println("<location path=\"${project_loc}/eclipse\"/>");
+ ps.println("<location useDefault=\"true\"/>");
+ // ps.println("<content useAllPlugins=\"true\">");
ps.println("<content>");
ps.println("<plugins>");
for (String id : ids) {
@@ -293,10 +302,15 @@
}
ps.println("</plugins>");
ps.println("<features>");
+ if (features != null) {
+ for (String f : features) {
+ ps.println("<feature id=\"" + f + "\"/>");
+ }
+ }
ps.println("</features>");
ps.println("<extraLocations>");
// Not sure why the extra path needs to the plugins folder
- ps.println("<location path=\"${eclipse_home}/plugins\"/>");
+ ps.println("<location path=\"${project_loc}/target/plugins\"/>");
ps.println("</extraLocations>");
ps.println("</content>");
Modified:
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ThirdPartyBundleBuildMojo.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ThirdPartyBundleBuildMojo.java?rev=707562&r1=707561&r2=707562&view=diff
==============================================================================
---
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ThirdPartyBundleBuildMojo.java
(original)
+++
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ThirdPartyBundleBuildMojo.java
Thu Oct 23 23:42:51 2008
@@ -44,7 +44,7 @@
* @description Build an OSGi bundle for the project's third party dependencies
*/
public class ThirdPartyBundleBuildMojo extends AbstractMojo {
-
+
/**
* The project to build the bundle for.
*
@@ -60,7 +60,7 @@
* @parameter
*/
private String symbolicName;
-
+
public void execute() throws MojoExecutionException {
Log log = getLog();
@@ -69,7 +69,8 @@
for (Object o : project.getArtifacts()) {
Artifact artifact = (Artifact)o;
- if (!(Artifact.SCOPE_COMPILE.equals(artifact.getScope()) ||
Artifact.SCOPE_RUNTIME.equals(artifact.getScope()))) {
+ if (!(Artifact.SCOPE_COMPILE.equals(artifact.getScope()) ||
Artifact.SCOPE_RUNTIME.equals(artifact
+ .getScope()))) {
if (log.isDebugEnabled()) {
log.debug("Skipping artifact: " + artifact);
}
@@ -102,15 +103,12 @@
}
try {
- String version = project.getVersion();
- if (version.endsWith(Artifact.SNAPSHOT_VERSION)) {
- version = version.substring(0, version.length() -
Artifact.SNAPSHOT_VERSION.length() - 1);
- }
+ String version = BundleUtil.osgiVersion(project.getVersion());
Manifest mf = BundleUtil.libraryManifest(jarFiles,
project.getName(), symbolicName, version, "lib");
File file = new File(project.getBasedir(), "META-INF");
file.mkdir();
- file= new File(file, "MANIFEST.MF");
+ file = new File(file, "MANIFEST.MF");
if (log.isDebugEnabled()) {
log.debug("Generating " + file);
}