+ throw new SlcException("Cannot resolve distribution", e);
+ }
+ }
+
+ protected void syncDistribution(Set<Artifact> artifacts) {
+ Long begin = System.currentTimeMillis();
+ try {
+ JcrUtils.mkdirs(jcrSession, artifactBasePath);
+ for (Artifact artifact : artifacts) {
+ String parentPath = artifactBasePath + '/'
+ + artifactParentPath(artifact);
+ Node parentNode;
+ if (!jcrSession.itemExists(parentPath)) {
+ parentNode = JcrUtils.mkdirs(jcrSession, parentPath,
+ NodeType.NT_FOLDER, false);
+ } else {
+ parentNode = jcrSession.getNode(parentPath);
+ }
+
+ File file = artifact.getFile();
+ Node fileNode;
+ if (!parentNode.hasNode(file.getName())) {
+ fileNode = createFileNode(parentNode, file);
+ } else {
+ fileNode = parentNode.getNode(file.getName());
+ }
+ }
+
+ Long duration = (System.currentTimeMillis() - begin) / 1000;
+ if (log.isDebugEnabled())
+ log.debug("Synchronized distribution in " + duration + "s");
+ } catch (Exception e) {
+ throw new SlcException("Cannot synchronize distribution", e);
+ }
+ }
+
+ protected String artifactParentPath(Artifact artifact) {
+ return artifact.getGroupId().replace('.', '/') + '/'
+ + artifact.getArtifactId() + '/' + artifact.getVersion();
+ }
+
+ protected Node createFileNode(Node parentNode, File file) {
+ try {
+ Node fileNode = parentNode
+ .addNode(file.getName(), NodeType.NT_FILE);
+ Node contentNode = fileNode.addNode(Node.JCR_CONTENT,
+ NodeType.NT_RESOURCE);
+ Binary binary = jcrSession.getValueFactory().createBinary(
+ new FileInputStream(file));
+ contentNode.setProperty(Property.JCR_DATA, binary);
+ binary.dispose();
+ return fileNode;
+ } catch (Exception e) {
+ throw new SlcException("Cannot create file node based on " + file
+ + " under " + parentNode, e);