Manage licences
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 18 Jun 2014 09:11:20 +0000 (09:11 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 18 Jun 2014 09:11:20 +0000 (09:11 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@7068 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ArchiveWrapper.java
runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/BndWrapper.java

index a34b64fb39802ad1a7f9f4aff967aef2379ef304..01ae4395eddca2712d4994e106654fb0c1ee5dc1 100644 (file)
@@ -28,6 +28,7 @@ import org.argeo.slc.NameVersion;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.aether.ArtifactIdComparator;
 import org.argeo.slc.build.Distribution;
+import org.argeo.slc.build.License;
 import org.argeo.slc.repo.OsgiFactory;
 import org.argeo.slc.repo.RepoUtils;
 import org.sonatype.aether.artifact.Artifact;
@@ -45,6 +46,7 @@ public class ArchiveWrapper implements Runnable, ModuleSet, Distribution {
 
        private OsgiFactory osgiFactory;
        private String version;
+       private License license;
 
        private String uri;
 
@@ -59,12 +61,13 @@ public class ArchiveWrapper implements Runnable, ModuleSet, Distribution {
        private Boolean mavenGroupIndexes = false;
 
        public void init() {
-               if (version != null)
-                       for (BndWrapper wrapper : wrappers.values()) {
-                               if (wrapper.getVersion() == null)
-                                       wrapper.setVersion(version);
-                               wrapper.setFactory(this);
-                       }
+               for (BndWrapper wrapper : wrappers.values()) {
+                       wrapper.setFactory(this);
+                       if (version != null && wrapper.getVersion() == null)
+                               wrapper.setVersion(version);
+                       if (license != null && wrapper.getLicense() == null)
+                               wrapper.setLicense(license);
+               }
        }
 
        public void destroy() {
@@ -267,6 +270,10 @@ public class ArchiveWrapper implements Runnable, ModuleSet, Distribution {
                this.version = version;
        }
 
+       public void setLicense(License license) {
+               this.license = license;
+       }
+
        public void setPathMatcher(PathMatcher pathMatcher) {
                this.pathMatcher = pathMatcher;
        }
index 29c0f78e7e2e0828b116673105d154a1f2970a69..bb2bf24044d77bd4a30ea0455457674180428ec8 100644 (file)
@@ -10,6 +10,7 @@ import org.apache.commons.logging.LogFactory;
 import org.argeo.slc.CategorizedNameVersion;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.build.Distribution;
+import org.argeo.slc.build.License;
 import org.osgi.framework.Version;
 import org.sonatype.aether.artifact.Artifact;
 import org.sonatype.aether.util.artifact.DefaultArtifact;
@@ -26,9 +27,11 @@ public class BndWrapper implements Constants, CategorizedNameVersion,
 
        private String groupId;
        private String name;
-       private String version;
        private Properties bndProperties = new Properties();
 
+       private String version;
+       private License license;
+
        private Boolean doNotModify = false;
 
        private Runnable factory = null;
@@ -42,6 +45,7 @@ public class BndWrapper implements Constants, CategorizedNameVersion,
 
                        Version versionToUse;
                        if (sourceManifest != null) {
+                               // Symbolic name
                                String sourceSymbolicName = sourceManifest.getMainAttributes()
                                                .getValue(BUNDLE_SYMBOLICNAME);
                                if (sourceSymbolicName != null
@@ -51,6 +55,7 @@ public class BndWrapper implements Constants, CategorizedNameVersion,
                                                        + ") is not consistant with the wrapped bundle symbolic name ("
                                                        + sourceSymbolicName + ")");
 
+                               // Version
                                String sourceVersion = sourceManifest.getMainAttributes()
                                                .getValue(BUNDLE_VERSION);
                                if (version == null && sourceVersion == null) {
@@ -85,6 +90,21 @@ public class BndWrapper implements Constants, CategorizedNameVersion,
                                properties.setProperty(BUNDLE_SYMBOLICNAME, name);
                                properties.setProperty(BUNDLE_VERSION, versionToUse.toString());
 
+                               // 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());
+                                       // TODO add LICENSE.TXT
+                               } else {
+                                       log.warn("No license set for " + toString());
+                               }
+
                                // b.addIncluded(jarFile);
                                b.addClasspath(jar);
 
@@ -108,6 +128,8 @@ public class BndWrapper implements Constants, CategorizedNameVersion,
        }
 
        public void setFactory(Runnable factory) {
+               if (this.factory != null)
+                       throw new SlcException("Factory already set on " + name);
                this.factory = factory;
        }
 
@@ -120,6 +142,9 @@ 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 + ")");
                this.version = version;
        }
 
@@ -127,6 +152,16 @@ public class BndWrapper implements Constants, CategorizedNameVersion,
                return version;
        }
 
+       public License getLicense() {
+               return license;
+       }
+
+       public void setLicense(License license) {
+               if (this.license != null)
+                       throw new SlcException("License already set on " + name);
+               this.license = license;
+       }
+
        public Properties getBndProperties() {
                return bndProperties;
        }