]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/commands/NormalizeWorkspace.java
Remove old license headers
[gpl/argeo-slc.git] / org.argeo.slc.client.ui.dist / src / org / argeo / slc / client / ui / dist / commands / NormalizeWorkspace.java
index 6591a56a72d1557e186066a7639a606f1835bb09..e5ed4d4e109aca40be811f0c11340e4f55eafe8a 100644 (file)
@@ -1,18 +1,3 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed 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.argeo.slc.client.ui.dist.commands;
 
 import javax.jcr.Credentials;
@@ -29,19 +14,19 @@ import javax.jcr.util.TraversingItemVisitor;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoMonitor;
-import org.argeo.eclipse.ui.EclipseArgeoMonitor;
+import org.argeo.api.security.Keyring;
+import org.argeo.eclipse.ui.EclipseJcrMonitor;
+import org.argeo.jcr.JcrMonitor;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.slc.SlcException;
+import org.argeo.slc.SlcNames;
 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;
-import org.argeo.util.security.Keyring;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
@@ -60,9 +45,8 @@ import org.eclipse.jface.resource.ImageDescriptor;
 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 ID = DistPlugin.PLUGIN_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";
@@ -88,25 +72,20 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                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 convert Maven sources to PDE Sources if needed.\n"
-                                       + "Note that no information will be overwritten: "
-                                       + "all existing information are kept."
+                                       + "Note that no information will be overwritten: " + "all existing information are kept."
                                        + "\n\n Do you really want to proceed ?";
 
-                       if (!MessageDialog.openConfirm(DistPlugin.getDefault()
-                                       .getWorkbench().getDisplay().getActiveShell(),
+                       if (!MessageDialog.openConfirm(DistPlugin.getDefault().getWorkbench().getDisplay().getActiveShell(),
                                        "Confirm workspace normalization", msg))
                                return null;
 
                        currSession = repository.login();
                        Node repoNode = currSession.getNode(targetRepoPath);
-                       Repository repository = RepoUtils.getRepository(repositoryFactory,
-                                       keyring, repoNode);
-                       Credentials credentials = RepoUtils.getRepositoryCredentials(
-                                       keyring, repoNode);
+                       Repository repository = RepoUtils.getRepository(repositoryFactory, keyring, repoNode);
+                       Credentials credentials = RepoUtils.getRepositoryCredentials(keyring, repoNode);
 
                        job = new NormalizeJob(repository.login(credentials, wkspName));
                        job.setUser(true);
@@ -130,30 +109,23 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                @Override
                protected IStatus run(IProgressMonitor progressMonitor) {
                        try {
-                               ArgeoMonitor monitor = new EclipseArgeoMonitor(progressMonitor);
+                               JcrMonitor monitor = new EclipseJcrMonitor(progressMonitor);
                                // Normalize artifacts
-                               Query countQuery = session
-                                               .getWorkspace()
-                                               .getQueryManager()
-                                               .createQuery("select file from [nt:file] as file",
-                                                               Query.JCR_SQL2);
+                               Query countQuery = session.getWorkspace().getQueryManager()
+                                               .createQuery("select file from [nt:file] as file", Query.JCR_SQL2);
                                QueryResult result = countQuery.execute();
                                Long expectedCount = result.getNodes().getSize();
-                               monitor.beginTask("Normalize artifacts of "
-                                               + session.getWorkspace().getName(),
+                               monitor.beginTask("Normalize artifacts of " + session.getWorkspace().getName(),
                                                expectedCount.intValue());
                                NormalizingTraverser tiv = new NormalizingTraverser(monitor);
                                Node artifactBaseNode = session.getNode(artifactBasePath);
                                artifactBaseNode.accept(tiv);
                        } catch (Exception e) {
-                               log.error("Error normalizing workspace "
-                                               + session.getWorkspace().getName() + ": "
-                                               + e.getMessage());
+                               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);
+                               return new Status(IStatus.ERROR, DistPlugin.PLUGIN_ID,
+                                               "Cannot normalize distribution " + session.getWorkspace().getName(), e);
                        } finally {
                                JcrUtils.logoutQuietly(session);
                        }
@@ -162,21 +134,22 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
        }
 
        private class NormalizingTraverser extends TraversingItemVisitor {
-               ArgeoMonitor monitor;
+               JcrMonitor monitor;
 
-               public NormalizingTraverser(ArgeoMonitor monitor) {
+               public NormalizingTraverser(JcrMonitor monitor) {
                        super();
                        this.monitor = monitor;
                }
 
                @Override
-               protected void entering(Property property, int level)
-                               throws RepositoryException {
+               protected void entering(Property property, int level) throws RepositoryException {
                }
 
                @Override
-               protected void entering(Node node, int level)
-                               throws RepositoryException {
+               protected void entering(Node node, int level) throws RepositoryException {
+                       if (node.getPath().startsWith(RepoConstants.DIST_DOWNLOAD_BASEPATH))
+                               return;
+
                        if (node.isNodeType(NodeType.NT_FILE)) {
                                if (node.getName().endsWith("-sources.jar")) {
                                        monitor.subTask(node.getName());
@@ -185,6 +158,9 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                                        monitor.worked(1);
                                        if (log.isDebugEnabled())
                                                log.debug("Processed source artifact " + node.getPath());
+                               } else if (node.getName().endsWith("-javadoc.jar")) {
+                                       if (log.isDebugEnabled())
+                                               log.debug("Skip indexing of Javadoc jar " + node.getPath());
                                } else if (node.getName().endsWith(".jar")) {
                                        if (jarFileIndexer.support(node.getPath()))
                                                if (artifactIndexer.support(node.getPath())) {
@@ -195,8 +171,7 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                                                        if (node.getSession().hasPendingChanges()) {
                                                                node.getSession().save();
                                                                if (log.isDebugEnabled())
-                                                                       log.debug("Processed jar artifact "
-                                                                                       + node.getPath());
+                                                                       log.debug("Processed jar artifact " + node.getPath());
                                                        }
                                                        monitor.worked(1);
                                                }
@@ -209,8 +184,7 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                                        if (node.getSession().hasPendingChanges()) {
                                                node.getSession().save();
                                                if (log.isDebugEnabled())
-                                                       log.debug("Processed pom artifact "
-                                                                       + node.getPath());
+                                                       log.debug("Processed pom artifact " + node.getPath());
                                        }
                                        monitor.worked(1);
                                } else {
@@ -220,8 +194,7 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                }
 
                @Override
-               protected void leaving(Property property, int level)
-                               throws RepositoryException {
+               protected void leaving(Property property, int level) throws RepositoryException {
                }
 
                @Override