X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=cms%2Forg.argeo.slc.repo%2Fsrc%2Forg%2Fargeo%2Fslc%2Frepo%2Fmaven%2FIndexDistribution.java;fp=cms%2Forg.argeo.slc.repo%2Fsrc%2Forg%2Fargeo%2Fslc%2Frepo%2Fmaven%2FIndexDistribution.java;h=0000000000000000000000000000000000000000;hb=6fc94d69efe089414ac9e63bde3efab1cbf7b7ca;hp=1d013f57d923ad297aa9a57c62a76b5a47def23f;hpb=b36c62642bd0db11b3133b369cc026fd4b7a1ec6;p=gpl%2Fargeo-slc.git diff --git a/cms/org.argeo.slc.repo/src/org/argeo/slc/repo/maven/IndexDistribution.java b/cms/org.argeo.slc.repo/src/org/argeo/slc/repo/maven/IndexDistribution.java deleted file mode 100644 index 1d013f57d..000000000 --- a/cms/org.argeo.slc.repo/src/org/argeo/slc/repo/maven/IndexDistribution.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.argeo.slc.repo.maven; - -import java.io.File; -import java.util.HashSet; -import java.util.Set; - -import javax.jcr.Node; -import javax.jcr.Repository; -import javax.jcr.RepositoryException; -import javax.jcr.Session; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.jcr.JcrUtils; -import org.argeo.slc.SlcException; -import org.argeo.slc.SlcNames; -import org.argeo.slc.SlcTypes; -import org.argeo.slc.repo.RepoConstants; -import org.eclipse.aether.artifact.Artifact; - -/** Create a distribution node from a set of artifacts */ -public class IndexDistribution implements Runnable { - private final static Log log = LogFactory.getLog(IndexDistribution.class); - private Repository repository; - private String workspace; - - private String artifactBasePath = RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH; - private String distributionsBasePath = RepoConstants.DISTRIBUTIONS_BASE_PATH; - private String distributionName; - - public void run() { - // TODO populate - Set artifacts = new HashSet(); - - // sync - Session session = null; - try { - session = repository.login(workspace); - syncDistribution(session, artifacts); - } catch (Exception e) { - throw new SlcException("Cannot import distribution", e); - } finally { - JcrUtils.logoutQuietly(session); - } - } - - protected void syncDistribution(Session jcrSession, Set artifacts) { - Long begin = System.currentTimeMillis(); - try { - JcrUtils.mkdirs(jcrSession, distributionsBasePath + '/' - + distributionName); - artifacts: for (Artifact artifact : artifacts) { - File file = artifact.getFile(); - if (file == null) { - file = MavenConventionsUtils.artifactToFile(artifact); - if (!file.exists()) { - log.warn("Generated file " + file + " for " + artifact - + " does not exist"); - continue artifacts; - } - } - - try { - String parentPath = artifactBasePath - + (artifactBasePath.endsWith("/") ? "" : "/") - + artifactParentPath(artifact); - Node parentNode = jcrSession.getNode(parentPath); - Node fileNode = parentNode.getNode(file.getName()); - - if (fileNode.hasProperty(SlcNames.SLC_SYMBOLIC_NAME)) { - String distPath = bundleDistributionPath(fileNode); - if (!jcrSession.itemExists(distPath) - && fileNode - .isNodeType(SlcTypes.SLC_BUNDLE_ARTIFACT)) - jcrSession.getWorkspace().clone( - jcrSession.getWorkspace().getName(), - fileNode.getPath(), distPath, false); - if (log.isDebugEnabled()) - log.debug("Indexed " + fileNode); - } - } catch (Exception e) { - log.error("Could not index " + artifact, e); - jcrSession.refresh(false); - throw e; - } - } - - Long duration = (System.currentTimeMillis() - begin) / 1000; - if (log.isDebugEnabled()) - log.debug("Indexed distribution in " + duration + "s"); - } catch (Exception e) { - throw new SlcException("Cannot synchronize distribution", e); - } - } - - private String artifactParentPath(Artifact artifact) { - return artifact.getGroupId().replace('.', '/') + '/' - + artifact.getArtifactId() + '/' + artifact.getVersion(); - } - - private String bundleDistributionPath(Node fileNode) { - try { - return distributionsBasePath - + '/' - + distributionName - + '/' - + fileNode.getProperty(SlcNames.SLC_SYMBOLIC_NAME) - .getString() - + '_' - + fileNode.getProperty(SlcNames.SLC_BUNDLE_VERSION) - .getString(); - } catch (RepositoryException e) { - throw new SlcException("Cannot create distribution path for " - + fileNode, e); - } - } - - public void setDistributionName(String distributionName) { - this.distributionName = distributionName; - } - - public void setRepository(Repository repository) { - this.repository = repository; - } - - public void setWorkspace(String workspace) { - this.workspace = workspace; - } - -}