diff --git a/java.source/src/org/netbeans/api/java/source/ClasspathInfo.java b/java.source/src/org/netbeans/api/java/source/ClasspathInfo.java --- a/java.source/src/org/netbeans/api/java/source/ClasspathInfo.java +++ b/java.source/src/org/netbeans/api/java/source/ClasspathInfo.java @@ -82,6 +82,7 @@ import org.netbeans.modules.java.source.classpath.AptCacheForSourceQuery; import org.netbeans.modules.java.source.classpath.SourcePath; import org.netbeans.modules.java.source.indexing.JavaIndex; +import org.netbeans.modules.java.source.parsing.AptOutputFileManager; import org.netbeans.modules.java.source.parsing.AptSourceFileManager; import org.netbeans.modules.java.source.parsing.FileObjects; import org.netbeans.modules.java.source.parsing.GeneratedFileMarker; @@ -126,6 +127,8 @@ private final ClassPath cachedUserSrcClassPath; private final ClassPath cachedAptSrcClassPath; private final ClassPath cachedSrcClassPath; // = cachedUserSrcClassPath + cachedAptSrcClassPath + private final ClassPath cachedAptOutputClassPath; + private final ClassPath cachedUserAndGenSrcClassPath; private final ClassPath cachedBootClassPath; private final ClassPath cachedCompileClassPath; private ClassPath outputClassPath; @@ -165,17 +168,18 @@ this.cachedBootClassPath.addPropertyChangeListener(WeakListeners.propertyChange(this.cpListener,this.cachedBootClassPath)); this.cachedCompileClassPath.addPropertyChangeListener(WeakListeners.propertyChange(this.cpListener,this.cachedCompileClassPath)); if (srcCp == null) { - this.cachedAptSrcClassPath = null; - this.cachedSrcClassPath = this.srcClassPath = this.cachedUserSrcClassPath = EMPTY_PATH; + this.cachedAptSrcClassPath = this.cachedAptOutputClassPath = null; + this.cachedSrcClassPath = this.srcClassPath = this.cachedUserSrcClassPath = this.cachedUserAndGenSrcClassPath = EMPTY_PATH; this.outputClassPath = EMPTY_PATH; - } - else { + } else { this.srcClassPath = srcCp; final boolean allowAptRoots = true; //todo: Set by PROCESSOR_PATH != null this.cachedUserSrcClassPath = SourcePath.sources(srcCp, backgroundCompilation); this.cachedAptSrcClassPath = allowAptRoots ? SourcePath.apt(srcCp, backgroundCompilation) : null; + this.cachedAptOutputClassPath = allowAptRoots ? SourcePath.aptOputput(srcCp, backgroundCompilation) : null; + this.cachedUserAndGenSrcClassPath = allowAptRoots ? ClassPathSupport.createProxyClassPath(this.cachedUserSrcClassPath,this.cachedAptOutputClassPath) : this.cachedUserSrcClassPath; this.cachedSrcClassPath = allowAptRoots ? ClassPathSupport.createProxyClassPath(this.cachedUserSrcClassPath,this.cachedAptSrcClassPath) : this.cachedUserSrcClassPath; - this.outputClassPath = CacheClassPath.forSourcePath (this.cachedUserSrcClassPath); + this.outputClassPath = CacheClassPath.forSourcePath (this.cachedUserAndGenSrcClassPath); this.cachedSrcClassPath.addPropertyChangeListener(WeakListeners.propertyChange(this.cpListener,this.cachedSrcClassPath)); } this.backgroundCompilation = backgroundCompilation; @@ -401,7 +405,8 @@ hasSources ? (!useModifiedFiles ? new CachingFileManager (this.archiveProvider, this.cachedSrcClassPath, filter, false, ignoreExcludes) : new SourceFileManager (this.cachedUserSrcClassPath, ignoreExcludes)) : null, cachedAptSrcClassPath != null ? new AptSourceFileManager(this.cachedUserSrcClassPath, this.cachedAptSrcClassPath, siblings.getProvider()) : null, - hasSources ? outFileManager = new OutputFileManager (this.archiveProvider, this.outputClassPath, this.cachedUserSrcClassPath, this.cachedAptSrcClassPath, siblings.getProvider()) : null, + cachedAptOutputClassPath != null ? new AptOutputFileManager(this.cachedAptOutputClassPath, this.cachedAptSrcClassPath) : null, + hasSources ? outFileManager = new OutputFileManager (this.archiveProvider, this.outputClassPath, this.cachedUserAndGenSrcClassPath, this.cachedAptSrcClassPath, siblings.getProvider()) : null, this.memoryFileManager, marker, siblings); diff --git a/java.source/src/org/netbeans/modules/java/source/indexing/APTUtils.java b/java.source/src/org/netbeans/modules/java/source/indexing/APTUtils.java --- a/java.source/src/org/netbeans/modules/java/source/indexing/APTUtils.java +++ b/java.source/src/org/netbeans/modules/java/source/indexing/APTUtils.java @@ -56,10 +56,12 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.WeakHashMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -96,6 +98,7 @@ private static final Map knownSourceRootsMap = new HashMap(); private static final Map> auxiliarySourceRootsMap = new WeakHashMap>(); private static final Lookup HARDCODED_PROCESSORS = Lookups.forPath("Editors/text/x-java/AnnotationProcessors"); + private static final Set blackList = new HashSet() {{add("org.netbeans.modules.openide.util.NbBundleProcessor");}}; //NOI18N private final FileObject root; private final ClassPath processorPath; private final AnnotationProcessingQuery.Result aptOptions; @@ -235,16 +238,18 @@ } List result = new LinkedList(); for (String name : processorNames) { - try { - Class clazz = Class.forName(name, true, cl); - Object instance = clazz.newInstance(); - if (instance instanceof Processor) { - result.add((Processor) instance); + if (!blackList.contains(name)) { + try { + Class clazz = Class.forName(name, true, cl); + Object instance = clazz.newInstance(); + if (instance instanceof Processor) { + result.add((Processor) instance); + } + } catch (ThreadDeath td) { + throw td; + } catch (Throwable t) { + LOG.log(Level.FINE, null, t); } - } catch (ThreadDeath td) { - throw td; - } catch (Throwable t) { - LOG.log(Level.FINE, null, t); } } if (!onScan) diff --git a/java.source/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java b/java.source/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java --- a/java.source/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java +++ b/java.source/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java @@ -151,7 +151,7 @@ } if (isAptBuildGeneratedFolder(context.getRootURI(),sourcePath)) { JavaIndex.LOG.fine("Ignoring annotation processor build generated folder"); //NOI18N - return; +// return; } final List javaSources = new ArrayList(); final Collection virtualSourceTuples = translateVirtualSources ( diff --git a/java.source/src/org/netbeans/modules/java/source/parsing/AptOutputFileManager.java b/java.source/src/org/netbeans/modules/java/source/parsing/AptOutputFileManager.java new file mode 100644 --- /dev/null +++ b/java.source/src/org/netbeans/modules/java/source/parsing/AptOutputFileManager.java @@ -0,0 +1,77 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.source.parsing; + +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.java.classpath.ClassPath; + +/** + * + * @author Tomas Zezula + */ +public class AptOutputFileManager extends SourceFileManager { + public AptOutputFileManager( + @NonNull final ClassPath aptOutput, + @NonNull final ClassPath aptCache) { + super(aptOutput, true, new RejectDuplicates(aptCache)); + } + + private static class RejectDuplicates implements Predicate { + + private final ClassPath aptCache; + + private RejectDuplicates(@NonNull final ClassPath aptCache) { + assert aptCache != null; + this.aptCache = aptCache; + } + + @Override + public boolean apply(final @NonNull SourceFileObject file) { + final String path = file.handle.getRelativePath(); + if (path == null) { + return false; + } + return aptCache.findResource(path) == null; + } + } +} diff --git a/java.source/src/org/netbeans/modules/java/source/parsing/ProxyFileManager.java b/java.source/src/org/netbeans/modules/java/source/parsing/ProxyFileManager.java --- a/java.source/src/org/netbeans/modules/java/source/parsing/ProxyFileManager.java +++ b/java.source/src/org/netbeans/modules/java/source/parsing/ProxyFileManager.java @@ -57,7 +57,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; -import java.util.Stack; import java.util.logging.Level; import java.util.logging.Logger; import javax.tools.FileObject; @@ -65,6 +64,7 @@ import javax.tools.JavaFileObject; import javax.tools.StandardLocation; import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.annotations.common.NullAllowed; import org.netbeans.modules.java.source.util.Iterators; /** @@ -97,6 +97,7 @@ private final JavaFileManager aptSources; private final MemoryFileManager memoryFileManager; private final JavaFileManager outputhPath; + private final JavaFileManager aptOutput; private final GeneratedFileMarker marker; private final SiblingSource siblings; private JavaFileObject lastInfered; @@ -107,17 +108,20 @@ /** Creates a new instance of ProxyFileManager */ - public ProxyFileManager(final JavaFileManager bootPath, - final JavaFileManager classPath, - final JavaFileManager sourcePath, - final JavaFileManager aptSources, - final JavaFileManager outputhPath, - final MemoryFileManager memoryFileManager, - final GeneratedFileMarker marker, - final SiblingSource siblings) { + public ProxyFileManager( + final @NonNull JavaFileManager bootPath, + final @NonNull JavaFileManager classPath, + final @NullAllowed JavaFileManager sourcePath, + final @NullAllowed JavaFileManager aptSources, + final @NullAllowed JavaFileManager aptOutput, + final @NullAllowed JavaFileManager outputhPath, + final @NullAllowed MemoryFileManager memoryFileManager, + final @NonNull GeneratedFileMarker marker, + final @NonNull SiblingSource siblings) { assert bootPath != null; assert classPath != null; assert memoryFileManager == null || sourcePath != null; + assert (aptOutput != null && aptSources != null && sourcePath != null) || (aptOutput == null && aptSources == null); assert marker != null; assert siblings != null; this.bootPath = bootPath; @@ -126,6 +130,7 @@ this.aptSources = aptSources; this.memoryFileManager = memoryFileManager; this.outputhPath = outputhPath; + this.aptOutput = aptOutput; this.marker = marker; this.siblings = siblings; } @@ -135,44 +140,28 @@ return this.outputhPath == null ? new JavaFileManager[] {this.classPath} : new JavaFileManager[] {this.classPath, this.outputhPath}; - } - else if (location == StandardLocation.PLATFORM_CLASS_PATH) { + } else if (location == StandardLocation.PLATFORM_CLASS_PATH) { return new JavaFileManager[] {this.bootPath}; - } - else if (location == StandardLocation.SOURCE_PATH && this.sourcePath != null) { + } else if (location == StandardLocation.SOURCE_PATH && this.sourcePath != null) { + final List fms = new ArrayList(4); + fms.add(this.sourcePath); + if (this.aptSources != null) { + fms.add(this.aptSources); + } if (this.memoryFileManager != null) { - if (this.aptSources != null) { - return new JavaFileManager[] { - this.sourcePath, - this.aptSources, - this.memoryFileManager - }; - } - else { - return new JavaFileManager[] { - this.sourcePath, - this.memoryFileManager - }; - } + fms.add(this.memoryFileManager); } - else { - if (this.aptSources != null) { - return new JavaFileManager[] {this.sourcePath, this.aptSources}; - } else { - return new JavaFileManager[] {this.sourcePath}; - } + if (this.aptOutput != null) { + fms.add(this.aptOutput); } - } - else if (location == StandardLocation.CLASS_OUTPUT && this.outputhPath != null) { + return fms.toArray(new JavaFileManager[fms.size()]); + } else if (location == StandardLocation.CLASS_OUTPUT && this.outputhPath != null) { return new JavaFileManager[] {this.outputhPath}; - } - else if (location == StandardLocation.SOURCE_OUTPUT && this.aptSources != null) { + } else if (location == StandardLocation.SOURCE_OUTPUT && this.aptSources != null) { return new JavaFileManager[] {this.aptSources}; - } - else if (location == SOURCE_PATH_WRITE) { + } else if (location == SOURCE_PATH_WRITE) { return new JavaFileManager[] {this.sourcePath}; - } - else if (location == ALL) { + } else if (location == ALL) { return getAllFileManagers(); } return new JavaFileManager[0]; @@ -189,6 +178,9 @@ if (this.memoryFileManager != null) { result.add(this.memoryFileManager); } + if (this.aptOutput != null) { + result.add(this.aptOutput); + } result.add(this.bootPath); result.add (this.classPath); if (this.outputhPath!=null) { diff --git a/java.source/src/org/netbeans/modules/java/source/parsing/SourceFileManager.java b/java.source/src/org/netbeans/modules/java/source/parsing/SourceFileManager.java --- a/java.source/src/org/netbeans/modules/java/source/parsing/SourceFileManager.java +++ b/java.source/src/org/netbeans/modules/java/source/parsing/SourceFileManager.java @@ -58,6 +58,7 @@ import javax.tools.JavaFileManager.Location; import javax.tools.JavaFileObject; import javax.tools.StandardLocation; +import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.java.classpath.ClassPath; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -71,12 +72,23 @@ final ClassPath sourceRoots; private final boolean ignoreExcludes; + private final Predicate filter; private static final Logger LOG = Logger.getLogger(SourceFileManager.class.getName()); /** Creates a new instance of SourceFileManager */ public SourceFileManager (final ClassPath sourceRoots, final boolean ignoreExcludes) { + this(sourceRoots,ignoreExcludes, new AcceptAll()); + } + + protected SourceFileManager( + @NonNull final ClassPath sourceRoots, + final boolean ignoreExcludes, + @NonNull final Predicate filter) { + assert sourceRoots != null; + assert filter != null; this.sourceRoots = sourceRoots; this.ignoreExcludes = ignoreExcludes; + this.filter = filter; } @Override @@ -98,8 +110,11 @@ FileObject file = files.nextElement(); if (ignoreExcludes || entry.includes(file)) { final JavaFileObject.Kind kind = FileObjects.getKind(file.getExt()); - if (kinds.contains(kind)) { - result.add (SourceFileObject.create(file, root)); + if (kinds.contains(kind)) { + final SourceFileObject source = SourceFileObject.create(file, root); + if (filter.apply(source)) { + result.add (source); + } } } } @@ -257,4 +272,15 @@ } return null; } + + protected static interface Predicate

{ + boolean apply(P param); + } + + private static final class AcceptAll implements Predicate { + @Override + public boolean apply(SourceFileObject param) { + return true; + } + } }