summaryrefslogtreecommitdiffstats
path: root/java/sca/tools/maven
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-11-21 01:11:07 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-11-21 01:11:07 +0000
commit60cd6cf6bfdb20a639acdbe9d881240711cd7529 (patch)
treee77e5275d2b177cc8dbaeab1ee30bc8495c3cdde /java/sca/tools/maven
parent297509632fec4b0630702e6368603a079e00b590 (diff)
Fix the issue with duplicate packages for 3rd party jars
Add the capability to generate an equinox configuration to launch and validate the bundles git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@719440 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/tools/maven')
-rw-r--r--java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java19
-rw-r--r--java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java60
2 files changed, 66 insertions, 13 deletions
diff --git a/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java b/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
index f104225483..7b078887c7 100644
--- a/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
+++ b/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
@@ -38,6 +38,7 @@ import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
+import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -51,7 +52,7 @@ import org.osgi.framework.Version;
* @version $Rev$ $Date$
*/
final class BundleUtil {
-
+ private final static Logger logger = Logger.getLogger(BundleUtil.class.getName());
/**
* Returns the name of a bundle, or null if the given file is not a bundle.
*
@@ -116,7 +117,7 @@ final class BundleUtil {
// Generate export-package and import-package declarations
StringBuffer exports = new StringBuffer();
StringBuffer imports = new StringBuffer();
- Set<String> importedPackages = new HashSet<String>();
+ Set<String> pkgs = new HashSet<String>();
for (String export : exportedPackages) {
// Add export declaration
@@ -125,13 +126,17 @@ final class BundleUtil {
// Add corresponding import declaration
String packageName = packageName(export);
- if (!importedPackages.contains(packageName)) {
- importedPackages.add(packageName);
- imports.append(packageName);
- imports.append(',');
+ if (!pkgs.contains(packageName)) {
+// imports.append(export);
+// imports.append(',');
+ pkgs.add(packageName);
+ exports.append(export);
+ exports.append(',');
+ } else {
+ logger.warning("Duplicate package skipped: " + export);
}
}
-
+
// Create a manifest
Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
diff --git a/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java b/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java
index de03d0d6d2..7db367b4f0 100644
--- a/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java
+++ b/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java
@@ -96,6 +96,12 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
* @parameter
*/
private String[] eclipseFeatures;
+
+ /**
+ * If we use the running eclipse as the default location for the target
+ * @parameter
+ */
+ private boolean useDefaultLocation = true;
/**
* Set to true to generate a plugin.xml.
@@ -103,6 +109,12 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
* @parameter
*/
private boolean generatePlugin;
+
+ /**
+ * Generate a configuration/config.ini for equinox
+ * @parameter
+ */
+ private boolean generateConfig;
/**
* @parameter
@@ -149,6 +161,7 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
// Process all the dependency artifacts
Set<String> bundleSymbolicNames = new HashSet<String>();
+ Set<String> fileNames = new HashSet<String>();
for (Object o : project.getArtifacts()) {
Artifact artifact = (Artifact)o;
@@ -208,6 +221,7 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
log.info("Adding OSGi bundle artifact: " + artifact);
copyFile(artifactFile, root);
bundleSymbolicNames.add(bundleName);
+ fileNames.add(artifactFile.getName());
} else if ("war".equals(artifact.getType())) {
@@ -223,7 +237,12 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
} else {
- File dir = new File(root, artifactFile.getName().substring(0, artifactFile.getName().length() - 4));
+// String version = BundleUtil.osgiVersion(artifact.getVersion());
+// String symbolicName = (artifact.getGroupId() + "." + artifact.getArtifactId());
+// String dirName = symbolicName + "_" + version;
+
+ String dirName = artifactFile.getName().substring(0, artifactFile.getName().length() - 4);
+ File dir = new File(root, dirName);
// Exclude artifact if its file name is excluded
if (excludedFileNames.contains(dir.getName())) {
@@ -262,6 +281,7 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
fos.close();
copyFile(artifactFile, dir);
bundleSymbolicNames.add(symbolicName);
+ fileNames.add(dir.getName());
}
}
@@ -289,13 +309,18 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
write(mf, fos);
fos.close();
bundleSymbolicNames.add(symbolicName);
+ fileNames.add(dir.getName());
}
}
// Generate a PDE target
if (generateTargetPlatform) {
File target = new File(project.getBuild().getDirectory(), project.getArtifactId() + ".target");
+ log.info("Generating target definition: " + target);
FileOutputStream targetFile = new FileOutputStream(target);
+ if (!bundleSymbolicNames.contains("org.eclipse.osgi")) {
+ bundleSymbolicNames.add("org.eclipse.osgi");
+ }
writeTarget(new PrintStream(targetFile), bundleSymbolicNames, eclipseFeatures);
targetFile.close();
}
@@ -307,6 +332,23 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
writePluginXML(new PrintStream(pluginXMLFile));
pluginXMLFile.close();
}
+
+ if(generateConfig) {
+ File config = new File(root, "configuration");
+ config.mkdir();
+ File ini = new File(config, "config.ini");
+ log.info("Generating configuation: " + ini);
+ FileOutputStream fos = new FileOutputStream(ini);
+ PrintStream ps = new PrintStream(fos);
+ ps.print("osgi.bundles=");
+ for(String f: fileNames) {
+ ps.print(f);
+ ps.print("@:start,");
+ }
+ ps.println();
+ ps.println("eclipse.ignoreApp=true");
+ ps.close();
+ }
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
@@ -341,7 +383,11 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
ps.println(" <execEnv>J2SE-1.5</execEnv>");
ps.println(" </targetJRE>");
- ps.println(" <location useDefault=\"true\"/>");
+ if(useDefaultLocation) {
+ ps.println(" <location useDefault=\"true\"/>");
+ } else {
+ ps.println(" <location path=\"" + targetDirectory + "\"/>");
+ }
// ps.println("<content useAllPlugins=\"true\">");
ps.println(" <content>");
@@ -357,10 +403,12 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
}
}
ps.println(" </features>");
- ps.println(" <extraLocations>");
- // Not sure why the extra path needs to the plugins folder
- ps.println(" <location path=\"" + targetDirectory + "\"/>");
- ps.println(" </extraLocations>");
+ if (useDefaultLocation) {
+ ps.println(" <extraLocations>");
+ // Not sure why the extra path needs to the plugins folder
+ ps.println(" <location path=\"" + targetDirectory + "\"/>");
+ ps.println(" </extraLocations>");
+ }
ps.println(" </content>");
ps.println("</target>");