use of java.util.jar.Attributes.Name in project eureka by Netflix.
the class DiscoveryBuildInfo method getManifestAttribute.
String getManifestAttribute(String name, String defaultValue) {
if (manifest == null) {
return defaultValue;
}
Name attrName = new Name(name);
Object value = manifest.getMainAttributes().get(attrName);
return value == null ? defaultValue : value.toString();
}
use of java.util.jar.Attributes.Name in project bnd by bndtools.
the class Analyzer method mergeManifest.
/**
* Merge the existing manifest with the instructions but do not override
* existing properties.
*
* @param manifest The manifest to merge with
* @throws IOException
*/
public void mergeManifest(Manifest manifest) throws IOException {
if (manifest != null) {
Attributes attributes = manifest.getMainAttributes();
for (Iterator<Object> i = attributes.keySet().iterator(); i.hasNext(); ) {
Name name = (Name) i.next();
String key = name.toString();
// Dont want instructions
if (key.startsWith("-"))
continue;
if (getProperty(key) == null)
setProperty(key, attributes.getValue(name));
}
}
}
use of java.util.jar.Attributes.Name in project bnd by bndtools.
the class bnd method _grep.
@Description("Grep the manifest of bundles/jar files. ")
public void _grep(grepOptions opts) throws Exception {
List<String> args = opts._arguments();
String s = args.remove(0);
Pattern pattern = Glob.toPattern(s);
if (pattern == null) {
messages.InvalidGlobPattern_(s);
return;
}
if (args.isEmpty()) {
args = new ExtList<String>(getBase().list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
}));
}
Set<String> headers = opts.headers();
if (headers == null)
headers = new TreeSet<String>();
if (opts.exports())
headers.add(Constants.EXPORT_PACKAGE);
if (opts.bsn())
headers.add(Constants.BUNDLE_SYMBOLICNAME);
if (opts.imports())
headers.add(Constants.IMPORT_PACKAGE);
Instructions instructions = new Instructions(headers);
for (String fileName : args) {
File file = getFile(fileName);
if (!file.isFile()) {
messages.NoSuchFile_(file);
continue;
}
try (JarInputStream in = new JarInputStream(IO.stream(file))) {
Manifest m = in.getManifest();
for (Object header : m.getMainAttributes().keySet()) {
Attributes.Name name = (Name) header;
if (instructions.isEmpty() || instructions.matches(name.toString())) {
String h = m.getMainAttributes().getValue(name);
QuotedTokenizer qt = new QuotedTokenizer(h, ",;=");
for (String value : qt.getTokenSet()) {
Matcher matcher = pattern.matcher(value);
while (matcher.find()) {
int start = matcher.start() - 8;
if (start < 0)
start = 0;
int end = matcher.end() + 8;
if (end > value.length())
end = value.length();
out.printf("%40s : %20s ...%s[%s]%s...\n", fileName, name, value.substring(start, matcher.start()), value.substring(matcher.start(), matcher.end()), value.substring(matcher.end(), end));
}
}
}
}
}
}
}
use of java.util.jar.Attributes.Name in project dex2jar by pxb1988.
the class InvocationWeaver method wave.
public void wave(Path from, final Path to) throws IOException {
BaseCmd.walkJarOrDir(from, new BaseCmd.FileVisitorX() {
@Override
public void visitFile(Path file, String relative) throws IOException {
String name = relative;
Path targetPath = to.resolve(relative);
BaseCmd.createParentDirectories(targetPath);
if (name.endsWith(".class")) {
String clzName = name.substring(0, name.length() - ".class".length());
if (ignores.contains(clzName)) {
Files.copy(file, targetPath);
} else {
byte[] out = wave0(Files.readAllBytes(file));
Files.write(targetPath, out);
}
} else {
if (name.startsWith("META-INF/")) {
if (name.equals(JarFile.MANIFEST_NAME)) {
try (InputStream in = Files.newInputStream(file)) {
Manifest mf = new Manifest(in);
mf.getMainAttributes().put(new Name("X-NOTICE"), "Modified");
mf.getEntries().clear();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mf.write(baos);
baos.flush();
Files.write(targetPath, baos.toByteArray());
}
} else if (name.endsWith(".DSA") || name.endsWith(".RSA") || name.endsWith(".SF") || name.endsWith(".ECDSA")) {
// ignored
} else {
Files.copy(file, targetPath);
}
} else {
Files.copy(file, targetPath);
}
}
}
});
if (callbacks.size() > 0) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
String type = buildInvocationClz(cw);
byte[] data = cw.toByteArray();
Path target = to.resolve(type + ".class");
BaseCmd.createParentDirectories(target);
Files.write(target, data);
nextInvocationName();
}
}
use of java.util.jar.Attributes.Name in project bnd by bndtools.
the class Analyzer method getManifest.
/**
* Specifically for Maven
*
*/
public static Properties getManifest(File dirOrJar) throws Exception {
try (Analyzer analyzer = new Analyzer()) {
analyzer.setJar(dirOrJar);
Properties properties = new UTF8Properties();
properties.put(IMPORT_PACKAGE, "*");
properties.put(EXPORT_PACKAGE, "*");
analyzer.setProperties(properties);
Manifest m = analyzer.calcManifest();
Properties result = new UTF8Properties();
for (Iterator<Object> i = m.getMainAttributes().keySet().iterator(); i.hasNext(); ) {
Attributes.Name name = (Attributes.Name) i.next();
result.put(name.toString(), m.getMainAttributes().getValue(name));
}
return result;
}
}
Aggregations