X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.repo%2Fsrc%2Forg%2Fargeo%2Fslc%2Frepo%2FModularDistributionFactory.java;h=25b6c48c4f9f4d1d5408c4c0464e6d8586f0b5dc;hb=94c490f2eca7bf99909070353d498d232e105810;hp=af96f232d10198084a4bb926d023175dbf7969b8;hpb=40fb326ca1e1e45f95e3a89c23fc3d07177da20d;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.repo/src/org/argeo/slc/repo/ModularDistributionFactory.java b/org.argeo.slc.repo/src/org/argeo/slc/repo/ModularDistributionFactory.java index af96f232d..25b6c48c4 100644 --- a/org.argeo.slc.repo/src/org/argeo/slc/repo/ModularDistributionFactory.java +++ b/org.argeo.slc.repo/src/org/argeo/slc/repo/ModularDistributionFactory.java @@ -6,6 +6,9 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.Iterator; import java.util.jar.Attributes; import java.util.jar.JarEntry; @@ -22,18 +25,20 @@ import org.argeo.jcr.JcrUtils; import org.argeo.slc.CategorizedNameVersion; import org.argeo.slc.NameVersion; import org.argeo.slc.SlcException; -import org.osgi.framework.Constants; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.DefaultArtifact; +import org.osgi.framework.Constants; /** * Creates a jar bundle from an ArgeoOsgiDistribution. This jar is then * persisted and indexed in a java repository using the OSGI Factory. * - * It does the following
  • Creates a Manifest
  • Creates files - * indexes (csv, feature.xml ...)
  • Populate the corresponding jar
  • - * Save it in the repository
  • Index the node and creates corresponding - * sha1 and md5 files
  • + * It does the following + *
  • Creates a Manifest
  • + *
  • Creates files indexes (csv, feature.xml ...)
  • + *
  • Populate the corresponding jar
  • + *
  • Save it in the repository
  • + *
  • Index the node and creates corresponding sha1 and md5 files
  • * */ public class ModularDistributionFactory implements Runnable { @@ -47,13 +52,13 @@ public class ModularDistributionFactory implements Runnable { // Constants private final static String CSV_FILE_NAME = "modularDistribution.csv"; + private final DateFormat snapshotTimestamp = new SimpleDateFormat("YYYYMMddhhmm"); // private final static String FEATURE_FILE_NAME = "feature.xml"; // private static int BUFFER_SIZE = 10240; /** Convenience constructor with minimal configuration */ - public ModularDistributionFactory(OsgiFactory osgiFactory, - ArgeoOsgiDistribution osgiDistribution) { + public ModularDistributionFactory(OsgiFactory osgiFactory, ArgeoOsgiDistribution osgiDistribution) { this.osgiFactory = osgiFactory; this.osgiDistribution = osgiDistribution; } @@ -69,18 +74,14 @@ public class ModularDistributionFactory implements Runnable { else if (artifactType == "pom") distFile = generatePomFile(); else - throw new SlcException( - "Unimplemented distribution artifact type: " - + artifactType + " for " - + osgiDistribution.toString()); + throw new SlcException("Unimplemented distribution artifact type: " + artifactType + " for " + + osgiDistribution.toString()); // Save in java repository - Artifact osgiArtifact = new DefaultArtifact( - osgiDistribution.getCategory(), osgiDistribution.getName(), + Artifact osgiArtifact = new DefaultArtifact(osgiDistribution.getCategory(), osgiDistribution.getName(), artifactType, osgiDistribution.getVersion()); - Node distNode = RepoUtils.copyBytesAsArtifact( - javaSession.getNode(artifactBasePath), osgiArtifact, + Node distNode = RepoUtils.copyBytesAsArtifact(javaSession.getNode(artifactBasePath), osgiArtifact, distFile); // index @@ -90,8 +91,7 @@ public class ModularDistributionFactory implements Runnable { javaSession.save(); } catch (RepositoryException e) { throw new SlcException( - "JCR error while persisting modular distribution in JCR " - + osgiDistribution.toString(), e); + "JCR error while persisting modular distribution in JCR " + osgiDistribution.toString(), e); } finally { JcrUtils.logoutQuietly(javaSession); } @@ -108,9 +108,7 @@ public class ModularDistributionFactory implements Runnable { jarOut.close(); return byteOut.toByteArray(); } catch (IOException e) { - throw new SlcException( - "IO error while generating modular distribution " - + osgiDistribution.toString(), e); + throw new SlcException("IO error while generating modular distribution " + osgiDistribution.toString(), e); } finally { IOUtils.closeQuietly(byteOut); IOUtils.closeQuietly(jarOut); @@ -141,32 +139,29 @@ public class ModularDistributionFactory implements Runnable { Manifest manifest = new Manifest(); // TODO make this configurable - manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, - "1.0"); - addManifestAttribute(manifest, - Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "JavaSE-1.6"); + manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); +// addManifestAttribute(manifest, Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "JavaSE-1.8"); addManifestAttribute(manifest, Constants.BUNDLE_VENDOR, "Argeo"); addManifestAttribute(manifest, Constants.BUNDLE_MANIFESTVERSION, "2"); - addManifestAttribute(manifest, "Bundle-License", - "http://www.apache.org/licenses/LICENSE-2.0.txt"); +// addManifestAttribute(manifest, "Bundle-License", "http://www.apache.org/licenses/LICENSE-2.0.txt"); // TODO define a user friendly name - addManifestAttribute(manifest, Constants.BUNDLE_NAME, - osgiDistribution.getName()); + addManifestAttribute(manifest, Constants.BUNDLE_NAME, osgiDistribution.getName()); // Categorized name version - addManifestAttribute(manifest, RepoConstants.SLC_GROUP_ID, - osgiDistribution.getCategory()); - addManifestAttribute(manifest, Constants.BUNDLE_SYMBOLICNAME, - osgiDistribution.getName()); - addManifestAttribute(manifest, Constants.BUNDLE_VERSION, - osgiDistribution.getVersion()); + addManifestAttribute(manifest, RepoConstants.SLC_GROUP_ID, osgiDistribution.getCategory()); + addManifestAttribute(manifest, Constants.BUNDLE_SYMBOLICNAME, osgiDistribution.getName()); + String version = osgiDistribution.getVersion(); + if (version.endsWith("-SNAPSHOT")) { + version = version.substring(0, version.length() - "-SNAPSHOT".length()); + version = version + ".SNAPSHOT-r" + snapshotTimestamp.format(new Date()); + } + addManifestAttribute(manifest, Constants.BUNDLE_VERSION, version); return manifest; } - private void addManifestAttribute(Manifest manifest, String name, - String value) { + private void addManifestAttribute(Manifest manifest, String name, String value) { manifest.getMainAttributes().put(new Attributes.Name(name), value); } @@ -178,15 +173,12 @@ public class ModularDistributionFactory implements Runnable { tmpFile.deleteOnExit(); writer = new FileWriter(tmpFile); // Populate the file - for (Iterator it = osgiDistribution - .nameVersions(); it.hasNext();) + for (Iterator it = osgiDistribution.nameVersions(); it.hasNext();) writer.write(getCsvLine(it.next())); writer.flush(); return FileUtils.readFileToByteArray(tmpFile); } catch (Exception e) { - throw new SlcException( - "unable to create csv distribution file for " - + osgiDistribution.toString(), e); + throw new SlcException("unable to create csv distribution file for " + osgiDistribution.toString(), e); } finally { IOUtils.closeQuietly(writer); } @@ -404,28 +396,25 @@ public class ModularDistributionFactory implements Runnable { StringBuilder b = new StringBuilder(); // XML header b.append("\n"); - b.append("\n"); + b.append( + "\n"); b.append("4.0.0"); // Artifact - b.append("").append(osgiDistribution.getCategory()) - .append("\n"); - b.append("").append(osgiDistribution.getName()) - .append("\n"); - b.append("").append(osgiDistribution.getVersion()) - .append("\n"); + b.append("").append(osgiDistribution.getCategory()).append("\n"); + b.append("").append(osgiDistribution.getName()).append("\n"); + b.append("").append(osgiDistribution.getVersion()).append("\n"); b.append("pom\n"); // p.append("").append("Bundle Name").append("\n"); - // p.append("").append("Bundle Description").append("\n"); + // p.append("").append("Bundle + // Description").append("\n"); // Dependencies b.append("\n"); - for (Iterator it = osgiDistribution - .nameVersions(); it.hasNext();) { + for (Iterator it = osgiDistribution.nameVersions(); it.hasNext();) { NameVersion nameVersion = it.next(); if (!(nameVersion instanceof CategorizedNameVersion)) - throw new SlcException("Unsupported type " - + nameVersion.getClass()); + throw new SlcException("Unsupported type " + nameVersion.getClass()); CategorizedNameVersion nv = (CategorizedNameVersion) nameVersion; b.append(getDependencySnippet(nv, false)); } @@ -435,10 +424,8 @@ public class ModularDistributionFactory implements Runnable { b.append("\n"); b.append("\n"); - for (Iterator it = osgiDistribution - .nameVersions(); it.hasNext();) - b.append(getDependencySnippet((CategorizedNameVersion) it.next(), - true)); + for (Iterator it = osgiDistribution.nameVersions(); it.hasNext();) + b.append(getDependencySnippet((CategorizedNameVersion) it.next(), true)); b.append("\n"); b.append("\n"); @@ -446,17 +433,14 @@ public class ModularDistributionFactory implements Runnable { return b.toString().getBytes(); } - private String getDependencySnippet(CategorizedNameVersion cnv, - boolean includeVersion) { // , String type, String scope + private String getDependencySnippet(CategorizedNameVersion cnv, boolean includeVersion) { // , String type, String + // scope StringBuilder b = new StringBuilder(); b.append("\n"); - b.append("\t").append(cnv.getCategory()) - .append("\n"); - b.append("\t").append(cnv.getName()) - .append("\n"); + b.append("\t").append(cnv.getCategory()).append("\n"); + b.append("\t").append(cnv.getName()).append("\n"); if (includeVersion) - b.append("\t").append(cnv.getVersion()) - .append("\n"); + b.append("\t").append(cnv.getVersion()).append("\n"); // if (type!= null) // p.append("\t").append(type).append("\n"); // if (type!= null) @@ -466,8 +450,7 @@ public class ModularDistributionFactory implements Runnable { } // Helpers - private void addToJar(byte[] content, String name, JarOutputStream target) - throws IOException { + private void addToJar(byte[] content, String name, JarOutputStream target) throws IOException { ByteArrayInputStream in = null; try { target.putNextEntry(new JarEntry(name)); @@ -485,8 +468,7 @@ public class ModularDistributionFactory implements Runnable { } } - private String getCsvLine(NameVersion nameVersion) - throws RepositoryException { + private String getCsvLine(NameVersion nameVersion) throws RepositoryException { if (!(nameVersion instanceof CategorizedNameVersion)) throw new SlcException("Unsupported type " + nameVersion.getClass()); CategorizedNameVersion cnv = (CategorizedNameVersion) nameVersion; @@ -523,8 +505,7 @@ public class ModularDistributionFactory implements Runnable { this.osgiDistribution = osgiDistribution; } - public void setModularDistributionSeparator( - String modularDistributionSeparator) { + public void setModularDistributionSeparator(String modularDistributionSeparator) { this.modularDistributionSeparator = modularDistributionSeparator; }