tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r719440 - in /tuscany/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin: BundleUtil.java ModuleBundlesBuildMojo.java
Date Fri, 21 Nov 2008 01:11:08 GMT
Author: rfeng
Date: Thu Nov 20 17:11:07 2008
New Revision: 719440

URL: http://svn.apache.org/viewvc?rev=719440&view=rev
Log:
Fix the issue with duplicate packages for 3rd party jars
Add the capability to generate an equinox configuration to launch and validate the bundles

Modified:
    tuscany/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
    tuscany/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java

Modified: tuscany/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java?rev=719440&r1=719439&r2=719440&view=diff
==============================================================================
--- tuscany/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
(original)
+++ tuscany/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/BundleUtil.java
Thu Nov 20 17:11:07 2008
@@ -38,6 +38,7 @@
 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 @@
  * @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 @@
             // 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 @@
 
                 // 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();

Modified: tuscany/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java?rev=719440&r1=719439&r2=719440&view=diff
==============================================================================
--- tuscany/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java
(original)
+++ tuscany/java/sca/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/ModuleBundlesBuildMojo.java
Thu Nov 20 17:11:07 2008
@@ -96,6 +96,12 @@
      * @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 @@
      *  @parameter
      */
     private boolean generatePlugin;
+    
+    /**
+     * Generate a configuration/config.ini for equinox
+     * @parameter
+     */
+    private boolean generateConfig;
 
     /**
      * @parameter
@@ -149,6 +161,7 @@
 
             // 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 @@
                     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 @@
 
                 } 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 @@
                     fos.close();
                     copyFile(artifactFile, dir);
                     bundleSymbolicNames.add(symbolicName);
+                    fileNames.add(dir.getName());
                 }
             }
 
@@ -289,13 +309,18 @@
                     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 @@
                 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 @@
         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 @@
             }
         }
         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>");



Mime
View raw message