X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.repo%2Fsrc%2Forg%2Fargeo%2Fslc%2Frepo%2FModularDistributionIndexer.java;h=7d854a1c5d23c3e7b0dbb744109b49c6d528c154;hb=82ce036ceb9e151dfc8ba46b6568929a22245099;hp=594168d511ea4042dc2c0c18dd8bfe03108e3a45;hpb=f59056d0b805cb91f524671a28b8780338509ba4;p=gpl%2Fargeo-slc.git
diff --git a/org.argeo.slc.repo/src/org/argeo/slc/repo/ModularDistributionIndexer.java b/org.argeo.slc.repo/src/org/argeo/slc/repo/ModularDistributionIndexer.java
index 594168d51..7d854a1c5 100644
--- a/org.argeo.slc.repo/src/org/argeo/slc/repo/ModularDistributionIndexer.java
+++ b/org.argeo.slc.repo/src/org/argeo/slc/repo/ModularDistributionIndexer.java
@@ -18,16 +18,16 @@ import javax.jcr.nodetype.NodeType;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.CategorizedNameVersion;
-import org.argeo.slc.DefaultNameVersion;
+import org.argeo.api.cms.CmsLog;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.CategoryNameVersion;
+import org.argeo.slc.DefaultCategoryNameVersion;
import org.argeo.slc.NameVersion;
import org.argeo.slc.SlcException;
-import org.argeo.slc.aether.AetherUtils;
-import org.argeo.slc.build.Distribution;
import org.argeo.slc.SlcNames;
import org.argeo.slc.SlcTypes;
+import org.argeo.slc.build.Distribution;
+import org.argeo.slc.repo.maven.AetherUtils;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.osgi.framework.Constants;
@@ -35,46 +35,29 @@ import org.osgi.framework.Constants;
/**
* Create or update JCR meta-data for an SLC Modular Distribution
*
- * Currently, following types are managed: * .jar: dependency
- * artifacts with csv index @Deprecated : .pom: artifact (binaries)
- * that indexes a group, the .pom file contains a tag "dependencyManagement"
- * that list all modules
+ * Currently, following types are managed:
+ * * .jar: dependency artifacts with csv index
+ * @Deprecated : .pom: artifact (binaries) that indexes a group, the .pom
+ * file contains a tag "dependencyManagement" that list all modules
*/
public class ModularDistributionIndexer implements NodeIndexer, SlcNames {
- private final static Log log = LogFactory
- .getLog(ModularDistributionIndexer.class);
+ private final static CmsLog log = CmsLog.getLog(ModularDistributionIndexer.class);
// Constants for csv indexing
private final static String INDEX_FILE_NAME = "modularDistribution.csv";
private String separator = ",";
- // TODO remove this: binaries have been replaced by modular distribution
- // // Artifact indexing
- // private final static List BINARIES_ARTIFACTS_NAME;
- // static {
- // List tmpList = new ArrayList();
- // tmpList.add(RepoConstants.BINARIES_ARTIFACT_ID);
- // // tmpList.add(RepoConstants.SOURCES_ARTIFACT_ID);
- // // tmpList.add(RepoConstants.SDK_ARTIFACT_ID);
- // BINARIES_ARTIFACTS_NAME = Collections.unmodifiableList(tmpList);
- // }
-
private Manifest manifest;
public Boolean support(String path) {
if (FilenameUtils.getExtension(path).equals("jar"))
return true;
- // if (FilenameUtils.getExtension(path).equals("pom")
- // && BINARIES_ARTIFACTS_NAME.contains(FilenameUtils.getName(path)
- // .split("-")[0]))
- // return true;
return false;
}
public void index(Node fileNode) {
Binary fileBinary = null;
try {
-
String fileNodePath = fileNode.getPath();
if (!support(fileNodePath))
return;
@@ -88,12 +71,9 @@ public class ModularDistributionIndexer implements NodeIndexer, SlcNames {
MyModularDistribution currDist = null;
if (FilenameUtils.getExtension(fileNode.getPath()).equals("jar"))
currDist = listModulesFromCsvIndex(fileNode, fileBinary);
- // else if (FilenameUtils.getExtension(fileNode.getPath()).equals(
- // "pom"))
- // currDist = listModulesFromPomIndex(fileNode, fileBinary);
- if (fileNode.isNodeType(SlcTypes.SLC_MODULAR_DISTRIBUTION)
- || currDist == null || !currDist.nameVersions().hasNext())
+ if (fileNode.isNodeType(SlcTypes.SLC_MODULAR_DISTRIBUTION) || currDist == null
+ || !currDist.nameVersions().hasNext())
return; // already indexed or no modules found
else {
fileNode.addMixin(SlcTypes.SLC_MODULAR_DISTRIBUTION);
@@ -108,13 +88,13 @@ public class ModularDistributionIndexer implements NodeIndexer, SlcNames {
if (log.isTraceEnabled())
log.trace("Indexed " + fileNode + " as modular distribution");
} catch (Exception e) {
- throw new SlcException("Cannot list dependencies from " + fileNode,
- e);
+ throw new SlcException("Cannot list dependencies from " + fileNode, e);
+ } finally {
+ JcrUtils.closeQuietly(fileBinary);
}
}
- private void indexDistribution(ArgeoOsgiDistribution osgiDist, Node distNode)
- throws RepositoryException {
+ private void indexDistribution(ArgeoOsgiDistribution osgiDist, Node distNode) throws RepositoryException {
distNode.addMixin(SlcTypes.SLC_MODULAR_DISTRIBUTION);
distNode.addMixin(SlcTypes.SLC_CATEGORIZED_NAME_VERSION);
distNode.setProperty(SlcNames.SLC_CATEGORY, osgiDist.getCategory());
@@ -124,32 +104,28 @@ public class ModularDistributionIndexer implements NodeIndexer, SlcNames {
distNode.getNode(SLC_MODULES).remove();
Node modules = distNode.addNode(SLC_MODULES, NodeType.NT_UNSTRUCTURED);
- for (Iterator extends NameVersion> it = osgiDist.nameVersions(); it
- .hasNext();)
+ for (Iterator extends NameVersion> it = osgiDist.nameVersions(); it.hasNext();)
addModule(modules, it.next());
}
// Helpers
- private Node addModule(Node modules, NameVersion nameVersion)
- throws RepositoryException {
- CategorizedNameVersion cnv = (CategorizedNameVersion) nameVersion;
+ private Node addModule(Node modules, NameVersion nameVersion) throws RepositoryException {
+ CategoryNameVersion cnv = (CategoryNameVersion) nameVersion;
Node moduleCoord = null;
- moduleCoord = modules.addNode(cnv.getName(),
- SlcTypes.SLC_MODULE_COORDINATES);
+ 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 MyModularDistribution listModulesFromCsvIndex(Node fileNode,
- Binary fileBinary) {
+ private MyModularDistribution listModulesFromCsvIndex(Node fileNode, Binary fileBinary) {
JarInputStream jarIn = null;
BufferedReader reader = null;
try {
jarIn = new JarInputStream(fileBinary.getStream());
- List modules = new ArrayList();
+ List modules = new ArrayList();
// meta data
manifest = jarIn.getManifest();
@@ -157,15 +133,11 @@ public class ModularDistributionIndexer implements NodeIndexer, SlcNames {
log.error(fileNode + " has no MANIFEST");
return null;
}
- String category = manifest.getMainAttributes().getValue(
- RepoConstants.SLC_GROUP_ID);
- String name = manifest.getMainAttributes().getValue(
- Constants.BUNDLE_SYMBOLICNAME);
- String version = manifest.getMainAttributes().getValue(
- Constants.BUNDLE_VERSION);
+ String category = manifest.getMainAttributes().getValue(RepoConstants.SLC_CATEGORY_ID);
+ String name = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
+ String version = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
- Artifact distribution = new DefaultArtifact(category, name, "jar",
- version);
+ Artifact distribution = new DefaultArtifact(category, name, "jar", version);
// Retrieve the index file
JarEntry indexEntry;
while ((indexEntry = jarIn.getNextJarEntry()) != null) {
@@ -176,14 +148,17 @@ public class ModularDistributionIndexer implements NodeIndexer, SlcNames {
try {
jarIn.closeEntry();
} catch (SecurityException se) {
- log.error("Invalid signature file digest "
- + "for Manifest main attributes: " + entryName
+ log.error("Invalid signature file digest " + "for Manifest main attributes: " + entryName
+ " while looking for an index in bundle " + name);
}
}
if (indexEntry == null)
return null; // Not a modular definition
+ if (category == null) {
+ log.warn("Modular definition found but no " + RepoConstants.SLC_CATEGORY_ID + " in " + fileNode);
+ }
+
// Process the index
reader = new BufferedReader(new InputStreamReader(jarIn));
String line = null;
@@ -192,11 +167,9 @@ public class ModularDistributionIndexer implements NodeIndexer, SlcNames {
st.nextToken(); // moduleName
st.nextToken(); // moduleVersion
String relativeUrl = st.nextToken();
- Artifact currModule = AetherUtils.convertPathToArtifact(
- relativeUrl, null);
- modules.add(new MyCategorizedNameVersion(currModule
- .getGroupId(), currModule.getArtifactId(), currModule
- .getVersion()));
+ Artifact currModule = AetherUtils.convertPathToArtifact(relativeUrl, null);
+ modules.add(new DefaultCategoryNameVersion(currModule.getGroupId(), currModule.getArtifactId(),
+ currModule.getVersion()));
}
return new MyModularDistribution(distribution, modules);
} catch (Exception e) {
@@ -207,106 +180,24 @@ public class ModularDistributionIndexer implements NodeIndexer, SlcNames {
}
}
- // private MyModularDistribution listModulesFromPomIndex(Node fileNode,
- // Binary fileBinary) {
- // InputStream input = null;
- // List modules = new
- // ArrayList();
- // try {
- // input = fileBinary.getStream();
- //
- // DocumentBuilder documentBuilder = DocumentBuilderFactory
- // .newInstance().newDocumentBuilder();
- // Document doc = documentBuilder.parse(input);
- // // properties
- // Properties props = new Properties();
- // // props.setProperty("project.version",
- // // pomArtifact.getBaseVersion());
- // NodeList properties = doc.getElementsByTagName("properties");
- // if (properties.getLength() > 0) {
- // NodeList propertiesElems = properties.item(0).getChildNodes();
- // for (int i = 0; i < propertiesElems.getLength(); i++) {
- // if (propertiesElems.item(i) instanceof Element) {
- // Element property = (Element) propertiesElems.item(i);
- // props.put(property.getNodeName(),
- // property.getTextContent());
- // }
- // }
- // }
- //
- // // full coordinates are under
- // NodeList dependencies = ((Element) doc.getElementsByTagName(
- // "dependencyManagement").item(0))
- // .getElementsByTagName("dependency");
- // for (int i = 0; i < dependencies.getLength(); i++) {
- // Element dependency = (Element) dependencies.item(i);
- // String groupId = dependency.getElementsByTagName("groupId")
- // .item(0).getTextContent().trim();
- // String artifactId = dependency
- // .getElementsByTagName("artifactId").item(0)
- // .getTextContent().trim();
- // String version = dependency.getElementsByTagName("version")
- // .item(0).getTextContent().trim();
- // modules.add(new MyCategorizedNameVersion(groupId, artifactId,
- // version));
- // }
- //
- // String groupId = doc.getElementsByTagName("groupId").item(0)
- // .getTextContent().trim();
- // String artifactId = doc.getElementsByTagName("artifactId").item(0)
- // .getTextContent().trim();
- // String version = doc.getElementsByTagName("version").item(0)
- // .getTextContent().trim();
- //
- // Artifact currDist = new DefaultArtifact(groupId, artifactId, "pom",
- // version);
- //
- // return new MyModularDistribution(currDist, modules);
- // } catch (Exception e) {
- // throw new SlcException("Cannot process pom " + fileNode, e);
- // } finally {
- // IOUtils.closeQuietly(input);
- // }
- // }
-
- /** The created modular distribution */
- private static class MyCategorizedNameVersion extends DefaultNameVersion
- implements CategorizedNameVersion {
- private final String category;
-
- public MyCategorizedNameVersion(String category, String name,
- String version) {
- super(name, version);
- this.category = category;
- }
-
- public String getCategory() {
- return category;
- }
- }
-
/**
- * A consistent and versioned OSGi distribution, which can be built and
- * tested.
+ * A consistent and versioned OSGi distribution, which can be built and tested.
*/
- private class MyModularDistribution extends ArtifactDistribution implements
- ArgeoOsgiDistribution {
+ private class MyModularDistribution extends ArtifactDistribution implements ArgeoOsgiDistribution {
- private List modules;
+ private List modules;
- public MyModularDistribution(Artifact artifact,
- List modules) {
+ public MyModularDistribution(Artifact artifact, List modules) {
super(artifact);
this.modules = modules;
}
- public Iterator nameVersions() {
+ public Iterator nameVersions() {
return modules.iterator();
}
// Modular distribution interface methods. Not yet used.
- public Distribution getModuleDistribution(String moduleName,
- String moduleVersion) {
+ public Distribution getModuleDistribution(String moduleName, String moduleVersion) {
return null;
}