X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.repo%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Frepo%2FJarFileIndexer.java;h=328d4c560ec67f26a89bb2a9b8ded00ec9a65bb0;hb=e70fb767d8ff5972d88ab436762e71ea622a0f72;hp=9e4af70651d68033faf2fba925082c5b4f724171;hpb=4663b42433ba4a16c81d90927aecff2a923cd7a4;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/JarFileIndexer.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/JarFileIndexer.java index 9e4af7065..328d4c560 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/JarFileIndexer.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/JarFileIndexer.java @@ -1,8 +1,24 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.slc.repo; 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; @@ -32,7 +48,7 @@ import org.osgi.framework.Version; * 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) { @@ -63,13 +79,27 @@ public class JarFileIndexer implements NodeIndexer { 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()) @@ -101,6 +131,7 @@ public class JarFileIndexer implements NodeIndexer { if (log.isTraceEnabled()) log.trace("Indexed JAR file " + fileNode); } + } catch (Exception e) { throw new SlcException("Cannot index jar " + fileNode, e); } finally { @@ -180,7 +211,7 @@ public class JarFileIndexer implements NodeIndexer { cleanSubNodes(fileNode, SlcNames.SLC_ + Constants.IMPORT_PACKAGE); if (attrs.containsKey(new Name(Constants.IMPORT_PACKAGE))) { String importPackages = attrs.getValue(Constants.IMPORT_PACKAGE); - List packages = parsePackages(importPackages); + List packages = parseCommaSeparated(importPackages); for (String pkg : packages) { String[] tokens = pkg.split(";"); Node node = fileNode.addNode(SlcNames.SLC_ @@ -207,7 +238,7 @@ public class JarFileIndexer implements NodeIndexer { if (attrs.containsKey(new Name(Constants.DYNAMICIMPORT_PACKAGE))) { String importPackages = attrs .getValue(Constants.DYNAMICIMPORT_PACKAGE); - List packages = parsePackages(importPackages); + List packages = parseCommaSeparated(importPackages); for (String pkg : packages) { String[] tokens = pkg.split(";"); Node node = fileNode.addNode(SlcNames.SLC_ @@ -227,7 +258,7 @@ public class JarFileIndexer implements NodeIndexer { cleanSubNodes(fileNode, SlcNames.SLC_ + Constants.EXPORT_PACKAGE); if (attrs.containsKey(new Name(Constants.EXPORT_PACKAGE))) { String exportPackages = attrs.getValue(Constants.EXPORT_PACKAGE); - List packages = parsePackages(exportPackages); + List packages = parseCommaSeparated(exportPackages); for (String pkg : packages) { String[] tokens = pkg.split(";"); Node node = fileNode.addNode(SlcNames.SLC_ @@ -263,7 +294,7 @@ public class JarFileIndexer implements NodeIndexer { 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 bundles = parseCommaSeparated(requireBundle); for (String bundle : bundles) { String[] tokens = bundle.split(";"); Node node = fileNode.addNode(SlcNames.SLC_ @@ -331,15 +362,17 @@ public class JarFileIndexer implements NodeIndexer { } /** Parse package list with nested directive with ',' */ - private List parsePackages(String str) { + private List parseCommaSeparated(String str) { List res = new ArrayList(); 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;