]> git.argeo.org Git - cc0/argeo-build.git/blobdiff - src/org/argeo/build/Repackage.java
Make Eclipse mirrors configurable
[cc0/argeo-build.git] / src / org / argeo / build / Repackage.java
index d902efb1a5c2656101fe8d4e4a44e6d65822e6fd..de99e5f8c453af44d532d69f67db3952ddafc204 100644 (file)
@@ -15,6 +15,7 @@ import java.lang.System.Logger;
 import java.lang.System.Logger.Level;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.DirectoryStream;
 import java.nio.file.FileSystem;
 import java.nio.file.FileSystems;
@@ -28,6 +29,7 @@ import java.nio.file.StandardOpenOption;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -90,6 +92,7 @@ public class Repackage {
                        throw new IllegalArgumentException(this.descriptorsBase + " does not exist");
                this.includeSources = includeSources;
 
+               // URIs mapping
                Path urisPath = this.descriptorsBase.resolve("uris.properties");
                if (Files.exists(urisPath)) {
                        try (InputStream in = Files.newInputStream(urisPath)) {
@@ -99,11 +102,21 @@ public class Repackage {
                        }
                }
 
-               // TODO make it configurable
+               // Eclipse mirrors
+               Path eclipseMirrorsPath = this.descriptorsBase.resolve("eclipse.mirrors.txt");
                List<String> eclipseMirrors = new ArrayList<>();
-               eclipseMirrors.add("https://archive.eclipse.org/");
-               eclipseMirrors.add("http://ftp-stud.hs-esslingen.de/Mirrors/eclipse/");
-               eclipseMirrors.add("http://ftp.fau.de/eclipse/");
+               if (Files.exists(eclipseMirrorsPath)) {
+                       try {
+                               eclipseMirrors = Files.readAllLines(eclipseMirrorsPath, StandardCharsets.UTF_8);
+                       } catch (IOException e) {
+                               throw new IllegalStateException("Cannot load " + eclipseMirrorsPath, e);
+                       }
+                       for (Iterator<String> it = eclipseMirrors.iterator(); it.hasNext();) {
+                               String value = it.next();
+                               if (value.strip().equals(""))
+                                       it.remove();
+                       }
+               }
 
                mirrors.put("http://www.eclipse.org/downloads", eclipseMirrors);
        }
@@ -609,7 +622,7 @@ public class Repackage {
                                                if (includeMatcher.matches(file)) {
                                                        for (PathMatcher excludeMatcher : excludeMatchers) {
                                                                if (excludeMatcher.matches(file)) {
-                                                                       logger.log(Level.WARNING, "Skipping excluded " + file);
+                                                                       logger.log(Level.TRACE, "Skipping excluded " + file);
                                                                        return FileVisitResult.CONTINUE;
                                                                }
                                                        }
@@ -696,6 +709,21 @@ public class Repackage {
                        Manifest sourceManifest = jarIn.getManifest();
                        Manifest manifest = sourceManifest != null ? new Manifest(sourceManifest) : new Manifest();
 
+                       // singleton
+                       boolean isSingleton = false;
+                       String rawSourceSymbolicName = manifest.getMainAttributes()
+                                       .getValue(ManifestConstants.BUNDLE_SYMBOLICNAME.toString());
+                       if (rawSourceSymbolicName != null) {
+
+                               // make sure there is no directive
+                               String[] arr = rawSourceSymbolicName.split(";");
+                               for (int i = 1; i < arr.length; i++) {
+                                       if (arr[i].trim().equals("singleton:=true"))
+                                               isSingleton = true;
+                                       logger.log(DEBUG, file.getFileName() + " is a singleton");
+                               }
+                       }
+
                        // remove problematic entries in MANIFEST
                        manifest.getEntries().clear();
 
@@ -786,6 +814,12 @@ public class Repackage {
                        // copy MANIFEST
                        Path manifestPath = targetBundleDir.resolve("META-INF/MANIFEST.MF");
                        Files.createDirectories(manifestPath.getParent());
+
+                       if (isSingleton && entries.containsKey(BUNDLE_SYMBOLICNAME.toString())) {
+                               entries.put(BUNDLE_SYMBOLICNAME.toString(),
+                                               entries.get(BUNDLE_SYMBOLICNAME.toString()) + ";singleton:=true");
+                       }
+
                        for (String key : entries.keySet()) {
                                String value = entries.get(key);
                                Object previousValue = manifest.getMainAttributes().putValue(key, value);