OSDN Git Service

Fixing Android Source attachements
authorsnpe <snpe@snpe.rs>
Sun, 23 Jan 2011 15:41:03 +0000 (16:41 +0100)
committersnpe <snpe@snpe.rs>
Fri, 11 Feb 2011 19:06:55 +0000 (20:06 +0100)
Steps to reproduce:

- add Android Source code to android.jar (you can install Android
  Sources plugin from http://code.google.com/p/adt-addons/)
- ensure that android.app.ActivityThread exists in the source
  attachement (if you use Sources plugin, it exists)
- create an Android application and add the next code to
  onCreate method:
super.onCreate(savedInstanceState);
        Object obj = null;
        System.out.println(obj.toString());
        setContentView(R.layout.main);
- set breakpoint at line
  System.out.println(obj.toString()); (NPE)
- debug the application
- wait that apps stop on breakpoint
- click Step Over

The procces will proceed in ActivityThread, but source is not shown.

The problem happens because the Android source locator introduced in
https://review.source.android.com/#change,16569 isn't correct.
ActivityThread.java isn't included to android.jar, but can be
included in the source attachement. This change adds source to Android
launch configuration too.

Change-Id: Id13ef9acac9a901a704ae79d3e3db3be5e09d929

eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sourcelookup/AdtSourceLookupDirector.java

index 551e6be..07c59b1 100644 (file)
             modes="debug, run"
             name="Android Application"
             public="true"
-            sourceLocatorId="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"
+            sourceLocatorId="com.android.ide.eclipse.adt.internal.sourcelookup.AdtSourceLookupDirector"
             sourcePathComputerId="org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer">
       </launchConfigurationType>
    </extension>
index 612ef76..e0e236b 100755 (executable)
@@ -17,7 +17,9 @@
 \r
 package com.android.ide.eclipse.adt.internal.sourcelookup;\r
 \r
-import com.android.ide.eclipse.adt.internal.project.AndroidClasspathContainerInitializer;\r
+import com.android.ide.eclipse.adt.internal.sdk.ProjectState;\r
+import com.android.ide.eclipse.adt.internal.sdk.Sdk;\r
+import com.android.sdklib.IAndroidTarget;\r
 \r
 import org.eclipse.core.resources.IProject;\r
 import org.eclipse.core.resources.ResourcesPlugin;\r
@@ -32,6 +34,7 @@ import org.eclipse.jdt.core.IClasspathEntry;
 import org.eclipse.jdt.core.IJavaProject;\r
 import org.eclipse.jdt.core.JavaCore;\r
 import org.eclipse.jdt.internal.launching.JavaSourceLookupDirector;\r
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;\r
 \r
 import java.io.File;\r
 \r
@@ -41,20 +44,35 @@ public class AdtSourceLookupDirector extends JavaSourceLookupDirector {
     public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException {\r
         dispose();\r
         setLaunchConfiguration(configuration);\r
-        String projectName = configuration.getAttribute("org.eclipse.jdt.launching.PROJECT_ATTR", //$NON-NLS-1$\r
+        String projectName =\r
+            configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,\r
                 ""); //$NON-NLS-1$\r
         if (projectName != null && projectName.length() > 0) {\r
             IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);\r
             if (project != null && project.isOpen()) {\r
+                ProjectState state = Sdk.getProjectState(project);\r
+                if (state == null) {\r
+                    initDefaults();\r
+                    return;\r
+                }\r
+                IAndroidTarget target = state.getTarget();\r
+                if (target == null) {\r
+                    initDefaults();\r
+                    return;\r
+                }\r
+                String path = target.getPath(IAndroidTarget.ANDROID_JAR);\r
+                if (path == null) {\r
+                    initDefaults();\r
+                    return;\r
+                }\r
                 IJavaProject javaProject = JavaCore.create(project);\r
                 if (javaProject != null && javaProject.isOpen()) {\r
-                    IClasspathEntry[] entries = javaProject.getRawClasspath();\r
+                    IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);\r
                     IClasspathEntry androidEntry = null;\r
                     for (int i = 0; i < entries.length; i++) {\r
                         IClasspathEntry entry = entries[i];\r
-                        if (entry.getPath() != null\r
-                                && AndroidClasspathContainerInitializer.CONTAINER_ID.equals(entry\r
-                                        .getPath().toString())) {\r
+                        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY\r
+                                && path.equals(entry.getPath().toString())) {\r
                             androidEntry = entry;\r
                             break;\r
                         }\r
@@ -88,6 +106,10 @@ public class AdtSourceLookupDirector extends JavaSourceLookupDirector {
                 }\r
             }\r
         }\r
+        initDefaults();\r
+    }\r
+\r
+    private void initDefaults() {\r
         setSourceContainers(new ISourceContainer[] {\r
             new DefaultSourceContainer()\r
         });\r