diff options
author | Tor Norbye <tnorbye@google.com> | 2012-10-16 12:49:43 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-10-16 12:51:38 -0700 |
commit | d8428eef9b0888561f45aee3c87abd139085174d (patch) | |
tree | 671d57d49cca8d510c097bed93e43ac398c1c5ef /lint/libs/lint_api | |
parent | 8868d79309786b1fe233151d9415453d0c10b2d5 (diff) | |
download | sdk-d8428eef9b0888561f45aee3c87abd139085174d.zip sdk-d8428eef9b0888561f45aee3c87abd139085174d.tar.gz sdk-d8428eef9b0888561f45aee3c87abd139085174d.tar.bz2 |
Add lint support for checking frameworks/base/core
This changeset adds basic support for running lint against
the AOSP frameworks/base/core codebase.
It also makes the resource folder provided by the lint
client.
Change-Id: I7e38b0925cb032f776c54f975b924b91d6ab7a24
Diffstat (limited to 'lint/libs/lint_api')
4 files changed, 96 insertions, 2 deletions
diff --git a/lint/libs/lint_api/src/com/android/tools/lint/client/api/LintClient.java b/lint/libs/lint_api/src/com/android/tools/lint/client/api/LintClient.java index 2e21c06..2a68ddf 100644 --- a/lint/libs/lint_api/src/com/android/tools/lint/client/api/LintClient.java +++ b/lint/libs/lint_api/src/com/android/tools/lint/client/api/LintClient.java @@ -20,6 +20,7 @@ import static com.android.SdkConstants.CLASS_FOLDER; import static com.android.SdkConstants.DOT_JAR; import static com.android.SdkConstants.GEN_FOLDER; import static com.android.SdkConstants.LIBS_FOLDER; +import static com.android.SdkConstants.RES_FOLDER; import static com.android.SdkConstants.SRC_FOLDER; import com.android.SdkConstants; @@ -233,6 +234,23 @@ public abstract class LintClient { } /** + * Returns the resource folder. + * + * @param project the project to look up the resource folder for + * @return a file pointing to the resource folder, or null if the project + * does not contain any resources + */ + @Nullable + public File getResourceFolder(@NonNull Project project) { + File res = new File(project.getDir(), RES_FOLDER); + if (res.exists()) { + return res; + } + + return null; + } + + /** * Returns the {@link SdkInfo} to use for the given project. * * @param project the project to look up an {@link SdkInfo} for diff --git a/lint/libs/lint_api/src/com/android/tools/lint/client/api/LintDriver.java b/lint/libs/lint_api/src/com/android/tools/lint/client/api/LintDriver.java index aad1ad7..415c305 100644 --- a/lint/libs/lint_api/src/com/android/tools/lint/client/api/LintDriver.java +++ b/lint/libs/lint_api/src/com/android/tools/lint/client/api/LintDriver.java @@ -819,8 +819,8 @@ public class LintDriver { if (files != null) { checkIndividualResources(project, main, xmlDetectors, files); } else { - File res = new File(project.getDir(), RES_FOLDER); - if (res.exists() && xmlDetectors.size() > 0) { + File res = project.getResourceFolder(); + if (res != null && xmlDetectors.size() > 0) { checkResFolder(project, main, res, xmlDetectors); } } @@ -1664,6 +1664,12 @@ public class LintDriver { @Override @Nullable + public File getResourceFolder(@NonNull Project project) { + return mDelegate.getResourceFolder(project); + } + + @Override + @Nullable public IDomParser getDomParser() { return mDelegate.getDomParser(); } diff --git a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java index 60c9e97..c0d5a85 100644 --- a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java +++ b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java @@ -668,6 +668,9 @@ public class LintUtils { return false; } } + } else if (Project.isAospFrameworksProject(dir)) { + // Hardcoded AOSP support for the frameworks project + return true; } return hasManifest; diff --git a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/Project.java b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/Project.java index b584020..eb41807 100644 --- a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/Project.java +++ b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/Project.java @@ -25,9 +25,11 @@ import static com.android.SdkConstants.ATTR_PACKAGE; import static com.android.SdkConstants.ATTR_TARGET_SDK_VERSION; import static com.android.SdkConstants.PROGUARD_CONFIG; import static com.android.SdkConstants.PROJECT_PROPERTIES; +import static com.android.SdkConstants.RES_FOLDER; import static com.android.SdkConstants.TAG_USES_SDK; import static com.android.SdkConstants.VALUE_TRUE; +import com.android.SdkConstants; import com.android.annotations.NonNull; import com.android.annotations.Nullable; import com.android.tools.lint.client.api.Configuration; @@ -247,6 +249,9 @@ public class Project { @NonNull public List<File> getJavaSourceFolders() { if (mJavaSourceFolders == null) { + if (isAospFrameworksProject(mDir)) { + return Collections.singletonList(new File(mDir, "java")); //$NON-NLS-1$ + } if (isAospBuildEnvironment()) { String top = getAospTop(); if (mDir.getAbsolutePath().startsWith(top)) { @@ -268,6 +273,21 @@ public class Project { @NonNull public List<File> getJavaClassFolders() { if (mJavaClassFolders == null) { + if (isAospFrameworksProject(mDir)) { + File top = mDir.getParentFile().getParentFile().getParentFile(); + if (top != null) { + File out = new File(top, "out"); + if (out.exists()) { + String relative = + "target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar"; + File jar = new File(out, relative.replace('/', File.separatorChar)); + if (jar.exists()) { + mJavaClassFolders = Collections.singletonList(jar); + return mJavaClassFolders; + } + } + } + } if (isAospBuildEnvironment()) { String top = getAospTop(); if (mDir.getAbsolutePath().startsWith(top)) { @@ -304,6 +324,28 @@ public class Project { } /** + * Returns the resource folder. + * + * @return a file pointing to the resource folder, or null if the project + * does not contain any resources + */ + @Nullable + public File getResourceFolder() { + File folder = mClient.getResourceFolder(this); + + if (folder != null && isAospFrameworksProject(mDir)) { + // No manifest file for this project: just init the manifest values here + mMinSdk = mTargetSdk = SdkConstants.HIGHEST_KNOWN_API; + folder = new File(folder, RES_FOLDER); + if (!folder.exists()) { + folder = null; + } + } + + return folder; + } + + /** * Returns the relative path of a given file relative to the user specified * directory (which is often the project directory but sometimes a higher up * directory when a directory tree is being scanned @@ -643,6 +685,31 @@ public class Project { return sAospBuild.booleanValue(); } + /** + * Is this the frameworks AOSP project? Needs some hardcoded support since + * it doesn't have a manifest file, etc. + * + * @param dir the project directory to check + * @return true if this looks like the frameworks/base/core project + */ + static boolean isAospFrameworksProject(@NonNull File dir) { + if (!dir.getPath().endsWith("core")) { //$NON-NLS-1$ + return false; + } + + File parent = dir.getParentFile(); + if (parent == null || !parent.getName().equals("base")) { //$NON-NLS-1$ + return false; + } + + parent = parent.getParentFile(); + if (parent == null || !parent.getName().equals("frameworks")) { //$NON-NLS-1$ + return false; + } + + return true; + } + /** Get the root AOSP dir, if any */ private static String getAospTop() { return System.getenv("ANDROID_BUILD_TOP"); //$NON-NLS-1$ |