diff options
8 files changed, 70 insertions, 59 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java index a7ef6c6..9e17f0f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java @@ -1580,7 +1580,10 @@ public class AdtPlugin extends AbstractUIPlugin implements ILogger { monitor.addFileListener(new IFileListener() { @Override public void fileChanged(@NonNull IFile file, @NonNull IMarkerDelta[] markerDeltas, - int kind, @Nullable String extension, int flags) { + int kind, @Nullable String extension, int flags, boolean isAndroidProject) { + if (!isAndroidProject) { + return; + } if (flags == IResourceDelta.MARKERS || !SdkConstants.EXT_XML.equals(extension)) { // ONLY the markers changed, or not XML file: not relevant to this listener return; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutReloadMonitor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutReloadMonitor.java index d9e798e..4e4429d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutReloadMonitor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutReloadMonitor.java @@ -175,7 +175,7 @@ public final class LayoutReloadMonitor { */ @Override public void fileChanged(@NonNull IFile file, @NonNull IMarkerDelta[] markerDeltas, - int kind, @Nullable String extension, int flags) { + int kind, @Nullable String extension, int flags, boolean isAndroidProject) { // This listener only cares about .class files and AndroidManifest.xml files if (!(SdkConstants.EXT_CLASS.equals(extension) || SdkConstants.EXT_XML.equals(extension) @@ -186,15 +186,7 @@ public final class LayoutReloadMonitor { // get the file's project IProject project = file.getProject(); - boolean hasAndroidNature = false; - try { - hasAndroidNature = project.hasNature(AdtConstants.NATURE_DEFAULT); - } catch (CoreException e) { - // do nothing if the nature cannot be queried. - return; - } - - if (hasAndroidNature) { + if (isAndroidProject) { // project is an Android project, it's the one being affected // directly by its own file change. processFileChanged(file, project, extension); @@ -204,16 +196,14 @@ public final class LayoutReloadMonitor { for (IProject p : referencingProjects) { try { - hasAndroidNature = p.hasNature(AdtConstants.NATURE_DEFAULT); + boolean hasAndroidNature = p.hasNature(AdtConstants.NATURE_DEFAULT); + if (hasAndroidNature) { + // the changed project is a dependency on an Android project, + // update the main project. + processFileChanged(file, p, extension); + } } catch (CoreException e) { // do nothing if the nature cannot be queried. - continue; - } - - if (hasAndroidNature) { - // the changed project is a dependency on an Android project, - // update the main project. - processFileChanged(file, p, extension); } } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java index b1bfa88..55ebf59 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java @@ -321,8 +321,8 @@ public final class ManifestEditor extends AndroidXmlEditor { mMarkerMonitor = new IFileListener() { @Override public void fileChanged(@NonNull IFile file, @NonNull IMarkerDelta[] markerDeltas, - int kind, @Nullable String extension, int flags) { - if (file.equals(inputFile)) { + int kind, @Nullable String extension, int flags, boolean isAndroidProject) { + if (isAndroidProject && file.equals(inputFile)) { processMarkerChanges(markerDeltas); } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintDeltaProcessor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintDeltaProcessor.java index df8d9af..ebb9a59 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintDeltaProcessor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintDeltaProcessor.java @@ -167,9 +167,10 @@ public class LintDeltaProcessor implements Runnable { @Override public void fileChanged(@NonNull IFile file, @NonNull IMarkerDelta[] markerDeltas, - int kind, @Nullable String extension, int flags) { - if (flags == IResourceDelta.MARKERS) { - // ONLY the markers changed. Ignore these since they happen + int kind, @Nullable String extension, int flags, boolean isAndroidProject) { + if (!isAndroidProject || flags == IResourceDelta.MARKERS) { + // If not an Android project or ONLY the markers changed. + // Ignore these since they happen // when we add markers for lint errors found in the current file, // which would cause us to repeatedly enter this method over and over // again. diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/CompiledResourcesMonitor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/CompiledResourcesMonitor.java index 6554cc2..ab5ae40 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/CompiledResourcesMonitor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/CompiledResourcesMonitor.java @@ -84,9 +84,9 @@ public final class CompiledResourcesMonitor implements IFileListener, IProjectLi */ @Override public void fileChanged(@NonNull IFile file, @NonNull IMarkerDelta[] markerDeltas, - int kind, @Nullable String extension, int flags) { - if (flags == IResourceDelta.MARKERS) { - // Only the markers changed: not relevant + int kind, @Nullable String extension, int flags, boolean isAndroidProject) { + if (!isAndroidProject || flags == IResourceDelta.MARKERS) { + // Not Android or only the markers changed: not relevant return; } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/GlobalProjectMonitor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/GlobalProjectMonitor.java index 7cb4e94..674a601 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/GlobalProjectMonitor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/GlobalProjectMonitor.java @@ -20,6 +20,7 @@ import com.android.annotations.NonNull; import com.android.annotations.Nullable; import com.android.ide.common.resources.ResourceFile; import com.android.ide.common.resources.ResourceFolder; +import com.android.ide.eclipse.adt.AdtConstants; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper; @@ -76,9 +77,10 @@ public final class GlobalProjectMonitor { * not have an extension * @param flags the {@link IResourceDelta#getFlags()} value with details * on what changed in the file + * @param isAndroidProject whether the parent project is an Android Project */ public void fileChanged(@NonNull IFile file, @NonNull IMarkerDelta[] markerDeltas, - int kind, @Nullable String extension, int flags); + int kind, @Nullable String extension, int flags, boolean isAndroidProject); } /** @@ -138,8 +140,9 @@ public final class GlobalProjectMonitor { * Sent when a folder changed. * @param folder The file that was changed * @param kind The change kind. This is equivalent to {@link IResourceDelta#getKind()} + * @param isAndroidProject whether the parent project is an Android Project */ - public void folderChanged(IFolder folder, int kind); + public void folderChanged(IFolder folder, int kind, boolean isAndroidProject); } /** @@ -208,6 +211,8 @@ public final class GlobalProjectMonitor { private IWorkspace mWorkspace; + private boolean mIsAndroidProject; + /** * Delta visitor for resource changes. */ @@ -226,7 +231,7 @@ public final class GlobalProjectMonitor { || (bundle.kindMask & kind) != 0) { try { bundle.listener.fileChanged((IFile)r, delta.getMarkerDeltas(), kind, - r.getFileExtension(), delta.getFlags()); + r.getFileExtension(), delta.getFlags(), mIsAndroidProject); } catch (Throwable t) { AdtPlugin.log(t,"Failed to call IFileListener.fileChanged"); } @@ -240,7 +245,7 @@ public final class GlobalProjectMonitor { if (bundle.kindMask == ListenerBundle.MASK_NONE || (bundle.kindMask & kind) != 0) { try { - bundle.listener.folderChanged((IFolder)r, kind); + bundle.listener.folderChanged((IFolder)r, kind, mIsAndroidProject); } catch (Throwable t) { AdtPlugin.log(t,"Failed to call IFileListener.folderChanged"); } @@ -248,11 +253,27 @@ public final class GlobalProjectMonitor { } return true; } else if (type == IResource.PROJECT) { + IProject project = (IProject)r; + + try { + mIsAndroidProject = project.hasNature(AdtConstants.NATURE_DEFAULT); + } catch (CoreException e) { + // this can only happen if the project does not exist or is not open, neither + // of which can happen here since we are processing changes in the project + // or at worst a project post-open event. + return false; + } + + if (mIsAndroidProject == false) { + // for non android project, skip the project listeners but return true + // to visit the children and notify the IFileListeners + return true; + } + int flags = delta.getFlags(); if ((flags & IResourceDelta.OPEN) != 0) { // the project is opening or closing. - IProject project = (IProject)r; if (project.isOpen()) { // notify the listeners. @@ -491,9 +512,15 @@ public final class GlobalProjectMonitor { // notify the listeners. for (IProjectListener pl : mProjectListeners) { try { - pl.projectDeleted(project); - } catch (Throwable t) { - AdtPlugin.log(t,"Failed to call IProjectListener.projectDeleted"); + if (project.hasNature(AdtConstants.NATURE_DEFAULT)) { + try { + pl.projectDeleted(project); + } catch (Throwable t) { + AdtPlugin.log(t,"Failed to call IProjectListener.projectDeleted"); + } + } + } catch (CoreException e) { + // just ignore this project. } } } else { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceManager.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceManager.java index e1a12d7..1e12861 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceManager.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceManager.java @@ -422,6 +422,15 @@ public final class ResourceManager { for (IResourceDelta delta : projectDeltas) { if (delta.getResource() instanceof IProject) { IProject project = (IProject) delta.getResource(); + + try { + if (project.hasNature(AdtConstants.NATURE_DEFAULT) == false) { + continue; + } + } catch (CoreException e) { + // only happens if the project is closed or doesn't exist. + } + IdeScanningContext context = new IdeScanningContext(getProjectResources(project), project, true); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java index 1a299d9..d9020f8 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java @@ -880,16 +880,6 @@ public final class Sdk { } private void onProjectRemoved(IProject removedProject, boolean deleted) { - try { - if (removedProject.hasNature(AdtConstants.NATURE_DEFAULT) == false) { - return; - } - } catch (CoreException e) { - // this can only happen if the project does not exist or is not open, neither - // of which can happen here since we're processing a Project removed/deleted event - // which is processed before the project is actually removed/closed. - } - if (DEBUG) { System.out.println(">>> CLOSED: " + removedProject.getName()); } @@ -963,15 +953,6 @@ public final class Sdk { } private void onProjectOpened(final IProject openedProject) { - try { - if (openedProject.hasNature(AdtConstants.NATURE_DEFAULT) == false) { - return; - } - } catch (CoreException e) { - // this can only happen if the project does not exist or is not open, neither - // of which can happen here since we're processing a Project opened event. - } - ProjectState openedState = getProjectState(openedProject); if (openedState != null) { @@ -1052,7 +1033,11 @@ public final class Sdk { private IFileListener mFileListener = new IFileListener() { @Override public void fileChanged(final @NonNull IFile file, @NonNull IMarkerDelta[] markerDeltas, - int kind, @Nullable String extension, int flags) { + int kind, @Nullable String extension, int flags, boolean isAndroidPRoject) { + if (!isAndroidPRoject) { + return; + } + if (SdkConstants.FN_PROJECT_PROPERTIES.equals(file.getName()) && file.getParent() == file.getProject()) { try { @@ -1060,10 +1045,6 @@ public final class Sdk { // the target. IProject iProject = file.getProject(); - if (iProject.hasNature(AdtConstants.NATURE_DEFAULT) == false) { - return; - } - ProjectState state = Sdk.getProjectState(iProject); // get the current target |