aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2009-12-04 17:33:21 -0800
committerXavier Ducrohet <xav@android.com>2009-12-04 17:41:47 -0800
commit33b62060beacbdf05ebbbfbb15b90365f005081f (patch)
treeda8eb3268db07bde6d7b6da69b989257cef1571e /eclipse
parent4e278588e789280a94e84215813a0e0ec4fe75fd (diff)
downloadsdk-33b62060beacbdf05ebbbfbb15b90365f005081f.zip
sdk-33b62060beacbdf05ebbbfbb15b90365f005081f.tar.gz
sdk-33b62060beacbdf05ebbbfbb15b90365f005081f.tar.bz2
Listen to default.properties change from outside of ADT and update the project.
BUG 2287591
Diffstat (limited to 'eclipse')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/BaseProjectHelper.java41
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/Sdk.java43
2 files changed, 62 insertions, 22 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/BaseProjectHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/BaseProjectHelper.java
index ff6cd04..104c13d 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/BaseProjectHelper.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/BaseProjectHelper.java
@@ -113,7 +113,7 @@ public final class BaseProjectHelper {
AdtPlugin.log(e, "Failed to add marker '%1$s' to '%2$s'", //$NON-NLS-1$
markerId, file.getFullPath());
}
-
+
return null;
}
@@ -143,7 +143,7 @@ public final class BaseProjectHelper {
AdtPlugin.log(e, "Failed to add marker '%1$s' to '%2$s'", //$NON-NLS-1$
markerId, resource.getFullPath());
}
-
+
return null;
}
@@ -157,7 +157,7 @@ public final class BaseProjectHelper {
* @param severity the severity of the marker.
* @param priority the priority of the marker
* @return the IMarker that was added.
- * @throws CoreException
+ * @throws CoreException
*/
public final static IMarker addMarker(IResource resource, String markerId,
String message, int lineNumber, int severity, int priority) throws CoreException {
@@ -204,7 +204,7 @@ public final class BaseProjectHelper {
if (Flags.isAbstract(flags)) {
return String.format("%1$s is abstract", className);
}
-
+
// test whether the class is public or not.
if (testVisibility && Flags.isPublic(flags) == false) {
// if its not public, it may have a public default constructor,
@@ -236,7 +236,7 @@ public final class BaseProjectHelper {
return String.format("%1$s is enclosed, but not static",
declaringType.getFullyQualifiedName());
}
-
+
flags = tmpType.getFlags();
if (testVisibility && Flags.isPublic(flags) == false) {
return String.format("%1$s is not public",
@@ -253,7 +253,7 @@ public final class BaseProjectHelper {
// test the class inherit from the specified super class.
// get the type hierarchy
ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
-
+
// if the super class is not the reference class, it may inherit from
// it so we get its supertype. At some point it will be null and we
// will stop
@@ -265,12 +265,12 @@ public final class BaseProjectHelper {
foundProperSuperClass = true;
}
}
-
+
// didn't find the proper superclass? return false.
if (foundProperSuperClass == false) {
return String.format("%1$s does not extend %2$s", className, superClassName);
}
-
+
return TEST_CLASS_OK;
} else {
return String.format("Class %1$s does not exist", className);
@@ -279,7 +279,7 @@ public final class BaseProjectHelper {
return String.format("%1$s: %2$s", className, e.getMessage());
}
}
-
+
/**
* Parses the manifest file for errors.
* <p/>
@@ -296,7 +296,7 @@ public final class BaseProjectHelper {
manifestFile.deleteMarkers(AndroidConstants.MARKER_XML, true, IResource.DEPTH_ZERO);
manifestFile.deleteMarkers(AndroidConstants.MARKER_ANDROID, true, IResource.DEPTH_ZERO);
}
-
+
// and parse
return AndroidManifestParser.parseForError(
BaseProjectHelper.getJavaProject(manifestFile.getProject()),
@@ -310,7 +310,8 @@ public final class BaseProjectHelper {
* @param project
* @return the IJavaProject or null if the project couldn't be created or if the project
* does not have the Java Nature.
- * @throws CoreException
+ * @throws CoreException if this method fails. Reasons include:
+ * <ul><li>This project does not exist.</li><li>This project is not open.</li></ul>
*/
public static IJavaProject getJavaProject(IProject project) throws CoreException {
if (project != null && project.hasNature(JavaCore.NATURE_ID)) {
@@ -318,7 +319,7 @@ public final class BaseProjectHelper {
}
return null;
}
-
+
/**
* Reveals a specific line in the source file defining a specified class,
* for a specific project.
@@ -332,7 +333,7 @@ public final class BaseProjectHelper {
// get the java project
IJavaProject javaProject = JavaCore.create(project);
-
+
try {
// look for the IType matching the class name.
IType result = javaProject.findType(className);
@@ -346,19 +347,19 @@ public final class BaseProjectHelper {
// no editor area? we open the java perspective.
new OpenJavaPerspectiveAction().run();
}
-
+
IEditorPart editor = JavaUI.openInEditor(result);
if (editor instanceof ITextEditor) {
// get the text editor that was just opened.
ITextEditor textEditor = (ITextEditor)editor;
-
+
IEditorInput input = textEditor.getEditorInput();
-
+
// get the location of the line to show.
IDocumentProvider documentProvider = textEditor.getDocumentProvider();
IDocument document = documentProvider.getDocument(input);
IRegion lineInfo = document.getLineInformation(line - 1);
-
+
// select and reveal the line.
textEditor.selectAndReveal(lineInfo.getOffset(), lineInfo.getLength());
}
@@ -368,7 +369,7 @@ public final class BaseProjectHelper {
} catch (BadLocationException e) {
}
}
-
+
/**
* Returns the list of android-flagged projects. This list contains projects that are opened
* in the workspace and that are flagged as android project (through the android nature)
@@ -421,7 +422,7 @@ public final class BaseProjectHelper {
// return the android projects list.
return androidProjectList.toArray(new IJavaProject[androidProjectList.size()]);
}
-
+
/**
* Returns the {@link IFolder} representing the output for the project.
* <p>
@@ -434,7 +435,7 @@ public final class BaseProjectHelper {
if (project.isOpen() && project.hasNature(JavaCore.NATURE_ID)) {
// get a java project from the normal project object
IJavaProject javaProject = JavaCore.create(project);
-
+
IPath path = javaProject.getOutputLocation();
IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
IResource outputResource = wsRoot.findMember(path);
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 45ff31f..e40a495 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
@@ -19,7 +19,9 @@ package com.android.ide.eclipse.adt.internal.sdk;
import com.android.ddmlib.IDevice;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.internal.project.AndroidClasspathContainerInitializer;
+import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceMonitor;
+import com.android.ide.eclipse.adt.internal.resources.manager.ResourceMonitor.IFileListener;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceMonitor.IProjectListener;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData.LayoutBridge;
import com.android.prefs.AndroidLocation.AndroidLocationException;
@@ -34,11 +36,17 @@ import com.android.sdklib.internal.project.ApkSettings;
import com.android.sdklib.internal.project.ProjectProperties;
import com.android.sdklib.internal.project.ProjectProperties.PropertyType;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
@@ -59,7 +67,7 @@ import java.util.Map;
*
* To get the list of platforms or add-ons present in the SDK, call {@link #getTargets()}.
*/
-public class Sdk implements IProjectListener {
+public class Sdk implements IProjectListener, IFileListener {
private static Sdk sCurrentSdk = null;
private final SdkManager mManager;
@@ -434,6 +442,7 @@ public class Sdk implements IProjectListener {
// listen to projects closing
ResourceMonitor monitor = ResourceMonitor.getMonitor();
monitor.addProjectListener(this);
+ monitor.addFileListener(this, IResourceDelta.CHANGED);
// pre-compute some paths
mDocBaseUrl = getDocumentationBaseUrl(mManager.getLocation() +
@@ -449,7 +458,9 @@ public class Sdk implements IProjectListener {
* Cleans and unloads the SDK.
*/
private void dispose() {
- ResourceMonitor.getMonitor().removeProjectListener(this);
+ ResourceMonitor monitor = ResourceMonitor.getMonitor();
+ monitor.removeProjectListener(this);
+ monitor.removeFileListener(this);
}
void setTargetData(IAndroidTarget target, AndroidTargetData data) {
@@ -547,5 +558,33 @@ public class Sdk implements IProjectListener {
// ignore this. The project will be added to the map the first time the target needs
// to be resolved.
}
+
+ public void fileChanged(final IFile file, IMarkerDelta[] markerDeltas, int kind) {
+ if (SdkConstants.FN_DEFAULT_PROPERTIES.equals(file.getName()) &&
+ file.getParent() == file.getProject()) {
+ // we can't do the change from the Workspace resource change notification
+ // so we create build-type job for it.
+ Job job = new Job("Project Update") {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ IJavaProject javaProject = BaseProjectHelper.getJavaProject(
+ file.getProject());
+ if (javaProject != null) {
+ AndroidClasspathContainerInitializer.updateProjects(
+ new IJavaProject[] { javaProject });
+ }
+ } catch (CoreException e) {
+ // This can't happen as it's only for closed project (or non existing)
+ // but in that case we can't get a fileChanged on this file.
+ }
+
+ return Status.OK_STATUS;
+ }
+ };
+ job.setPriority(Job.BUILD); // build jobs are run after other interactive jobs
+ job.schedule();
+ }
+ }
}