X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=src%2Forg%2Fargeo%2Fbuild%2FRepackage.java;h=193d13426bef01494c9561e3bce25c831d6e8b01;hb=1d28b46e23fabe3bdd0ee17e27ba6160ed002b3f;hp=cf6adda2a6cec834f318ed5ddd3d1fc7bf377441;hpb=894c01e1f5a19107646e7ac870425de67423cfdd;p=cc0%2Fargeo-build.git diff --git a/src/org/argeo/build/Repackage.java b/src/org/argeo/build/Repackage.java index cf6adda..193d134 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; @@ -100,8 +103,11 @@ public class Repackage { 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)) @@ -191,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); @@ -206,7 +212,6 @@ public class Repackage { /** Process multiple Maven artifacts. */ public void processM2BasedDistributionUnit(Path duDir) { try { - // String category = duDir.getParent().getFileName().toString(); Path categoryRelativePath = descriptorsBase.relativize(duDir.getParent()); Path targetCategoryBase = a2Base.resolve(categoryRelativePath); @@ -214,7 +219,6 @@ public class Repackage { Path mergeBnd = duDir.resolve(MERGE_BND); if (Files.exists(mergeBnd)) { mergeM2Artifacts(mergeBnd); -// return; } Path commonBnd = duDir.resolve(COMMON_BND); @@ -277,7 +281,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); @@ -329,7 +333,14 @@ public class Repackage { if (bundleSymbolicName == null) throw new IllegalArgumentException("Bundle-SymbolicName must be set in " + mergeBnd); CategoryNameVersion nameVersion = new M2Artifact(category + ":" + bundleSymbolicName + ":" + m2Version); + Path targetBundleDir = targetCategoryBase.resolve(bundleSymbolicName + "." + nameVersion.getBranch()); + if (Files.exists(targetBundleDir)) { + logger.log(WARNING, targetBundleDir + " exists, deleting it..."); + deleteDirectory(targetBundleDir); + } else { + Files.createDirectories(targetBundleDir); + } String[] artifacts = artifactsStr.split(","); artifacts: for (String str : artifacts) { @@ -340,7 +351,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) { @@ -521,7 +532,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) { @@ -537,9 +548,9 @@ public class Repackage { ? targetBundleDir.getParent().resolve(targetBundleDir.toString() + ".src") : targetBundleDir.resolve("OSGI-OPT/src"); - // TODO make it less dangerous? if (Files.exists(targetSourceDir)) { -// deleteDirectory(targetSourceDir); + logger.log(WARNING, targetSourceDir + " exists, deleting it..."); + deleteDirectory(targetSourceDir); } else { Files.createDirectories(targetSourceDir); } @@ -569,14 +580,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"); } /* @@ -590,9 +602,8 @@ public class Repackage { Path targetCategoryBase = a2Base.resolve(categoryRelativePath); Files.createDirectories(targetCategoryBase); // first delete all directories from previous builds - for (Path dir : Files.newDirectoryStream(targetCategoryBase, (p) -> Files.isDirectory(p))) { + for (Path dir : Files.newDirectoryStream(targetCategoryBase, (p) -> Files.isDirectory(p))) deleteDirectory(dir); - } Files.createDirectories(originBase); @@ -696,9 +707,9 @@ public class Repackage { ? targetBundleDir.getParent().resolve(targetBundleDir.toString() + ".src") : targetBundleDir.resolve("OSGI-OPT/src"); - // TODO make it less dangerous? if (Files.exists(targetSourceDir)) { -// deleteDirectory(targetSourceDir); + logger.log(WARNING, targetSourceDir + " exists, deleting it..."); + deleteDirectory(targetSourceDir); } else { Files.createDirectories(targetSourceDir); } @@ -771,6 +782,12 @@ public class Repackage { } } targetBundleDir = targetBase.resolve(nameVersion.getName() + "." + nameVersion.getBranch()); + if (Files.exists(targetBundleDir)) { + logger.log(WARNING, targetBundleDir + " exists, deleting it..."); + deleteDirectory(targetBundleDir); + } else { + Files.createDirectories(targetBundleDir); + } // force Java 9 module name entries.put(ManifestConstants.AUTOMATIC_MODULE_NAME.toString(), nameVersion.getName()); @@ -1015,9 +1032,10 @@ public class Repackage { return jarPath; } - Path guessedA2Base = bundleCategoryDir.getParent(); - Path srcA2Base = guessedA2Base.getParent().resolve(guessedA2Base.getFileName() + ".src"); - Path srcJarP = srcA2Base.resolve(bundleCategoryDir.getFileName()).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();