Improve OSGi related processes
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 21 Jun 2012 15:45:02 +0000 (15:45 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 21 Jun 2012 15:45:02 +0000 (15:45 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@5340 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java
runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/MavenConventionsUtils.java
runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ImportBundlesZip.java
runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/NormalizeGroup.java

index ff7b13d8faaa45f0ba50e4f83435ace8eb7563f5..6d22cbe687632ebcff13c7f4df87412ab4e653fd 100644 (file)
@@ -286,4 +286,13 @@ public class RepoUtils implements SlcNames {
 
        private RepoUtils() {
        }
+
+       /** If a source return the base bundle name, does not change otherwise */
+       public static String extractBundleNameFromSourceName(String sourceBundleName) {
+               if (sourceBundleName.endsWith(".source"))
+                       return sourceBundleName.substring(0, sourceBundleName.length()
+                                       - ".source".length());
+               else
+                       return sourceBundleName;
+       }
 }
index 2bf08c5b39d31ecaca75455085d82c0d2184260a..06be9eca39a6f863ae29f0d211df139a2944846c 100644 (file)
@@ -95,7 +95,7 @@ public class MavenConventionsUtils {
                // XML header
                p.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
                p.append("<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n");
-               p.append("<modelVersion>4.0.0</modelVersion>");
+               p.append("<modelVersion>4.0.0</modelVersion>\n");
 
                // Artifact
                if (parent != null) {
@@ -148,9 +148,9 @@ public class MavenConventionsUtils {
                p.append("</dependencyManagement>\n");
 
                // Repositories
-               p.append("<repositories>\n");
-               p.append("<repository><id>argeo</id><url>http://maven.argeo.org/argeo</url></repository>\n");
-               p.append("</repositories>\n");
+//             p.append("<repositories>\n");
+//             p.append("<repository><id>argeo</id><url>http://maven.argeo.org/argeo</url></repository>\n");
+//             p.append("</repositories>\n");
 
                p.append("</project>\n");
                return p.toString();
index 092101a8d8b7e822ab0819e28252057df9683247..a11f2439c7d494114df8fa7c7eadbaae447a1d43 100644 (file)
@@ -22,7 +22,6 @@ import org.argeo.slc.SlcException;
 import org.argeo.slc.repo.ArtifactIndexer;
 import org.argeo.slc.repo.JarFileIndexer;
 import org.argeo.slc.repo.RepoUtils;
-import org.argeo.slc.repo.maven.MavenConventionsUtils;
 import org.sonatype.aether.artifact.Artifact;
 import org.sonatype.aether.util.artifact.DefaultArtifact;
 
@@ -53,14 +52,14 @@ public class ImportBundlesZip implements Runnable {
                        session = repository.login(workspace);
 
                        // clear
-                       String groupPath = MavenConventionsUtils.groupPath(
-                                       artifactBasePath, groupId);
-                       if (session.itemExists(groupPath)) {
-                               session.getNode(groupPath).remove();
-                               session.save();
-                               if (log.isDebugEnabled())
-                                       log.debug("Cleared " + groupPath);
-                       }
+                       // String groupPath = MavenConventionsUtils.groupPath(
+                       // artifactBasePath, groupId);
+                       // if (session.itemExists(groupPath)) {
+                       // session.getNode(groupPath).remove();
+                       // session.save();
+                       // if (log.isDebugEnabled())
+                       // log.debug("Cleared " + groupPath);
+                       // }
 
                        zipIn = new ZipInputStream(url.openStream());
                        ZipEntry zipEntry = null;
@@ -86,10 +85,15 @@ public class ImportBundlesZip implements Runnable {
                                        continue entries;
                                }
 
+                               String bundleName = RepoUtils.extractBundleNameFromSourceName(nv
+                                               .getName());
                                // skip excluded bundles and their sources
-                               if (excludedBundles.contains(extractBundleNameFromSourceName(nv
-                                               .getName())))
+                               if (excludedBundles.contains(bundleName))
                                        continue entries;
+                               // for(String excludedBundle:excludedBundles){
+                               // if(bundleName.contains(excludedBundle))
+                               // continue entries;
+                               // }
 
                                Artifact artifact = new DefaultArtifact(groupId, nv.getName(),
                                                "jar", nv.getVersion());
@@ -115,15 +119,6 @@ public class ImportBundlesZip implements Runnable {
 
        }
 
-       /** If a source return the base bundle name, does not change otherwise */
-       private String extractBundleNameFromSourceName(String sourceBundleName) {
-               if (sourceBundleName.endsWith(".source"))
-                       return sourceBundleName.substring(0, sourceBundleName.length()
-                                       - ".source".length());
-               else
-                       return sourceBundleName;
-       }
-
        public void setRepository(Repository repository) {
                this.repository = repository;
        }
index 57cc1145c9f2e909b6c4f5c8d47f5dee19bce35d..144c15987f6e6f9c3a5cb6f3927757f6a690f3f6 100644 (file)
@@ -59,8 +59,10 @@ public class NormalizeGroup implements Runnable, SlcNames {
        private String workspace;
        private String groupId;
        private String artifactBasePath = "/";
-       private String version = "1.3.0";
-       private String parentPomCoordinates = "org.argeo:parent:1.3.0";
+       private String version = null;// = "1.3.0";
+       private String parentPomCoordinates;// = "org.argeo:parent:1.3.0";
+
+       private List<String> excludedSuffixes = new ArrayList<String>();
 
        private ArtifactIndexer artifactIndexer = new ArtifactIndexer();
        private JarFileIndexer jarFileIndexer = new JarFileIndexer();
@@ -155,8 +157,10 @@ public class NormalizeGroup implements Runnable, SlcNames {
                        Set<Artifact> 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, new DefaultArtifact(parentPomCoordinates));
+                               artifacts, parentArtifact);
                Node node = RepoUtils.copyBytesAsArtifact(
                                session.getNode(artifactBasePath), artifact, pom.getBytes());
                artifactIndexer.index(node);
@@ -178,6 +182,12 @@ public class NormalizeGroup implements Runnable, SlcNames {
 
                if (symbolicName.endsWith(".source")) {
                        // TODO make a shared node with classifier 'sources'
+                       String bundleName = RepoUtils
+                                       .extractBundleNameFromSourceName(symbolicName);
+                       for (String excludedSuffix : excludedSuffixes) {
+                               if (bundleName.endsWith(excludedSuffix))
+                                       return;// skip adding to sources
+                       }
                        sources.add(RepoUtils.asArtifact(bundleNode));
                        return;
                }
@@ -191,6 +201,10 @@ public class NormalizeGroup implements Runnable, SlcNames {
                }
 
                symbolicNamesToNodes.put(symbolicName, bundleNode);
+               for (String excludedSuffix : excludedSuffixes) {
+                       if (symbolicName.endsWith(excludedSuffix))
+                               return;// skip adding to binaries
+               }
                binaries.add(RepoUtils.asArtifact(bundleNode));
        }
 
@@ -355,4 +369,16 @@ public class NormalizeGroup implements Runnable, SlcNames {
                this.parentPomCoordinates = parentPomCoordinates;
        }
 
+       public void setArtifactBasePath(String artifactBasePath) {
+               this.artifactBasePath = artifactBasePath;
+       }
+
+       public void setVersion(String version) {
+               this.version = version;
+       }
+
+       public void setExcludedSuffixes(List<String> excludedSuffixes) {
+               this.excludedSuffixes = excludedSuffixes;
+       }
+
 }