- // indexes
- Set<Artifact> indexes = new TreeSet<Artifact>(
- new ArtifactIdComparator());
- Artifact indexArtifact = writeIndex(session, BINARIES_ARTIFACT_ID,
- binaries);
- indexes.add(indexArtifact);
- indexArtifact = writeIndex(session, SOURCES_ARTIFACT_ID, sources);
- indexes.add(indexArtifact);
- // sdk
- writeIndex(session, SDK_ARTIFACT_ID, indexes);
- } catch (Exception e) {
- throw new SlcException("Cannot normalize group " + groupId + " in "
- + workspace, e);
- } finally {
- JcrUtils.logoutQuietly(session);
+ // indexes
+ Set<Artifact> indexes = new TreeSet<Artifact>(
+ new ArtifactIdComparator());
+ Artifact indexArtifact = writeIndex(session,
+ RepoConstants.BINARIES_ARTIFACT_ID, binaries);
+ indexes.add(indexArtifact);
+ indexArtifact = writeIndex(session, RepoConstants.SOURCES_ARTIFACT_ID,
+ sources);
+ indexes.add(indexArtifact);
+ // sdk
+ writeIndex(session, RepoConstants.SDK_ARTIFACT_ID, indexes);
+ if (monitor != null)
+ monitor.worked(1);
+ }
+
+ private Version extractOsgiVersion(Node artifactVersion)
+ throws RepositoryException {
+ String rawVersion = artifactVersion.getProperty(SLC_ARTIFACT_VERSION)
+ .getString();
+ String cleanVersion = rawVersion.replace("-SNAPSHOT", ".SNAPSHOT");
+ 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();