[hg] main-silver: reset cache on project change

  • From: Milos Kleint < >
  • To: ,
  • Subject: [hg] main-silver: reset cache on project change
  • Date: Tue, 07 May 2013 18:45:38 -0700

changeset 0caf510ad3a0 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/0caf510ad3a0
description:
        reset cache on project change

diffstat:

 
maven.apisupport/src/org/netbeans/modules/maven/apisupport/AccessQueryImpl.java
 |  71 ++++++---
 1 files changed, 46 insertions(+), 25 deletions(-)

diffs (107 lines):

diff --git 
a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/AccessQueryImpl.java
 
b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/AccessQueryImpl.java
--- 
a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/AccessQueryImpl.java
+++ 
b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/AccessQueryImpl.java
@@ -42,6 +42,8 @@
 
 package org.netbeans.modules.maven.apisupport;
 
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.io.InputStream;
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
@@ -66,8 +68,9 @@
  */
 @ProjectServiceProvider(service=AccessibilityQueryImplementation.class, 
projectType="org-netbeans-modules-maven/" + NbMavenProject.TYPE_NBM)
 public class AccessQueryImpl implements AccessibilityQueryImplementation {
-    private Project project;
+    private final Project project;
     private WeakReference<List<Pattern>> ref;
+    private PropertyChangeListener projectListener;
     
     private static final String MANIFEST_PATH = "src/main/nbm/manifest.mf"; 
//NOI18N
     private static final String ATTR_PUBLIC_PACKAGE = 
"OpenIDE-Module-Public-Packages"; //NOI18N
@@ -108,36 +111,27 @@
     }
     
     
-    List<Pattern> getPublicPackagesPatterns() {
+    synchronized List<Pattern> getPublicPackagesPatterns() {
+        if (projectListener == null) {
+            projectListener = new PropertyChangeListener() {
+                @Override
+                public void propertyChange(PropertyChangeEvent evt) {
+                    if 
(NbMavenProject.PROP_PROJECT.equals(evt.getPropertyName())) {
+                        synchronized (AccessQueryImpl.this) {
+                            ref = null;
+                        }
+                    }
+                }
+            };
+            
project.getLookup().lookup(NbMavenProject.class).addPropertyChangeListener(projectListener);
+        }
         if (ref != null) {
             List<Pattern> patterns = ref.get();
             if (patterns != null) {
                 return patterns;
             }
         }
-        List<Pattern> toRet = new ArrayList<Pattern>();
-        String[] params = PluginPropertyUtils.getPluginPropertyList(project, 
-                MavenNbModuleImpl.GROUPID_MOJO, 
MavenNbModuleImpl.NBM_PLUGIN, //NOI18N
-                "publicPackages", "publicPackage", "manifest"); //NOI18N
-        if (params != null) {
-            toRet = prepareMavenPublicPackagesPatterns(params);
-        } else {
-            FileObject obj = 
project.getProjectDirectory().getFileObject(MANIFEST_PATH);
-            if (obj != null) {
-                InputStream in = null;
-                try {
-                    in = obj.getInputStream();
-                    Manifest man = new Manifest();
-                    man.read(in);
-                    String value = 
man.getMainAttributes().getValue(ATTR_PUBLIC_PACKAGE);
-                    toRet = prepareManifestPublicPackagesPatterns(value);
-                } catch (Exception ex) {
-                    Exceptions.printStackTrace(ex);
-                } finally {
-                    IOUtil.close(in);
-                }
-            }
-        }
+        List<Pattern> toRet = loadPublicPackagesPatterns(project);
         ref = new WeakReference<List<Pattern>>(toRet);
         return toRet;
     }
@@ -187,4 +181,31 @@
         return toRet;
     }
     
+    private static List<Pattern> loadPublicPackagesPatterns(Project project) 
{
+        List<Pattern> toRet = new ArrayList<Pattern>();
+        String[] params = PluginPropertyUtils.getPluginPropertyList(project, 
+                MavenNbModuleImpl.GROUPID_MOJO, 
MavenNbModuleImpl.NBM_PLUGIN, //NOI18N
+                "publicPackages", "publicPackage", "manifest"); //NOI18N
+        if (params != null) {
+            toRet = prepareMavenPublicPackagesPatterns(params);
+        } else {
+            FileObject obj = 
project.getProjectDirectory().getFileObject(MANIFEST_PATH);
+            if (obj != null) {
+                InputStream in = null;
+                try {
+                    in = obj.getInputStream();
+                    Manifest man = new Manifest();
+                    man.read(in);
+                    String value = 
man.getMainAttributes().getValue(ATTR_PUBLIC_PACKAGE);
+                    toRet = prepareManifestPublicPackagesPatterns(value);
+                } catch (Exception ex) {
+                    Exceptions.printStackTrace(ex);
+                } finally {
+                    IOUtil.close(in);
 }
+            }
+        }
+        return toRet;
+    }
+    
+}

[hg] main-silver: reset cache on project change

Milos Kleint 05/08/2013

Project Features

About this Project

APIsupport was started in November 2009, is owned by Antonin Nebuzelsky, and has 43 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close