X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.repo%2Fsrc%2Forg%2Fargeo%2Fslc%2Frepo%2Fmaven%2FMigration_01_03.java;h=8e201253a27f74a176f99217b31f54b25dd03881;hb=d64292c93f4a3532576e98f651344d89e883e2aa;hp=065e22ef64378e839201b0be4be4678615d84b49;hpb=f59056d0b805cb91f524671a28b8780338509ba4;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.repo/src/org/argeo/slc/repo/maven/Migration_01_03.java b/org.argeo.slc.repo/src/org/argeo/slc/repo/maven/Migration_01_03.java index 065e22ef6..8e201253a 100644 --- a/org.argeo.slc.repo/src/org/argeo/slc/repo/maven/Migration_01_03.java +++ b/org.argeo.slc.repo/src/org/argeo/slc/repo/maven/Migration_01_03.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.io.IOException; @@ -38,8 +23,7 @@ import javax.jcr.query.qom.QueryObjectModel; import javax.jcr.query.qom.QueryObjectModelFactory; import javax.jcr.query.qom.Selector; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.argeo.api.cms.CmsLog; import org.argeo.jcr.JcrUtils; import org.argeo.slc.NameVersion; import org.argeo.slc.SlcException; @@ -64,7 +48,7 @@ import org.osgi.framework.Constants; */ public class Migration_01_03 implements Runnable, SlcNames { final String SPRING_SOURCE_PREFIX = "com.springsource"; - private final static Log log = LogFactory.getLog(Migration_01_03.class); + private final static CmsLog log = CmsLog.getLog(Migration_01_03.class); private Repository repository; private String sourceWorkspace; @@ -76,8 +60,7 @@ public class Migration_01_03 implements Runnable, SlcNames { private Session origSession; private Session targetSession; - private List systemPackages = OsgiProfile.PROFILE_JAVA_SE_1_6 - .getSystemPackages(); + private List systemPackages = OsgiProfile.PROFILE_JAVA_SE_1_6.getSystemPackages(); private String artifactBasePath = "/"; @@ -85,10 +68,8 @@ public class Migration_01_03 implements Runnable, SlcNames { private JarFileIndexer jarFileIndexer = new JarFileIndexer(); public void init() throws RepositoryException { - origSession = JcrUtils.loginOrCreateWorkspace(repository, - sourceWorkspace); - targetSession = JcrUtils.loginOrCreateWorkspace(repository, - targetWorkspace); + origSession = JcrUtils.loginOrCreateWorkspace(repository, sourceWorkspace); + targetSession = JcrUtils.loginOrCreateWorkspace(repository, targetWorkspace); // works only in OSGi!! // systemPackages = Arrays.asList(System.getProperty( @@ -104,12 +85,10 @@ public class Migration_01_03 implements Runnable, SlcNames { try { // clear target - NodeIterator nit = targetSession.getNode(artifactBasePath) - .getNodes(); + NodeIterator nit = targetSession.getNode(artifactBasePath).getNodes(); while (nit.hasNext()) { Node node = nit.nextNode(); - if (node.isNodeType(NodeType.NT_FOLDER) - || node.isNodeType(NodeType.NT_UNSTRUCTURED)) { + if (node.isNodeType(NodeType.NT_FOLDER) || node.isNodeType(NodeType.NT_UNSTRUCTURED)) { node.remove(); node.getSession().save(); if (log.isDebugEnabled()) @@ -127,23 +106,21 @@ public class Migration_01_03 implements Runnable, SlcNames { processOrigArtifactVersion(origArtifactNode); } } catch (Exception e) { - throw new SlcException("Cannot perform v1.3 migration from " - + sourceWorkspace + " to " + targetWorkspace, e); + throw new SlcException("Cannot perform v1.3 migration from " + sourceWorkspace + " to " + targetWorkspace, + e); } finally { JcrUtils.discardQuietly(targetSession); } } - protected void processOrigArtifactVersion(Node origArtifactNode) - throws RepositoryException, IOException { + protected void processOrigArtifactVersion(Node origArtifactNode) throws RepositoryException, IOException { Artifact origArtifact = RepoUtils.asArtifact(origArtifactNode); // skip eclipse artifacts - if ((origArtifact.getGroupId().startsWith("org.eclipse") && !(origArtifact - .getArtifactId().equals("org.eclipse.osgi") - || origArtifact.getArtifactId().equals( - "org.eclipse.osgi.source") || origArtifact - .getArtifactId().startsWith("org.eclipse.rwt.widgets.upload"))) + if ((origArtifact.getGroupId().startsWith("org.eclipse") + && !(origArtifact.getArtifactId().equals("org.eclipse.osgi") + || origArtifact.getArtifactId().equals("org.eclipse.osgi.source") + || origArtifact.getArtifactId().startsWith("org.eclipse.rwt.widgets.upload"))) || origArtifact.getArtifactId().startsWith("com.ibm.icu")) { if (log.isDebugEnabled()) log.debug("Skip " + origArtifact); @@ -151,20 +128,16 @@ public class Migration_01_03 implements Runnable, SlcNames { } // skip SpringSource ActiveMQ - if (origArtifact.getArtifactId().startsWith( - "com.springsource.org.apache.activemq")) + if (origArtifact.getArtifactId().startsWith("com.springsource.org.apache.activemq")) return; - String origJarNodeName = MavenConventionsUtils - .artifactFileName(origArtifact); + String origJarNodeName = MavenConventionsUtils.artifactFileName(origArtifact); if (!origArtifactNode.hasNode(origJarNodeName)) - throw new SlcException("Cannot find jar node for " - + origArtifactNode); + throw new SlcException("Cannot find jar node for " + origArtifactNode); Node origJarNode = origArtifactNode.getNode(origJarNodeName); // read MANIFEST - Binary manifestBinary = origJarNode.getProperty(SLC_MANIFEST) - .getBinary(); + Binary manifestBinary = origJarNode.getProperty(SLC_MANIFEST).getBinary(); Manifest origManifest = new Manifest(manifestBinary.getStream()); JcrUtils.closeQuietly(manifestBinary); @@ -172,26 +145,23 @@ public class Migration_01_03 implements Runnable, SlcNames { Manifest targetManifest = new Manifest(origManifest); // transform symbolic name - String origSymbolicName = origManifest.getMainAttributes().getValue( - Constants.BUNDLE_SYMBOLICNAME); + String origSymbolicName = origManifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); final String targetSymbolicName; if (symbolicNamesMapping.containsKey(origSymbolicName)) { targetSymbolicName = symbolicNamesMapping.get(origSymbolicName); } else if (origSymbolicName.startsWith(SPRING_SOURCE_PREFIX) && !origSymbolicName.equals(SPRING_SOURCE_PREFIX + ".json")) { - targetSymbolicName = origSymbolicName - .substring(SPRING_SOURCE_PREFIX.length() + 1); + targetSymbolicName = origSymbolicName.substring(SPRING_SOURCE_PREFIX.length() + 1); } else { targetSymbolicName = origSymbolicName; } if (!targetSymbolicName.equals(origSymbolicName)) { - targetManifest.getMainAttributes().putValue( - Constants.BUNDLE_SYMBOLICNAME, targetSymbolicName); + targetManifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, targetSymbolicName); manifestModified = true; if (log.isDebugEnabled()) - log.debug(Constants.BUNDLE_SYMBOLICNAME + " to " - + targetSymbolicName + " \t\tfrom " + origSymbolicName); + log.debug( + Constants.BUNDLE_SYMBOLICNAME + " to " + targetSymbolicName + " \t\tfrom " + origSymbolicName); } // skip excluded bundles @@ -199,19 +169,15 @@ public class Migration_01_03 implements Runnable, SlcNames { return; // check fragment host - if (origManifest.getMainAttributes().containsKey( - new Name(Constants.FRAGMENT_HOST))) { - String origFragmentHost = origManifest.getMainAttributes() - .getValue(Constants.FRAGMENT_HOST); + if (origManifest.getMainAttributes().containsKey(new Name(Constants.FRAGMENT_HOST))) { + String origFragmentHost = origManifest.getMainAttributes().getValue(Constants.FRAGMENT_HOST); String targetFragmentHost; if (symbolicNamesMapping.containsKey(origFragmentHost)) { targetFragmentHost = symbolicNamesMapping.get(origFragmentHost); } else if (origFragmentHost.startsWith(SPRING_SOURCE_PREFIX) && !origFragmentHost.equals(SPRING_SOURCE_PREFIX + ".json")) { - targetFragmentHost = origFragmentHost - .substring(SPRING_SOURCE_PREFIX.length() + 1); - } else if (origFragmentHost - .equals("org.argeo.dep.jacob;bundle-version=\"[1.14.3,1.14.4)\"")) { + targetFragmentHost = origFragmentHost.substring(SPRING_SOURCE_PREFIX.length() + 1); + } else if (origFragmentHost.equals("org.argeo.dep.jacob;bundle-version=\"[1.14.3,1.14.4)\"")) { // this one for those who think I cannot be pragmatic - mbaudier targetFragmentHost = "com.jacob;bundle-version=\"[1.14.3,1.14.4)\""; } else { @@ -219,12 +185,10 @@ public class Migration_01_03 implements Runnable, SlcNames { } if (!targetFragmentHost.equals(origFragmentHost)) { - targetManifest.getMainAttributes().putValue( - Constants.FRAGMENT_HOST, targetFragmentHost); + targetManifest.getMainAttributes().putValue(Constants.FRAGMENT_HOST, targetFragmentHost); manifestModified = true; if (log.isDebugEnabled()) - log.debug(Constants.FRAGMENT_HOST + " to " - + targetFragmentHost + " from " + origFragmentHost); + log.debug(Constants.FRAGMENT_HOST + " to " + targetFragmentHost + " from " + origFragmentHost); } } @@ -232,35 +196,28 @@ public class Migration_01_03 implements Runnable, SlcNames { // javax with versions StringBuffer targetImportPackages = new StringBuffer(""); - NodeIterator origImportPackages = origJarNode.getNodes(SLC_ - + Constants.IMPORT_PACKAGE); + NodeIterator origImportPackages = origJarNode.getNodes(SLC_ + Constants.IMPORT_PACKAGE); Boolean importPackagesModified = false; while (origImportPackages.hasNext()) { Node importPackage = origImportPackages.nextNode(); String pkg = importPackage.getProperty(SLC_NAME).getString(); targetImportPackages.append(pkg); if (importPackage.hasProperty(SLC_VERSION)) { - String sourceVersion = importPackage.getProperty(SLC_VERSION) - .getString(); + String sourceVersion = importPackage.getProperty(SLC_VERSION).getString(); String targetVersion = sourceVersion; if (systemPackages.contains(pkg)) { - if (!(sourceVersion.trim().equals("0") || sourceVersion - .trim().equals("0.0.0"))) { + if (!(sourceVersion.trim().equals("0") || sourceVersion.trim().equals("0.0.0"))) { targetVersion = null; importPackagesModified = true; if (log.isDebugEnabled()) - log.debug(origSymbolicName - + ": Nullify version of " + pkg + " from " - + sourceVersion); + log.debug(origSymbolicName + ": Nullify version of " + pkg + " from " + sourceVersion); } } if (targetVersion != null) - targetImportPackages.append(";version=\"") - .append(targetVersion).append("\""); + targetImportPackages.append(";version=\"").append(targetVersion).append("\""); } if (importPackage.hasProperty(SLC_OPTIONAL)) { - Boolean optional = importPackage.getProperty(SLC_OPTIONAL) - .getBoolean(); + Boolean optional = importPackage.getProperty(SLC_OPTIONAL).getBoolean(); if (optional) targetImportPackages.append(";resolution:=\"optional\""); @@ -270,8 +227,7 @@ public class Migration_01_03 implements Runnable, SlcNames { } if (importPackagesModified) { - targetManifest.getMainAttributes().putValue( - Constants.IMPORT_PACKAGE, targetImportPackages.toString()); + targetManifest.getMainAttributes().putValue(Constants.IMPORT_PACKAGE, targetImportPackages.toString()); manifestModified = true; } @@ -281,8 +237,7 @@ public class Migration_01_03 implements Runnable, SlcNames { // target coordinates final String targetGroupId; - if (origArtifact.getArtifactId().startsWith( - "org.eclipse.rwt.widgets.upload")) + if (origArtifact.getArtifactId().startsWith("org.eclipse.rwt.widgets.upload")) targetGroupId = "org.argeo.tp.rap"; else if (origArtifact.getArtifactId().startsWith("org.polymap")) targetGroupId = "org.argeo.tp.rap"; @@ -295,29 +250,22 @@ public class Migration_01_03 implements Runnable, SlcNames { targetGroupId = "org.argeo.tp"; String targetArtifactId = targetSymbolicName.split(";")[0]; - Artifact targetArtifact = new DefaultArtifact(targetGroupId, - targetArtifactId, "jar", origArtifact.getVersion()); - String targetParentPath = MavenConventionsUtils.artifactParentPath( - artifactBasePath, targetArtifact); - String targetFileName = MavenConventionsUtils - .artifactFileName(targetArtifact); + Artifact targetArtifact = new DefaultArtifact(targetGroupId, targetArtifactId, "jar", + origArtifact.getVersion()); + String targetParentPath = MavenConventionsUtils.artifactParentPath(artifactBasePath, targetArtifact); + String targetFileName = MavenConventionsUtils.artifactFileName(targetArtifact); String targetJarPath = targetParentPath + '/' + targetFileName; // copy - Node targetParentNode = JcrUtils.mkfolders(targetSession, - targetParentPath); + Node targetParentNode = JcrUtils.mkfolders(targetSession, targetParentPath); targetSession.save(); if (manifestModified) { - Binary origBinary = origJarNode.getNode(Node.JCR_CONTENT) - .getProperty(Property.JCR_DATA).getBinary(); - byte[] targetJarBytes = RepoUtils.modifyManifest( - origBinary.getStream(), targetManifest); - JcrUtils.copyBytesAsFile(targetParentNode, targetFileName, - targetJarBytes); + Binary origBinary = origJarNode.getNode(Node.JCR_CONTENT).getProperty(Property.JCR_DATA).getBinary(); + byte[] targetJarBytes = RepoUtils.modifyManifest(origBinary.getStream(), targetManifest); + JcrUtils.copyBytesAsFile(targetParentNode, targetFileName, targetJarBytes); JcrUtils.closeQuietly(origBinary); } else {// just copy - targetSession.getWorkspace().copy(sourceWorkspace, - origJarNode.getPath(), targetJarPath); + targetSession.getWorkspace().copy(sourceWorkspace, origJarNode.getPath(), targetJarPath); } targetSession.save(); @@ -329,47 +277,36 @@ public class Migration_01_03 implements Runnable, SlcNames { targetSession.save(); // sources - Artifact origSourceArtifact = new DefaultArtifact( - origArtifact.getGroupId(), origArtifact.getArtifactId() - + ".source", "jar", origArtifact.getVersion()); - String origSourcePath = MavenConventionsUtils.artifactPath( - artifactBasePath, origSourceArtifact); + Artifact origSourceArtifact = new DefaultArtifact(origArtifact.getGroupId(), + origArtifact.getArtifactId() + ".source", "jar", origArtifact.getVersion()); + String origSourcePath = MavenConventionsUtils.artifactPath(artifactBasePath, origSourceArtifact); if (origSession.itemExists(origSourcePath)) { Node origSourceJarNode = origSession.getNode(origSourcePath); - Artifact targetSourceArtifact = new DefaultArtifact(targetGroupId, - targetArtifactId + ".source", "jar", + Artifact targetSourceArtifact = new DefaultArtifact(targetGroupId, targetArtifactId + ".source", "jar", origArtifact.getVersion()); - String targetSourceParentPath = MavenConventionsUtils - .artifactParentPath(artifactBasePath, targetSourceArtifact); - String targetSourceFileName = MavenConventionsUtils - .artifactFileName(targetSourceArtifact); - String targetSourceJarPath = targetSourceParentPath + '/' - + targetSourceFileName; - - Node targetSourceParentNode = JcrUtils.mkfolders(targetSession, - targetSourceParentPath); + String targetSourceParentPath = MavenConventionsUtils.artifactParentPath(artifactBasePath, + targetSourceArtifact); + String targetSourceFileName = MavenConventionsUtils.artifactFileName(targetSourceArtifact); + String targetSourceJarPath = targetSourceParentPath + '/' + targetSourceFileName; + + Node targetSourceParentNode = JcrUtils.mkfolders(targetSession, targetSourceParentPath); targetSession.save(); if (!targetSymbolicName.equals(origSymbolicName)) { - Binary origBinary = origSourceJarNode.getNode(Node.JCR_CONTENT) - .getProperty(Property.JCR_DATA).getBinary(); - NameVersion targetNameVersion = RepoUtils - .readNameVersion(targetManifest); - byte[] targetJarBytes = RepoUtils.packageAsPdeSource( - origBinary.getStream(), targetNameVersion); - JcrUtils.copyBytesAsFile(targetSourceParentNode, - targetSourceFileName, targetJarBytes); + Binary origBinary = origSourceJarNode.getNode(Node.JCR_CONTENT).getProperty(Property.JCR_DATA) + .getBinary(); + NameVersion targetNameVersion = RepoUtils.readNameVersion(targetManifest); + byte[] targetJarBytes = RepoUtils.packageAsPdeSource(origBinary.getStream(), targetNameVersion); + JcrUtils.copyBytesAsFile(targetSourceParentNode, targetSourceFileName, targetJarBytes); JcrUtils.closeQuietly(origBinary); } else {// just copy - targetSession.getWorkspace().copy(sourceWorkspace, - origSourceJarNode.getPath(), targetSourceJarPath); + targetSession.getWorkspace().copy(sourceWorkspace, origSourceJarNode.getPath(), targetSourceJarPath); } targetSession.save(); // reindex - Node targetSourceJarNode = targetSession - .getNode(targetSourceJarPath); + Node targetSourceJarNode = targetSession.getNode(targetSourceJarPath); artifactIndexer.index(targetSourceJarNode); jarFileIndexer.index(targetSourceJarNode); @@ -381,21 +318,18 @@ public class Migration_01_03 implements Runnable, SlcNames { * UTILITIES */ - static NodeIterator listArtifactVersions(Session session) - throws RepositoryException { + static NodeIterator listArtifactVersions(Session session) throws RepositoryException { QueryManager queryManager = session.getWorkspace().getQueryManager(); QueryObjectModelFactory factory = queryManager.getQOMFactory(); final String artifactVersionsSelector = "artifactVersions"; - Selector source = factory.selector(SlcTypes.SLC_ARTIFACT_VERSION_BASE, - artifactVersionsSelector); + Selector source = factory.selector(SlcTypes.SLC_ARTIFACT_VERSION_BASE, artifactVersionsSelector); - Ordering orderByArtifactId = factory.ascending(factory.propertyValue( - artifactVersionsSelector, SlcNames.SLC_ARTIFACT_ID)); + Ordering orderByArtifactId = factory + .ascending(factory.propertyValue(artifactVersionsSelector, SlcNames.SLC_ARTIFACT_ID)); Ordering[] orderings = { orderByArtifactId }; - QueryObjectModel query = factory.createQuery(source, null, orderings, - null); + QueryObjectModel query = factory.createQuery(source, null, orderings, null); QueryResult result = query.execute(); return result.getNodes();