]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/JarFileIndexer.java
Change workspace names
[gpl/argeo-slc.git] / runtime / org.argeo.slc.repo / src / main / java / org / argeo / slc / repo / JarFileIndexer.java
index 6ab3c529dd84a4b237a3556bb16c6c2bc2de5e6c..80c750407a70c23343390db139aad1066fcc4941 100644 (file)
@@ -18,6 +18,7 @@ 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;
@@ -47,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) {
@@ -78,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())
@@ -116,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 {
@@ -352,9 +368,11 @@ public class JarFileIndexer implements NodeIndexer {
                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;