X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.slc.repo%2Fsrc%2Forg%2Fargeo%2Fslc%2Frepo%2FPdeSourcesIndexer.java;h=0ce3ba9200cc904572e2dbc2cca9540e3bba57ac;hb=58b35f147f3c1c1a12a07c303105618f679c7161;hp=97ca286ce31e10f27e3661954f4d2237d27f5aca;hpb=b9505fef5ba8186433e903e9de3c73c17bdf6562;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.repo/src/org/argeo/slc/repo/PdeSourcesIndexer.java b/org.argeo.slc.repo/src/org/argeo/slc/repo/PdeSourcesIndexer.java index 97ca286ce..0ce3ba920 100644 --- a/org.argeo.slc.repo/src/org/argeo/slc/repo/PdeSourcesIndexer.java +++ b/org.argeo.slc.repo/src/org/argeo/slc/repo/PdeSourcesIndexer.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; import javax.jcr.Binary; @@ -27,10 +12,10 @@ import org.apache.commons.logging.LogFactory; import org.argeo.jcr.JcrUtils; import org.argeo.slc.NameVersion; import org.argeo.slc.SlcException; -import org.argeo.slc.aether.AetherUtils; +import org.argeo.slc.repo.maven.AetherUtils; import org.argeo.slc.repo.maven.MavenConventionsUtils; -import org.sonatype.aether.artifact.Artifact; -import org.sonatype.aether.util.artifact.DefaultArtifact; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; /** * Creates pde sources from a source {@link Artifact} with name @@ -57,8 +42,7 @@ public class PdeSourcesIndexer implements NodeIndexer { // int lastInd = name.lastIndexOf("["); // if (lastInd != -1) // name = name.substring(0, lastInd); - return name.endsWith("-sources") - && FilenameUtils.getExtension(path).equals("jar"); + return name.endsWith("-sources") && FilenameUtils.getExtension(path).equals("jar"); } public void index(Node sourcesNode) { @@ -68,8 +52,7 @@ public class PdeSourcesIndexer implements NodeIndexer { packageSourcesAsPdeSource(sourcesNode); } catch (Exception e) { - throw new SlcException("Cannot generate pde sources for node " - + sourcesNode, e); + throw new SlcException("Cannot generate pde sources for node " + sourcesNode, e); } } @@ -78,44 +61,34 @@ public class PdeSourcesIndexer implements NodeIndexer { Binary osgiBinary = null; try { Session session = sourcesNode.getSession(); - Artifact sourcesArtifact = AetherUtils.convertPathToArtifact( - sourcesNode.getPath(), null); + Artifact sourcesArtifact = AetherUtils.convertPathToArtifact(sourcesNode.getPath(), null); // read name version from manifest - Artifact osgiArtifact = new DefaultArtifact( - sourcesArtifact.getGroupId(), - sourcesArtifact.getArtifactId(), - sourcesArtifact.getExtension(), - sourcesArtifact.getVersion()); - String osgiPath = MavenConventionsUtils.artifactPath( - artifactBasePath, osgiArtifact); - osgiBinary = session.getNode(osgiPath).getNode(Node.JCR_CONTENT) - .getProperty(Property.JCR_DATA).getBinary(); - - NameVersion nameVersion = RepoUtils.readNameVersion(osgiBinary - .getStream()); + Artifact osgiArtifact = new DefaultArtifact(sourcesArtifact.getGroupId(), sourcesArtifact.getArtifactId(), + sourcesArtifact.getExtension(), sourcesArtifact.getVersion()); + String osgiPath = MavenConventionsUtils.artifactPath(artifactBasePath, osgiArtifact); + osgiBinary = session.getNode(osgiPath).getNode(Node.JCR_CONTENT).getProperty(Property.JCR_DATA).getBinary(); + + NameVersion nameVersion = RepoUtils.readNameVersion(osgiBinary.getStream()); + if (nameVersion == null) { + log.warn("Cannot package PDE sources for " + osgiPath + " as it is probably not an OSGi bundle"); + return; + } // create PDe sources artifact - Artifact pdeSourceArtifact = new DefaultArtifact( - sourcesArtifact.getGroupId(), - sourcesArtifact.getArtifactId() + ".source", - sourcesArtifact.getExtension(), + Artifact pdeSourceArtifact = new DefaultArtifact(sourcesArtifact.getGroupId(), + sourcesArtifact.getArtifactId() + ".source", sourcesArtifact.getExtension(), sourcesArtifact.getVersion()); - String targetSourceParentPath = MavenConventionsUtils - .artifactParentPath(artifactBasePath, pdeSourceArtifact); - String targetSourceFileName = MavenConventionsUtils - .artifactFileName(pdeSourceArtifact); + String targetSourceParentPath = MavenConventionsUtils.artifactParentPath(artifactBasePath, + pdeSourceArtifact); + String targetSourceFileName = MavenConventionsUtils.artifactFileName(pdeSourceArtifact); // String targetSourceJarPath = targetSourceParentPath + '/' // + targetSourceFileName; - Node targetSourceParentNode = JcrUtils.mkfolders(session, - targetSourceParentPath); - origBinary = sourcesNode.getNode(Node.JCR_CONTENT) - .getProperty(Property.JCR_DATA).getBinary(); - byte[] targetJarBytes = RepoUtils.packageAsPdeSource( - origBinary.getStream(), nameVersion); - JcrUtils.copyBytesAsFile(targetSourceParentNode, - targetSourceFileName, targetJarBytes); + Node targetSourceParentNode = JcrUtils.mkfolders(session, targetSourceParentPath); + origBinary = sourcesNode.getNode(Node.JCR_CONTENT).getProperty(Property.JCR_DATA).getBinary(); + byte[] targetJarBytes = RepoUtils.packageAsPdeSource(origBinary.getStream(), nameVersion); + JcrUtils.copyBytesAsFile(targetSourceParentNode, targetSourceFileName, targetJarBytes); // reindex // Automagically done via the various listeners or manually @@ -124,12 +97,10 @@ public class PdeSourcesIndexer implements NodeIndexer { // artifactIndexer.index(targetSourceJarNode); // jarFileIndexer.index(targetSourceJarNode); if (log.isTraceEnabled()) - log.trace("Created pde source artifact " + pdeSourceArtifact - + " from " + sourcesNode); + log.trace("Created pde source artifact " + pdeSourceArtifact + " from " + sourcesNode); } catch (RepositoryException e) { - throw new SlcException("Cannot add PDE sources for " + sourcesNode, - e); + throw new SlcException("Cannot add PDE sources for " + sourcesNode, e); } finally { JcrUtils.closeQuietly(origBinary); JcrUtils.closeQuietly(osgiBinary);