X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=src%2Forg%2Fargeo%2Fbuild%2FRepackage.java;h=55003c144ef1d7bf8df219c19449939d6b4d5948;hb=cf1c40e568422cf1a18ef17b0af15408f6f57b5c;hp=4f0089a3204fb8e1803b155f99e33efa4117303d;hpb=3bf6a139f456ff71bec3bc61d8cd14a1d058133a;p=cc0%2Fargeo-build.git diff --git a/src/org/argeo/build/Repackage.java b/src/org/argeo/build/Repackage.java index 4f0089a..55003c1 100644 --- a/src/org/argeo/build/Repackage.java +++ b/src/org/argeo/build/Repackage.java @@ -81,7 +81,10 @@ public class Repackage { private final static String MERGE_BND = "merge.bnd"; private Path originBase; + private Path mavenBase; + private Path a2Base; + private Path a2SrcBase; private Path a2LibBase; private Path descriptorsBase; @@ -93,19 +96,18 @@ public class Repackage { private final boolean sourceBundles; public Repackage(Path a2Base, Path descriptorsBase) { - if (System.getenv(ENV_BUILD_SOURCE_BUNDLES) != null) { - sourceBundles = Boolean.parseBoolean(System.getenv(ENV_BUILD_SOURCE_BUNDLES)); - if (sourceBundles) - logger.log(Level.INFO, "Sources will be packaged separately"); - } else { - sourceBundles = true; - } + sourceBundles = Boolean.parseBoolean(System.getenv(ENV_BUILD_SOURCE_BUNDLES)); + if (sourceBundles) + logger.log(Level.INFO, "Sources will be packaged separately"); Objects.requireNonNull(a2Base); Objects.requireNonNull(descriptorsBase); this.originBase = Paths.get(System.getProperty("user.home"), ".cache", "argeo/build/origin"); + this.mavenBase = Paths.get(System.getProperty("user.home"), ".m2", "repository"); + // TODO define and use a build base this.a2Base = a2Base; + this.a2SrcBase = a2Base.getParent().resolve(a2Base.getFileName() + ".src"); this.a2LibBase = a2Base.resolve("lib"); this.descriptorsBase = descriptorsBase; if (!Files.exists(this.descriptorsBase)) @@ -195,7 +197,7 @@ public class Repackage { throw new IllegalArgumentException("No M2 coordinates available for " + bndFile); M2Artifact artifact = new M2Artifact(m2Coordinates); URL url = M2ConventionsUtils.mavenRepoUrl(repoStr, artifact); - Path downloaded = downloadMaven(url, originBase, artifact); + Path downloaded = downloadMaven(url, artifact); Path targetBundleDir = processBndJar(downloaded, targetCategoryBase, fileProps, artifact); @@ -281,7 +283,7 @@ public class Repackage { // download URL url = M2ConventionsUtils.mavenRepoUrl(repoStr, artifact); - Path downloaded = downloadMaven(url, originBase, artifact); + Path downloaded = downloadMaven(url, artifact); Path targetBundleDir = processBndJar(downloaded, targetCategoryBase, mergeProps, artifact); // logger.log(Level.DEBUG, () -> "Processed " + downloaded); @@ -344,7 +346,7 @@ public class Repackage { if (artifact.getVersion() == null) artifact.setVersion(m2Version); URL url = M2ConventionsUtils.mavenRepoUrl(repoStr, artifact); - Path downloaded = downloadMaven(url, originBase, artifact); + Path downloaded = downloadMaven(url, artifact); JarEntry entry; try (JarInputStream jarIn = new JarInputStream(Files.newInputStream(downloaded), false)) { entries: while ((entry = jarIn.getNextJarEntry()) != null) { @@ -525,7 +527,7 @@ public class Repackage { try { M2Artifact sourcesArtifact = new M2Artifact(artifact.toM2Coordinates(), "sources"); URL sourcesUrl = M2ConventionsUtils.mavenRepoUrl(repoStr, sourcesArtifact); - Path sourcesDownloaded = downloadMaven(sourcesUrl, originBase, artifact, true); + Path sourcesDownloaded = downloadMaven(sourcesUrl, artifact, true); processM2SourceJar(sourcesDownloaded, targetBundleDir); logger.log(Level.TRACE, () -> "Processed source " + sourcesDownloaded); } catch (Exception e) { @@ -573,14 +575,15 @@ public class Repackage { } /** Download a Maven artifact. */ - protected Path downloadMaven(URL url, Path dir, M2Artifact artifact) throws IOException { - return downloadMaven(url, dir, artifact, false); + protected Path downloadMaven(URL url, M2Artifact artifact) throws IOException { + return downloadMaven(url, artifact, false); } /** Download a Maven artifact. */ - protected Path downloadMaven(URL url, Path dir, M2Artifact artifact, boolean sources) throws IOException { - return download(url, dir, artifact.getGroupId() + '/' + artifact.getArtifactId() + "-" + artifact.getVersion() - + (sources ? "-sources" : "") + ".jar"); + protected Path downloadMaven(URL url, M2Artifact artifact, boolean sources) throws IOException { + return download(url, mavenBase, artifact.getGroupId().replace(".", "/") // + + '/' + artifact.getArtifactId() + '/' + artifact.getVersion() // + + '/' + artifact.getArtifactId() + "-" + artifact.getVersion() + (sources ? "-sources" : "") + ".jar"); } /* @@ -1012,12 +1015,19 @@ public class Repackage { deleteDirectory(bundleDir); if (sourceBundles) { - Path sourceDir = bundleDir.getParent().resolve(bundleDir.toString() + ".src"); + Path bundleCategoryDir = bundleDir.getParent(); + Path sourceDir = bundleCategoryDir.resolve(bundleDir.toString() + ".src"); if (!Files.exists(sourceDir)) { logger.log(WARNING, sourceDir + " does not exist, skipping..."); return jarPath; + } - Path srcJarP = sourceDir.getParent().resolve(sourceDir.getFileName() + ".jar"); + + Path relPath = a2Base.relativize(bundleCategoryDir); + Path srcCategoryDir = a2SrcBase.resolve(relPath); + Path srcJarP = srcCategoryDir.resolve(sourceDir.getFileName() + ".jar"); + Files.createDirectories(srcJarP.getParent()); + String bundleSymbolicName = manifest.getMainAttributes().getValue("Bundle-SymbolicName").toString(); // in case there are additional directives bundleSymbolicName = bundleSymbolicName.split(";")[0];