本文整理了Java中aQute.lib.osgi.Jar
类的一些代码示例,展示了Jar
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jar
类的具体详情如下:
包路径:aQute.lib.osgi.Jar
类名称:Jar
暂无
代码示例来源:origin: biz.aQute/bnd
void applyPatch(String old, String patch, String newer) throws Exception {
Jar a = new Jar(new File(old));
Jar b = new Jar(new File(patch));
Manifest bm = b.getManifest();
String patchDelete = bm.getMainAttributes().getValue("Patch-Delete");
String patchVersion = bm.getMainAttributes().getValue("Patch-Version");
if (patchVersion == null) {
error("To patch, you must provide a patch bundle.\nThe given " + patch
+ " bundle does not contain the Patch-Version header");
return;
}
Collection<String> delete = split(patchDelete);
Set<String> paths = new HashSet<String>(a.getResources().keySet());
paths.removeAll(delete);
for (String path : paths) {
Resource br = b.getResource(path);
if (br == null)
b.putResource(path, a.getResource(path));
}
bm.getMainAttributes().putValue("Bundle-Version", patchVersion);
b.write(new File(newer));
a.close();
b.close();
}
代码示例来源:origin: io.fabric8.fab/fab-core
public Set<String> getPackages() throws IOException {
if (packages == null) {
if (getExtension().equals("jar") || getExtension().equals("zip")) {
aQute.lib.osgi.Jar jar = new aQute.lib.osgi.Jar(getJarFile());
try {
packages = new HashSet<String>(jar.getPackages());
} finally {
jar.close();
}
} else {
return Collections.emptySet();
}
}
return packages;
}
代码示例来源:origin: biz.aQute/aQute.bnd
public boolean rename(String oldPath, String newPath) {
Resource resource = remove(oldPath);
if (resource == null)
return false;
return putResource(newPath, resource);
}
代码示例来源:origin: biz.aQute/bnd
/**
* Cleanup the manifest for writing. Cleaning up consists of adding a space
* after any \n to prevent the manifest to see this newline as a delimiter.
*
* @param out
* Output
* @throws IOException
*/
public void writeManifest(OutputStream out) throws Exception {
writeManifest(getManifest(), out);
}
代码示例来源:origin: biz.aQute/bnd
private void copyInfoResource(Jar source, Jar dest, String type) {
if ( source.getResources().containsKey(type) && !dest.getResources().containsKey(type))
dest.putResource(type, source.getResource(type));
}
代码示例来源:origin: biz.aQute/bnd
void createPatch(String old, String newer, String patch) throws Exception {
Jar a = new Jar(new File(old));
Manifest am = a.getManifest();
Jar b = new Jar(new File(newer));
Manifest bm = b.getManifest();
Set<String> delete = newSet();
for (String path : a.getResources().keySet()) {
Resource br = b.getResource(path);
if (br == null) {
trace("DELETE %s", path);
delete.add(path);
} else {
Resource ar = a.getResource(path);
if (isEqual(ar, br)) {
trace("UNCHANGED %s", path);
b.remove(path);
} else
trace("UPDATE %s", path);
}
}
bm.getMainAttributes().putValue("Patch-Delete", join(delete, ", "));
bm.getMainAttributes().putValue("Patch-Version",
am.getMainAttributes().getValue("Bundle-Version"));
b.write(new File(patch));
a.close();
a.close();
}
代码示例来源:origin: biz.aQute/aQute.bnd
/**
* Release
*
* @param name
* The respository name
* @param test
* Run testcases
* @throws Exception
*/
public void release(String name, boolean test) throws Exception {
File[] jars = build(test);
// If build fails jars will be null
if (jars == null) {
return;
}
for (File jar : jars) {
Jar j = new Jar(jar);
release(name, j);
j.close();
}
}
代码示例来源:origin: org.fusesource.fabric/process-manager
/**
* Sets the executable class name in the given jar
*/
protected void setMainClass(ProcessConfig config, File installDir, File jarFile, int id, String mainClass) throws Exception {
File tmpFile = File.createTempFile("fuse-process-" + id, ".jar");
Files.copy(jarFile, tmpFile);
Jar jar = new Jar(tmpFile);
Attributes attributes = jar.getManifest().getMainAttributes();
attributes.putValue("Main-Class", mainClass);
jar.write(jarFile);
}
代码示例来源:origin: biz.aQute/bnd
public Jar getValidJar(URL url) throws Exception {
InputStream in = url.openStream();
try {
Jar jar = new Jar(url.getFile().replace('/', '.'), in, System.currentTimeMillis());
return getValidJar(jar, url.toString());
} finally {
in.close();
}
}
代码示例来源:origin: biz.aQute/bnd
public File saveBuild(Jar jar) throws Exception {
try {
String bsn = jar.getName();
File f = getOutputFile(bsn);
String msg = "";
if (!f.exists() || f.lastModified() < jar.lastModified()) {
reportNewer(f.lastModified(), jar);
f.delete();
if (!f.getParentFile().isDirectory())
f.getParentFile().mkdirs();
jar.write(f);
getWorkspace().changedFile(f);
} else {
msg = "(not modified since " + new Date(f.lastModified()) + ")";
}
trace(jar.getName() + " (" + f.getName() + ") " + jar.getResources().size() + " " + msg);
return f;
} finally {
jar.close();
}
}
代码示例来源:origin: biz.aQute/aQute.bnd
private void doExpand(Jar jar) throws IOException {
if (getClasspath().size() == 0
&& (getProperty(EXPORT_PACKAGE) != null || getProperty(PRIVATE_PACKAGE) != null))
warning("Classpath is empty. Private-Package and Export-Package can only expand from the classpath when there is one");
Map<Instruction, Map<String, String>> privateMap = replaceWitInstruction(
getHeader(PRIVATE_PACKAGE), PRIVATE_PACKAGE);
Map<Instruction, Map<String, String>> exportMap = replaceWitInstruction(
getHeader(EXPORT_PACKAGE), EXPORT_PACKAGE);
if (isTrue(getProperty(Constants.UNDERTEST))) {
privateMap.putAll(replaceWitInstruction(parseHeader(getProperty(
Constants.TESTPACKAGES, "test;presence:=optional")),
TESTPACKAGES));
}
if (!privateMap.isEmpty())
doExpand(jar, "Private-Package, or -testpackages", privateMap, true);
if (!exportMap.isEmpty()) {
Jar exports = new Jar("exports");
doExpand(exports, "Export-Package", exportMap, true);
jar.addAll(exports);
exports.close();
}
if (privateMap.isEmpty() && exportMap.isEmpty() && !isResourceOnly()) {
warning("Neither Export-Package, Private-Package, -testpackages is set, therefore no packages will be included");
}
}
代码示例来源:origin: biz.aQute/bnd
try {
File file = new File(args[i]);
Jar jar = new Jar(file.getName(), file);
try {
for (Map.Entry<String, Resource> entry : jar.getResources().entrySet()) {
String key = entry.getKey();
Resource r = entry.getValue();
jar.close();
代码示例来源:origin: biz.aQute/bnd
jar.write(out);
} finally {
out.close();
trace("Submitted: %s to %s", jar.getName(), url);
Jar result = new Jar(url.toExternalForm(), in);
addClose(result);
trace("Received: %s", result.getName());
Resource errors = result.getResource("META-INF/errors");
Resource warnings = result.getResource("META-INF/warnings");
if (errors != null)
parse(errors.openInputStream(), url.getFile(), getErrors());
代码示例来源:origin: biz.aQute/bnd
/**
* Write out an entry, handling proper unicode and line length constraints
*
*/
private static void writeEntry(OutputStream out, String name, String value) throws IOException {
int n = write(out, 0, name + ": ");
n = write(out, n, value);
write(out, 0, "\r\n");
}
代码示例来源:origin: biz.aQute/bnd
/**
* Make sure we have a manifest
* @throws Exception
*/
public void ensureManifest() throws Exception {
if ( getManifest() != null)
return;
manifest = new Manifest();
}
代码示例来源:origin: biz.aQute/bnd
/**
* @param out
* @param file
* @throws IOException
* @throws Exception
*/
void doSingleFileLib(File file, Appendable out) throws IOException, Exception {
Jar jar = new Jar(file);
String bsn = jar.getBsn();
System.out.println(bsn);
String version = jar.getVersion();
jar.close();
if (bsn == null) {
error("No valid bsn for %s", file);
bsn = "not set";
}
if (version == null)
version = "0";
Version v = new Version(version);
v = new Version(v.getMajor(), v.getMinor(), v.getMicro());
out.append(bsn);
out.append(";version=" + v + "\n"); // '[" + v + "," + v + "]'\n");
}
代码示例来源:origin: io.fabric8.fab/fab-osgi
public void run()
{
try
{
jar.write( pout );
}
catch( Exception e )
{
LOG.warn( "Bundle cannot be generated" );
}
finally
{
try
{
jar.close();
pout.close();
}
catch( IOException ignore )
{
// if we get here something is very wrong
LOG.error( "Bundle cannot be generated", ignore );
}
}
}
}.start();
代码示例来源:origin: biz.aQute/bnd
dirty = true;
Manifest manifest = jar.getManifest();
if (manifest == null)
throw new IllegalArgumentException("No manifest in JAR: " + jar);
if (!file.exists() || file.lastModified() < jar.lastModified()) {
jar.write(file);
reporter.progress("Updated " + file.getAbsolutePath());
fireBundleAdded(jar, file);
if (latest.exists() && latest.lastModified() < jar.lastModified()) {
jar.write(latest);
file = latest;
代码示例来源:origin: biz.aQute/bnd
out.println("Classpath used");
for (Jar jar : getClasspath()) {
out.printf("File : %s\n", jar.getSource());
out.printf("File abs path : %s\n", jar.getSource()
.getAbsolutePath());
out.printf("Name : %s\n", jar.getName());
Map<String, Map<String, Resource>> dirs = jar.getDirectories();
for (Map.Entry<String, Map<String, Resource>> entry : dirs.entrySet()) {
Map<String, Resource> dir = entry.getValue();
dot.close();
jar.close();
代码示例来源:origin: biz.aQute/aQute.bnd
public void write(OutputStream out) throws IOException {
ZipOutputStream jout = nomanifest ? new ZipOutputStream(out) : new JarOutputStream(out);
Set<String> done = new HashSet<String>();
Set<String> directories = new HashSet<String>();
if (doNotTouchManifest) {
writeResource(jout, directories, "META-INF/MANIFEST.MF",
getResource("META-INF/MANIFEST.MF"));
done.add("META-INF/MANIFEST.MF");
} else if (!nomanifest)
doManifest(done, jout);
for (Map.Entry<String, Resource> entry : getResources().entrySet()) {
// Skip metainf contents
if (!done.contains(entry.getKey()))
writeResource(jout, directories, (String) entry.getKey(),
(Resource) entry.getValue());
}
jout.finish();
}
内容来源于网络,如有侵权,请联系作者删除!