X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=src%2Forg%2Fargeo%2Fbuild%2FRepackage.java;h=05ea8c8c4fa598acb9ea26d68d49a3aa9860dfb5;hb=cb6fcab3d5d5ac44dc42cdc792e66f547da09f29;hp=38f8e3f79343c99ca0b393bead854bff6b3ee851;hpb=8c64cf692b20399841a51979ae6d2d4ecb62ebaf;p=cc0%2Fargeo-build.git diff --git a/src/org/argeo/build/Repackage.java b/src/org/argeo/build/Repackage.java index 38f8e3f..05ea8c8 100644 --- a/src/org/argeo/build/Repackage.java +++ b/src/org/argeo/build/Repackage.java @@ -7,6 +7,7 @@ import static org.argeo.build.Repackage.ManifestConstants.EXPORT_PACKAGE; import static org.argeo.build.Repackage.ManifestConstants.SLC_ORIGIN_M2; import static org.argeo.build.Repackage.ManifestConstants.SLC_ORIGIN_M2_REPO; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -184,7 +185,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 = download(url, originBase, artifact); + Path downloaded = downloadMaven(url, originBase, artifact); Path targetBundleDir = processBndJar(downloaded, targetCategoryBase, fileProps, artifact); @@ -270,7 +271,7 @@ public class Repackage { // download URL url = M2ConventionsUtils.mavenRepoUrl(repoStr, artifact); - Path downloaded = download(url, originBase, artifact); + Path downloaded = downloadMaven(url, originBase, artifact); Path targetBundleDir = processBndJar(downloaded, targetCategoryBase, mergeProps, artifact); // logger.log(Level.DEBUG, () -> "Processed " + downloaded); @@ -310,6 +311,10 @@ public class Repackage { mergeProps.put(ManifestConstants.BUNDLE_VERSION.toString(), m2Version); String artifactsStr = mergeProps.getProperty(ManifestConstants.SLC_ORIGIN_M2_MERGE.toString()); + if (artifactsStr == null) + throw new IllegalArgumentException( + mergeBnd + ": " + ManifestConstants.SLC_ORIGIN_M2_MERGE + " must be set"); + String repoStr = mergeProps.containsKey(SLC_ORIGIN_M2_REPO.toString()) ? mergeProps.getProperty(SLC_ORIGIN_M2_REPO.toString()) : null; @@ -329,7 +334,7 @@ public class Repackage { if (artifact.getVersion() == null) artifact.setVersion(m2Version); URL url = M2ConventionsUtils.mavenRepoUrl(repoStr, artifact); - Path downloaded = download(url, originBase, artifact); + Path downloaded = downloadMaven(url, originBase, artifact); JarEntry entry; try (JarInputStream jarIn = new JarInputStream(Files.newInputStream(downloaded), false)) { entries: while ((entry = jarIn.getNextJarEntry()) != null) { @@ -507,11 +512,15 @@ public class Repackage { throws IOException { if (sourceBundles) return; - M2Artifact sourcesArtifact = new M2Artifact(artifact.toM2Coordinates(), "sources"); - URL sourcesUrl = M2ConventionsUtils.mavenRepoUrl(repoStr, sourcesArtifact); - Path sourcesDownloaded = download(sourcesUrl, originBase, artifact, true); - processM2SourceJar(sourcesDownloaded, targetBundleDir); - logger.log(Level.TRACE, () -> "Processed source " + sourcesDownloaded); + try { + M2Artifact sourcesArtifact = new M2Artifact(artifact.toM2Coordinates(), "sources"); + URL sourcesUrl = M2ConventionsUtils.mavenRepoUrl(repoStr, sourcesArtifact); + Path sourcesDownloaded = downloadMaven(sourcesUrl, originBase, artifact, true); + processM2SourceJar(sourcesDownloaded, targetBundleDir); + logger.log(Level.TRACE, () -> "Processed source " + sourcesDownloaded); + } catch (Exception e) { + logger.log(Level.ERROR, () -> "Cannot download source for " + artifact); + } } @@ -552,12 +561,12 @@ public class Repackage { } /** Download a Maven artifact. */ - protected Path download(URL url, Path dir, M2Artifact artifact) throws IOException { - return download(url, dir, artifact, false); + protected Path downloadMaven(URL url, Path dir, M2Artifact artifact) throws IOException { + return downloadMaven(url, dir, artifact, false); } /** Download a Maven artifact. */ - protected Path download(URL url, Path dir, M2Artifact artifact, boolean sources) throws IOException { + 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"); } @@ -570,7 +579,6 @@ public class Repackage { public void processEclipseArchive(Path duDir) { try { Path categoryRelativePath = descriptorsBase.relativize(duDir.getParent()); - // String category = categoryRelativePath.getFileName().toString(); Path targetCategoryBase = a2Base.resolve(categoryRelativePath); Files.createDirectories(targetCategoryBase); // first delete all directories from previous builds @@ -592,7 +600,7 @@ public class Repackage { throw new IllegalStateException("No url available for " + duDir); commonProps.put(ManifestConstants.SLC_ORIGIN_URI.toString(), url); } - Path downloaded = tryDownload(url, originBase); + Path downloaded = tryDownloadArchive(url, originBase); FileSystem zipFs = FileSystems.newFileSystem(downloaded, (ClassLoader) null); @@ -894,7 +902,7 @@ public class Repackage { } /** Try to download from an URI. */ - protected Path tryDownload(String uri, Path dir) throws IOException { + protected Path tryDownloadArchive(String uri, Path dir) throws IOException { // find mirror List urlBases = null; String uriPrefix = null; @@ -909,7 +917,7 @@ public class Repackage { } if (urlBases == null) try { - return download(new URL(uri), dir); + return downloadArchive(new URL(uri), dir); } catch (FileNotFoundException e) { throw new FileNotFoundException("Cannot find " + uri); } @@ -919,7 +927,7 @@ public class Repackage { String relativePath = uri.substring(uriPrefix.length()); URL url = new URL(urlBase + relativePath); try { - return download(url, dir); + return downloadArchive(url, dir); } catch (FileNotFoundException e) { logger.log(Level.WARNING, "Cannot download " + url + ", trying another mirror"); } @@ -927,8 +935,11 @@ public class Repackage { throw new FileNotFoundException("Cannot find " + uri); } - /** Effectively download. */ - protected Path download(URL url, Path dir) throws IOException { + /** + * Effectively download. Synchronised in order to avoid downloading twice in + * parallel. + */ + protected synchronized Path downloadArchive(URL url, Path dir) throws IOException { return download(url, dir, (String) null); } @@ -937,7 +948,9 @@ public class Repackage { Path dest; if (name == null) { - name = url.getPath().substring(url.getPath().lastIndexOf('/') + 1); + // We use also use parent directory in case the archive itself has a fixed name + name = url.getPath().substring(url.getPath().lastIndexOf('/') + 1) + .substring(url.getPath().lastIndexOf('/') + 1); } dest = dir.resolve(name); @@ -972,7 +985,8 @@ public class Repackage { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().equals("MANIFEST.MF")) return super.visitFile(file, attrs); - JarEntry entry = new JarEntry(bundleDir.relativize(file).toString()); + JarEntry entry = new JarEntry( + bundleDir.relativize(file).toString().replace(File.separatorChar, '/')); jarOut.putNextEntry(entry); Files.copy(file, jarOut); return super.visitFile(file, attrs);