aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/EclipseLintClient.java8
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/lint/ProjectLintConfigurationTest.java4
-rw-r--r--lint/cli/src/com/android/tools/lint/Main.java6
-rw-r--r--lint/libs/lint_api/src/com/android/tools/lint/client/api/DefaultConfiguration.java4
-rw-r--r--lint/libs/lint_api/src/com/android/tools/lint/client/api/LintClient.java2
-rw-r--r--lint/libs/lint_api/src/com/android/tools/lint/client/api/LintDriver.java44
-rw-r--r--lint/libs/lint_api/src/com/android/tools/lint/detector/api/Context.java28
-rw-r--r--lint/libs/lint_api/src/com/android/tools/lint/detector/api/XmlContext.java2
-rw-r--r--lint/libs/lint_checks/tests/src/com/android/tools/lint/LintCliXmlParserTest.java5
-rw-r--r--lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AbstractCheckTest.java5
10 files changed, 85 insertions, 23 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/EclipseLintClient.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/EclipseLintClient.java
index 9db17d8..9424bf0 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/EclipseLintClient.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/EclipseLintClient.java
@@ -203,12 +203,8 @@ public class EclipseLintClient extends LintClient implements IDomParser {
}
@Override
- public void report(Context context, Issue issue, Location location, String message,
- Object data) {
- assert context.isEnabled(issue);
- assert context.getConfiguration().getSeverity(issue) != Severity.IGNORE;
- Severity s = context.getConfiguration().getSeverity(issue);
-
+ public void report(Context context, Issue issue, Severity s, Location location,
+ String message, Object data) {
int severity = getMarkerSeverity(s);
IMarker marker = null;
if (location != null) {
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/lint/ProjectLintConfigurationTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/lint/ProjectLintConfigurationTest.java
index 96014de..202d768 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/lint/ProjectLintConfigurationTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/lint/ProjectLintConfigurationTest.java
@@ -208,8 +208,8 @@ public class ProjectLintConfigurationTest extends AdtProjectTest {
private static class TestClient extends LintClient {
@Override
- public void report(Context context, Issue issue, Location location, String message,
- Object data) {
+ public void report(Context context, Issue issue, Severity severity, Location location,
+ String message, Object data) {
}
@Override
diff --git a/lint/cli/src/com/android/tools/lint/Main.java b/lint/cli/src/com/android/tools/lint/Main.java
index 2621d0a..6cf2863 100644
--- a/lint/cli/src/com/android/tools/lint/Main.java
+++ b/lint/cli/src/com/android/tools/lint/Main.java
@@ -842,14 +842,14 @@ public class Main extends LintClient {
}
@Override
- public void report(Context context, Issue issue, Location location, String message,
- Object data) {
+ public void report(Context context, Issue issue, Severity severity, Location location,
+ String message, Object data) {
assert context.isEnabled(issue);
- Severity severity = context.getConfiguration().getSeverity(issue);
if (severity == Severity.IGNORE) {
return;
}
+
if (severity == Severity.FATAL) {
mFatal = true;
// From here on, treat the fatal error as an error such that we don't display
diff --git a/lint/libs/lint_api/src/com/android/tools/lint/client/api/DefaultConfiguration.java b/lint/libs/lint_api/src/com/android/tools/lint/client/api/DefaultConfiguration.java
index 56cee8e..6dc4804 100644
--- a/lint/libs/lint_api/src/com/android/tools/lint/client/api/DefaultConfiguration.java
+++ b/lint/libs/lint_api/src/com/android/tools/lint/client/api/DefaultConfiguration.java
@@ -203,7 +203,9 @@ public class DefaultConfiguration extends Configuration {
}
message = "Failed to parse lint.xml configuration file: " + message;
mClient.report(new Context(null, mProject, mProject, mConfigFile),
- IssueRegistry.LINT_ERROR, Location.create(mConfigFile), message, null);
+ IssueRegistry.LINT_ERROR,
+ mProject.getConfiguration().getSeverity(IssueRegistry.LINT_ERROR),
+ Location.create(mConfigFile), message, null);
}
private void readConfig() {
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 48e86b5..0e47dde 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
@@ -76,6 +76,7 @@ public abstract class LintClient {
*
* @param context the context used by the detector when the issue was found
* @param issue the issue that was found
+ * @param severity the severity of the issue
* @param location the location of the issue
* @param message the associated user message
* @param data optional extra data for a discovered issue, or null. The
@@ -88,6 +89,7 @@ public abstract class LintClient {
public abstract void report(
@NonNull Context context,
@NonNull Issue issue,
+ @NonNull Severity severity,
@Nullable Location location,
@NonNull String message,
@Nullable Object data);
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 d328ab8..ad736c6 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
@@ -123,6 +123,7 @@ public class LintDriver {
private int mPhase;
private List<Detector> mRepeatingDetectors;
private EnumSet<Scope> mRepeatScope;
+ private Project[] mCurrentProjects;
private boolean mAbbreviating = true;
/**
@@ -172,6 +173,31 @@ public class LintDriver {
}
/**
+ * Returns the project containing a given file, or null if not found. This searches
+ * only among the currently checked project and its library projects, not among all
+ * possible projects being scanned sequentially.
+ *
+ * @param file the file to be checked
+ * @return the corresponding project, or null if not found
+ */
+ @Nullable
+ public Project findProjectFor(@NonNull File file) {
+ if (mCurrentProjects != null) {
+ if (mCurrentProjects.length == 1) {
+ return mCurrentProjects[0];
+ }
+ String path = file.getPath();
+ for (Project project : mCurrentProjects) {
+ if (path.startsWith(project.getDir().getPath())) {
+ return project;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
* Sets whether lint should abbreviate output when appropriate.
*
* @param abbreviating true to abbreviate output, false to include everything
@@ -620,6 +646,12 @@ public class LintDriver {
Context projectContext = new Context(this, project, null, projectDir);
fireEvent(EventType.SCANNING_PROJECT, projectContext);
+ List<Project> allLibraries = project.getAllLibraries();
+ Set<Project> allProjects = new HashSet<Project>(allLibraries.size() + 1);
+ allProjects.add(project);
+ allProjects.addAll(allLibraries);
+ mCurrentProjects = allProjects.toArray(new Project[allProjects.size()]);
+
for (Detector check : mApplicableDetectors) {
check.beforeCheckProject(projectContext);
if (mCanceled) {
@@ -627,7 +659,6 @@ public class LintDriver {
}
}
-
runFileDetectors(project, project);
if (!Scope.checkSingleFile(mScope)) {
@@ -671,9 +702,12 @@ public class LintDriver {
// is valid
Issue.create("Lint", "", "", Category.PERFORMANCE, 0, Severity.INFORMATIONAL, //$NON-NLS-1$
null, EnumSet.noneOf(Scope.class)),
+ Severity.INFORMATIONAL,
null /*range*/,
"Lint canceled by user", null);
}
+
+ mCurrentProjects = null;
}
private void runFileDetectors(@NonNull Project project, @Nullable Project main) {
@@ -876,7 +910,9 @@ public class LintDriver {
+ "Does the project need to be built first?", project.getName());
Location location = Location.create(project.getDir());
mClient.report(new Context(this, project, main, project.getDir()),
- IssueRegistry.LINT_ERROR, location, message, null);
+ IssueRegistry.LINT_ERROR,
+ project.getConfiguration().getSeverity(IssueRegistry.LINT_ERROR),
+ location, message, null);
classEntries = Collections.emptyList();
} else {
classEntries = new ArrayList<ClassEntry>(64);
@@ -1331,6 +1367,7 @@ public class LintDriver {
public void report(
@NonNull Context context,
@NonNull Issue issue,
+ @NonNull Severity severity,
@Nullable Location location,
@NonNull String message,
@Nullable Object data) {
@@ -1347,12 +1384,11 @@ public class LintDriver {
return;
}
- Severity severity = configuration.getSeverity(issue);
if (severity == Severity.IGNORE) {
return;
}
- mDelegate.report(context, issue, location, message, data);
+ mDelegate.report(context, issue, severity, location, message, data);
}
// Everything else just delegates to the embedding lint client
diff --git a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/Context.java b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/Context.java
index 33e39e7..9ddd10a 100644
--- a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/Context.java
+++ b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/Context.java
@@ -257,7 +257,33 @@ public class Context {
@Nullable Location location,
@NonNull String message,
@Nullable Object data) {
- mDriver.getClient().report(this, issue, location, message, data);
+ Configuration configuration = mConfiguration;
+
+ // If this error was computed for a context where the context corresponds to
+ // a project instead of a file, the actual error may be in a different project (e.g.
+ // a library project), so adjust the configuration as necessary.
+ if (location != null && location.getFile() != null) {
+ Project project = mDriver.findProjectFor(location.getFile());
+ if (project != null) {
+ configuration = project.getConfiguration();
+ }
+ }
+
+ // If an error occurs in a library project, but you've disabled that check in the
+ // main project, disable it in the library project too. (In some cases you don't
+ // control the lint.xml of a library project, and besides, if you're not interested in
+ // a check for your main project you probably don't care about it in the library either.)
+ if (configuration != mConfiguration
+ && mConfiguration.getSeverity(issue) == Severity.IGNORE) {
+ return;
+ }
+
+ Severity severity = configuration.getSeverity(issue);
+ if (severity == Severity.IGNORE) {
+ return;
+ }
+
+ mDriver.getClient().report(this, issue, severity, location, message, data);
}
/**
diff --git a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/XmlContext.java b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/XmlContext.java
index 7733dc7..aabbf79 100644
--- a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/XmlContext.java
+++ b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/XmlContext.java
@@ -102,7 +102,7 @@ public class XmlContext extends Context {
if (scope != null && mDriver.isSuppressed(issue, scope)) {
return;
}
- mDriver.getClient().report(this, issue, location, message, data);
+ super.report(issue, location, message, data);
}
@Override
diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/LintCliXmlParserTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/LintCliXmlParserTest.java
index 7186fb1..a6f4aaf 100644
--- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/LintCliXmlParserTest.java
+++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/LintCliXmlParserTest.java
@@ -25,6 +25,7 @@ import com.android.tools.lint.detector.api.Location;
import com.android.tools.lint.detector.api.Location.Handle;
import com.android.tools.lint.detector.api.Position;
import com.android.tools.lint.detector.api.Project;
+import com.android.tools.lint.detector.api.Severity;
import com.android.tools.lint.detector.api.XmlContext;
import org.w3c.dom.Attr;
@@ -153,8 +154,8 @@ public class LintCliXmlParserTest extends TestCase {
private static class TestClient extends Main {
@Override
- public void report(Context context, Issue issue, Location location, String message,
- Object data) {
+ public void report(Context context, Issue issue, Severity severity, Location location,
+ String message, Object data) {
System.out.println(location + ":" + message);
}
}
diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AbstractCheckTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AbstractCheckTest.java
index 4555420..ba22ed3 100644
--- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AbstractCheckTest.java
+++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AbstractCheckTest.java
@@ -270,8 +270,8 @@ public abstract class AbstractCheckTest extends TestCase {
}
@Override
- public void report(Context context, Issue issue, Location location, String message,
- Object data) {
+ public void report(Context context, Issue issue, Severity severity, Location location,
+ String message, Object data) {
StringBuilder sb = new StringBuilder();
if (issue == IssueRegistry.LINT_ERROR) {
@@ -305,7 +305,6 @@ public abstract class AbstractCheckTest extends TestCase {
sb.append(' ');
}
- Severity severity = context.getConfiguration().getSeverity(issue);
if (severity == Severity.FATAL) {
// Treat fatal errors like errors in the golden files.
severity = Severity.ERROR;