Latest bnd code
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1350613 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/aQute/lib/deployer/FileInstallRepo.java b/bundleplugin/src/main/java/aQute/lib/deployer/FileInstallRepo.java
index 780c32f..cd98036 100644
--- a/bundleplugin/src/main/java/aQute/lib/deployer/FileInstallRepo.java
+++ b/bundleplugin/src/main/java/aQute/lib/deployer/FileInstallRepo.java
@@ -13,138 +13,137 @@
public class FileInstallRepo extends FileRepo {
- String group;
- boolean dirty;
- Reporter reporter;
- Pattern REPO_FILE = Pattern
- .compile("([-a-zA-z0-9_\\.]+)-([0-9\\.]+)\\.(jar|lib)");
-
- public void setProperties(Map<String, String> map) {
- super.setProperties(map);
- group = map.get("group");
- }
- public void setReporter(Reporter reporter) {
- super.setReporter(reporter);
- this.reporter = reporter;
- }
+ String group;
+ boolean dirty;
+ Reporter reporter;
+ Pattern REPO_FILE = Pattern.compile("([-a-zA-z0-9_\\.]+)-([0-9\\.]+)\\.(jar|lib)");
- public File put(Jar jar) throws Exception {
- dirty = true;
- Manifest manifest = jar.getManifest();
- if (manifest == null)
- throw new IllegalArgumentException("No manifest in JAR: " + jar);
+ public void setProperties(Map<String,String> map) {
+ super.setProperties(map);
+ group = map.get("group");
+ }
- String bsn = manifest.getMainAttributes().getValue(
- Analyzer.BUNDLE_SYMBOLICNAME);
- if (bsn == null)
- throw new IllegalArgumentException("No Bundle SymbolicName set");
+ public void setReporter(Reporter reporter) {
+ super.setReporter(reporter);
+ this.reporter = reporter;
+ }
- Parameters b = Processor.parseHeader(bsn, null);
- if (b.size() != 1)
- throw new IllegalArgumentException("Multiple bsn's specified " + b);
+ public File put(Jar jar) throws Exception {
+ dirty = true;
+ Manifest manifest = jar.getManifest();
+ if (manifest == null)
+ throw new IllegalArgumentException("No manifest in JAR: " + jar);
- for (String key : b.keySet()) {
- bsn = key;
- if (!Verifier.SYMBOLICNAME.matcher(bsn).matches())
- throw new IllegalArgumentException(
- "Bundle SymbolicName has wrong format: " + bsn);
- }
+ String bsn = manifest.getMainAttributes().getValue(Analyzer.BUNDLE_SYMBOLICNAME);
+ if (bsn == null)
+ throw new IllegalArgumentException("No Bundle SymbolicName set");
- String versionString = manifest.getMainAttributes().getValue(
- Analyzer.BUNDLE_VERSION);
- Version version;
- if (versionString == null)
- version = new Version();
- else
- version = new Version(versionString);
+ Parameters b = Processor.parseHeader(bsn, null);
+ if (b.size() != 1)
+ throw new IllegalArgumentException("Multiple bsn's specified " + b);
- File dir;
- if (group == null) {
- dir = getRoot();
- } else {
- dir= new File(getRoot(), group);
- dir.mkdirs();
- }
- String fName = bsn + "-" + version.getMajor() + "."
- + version.getMinor() + "." + version.getMicro() + ".jar";
- File file = new File(dir, fName);
+ for (String key : b.keySet()) {
+ bsn = key;
+ if (!Verifier.SYMBOLICNAME.matcher(bsn).matches())
+ throw new IllegalArgumentException("Bundle SymbolicName has wrong format: " + bsn);
+ }
- jar.write(file);
- fireBundleAdded(jar, file);
+ String versionString = manifest.getMainAttributes().getValue(Analyzer.BUNDLE_VERSION);
+ Version version;
+ if (versionString == null)
+ version = new Version();
+ else
+ version = new Version(versionString);
- file = new File(dir, bsn + "-latest.jar");
- if (file.isFile() && file.lastModified() < jar.lastModified()) {
- jar.write(file);
- }
- return file;
- }
- public boolean refresh() {
- if ( dirty ) {
- dirty = false;
- return true;
- } else
- return false;
- }
+ File dir;
+ if (group == null) {
+ dir = getRoot();
+ } else {
+ dir = new File(getRoot(), group);
+ dir.mkdirs();
+ }
+ String fName = bsn + "-" + version.getMajor() + "." + version.getMinor() + "." + version.getMicro() + ".jar";
+ File file = new File(dir, fName);
+
+ jar.write(file);
+ fireBundleAdded(jar, file);
+
+ file = new File(dir, bsn + "-latest.jar");
+ if (file.isFile() && file.lastModified() < jar.lastModified()) {
+ jar.write(file);
+ }
+ return file;
+ }
+
+ public boolean refresh() {
+ if (dirty) {
+ dirty = false;
+ return true;
+ } else
+ return false;
+ }
+
@Override
public List<String> list(String regex) {
- Instruction pattern = null;
- if (regex != null)
- pattern = new Instruction(regex);
+ Instruction pattern = null;
+ if (regex != null)
+ pattern = new Instruction(regex);
- String list[] = getRoot().list();
- List<String> result = new ArrayList<String>();
- for (String f : list) {
- Matcher m = REPO_FILE.matcher(f);
- if (!m.matches()) {
- continue;
- }
- String s = m.group(1);
- if (pattern == null || pattern.matches(s))
- result.add(s);
- }
- return result;
+ String list[] = getRoot().list();
+ List<String> result = new ArrayList<String>();
+ for (String f : list) {
+ Matcher m = REPO_FILE.matcher(f);
+ if (!m.matches()) {
+ continue;
+ }
+ String s = m.group(1);
+ if (pattern == null || pattern.matches(s))
+ result.add(s);
+ }
+ return result;
}
+
@Override
public File[] get(String bsn, String versionRange) throws MalformedURLException {
- // If the version is set to project, we assume it is not
- // for us. A project repo will then get it.
- if (versionRange != null && versionRange.equals("project"))
- return null;
+ // If the version is set to project, we assume it is not
+ // for us. A project repo will then get it.
+ if (versionRange != null && versionRange.equals("project"))
+ return null;
- //
- // The version range we are looking for can
- // be null (for all) or a version range.
- //
- VersionRange range;
- if (versionRange == null || versionRange.equals("latest")) {
- range = new VersionRange("0");
- } else
- range = new VersionRange(versionRange);
+ //
+ // The version range we are looking for can
+ // be null (for all) or a version range.
+ //
+ VersionRange range;
+ if (versionRange == null || versionRange.equals("latest")) {
+ range = new VersionRange("0");
+ } else
+ range = new VersionRange(versionRange);
- //
- // Iterator over all the versions for this BSN.
- // Create a sorted map over the version as key
- // and the file as URL as value. Only versions
- // that match the desired range are included in
- // this list.
- //
- File instances[] = getRoot().listFiles();
- SortedMap<Version, File> versions = new TreeMap<Version, File>();
- for (int i = 0; i < instances.length; i++) {
- Matcher m = REPO_FILE.matcher(instances[i].getName());
- if (m.matches() && m.group(1).equals(bsn)) {
- String versionString = m.group(2);
- Version version;
- if (versionString.equals("latest"))
- version = new Version(Integer.MAX_VALUE);
- else
- version = new Version(versionString);
+ //
+ // Iterator over all the versions for this BSN.
+ // Create a sorted map over the version as key
+ // and the file as URL as value. Only versions
+ // that match the desired range are included in
+ // this list.
+ //
+ File instances[] = getRoot().listFiles();
+ SortedMap<Version,File> versions = new TreeMap<Version,File>();
+ for (int i = 0; i < instances.length; i++) {
+ Matcher m = REPO_FILE.matcher(instances[i].getName());
+ if (m.matches() && m.group(1).equals(bsn)) {
+ String versionString = m.group(2);
+ Version version;
+ if (versionString.equals("latest"))
+ version = new Version(Integer.MAX_VALUE);
+ else
+ version = new Version(versionString);
- if (range.includes(version))
- versions.put(version, instances[i]);
- }
- }
- return versions.values().toArray(new File[versions.size()]);
+ if (range.includes(version))
+ versions.put(version, instances[i]);
+ }
+ }
+ return versions.values().toArray(new File[versions.size()]);
}
}
diff --git a/bundleplugin/src/main/java/aQute/lib/deployer/FileRepo.java b/bundleplugin/src/main/java/aQute/lib/deployer/FileRepo.java
index 8cd39f1..3e79730 100644
--- a/bundleplugin/src/main/java/aQute/lib/deployer/FileRepo.java
+++ b/bundleplugin/src/main/java/aQute/lib/deployer/FileRepo.java
@@ -17,18 +17,16 @@
public final static String READONLY = "readonly";
public final static String NAME = "name";
- File[] EMPTY_FILES = new File[0];
- protected File root;
- Registry registry;
- boolean canWrite = true;
- Pattern REPO_FILE = Pattern
- .compile("([-a-zA-z0-9_\\.]+)-([0-9\\.]+|latest)\\.(jar|lib)");
- Reporter reporter;
- boolean dirty;
- String name;
+ File[] EMPTY_FILES = new File[0];
+ protected File root;
+ Registry registry;
+ boolean canWrite = true;
+ Pattern REPO_FILE = Pattern.compile("([-a-zA-z0-9_\\.]+)-([0-9\\.]+|latest)\\.(jar|lib)");
+ Reporter reporter;
+ boolean dirty;
+ String name;
- public FileRepo() {
- }
+ public FileRepo() {}
public FileRepo(String name, File location, boolean canWrite) {
this.name = name;
@@ -40,7 +38,7 @@
// for extensions
}
- public void setProperties(Map<String, String> map) {
+ public void setProperties(Map<String,String> map) {
String location = map.get(LOCATION);
if (location == null)
throw new IllegalArgumentException("Location must be set on a FileRepo plugin");
@@ -93,7 +91,7 @@
// this list.
//
File instances[] = f.listFiles();
- SortedMap<Version, File> versions = new TreeMap<Version, File>();
+ SortedMap<Version,File> versions = new TreeMap<Version,File>();
for (int i = 0; i < instances.length; i++) {
Matcher m = REPO_FILE.matcher(instances[i].getName());
if (m.matches() && m.group(1).equals(bsn)) {
@@ -111,7 +109,9 @@
File[] files = versions.values().toArray(EMPTY_FILES);
if ("latest".equals(versionRange) && files.length > 0) {
- return new File[] { files[files.length - 1] };
+ return new File[] {
+ files[files.length - 1]
+ };
}
return files;
}
@@ -149,8 +149,8 @@
else
version = new Version(versionString);
- reporter.trace("bsn=%s version=%s",bsn,version);
-
+ reporter.trace("bsn=%s version=%s", bsn, version);
+
File dir = new File(root, bsn);
dir.mkdirs();
String fName = bsn + "-" + version.getWithoutQualifier() + ".jar";
@@ -178,12 +178,12 @@
protected void fireBundleAdded(Jar jar, File file) {
if (registry == null)
return;
- List<RepositoryListenerPlugin> listeners = registry
- .getPlugins(RepositoryListenerPlugin.class);
+ List<RepositoryListenerPlugin> listeners = registry.getPlugins(RepositoryListenerPlugin.class);
for (RepositoryListenerPlugin listener : listeners) {
try {
listener.bundleAdded(this, jar, file);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
if (reporter != null)
reporter.warning("Repository listener threw an unexpected exception: %s", e);
}
@@ -275,16 +275,14 @@
public Jar get(String bsn, Version v) throws Exception {
init();
File bsns = new File(root, bsn);
- File version = new File(bsns, bsn + "-" + v.getMajor() + "." + v.getMinor() + "."
- + v.getMicro() + ".jar");
- if ( version.exists())
+ File version = new File(bsns, bsn + "-" + v.getMajor() + "." + v.getMinor() + "." + v.getMicro() + ".jar");
+ if (version.exists())
return new Jar(version);
else
return null;
}
- public File get(String bsn, String version, Strategy strategy, Map<String, String> properties)
- throws Exception {
+ public File get(String bsn, String version, Strategy strategy, Map<String,String> properties) throws Exception {
if (version == null)
version = "0.0.0";
@@ -313,10 +311,10 @@
if (files.length >= 0) {
switch (strategy) {
- case LOWEST:
- return files[0];
- case HIGHEST:
- return files[files.length - 1];
+ case LOWEST :
+ return files[0];
+ case HIGHEST :
+ return files[files.length - 1];
}
}
return null;