X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.slc.repo%2Fsrc%2Forg%2Fargeo%2Fslc%2Frepo%2Fosgi%2FArgeoOsgiDistributionImpl.java;h=7521395e849ab7ad4597e52c145d17e62839b3d6;hb=3ff90591a4e64b7459372afe4129f84fb959bbe0;hp=7d74856047292af610decc1760b17962c7c99f50;hpb=0ca31066e359f7f494f0ec7ad9b5091c46f0fa24;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/ArgeoOsgiDistributionImpl.java b/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/ArgeoOsgiDistributionImpl.java index 7d7485604..7521395e8 100644 --- a/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/ArgeoOsgiDistributionImpl.java +++ b/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/ArgeoOsgiDistributionImpl.java @@ -1,19 +1,31 @@ package org.argeo.slc.repo.osgi; +import java.io.IOException; +import java.io.Writer; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.SortedSet; +import java.util.TreeMap; import java.util.TreeSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.argeo.slc.CategorizedNameVersion; import org.argeo.slc.ModuleSet; import org.argeo.slc.NameVersion; import org.argeo.slc.build.Distribution; import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.repo.ArgeoOsgiDistribution; import org.argeo.slc.repo.ArtifactDistribution; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.osgi.framework.Constants; /** * A consistent and versioned OSGi distribution, which can be built and tested. @@ -30,6 +42,7 @@ public class ArgeoOsgiDistributionImpl extends ArtifactDistribution implements A public void init() { if (log.isDebugEnabled()) log.debug(describe()); +// migrateTov2(Paths.get(System.getProperty("user.home"), "dev/git/gpl/argeo-tp/argeo-tp")); } public void destroy() { @@ -62,6 +75,96 @@ public class ArgeoOsgiDistributionImpl extends ArtifactDistribution implements A return buf.toString(); } + public void migrateTov2(Path baseDir) { + Set archiveWrappers = new HashSet<>(); + Iterator nvIt = nameVersions(); + while (nvIt.hasNext()) { + NameVersion nv = nvIt.next(); + try { + if (nv instanceof CategorizedNameVersion) { + CategorizedNameVersion cnv = (CategorizedNameVersion) nv; + // TODO add branch? + Path categoryBase = baseDir.resolve(cnv.getCategory()); + Files.createDirectories(categoryBase); + if (cnv instanceof BndWrapper) { + BndWrapper bw = (BndWrapper) cnv; + Path bndPath = categoryBase.resolve(cnv.getName() + ".bnd"); + Map props = new TreeMap<>(); + for (Map.Entry entry : ((BndWrapper) cnv).getBndProperties().entrySet()) { + props.put(entry.getKey().toString(), entry.getValue().toString()); + } + props.put(Constants.BUNDLE_SYMBOLICNAME, cnv.getName()); + props.put(Constants.BUNDLE_VERSION, cnv.getVersion()); + if (bw.getLicense() != null) + props.put(Constants.BUNDLE_LICENSE, bw.getLicense().toString()); + else + log.warn("No license for " + cnv); + if (bw.getDoNotModify()) { + props.put("SLC-Source-Original", "true"); + } + // props.put("SLC-Category", cnv.getCategory()); + + if (cnv instanceof MavenWrapper) { + MavenWrapper mw = (MavenWrapper) cnv; + String sourceCoords = mw.getSourceCoords(); + props.put("SLC-Source-M2", sourceCoords); + Artifact mavenCnv = new DefaultArtifact(sourceCoords); + if (mavenCnv.getArtifactId().equals(cnv.getName())) + props.remove(Constants.BUNDLE_SYMBOLICNAME); + if (mavenCnv.getVersion().equals(cnv.getVersion())) + props.remove(Constants.BUNDLE_VERSION); + } else if (cnv instanceof UriWrapper) { + UriWrapper mw = (UriWrapper) cnv; + props.put("SLC-Source-URI", mw.getEffectiveUri()); + if (mw.getUri() == null && mw.getBaseUri() != null) { + log.warn("Base URI for " + cnv); + props.put("SLC-Source-BaseURI", mw.getBaseUri()); + props.put("SLC-Source-VersionSeparator", mw.getVersionSeparator()); + } + } else { + log.warn("Unidentified BND wrapper " + cnv); + } + + // write BND file + try (Writer writer = Files.newBufferedWriter(bndPath)) { + // writer.write("# " + cnv + "\n"); + props: for (String key : props.keySet()) { + String value = props.get(key); + if (Constants.EXPORT_PACKAGE.equals(key) && "*".equals(value.trim())) + continue props; + + writer.write(key + ": " + value + '\n'); + } + if (log.isTraceEnabled()) + log.trace("Wrote " + bndPath); + } + } else if (cnv instanceof OsgiCategorizedNV) { + OsgiCategorizedNV onv = (OsgiCategorizedNV) cnv; + ArchiveWrapper aw = onv.getBuild(); + archiveWrappers.add(aw); + // TODO specify and implement archive wrapper support + } else { + log.warn("Unsupported wrapper " + cnv.getClass() + " for " + cnv); + } + + } else { + log.error("Category required for " + nv + ", skipping..."); + } + } catch (IOException e) { + log.error("Could not process " + nv, e); + } + } + if (log.isDebugEnabled()) { + for (ArchiveWrapper aw : archiveWrappers) { + log.debug("Archive wrapper " + aw.getUri() + ":"); + log.debug(" includes: " + aw.getIncludes()); + log.debug(" excludes: " + aw.getExcludes()); + log.debug(" beans : " + aw.getWrappers()); + } + } + + } + public Iterator nameVersions() { List nameVersions = new ArrayList(); for (Object module : modules) {