X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.repo%2Fsrc%2Forg%2Fargeo%2Fslc%2Frepo%2Fmaven%2FGenerateBinaries.java;h=095b371767e0cebafbb6110415fbe09cb2aa7cb2;hb=d64292c93f4a3532576e98f651344d89e883e2aa;hp=83335e9a5eef80982abd477cffeb91fb2a7a98da;hpb=d154e9f68017e8c5a8edac15475b2d79aea3e9d4;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.repo/src/org/argeo/slc/repo/maven/GenerateBinaries.java b/org.argeo.slc.repo/src/org/argeo/slc/repo/maven/GenerateBinaries.java index 83335e9a5..095b37176 100644 --- a/org.argeo.slc.repo/src/org/argeo/slc/repo/maven/GenerateBinaries.java +++ b/org.argeo.slc.repo/src/org/argeo/slc/repo/maven/GenerateBinaries.java @@ -1,18 +1,3 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * 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.util.ArrayList; @@ -28,8 +13,7 @@ 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.api.cms.CmsLog; import org.argeo.jcr.JcrMonitor; import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; @@ -47,7 +31,7 @@ import org.osgi.framework.Version; * group. */ public class GenerateBinaries implements Runnable, SlcNames { - private final static Log log = LogFactory.getLog(GenerateBinaries.class); + private final static CmsLog log = CmsLog.getLog(GenerateBinaries.class); // Connection info private Repository repository; @@ -64,10 +48,8 @@ public class GenerateBinaries implements Runnable, SlcNames { private List excludedSuffixes = new ArrayList(); // Indexes - private Set binaries = new TreeSet( - new ArtifactIdComparator()); - private Set sources = new TreeSet( - new ArtifactIdComparator()); + private Set binaries = new TreeSet(new ArtifactIdComparator()); + private Set sources = new TreeSet(new ArtifactIdComparator()); // local cache private ArtifactIndexer artifactIndexer = new ArtifactIndexer(); @@ -77,13 +59,11 @@ public class GenerateBinaries implements Runnable, SlcNames { Session session = null; try { session = repository.login(credentials, workspace); - Node groupNode = session.getNode(MavenConventionsUtils.groupPath( - artifactBasePath, groupId)); + Node groupNode = session.getNode(MavenConventionsUtils.groupPath(artifactBasePath, groupId)); internalPreProcessing(groupNode, null); internalProcessing(groupNode, null); } catch (Exception e) { - throw new SlcException("Cannot normalize group " + groupId + " in " - + workspace, e); + throw new SlcException("Cannot normalize group " + groupId + " in " + workspace, e); } finally { JcrUtils.logoutQuietly(session); } @@ -93,18 +73,15 @@ public class GenerateBinaries implements Runnable, SlcNames { * Generates binaries-, sources- and sdk-version.pom artifacts for the given * version (or the highest of all children version if none is precised). * - * By default, it includes each latest version of all artifact of this - * group. + * By default, it includes each latest version of all artifact of this group. * * The 3 generated artifacts are then marked as modular distributions and * indexed. */ - public static void processGroupNode(Node groupNode, String version, - JcrMonitor monitor) throws RepositoryException { + public static void processGroupNode(Node groupNode, String version, JcrMonitor monitor) throws RepositoryException { // TODO set artifactsBase based on group node GenerateBinaries gb = new GenerateBinaries(); - String groupId = groupNode.getProperty(SlcNames.SLC_GROUP_BASE_ID) - .getString(); + String groupId = groupNode.getProperty(SlcNames.SLC_GROUP_BASE_ID).getString(); gb.setGroupId(groupId); gb.setVersion(version); // TODO use already done pre-processing @@ -113,12 +90,10 @@ public class GenerateBinaries implements Runnable, SlcNames { } /** Only builds local indexes. Does not change anything in the local Session */ - public static GenerateBinaries preProcessGroupNode(Node groupNode, - JcrMonitor monitor) throws RepositoryException { + public static GenerateBinaries preProcessGroupNode(Node groupNode, JcrMonitor monitor) throws RepositoryException { // TODO set artifactsBase based on group node GenerateBinaries gb = new GenerateBinaries(); - String groupId = groupNode.getProperty(SlcNames.SLC_GROUP_BASE_ID) - .getString(); + String groupId = groupNode.getProperty(SlcNames.SLC_GROUP_BASE_ID).getString(); gb.setGroupId(groupId); // gb.setVersion(version); // gb.setOverridePoms(overridePoms); @@ -132,8 +107,7 @@ public class GenerateBinaries implements Runnable, SlcNames { } public Artifact getHighestArtifactVersion() throws RepositoryException { - return allArtifactsHighestVersion == null ? null : RepoUtils - .asArtifact(allArtifactsHighestVersion); + return allArtifactsHighestVersion == null ? null : RepoUtils.asArtifact(allArtifactsHighestVersion); } // ////////////////////////////////////// @@ -143,12 +117,11 @@ public class GenerateBinaries implements Runnable, SlcNames { * Browse all children of a Node considered as a folder that follows Aether * conventions i.e that has Aether's artifact base as children. * - * Each of such child contains a set of Aether artifact versions. This - * methods build the binaries {@code Set} and other indexes. It - * does not impact the + * Each of such child contains a set of Aether artifact versions. This methods + * build the binaries {@code Set} and other indexes. It does not + * impact the */ - protected void internalPreProcessing(Node groupNode, JcrMonitor monitor) - throws RepositoryException { + protected void internalPreProcessing(Node groupNode, JcrMonitor monitor) throws RepositoryException { if (monitor != null) monitor.subTask("Pre processing group " + groupId); @@ -156,8 +129,7 @@ public class GenerateBinaries implements Runnable, SlcNames { // gathering latest versions of each artifact allArtifactsHighestVersion = null; - aBases: for (NodeIterator aBases = groupNode.getNodes(); aBases - .hasNext();) { + aBases: for (NodeIterator aBases = groupNode.getNodes(); aBases.hasNext();) { Node aBase = aBases.nextNode(); if (aBase.isNodeType(SlcTypes.SLC_ARTIFACT_BASE)) { Node highestAVersion = getArtifactLatestVersion(aBase); @@ -166,8 +138,7 @@ public class GenerateBinaries implements Runnable, SlcNames { else { // retrieve relevant child node // Information is stored on the NT_FILE child node. - for (NodeIterator files = highestAVersion.getNodes(); files - .hasNext();) { + for (NodeIterator files = highestAVersion.getNodes(); files.hasNext();) { Node file = files.nextNode(); if (file.isNodeType(SlcTypes.SLC_BUNDLE_ARTIFACT)) { if (log.isDebugEnabled()) @@ -186,8 +157,7 @@ public class GenerateBinaries implements Runnable, SlcNames { } /** Does the real job : writes JCR META-DATA and generates binaries */ - protected void internalProcessing(Node groupNode, JcrMonitor monitor) - throws RepositoryException { + protected void internalProcessing(Node groupNode, JcrMonitor monitor) throws RepositoryException { if (monitor != null) monitor.subTask("Processing group " + groupId); @@ -199,11 +169,9 @@ public class GenerateBinaries implements Runnable, SlcNames { // => the version can then be left empty if (version == null || version.trim().equals("")) if (allArtifactsHighestVersion != null) - version = allArtifactsHighestVersion.getProperty( - SLC_ARTIFACT_VERSION).getString(); + version = allArtifactsHighestVersion.getProperty(SLC_ARTIFACT_VERSION).getString(); else - throw new SlcException("Group version " + version - + " is empty."); + throw new SlcException("Group version " + version + " is empty."); // int bundleCount = symbolicNamesToNodes.size(); // int count = 1; @@ -218,16 +186,13 @@ public class GenerateBinaries implements Runnable, SlcNames { // } // indexes - Set indexes = new TreeSet( - new ArtifactIdComparator()); + Set indexes = new TreeSet(new ArtifactIdComparator()); Artifact indexArtifact; - indexArtifact = writeIndex(session, RepoConstants.BINARIES_ARTIFACT_ID, - binaries); + indexArtifact = writeIndex(session, RepoConstants.BINARIES_ARTIFACT_ID, binaries); indexes.add(indexArtifact); - indexArtifact = writeIndex(session, RepoConstants.SOURCES_ARTIFACT_ID, - sources); + indexArtifact = writeIndex(session, RepoConstants.SOURCES_ARTIFACT_ID, sources); indexes.add(indexArtifact); // sdk @@ -237,8 +202,7 @@ public class GenerateBinaries implements Runnable, SlcNames { monitor.worked(1); } - protected void preProcessBundleArtifact(Node bundleNode) - throws RepositoryException { + protected void preProcessBundleArtifact(Node bundleNode) throws RepositoryException { String symbolicName = JcrUtils.get(bundleNode, SLC_SYMBOLIC_NAME); // Sanity check. @@ -248,8 +212,7 @@ public class GenerateBinaries implements Runnable, SlcNames { // Manage source bundles if (symbolicName.endsWith(".source")) { // TODO make a shared node with classifier 'sources'? - String bundleName = RepoUtils - .extractBundleNameFromSourceName(symbolicName); + String bundleName = RepoUtils.extractBundleNameFromSourceName(symbolicName); for (String excludedSuffix : excludedSuffixes) { if (bundleName.endsWith(excludedSuffix)) return;// skip adding to sources @@ -277,8 +240,7 @@ public class GenerateBinaries implements Runnable, SlcNames { // Extra check. to remove if (bundleNode.getSession().hasPendingChanges()) - throw new SlcException("Pending changes in the session, " - + "this should not be true here."); + throw new SlcException("Pending changes in the session, " + "this should not be true here."); } // protected void processBundleArtifact(Node bundleNode) @@ -307,25 +269,19 @@ public class GenerateBinaries implements Runnable, SlcNames { // LOCAL WRITERS // - private Artifact writeIndex(Session session, String artifactId, - Set artifacts) throws RepositoryException { - Artifact artifact = new DefaultArtifact(groupId, artifactId, "pom", - version); - Artifact parentArtifact = parentPomCoordinates != null ? new DefaultArtifact( - parentPomCoordinates) : null; - String pom = MavenConventionsUtils.artifactsAsDependencyPom(artifact, - artifacts, parentArtifact); - Node node = RepoUtils.copyBytesAsArtifact( - session.getNode(artifactBasePath), artifact, pom.getBytes()); + private Artifact writeIndex(Session session, String artifactId, Set artifacts) + throws RepositoryException { + Artifact artifact = new DefaultArtifact(groupId, artifactId, "pom", version); + Artifact parentArtifact = parentPomCoordinates != null ? new DefaultArtifact(parentPomCoordinates) : null; + String pom = MavenConventionsUtils.artifactsAsDependencyPom(artifact, artifacts, parentArtifact); + Node node = RepoUtils.copyBytesAsArtifact(session.getNode(artifactBasePath), artifact, pom.getBytes()); artifactIndexer.index(node); // TODO factorize String pomSha = JcrUtils.checksumFile(node, "SHA-1"); - JcrUtils.copyBytesAsFile(node.getParent(), node.getName() + ".sha1", - pomSha.getBytes()); + JcrUtils.copyBytesAsFile(node.getParent(), node.getName() + ".sha1", pomSha.getBytes()); String pomMd5 = JcrUtils.checksumFile(node, "MD5"); - JcrUtils.copyBytesAsFile(node.getParent(), node.getName() + ".md5", - pomMd5.getBytes()); + JcrUtils.copyBytesAsFile(node.getParent(), node.getName() + ".md5", pomMd5.getBytes()); session.save(); return artifact; } @@ -334,8 +290,7 @@ public class GenerateBinaries implements Runnable, SlcNames { private Node getArtifactLatestVersion(Node artifactBase) { try { Node highestAVersion = null; - for (NodeIterator aVersions = artifactBase.getNodes(); aVersions - .hasNext();) { + for (NodeIterator aVersions = artifactBase.getNodes(); aVersions.hasNext();) { Node aVersion = aVersions.nextNode(); if (aVersion.isNodeType(SlcTypes.SLC_ARTIFACT_VERSION_BASE)) { if (highestAVersion == null) { @@ -356,8 +311,7 @@ public class GenerateBinaries implements Runnable, SlcNames { if (currVersion.compareTo(currentHighestVersion) > 0) { highestAVersion = aVersion; } - if (currVersion - .compareTo(extractOsgiVersion(allArtifactsHighestVersion)) > 0) { + if (currVersion.compareTo(extractOsgiVersion(allArtifactsHighestVersion)) > 0) { allArtifactsHighestVersion = aVersion; } } @@ -366,15 +320,12 @@ public class GenerateBinaries implements Runnable, SlcNames { } return highestAVersion; } catch (RepositoryException re) { - throw new SlcException("Unable to get latest version for node " - + artifactBase, re); + throw new SlcException("Unable to get latest version for node " + artifactBase, re); } } - private Version extractOsgiVersion(Node artifactVersion) - throws RepositoryException { - String rawVersion = artifactVersion.getProperty(SLC_ARTIFACT_VERSION) - .getString(); + private Version extractOsgiVersion(Node artifactVersion) throws RepositoryException { + String rawVersion = artifactVersion.getProperty(SLC_ARTIFACT_VERSION).getString(); String cleanVersion = rawVersion.replace("-SNAPSHOT", ".SNAPSHOT"); Version osgiVersion = null; // log invalid version value to enable tracking them @@ -425,7 +376,10 @@ public class GenerateBinaries implements Runnable, SlcNames { // // // XML header // p.append("\n"); - // p.append("\n"); + // p.append("\n"); // p.append("4.0.0"); // // // Artifact