X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.repo%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Frepo%2Fmaven%2FImportMavenDependencies.java;h=5fe9491639772458e6509883913f9bcf24100e55;hb=74904a755b5b344238eafa798419b80c5e74f7ed;hp=8d5ff5ae251594fbfed194ac2b9c5923694172a4;hpb=d0b3401a83490920a40f114e71bf22149920b01b;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/ImportMavenDependencies.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/ImportMavenDependencies.java index 8d5ff5ae2..5fe949163 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/ImportMavenDependencies.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/ImportMavenDependencies.java @@ -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; @@ -20,7 +35,6 @@ import java.util.jar.Manifest; import javax.jcr.Binary; import javax.jcr.Node; import javax.jcr.NodeIterator; -import javax.jcr.PathNotFoundException; import javax.jcr.Property; import javax.jcr.RepositoryException; import javax.jcr.Session; @@ -35,8 +49,10 @@ import org.apache.commons.logging.LogFactory; import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; import org.argeo.slc.aether.AetherTemplate; -import org.argeo.slc.repo.RepoNames; -import org.argeo.slc.repo.RepoTypes; +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; import org.sonatype.aether.artifact.Artifact; @@ -55,10 +71,12 @@ public class ImportMavenDependencies implements Runnable { private Set excludedArtifacts = new HashSet(); private Session jcrSession; - private String artifactBasePath = "/slc/repo/artifacts"; - private String distributionsBasePath = "/slc/repo/distributions"; + private String artifactBasePath = RepoConstants.ARTIFACTS_BASE_PATH; + private String distributionsBasePath = RepoConstants.DISTRIBUTIONS_BASE_PATH; private String distributionName; + private ArtifactIndexer artifactIndexer = new ArtifactIndexer(); + public void run() { log.debug(jcrSession.getUserID()); Set artifacts = resolveDistribution(); @@ -138,12 +156,13 @@ public class ImportMavenDependencies implements Runnable { } try { - String parentPath = artifactBasePath + '/' + String parentPath = artifactBasePath + + (artifactBasePath.endsWith("/") ? "" : "/") + artifactParentPath(artifact); Node parentNode; if (!jcrSession.itemExists(parentPath)) { parentNode = JcrUtils.mkdirs(jcrSession, parentPath, - NodeType.NT_FOLDER, false); + NodeType.NT_FOLDER); } else { parentNode = jcrSession.getNode(parentPath); } @@ -154,8 +173,10 @@ public class ImportMavenDependencies implements Runnable { } else { fileNode = parentNode.getNode(file.getName()); } - processArtifact(fileNode, artifact); - if (fileNode.isNodeType(RepoTypes.SLC_JAR_FILE)) { + + if (artifactIndexer.support(fileNode.getPath())) + artifactIndexer.index(fileNode); + if (fileNode.isNodeType(SlcTypes.SLC_JAR_FILE)) { processOsgiBundle(fileNode); } jcrSession.save(); @@ -163,7 +184,7 @@ public class ImportMavenDependencies implements Runnable { if (!jcrSession .itemExists(bundleDistributionPath(fileNode)) && fileNode - .isNodeType(RepoTypes.SLC_BUNDLE_ARTIFACT)) + .isNodeType(SlcTypes.SLC_BUNDLE_ARTIFACT)) jcrSession.getWorkspace().clone( jcrSession.getWorkspace().getName(), fileNode.getPath(), @@ -197,10 +218,10 @@ public class ImportMavenDependencies implements Runnable { + '/' + distributionName + '/' - + fileNode.getProperty(RepoNames.SLC_SYMBOLIC_NAME) + + fileNode.getProperty(SlcNames.SLC_SYMBOLIC_NAME) .getString() + '_' - + fileNode.getProperty(RepoNames.SLC_BUNDLE_VERSION) + + fileNode.getProperty(SlcNames.SLC_BUNDLE_VERSION) .getString(); } catch (RepositoryException e) { throw new SlcException("Cannot create distribution path for " @@ -208,25 +229,6 @@ public class ImportMavenDependencies implements Runnable { } } - protected void processArtifact(Node fileNode, Artifact artifact) { - try { - fileNode.addMixin(RepoTypes.SLC_ARTIFACT); - fileNode.setProperty(RepoNames.SLC_ARTIFACT_ID, - artifact.getArtifactId()); - fileNode.setProperty(RepoNames.SLC_GROUP_ID, artifact.getGroupId()); - fileNode.setProperty(RepoNames.SLC_ARTIFACT_VERSION, - artifact.getVersion()); - fileNode.setProperty(RepoNames.SLC_ARTIFACT_EXTENSION, - artifact.getExtension()); - fileNode.setProperty(RepoNames.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 @@ -252,7 +254,7 @@ public class ImportMavenDependencies implements Runnable { Binary manifestBinary = null; InputStream manifestIn = null; try { - manifestBinary = fileNode.getProperty(RepoNames.SLC_MANIFEST) + manifestBinary = fileNode.getProperty(SlcNames.SLC_MANIFEST) .getBinary(); manifestIn = manifestBinary.getStream(); Manifest manifest = new Manifest(manifestIn); @@ -267,13 +269,13 @@ public class ImportMavenDependencies implements Runnable { return;// not an osgi bundle } - fileNode.addMixin(RepoTypes.SLC_BUNDLE_ARTIFACT); + fileNode.addMixin(SlcTypes.SLC_BUNDLE_ARTIFACT); // symbolic name String symbolicName = attrs.getValue(Constants.BUNDLE_SYMBOLICNAME); // make sure there is no directive symbolicName = symbolicName.split(";")[0]; - fileNode.setProperty(RepoNames.SLC_SYMBOLIC_NAME, symbolicName); + fileNode.setProperty(SlcNames.SLC_SYMBOLIC_NAME, symbolicName); // direct mapping addAttr(Constants.BUNDLE_SYMBOLICNAME, fileNode, attrs); @@ -295,7 +297,7 @@ public class ImportMavenDependencies implements Runnable { if (attrs.containsKey(new Name( Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT))) fileNode.setProperty( - RepoNames.SLC_ + SlcNames.SLC_ + Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, attrs.getValue( Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT) @@ -303,57 +305,58 @@ public class ImportMavenDependencies implements Runnable { // bundle classpath if (attrs.containsKey(new Name(Constants.BUNDLE_CLASSPATH))) - fileNode.setProperty(RepoNames.SLC_ - + Constants.BUNDLE_CLASSPATH, - attrs.getValue(Constants.BUNDLE_CLASSPATH).split(",")); + fileNode.setProperty( + SlcNames.SLC_ + Constants.BUNDLE_CLASSPATH, attrs + .getValue(Constants.BUNDLE_CLASSPATH) + .split(",")); // version Version version = new Version( attrs.getValue(Constants.BUNDLE_VERSION)); - fileNode.setProperty(RepoNames.SLC_BUNDLE_VERSION, + fileNode.setProperty(SlcNames.SLC_BUNDLE_VERSION, version.toString()); - cleanSubNodes(fileNode, RepoNames.SLC_ + Constants.BUNDLE_VERSION); - Node bundleVersionNode = fileNode.addNode(RepoNames.SLC_ - + Constants.BUNDLE_VERSION, RepoTypes.SLC_OSGI_VERSION); + cleanSubNodes(fileNode, SlcNames.SLC_ + Constants.BUNDLE_VERSION); + Node bundleVersionNode = fileNode.addNode(SlcNames.SLC_ + + Constants.BUNDLE_VERSION, SlcTypes.SLC_OSGI_VERSION); mapOsgiVersion(version, bundleVersionNode); // fragment - cleanSubNodes(fileNode, RepoNames.SLC_ + Constants.FRAGMENT_HOST); + cleanSubNodes(fileNode, SlcNames.SLC_ + Constants.FRAGMENT_HOST); if (attrs.containsKey(new Name(Constants.FRAGMENT_HOST))) { String fragmentHost = attrs.getValue(Constants.FRAGMENT_HOST); String[] tokens = fragmentHost.split(";"); - Node node = fileNode.addNode(RepoNames.SLC_ - + Constants.FRAGMENT_HOST, RepoTypes.SLC_FRAGMENT_HOST); - node.setProperty(RepoNames.SLC_SYMBOLIC_NAME, tokens[0]); + Node node = fileNode.addNode(SlcNames.SLC_ + + Constants.FRAGMENT_HOST, SlcTypes.SLC_FRAGMENT_HOST); + node.setProperty(SlcNames.SLC_SYMBOLIC_NAME, tokens[0]); for (int i = 1; i < tokens.length; i++) { if (tokens[i] .startsWith(Constants.BUNDLE_VERSION_ATTRIBUTE)) { - node.setProperty(RepoNames.SLC_BUNDLE_VERSION, + node.setProperty(SlcNames.SLC_BUNDLE_VERSION, attributeValue(tokens[i])); } } } // imported packages - cleanSubNodes(fileNode, RepoNames.SLC_ + Constants.IMPORT_PACKAGE); + cleanSubNodes(fileNode, SlcNames.SLC_ + Constants.IMPORT_PACKAGE); if (attrs.containsKey(new Name(Constants.IMPORT_PACKAGE))) { String importPackages = attrs .getValue(Constants.IMPORT_PACKAGE); List packages = parsePackages(importPackages); for (String pkg : packages) { String[] tokens = pkg.split(";"); - Node node = fileNode.addNode(RepoNames.SLC_ + Node node = fileNode.addNode(SlcNames.SLC_ + Constants.IMPORT_PACKAGE, - RepoTypes.SLC_IMPORTED_PACKAGE); - node.setProperty(RepoNames.SLC_NAME, tokens[0]); + SlcTypes.SLC_IMPORTED_PACKAGE); + node.setProperty(SlcNames.SLC_NAME, tokens[0]); for (int i = 1; i < tokens.length; i++) { if (tokens[i].startsWith(Constants.VERSION_ATTRIBUTE)) { - node.setProperty(RepoNames.SLC_VERSION, + node.setProperty(SlcNames.SLC_VERSION, attributeValue(tokens[i])); } else if (tokens[i] .startsWith(Constants.RESOLUTION_DIRECTIVE)) { node.setProperty( - RepoNames.SLC_OPTIONAL, + SlcNames.SLC_OPTIONAL, directiveValue(tokens[i]).equals( Constants.RESOLUTION_OPTIONAL)); } @@ -362,7 +365,7 @@ public class ImportMavenDependencies implements Runnable { } // dynamic import package - cleanSubNodes(fileNode, RepoNames.SLC_ + cleanSubNodes(fileNode, SlcNames.SLC_ + Constants.DYNAMICIMPORT_PACKAGE); if (attrs.containsKey(new Name(Constants.DYNAMICIMPORT_PACKAGE))) { String importPackages = attrs @@ -370,13 +373,13 @@ public class ImportMavenDependencies implements Runnable { List packages = parsePackages(importPackages); for (String pkg : packages) { String[] tokens = pkg.split(";"); - Node node = fileNode.addNode(RepoNames.SLC_ + Node node = fileNode.addNode(SlcNames.SLC_ + Constants.DYNAMICIMPORT_PACKAGE, - RepoTypes.SLC_DYNAMIC_IMPORTED_PACKAGE); - node.setProperty(RepoNames.SLC_NAME, tokens[0]); + SlcTypes.SLC_DYNAMIC_IMPORTED_PACKAGE); + node.setProperty(SlcNames.SLC_NAME, tokens[0]); for (int i = 1; i < tokens.length; i++) { if (tokens[i].startsWith(Constants.VERSION_ATTRIBUTE)) { - node.setProperty(RepoNames.SLC_VERSION, + node.setProperty(SlcNames.SLC_VERSION, attributeValue(tokens[i])); } } @@ -384,26 +387,26 @@ public class ImportMavenDependencies implements Runnable { } // exported packages - cleanSubNodes(fileNode, RepoNames.SLC_ + Constants.EXPORT_PACKAGE); + cleanSubNodes(fileNode, SlcNames.SLC_ + Constants.EXPORT_PACKAGE); if (attrs.containsKey(new Name(Constants.EXPORT_PACKAGE))) { String exportPackages = attrs .getValue(Constants.EXPORT_PACKAGE); List packages = parsePackages(exportPackages); for (String pkg : packages) { String[] tokens = pkg.split(";"); - Node node = fileNode.addNode(RepoNames.SLC_ + Node node = fileNode.addNode(SlcNames.SLC_ + Constants.EXPORT_PACKAGE, - RepoTypes.SLC_EXPORTED_PACKAGE); - node.setProperty(RepoNames.SLC_NAME, tokens[0]); + SlcTypes.SLC_EXPORTED_PACKAGE); + node.setProperty(SlcNames.SLC_NAME, tokens[0]); // TODO: are these cleans really necessary? - cleanSubNodes(node, RepoNames.SLC_USES); - cleanSubNodes(node, RepoNames.SLC_VERSION); + cleanSubNodes(node, SlcNames.SLC_USES); + cleanSubNodes(node, SlcNames.SLC_VERSION); for (int i = 1; i < tokens.length; i++) { if (tokens[i].startsWith(Constants.VERSION_ATTRIBUTE)) { String versionStr = attributeValue(tokens[i]); Node versionNode = node.addNode( - RepoNames.SLC_VERSION, - RepoTypes.SLC_OSGI_VERSION); + SlcNames.SLC_VERSION, + SlcTypes.SLC_OSGI_VERSION); mapOsgiVersion(new Version(versionStr), versionNode); } else if (tokens[i] .startsWith(Constants.USES_DIRECTIVE)) { @@ -412,10 +415,9 @@ public class ImportMavenDependencies implements Runnable { for (String usedPackage : usedPackages.split(",")) { // log.debug("usedPackage='" + usedPackage + // "'"); - Node usesNode = node.addNode( - RepoNames.SLC_USES, - RepoTypes.SLC_JAVA_PACKAGE); - usesNode.setProperty(RepoNames.SLC_NAME, + Node usesNode = node.addNode(SlcNames.SLC_USES, + SlcTypes.SLC_JAVA_PACKAGE); + usesNode.setProperty(SlcNames.SLC_NAME, usedPackage); } } @@ -424,25 +426,25 @@ public class ImportMavenDependencies implements Runnable { } // required bundle - cleanSubNodes(fileNode, RepoNames.SLC_ + Constants.REQUIRE_BUNDLE); + cleanSubNodes(fileNode, SlcNames.SLC_ + Constants.REQUIRE_BUNDLE); if (attrs.containsKey(new Name(Constants.REQUIRE_BUNDLE))) { String requireBundle = attrs.getValue(Constants.REQUIRE_BUNDLE); String[] bundles = requireBundle.split(","); for (String bundle : bundles) { String[] tokens = bundle.split(";"); - Node node = fileNode.addNode(RepoNames.SLC_ + Node node = fileNode.addNode(SlcNames.SLC_ + Constants.REQUIRE_BUNDLE, - RepoTypes.SLC_REQUIRED_BUNDLE); - node.setProperty(RepoNames.SLC_SYMBOLIC_NAME, tokens[0]); + SlcTypes.SLC_REQUIRED_BUNDLE); + node.setProperty(SlcNames.SLC_SYMBOLIC_NAME, tokens[0]); for (int i = 1; i < tokens.length; i++) { if (tokens[i] .startsWith(Constants.BUNDLE_VERSION_ATTRIBUTE)) { - node.setProperty(RepoNames.SLC_BUNDLE_VERSION, + node.setProperty(SlcNames.SLC_BUNDLE_VERSION, attributeValue(tokens[i])); } else if (tokens[i] .startsWith(Constants.RESOLUTION_DIRECTIVE)) { node.setProperty( - RepoNames.SLC_OPTIONAL, + SlcNames.SLC_OPTIONAL, directiveValue(tokens[i]).equals( Constants.RESOLUTION_OPTIONAL)); } @@ -490,7 +492,7 @@ public class ImportMavenDependencies implements Runnable { throws RepositoryException { if (attrs.containsKey(key)) { String value = attrs.getValue(key); - node.setProperty(RepoNames.SLC_ + key, value); + node.setProperty(SlcNames.SLC_ + key, value); } } @@ -505,12 +507,12 @@ public class ImportMavenDependencies implements Runnable { protected void mapOsgiVersion(Version version, Node versionNode) throws RepositoryException { - versionNode.setProperty(RepoNames.SLC_AS_STRING, version.toString()); - versionNode.setProperty(RepoNames.SLC_MAJOR, version.getMajor()); - versionNode.setProperty(RepoNames.SLC_MINOR, version.getMinor()); - versionNode.setProperty(RepoNames.SLC_MICRO, version.getMicro()); + versionNode.setProperty(SlcNames.SLC_AS_STRING, version.toString()); + versionNode.setProperty(SlcNames.SLC_MAJOR, version.getMajor()); + versionNode.setProperty(SlcNames.SLC_MINOR, version.getMinor()); + versionNode.setProperty(SlcNames.SLC_MICRO, version.getMicro()); if (!version.getQualifier().equals("")) - versionNode.setProperty(RepoNames.SLC_QUALIFIER, + versionNode.setProperty(SlcNames.SLC_QUALIFIER, version.getQualifier()); } @@ -558,8 +560,8 @@ public class ImportMavenDependencies implements Runnable { bi = new ByteArrayInputStream(bo.toByteArray()); manifestBinary = jcrSession.getValueFactory().createBinary( bi); - fileNode.addMixin(RepoTypes.SLC_JAR_FILE); - fileNode.setProperty(RepoNames.SLC_MANIFEST, manifestBinary); + fileNode.addMixin(SlcTypes.SLC_JAR_FILE); + fileNode.setProperty(SlcNames.SLC_MANIFEST, manifestBinary); Attributes attrs = manifest.getMainAttributes(); addAttr(Attributes.Name.MANIFEST_VERSION, fileNode, attrs); addAttr(Attributes.Name.SIGNATURE_VERSION, fileNode, attrs);