use of java.util.jar.Attributes in project vertx-docgen by vert-x3.
the class BaseProcessor method resolveCoordinate.
/**
* Resolve the coordinate of the type element, this method returns either:
* <ul>
* <li>a {@link io.vertx.docgen.Coordinate} object, the coordinate object can have null fields</li>
* <li>{@code null} : the current element is being compiled, which likely means create a local link</li>
* </ul>
*
* @param typeElt the type element to resolve
* @return the resolved coordinate object or null if the element is locally compiled
*/
private Coordinate resolveCoordinate(TypeElement typeElt) {
try {
Symbol.ClassSymbol cs = (Symbol.ClassSymbol) typeElt;
if (cs.sourcefile != null && getURL(cs.sourcefile) != null) {
// .java source we can link locally
return null;
}
if (cs.classfile != null) {
JavaFileObject cf = cs.classfile;
URL classURL = getURL(cf);
if (classURL != null && classURL.getFile().endsWith(".class")) {
URL manifestURL = new URL(classURL.toString().substring(0, classURL.toString().length() - (typeElt.getQualifiedName().toString().length() + 6)) + "META-INF/MANIFEST.MF");
InputStream manifestIs = manifestURL.openStream();
if (manifestIs != null) {
Manifest manifest = new Manifest(manifestIs);
Attributes attributes = manifest.getMainAttributes();
String groupId = attributes.getValue(new Attributes.Name("Maven-Group-Id"));
String artifactId = attributes.getValue(new Attributes.Name("Maven-Artifact-Id"));
String version = attributes.getValue(new Attributes.Name("Maven-Version"));
return new Coordinate(groupId, artifactId, version);
}
}
}
} catch (Exception ignore) {
//
}
return new Coordinate(null, null, null);
}
use of java.util.jar.Attributes in project tigervnc by TigerVNC.
the class VncViewer method getTimestamp.
private static void getTimestamp() {
if (version == null || build == null) {
try {
Manifest manifest = new Manifest(timestamp);
Attributes attributes = manifest.getMainAttributes();
version = attributes.getValue("Version");
build = attributes.getValue("Build");
buildDate = attributes.getValue("Package-Date");
buildTime = attributes.getValue("Package-Time");
} catch (java.lang.Exception e) {
}
}
}
use of java.util.jar.Attributes in project J2ME-Loader by nikita36078.
the class AndroidProducer method processJar.
public static void processJar(File jarInputFile, File jarOutputFile, boolean isMidlet) throws IOException {
JarInputStream jis = null;
JarOutputStream jos = null;
HashMap<String, byte[]> resources = new HashMap<>();
try {
jis = new JarInputStream(new FileInputStream(jarInputFile));
Manifest manifest = jis.getManifest();
if (manifest == null) {
jos = new JarOutputStream(new FileOutputStream(jarOutputFile));
} else {
Attributes attributes = manifest.getMainAttributes();
if (!attributes.containsKey(Attributes.Name.MANIFEST_VERSION)) {
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
}
jos = new JarOutputStream(new FileOutputStream(jarOutputFile), manifest);
}
byte[] buffer = new byte[1024];
JarEntry jarEntry;
while ((jarEntry = jis.getNextJarEntry()) != null) {
if (!jarEntry.isDirectory()) {
String name = jarEntry.getName();
int size = 0;
int read;
int length = buffer.length;
while ((read = jis.read(buffer, size, length)) > 0) {
size += read;
length = 1024;
if (size + length > buffer.length) {
byte[] newInputBuffer = new byte[size + length];
System.arraycopy(buffer, 0, newInputBuffer, 0, buffer.length);
buffer = newInputBuffer;
}
}
byte[] inBuffer = new byte[size];
System.arraycopy(buffer, 0, inBuffer, 0, size);
resources.put(name, inBuffer);
if (name.endsWith(".class")) {
analyze(name.substring(0, name.length() - ".class".length()), new ByteArrayInputStream(inBuffer));
}
}
}
for (String name : resources.keySet()) {
byte[] inBuffer = resources.get(name);
byte[] outBuffer = inBuffer;
if (name.endsWith(".class")) {
outBuffer = instrument(name, new ByteArrayInputStream(inBuffer), isMidlet);
}
jos.putNextEntry(new JarEntry(name));
jos.write(outBuffer);
}
} finally {
if (jis != null) {
jis.close();
}
if (jos != null) {
jos.close();
}
}
}
use of java.util.jar.Attributes in project ignite by apache.
the class GridUriDeploymentJarVerifier method getSignedFiles.
/**
* Gets all signed files from the manifest.
* <p>
* It scans all manifest entries and their attributes. If there is an attribute
* name which ends with "-DIGEST" we are assuming that manifest entry name is a
* signed file name.
*
* @param manifest JAR file manifest.
* @return Either empty set if none found or set of signed file names.
*/
private static Set<String> getSignedFiles(Manifest manifest) {
Set<String> fileNames = new HashSet<>();
Map<String, Attributes> entries = manifest.getEntries();
if (entries != null && entries.size() > 0) {
for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
Attributes attrs = entry.getValue();
for (Map.Entry<Object, Object> attrEntry : attrs.entrySet()) {
if (attrEntry.getKey().toString().toUpperCase().endsWith("-DIGEST")) {
fileNames.add(entry.getKey());
break;
}
}
}
}
return fileNames;
}
use of java.util.jar.Attributes in project Lucee by lucee.
the class BundleBuilderFactory method extendManifest.
private void extendManifest(Manifest mf) {
Attributes attrs = mf.getMainAttributes();
attrs.putValue("Bundle-ManifestVersion", "" + MANIFEST_VERSION);
if (!StringUtil.isEmpty(name))
attrs.putValue("Bundle-Name", name);
attrs.putValue("Bundle-SymbolicName", symbolicName);
if (!StringUtil.isEmpty(description))
attrs.putValue("Bundle-Description", description);
if (!StringUtil.isEmpty(bundleActivationPolicy))
attrs.putValue("Bundle-ActivationPolicy", bundleActivationPolicy);
if (version != null)
attrs.putValue("Bundle-Version", version.toString());
if (!StringUtil.isEmpty(activator)) {
if (!activator.equalsIgnoreCase("none")) {
attrs.putValue("Bundle-Activator", activator);
addImportPackage("org.osgi.framework");
} else {
// attrs.remove("Bundle-Activator");
attrs.putValue("Bundle-Activator", "");
}
}
// Export-Package
String str = ignoreExistingManifest ? null : attrs.getValue("Export-Package");
// no existing Export-Package
Set<String> set;
if (Util.isEmpty(str, true)) {
set = existingPackages;
} else {
set = new HashSet<String>();
addPackages(set, str);
}
if (!ArrayUtil.isEmpty(exportPackage) && !isAsterix(exportPackage)) {
Iterator<String> it = exportPackage.iterator();
while (it.hasNext()) {
set.add(it.next());
}
}
exportPackage = ListUtil.toList(set);
addList(attrs, "Export-Package", exportPackage);
// Require-Bundle
str = attrs.getValue("Require-Bundle");
if (Util.isEmpty(str, true))
addList(attrs, "Require-Bundle", requireBundle);
// Require-Bundle
str = attrs.getValue("Require-Bundle-Fragment");
if (Util.isEmpty(str, true))
addList(attrs, "Require-Bundle-Fragment", requireBundleFragment);
// str = attrs.getValue("Fragment-Host");
// if(Util.isEmpty(str,true))
attrs.remove("Fragment-Host");
addList(attrs, "Fragment-Host", fragmentHost);
str = attrs.getValue("Import-Package");
if (Util.isEmpty(str, true))
addList(attrs, "Import-Package", importPackage);
str = attrs.getValue("DynamicImport-Package");
if (Util.isEmpty(str, true))
addList(attrs, "DynamicImport-Package", dynImportPackage);
str = attrs.getValue("Bundle-ClassPath");
if (Util.isEmpty(str, true))
addList(attrs, "Bundle-ClassPath", classPath);
}
Aggregations