From 7ac8a536076af44569a23d9d67bb443cdc06018b Mon Sep 17 00:00:00 2001 From: Bruno Sinou Date: Thu, 20 Mar 2014 23:26:12 +0000 Subject: [PATCH] Fix a few issues while testing and building distributions. git-svn-id: https://svn.argeo.org/slc/trunk@6904 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../META-INF/spring/commands.xml | 2 +- .../dist/commands/CopyLocalJavaWorkspace.java | 20 +++---- .../ui/dist/commands/CopyWorkspace.java | 2 +- .../java/org/argeo/slc/repo/RepoUtils.java | 13 ++++- .../slc/repo/maven/GenerateBinaries.java | 44 +++++++-------- .../argeo/slc/repo/osgi/NormalizeGroup.java | 54 ++++++++++++++++--- 6 files changed, 92 insertions(+), 43 deletions(-) diff --git a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml index d5e75b8a9..c8ec38b37 100644 --- a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml +++ b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml @@ -92,7 +92,7 @@ - + sources = new TreeSet( new ArtifactIdComparator()); - + // local cache private ArtifactIndexer artifactIndexer = new ArtifactIndexer(); private Node allArtifactsHighestVersion; @@ -94,13 +94,14 @@ 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. + * The 3 generated artifacts are then marked as modular distributions and + * indexed. */ public static void processGroupNode(Node groupNode, String version, - ArgeoMonitor monitor) - throws RepositoryException { + ArgeoMonitor monitor) throws RepositoryException { // TODO set artifactsBase based on group node GenerateBinaries gb = new GenerateBinaries(); String groupId = groupNode.getProperty(SlcNames.SLC_GROUP_BASE_ID) @@ -178,11 +179,11 @@ public class GenerateBinaries implements Runnable, SlcNames { } } } -// if (log.isDebugEnabled()) { -// int bundleCount = symbolicNamesToNodes.size(); -// log.debug("" + bundleCount + " bundles have been indexed for " -// + groupId); -// } + // if (log.isDebugEnabled()) { + // int bundleCount = symbolicNamesToNodes.size(); + // log.debug("" + bundleCount + " bundles have been indexed for " + // + groupId); + // } } /** Does the real job : writes JCR META-DATA and generates binaries */ @@ -205,18 +206,17 @@ public class GenerateBinaries implements Runnable, SlcNames { throw new SlcException("Group version " + version + " is empty."); -// int bundleCount = symbolicNamesToNodes.size(); -// -// int count = 1; -// for (Node bundleNode : symbolicNamesToNodes.values()) { -// if (log.isDebugEnabled()) -// log.debug("Processing " + bundleNode.getName() + " ( " + count -// + "/" + bundleCount + " )"); -// -// // processBundleArtifact(bundleNode); -// // bundleNode.getSession().save(); -// count++; -// } + // int bundleCount = symbolicNamesToNodes.size(); + // int count = 1; + // for (Node bundleNode : symbolicNamesToNodes.values()) { + // if (log.isDebugEnabled()) + // log.debug("Processing " + bundleNode.getName() + " ( " + count + // + "/" + bundleCount + " )"); + // + // // processBundleArtifact(bundleNode); + // // bundleNode.getSession().save(); + // count++; + // } // indexes Set indexes = new TreeSet( diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/NormalizeGroup.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/NormalizeGroup.java index 716bf345c..99f31bb04 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/NormalizeGroup.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/NormalizeGroup.java @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.StringTokenizer; import java.util.TreeSet; import javax.jcr.Node; @@ -38,7 +39,6 @@ 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.NodeIndexer; import org.argeo.slc.repo.RepoConstants; import org.argeo.slc.repo.RepoUtils; import org.argeo.slc.repo.maven.MavenConventionsUtils; @@ -51,8 +51,8 @@ import org.sonatype.aether.util.artifact.DefaultArtifact; * Make sure that all JCR metadata and Maven metadata are consistent for this * group of OSGi bundles. * - * The job is now done via the various {@code NodeIndexer} of the WorkspaceManager. - * TODO import dependencies in the workspace. + * The job is now done via the various {@code NodeIndexer} of the + * WorkspaceManager. TODO import dependencies in the workspace. */ @Deprecated public class NormalizeGroup implements Runnable, SlcNames { @@ -184,8 +184,8 @@ public class NormalizeGroup implements Runnable, SlcNames { SLC_ARTIFACT_VERSION).getString(); else version = "0.0"; -// throw new SlcException("Group version " + version -// + " is empty."); + // throw new SlcException("Group version " + version + // + " is empty."); int bundleCount = symbolicNamesToNodes.size(); if (log.isDebugEnabled()) @@ -221,7 +221,46 @@ public class NormalizeGroup implements Runnable, SlcNames { String rawVersion = artifactVersion.getProperty(SLC_ARTIFACT_VERSION) .getString(); String cleanVersion = rawVersion.replace("-SNAPSHOT", ".SNAPSHOT"); - return new Version(cleanVersion); + Version osgiVersion = null; + // log invalid version value to enable tracking them + try { + osgiVersion = new Version(cleanVersion); + } catch (IllegalArgumentException e) { + log.error("Version string " + cleanVersion + " is invalid "); + String twickedVersion = twickInvalidVersion(cleanVersion); + osgiVersion = new Version(twickedVersion); + log.error("Using " + twickedVersion + " instead"); + // throw e; + } + return osgiVersion; + } + + private String twickInvalidVersion(String tmpVersion) { + String[] tokens = tmpVersion.split("\\."); + if (tokens.length == 3 && tokens[2].lastIndexOf("-") > 0) { + String newSuffix = tokens[2].replaceFirst("-", "."); + tmpVersion = tmpVersion.replaceFirst(tokens[2], newSuffix); + } else if (tokens.length > 4) { + // FIXME manually remove other "." + StringTokenizer st = new StringTokenizer(tmpVersion, ".", true); + StringBuilder builder = new StringBuilder(); + // Major + builder.append(st.nextToken()).append(st.nextToken()); + // Minor + builder.append(st.nextToken()).append(st.nextToken()); + // Micro + builder.append(st.nextToken()).append(st.nextToken()); + // Qualifier + builder.append(st.nextToken()); + while (st.hasMoreTokens()) { + // consume delimiter + st.nextToken(); + if (st.hasMoreTokens()) + builder.append("-").append(st.nextToken()); + } + tmpVersion = builder.toString(); + } + return tmpVersion; } private Artifact writeIndex(Session session, String artifactId, @@ -363,8 +402,6 @@ public class NormalizeGroup implements Runnable, SlcNames { // TODO require bundles - - List dependencyNodes = new ArrayList(); for (String depSymbName : dependenciesSymbolicNames) { if (depSymbName.equals(ownSymbolicName)) @@ -431,6 +468,7 @@ public class NormalizeGroup implements Runnable, SlcNames { return p.toString(); } + /* DEPENDENCY INJECTION */ public void setRepository(Repository repository) { this.repository = repository; } -- 2.39.5