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.ModularDistributionIndexer;
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;
private Repository repository;
// Relevant default node indexers
- private ArtifactIndexer artifactIndexer = new ArtifactIndexer();
- private JarFileIndexer jarFileIndexer = new JarFileIndexer();
+ // WARNING Order call is important.
private ModularDistributionIndexer distBundleIndexer = new ModularDistributionIndexer();
+ private JarFileIndexer jarFileIndexer = new JarFileIndexer();
private PdeSourcesIndexer pdeSourceIndexer = new PdeSourcesIndexer();
+ private ArtifactIndexer artifactIndexer = new ArtifactIndexer();
public Object execute(ExecutionEvent event) throws ExecutionException {
String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
if (jarFileIndexer.support(node.getPath()))
if (artifactIndexer.support(node.getPath())) {
monitor.subTask(node.getName());
- artifactIndexer.index(node);
- jarFileIndexer.index(node);
distBundleIndexer.index(node);
+ jarFileIndexer.index(node);
+ artifactIndexer.index(node);
if (node.getSession().hasPendingChanges()) {
node.getSession().save();
if (log.isDebugEnabled())
monitor.worked(1);
}
} else if (node.getName().endsWith(".pom")) {
- if (distBundleIndexer.support(node.getPath()))
- distBundleIndexer.index(node);
+ // 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()) {
package org.argeo.slc.repo;
import javax.jcr.Node;
+import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeType;
md5.getBytes());
}
- // Create a default pom only with artifact coordinates if none
- // already exist
+ // Create a default pom if none already exist
String fileNodeName = fileNode.getName();
- String pomName= null;
+ String pomName = null;
if (fileNodeName.endsWith(".jar"))
- pomName = fileNodeName.substring(0, fileNodeName.length()-".jar".length()) + ".pom";
-
+ pomName = fileNodeName.substring(0, fileNodeName.length()
+ - ".jar".length())
+ + ".pom";
+
if (pomName != null && !fileNode.getParent().hasNode(pomName)) {
String pom = generatePomForBundle(fileNode);
Node pomNode = JcrUtils.copyBytesAsFile(fileNode.getParent(),
pomName, pom.getBytes());
// corresponding check sums
String sha = JcrUtils.checksumFile(pomNode, "SHA-1");
- JcrUtils.copyBytesAsFile(fileNode.getParent(), pomName + ".sha1",
- sha.getBytes());
+ JcrUtils.copyBytesAsFile(fileNode.getParent(), pomName
+ + ".sha1", sha.getBytes());
String md5 = JcrUtils.checksumFile(fileNode, "MD5");
- JcrUtils.copyBytesAsFile(fileNode.getParent(), pomName +".md5",
- md5.getBytes());
+ JcrUtils.copyBytesAsFile(fileNode.getParent(),
+ pomName + ".md5", md5.getBytes());
}
// set higher levels
private String generatePomForBundle(Node n) throws RepositoryException {
StringBuffer p = new StringBuffer();
-
- // XML header
p.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
p.append("<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n");
p.append("<modelVersion>4.0.0</modelVersion>");
- // Artifact
+ // Categorized name version
p.append("<groupId>").append(JcrUtils.get(n, SLC_GROUP_ID))
.append("</groupId>\n");
p.append("<artifactId>").append(JcrUtils.get(n, SLC_ARTIFACT_ID))
.append("</artifactId>\n");
p.append("<version>").append(JcrUtils.get(n, SLC_ARTIFACT_VERSION))
.append("</version>\n");
- p.append("<packaging>pom</packaging>\n");
+ // TODO make it more generic
+ p.append("<packaging>jar</packaging>\n");
if (n.hasProperty(SLC_ + Constants.BUNDLE_NAME))
p.append("<name>")
.append(JcrUtils.get(n, SLC_ + Constants.BUNDLE_NAME))
.append(JcrUtils
.get(n, SLC_ + Constants.BUNDLE_DESCRIPTION))
.append("</description>\n");
+
+ // Dependencies in case of a distribution
+ if (n.isNodeType(SlcTypes.SLC_MODULAR_DISTRIBUTION)) {
+ p.append(getDependenciesSnippet(n.getNode(SlcNames.SLC_MODULES)
+ .getNodes()));
+ p.append(getDependencyManagementSnippet(n.getNode(
+ SlcNames.SLC_MODULES).getNodes()));
+ }
p.append("</project>\n");
return p.toString();
}
+
+ private String getDependenciesSnippet(NodeIterator nit)
+ throws RepositoryException {
+ StringBuilder b = new StringBuilder();
+ b.append("<dependencies>\n");
+ while (nit.hasNext()) {
+ Node currModule = nit.nextNode();
+ if (currModule.isNodeType(SlcTypes.SLC_MODULE_COORDINATES)) {
+ b.append(getDependencySnippet(
+ currModule.getProperty(SlcNames.SLC_CATEGORY)
+ .getString(),
+ currModule.getProperty(SlcNames.SLC_NAME).getString(),
+ null));
+ }
+ }
+ b.append("</dependencies>\n");
+ return b.toString();
+ }
+
+ private String getDependencyManagementSnippet(NodeIterator nit)
+ throws RepositoryException {
+ StringBuilder b = new StringBuilder();
+ b.append("<dependencyManagement>\n");
+ b.append("<dependencies>\n");
+ while (nit.hasNext()) {
+ Node currModule = nit.nextNode();
+ if (currModule.isNodeType(SlcTypes.SLC_MODULE_COORDINATES)) {
+ b.append(getDependencySnippet(
+ currModule.getProperty(SlcNames.SLC_CATEGORY)
+ .getString(),
+ currModule.getProperty(SlcNames.SLC_NAME).getString(),
+ currModule.getProperty(SlcNames.SLC_VERSION)
+ .getString()));
+ }
+ }
+ b.append("</dependencies>\n");
+ b.append("</dependencyManagement>\n");
+ return b.toString();
+ }
+
+ private String getDependencySnippet(String category, String name,
+ String version) {
+ StringBuilder b = new StringBuilder();
+ b.append("<dependency>\n");
+ b.append("\t<groupId>").append(category).append("</groupId>\n");
+ b.append("\t<artifactId>").append(name).append("</artifactId>\n");
+ if (version != null)
+ b.append("\t<version>").append(version).append("</version>\n");
+ b.append("</dependency>\n");
+ return b.toString();
+ }
}
\ No newline at end of file
package org.argeo.slc.repo;
import java.io.BufferedReader;
-import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import java.util.Properties;
import java.util.StringTokenizer;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeType;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.osgi.framework.Constants;
import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.util.artifact.DefaultArtifact;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
/**
* Create or update JCR meta-data for an SLC Modular Distribution
*
* Currently, following types are managed: <list><li>* .jar: dependency
- * artifacts with csv index</li> <li>.pom: artifact (binaries) that indexes a
- * group, the .pom file contains a tag "dependencyManagement" that list all
- * modules</li> </list>
+ * artifacts with csv index</li> <li>@Deprecated : .pom: artifact (binaries)
+ * that indexes a group, the .pom file contains a tag "dependencyManagement"
+ * that list all modules</li> </list>
*/
public class ModularDistributionIndexer implements NodeIndexer, SlcNames {
private final static Log log = LogFactory
private final static String INDEX_FILE_NAME = "modularDistribution.csv";
private String separator = ",";
- // Artifact indexing
- private final static List<String> BINARIES_ARTIFACTS_NAME;
- static {
- List<String> tmpList = new ArrayList<String>();
- tmpList.add(RepoConstants.BINARIES_ARTIFACT_ID);
- // tmpList.add(RepoConstants.SOURCES_ARTIFACT_ID);
- // tmpList.add(RepoConstants.SDK_ARTIFACT_ID);
- BINARIES_ARTIFACTS_NAME = Collections.unmodifiableList(tmpList);
- }
+ // TODO remove this: binaries have been replaced by modular distribution
+ // // Artifact indexing
+ // private final static List<String> BINARIES_ARTIFACTS_NAME;
+ // static {
+ // List<String> tmpList = new ArrayList<String>();
+ // 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;
- // private Comparator<Artifact> artifactComparator = new
- // ArtifactIdComparator();
-
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;
+ // if (FilenameUtils.getExtension(path).equals("pom")
+ // && BINARIES_ARTIFACTS_NAME.contains(FilenameUtils.getName(path)
+ // .split("-")[0]))
+ // return true;
return false;
}
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);
+ // else if (FilenameUtils.getExtension(fileNode.getPath()).equals(
+ // "pom"))
+ // currDist = listModulesFromPomIndex(fileNode, fileBinary);
if (fileNode.isNodeType(SlcTypes.SLC_MODULAR_DISTRIBUTION)
|| currDist == null || !currDist.nameVersions().hasNext())
String version = manifest.getMainAttributes().getValue(
Constants.BUNDLE_VERSION);
- Artifact distribution = new DefaultArtifact(category, name, "pom",
+ Artifact distribution = new DefaultArtifact(category, name, "jar",
version);
// Retrieve the index file
JarEntry indexEntry;
}
}
if (indexEntry == null)
- return null; // Not a modular definition artifact
+ return null; // Not a modular definition
// Process the index
reader = new BufferedReader(new InputStreamReader(jarIn));
}
}
- private MyModularDistribution listModulesFromPomIndex(Node fileNode,
- Binary fileBinary) {
- InputStream input = null;
- List<CategorizedNameVersion> modules = new ArrayList<CategorizedNameVersion>();
- 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 <dependencyManagement><dependencies>
- 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);
- }
- }
+ // private MyModularDistribution listModulesFromPomIndex(Node fileNode,
+ // Binary fileBinary) {
+ // InputStream input = null;
+ // List<CategorizedNameVersion> modules = new
+ // ArrayList<CategorizedNameVersion>();
+ // 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 <dependencyManagement><dependencies>
+ // 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
public void setSeparator(String modulesUrlSeparator) {
this.separator = modulesUrlSeparator;
}
-
}
\ No newline at end of file