aboutsummaryrefslogtreecommitdiffstats
path: root/lint/libs
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2013-01-03 16:53:56 -0800
committerTor Norbye <tnorbye@google.com>2013-01-04 10:22:48 -0800
commit6050e51438c29d5f5f6413dd842fa2d019d954db (patch)
treea5df515ba1831f3466e16c7e661914f6f4169b2d /lint/libs
parentcf7f3984edfb23ce6bb85ebd101c165c7c0cafa6 (diff)
downloadsdk-6050e51438c29d5f5f6413dd842fa2d019d954db.zip
sdk-6050e51438c29d5f5f6413dd842fa2d019d954db.tar.gz
sdk-6050e51438c29d5f5f6413dd842fa2d019d954db.tar.bz2
Make resource folders customizeable
Until now, lint has hardcoded where the project resources are to be found: in $project/res. With the new build system this will no longer necessarily be the case; there can be multiple resource folders, and the locations might not be just res/. Therefore, this CL generalizes lint's handling of resource folders: it is now provided by the LintClient, and the command line lint tool uses this to offer a new --resources flag which can be used to set the resource directory/directories for a project. Change-Id: I3717c6474141776ee5541d476f9bad5bb8e1a9c7
Diffstat (limited to 'lint/libs')
-rw-r--r--lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintClient.java14
-rw-r--r--lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintDriver.java14
-rw-r--r--lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Project.java14
-rw-r--r--lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/IconDetector.java4
-rw-r--r--lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PrivateKeyDetector.java4
-rw-r--r--lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UnusedResourceDetector.java14
6 files changed, 36 insertions, 28 deletions
diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintClient.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintClient.java
index 9afef42..6c4b202 100644
--- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintClient.java
+++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintClient.java
@@ -52,6 +52,7 @@ import java.io.IOException;
import java.io.StringReader;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -236,20 +237,19 @@ public abstract class LintClient {
}
/**
- * Returns the resource folder.
+ * Returns the resource folders.
*
* @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
+ * @return a list of files pointing to the resource folders, possibly empty
*/
- @Nullable
- public File getResourceFolder(@NonNull Project project) {
+ @NonNull
+ public List<File> getResourceFolders(@NonNull Project project) {
File res = new File(project.getDir(), RES_FOLDER);
if (res.exists()) {
- return res;
+ return Collections.singletonList(res);
}
- return null;
+ return Collections.emptyList();
}
/**
diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintDriver.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintDriver.java
index dd268a5..28168a6 100644
--- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintDriver.java
+++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/client/api/LintDriver.java
@@ -841,9 +841,11 @@ public class LintDriver {
if (files != null) {
checkIndividualResources(project, main, xmlDetectors, files);
} else {
- File res = project.getResourceFolder();
- if (res != null && !xmlDetectors.isEmpty()) {
- checkResFolder(project, main, res, xmlDetectors);
+ List<File> resourceFolders = project.getResourceFolders();
+ if (!resourceFolders.isEmpty() && !xmlDetectors.isEmpty()) {
+ for (File res : resourceFolders) {
+ checkResFolder(project, main, res, xmlDetectors);
+ }
}
}
}
@@ -1686,9 +1688,9 @@ public class LintDriver {
}
@Override
- @Nullable
- public File getResourceFolder(@NonNull Project project) {
- return mDelegate.getResourceFolder(project);
+ @NonNull
+ public List<File> getResourceFolders(@NonNull Project project) {
+ return mDelegate.getResourceFolders(project);
}
@Override
diff --git a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Project.java b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Project.java
index df27b2f..67c3b16 100644
--- a/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Project.java
+++ b/lint/libs/lint_api/src/main/java/com/android/tools/lint/detector/api/Project.java
@@ -353,20 +353,20 @@ public class Project {
* @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);
+ @NonNull
+ public List<File> getResourceFolders() {
+ List<File> folders = mClient.getResourceFolders(this);
- if (folder != null && isAospFrameworksProject(mDir)) {
+ if (folders.size() == 1 && 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);
+ File folder = new File(folders.get(0), RES_FOLDER);
if (!folder.exists()) {
- folder = null;
+ folders = Collections.emptyList();
}
}
- return folder;
+ return folders;
}
/**
diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/IconDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/IconDetector.java
index 4d8b3a4..7f26c96 100644
--- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/IconDetector.java
+++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/IconDetector.java
@@ -386,8 +386,8 @@ public class IconDetector extends ResourceXmlDetector implements Detector.JavaSc
}
private void checkResourceFolder(Context context, @NonNull Project project) {
- File res = project.getResourceFolder();
- if (res != null) {
+ List<File> resourceFolders = project.getResourceFolders();
+ for (File res : resourceFolders) {
File[] folders = res.listFiles();
if (folders != null) {
boolean checkFolders = context.isEnabled(ICON_DENSITIES)
diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PrivateKeyDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PrivateKeyDetector.java
index b1e848b..f957331 100644
--- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PrivateKeyDetector.java
+++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/PrivateKeyDetector.java
@@ -105,7 +105,9 @@ public class PrivateKeyDetector extends Detector {
Project project = context.getProject();
File projectFolder = project.getDir();
- checkFolder(context, new File(projectFolder, "res"));
+ for (File res : project.getResourceFolders()) {
+ checkFolder(context, res);
+ }
checkFolder(context, new File(projectFolder, "assets"));
for (File srcFolder : project.getJavaSourceFolders()) {
diff --git a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UnusedResourceDetector.java b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UnusedResourceDetector.java
index 436f420..2a2d77c 100644
--- a/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UnusedResourceDetector.java
+++ b/lint/libs/lint_checks/src/main/java/com/android/tools/lint/checks/UnusedResourceDetector.java
@@ -54,6 +54,7 @@ import com.android.tools.lint.detector.api.Scope;
import com.android.tools.lint.detector.api.Severity;
import com.android.tools.lint.detector.api.Speed;
import com.android.tools.lint.detector.api.XmlContext;
+import com.google.common.collect.Lists;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
@@ -260,16 +261,19 @@ public class UnusedResourceDetector extends ResourceXmlDetector implements Detec
if (type != null && LintUtils.isFileBasedResourceType(type)) {
String name = resource.substring(secondDot + 1);
- File[] folders = null;
- File res = context.getProject().getResourceFolder();
- if (res != null) {
- folders = res.listFiles();
+ List<File> folders = Lists.newArrayList();
+ List<File> resourceFolders = context.getProject().getResourceFolders();
+ for (File res : resourceFolders) {
+ File[] f = res.listFiles();
+ if (f != null) {
+ folders.addAll(Arrays.asList(f));
+ }
}
if (folders != null) {
// Process folders in alphabetical order such that we process
// based folders first: we want the locations in base folder
// order
- Arrays.sort(folders, new Comparator<File>() {
+ Collections.sort(folders, new Comparator<File>() {
@Override
public int compare(File file1, File file2) {
return file1.getName().compareTo(file2.getName());