diff -r 4d993c0dea81 api.java/apichanges.xml
--- a/api.java/apichanges.xml Wed Feb 27 20:24:37 2008 +0100
+++ b/api.java/apichanges.xml Thu Feb 28 14:45:34 2008 +0100
@@ -73,7 +73,24 @@
-
+
+
+ Support for passing hint to the java infrastructure whether it should prefer source or binary
+
+
+
+
+
+
+ It is possible for the SouceForBinaryQuery provider to specify whether the java module should prefer
+ sources or binaries. In general sources should be preferred for projects where user can make modification.
+ The binaries should be preferred for libraries and platforms where sources may not be complete or correct.
+
+
+
+
+
+
Support for specifying classpath inclusion
diff -r 4d993c0dea81 api.java/arch.xml
--- a/api.java/arch.xml Wed Feb 27 20:24:37 2008 +0100
+++ b/api.java/arch.xml Thu Feb 28 14:45:34 2008 +0100
@@ -958,4 +958,85 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ XXX no answer for compat-deprecation
+
+
+
+
+
+
+
+
+ XXX no answer for exec-ant-tasks
+
+
+
+
+
+
+
+
+ XXX no answer for resources-preferences
+
+
+
diff -r 4d993c0dea81 api.java/manifest.mf
--- a/api.java/manifest.mf Wed Feb 27 20:24:37 2008 +0100
+++ b/api.java/manifest.mf Thu Feb 28 14:45:34 2008 +0100
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.api.java/1
-OpenIDE-Module-Specification-Version: 1.14
+OpenIDE-Module-Specification-Version: 1.15
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/java/classpath/Bundle.properties
AutoUpdate-Show-In-Client: false
diff -r 4d993c0dea81 api.java/src/org/netbeans/api/java/queries/SourceForBinaryQuery.java
--- a/api.java/src/org/netbeans/api/java/queries/SourceForBinaryQuery.java Wed Feb 27 20:24:37 2008 +0100
+++ b/api.java/src/org/netbeans/api/java/queries/SourceForBinaryQuery.java Thu Feb 28 14:45:34 2008 +0100
@@ -43,13 +43,17 @@
import java.net.URL;
import java.util.Arrays;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
+import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.Lookup;
+import org.openide.util.WeakListeners;
/**
* The query is used for finding sources for binaries.
@@ -78,13 +82,7 @@
* @return a result object encapsulating the answer (never null)
*/
public static Result findSourceRoots (URL binaryRoot) {
- if (FileUtil.isArchiveFile(binaryRoot)) {
- throw new IllegalArgumentException("File URL pointing to " + // NOI18N
- "JAR is not valid classpath entry. Use jar: URL. Was: "+binaryRoot); // NOI18N
- }
- if (!binaryRoot.toExternalForm().endsWith("/")) {
- throw new IllegalArgumentException ("Folder URL must end with '/'. Was: "+binaryRoot);
- }
+ checkPreconditions (binaryRoot);
for (SourceForBinaryQueryImplementation impl : implementations.allInstances()) {
Result result = impl.findSourceRoots(binaryRoot);
if (result != null) {
@@ -96,6 +94,54 @@
}
LOG.log(Level.FINE, "findSourceRoots({0}) -> nil", binaryRoot);
return EMPTY_RESULT;
+ }
+
+ /**
+ * Returns the source root for given binary root (for example, src folder for jar file or build folder).
+ * In addition to the original {@link SourceForBinaryQuery#findSourceRoots(java.net.URL)} it provides
+ * information if the source root(s) should be preferred over the binaries used by the java infrastructure.
+ * Most of the clients don't need this information, so thay can use the original
+ * {@link SourceForBinaryQuery#findSourceRoots(java.net.URL)} method.
+ * @param binaryRoot the ClassPath root of compiled files.
+ * @return a result object encapsulating the answer (never null)
+ * @since 1.15
+ */
+ public static Result2 findSourceRoots2 (URL binaryRoot) {
+ checkPreconditions (binaryRoot);
+ for (SourceForBinaryQueryImplementation impl : implementations.allInstances()) {
+ Result2 result = null;
+ if (impl instanceof SourceForBinaryQueryImplementation2) {
+ SourceForBinaryQueryImplementation2.Result _result = ((SourceForBinaryQueryImplementation2)impl).findSourceRoots2(binaryRoot);
+ if (_result != null) {
+ result = new Result2New(_result);
+ }
+ }
+ else {
+ Result _result = impl.findSourceRoots(binaryRoot);
+ if (_result != null) {
+ result = new Result2(_result);
+ }
+ }
+ if (result != null) {
+ if (LOG.isLoggable(Level.FINE)) {
+ LOG.log(Level.FINE, "findSourceRoots2({0}) -> {1} from {2}", new Object[] {binaryRoot, Arrays.asList(result.getRoots()), impl});
+ }
+ return result;
+ }
+ }
+ LOG.log(Level.FINE, "findSourceRoots2({0}) -> nil", binaryRoot);
+ return EMPTY_RESULT2;
+
+ }
+
+ private static void checkPreconditions (final URL binaryRoot) {
+ if (FileUtil.isArchiveFile(binaryRoot)) {
+ throw new IllegalArgumentException("File URL pointing to " + // NOI18N
+ "JAR is not valid classpath entry. Use jar: URL. Was: "+binaryRoot); // NOI18N
+ }
+ if (!binaryRoot.toExternalForm().endsWith("/")) {
+ throw new IllegalArgumentException ("Folder URL must end with '/'. Was: "+binaryRoot);
+ }
}
/**
@@ -124,7 +170,87 @@
}
+ /**
+ * Result of finding sources, encapsulating the answer as well as the
+ * ability to listen to it.
+ * In addition to the Result it provides information if the source root(s)
+ * should be preferred over the binaries used by the java infrastructure.
+ * Most of the clients don't need this information, so thay can use the
+ * original {@link Result}.
+ * @since 1.15
+ */
+ public static class Result2 implements Result {
+
+ private final Result delegate;
+ //@GuardedBy(this)
+ private ChangeListener spiListener;
+ private final CopyOnWriteArrayList listeners;
+
+ private Result2 (final Result result) {
+ assert result != null;
+ this.delegate = result;
+ this.listeners = new CopyOnWriteArrayList();
+ }
+
+ public FileObject[] getRoots() {
+ return this.delegate.getRoots();
+ }
+
+ public void addChangeListener(ChangeListener l) {
+ l.getClass();
+ synchronized (this) {
+ if (this.spiListener == null) {
+ this.spiListener = new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ fireChange();
+ }
+ };
+ this.delegate.addChangeListener(WeakListeners.change(this.spiListener, this.delegate));
+ }
+ }
+ this.listeners.add(l);
+ }
+
+ public void removeChangeListener(ChangeListener l) {
+ l.getClass();
+ this.listeners.remove(l);
+ }
+
+ public boolean preferSources() {
+ //Preserve the old behavior from 4.0 to 6.1, ignore sources inside archives
+ final FileObject[] roots = this.delegate.getRoots();
+ for (FileObject root : roots) {
+ if (FileUtil.getArchiveFile(root) != null) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private void fireChange () {
+ final ChangeEvent event = new ChangeEvent(this);
+ for (ChangeListener l : this.listeners) {
+ l.stateChanged(event);
+ }
+ }
+ }
+
+ private static final class Result2New extends Result2 {
+
+ private final SourceForBinaryQueryImplementation2.Result delegate;
+
+ private Result2New (final SourceForBinaryQueryImplementation2.Result delegate) {
+ super (delegate);
+ this.delegate = delegate;
+ }
+
+ public boolean preferSources() {
+ return this.delegate.preferSources();
+ }
+ }
+
private static final Result EMPTY_RESULT = new EmptyResult();
+ private static final Result2 EMPTY_RESULT2 = new Result2 (EMPTY_RESULT);
private static final class EmptyResult implements Result {
private static final FileObject[] NO_ROOTS = new FileObject[0];
EmptyResult() {}
diff -r 4d993c0dea81 api.java/src/org/netbeans/spi/java/queries/SourceForBinaryQueryImplementation2.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/api.java/src/org/netbeans/spi/java/queries/SourceForBinaryQueryImplementation2.java Thu Feb 28 14:45:34 2008 +0100
@@ -0,0 +1,96 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ *
+ * 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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 2008 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.spi.java.queries;
+
+import java.net.URL;
+import org.netbeans.api.java.queries.SourceForBinaryQuery;
+
+/**
+ * Information about where Java sources corresponding to binaries
+ * (classfiles) can be found.
+ * @see org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation
+ *
+ * In addition to the original SourceForBinaryQueryImplementation this interface
+ * also provides information used by the java infrastructure if sources should be
+ * preferred over the binaries. In general sources should be preferred for projects
+ * which are user editable but not for libraries or platforms where the sources
+ * may not be complete or up to date.
+ *
+ * @since org.netbeans.api.java/1 1.15
+ */
+public interface SourceForBinaryQueryImplementation2 extends SourceForBinaryQueryImplementation {
+
+ /**
+ * Returns the source root(s) for a given binary root.
+ *
+ * The returned Result is a live object the API listens on, if possible it should be a singleton
+ * to improve the performance. It means that for repeated calling of this method with the same
+ * recognized root the method should return the same instance of the Result.
+ * The typical implemantation of the findSourceRoots contains 3 steps:
+ *
+ * - Look into the cache if there is already a result for the root, if so return it
+ * - Check if the binaryRoot is recognized, if not return null
+ * - Create a new Result for the binaryRoot, put it into the cache
+ * and return it.
+ *
+ *
+ *
+ * Any absolute URL may be used but typically it will use the file
+ * protocol for directory entries and jar
protocol for JAR entries
+ * (e.g. jar:file:/tmp/foo.jar!/).
+ *
+ * @param binaryRoot the class path root of Java class files
+ * @return a result object encapsulating the answer or null if the binaryRoot is not recognized
+ */
+ public Result findSourceRoots2 (final URL binaryRoot);
+
+ public static interface Result extends SourceForBinaryQuery.Result {
+
+ /**
+ * When true the java model prefers sources otherwise binaries are used.
+ * Project's {@link SourceForBinaryQueryImplementation} should return
+ * true. The platform and libraries {@link SourceForBinaryQueryImplementation}
+ * should return false - the attached sources may not be complete.
+ * @return true if sources should be used by the java infrastructure
+ */
+ public boolean preferSources();
+ }
+
+}
diff -r 4d993c0dea81 j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/query/J2eePlatformSourceForBinaryQuery.java
--- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/query/J2eePlatformSourceForBinaryQuery.java Wed Feb 27 20:24:37 2008 +0100
+++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/query/J2eePlatformSourceForBinaryQuery.java Thu Feb 28 14:45:34 2008 +0100
@@ -58,7 +58,7 @@
import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
import org.netbeans.modules.j2ee.deployment.common.api.J2eeLibraryTypeProvider;
import org.netbeans.modules.j2ee.deployment.plugins.spi.J2eePlatformImpl;
-import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
+import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
import org.netbeans.spi.project.libraries.LibraryImplementation;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileStateInvalidException;
@@ -72,16 +72,16 @@
* Finds the locations of sources for various libraries.
* @since 1.5
*/
-public class J2eePlatformSourceForBinaryQuery implements SourceForBinaryQueryImplementation {
+public class J2eePlatformSourceForBinaryQuery implements SourceForBinaryQueryImplementation2 {
- private final Map/**/ cache = new HashMap();
+ private final Map cache = new HashMap();
private final Map/**/ normalizedURLCache = new HashMap();
/** Default constructor for lookup. */
public J2eePlatformSourceForBinaryQuery() {}
- public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) {
- SourceForBinaryQuery.Result res = (SourceForBinaryQuery.Result) this.cache.get (binaryRoot);
+ public SourceForBinaryQueryImplementation2.Result findSourceRoots2 (URL binaryRoot) {
+ SourceForBinaryQueryImplementation2.Result res = this.cache.get (binaryRoot);
if (res != null) {
return res;
}
@@ -115,6 +115,10 @@
}
}
return null;
+ }
+
+ public SourceForBinaryQuery.Result findSourceRoots (final URL binaryRoot) {
+ return this.findSourceRoots2(binaryRoot);
}
@@ -155,7 +159,7 @@
}
- private static class Result implements SourceForBinaryQuery.Result, PropertyChangeListener {
+ private static class Result implements SourceForBinaryQueryImplementation2.Result, PropertyChangeListener {
private LibraryImplementation lib;
private URL entry;
@@ -226,6 +230,10 @@
((ChangeListener)it.next()).stateChanged(event);
}
}
+
+ public boolean preferSources() {
+ return false;
+ }
}
diff -r 4d993c0dea81 j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/sharability/SourceForBinaryQueryImpl.java
--- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/sharability/SourceForBinaryQueryImpl.java Wed Feb 27 20:24:37 2008 +0100
+++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/sharability/SourceForBinaryQueryImpl.java Thu Feb 28 14:45:34 2008 +0100
@@ -52,7 +52,7 @@
import org.netbeans.api.java.queries.SourceForBinaryQuery;
import org.netbeans.api.project.libraries.Library;
import org.netbeans.api.project.libraries.LibraryManager;
-import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
+import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
import org.netbeans.spi.project.libraries.support.LibrariesSupport;
import org.openide.ErrorManager;
import org.openide.filesystems.FileObject;
@@ -66,21 +66,21 @@
* Finds the locations of sources for various libraries.
* @author Tomas Zezula
*/
-public class SourceForBinaryQueryImpl implements SourceForBinaryQueryImplementation {
+public class SourceForBinaryQueryImpl implements SourceForBinaryQueryImplementation2 {
private static final String[] CLASSPATH_VOLUMES = new String[] {
ServerLibraryTypeProvider.VOLUME_CLASSPATH,
ServerLibraryTypeProvider.VOLUME_WS_COMPILE_CLASSPATH
};
- private final Map cache = new ConcurrentHashMap();
+ private final Map cache = new ConcurrentHashMap();
private final Map normalizedURLCache = new ConcurrentHashMap();
/** Default constructor for lookup. */
public SourceForBinaryQueryImpl() {}
- public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) {
- SourceForBinaryQuery.Result res = cache.get(binaryRoot);
+ public SourceForBinaryQueryImplementation2.Result findSourceRoots2(URL binaryRoot) {
+ SourceForBinaryQueryImplementation2.Result res = cache.get(binaryRoot);
if (res != null) {
return res;
}
@@ -106,6 +106,10 @@
}
}
return null;
+ }
+
+ public SourceForBinaryQuery.Result findSourceRoots (final URL binaryRoot) {
+ return this.findSourceRoots2(binaryRoot);
}
@@ -146,7 +150,7 @@
}
- private static class Result implements SourceForBinaryQuery.Result, PropertyChangeListener {
+ private static class Result implements SourceForBinaryQueryImplementation2.Result, PropertyChangeListener {
private Library lib;
private URL entry;
@@ -205,6 +209,10 @@
cs.fireChange();
}
}
+
+ public boolean preferSources() {
+ return false;
+ }
}
diff -r 4d993c0dea81 java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SELibrarySourceForBinaryQuery.java
--- a/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SELibrarySourceForBinaryQuery.java Wed Feb 27 20:24:37 2008 +0100
+++ b/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SELibrarySourceForBinaryQuery.java Thu Feb 28 14:45:34 2008 +0100
@@ -52,10 +52,9 @@
import org.netbeans.api.java.queries.SourceForBinaryQuery;
import org.netbeans.api.project.libraries.Library;
import org.netbeans.api.project.libraries.LibraryManager;
-import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
+import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
import org.netbeans.spi.project.libraries.support.LibrariesSupport;
import org.openide.ErrorManager;
-import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileStateInvalidException;
import org.openide.filesystems.FileUtil;
@@ -67,16 +66,16 @@
* Finds the locations of sources for various libraries.
* @author Tomas Zezula
*/
-public class J2SELibrarySourceForBinaryQuery implements SourceForBinaryQueryImplementation {
+public class J2SELibrarySourceForBinaryQuery implements SourceForBinaryQueryImplementation2 {
- private final Map cache = new ConcurrentHashMap();
+ private final Map cache = new ConcurrentHashMap();
private final Map normalizedURLCache = new ConcurrentHashMap();
/** Default constructor for lookup. */
public J2SELibrarySourceForBinaryQuery() {}
- public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) {
- SourceForBinaryQuery.Result res = cache.get(binaryRoot);
+ public SourceForBinaryQueryImplementation2.Result findSourceRoots2 (URL binaryRoot) {
+ SourceForBinaryQueryImplementation2.Result res = cache.get(binaryRoot);
if (res != null) {
return res;
}
@@ -101,6 +100,10 @@
return null;
}
+
+ public SourceForBinaryQuery.Result findSourceRoots (final URL binaryRoot) {
+ return this.findSourceRoots2(binaryRoot);
+ }
private URL getNormalizedURL (URL url) {
//URL is already nornalized, return it
@@ -139,7 +142,7 @@
}
- private static class Result implements SourceForBinaryQuery.Result, PropertyChangeListener {
+ private static class Result implements SourceForBinaryQueryImplementation2.Result, PropertyChangeListener {
private Library lib;
private URL entry;
@@ -191,6 +194,10 @@
cs.fireChange();
}
}
+
+ public boolean preferSources() {
+ return false;
+ }
}
diff -r 4d993c0dea81 java.platform/src/org/netbeans/modules/java/platform/queries/PlatformSourceForBinaryQuery.java
--- a/java.platform/src/org/netbeans/modules/java/platform/queries/PlatformSourceForBinaryQuery.java Wed Feb 27 20:24:37 2008 +0100
+++ b/java.platform/src/org/netbeans/modules/java/platform/queries/PlatformSourceForBinaryQuery.java Thu Feb 28 14:45:34 2008 +0100
@@ -55,6 +55,7 @@
import org.netbeans.api.java.platform.JavaPlatformManager;
import org.netbeans.api.java.platform.JavaPlatform;
import org.netbeans.api.java.queries.SourceForBinaryQuery;
+import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
import org.openide.util.ChangeSupport;
import org.openide.util.Exceptions;
import org.openide.util.WeakListeners;
@@ -65,13 +66,13 @@
* provides sources for the active platform and project libraries
*/
-public class PlatformSourceForBinaryQuery implements SourceForBinaryQueryImplementation {
+public class PlatformSourceForBinaryQuery implements SourceForBinaryQueryImplementation2 {
private static final String JAR_FILE = "jar:file:"; //NOI18N
private static final String RTJAR_PATH = "/jre/lib/rt.jar!/"; //NOI18N
private static final String SRC_ZIP = "/src.zip"; //NOI18N
- private Map cache = new HashMap();
+ private Map cache = new HashMap();
public PlatformSourceForBinaryQuery () {
}
@@ -81,8 +82,8 @@
* @param binaryRoot the URL of a classpath root (platform supports file and jar protocol)
* @return FileObject[], never returns null
*/
- public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) {
- SourceForBinaryQuery.Result res = this.cache.get (binaryRoot);
+ public SourceForBinaryQueryImplementation2.Result findSourceRoots2(URL binaryRoot) {
+ SourceForBinaryQueryImplementation2.Result res = this.cache.get (binaryRoot);
if (res != null) {
return res;
}
@@ -115,7 +116,11 @@
return null;
}
- private static class Result implements SourceForBinaryQuery.Result, PropertyChangeListener {
+ public SourceForBinaryQuery.Result findSourceRoots (URL binaryRoot) {
+ return this.findSourceRoots2(binaryRoot);
+ }
+
+ private static class Result implements SourceForBinaryQueryImplementation2.Result, PropertyChangeListener {
private JavaPlatform platform;
private final ChangeSupport cs = new ChangeSupport(this);
@@ -145,10 +150,14 @@
cs.fireChange();
}
}
+
+ public boolean preferSources() {
+ return false;
+ }
}
- private static class UnregisteredPlatformResult implements SourceForBinaryQuery.Result {
+ private static class UnregisteredPlatformResult implements SourceForBinaryQueryImplementation2.Result {
private FileObject srcRoot;
@@ -168,5 +177,9 @@
public void removeChangeListener(ChangeListener l) {
//Not supported, no listening.
}
-}}
+ public boolean preferSources() {
+ return false;
+ }
+ }}
+
diff -r 4d993c0dea81 java.project/src/org/netbeans/modules/java/project/ExtraProjectSourceForBinaryQueryImpl.java
--- a/java.project/src/org/netbeans/modules/java/project/ExtraProjectSourceForBinaryQueryImpl.java Wed Feb 27 20:24:37 2008 +0100
+++ b/java.project/src/org/netbeans/modules/java/project/ExtraProjectSourceForBinaryQueryImpl.java Thu Feb 28 14:45:34 2008 +0100
@@ -56,9 +56,8 @@
import org.netbeans.api.java.queries.SourceForBinaryQuery;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
-import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
+import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
import org.netbeans.spi.project.support.ant.AntProjectHelper;
-import org.netbeans.spi.project.support.ant.AntProjectListener;
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
import org.netbeans.spi.project.support.ant.PropertyUtils;
import org.netbeans.spi.project.ui.ProjectOpenedHook;
@@ -72,7 +71,7 @@
*
* @author mkleint
*/
-public final class ExtraProjectSourceForBinaryQueryImpl extends ProjectOpenedHook implements SourceForBinaryQueryImplementation {
+public final class ExtraProjectSourceForBinaryQueryImpl extends ProjectOpenedHook implements SourceForBinaryQueryImplementation2 {
private static final String REF_START = "file.reference."; //NOI18N
private static final String SOURCE_START = "source.reference."; //NOI18N
@@ -113,7 +112,7 @@
* @param binaryRoot
* @return
*/
- public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) {
+ public SourceForBinaryQueryImplementation2.Result findSourceRoots2 (URL binaryRoot) {
synchronized (cache) {
ExtraResult res = cache.get(binaryRoot);
if (res != null) {
@@ -126,6 +125,10 @@
}
}
return null;
+ }
+
+ public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) {
+ return this.findSourceRoots2(binaryRoot);
}
@Override
@@ -213,7 +216,7 @@
}
- private class ExtraResult implements SourceForBinaryQuery.Result {
+ private class ExtraResult implements SourceForBinaryQueryImplementation2.Result {
private URL binaryroot;
private ChangeSupport chs = new ChangeSupport(this);
@@ -254,7 +257,10 @@
public void removeChangeListener(ChangeListener l) {
chs.removeChangeListener(l);
}
-
+
+ public boolean preferSources() {
+ return false;
+ }
}
diff -r 4d993c0dea81 java.source/nbproject/project.xml
--- a/java.source/nbproject/project.xml Wed Feb 27 20:24:37 2008 +0100
+++ b/java.source/nbproject/project.xml Thu Feb 28 14:45:35 2008 +0100
@@ -209,15 +209,6 @@
1
1.5
-
-
-
- org.netbeans.modules.project.libraries
-
-
-
- 1
- 1.14
diff -r 4d993c0dea81 java.source/src/org/netbeans/api/java/source/ClassIndex.java
--- a/java.source/src/org/netbeans/api/java/source/ClassIndex.java Wed Feb 27 20:24:37 2008 +0100
+++ b/java.source/src/org/netbeans/api/java/source/ClassIndex.java Thu Feb 28 14:45:35 2008 +0100
@@ -433,28 +433,24 @@
final GlobalSourcePath gsp = GlobalSourcePath.getDefault();
List entries = cp.entries();
for (ClassPath.Entry entry : entries) {
- try {
- URL[] srcRoots;
- if (!sources) {
- srcRoots = gsp.getSourceRootForBinaryRoot (entry.getURL(), cp, true);
- if (srcRoots == null) {
- srcRoots = new URL[] {entry.getURL()};
- }
+ URL[] srcRoots;
+ if (!sources) {
+ srcRoots = gsp.getSourceRootForBinaryRoot (entry.getURL(), cp, true);
+ if (srcRoots == null) {
+ srcRoots = new URL[] {entry.getURL()};
}
- else {
- srcRoots = new URL[] {entry.getURL()};
- }
- for (URL srcRoot : srcRoots) {
- oldState.add (srcRoot);
- ClassIndexImpl ci = ClassIndexManager.getDefault().getUsagesQuery(srcRoot);
- if (ci != null) {
- ci.addClassIndexImplListener(spiListener);
- queries.add (ci);
- }
+ }
+ else {
+ srcRoots = new URL[] {entry.getURL()};
+ }
+ for (URL srcRoot : srcRoots) {
+ oldState.add (srcRoot);
+ ClassIndexImpl ci = ClassIndexManager.getDefault().getUsagesQuery(srcRoot);
+ if (ci != null) {
+ ci.addClassIndexImplListener(spiListener);
+ queries.add (ci);
}
- } catch (IOException ioe) {
- Exceptions.printStackTrace(ioe);
- }
+ }
}
}
diff -r 4d993c0dea81 java.source/src/org/netbeans/modules/java/source/classpath/GlobalSourcePath.java
--- a/java.source/src/org/netbeans/modules/java/source/classpath/GlobalSourcePath.java Wed Feb 27 20:24:37 2008 +0100
+++ b/java.source/src/org/netbeans/modules/java/source/classpath/GlobalSourcePath.java Thu Feb 28 14:45:35 2008 +0100
@@ -44,10 +44,8 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.ref.WeakReference;
-import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -58,32 +56,20 @@
import java.util.Set;
import java.util.TooManyListenersException;
import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.logging.Logger;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.classpath.GlobalPathRegistry;
import org.netbeans.api.java.classpath.GlobalPathRegistryEvent;
import org.netbeans.api.java.classpath.GlobalPathRegistryListener;
-import org.netbeans.api.java.platform.JavaPlatform;
-import org.netbeans.api.java.platform.JavaPlatformManager;
import org.netbeans.api.java.queries.SourceForBinaryQuery;
-import org.netbeans.api.project.FileOwnerQuery;
-import org.netbeans.api.project.Project;
-import org.netbeans.api.project.ProjectManager;
-import org.netbeans.api.project.SourceGroup;
-import org.netbeans.api.project.Sources;
-import org.netbeans.api.project.libraries.Library;
-import org.netbeans.api.project.libraries.LibraryManager;
+import org.netbeans.modules.java.source.usages.ClassIndexManager;
import org.netbeans.spi.java.classpath.ClassPathImplementation;
import org.netbeans.spi.java.classpath.PathResourceImplementation;
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
-import org.netbeans.spi.project.libraries.support.LibrariesSupport;
-import org.openide.ErrorManager;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileStateInvalidException;
import org.openide.util.Exceptions;
-import org.openide.util.Mutex;
import org.openide.util.RequestProcessor;
import org.openide.util.Utilities;
import org.openide.util.WeakListeners;
@@ -116,15 +102,7 @@
private final BinaryPathImplementation binaryPath;
private final UnknownSourcePathImplementation unknownSourcePath;
- private final JavaPlatformManager pm;
- private Set seenPlatforms;
- private Set seenLibs;
- private Collection seenLibManagers;
-
- private Set libsSrcs;
-
private final Listener listener;
- private final LibsListener libsListener;
private volatile PropertyChangeListener excludesListener;
@@ -140,14 +118,7 @@
this.sourceResults = Collections.emptyMap();
this.unknownRoots = new HashMap();
this.translatedRoots = new HashMap ();
- this.gpr.addGlobalPathRegistryListener ((GlobalPathRegistryListener)WeakListeners.create(GlobalPathRegistryListener.class,this.listener,this.gpr));
- this.seenPlatforms = new HashSet();
- this.seenLibs = new HashSet ();
- this.seenLibManagers = new HashSet();
- this.libsListener = new LibsListener ();
- LibraryManager.addOpenManagersPropertyChangeListener(WeakListeners.propertyChange(libsListener, null));
- this.pm = JavaPlatformManager.getDefault();
- this.pm.addPropertyChangeListener(WeakListeners.propertyChange(libsListener, this.pm));
+ this.gpr.addGlobalPathRegistryListener ((GlobalPathRegistryListener)WeakListeners.create(GlobalPathRegistryListener.class,this.listener,this.gpr));
}
@@ -170,7 +141,7 @@
}
else {
List cacheRoots = new ArrayList ();
- Collection extends PathResourceImplementation> unknownRes = getSources(SourceForBinaryQuery.findSourceRoots(binaryRoot).getRoots(),cacheRoots,null);
+ Collection extends PathResourceImplementation> unknownRes = getSources(SourceForBinaryQuery.findSourceRoots2(binaryRoot),cacheRoots,null);
if (unknownRes.isEmpty()) {
return null;
}
@@ -193,19 +164,23 @@
public boolean isLibrary (final ClassPath cp) {
assert cp != null;
- Set libs = getLibsSources();
- for (ClassPath.Entry entry : cp.entries()) {
- if (libs.contains(entry.getURL())) {
+ final ClassIndexManager mgr = ClassIndexManager.getDefault();
+ for (FileObject fo : cp.getRoots()) {
+ if (isLibrary (fo)) {
return true;
}
}
return false;
}
- public boolean isLibrary (final URL root) {
+ public boolean isLibrary (final FileObject root) {
assert root != null;
- Set libs = getLibsSources();
- return libs.contains(root);
+ try {
+ return ClassIndexManager.getDefault().getUsagesQuery(root.getURL()) == null;
+ } catch (FileStateInvalidException e) {
+ Exceptions.printStackTrace(e);
+ return true; //Safer
+ }
}
public ClassPathImplementation getSourcePath () {
@@ -260,10 +235,10 @@
for (ClassPath.Entry entry : cp.entries()) {
URL url = entry.getURL();
if (!translatedRoots.containsKey(url)) {
- SourceForBinaryQuery.Result sr = r.oldSR.remove (url);
+ SourceForBinaryQuery.Result2 sr = r.oldSR.remove (url);
boolean isNewSR;
if (sr == null) {
- sr = SourceForBinaryQuery.findSourceRoots(url);
+ sr = SourceForBinaryQuery.findSourceRoots2(url);
isNewSR = true;
}
else {
@@ -272,7 +247,7 @@
assert !newSR.containsKey(url);
newSR.put(url,sr);
List cacheURLs = new ArrayList ();
- Collection extends PathResourceImplementation> srcRoots = getSources (sr.getRoots(), cacheURLs, r.unknownRoots);
+ Collection extends PathResourceImplementation> srcRoots = getSources (sr, cacheURLs, r.unknownRoots);
if (srcRoots.isEmpty()) {
binaryResult.add (ClassPathSupport.createResource(url));
}
@@ -296,10 +271,10 @@
for (ClassPath.Entry entry : cp.entries()) {
URL url = entry.getURL();
if (!translatedRoots.containsKey(url)) {
- SourceForBinaryQuery.Result sr = r.oldSR.remove (url);
+ SourceForBinaryQuery.Result2 sr = r.oldSR.remove (url);
boolean isNewSR;
if (sr == null) {
- sr = SourceForBinaryQuery.findSourceRoots(url);
+ sr = SourceForBinaryQuery.findSourceRoots2(url);
isNewSR = true;
}
else {
@@ -308,7 +283,7 @@
assert !newSR.containsKey(url);
newSR.put(url,sr);
List cacheURLs = new ArrayList ();
- Collection extends PathResourceImplementation> srcRoots = getSources(sr.getRoots(),cacheURLs, r.unknownRoots);
+ Collection extends PathResourceImplementation> srcRoots = getSources(sr,cacheURLs, r.unknownRoots);
if (srcRoots.isEmpty()) {
binaryResult.add(ClassPathSupport.createResource(url));
}
@@ -331,7 +306,7 @@
cp.removePropertyChangeListener(r.propertyListener);
}
- for (Map.Entry entry : r.oldSR.entrySet()) {
+ for (Map.Entry entry : r.oldSR.entrySet()) {
entry.getValue().removeChangeListener(r.changeListener);
}
for (URL unknownRoot : r.unknownRoots.keySet()) {
@@ -377,145 +352,31 @@
}
}
- private Collection extends PathResourceImplementation> getSources (final FileObject[] roots, final List cacheDirs, final Map unknownRoots) {
- assert roots != null;
- URL[] urls = new URL[roots.length];
- boolean add = true;
- Set libs = getLibsSources();
- for (int i=0; i getSources (final SourceForBinaryQuery.Result2 sr, final List cacheDirs, final Map unknownRoots) {
+ assert sr != null;
+ if (sr.preferSources()) {
+ final FileObject[] roots = sr.getRoots();
+ assert roots != null;
List result = new ArrayList (roots.length);
- for (int i=0; iemptySet();
- }
-
- private Set getLibsSources () {
- if (!useLibraries) {
- //Running in the test where libraries modules SPI is not initialized
- return Collections.emptySet();
+ else {
+ return Collections.emptySet();
}
- // retrieve list outside of java mutex:
- final Collection libraryManagers = LibraryManager.getOpenManagers();
- final Mutex.Action> libsTask = new Mutex.Action> () {
- public Set run () {
- synchronized (GlobalSourcePath.this) {
- if (GlobalSourcePath.this.libsSrcs == null) {
- final Set _libSrcs = new HashSet();
- Set platforms = new HashSet (Arrays.asList(pm.getInstalledPlatforms()));
- Set oldPlatforms = new HashSet (GlobalSourcePath.this.seenPlatforms);
- OUTER: for (JavaPlatform platform : platforms) {
- if (!oldPlatforms.remove(platform)) {
- platform.addPropertyChangeListener(GlobalSourcePath.this.libsListener);
- }
- ClassPath cp = platform.getSourceFolders();
- assert cp != null : platform.getClass();
- for (ClassPath.Entry e : cp.entries()) {
- URL url = e.getURL();
- try {
- Project p = FileOwnerQuery.getOwner(url.toURI());
- if (p != null) {
- Sources src = p.getLookup().lookup(Sources.class);
- if (src != null) {
- for (SourceGroup group : src.getSourceGroups("java")) { //NOI18N
- if (url.equals(group.getRootFolder().getURL())) {
- continue OUTER;
- }
- }
- }
- }
- } catch (URISyntaxException ex) {
- Exceptions.printStackTrace(ex);
- }
- catch (FileStateInvalidException ex) {
- Exceptions.printStackTrace(ex);
- }
- _libSrcs.add(url);
- }
- }
- for (JavaPlatform platform : oldPlatforms) {
- platform.removePropertyChangeListener(GlobalSourcePath.this.libsListener);
- }
- GlobalSourcePath.this.seenPlatforms = platforms;
-
- for (LibraryManager lm : GlobalSourcePath.this.seenLibManagers) {
- lm.removePropertyChangeListener(libsListener);
- }
- Set oldLibs = new HashSet(GlobalSourcePath.this.seenLibs);
- Set newLibs = new HashSet();
- for (LibraryManager lm : libraryManagers) {
- lm.addPropertyChangeListener(libsListener);
-
- Set libs = new HashSet (Arrays.asList(lm.getLibraries()));
- OUTER: for (Library lib :libs) {
- newLibs.add(lib);
- if (!oldLibs.remove(lib)) {
- lib.addPropertyChangeListener(GlobalSourcePath.this.libsListener);
- }
- if (lib.getContent("classpath") != null) { //NOI18N
- List libSrc = lib.getContent("src"); //NOI18N
- for (URL url : libSrc) {
- try {
- url = LibrariesSupport.resolveLibraryEntryURL(lm.getLocation(), url);
- Project p = FileOwnerQuery.getOwner(url.toURI());
- if (p != null) {
- Sources src = p.getLookup().lookup(Sources.class);
- if (src != null) {
- for (SourceGroup group : src.getSourceGroups("java")) { //NOI18N
- if (url.equals(group.getRootFolder().getURL())) {
- continue OUTER;
- }
- }
- }
- }
- } catch (URISyntaxException ex) {
- Exceptions.printStackTrace(ex);
- }
- catch (FileStateInvalidException ex) {
- Exceptions.printStackTrace(ex);
- }
- _libSrcs.add(url);
- }
-
- }
- }
- }
- for (Library lib : oldLibs) {
- lib.removePropertyChangeListener(GlobalSourcePath.this.libsListener);
- }
- GlobalSourcePath.this.seenLibManagers = libraryManagers;
- GlobalSourcePath.this.seenLibs = newLibs;
- GlobalSourcePath.this.libsSrcs = _libSrcs;
- }
- return GlobalSourcePath.this.libsSrcs;
- }
- }
- };
- return ProjectManager.mutex().readAccess(libsTask);
}
private class WeakValue extends WeakReference implements Runnable {
@@ -550,13 +411,13 @@
final Set bootCps;
final Set compileCps;
final Set oldCps;
- final Map oldSR;
+ final Map oldSR;
final Map unknownRoots;
final PropertyChangeListener propertyListener;
final ChangeListener changeListener;
public Request (final long timeStamp, final Set sourceCps, final Set bootCps, final Set compileCps,
- final Set oldCps, final Map oldSR, final Map unknownRoots,
+ final Set oldCps, final Map oldSR, final Map unknownRoots,
final PropertyChangeListener propertyListener, final ChangeListener changeListener) {
assert sourceCps != null;
assert bootCps != null;
@@ -867,16 +728,6 @@
}
}
- private class LibsListener implements PropertyChangeListener {
-
- public void propertyChange(PropertyChangeEvent evt) {
- synchronized (GlobalSourcePath.this) {
- GlobalSourcePath.this.libsSrcs = null;
- }
- }
-
- }
-
public static synchronized GlobalSourcePath getDefault () {
if (instance == null) {
instance = new GlobalSourcePath ();
diff -r 4d993c0dea81 java.source/src/org/netbeans/modules/java/source/usages/ClassIndexManager.java
--- a/java.source/src/org/netbeans/modules/java/source/usages/ClassIndexManager.java Wed Feb 27 20:24:37 2008 +0100
+++ b/java.source/src/org/netbeans/modules/java/source/usages/ClassIndexManager.java Thu Feb 28 14:45:35 2008 +0100
@@ -141,7 +141,7 @@
return Thread.currentThread().equals(this.owner);
}
- public synchronized ClassIndexImpl getUsagesQuery (final URL root) throws IOException {
+ public synchronized ClassIndexImpl getUsagesQuery (final URL root) {
assert root != null;
if (invalid) {
return null;
diff -r 4d993c0dea81 java.source/src/org/netbeans/modules/java/source/usages/RepositoryUpdater.java
--- a/java.source/src/org/netbeans/modules/java/source/usages/RepositoryUpdater.java Wed Feb 27 20:24:37 2008 +0100
+++ b/java.source/src/org/netbeans/modules/java/source/usages/RepositoryUpdater.java Thu Feb 28 14:45:35 2008 +0100
@@ -551,7 +551,7 @@
public final void scheduleCompilation (final FileObject fo, final FileObject root) throws IOException {
URL foURL = fo.getURL();
URL rootURL = root.getURL();
- if (!cpImpl.isLibrary(rootURL)) {
+ if (!cpImpl.isLibrary(root)) {
assert "file".equals(foURL.getProtocol()) && "file".equals(rootURL.getProtocol());
scheduleCompilation (foURL,rootURL,fo.isFolder());
}