]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/BndWrapper.java
Work on the binaries indexer.
[gpl/argeo-slc.git] / runtime / org.argeo.slc.repo / src / main / java / org / argeo / slc / repo / osgi / BndWrapper.java
index 564dd52d360d9349ea9ecde8050270e3ac15bd04..f1acf49e4d8c54fb2e10c3d953ab73db1455beba 100644 (file)
@@ -29,47 +29,70 @@ public class BndWrapper implements Constants, CategorizedNameVersion,
        private String version;
        private Properties bndProperties = new Properties();
 
+       private Boolean doNotModify = false;
+
        public void wrapJar(InputStream in, OutputStream out) {
                Builder b = new Builder();
                try {
                        Jar jar = new Jar(null, in);
 
                        Manifest sourceManifest = jar.getManifest();
-                       String sourceVersion = sourceManifest.getMainAttributes().getValue(
-                                       BUNDLE_VERSION);
+
                        Version versionToUse;
-                       if (version == null && sourceVersion == null) {
-                               throw new SlcException("A bundle version must be defined.");
-                       } else if (version == null && sourceVersion != null) {
-                               versionToUse = new Version(sourceVersion);
-                       } else if (version != null && sourceVersion == null) {
-                               versionToUse = new Version(version);
-                       } else {// both set
-                               versionToUse = new Version(version);
-                               Version sv = new Version(sourceVersion);
-                               if (versionToUse.getMajor() != sv.getMajor()
-                                               || versionToUse.getMinor() != sv.getMinor()
-                                               || versionToUse.getMicro() != sv.getMicro()) {
-                                       log.warn("The new version ("
-                                                       + versionToUse
-                                                       + ") is not consistant with the wrapped bundle version ("
-                                                       + sv + ")");
+                       if (sourceManifest != null) {
+                               String sourceSymbolicName = sourceManifest.getMainAttributes()
+                                               .getValue(BUNDLE_SYMBOLICNAME);
+                               if (sourceSymbolicName != null
+                                               && sourceSymbolicName.equals(name))
+                                       log.warn("The new symbolic name ("
+                                                       + name
+                                                       + ") is not consistant with the wrapped bundle symbolic name ("
+                                                       + sourceSymbolicName + ")");
+
+                               String sourceVersion = sourceManifest.getMainAttributes()
+                                               .getValue(BUNDLE_VERSION);
+                               if (version == null && sourceVersion == null) {
+                                       throw new SlcException("A bundle version must be defined.");
+                               } else if (version == null && sourceVersion != null) {
+                                       versionToUse = new Version(sourceVersion);
+                                       version = sourceVersion; // set wrapper version
+                               } else if (version != null && sourceVersion == null) {
+                                       versionToUse = new Version(version);
+                               } else {// both set
+                                       versionToUse = new Version(version);
+                                       Version sv = new Version(sourceVersion);
+                                       if (versionToUse.getMajor() != sv.getMajor()
+                                                       || versionToUse.getMinor() != sv.getMinor()
+                                                       || versionToUse.getMicro() != sv.getMicro()) {
+                                               log.warn("The new version ("
+                                                               + versionToUse
+                                                               + ") is not consistant with the wrapped bundle version ("
+                                                               + sv + ")");
+                                       }
                                }
+                       } else {
+                               versionToUse = new Version(version);
                        }
 
-                       Properties properties = new Properties();
-                       properties.putAll(bndProperties);
-                       properties.setProperty(BUNDLE_SYMBOLICNAME, name);
-                       properties.setProperty(BUNDLE_VERSION, versionToUse.toString());
+                       if (doNotModify) {
+                               jar.write(out);
+                       } else {
 
-                       // b.addIncluded(jarFile);
-                       b.addClasspath(jar);
+                               Properties properties = new Properties();
+                               properties.putAll(bndProperties);
+                               properties.setProperty(BUNDLE_SYMBOLICNAME, name);
+                               properties.setProperty(BUNDLE_VERSION, versionToUse.toString());
 
-                       log.debug(properties);
-                       b.setProperties(properties);
+                               // b.addIncluded(jarFile);
+                               b.addClasspath(jar);
 
-                       Jar newJar = b.build();
-                       newJar.write(out);
+                               if (log.isDebugEnabled())
+                                       log.debug(properties);
+                               b.setProperties(properties);
+
+                               Jar newJar = b.build();
+                               newJar.write(out);
+                       }
                } catch (Exception e) {
                        throw new SlcException("Cannot wrap jar", e);
                } finally {
@@ -147,4 +170,8 @@ public class BndWrapper implements Constants, CategorizedNameVersion,
                        return false;
        }
 
+       public void setDoNotModify(Boolean doNotModify) {
+               this.doNotModify = doNotModify;
+       }
+
 }