-
-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a MakeJar to create a plain-old-jar file as a resource
Currently one can already create a new bundle using additional bnd instructions file but this has some caveats when one only wants to package some stuff into a jar and also some processing overhead. This adds a new MakeJar that do what the name suggest and create a dumb jar from an input directory. Signed-off-by: Christoph Läubrich <[email protected]>
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, String> 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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters