Author: jsdelfino
Date: Sun Oct 12 15:43:10 2008
New Revision: 703892
URL: http://svn.apache.org/viewvc?rev=703892&view=rev
Log:
Minor cleanup of the bundle plugin. Added a new plugin to generate the correct
PDE .classpath entries.
Added:
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
- copied, changed from r703891,
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleUtil.java
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ThirdPartyBundleBuildMojo.java
- copied, changed from r703891,
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleMojo.java
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ThirdPartyBundleFixupClasspathMojo.java
Removed:
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleMojo.java
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleUtil.java
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/TuscanyBundlePluginMojo.java
Copied:
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
(from r703891,
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleUtil.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?p2=tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java&p1=tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleUtil.java&r1=703891&r2=703892&rev=703892&view=diff
==============================================================================
---
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleUtil.java
(original)
+++
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
Sun Oct 12 15:43:10 2008
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.tools.sca.tuscany.bundle.plugin;
+package org.apache.tuscany.sca.tools.bundle.plugin;
import static org.osgi.framework.Constants.BUNDLE_CLASSPATH;
import static org.osgi.framework.Constants.BUNDLE_MANIFESTVERSION;
@@ -49,11 +49,11 @@
import org.osgi.framework.Bundle;
/**
- * Common functions and constants used by the admin components.
+ * Common functions used by the plugin.
*
* @version $Rev$ $Date$
*/
-public final class LibraryBundleUtil {
+final class BundleUtil {
private static final String LAUNCHER_EQUINOX_LIBRARIES =
"org.apache.tuscany.sca.node.launcher.equinox.libraries";
@@ -126,7 +126,7 @@
}
}
- static Manifest libraryManifest(Set<File> jarFiles, String name, String
version, boolean copyJars)
+ static Manifest libraryManifest(Set<File> jarFiles, String name, String
version)
throws IllegalStateException {
try {
@@ -137,15 +137,9 @@
Set<String> packages = new HashSet<String>();
for (File jarFile : jarFiles) {
addPackages(jarFile, packages);
- if (copyJars) {
- classpath.append("lib/");
- classpath.append(jarFile.getName());
- classpath.append(",");
- } else {
- classpath.append("\"external:");
-
classpath.append(jarFile.getPath().replace(File.separatorChar, '/'));
- classpath.append("\",");
- }
+ classpath.append("lib/");
+ classpath.append(jarFile.getName());
+ classpath.append(",");
}
Set<String> importPackages = new HashSet<String>();
Copied:
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ThirdPartyBundleBuildMojo.java
(from r703891,
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleMojo.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?p2=tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ThirdPartyBundleBuildMojo.java&p1=tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleMojo.java&r1=703891&r2=703892&rev=703892&view=diff
==============================================================================
---
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleMojo.java
(original)
+++
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ThirdPartyBundleBuildMojo.java
Sun Oct 12 15:43:10 2008
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.tools.sca.tuscany.bundle.plugin;
+package org.apache.tuscany.sca.tools.bundle.plugin;
-import static
org.apache.tuscany.tools.sca.tuscany.bundle.plugin.LibraryBundleUtil.write;
+import static org.apache.tuscany.sca.tools.bundle.plugin.BundleUtil.write;
import java.io.File;
import java.io.FileInputStream;
@@ -48,12 +48,12 @@
/**
* @version $Rev$ $Date$
- * @goal build
- * @phase process-sources
+ * @goal assemble-thirdparty-bundle
+ * @phase process-classes
* @requiresDependencyResolution test
- * @description Build a virtual bundle for 3rd party dependencies
+ * @description Build an OSGi bundle for third party dependencies
*/
-public class LibraryBundleMojo extends AbstractMojo {
+public class ThirdPartyBundleBuildMojo extends AbstractMojo {
/**
* The project to create a build for.
*
@@ -108,11 +108,6 @@
private java.util.List remoteRepos;
/**
- * @parameter
- */
- private boolean copyJars = false;
-
- /**
* Dependency tree builder
*
* @component
@@ -216,7 +211,7 @@
}
String bundleName = null;
try {
- bundleName =
LibraryBundleUtil.getBundleName(artifact.getFile());
+ bundleName = BundleUtil.getBundleName(artifact.getFile());
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
@@ -236,7 +231,7 @@
version = version.substring(0, version.length() -
Artifact.SNAPSHOT_VERSION.length() - 1);
}
- Manifest mf = LibraryBundleUtil.libraryManifest(jarFiles,
project.getName(), version, copyJars);
+ Manifest mf = BundleUtil.libraryManifest(jarFiles,
project.getName(), version);
File file = new File(project.getBasedir(), "META-INF");
file.mkdir();
file= new File(file, "MANIFEST.MF");
@@ -248,33 +243,31 @@
write(mf, fos);
fos.close();
- if (copyJars) {
- File lib = new File(project.getBasedir(), "lib");
- if (lib.isDirectory()) {
- for (File c : lib.listFiles()) {
- c.delete();
- }
+ File lib = new File(project.getBasedir(), "lib");
+ if (lib.isDirectory()) {
+ for (File c : lib.listFiles()) {
+ c.delete();
}
- lib.mkdir();
- byte[] buf = new byte[4096];
- for (File jar : jarFiles) {
- File jarFile = new File(lib, jar.getName());
- if (log.isDebugEnabled()) {
- log.debug("Copying " + jar + " to " + jarFile);
- }
- FileInputStream in = new FileInputStream(jar);
- FileOutputStream out = new FileOutputStream(jarFile);
- for (;;) {
- int len = in.read(buf);
- if (len > 0) {
- out.write(buf, 0, len);
- } else {
- break;
- }
+ }
+ lib.mkdir();
+ byte[] buf = new byte[4096];
+ for (File jar : jarFiles) {
+ File jarFile = new File(lib, jar.getName());
+ if (log.isDebugEnabled()) {
+ log.debug("Copying " + jar + " to " + jarFile);
+ }
+ FileInputStream in = new FileInputStream(jar);
+ FileOutputStream out = new FileOutputStream(jarFile);
+ for (;;) {
+ int len = in.read(buf);
+ if (len > 0) {
+ out.write(buf, 0, len);
+ } else {
+ break;
}
- in.close();
- out.close();
}
+ in.close();
+ out.close();
}
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
Added:
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ThirdPartyBundleFixupClasspathMojo.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/ThirdPartyBundleFixupClasspathMojo.java?rev=703892&view=auto
==============================================================================
---
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ThirdPartyBundleFixupClasspathMojo.java
(added)
+++
tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ThirdPartyBundleFixupClasspathMojo.java
Sun Oct 12 15:43:10 2008
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * 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.
+ */
+package org.apache.tuscany.sca.tools.bundle.plugin;
+
+import static org.apache.tuscany.sca.tools.bundle.plugin.BundleUtil.write;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.Manifest;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.dependency.tree.DependencyTree;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
+
+/**
+ * @version $Rev$ $Date$
+ * @goal fixup-pde-classpath
+ * @phase process-resources
+ * @requiresDependencyResolution test
+ * @description Adjust third party bundle classpath
+ */
+public class ThirdPartyBundleFixupClasspathMojo extends AbstractMojo {
+ /**
+ * The project to create a build for.
+ *
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
+ /**
+ * The basedir of the project.
+ *
+ * @parameter expression="${basedir}"
+ * @required @readonly
+ */
+ private File basedir;
+
+ public void execute() throws MojoExecutionException {
+ Log log = getLog();
+
+ if (project.getPackaging().equals("pom")) {
+ return;
+ }
+
+ try {
+ // Adjust .classpath, make all classpath entries point to the lib
directory
+ File classpath = new File(basedir, ".classpath");
+ BufferedReader reader = new BufferedReader(new
InputStreamReader(new FileInputStream(classpath)));
+ StringWriter buffer = new StringWriter();
+ PrintWriter printer = new PrintWriter(buffer);
+ for (;;) {
+ String line = reader.readLine();
+ if (line == null) {
+ break;
+ }
+ int i = line.indexOf("kind=\"var\"");
+ if (i != -1) {
+ line = line.substring(0, i) + "kind=\"lib\"
exported=\"true\"" + line.substring(i+10);
+
+ i = line.indexOf("path=\"");
+ if (i != -1) {
+ int e = line.indexOf("\"", i+6);
+ String path = line.substring(i + 6, e);
+ int s = path.lastIndexOf("/");
+ if (s != -1) {
+ path = "lib" + path.substring(s);
+ line = line.substring(0, i) + "path=\"" + path +
line.substring(e);
+ }
+ }
+ }
+ printer.println(line);
+ }
+ reader.close();
+ Writer writer = new OutputStreamWriter(new
FileOutputStream(classpath));
+ writer.write(buffer.toString());
+ writer.close();
+
+ } catch (Exception e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+
+ }
+
+}