]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/ImportMavenDependencies.java
Update headers
[gpl/argeo-slc.git] / runtime / org.argeo.slc.repo / src / main / java / org / argeo / slc / repo / maven / ImportMavenDependencies.java
index ed06e502381efca41c2952edd96444edb6f95c55..5fe9491639772458e6509883913f9bcf24100e55 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * 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.repo.maven;
 
 import java.io.ByteArrayInputStream;
@@ -36,6 +51,7 @@ import org.argeo.slc.SlcException;
 import org.argeo.slc.aether.AetherTemplate;
 import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.jcr.SlcTypes;
+import org.argeo.slc.repo.ArtifactIndexer;
 import org.argeo.slc.repo.RepoConstants;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Version;
@@ -56,9 +72,11 @@ public class ImportMavenDependencies implements Runnable {
 
        private Session jcrSession;
        private String artifactBasePath = RepoConstants.ARTIFACTS_BASE_PATH;
-       private String distributionsBasePath = "/slc/repo/distributions";
+       private String distributionsBasePath = RepoConstants.DISTRIBUTIONS_BASE_PATH;
        private String distributionName;
 
+       private ArtifactIndexer artifactIndexer = new ArtifactIndexer();
+
        public void run() {
                log.debug(jcrSession.getUserID());
                Set<Artifact> artifacts = resolveDistribution();
@@ -138,7 +156,8 @@ public class ImportMavenDependencies implements Runnable {
                                }
 
                                try {
-                                       String parentPath = artifactBasePath + '/'
+                                       String parentPath = artifactBasePath
+                                                       + (artifactBasePath.endsWith("/") ? "" : "/")
                                                        + artifactParentPath(artifact);
                                        Node parentNode;
                                        if (!jcrSession.itemExists(parentPath)) {
@@ -154,7 +173,9 @@ public class ImportMavenDependencies implements Runnable {
                                        } else {
                                                fileNode = parentNode.getNode(file.getName());
                                        }
-                                       processArtifact(fileNode, artifact);
+
+                                       if (artifactIndexer.support(fileNode.getPath()))
+                                               artifactIndexer.index(fileNode);
                                        if (fileNode.isNodeType(SlcTypes.SLC_JAR_FILE)) {
                                                processOsgiBundle(fileNode);
                                        }
@@ -208,25 +229,6 @@ public class ImportMavenDependencies implements Runnable {
                }
        }
 
-       protected void processArtifact(Node fileNode, Artifact artifact) {
-               try {
-                       fileNode.addMixin(SlcTypes.SLC_ARTIFACT);
-                       fileNode.setProperty(SlcNames.SLC_ARTIFACT_ID,
-                                       artifact.getArtifactId());
-                       fileNode.setProperty(SlcNames.SLC_GROUP_ID, artifact.getGroupId());
-                       fileNode.setProperty(SlcNames.SLC_ARTIFACT_VERSION,
-                                       artifact.getVersion());
-                       fileNode.setProperty(SlcNames.SLC_ARTIFACT_EXTENSION,
-                                       artifact.getExtension());
-                       fileNode.setProperty(SlcNames.SLC_ARTIFACT_CLASSIFIER,
-                                       artifact.getClassifier());
-               } catch (RepositoryException e) {
-                       throw new SlcException("Cannot process artifact " + artifact
-                                       + " on node " + fileNode, e);
-               }
-
-       }
-
        protected File artifactToFile(Artifact artifact) {
                return new File(System.getProperty("user.home")
                                + File.separator