X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.slc.repo%2Fsrc%2Forg%2Fargeo%2Fslc%2Frepo%2Fosgi%2FBndWrapper.java;h=57d7a81d2cbb968be5a7a7e31526156bf5a481b3;hb=1b8b4c8443356a7a4adc632f391daa8c0ded8053;hp=17bdbe11772ab1a71a40d82d8e533b3a36175bee;hpb=8a01e42cd1a963be1f37d444f15e09512dc7d07f;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/BndWrapper.java b/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/BndWrapper.java index 17bdbe117..57d7a81d2 100644 --- a/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/BndWrapper.java +++ b/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/BndWrapper.java @@ -7,25 +7,22 @@ import java.util.Properties; import java.util.jar.Manifest; import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.CategorizedNameVersion; +import org.argeo.api.cms.CmsLog; +import org.argeo.slc.CategoryNameVersion; import org.argeo.slc.SlcException; import org.argeo.slc.build.Distribution; import org.argeo.slc.build.License; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.DefaultArtifact; import org.osgi.framework.Version; -import org.springframework.beans.factory.BeanNameAware; -import aQute.lib.osgi.Builder; -import aQute.lib.osgi.Constants; -import aQute.lib.osgi.Jar; +import aQute.bnd.osgi.Builder; +import aQute.bnd.osgi.Constants; +import aQute.bnd.osgi.Jar; /** Utilities around the BND library, which manipulates OSGi metadata. */ -public class BndWrapper implements Constants, CategorizedNameVersion, - Distribution, BeanNameAware { - private final static Log log = LogFactory.getLog(BndWrapper.class); +public class BndWrapper implements Constants, CategoryNameVersion, Distribution { + private final static CmsLog log = CmsLog.getLog(BndWrapper.class); private String groupId; private String name; @@ -44,24 +41,19 @@ public class BndWrapper implements Constants, CategorizedNameVersion, try { byte[] jarBytes = IOUtils.toByteArray(in); - jar = new Jar(null, new ByteArrayInputStream(jarBytes)); + jar = new Jar(name, new ByteArrayInputStream(jarBytes)); Manifest sourceManifest = jar.getManifest(); Version versionToUse; if (sourceManifest != null) { // Symbolic name - String sourceSymbolicName = sourceManifest.getMainAttributes() - .getValue(BUNDLE_SYMBOLICNAME); - if (sourceSymbolicName != null - && !sourceSymbolicName.equals(name)) - log.info("The new symbolic name (" - + name - + ") is not consistant with the wrapped bundle symbolic name (" - + sourceSymbolicName + ")"); + String sourceSymbolicName = sourceManifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME); + if (sourceSymbolicName != null && !sourceSymbolicName.equals(name)) + log.info("The new symbolic name (" + name + + ") is not consistant with the wrapped bundle symbolic name (" + sourceSymbolicName + ")"); // Version - String sourceVersion = sourceManifest.getMainAttributes() - .getValue(BUNDLE_VERSION); + String sourceVersion = sourceManifest.getMainAttributes().getValue(BUNDLE_VERSION); if (getVersion() == null && sourceVersion == null) { throw new SlcException("A bundle version must be defined."); } else if (getVersion() == null && sourceVersion != null) { @@ -72,13 +64,10 @@ public class BndWrapper implements Constants, CategorizedNameVersion, } else {// both set versionToUse = new Version(getVersion()); Version sv = new Version(sourceVersion); - if (versionToUse.getMajor() != sv.getMajor() - || versionToUse.getMinor() != sv.getMinor() + 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 + ")"); + log.warn("The new version (" + versionToUse + + ") is not consistant with the wrapped bundle version (" + sv + ")"); } } } else { @@ -97,14 +86,7 @@ public class BndWrapper implements Constants, CategorizedNameVersion, // License if (license != null) { - StringBuilder sb = new StringBuilder(license.getUri()); - if (license.getName() != null) - sb.append(';').append("description=") - .append(license.getName()); - if (license.getLink() != null) - sb.append(';').append("link=") - .append(license.getLink()); - properties.setProperty(BUNDLE_LICENSE, sb.toString()); + properties.setProperty(BUNDLE_LICENSE, license.toString()); // TODO add LICENSE.TXT } else { log.warn("No license set for " + toString()); @@ -124,9 +106,13 @@ public class BndWrapper implements Constants, CategorizedNameVersion, } catch (Exception e) { throw new SlcException("Cannot wrap jar", e); } finally { - b.close(); - if (jar != null) - jar.close(); + try { + b.close(); + if (jar != null) + jar.close(); + } catch (Exception e) { + // silent + } } } @@ -151,8 +137,7 @@ public class BndWrapper implements Constants, CategorizedNameVersion, public void setVersion(String version) { if (this.version != null) - throw new SlcException("Version already set on " + name + " (" - + this.version + ")"); + throw new SlcException("Version already set on " + name + " (" + this.version + ")"); this.version = version; } @@ -178,16 +163,6 @@ public class BndWrapper implements Constants, CategorizedNameVersion, this.bndProperties = bndProperties; } - public void setBeanName(String name) { - if (this.name == null) { - this.name = name; - } else { - if (!name.contains("#")) - log.warn("Using explicitely set name " + this.name - + " and not bean name " + name); - } - } - public String getGroupId() { return groupId; } @@ -201,7 +176,7 @@ public class BndWrapper implements Constants, CategorizedNameVersion, } public String getDistributionId() { - return getArtifact().toString(); + return getCategory() + ":" + getName() + ":" + getVersion(); } public Artifact getArtifact() { @@ -210,20 +185,21 @@ public class BndWrapper implements Constants, CategorizedNameVersion, @Override public String toString() { - return getArtifact().toString(); + return getDistributionId(); } @Override public int hashCode() { - return getArtifact().hashCode(); + if (name != null) + return name.hashCode(); + return super.hashCode(); } @Override public boolean equals(Object obj) { - if (obj instanceof CategorizedNameVersion) { - CategorizedNameVersion cnv = (CategorizedNameVersion) obj; - return getCategory().equals(cnv.getCategory()) - && getName().equals(cnv.getName()) + if (obj instanceof CategoryNameVersion) { + CategoryNameVersion cnv = (CategoryNameVersion) obj; + return getCategory().equals(cnv.getCategory()) && getName().equals(cnv.getName()) && getVersion().equals(cnv.getVersion()); } else return false; @@ -233,4 +209,8 @@ public class BndWrapper implements Constants, CategorizedNameVersion, this.doNotModify = doNotModify; } + public Boolean getDoNotModify() { + return doNotModify; + } + }