/*
- * Copyright (C) 2007-2012 Mathieu Baudier
+ * Copyright (C) 2007-2012 Argeo GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.Attributes.Name;
* Indexes jar file, currently supports standard J2SE and OSGi metadata (both
* from MANIFEST)
*/
-public class JarFileIndexer implements NodeIndexer {
+public class JarFileIndexer implements NodeIndexer, SlcNames {
private final static Log log = LogFactory.getLog(JarFileIndexer.class);
public Boolean support(String path) {
ByteArrayInputStream bi = null;
Binary manifestBinary = null;
try {
+ if(!support(fileNode.getPath()))
+ return;
+
if (!fileNode.isNodeType(NodeType.NT_FILE))
return;
log.error(fileNode + " has no MANIFEST");
return;
}
+
bo = new ByteArrayOutputStream();
manifest.write(bo);
- bi = new ByteArrayInputStream(bo.toByteArray());
+ byte[] newManifest = bo.toByteArray();
+ if (fileNode.hasProperty(SLC_MANIFEST)) {
+ byte[] storedManifest = JcrUtils.getBinaryAsBytes(fileNode
+ .getProperty(SLC_MANIFEST));
+ if (Arrays.equals(newManifest, storedManifest)) {
+ if (log.isTraceEnabled())
+ log.trace("Manifest not changed, doing nothing "
+ + fileNode);
+ return;
+ }
+ }
+
+ bi = new ByteArrayInputStream(newManifest);
manifestBinary = jcrSession.getValueFactory().createBinary(bi);
// standard jar file
fileNode.addMixin(SlcTypes.SLC_JAR_FILE);
+
fileNode.setProperty(SlcNames.SLC_MANIFEST, manifestBinary);
Attributes attrs = manifest.getMainAttributes();
if (log.isTraceEnabled())
if (log.isTraceEnabled())
log.trace("Indexed JAR file " + fileNode);
}
+
} catch (Exception e) {
throw new SlcException("Cannot index jar " + fileNode, e);
} finally {
cleanSubNodes(fileNode, SlcNames.SLC_ + Constants.IMPORT_PACKAGE);
if (attrs.containsKey(new Name(Constants.IMPORT_PACKAGE))) {
String importPackages = attrs.getValue(Constants.IMPORT_PACKAGE);
- List<String> packages = parsePackages(importPackages);
+ List<String> packages = parseCommaSeparated(importPackages);
for (String pkg : packages) {
String[] tokens = pkg.split(";");
Node node = fileNode.addNode(SlcNames.SLC_
if (attrs.containsKey(new Name(Constants.DYNAMICIMPORT_PACKAGE))) {
String importPackages = attrs
.getValue(Constants.DYNAMICIMPORT_PACKAGE);
- List<String> packages = parsePackages(importPackages);
+ List<String> packages = parseCommaSeparated(importPackages);
for (String pkg : packages) {
String[] tokens = pkg.split(";");
Node node = fileNode.addNode(SlcNames.SLC_
cleanSubNodes(fileNode, SlcNames.SLC_ + Constants.EXPORT_PACKAGE);
if (attrs.containsKey(new Name(Constants.EXPORT_PACKAGE))) {
String exportPackages = attrs.getValue(Constants.EXPORT_PACKAGE);
- List<String> packages = parsePackages(exportPackages);
+ List<String> packages = parseCommaSeparated(exportPackages);
for (String pkg : packages) {
String[] tokens = pkg.split(";");
Node node = fileNode.addNode(SlcNames.SLC_
cleanSubNodes(fileNode, SlcNames.SLC_ + Constants.REQUIRE_BUNDLE);
if (attrs.containsKey(new Name(Constants.REQUIRE_BUNDLE))) {
String requireBundle = attrs.getValue(Constants.REQUIRE_BUNDLE);
- String[] bundles = requireBundle.split(",");
+ List<String> bundles = parseCommaSeparated(requireBundle);
for (String bundle : bundles) {
String[] tokens = bundle.split(";");
Node node = fileNode.addNode(SlcNames.SLC_
}
/** Parse package list with nested directive with ',' */
- private List<String> parsePackages(String str) {
+ private List<String> parseCommaSeparated(String str) {
List<String> res = new ArrayList<String>();
StringBuffer curr = new StringBuffer("");
boolean in = false;
for (char c : str.toCharArray()) {
if (c == ',') {
- if (!in) {
+ if (!in) {// new package
res.add(curr.toString());
curr = new StringBuffer("");
+ } else {// a ',' within " "
+ curr.append(c);
}
} else if (c == '\"') {
in = !in;