import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.StringTokenizer;
import java.util.TreeSet;
import javax.jcr.Node;
/**
* 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.
*/
+@Deprecated
public class NormalizeGroup implements Runnable, SlcNames {
private final static Log log = LogFactory.getLog(NormalizeGroup.class);
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);
}
}
- // 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
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())
// indexes
Set<Artifact> indexes = new TreeSet<Artifact>(
new ArtifactIdComparator());
- Artifact indexArtifact = writeIndex(session, RepoConstants.BINARIES_ARTIFACT_ID,
- binaries);
+ Artifact indexArtifact = writeIndex(session,
+ RepoConstants.BINARIES_ARTIFACT_ID, binaries);
indexes.add(indexArtifact);
- indexArtifact = writeIndex(session, RepoConstants.SOURCES_ARTIFACT_ID, sources);
+ indexArtifact = writeIndex(session, RepoConstants.SOURCES_ARTIFACT_ID,
+ sources);
indexes.add(indexArtifact);
// sdk
writeIndex(session, RepoConstants.SDK_ARTIFACT_ID, indexes);
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,
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
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))
p.append("\t<groupId>").append(groupId).append("</groupId>\n");
p.append("\t<artifactId>")
.append(ownSymbolicName.endsWith(".source") ? RepoConstants.SOURCES_ARTIFACT_ID
- : RepoConstants.BINARIES_ARTIFACT_ID).append("</artifactId>\n");
+ : 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");
return p.toString();
}
+ /* DEPENDENCY INJECTION */
public void setRepository(Repository repository) {
this.repository = repository;
}