Skip to content
Snippets Groups Projects
Commit a723943b authored by david_williams's avatar david_williams
Browse files

small updates

parent e001a770
No related branches found
No related tags found
No related merge requests found
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: aaa; singleton:=true
Bundle-Version: 1.0.0
Require-Bundle: org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: aaa
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: aaa; singleton:=true
Bundle-Version: 1.0.0
Require-Bundle: org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: aaa
package aaa;
import java.io.*;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Map;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.BundleException;
/**
* This simple utility was attached to bug
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=329376
* and provides a simple quick check on one form of incorrect headers.
* This simple utility was attached to bug
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=329376 and provides a simple
* quick check on one form of incorrect headers.
*/
public class Application implements IApplication {
private static final boolean DEBUG = false;
private static final String PATH = "/Users/equinox/eclipse_ibuild/plugins";
public Object start(IApplicationContext context) throws Exception {
File root = new File(PATH);
File[] children = root.listFiles();
for (File child : children) {
if (child.isDirectory()) {
processFolder(child);
} else if (child.getName().endsWith(".jar") || child.getName().endsWith(".zip")) {
processJar(child);
} else {
error("Skipping unexpected file type: " + child);
}
}
return IApplication.EXIT_OK;
}
private void debug(String message) {
if (DEBUG)
System.out.println(message);
}
private void error(String message) {
System.err.println(message);
}
private void processFolder(File folder) throws BundleException {
debug("Processing: " + folder);
File manifestFile = new File(folder, "META-INF/MANIFEST.MF");
if (!manifestFile.exists()) {
error("ERROR: Unable to read manifest at: " + manifestFile.getAbsolutePath());
return;
}
InputStream input = null;
try {
input = new BufferedInputStream(new FileInputStream(manifestFile));
processStream(input, manifestFile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
// ignore
}
}
}
}
private void processJar(File file) throws IOException, BundleException {
debug("Processing: " + file);
JarFile jar = new JarFile(file);
ZipEntry entry = jar.getEntry("META-INF/MANIFEST.MF");
if (entry == null) {
error("No manifest found in: " + file.getAbsolutePath());
return;
}
InputStream input = null;
try {
input = new BufferedInputStream(jar.getInputStream(entry));
processStream(input, file.getAbsolutePath());
} catch (IOException e) {
if (input != null) {
try {
input.close();
} catch (IOException e1) {
// ignore
}
}
}
}
private void processStream(InputStream input, String filename) throws IOException, BundleException {
String[] KEYS = new String[] { "Require-Bundle", "Fragment-Host" };
Map<String, String> manifest = getManifest(input);
for (String key : KEYS) {
String value = manifest.get(key);
if (value == null)
continue;
ManifestElement[] elements = ManifestElement.parseHeader(key, value);
if (elements != null) {
for (ManifestElement element : elements) {
if (element != null) {
for (Enumeration<String> e = element.getKeys(); e != null && e.hasMoreElements();) {
String attr = e.nextElement();
if ("version".equals(attr)) {
error(filename);
return;
}
}
}
}
}
}
}
private Map<String, String> getManifest(InputStream input) throws IOException, BundleException {
return ManifestElement.parseBundleManifest(input, null);
}
public void stop() {
// nothing to do
}
private static final boolean DEBUG = false;
private static final String PATH = "/Users/equinox/eclipse_ibuild/plugins";
private String rootpath;
private int checkedOk;
private int failedCount;
private int errorCount;
public Object start(IApplicationContext context) throws Exception {
File root = getRoot(context);
checkBundles(root);
printReport();
return IApplication.EXIT_OK;
}
private void checkBundles(File root) throws BundleException, IOException {
File[] children = root.listFiles();
for (File child : children) {
if (child.isDirectory()) {
processFolder(child);
}
else if (child.getName().endsWith(".jar") || child.getName().endsWith(".zip")) {
processJar(child);
}
else {
error("Skipping unexpected file type: " + child);
}
}
}
private void printReport() {
System.out.println();
System.out.println("Checked bundles under root path: " + rootpath);
System.out.println("Failed to read manifest (may be normal): " + failedCount);
System.out.println("Bundles with version attribute errors: " + errorCount);
System.out.println("CheckedOk: " + checkedOk);
System.out.println();
}
private File getRoot(IApplicationContext context) {
Map args = context.getArguments();
String appargskey = "application.args";
String[] appargs = (String[]) args.get(appargskey);
if (appargs.length > 0) {
rootpath = appargs[0];
System.out.println("Found path from application arguments: " + rootpath);
}
else {
rootpath = PATH;
System.out.println("No path was found from application arguments, so using default: " + rootpath);
}
File root = new File(rootpath);
return root;
}
private void debug(String message) {
if (DEBUG) {
System.out.println(message);
}
}
private void error(String message) {
System.err.println(message);
}
private void processFolder(File folder) throws BundleException {
debug("Processing: " + folder);
File manifestFile = new File(folder, "META-INF/MANIFEST.MF");
if (!manifestFile.exists()) {
error("WARNING: Unable to read manifest at: " + manifestFile.getAbsolutePath());
failedCount++;
return;
}
InputStream input = null;
try {
input = new BufferedInputStream(new FileInputStream(manifestFile));
processStream(input, manifestFile.getAbsolutePath());
}
catch (IOException e) {
e.printStackTrace();
}
finally {
if (input != null) {
try {
input.close();
}
catch (IOException e) {
// ignore
}
}
}
}
private void processJar(File file) throws IOException, BundleException {
debug("Processing: " + file);
JarFile jar = new JarFile(file);
ZipEntry entry = jar.getEntry("META-INF/MANIFEST.MF");
if (entry == null) {
error("WARNING: No manifest found in: " + file.getAbsolutePath());
failedCount++;
return;
}
InputStream input = null;
try {
input = new BufferedInputStream(jar.getInputStream(entry));
processStream(input, file.getAbsolutePath());
}
catch (IOException e) {
if (input != null) {
try {
input.close();
}
catch (IOException e1) {
System.out.println("Unexpectedly could not close stream?");
}
}
}
}
private void processStream(InputStream input, String filename) throws IOException, BundleException {
String[] KEYS = new String[]{"Require-Bundle", "Fragment-Host"};
Map<String, String> manifest = getManifest(input);
for (String key : KEYS) {
String value = manifest.get(key);
if (value == null) {
continue;
}
ManifestElement[] elements = ManifestElement.parseHeader(key, value);
if (elements != null) {
for (ManifestElement element : elements) {
if (element != null) {
for (Enumeration<String> e = element.getKeys(); (e != null) && e.hasMoreElements();) {
String attr = e.nextElement();
if ("version".equals(attr)) {
error(filename);
errorCount++;
return;
}
}
}
}
checkedOk++;
}
}
}
private Map<String, String> getManifest(InputStream input) throws IOException, BundleException {
return ManifestElement.parseBundleManifest(input, null);
}
public void stop() {
// nothing to do
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment