diff --git a/biz.aQute.bndlib/src/aQute/bnd/make/MakeJar.java b/biz.aQute.bndlib/src/aQute/bnd/make/MakeJar.java new file mode 100644 index 00000000000..676ad100a62 --- /dev/null +++ b/biz.aQute.bndlib/src/aQute/bnd/make/MakeJar.java @@ -0,0 +1,49 @@ +package aQute.bnd.make; + +import java.io.File; +import java.util.Map; +import java.util.jar.Attributes; +import java.util.jar.Manifest; + +import aQute.bnd.osgi.About; +import aQute.bnd.osgi.Builder; +import aQute.bnd.osgi.Constants; +import aQute.bnd.osgi.Jar; +import aQute.bnd.osgi.JarResource; +import aQute.bnd.osgi.Resource; +import aQute.bnd.service.MakePlugin; + +public class MakeJar implements MakePlugin { + + @Override + public Resource make(Builder builder, String destination, Map argumentsOnMake) throws Exception { + String type = argumentsOnMake.get("type"); //$NON-NLS-1$ + if (!"jar".equals(type)) { //$NON-NLS-1$ + return null; + } + String input = argumentsOnMake.get("input"); //$NON-NLS-1$ + if (input == null) { + builder.error("No input specified on a make instruction for %s, args=%s", destination, argumentsOnMake); //$NON-NLS-1$ + return null; + } + File folder = builder.getFile(input); + if (!folder.isDirectory()) { + return null; + } + Jar jar = new Jar(folder); + Manifest manifest = new Manifest(); + Attributes mainAttributes = manifest.getMainAttributes(); + mainAttributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); //$NON-NLS-1$ + if (!Boolean.parseBoolean(argumentsOnMake.get("noExtra"))) { //$NON-NLS-1$ + mainAttributes.putValue(Constants.CREATED_BY, + String.format("%s (%s)", System.getProperty("java.version"), System.getProperty("java.vendor"))); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + mainAttributes.putValue(Constants.TOOL, "Bnd-" + About.getBndVersion()); //$NON-NLS-1$ + if (!Boolean.parseBoolean(argumentsOnMake.get("reproducible"))) { //$NON-NLS-1$ + mainAttributes.putValue(Constants.BND_LASTMODIFIED, Long.toString(System.currentTimeMillis())); + } + } + jar.setManifest(manifest); + return new JarResource(jar); + } + +} diff --git a/biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java b/biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java index b2a9c6a38e1..eb955fb594a 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java +++ b/biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java @@ -44,6 +44,7 @@ import aQute.bnd.make.Make; import aQute.bnd.make.MakeBnd; import aQute.bnd.make.MakeCopy; +import aQute.bnd.make.MakeJar; import aQute.bnd.make.component.ServiceComponent; import aQute.bnd.maven.PomPropertiesResource; import aQute.bnd.maven.PomResource; @@ -1732,6 +1733,7 @@ public Pattern getDoNotCopy() { */ static MakeBnd makeBnd = new MakeBnd(); + static MakeJar makeJar = new MakeJar(); static MakeCopy makeCopy = new MakeCopy(); static ServiceComponent serviceComponent = new ServiceComponent(); static CDIAnnotations cdiAnnotations = new CDIAnnotations(); @@ -1745,6 +1747,7 @@ public Pattern getDoNotCopy() { @Override protected void setTypeSpecificPlugins(PluginsContainer pluginsContainer) { pluginsContainer.add(makeBnd); + pluginsContainer.add(makeJar); pluginsContainer.add(makeCopy); pluginsContainer.add(serviceComponent); pluginsContainer.add(cdiAnnotations);