You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/01/28 19:32:27 UTC

[GitHub] geertjanw closed pull request #372: [NETBEANS-238]: speeding up package lookup in jars by not listing the?

geertjanw closed pull request #372: [NETBEANS-238]: speeding up package lookup in jars by not listing the?
URL: https://github.com/apache/incubator-netbeans/pull/372
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/java.source.base/src/org/netbeans/modules/java/source/classpath/CacheClassPath.java b/java.source.base/src/org/netbeans/modules/java/source/classpath/CacheClassPath.java
index 58d7b3f7a..453648692 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/classpath/CacheClassPath.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/classpath/CacheClassPath.java
@@ -245,7 +245,7 @@ public CachingPathResourceImpl(
             if (result == null) {
                 result = EMPTY;
                 try {
-                    File sigs = JavaIndex.getClassFolder(originalRoot,false,scan);
+                    File sigs = JavaIndex.getClassFolder(originalRoot,false,false);
                     URL orl = FileUtil.urlForArchiveOrDir(sigs);
                     if (orl != null) {
                         result = new URL[] {orl};
diff --git a/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaBinaryIndexer.java b/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaBinaryIndexer.java
index 7875bda22..1629da456 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaBinaryIndexer.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaBinaryIndexer.java
@@ -120,7 +120,7 @@ protected void index(final Context context) {
     }
 
     private static void deleteSigFiles(final URL root, final List<? extends ElementHandle<TypeElement>> toRemove) throws IOException {
-        File cacheFolder = JavaIndex.getClassFolder(root);
+        File cacheFolder = JavaIndex.getClassFolder(root, false, false);
         if (cacheFolder.exists()) {
             if (toRemove.size() > CLEAN_ALL_LIMIT) {
                 //Todo: do as SlowIOTask
@@ -287,11 +287,21 @@ public void scanFinished(Context context) {
                 } else {
                     txCtx.commit();
                 }
+                File classes = JavaIndex.getClassFolder(context.getRootURI(), false, false);
+                if (classes.exists() && isEmpty(classes)) {
+                    classes.delete();
+                }
             } catch (IOException ex) {
                 Exceptions.printStackTrace(ex);
             }
         }
 
+        private boolean isEmpty(File dir) {
+            String[] content = dir.list();
+
+            return content == null || content.length == 0;
+        }
+
         @MimeRegistration(mimeType="", service=BinaryIndexerFactory.class)
         public static Factory register() {
             return NoJavacHelper.hasWorkingJavac() ? new Factory() : null;
diff --git a/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaIndex.java b/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaIndex.java
index 62a253740..d44b77b18 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaIndex.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaIndex.java
@@ -366,4 +366,9 @@ public void run() {
             }
         }
     }
+
+    public static boolean isCacheFolder(File dir) {
+        File cacheFolder = FileUtil.toFile(CacheFolder.getCacheFolder());
+        return dir.toURI().toASCIIString().startsWith(cacheFolder.toURI().toASCIIString());
+    }
 }
diff --git a/java.source.base/src/org/netbeans/modules/java/source/parsing/Archive.java b/java.source.base/src/org/netbeans/modules/java/source/parsing/Archive.java
index a8fc9fa3f..47b498322 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/parsing/Archive.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/parsing/Archive.java
@@ -20,6 +20,7 @@
 package org.netbeans.modules.java.source.parsing;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.Set;
 import javax.tools.JavaFileObject;
 import org.netbeans.api.annotations.common.NonNull;
@@ -69,4 +70,30 @@
      * @return true if the {@link Archive} is supports multiple releases.
      */
     public boolean isMultiRelease();
+
+    public static Archive EMPTY = new Archive() {
+        @Override
+        public Iterable<JavaFileObject> getFiles(String folderName, ClassPath.Entry entry, Set<JavaFileObject.Kind> kinds, JavaFileFilterImplementation filter, boolean recursive) throws IOException {
+            return Collections.emptyList();
+        }
+
+        @Override
+        public JavaFileObject create(String relativeName, JavaFileFilterImplementation filter) throws UnsupportedOperationException {
+            return null;
+        }
+
+        @Override
+        public void clear() {
+        }
+
+        @Override
+        public JavaFileObject getFile(String name) throws IOException {
+            return null;
+        }
+
+        @Override
+        public boolean isMultiRelease() {
+            return false;
+        }
+    };
 }
diff --git a/java.source.base/src/org/netbeans/modules/java/source/parsing/CacheFolderArchive.java b/java.source.base/src/org/netbeans/modules/java/source/parsing/CacheFolderArchive.java
new file mode 100644
index 000000000..fed6986da
--- /dev/null
+++ b/java.source.base/src/org/netbeans/modules/java/source/parsing/CacheFolderArchive.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.netbeans.modules.java.source.parsing;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Set;
+
+import javax.tools.JavaFileObject;
+import javax.tools.JavaFileObject.Kind;
+
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.java.classpath.ClassPath.Entry;
+import org.netbeans.modules.java.preprocessorbridge.spi.JavaFileFilterImplementation;
+import org.openide.filesystems.FileAttributeEvent;
+import org.openide.filesystems.FileChangeListener;
+import org.openide.filesystems.FileEvent;
+import org.openide.filesystems.FileRenameEvent;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Parameters;
+
+/**
+ *
+ * @author Tomas Zezula
+ */
+class CacheFolderArchive implements Archive, FileChangeListener {
+
+    private volatile Archive delegate;
+    private final File cache;
+
+    public CacheFolderArchive(
+            @NonNull File cache) {
+        Parameters.notNull("cache", cache); //NOI18N
+        this.cache = cache;
+        if (cache.isDirectory()) {
+            delegate = new FolderArchive(cache);
+        } else {
+            FileUtil.addFileChangeListener(this, cache);
+            delegate = Archive.EMPTY;
+        }
+    }
+
+    @Override
+    public JavaFileObject getFile(String name) throws IOException {
+        return delegate.getFile(name);
+    }
+
+    @Override
+    public void clear() {
+        delegate.clear();
+    }
+
+    @Override
+    public JavaFileObject create(String relativeName, JavaFileFilterImplementation filter) throws UnsupportedOperationException {
+        return delegate.create(relativeName, filter);
+    }
+
+    @Override
+    public boolean isMultiRelease() {
+        return delegate.isMultiRelease();
+    }
+
+    @Override
+    public Iterable<JavaFileObject> getFiles(String folderName, Entry entry, Set<Kind> kinds, JavaFileFilterImplementation filter, boolean recursive) throws IOException {
+        return delegate.getFiles(folderName, entry, kinds, filter, recursive);
+    }
+
+    private void update() {
+        if (cache.isDirectory()) {
+            delegate = new FolderArchive(cache);
+            FileUtil.removeFileChangeListener(this, cache);
+        }
+    }
+
+    @Override
+    public void fileFolderCreated(FileEvent fe) {
+        update();
+    }
+
+    @Override
+    public void fileDataCreated(FileEvent fe) {
+        update();
+    }
+
+    @Override
+    public void fileChanged(FileEvent fe) {
+        update();
+    }
+
+    @Override
+    public void fileDeleted(FileEvent fe) {
+        update();
+    }
+
+    @Override
+    public void fileRenamed(FileRenameEvent fe) {
+        update();
+    }
+
+    @Override
+    public void fileAttributeChanged(FileAttributeEvent fe) {
+        update();
+    }
+
+}
diff --git a/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingArchiveProvider.java b/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingArchiveProvider.java
index 06c746539..56b9c1c87 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingArchiveProvider.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingArchiveProvider.java
@@ -27,17 +27,21 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+
 import org.netbeans.api.annotations.common.CheckForNull;
 import org.netbeans.api.annotations.common.NonNull;
 import org.netbeans.api.java.classpath.ClassPath;
 import org.netbeans.api.java.platform.JavaPlatform;
 import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.modules.java.source.indexing.JavaIndex;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
 import org.openide.filesystems.URLMapper;
@@ -241,7 +245,9 @@ synchronized void clear() {
         String protocol = root.first().getProtocol();
         if ("file".equals(protocol)) {      //NOI18N
             File f = BaseUtilities.toFile(root.second());
-            if (f.isDirectory()) {
+            if (JavaIndex.isCacheFolder(f)) {
+                return Pair.<Archive,URI>of(new CacheFolderArchive(f), null);
+            } else if (f.isDirectory()) {
                 return Pair.<Archive,URI>of(new FolderArchive (f), null);
             }
             else {
diff --git a/java.source.base/src/org/netbeans/modules/java/source/parsing/WriteBackTransaction.java b/java.source.base/src/org/netbeans/modules/java/source/parsing/WriteBackTransaction.java
index bf135f728..09c36cd29 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/parsing/WriteBackTransaction.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/parsing/WriteBackTransaction.java
@@ -72,7 +72,7 @@
         super(true);
         this.root = root;
         try {
-            this.classesFolder = BaseUtilities.toURI(JavaIndex.getClassFolder(root)).toURL();
+            this.classesFolder = BaseUtilities.toURI(JavaIndex.getClassFolder(root, false, false)).toURL();
         } catch (IOException ioe) {
             throw new RuntimeException(ioe);
         }
diff --git a/java.source.nbjavac/src/org/netbeans/modules/java/source/nbjavac/parsing/TreeLoader.java b/java.source.nbjavac/src/org/netbeans/modules/java/source/nbjavac/parsing/TreeLoader.java
index c6b7849cd..9067e4017 100644
--- a/java.source.nbjavac/src/org/netbeans/modules/java/source/nbjavac/parsing/TreeLoader.java
+++ b/java.source.nbjavac/src/org/netbeans/modules/java/source/nbjavac/parsing/TreeLoader.java
@@ -391,7 +391,7 @@ private static File getClassFolder(
         }
         int index = surl.lastIndexOf(FileObjects.convertPackage2Folder(binaryName));
         if (index > 0) {
-            return JavaIndex.getClassFolder(new URL(surl.substring(0, index)));
+            return JavaIndex.getClassFolder(new URL(surl.substring(0, index)), false, false);
         } else {
             LOGGER.log(
                Level.INFO,


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists