Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[FABRIC-300] Patching service now strips directives from symbolic nam…

…es when performing bundle comparisons.
  • Loading branch information...
commit 8d6b11ba9097f6d31771f57d4276c64bab51d9fe 1 parent cb3362e
@iocanel iocanel authored
View
23 patch/patch-core/src/main/java/org/fusesource/patch/impl/ServiceImpl.java
@@ -43,6 +43,8 @@
import java.util.jar.Attributes;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -82,6 +84,8 @@
private static final String OLD_VERSION = "old-version";
private static final String OLD_LOCATION = "old-location";
+ private static final Pattern SYMBOLIC_NAME_PATTERN = Pattern.compile("([^;: ]+)(.*)");
+
public ServiceImpl(BundleContext bundleContext) {
// Use system bundle' bundle context to avoid running into
// "Invalid BundleContext" exceptions when updating bundles
@@ -285,7 +289,7 @@ void rollback(Patch patch, boolean force) throws PatchException {
boolean found = false;
Version v = Version.parseVersion(update.getNewVersion());
for (Bundle bundle : allBundles) {
- if (bundle.getSymbolicName().equals(update.getSymbolicName())
+ if (stripSymbolicName(bundle.getSymbolicName()).equals(stripSymbolicName(update.getSymbolicName()))
&& bundle.getVersion().equals(v)) {
found = true;
break;
@@ -308,7 +312,7 @@ void rollback(Patch patch, boolean force) throws PatchException {
for (BundleUpdate update : result.getUpdates()) {
Version v = Version.parseVersion(update.getNewVersion());
for (Bundle bundle : allBundles) {
- if (bundle.getSymbolicName().equals(update.getSymbolicName())
+ if (stripSymbolicName(bundle.getSymbolicName()).equals(stripSymbolicName(update.getSymbolicName()))
&& bundle.getVersion().equals(v)) {
toUpdate.put(bundle, update.getPreviousLocation());
}
@@ -355,7 +359,7 @@ Result install(Patch patch, boolean simulate) {
VersionRange range = new VersionRange(false, lower, v, true);
for (Bundle bundle : allBundles) {
Version oldV = bundle.getVersion();
- if (bundle.getBundleId() != 0 && sn.equals(bundle.getSymbolicName()) && range.contains(oldV)) {
+ if (bundle.getBundleId() != 0 && stripSymbolicName(sn).equals(stripSymbolicName(bundle.getSymbolicName())) && range.contains(oldV)) {
String location = bundle.getLocation();
BundleUpdate update = new BundleUpdateImpl(sn, v.toString(), url, oldV.toString(), location);
updates.add(update);
@@ -665,4 +669,17 @@ static void close(Closeable... closeables) {
}
}
+ /**
+ * Strips symbolic name from directives.
+ * @param symbolicName
+ * @return
+ */
+ static String stripSymbolicName(String symbolicName) {
+ Matcher m = SYMBOLIC_NAME_PATTERN.matcher(symbolicName);
+ if (m.matches() && m.groupCount() >= 1) {
+ return m.group(1);
+ } else {
+ return symbolicName;
+ }
+ }
}
View
102 patch/patch-core/src/test/java/org/fusesource/patch/impl/ServiceImplTest.java
@@ -37,6 +37,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
+import junit.framework.Assert;
import org.easymock.EasyMock;
import org.easymock.IAnswer;
import org.fusesource.patch.Patch;
@@ -51,6 +52,7 @@
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
+import static org.fusesource.patch.impl.ServiceImpl.stripSymbolicName;
public class ServiceImplTest {
@@ -74,53 +76,13 @@ public void setUp() throws Exception {
generateData();
}
-
- private void generateData() throws Exception {
- storage = new File(baseDir, "storage");
- delete(storage);
- storage.mkdirs();
- bundlev131 = createBundle("my-bsn", "1.3.1");
- bundlev132 = createBundle("my-bsn", "1.3.2");
- bundlev140 = createBundle("my-bsn", "1.4.0");
-
- patch132 = createPatch("patch-1.3.2", bundlev132);
- patch140 = createPatch("patch-1.4.0", bundlev140);
- }
-
- private File createPatch(String id, File bundle) throws Exception {
- File patchFile = new File(storage, "temp/" + id + ".zip");
- File pd = new File(storage, "temp/" + id + "/" + id + ".patch");
- pd.getParentFile().mkdirs();
- Properties props = new Properties();
- props.put("id", id);
- props.put("bundle.count", "1");
- props.put("bundle.0", bundle.toURI().toURL().toString());
- FileOutputStream fos = new FileOutputStream(pd);
- props.store(fos, null);
- fos.close();
- fos = new FileOutputStream(patchFile);
- jarDir(pd.getParentFile(), fos);
- fos.close();
- return patchFile;
- }
-
- private File createBundle(String bundleSymbolicName, String version) throws Exception {
- File jar = new File(storage, "temp/" + bundleSymbolicName + "-" + version + ".jar");
- File man = new File(storage, "temp/" + bundleSymbolicName + "-" + version + "/META-INF/MANIFEST.MF");
- man.getParentFile().mkdirs();
- Manifest mf = new Manifest();
- mf.getMainAttributes().putValue("Manifest-Version", "1.0");
- mf.getMainAttributes().putValue("Bundle-ManifestVersion", "2");
- mf.getMainAttributes().putValue("Bundle-SymbolicName", bundleSymbolicName);
- mf.getMainAttributes().putValue("Bundle-Version", version);
- FileOutputStream fos = new FileOutputStream(man);
- mf.write(fos);
- fos.close();
- fos = new FileOutputStream(jar);
- jarDir(man.getParentFile().getParentFile(), fos);
- fos.close();
- return jar;
+ @Test
+ public void testSymbolicNameStrip() {
+ Assert.assertEquals("my.bundle", stripSymbolicName("my.bundle"));
+ Assert.assertEquals("my.bundle", stripSymbolicName("my.bundle;singleton:=true"));
+ Assert.assertEquals("my.bundle", stripSymbolicName("my.bundle;blueprint.graceperiod:=false;"));
+ Assert.assertEquals("my.bundle", stripSymbolicName("my.bundle;blueprint.graceperiod:=false; blueprint.timeout=10000;"));
}
@Test
@@ -269,6 +231,54 @@ public Object answer() throws Throwable {
}
+ private void generateData() throws Exception {
+ storage = new File(baseDir, "storage");
+ delete(storage);
+ storage.mkdirs();
+
+ bundlev131 = createBundle("my-bsn", "1.3.1");
+ bundlev132 = createBundle("my-bsn;directive1:=true; directve2:=1000", "1.3.2");
+ bundlev140 = createBundle("my-bsn", "1.4.0");
+
+ patch132 = createPatch("patch-1.3.2", bundlev132);
+ patch140 = createPatch("patch-1.4.0", bundlev140);
+ }
+
+ private File createPatch(String id, File bundle) throws Exception {
+ File patchFile = new File(storage, "temp/" + id + ".zip");
+ File pd = new File(storage, "temp/" + id + "/" + id + ".patch");
+ pd.getParentFile().mkdirs();
+ Properties props = new Properties();
+ props.put("id", id);
+ props.put("bundle.count", "1");
+ props.put("bundle.0", bundle.toURI().toURL().toString());
+ FileOutputStream fos = new FileOutputStream(pd);
+ props.store(fos, null);
+ fos.close();
+ fos = new FileOutputStream(patchFile);
+ jarDir(pd.getParentFile(), fos);
+ fos.close();
+ return patchFile;
+ }
+
+ private File createBundle(String bundleSymbolicName, String version) throws Exception {
+ File jar = new File(storage, "temp/" + stripSymbolicName(bundleSymbolicName) + "-" + version + ".jar");
+ File man = new File(storage, "temp/" + stripSymbolicName(bundleSymbolicName) + "-" + version + "/META-INF/MANIFEST.MF");
+ man.getParentFile().mkdirs();
+ Manifest mf = new Manifest();
+ mf.getMainAttributes().putValue("Manifest-Version", "1.0");
+ mf.getMainAttributes().putValue("Bundle-ManifestVersion", "2");
+ mf.getMainAttributes().putValue("Bundle-SymbolicName", bundleSymbolicName);
+ mf.getMainAttributes().putValue("Bundle-Version", version);
+ FileOutputStream fos = new FileOutputStream(man);
+ mf.write(fos);
+ fos.close();
+ fos = new FileOutputStream(jar);
+ jarDir(man.getParentFile().getParentFile(), fos);
+ fos.close();
+ return jar;
+ }
+
private <T> Set<T> asSet(T... objects) {
HashSet<T> set = new HashSet<T>();
for (T t : objects) {
Please sign in to comment.
Something went wrong with that request. Please try again.