This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 215930
Collapse All | Expand All

(-)a/web.jsf.editor/src/org/netbeans/modules/web/jsf/editor/JsfSupportImpl.java (-14 / +56 lines)
Lines 41-55 Link Here
41
 */
41
 */
42
package org.netbeans.modules.web.jsf.editor;
42
package org.netbeans.modules.web.jsf.editor;
43
43
44
import javax.swing.text.Document;
45
import org.netbeans.api.project.Project;
44
import org.netbeans.api.project.Project;
46
import org.netbeans.modules.parsing.api.Source;
45
import org.netbeans.modules.parsing.api.Source;
47
import org.netbeans.modules.web.beans.api.model.support.WebBeansModelSupport;
46
import org.netbeans.modules.web.beans.api.model.support.WebBeansModelSupport;
48
import java.beans.PropertyChangeEvent;
47
import java.beans.PropertyChangeEvent;
49
import java.beans.PropertyChangeListener;
48
import java.beans.PropertyChangeListener;
49
import java.util.Collection;
50
import java.util.HashSet;
50
import java.util.Map;
51
import java.util.Map;
52
import java.util.WeakHashMap;
51
import org.netbeans.api.java.classpath.ClassPath;
53
import org.netbeans.api.java.classpath.ClassPath;
52
import org.netbeans.api.project.FileOwnerQuery;
54
import org.netbeans.api.java.project.JavaProjectConstants;
55
import org.netbeans.api.project.ProjectUtils;
56
import org.netbeans.api.project.SourceGroup;
57
import org.netbeans.api.project.Sources;
53
import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel;
58
import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel;
54
import org.netbeans.modules.web.api.webmodule.WebModule;
59
import org.netbeans.modules.web.api.webmodule.WebModule;
55
import org.netbeans.modules.web.beans.api.model.ModelUnit;
60
import org.netbeans.modules.web.beans.api.model.ModelUnit;
Lines 61-66 Link Here
61
import org.netbeans.modules.web.jsfapi.api.JsfSupport;
66
import org.netbeans.modules.web.jsfapi.api.JsfSupport;
62
import org.netbeans.modules.web.jsfapi.api.Library;
67
import org.netbeans.modules.web.jsfapi.api.Library;
63
import org.netbeans.modules.web.jsfapi.spi.JsfSupportProvider;
68
import org.netbeans.modules.web.jsfapi.spi.JsfSupportProvider;
69
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
64
import org.openide.filesystems.FileObject;
70
import org.openide.filesystems.FileObject;
65
import org.openide.util.Lookup;
71
import org.openide.util.Lookup;
66
import org.openide.util.lookup.AbstractLookup;
72
import org.openide.util.lookup.AbstractLookup;
Lines 89-118 Link Here
89
            return null;
95
            return null;
90
        }
96
        }
91
    }
97
    }
98
    
99
    private static final Map<Project, Boolean> REJECTED_PROJECTS_CACHE = //java source project resolution map
100
            new WeakHashMap<Project, Boolean>();
92
101
102
    //synchronized in JsfSupportProvider.get(Project project)
93
    static JsfSupportImpl findForProject(Project project) {
103
    static JsfSupportImpl findForProject(Project project) {
94
        WebModule wm = WebModule.getWebModule(project.getProjectDirectory());
104
        //JsfSupportProvider.get(Project) caches JsfSupport instances, but for projects
95
        FileObject classpathBase = wm != null ? wm.getDocumentBase() : project.getProjectDirectory();
105
        //which don't have the jsf ability this method is called again and again, some 
96
	ClassPath classPath = ClassPath.getClassPath(classpathBase, ClassPath.COMPILE);
106
        //some caching will help here.
97
	if(classPath == null) {
107
        Boolean res = REJECTED_PROJECTS_CACHE.get(project);
98
	    return null;
108
        if(res != null && res.booleanValue()) {
99
	}
109
            //this project was already tested and it doesn't support the JSF
100
110
            return null;
101
        return new JsfSupportImpl(project, wm, classPath);
111
        }
102
112
        
113
        WebModule webModule = WebModule.getWebModule(project.getProjectDirectory());
114
        if(webModule != null) {
115
            //web project
116
            ClassPath compileCP = ClassPath.getClassPath(webModule.getDocumentBase(), ClassPath.COMPILE);
117
            ClassPath executeCP = ClassPath.getClassPath(webModule.getDocumentBase(), ClassPath.EXECUTE);
118
            
119
            return new JsfSupportImpl(project, webModule, compileCP, executeCP);
120
        } else {
121
            //non-web project
122
            Sources sources = ProjectUtils.getSources(project);
123
            if ( sources != null ){
124
                SourceGroup[] sourceGroups = sources.getSourceGroups( JavaProjectConstants.SOURCES_TYPE_JAVA );
125
                if(sourceGroups.length > 0) {
126
                    Collection<ClassPath> compileCps = new HashSet<ClassPath>();
127
                    Collection<ClassPath> executeCps = new HashSet<ClassPath>();
128
                    for(SourceGroup sg : sourceGroups) {
129
                        compileCps.add(ClassPath.getClassPath(sg.getRootFolder(), ClassPath.COMPILE));
130
                        executeCps.add(ClassPath.getClassPath(sg.getRootFolder(), ClassPath.EXECUTE));
131
                    }
132
                    return new JsfSupportImpl(project, null, 
133
                            ClassPathSupport.createProxyClassPath(compileCps.toArray(new ClassPath[]{})),
134
                            ClassPathSupport.createProxyClassPath(executeCps.toArray(new ClassPath[]{})));
135
                }
136
            }
137
        }
138
        
139
        //no jsf support for this project
140
        REJECTED_PROJECTS_CACHE.put(project, Boolean.TRUE);
141
        
142
        return null;
103
    }
143
    }
144
    
104
    private FaceletsLibrarySupport faceletsLibrarySupport;
145
    private FaceletsLibrarySupport faceletsLibrarySupport;
105
    private Project project;
146
    private Project project;
106
    private WebModule wm;
147
    private WebModule wm;
107
    private ClassPath classpath;
148
    private ClassPath classpath, executeClassPath;
108
    private JsfIndex index;
149
    private JsfIndex index;
109
    private MetadataModel<WebBeansModel> webBeansModel;
150
    private MetadataModel<WebBeansModel> webBeansModel;
110
    private Lookup lookup;
151
    private Lookup lookup;
111
152
112
    private JsfSupportImpl(Project project, WebModule wm, ClassPath classPath) {
153
    private JsfSupportImpl(Project project, WebModule wm, ClassPath classPath, ClassPath executeClassPath) {
113
        this.project = project;
154
        this.project = project;
114
        this.wm = wm;
155
        this.wm = wm;
115
        this.classpath = classPath;
156
        this.classpath = classPath;
157
        this.executeClassPath = executeClassPath;
116
        this.faceletsLibrarySupport = new FaceletsLibrarySupport(this);
158
        this.faceletsLibrarySupport = new FaceletsLibrarySupport(this);
117
159
118
        //adds a classpath listener which invalidates the index instance after classpath change
160
        //adds a classpath listener which invalidates the index instance after classpath change
Lines 180-186 Link Here
180
    //garbage methods below, needs cleanup!
222
    //garbage methods below, needs cleanup!
181
    public synchronized JsfIndex getIndex() {
223
    public synchronized JsfIndex getIndex() {
182
        if(index == null) {
224
        if(index == null) {
183
	    this.index = JsfIndex.create(getBaseFile());
225
	    this.index = JsfIndex.create(getBaseFile(), classpath, executeClassPath);
184
        }
226
        }
185
        return this.index;
227
        return this.index;
186
    }
228
    }
(-)a/web.jsf.editor/src/org/netbeans/modules/web/jsf/editor/index/JsfIndex.java (-11 / +5 lines)
Lines 63-70 Link Here
63
 */
63
 */
64
public class JsfIndex {
64
public class JsfIndex {
65
65
66
    public static JsfIndex create(FileObject baseFile) {
66
    public static JsfIndex create(FileObject baseFile, ClassPath compileCp, ClassPath executeCp) {
67
        return new JsfIndex(baseFile);
67
        return new JsfIndex(baseFile, compileCp, executeCp);
68
    }
68
    }
69
    private final FileObject[] sourceRoots;
69
    private final FileObject[] sourceRoots;
70
    private final FileObject[] binaryRoots;
70
    private final FileObject[] binaryRoots;
Lines 72-90 Link Here
72
    private final FileObject base;
72
    private final FileObject base;
73
73
74
    /** Creates a new instance of JsfIndex */
74
    /** Creates a new instance of JsfIndex */
75
    private JsfIndex(FileObject baseFile) {
75
    private JsfIndex(FileObject baseFile, ClassPath compileCp, ClassPath executeCp) {
76
        this.base = baseFile;
76
        this.base = baseFile;
77
        
77
        
78
        //#179930 - merge compile and execute classpath, remove once #180183 resolved
78
        //#179930 - merge compile and execute classpath, remove once #180183 resolved
79
        Collection<FileObject> roots = new HashSet<FileObject>();
79
        Collection<FileObject> roots = new HashSet<FileObject>();
80
        ClassPath compileCp = ClassPath.getClassPath(base, ClassPath.COMPILE);
80
        roots.addAll(Arrays.asList(compileCp.getRoots()));
81
        if(compileCp != null) {
81
        roots.addAll(Arrays.asList(executeCp.getRoots()));
82
            roots.addAll(Arrays.asList(compileCp.getRoots()));
83
        }
84
        ClassPath executeCp = ClassPath.getClassPath(base, ClassPath.EXECUTE);
85
        if(executeCp != null) {
86
            roots.addAll(Arrays.asList(executeCp.getRoots()));
87
        }
88
        binaryRoots = roots.toArray(new FileObject[]{});
82
        binaryRoots = roots.toArray(new FileObject[]{});
89
83
90
        Collection<FileObject> croots = QuerySupport.findRoots(base, null, null, null);
84
        Collection<FileObject> croots = QuerySupport.findRoots(base, null, null, null);

Return to bug 215930