Fix some glitches in the normalization
authorBruno Sinou <bsinou@argeo.org>
Tue, 6 Jan 2015 13:22:39 +0000 (13:22 +0000)
committerBruno Sinou <bsinou@argeo.org>
Tue, 6 Jan 2015 13:22:39 +0000 (13:22 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@7626 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/NormalizeWorkspace.java
runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/ModularDistributionFactory.java
runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ProcessDistribution.java

index 7212756ce1f34b8319f182e26e7ea90a05effe3e..6591a56a72d1557e186066a7639a606f1835bb09 100644 (file)
@@ -75,10 +75,10 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
        private Repository repository;
 
        // Relevant default node indexers
-       // WARNING Order call is important.
-       private ModularDistributionIndexer distBundleIndexer = new ModularDistributionIndexer();
-       private JarFileIndexer jarFileIndexer = new JarFileIndexer();
        private PdeSourcesIndexer pdeSourceIndexer = new PdeSourcesIndexer();
+       // WARNING Order is important: must be called in the following order.
+       private ModularDistributionIndexer modularDistributionIndexer = new ModularDistributionIndexer();
+       private JarFileIndexer jarFileIndexer = new JarFileIndexer();
        private ArtifactIndexer artifactIndexer = new ArtifactIndexer();
 
        public Object execute(ExecutionEvent event) throws ExecutionException {
@@ -189,7 +189,7 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                                        if (jarFileIndexer.support(node.getPath()))
                                                if (artifactIndexer.support(node.getPath())) {
                                                        monitor.subTask(node.getName());
-                                                       distBundleIndexer.index(node);
+                                                       modularDistributionIndexer.index(node);
                                                        jarFileIndexer.index(node);
                                                        artifactIndexer.index(node);
                                                        if (node.getSession().hasPendingChanges()) {
index c4cc89a918badede5bdeacb0c4ba92eeaa48935a..a2c075e981ab16411021accbd99844ac4094aa08 100644 (file)
@@ -15,22 +15,20 @@ import java.util.jar.Manifest;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.nodetype.NodeType;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
+import org.argeo.jcr.JcrUtils;
 import org.argeo.slc.CategorizedNameVersion;
 import org.argeo.slc.NameVersion;
 import org.argeo.slc.SlcException;
-import org.argeo.slc.jcr.SlcNames;
-import org.argeo.slc.jcr.SlcTypes;
 import org.osgi.framework.Constants;
 import org.sonatype.aether.artifact.Artifact;
 import org.sonatype.aether.util.artifact.DefaultArtifact;
 
 /**
  * Creates a jar bundle from an ArgeoOsgiDistribution. This jar is then
- * persisted and indexed in a java repository.
+ * persisted and indexed in a java repository using the OSGI Factory.
  * 
  * It does the following <list><li>Creates a Manifest</li><li>Creates files
  * indexes (csv, feature.xml ...)</li><li>Populate the corresponding jar</li><li>
@@ -40,6 +38,7 @@ import org.sonatype.aether.util.artifact.DefaultArtifact;
  */
 public class ModularDistributionFactory implements Runnable {
 
+       private OsgiFactory osgiFactory;
        private Session javaSession;
        private ArgeoOsgiDistribution osgiDistribution;
        private String modularDistributionSeparator = ",";
@@ -48,24 +47,22 @@ public class ModularDistributionFactory implements Runnable {
 
        // Constants
        private final static String CSV_FILE_NAME = "modularDistribution.csv";
-       private final static String FEATURE_FILE_NAME = "feature.xml";
-       public static int BUFFER_SIZE = 10240;
+       // private final static String FEATURE_FILE_NAME = "feature.xml";
+       // private static int BUFFER_SIZE = 10240;
 
        /** Convenience constructor with minimal configuration */
-       public ModularDistributionFactory(Session javaSession,
+       public ModularDistributionFactory(OsgiFactory osgiFactory,
                        ArgeoOsgiDistribution osgiDistribution) {
-               this.javaSession = javaSession;
+               this.osgiFactory = osgiFactory;
                this.osgiDistribution = osgiDistribution;
        }
 
        @Override
        public void run() {
-               internalCreateDistribution();
-       }
-
-       private void internalCreateDistribution() {
                byte[] distFile = null;
                try {
+                       javaSession = osgiFactory.openJavaSession();
+
                        if (artifactType == "jar")
                                distFile = generateJarFile();
                        else if (artifactType == "pom")
@@ -86,14 +83,17 @@ public class ModularDistributionFactory implements Runnable {
                                        distFile);
 
                        // index
-                       indexDistribution(distNode);
+                       osgiFactory.indexNode(distNode);
 
                        // Really ?
                        javaSession.save();
+
                } catch (RepositoryException e) {
                        throw new SlcException(
                                        "JCR error while persisting modular distribution in JCR "
                                                        + osgiDistribution.toString(), e);
+               } finally {
+                       JcrUtils.logoutQuietly(javaSession);
                }
        }
 
@@ -117,24 +117,25 @@ public class ModularDistributionFactory implements Runnable {
                }
        }
 
-       private void indexDistribution(Node distNode) throws RepositoryException {
-               distNode.addMixin(SlcTypes.SLC_MODULAR_DISTRIBUTION);
-               distNode.addMixin(SlcTypes.SLC_CATEGORIZED_NAME_VERSION);
-               distNode.setProperty(SlcNames.SLC_CATEGORY,
-                               osgiDistribution.getCategory());
-               distNode.setProperty(SlcNames.SLC_NAME, osgiDistribution.getName());
-               distNode.setProperty(SlcNames.SLC_VERSION,
-                               osgiDistribution.getVersion());
-
-               if (distNode.hasNode(SlcNames.SLC_MODULES))
-                       distNode.getNode(SlcNames.SLC_MODULES).remove();
-               Node modules = distNode.addNode(SlcNames.SLC_MODULES,
-                               NodeType.NT_UNSTRUCTURED);
-
-               for (Iterator<? extends NameVersion> it = osgiDistribution
-                               .nameVersions(); it.hasNext();)
-                       addModule(modules, it.next());
-       }
+       // private void indexDistribution(Node distNode) throws RepositoryException
+       // {
+       // distNode.addMixin(SlcTypes.SLC_MODULAR_DISTRIBUTION);
+       // distNode.addMixin(SlcTypes.SLC_CATEGORIZED_NAME_VERSION);
+       // distNode.setProperty(SlcNames.SLC_CATEGORY,
+       // osgiDistribution.getCategory());
+       // distNode.setProperty(SlcNames.SLC_NAME, osgiDistribution.getName());
+       // distNode.setProperty(SlcNames.SLC_VERSION,
+       // osgiDistribution.getVersion());
+       //
+       // if (distNode.hasNode(SlcNames.SLC_MODULES))
+       // distNode.getNode(SlcNames.SLC_MODULES).remove();
+       // Node modules = distNode.addNode(SlcNames.SLC_MODULES,
+       // NodeType.NT_UNSTRUCTURED);
+       //
+       // for (Iterator<? extends NameVersion> it = osgiDistribution
+       // .nameVersions(); it.hasNext();)
+       // addModule(modules, it.next());
+       // }
 
        private Manifest createManifest() {
                Manifest manifest = new Manifest();
@@ -191,6 +192,7 @@ public class ModularDistributionFactory implements Runnable {
                }
        }
 
+       @SuppressWarnings("unused")
        private byte[] createFeatureDescriptor() {
                // Directly retrieved from Argeo maven plugin
                // Does not work due to the lack of org.codehaus.plexus/plexus-archiver
@@ -464,22 +466,22 @@ public class ModularDistributionFactory implements Runnable {
        }
 
        // Helpers
-       private Node addModule(Node modules, NameVersion nameVersion)
-                       throws RepositoryException {
-               CategorizedNameVersion cnv = (CategorizedNameVersion) nameVersion;
-               Node moduleCoord = null;
-               // TODO solve the same name issue
-               // if (modules.hasNode(cnv.getName()))
-               // moduleCoord = modules.getNode(cnv.getName());
-               // else {
-               moduleCoord = modules.addNode(cnv.getName(),
-                               SlcTypes.SLC_MODULE_COORDINATES);
-               moduleCoord.setProperty(SlcNames.SLC_CATEGORY, cnv.getCategory());
-               moduleCoord.setProperty(SlcNames.SLC_NAME, cnv.getName());
-               moduleCoord.setProperty(SlcNames.SLC_VERSION, cnv.getVersion());
-               // }
-               return moduleCoord;
-       }
+       // private Node addModule(Node modules, NameVersion nameVersion)
+       // throws RepositoryException {
+       // CategorizedNameVersion cnv = (CategorizedNameVersion) nameVersion;
+       // Node moduleCoord = null;
+       // // TODO solve the same name issue
+       // // if (modules.hasNode(cnv.getName()))
+       // // moduleCoord = modules.getNode(cnv.getName());
+       // // else {
+       // moduleCoord = modules.addNode(cnv.getName(),
+       // SlcTypes.SLC_MODULE_COORDINATES);
+       // moduleCoord.setProperty(SlcNames.SLC_CATEGORY, cnv.getCategory());
+       // moduleCoord.setProperty(SlcNames.SLC_NAME, cnv.getName());
+       // moduleCoord.setProperty(SlcNames.SLC_VERSION, cnv.getVersion());
+       // // }
+       // return moduleCoord;
+       // }
 
        private void addToJar(byte[] content, String name, JarOutputStream target)
                        throws IOException {
index 80401d73fd06c57927c05e950feb8cb59a627d5f..bdb81ae0b57454ae1ceac883f14ac36ddb4a87c2 100644 (file)
@@ -29,13 +29,12 @@ public class ProcessDistribution implements Runnable {
                Session javaSession = null;
                try {
                        javaSession = osgiFactory.openJavaSession();
-
                        for (Iterator<? extends NameVersion> it = osgiDistribution
                                        .nameVersions(); it.hasNext();)
                                processNameVersion(javaSession, it.next());
 
                        ModularDistributionFactory mdf = new ModularDistributionFactory(
-                                       javaSession, osgiDistribution);
+                                       osgiFactory, osgiDistribution);
                        mdf.run();
 
                        // TODO why is the created distribution not automatically indexed?