]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/NormalizeGroup.java
Work on the binaries indexer.
[gpl/argeo-slc.git] / runtime / org.argeo.slc.repo / src / main / java / org / argeo / slc / repo / osgi / NormalizeGroup.java
index bc228285a0b88ad633a93c8a6993cf20075895a1..34e1aee249e0d24fee5d3c76190bb59b64efc536 100644 (file)
@@ -38,6 +38,7 @@ import org.argeo.slc.aether.ArtifactIdComparator;
 import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.jcr.SlcTypes;
 import org.argeo.slc.repo.ArtifactIndexer;
+import org.argeo.slc.repo.RepoConstants;
 import org.argeo.slc.repo.RepoUtils;
 import org.argeo.slc.repo.maven.MavenConventionsUtils;
 import org.osgi.framework.Constants;
@@ -50,10 +51,6 @@ import org.sonatype.aether.util.artifact.DefaultArtifact;
  * group of OSGi bundles.
  */
 public class NormalizeGroup implements Runnable, SlcNames {
-       public final static String BINARIES_ARTIFACT_ID = "binaries";
-       public final static String SOURCES_ARTIFACT_ID = "sources";
-       public final static String SDK_ARTIFACT_ID = "sdk";
-
        private final static Log log = LogFactory.getLog(NormalizeGroup.class);
 
        private Repository repository;
@@ -130,6 +127,17 @@ public class NormalizeGroup implements Runnable, SlcNames {
                                                        if (allArtifactsHighestVersion == null)
                                                                allArtifactsHighestVersion = aVersion;
 
+                                                       // BS will fail if artifacts arrive in this order
+                                                       // Name1 - V1, name2 - V3, V1 will remain the
+                                                       // allArtifactsHighestVersion
+                                                       // Fixed below
+                                                       else {
+                                                               Version currVersion = extractOsgiVersion(aVersion);
+                                                               Version highestVersion = extractOsgiVersion(allArtifactsHighestVersion);
+                                                               if (currVersion.compareTo(highestVersion) > 0)
+                                                                       allArtifactsHighestVersion = aVersion;
+                                                       }
+
                                                } else {
                                                        Version currVersion = extractOsgiVersion(aVersion);
                                                        Version currentHighestVersion = extractOsgiVersion(highestAVersion);
@@ -161,7 +169,7 @@ public class NormalizeGroup implements Runnable, SlcNames {
                        }
                }
 
-               // if version not set or empty, use the highets version
+               // if version not set or empty, use the highest version
                // useful when indexing a product maven repository where
                // all artifacts have the same version for a given release
                // => the version can then be left empty
@@ -170,8 +178,9 @@ public class NormalizeGroup implements Runnable, SlcNames {
                                version = allArtifactsHighestVersion.getProperty(
                                                SLC_ARTIFACT_VERSION).getString();
                        else
-                               throw new SlcException("Group version " + version
-                                               + " is empty.");
+                               version = "0.0";
+//                             throw new SlcException("Group version " + version
+//                                             + " is empty.");
 
                int bundleCount = symbolicNamesToNodes.size();
                if (log.isDebugEnabled())
@@ -190,13 +199,14 @@ public class NormalizeGroup implements Runnable, SlcNames {
                // indexes
                Set<Artifact> indexes = new TreeSet<Artifact>(
                                new ArtifactIdComparator());
-               Artifact indexArtifact = writeIndex(session, BINARIES_ARTIFACT_ID,
-                               binaries);
+               Artifact indexArtifact = writeIndex(session,
+                               RepoConstants.BINARIES_ARTIFACT_ID, binaries);
                indexes.add(indexArtifact);
-               indexArtifact = writeIndex(session, SOURCES_ARTIFACT_ID, sources);
+               indexArtifact = writeIndex(session, RepoConstants.SOURCES_ARTIFACT_ID,
+                               sources);
                indexes.add(indexArtifact);
                // sdk
-               writeIndex(session, SDK_ARTIFACT_ID, indexes);
+               writeIndex(session, RepoConstants.SDK_ARTIFACT_ID, indexes);
                if (monitor != null)
                        monitor.worked(1);
        }
@@ -234,12 +244,8 @@ public class NormalizeGroup implements Runnable, SlcNames {
 
        protected void preProcessBundleArtifact(Node bundleNode)
                        throws RepositoryException {
-               // we assume nodes are already indexed
-               // artifactIndexer.index(bundleNode);
-               // jarFileIndexer.index(bundleNode);
 
                String symbolicName = JcrUtils.get(bundleNode, SLC_SYMBOLIC_NAME);
-
                if (symbolicName.endsWith(".source")) {
                        // TODO make a shared node with classifier 'sources'?
                        String bundleName = RepoUtils
@@ -304,7 +310,6 @@ public class NormalizeGroup implements Runnable, SlcNames {
                p.append("<modelVersion>4.0.0</modelVersion>");
 
                // Artifact
-               // p.append("<parent><groupId>org.argeo</groupId><artifactId>parent</artifactId><version>1.2.0</version></parent>\n");
                p.append("<groupId>").append(JcrUtils.get(n, SLC_GROUP_ID))
                                .append("</groupId>\n");
                p.append("<artifactId>").append(JcrUtils.get(n, SLC_ARTIFACT_ID))
@@ -353,6 +358,8 @@ public class NormalizeGroup implements Runnable, SlcNames {
 
                // TODO require bundles
 
+               
+               
                List<Node> dependencyNodes = new ArrayList<Node>();
                for (String depSymbName : dependenciesSymbolicNames) {
                        if (depSymbName.equals(ownSymbolicName))
@@ -405,8 +412,9 @@ public class NormalizeGroup implements Runnable, SlcNames {
                p.append("<dependency>\n");
                p.append("\t<groupId>").append(groupId).append("</groupId>\n");
                p.append("\t<artifactId>")
-                               .append(ownSymbolicName.endsWith(".source") ? SOURCES_ARTIFACT_ID
-                                               : BINARIES_ARTIFACT_ID).append("</artifactId>\n");
+                               .append(ownSymbolicName.endsWith(".source") ? RepoConstants.SOURCES_ARTIFACT_ID
+                                               : RepoConstants.BINARIES_ARTIFACT_ID)
+                               .append("</artifactId>\n");
                p.append("\t<version>").append(version).append("</version>\n");
                p.append("\t<type>pom</type>\n");
                p.append("\t<scope>import</scope>\n");