]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/NormalizeWorkspace.java
Migrate SLC modules
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / commands / NormalizeWorkspace.java
index a9abb5fe82bca38db6d58ead5dd45b5ce6e287e7..6591a56a72d1557e186066a7639a606f1835bb09 100644 (file)
@@ -37,6 +37,7 @@ import org.argeo.slc.client.ui.dist.DistPlugin;
 import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.repo.ArtifactIndexer;
 import org.argeo.slc.repo.JarFileIndexer;
+import org.argeo.slc.repo.ModularDistributionIndexer;
 import org.argeo.slc.repo.PdeSourcesIndexer;
 import org.argeo.slc.repo.RepoConstants;
 import org.argeo.slc.repo.RepoUtils;
@@ -60,35 +61,37 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
        private final static Log log = LogFactory.getLog(NormalizeWorkspace.class);
 
        public final static String ID = DistPlugin.ID + ".normalizeWorkspace";
+       public final static ImageDescriptor DEFAULT_ICON = DistPlugin
+                       .getImageDescriptor("icons/normalize.gif");
 
        public final static String PARAM_WORKSPACE_NAME = "workspaceName";
        public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
-       public final static ImageDescriptor DEFAULT_ICON = DistPlugin
-                       .getImageDescriptor("icons/normalize.gif");
 
        private String artifactBasePath = RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH;
 
-       private ArtifactIndexer artifactIndexer = new ArtifactIndexer();
-       private JarFileIndexer jarFileIndexer = new JarFileIndexer();
-       private PdeSourcesIndexer pdeSourceIndexer = new PdeSourcesIndexer(
-                       artifactIndexer, jarFileIndexer);
-
        // DEPENDENCY INJECTION
        private RepositoryFactory repositoryFactory;
        private Keyring keyring;
        private Repository repository;
 
-       public Object execute(ExecutionEvent event) throws ExecutionException {
+       // Relevant default node indexers
+       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 {
                String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
                String wkspName = event.getParameter(PARAM_WORKSPACE_NAME);
 
                Session currSession = null;
                NormalizeJob job;
                try {
-                       String msg = "Your are about to normalize workspace: " + wkspName
+                       String msg = "Your are about to normalize workspace: "
+                                       + wkspName
                                        + ".\nThis will index OSGi bundles and Maven artifacts, "
-                                       + "it will also generate pdeSources if needed.\n"
+                                       + "it will also convert Maven sources to PDE Sources if needed.\n"
                                        + "Note that no information will be overwritten: "
                                        + "all existing information are kept."
                                        + "\n\n Do you really want to proceed ?";
@@ -126,10 +129,9 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
 
                @Override
                protected IStatus run(IProgressMonitor progressMonitor) {
-
                        try {
                                ArgeoMonitor monitor = new EclipseArgeoMonitor(progressMonitor);
-                               // normalize artifacts
+                               // Normalize artifacts
                                Query countQuery = session
                                                .getWorkspace()
                                                .getQueryManager()
@@ -141,8 +143,14 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                                                + session.getWorkspace().getName(),
                                                expectedCount.intValue());
                                NormalizingTraverser tiv = new NormalizingTraverser(monitor);
-                               session.getNode(artifactBasePath).accept(tiv);
+                               Node artifactBaseNode = session.getNode(artifactBasePath);
+                               artifactBaseNode.accept(tiv);
                        } catch (Exception e) {
+                               log.error("Error normalizing workspace "
+                                               + session.getWorkspace().getName() + ": "
+                                               + e.getMessage());
+                               if (log.isErrorEnabled())
+                                       e.printStackTrace();
                                return new Status(IStatus.ERROR, DistPlugin.ID,
                                                "Cannot normalize distribution "
                                                                + session.getWorkspace().getName(), e);
@@ -181,14 +189,30 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                                        if (jarFileIndexer.support(node.getPath()))
                                                if (artifactIndexer.support(node.getPath())) {
                                                        monitor.subTask(node.getName());
-                                                       artifactIndexer.index(node);
+                                                       modularDistributionIndexer.index(node);
                                                        jarFileIndexer.index(node);
-                                                       node.getSession().save();
+                                                       artifactIndexer.index(node);
+                                                       if (node.getSession().hasPendingChanges()) {
+                                                               node.getSession().save();
+                                                               if (log.isDebugEnabled())
+                                                                       log.debug("Processed jar artifact "
+                                                                                       + node.getPath());
+                                                       }
                                                        monitor.worked(1);
-                                                       if (log.isDebugEnabled())
-                                                               log.debug("Processed artifact "
-                                                                               + node.getPath());
                                                }
+                               } else if (node.getName().endsWith(".pom")) {
+                                       // Removed: we do not support binaries concept anymore.
+                                       // if (distBundleIndexer.support(node.getPath()))
+                                       // distBundleIndexer.index(node);
+                                       if (artifactIndexer.support(node.getPath()))
+                                               artifactIndexer.index(node);
+                                       if (node.getSession().hasPendingChanges()) {
+                                               node.getSession().save();
+                                               if (log.isDebugEnabled())
+                                                       log.debug("Processed pom artifact "
+                                                                       + node.getPath());
+                                       }
+                                       monitor.worked(1);
                                } else {
                                        monitor.worked(1);
                                }
@@ -203,7 +227,6 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                @Override
                protected void leaving(Node node, int level) throws RepositoryException {
                }
-
        }
 
        /* DEPENDENCY INJECTION */