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 {
return false;
}
+ public void setDoNotModify(Boolean doNotModify) {
+ this.doNotModify = doNotModify;
+ }
+
}