diff options
author | Tor Norbye <tnorbye@google.com> | 2012-08-02 14:52:39 -0700 |
---|---|---|
committer | android code review <noreply-gerritcodereview@google.com> | 2012-08-02 14:52:39 -0700 |
commit | 84f7894876d423307586c55d7746c66c905c4a42 (patch) | |
tree | 41c6fe5bbf12c723978eb34227f3e1a52da00e57 /lint/cli | |
parent | beae71ea8cdda64cae67945c669d70497b753274 (diff) | |
parent | 3abd464aaa992994fc17786cdb5b2532ceb84143 (diff) | |
download | sdk-84f7894876d423307586c55d7746c66c905c4a42.zip sdk-84f7894876d423307586c55d7746c66c905c4a42.tar.gz sdk-84f7894876d423307586c55d7746c66c905c4a42.tar.bz2 |
Merge "Allow custom source and class folders"
Diffstat (limited to 'lint/cli')
-rw-r--r-- | lint/cli/src/com/android/tools/lint/Main.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lint/cli/src/com/android/tools/lint/Main.java b/lint/cli/src/com/android/tools/lint/Main.java index f0cbf8b..8ca3c50 100644 --- a/lint/cli/src/com/android/tools/lint/Main.java +++ b/lint/cli/src/com/android/tools/lint/Main.java @@ -41,6 +41,7 @@ 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.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.google.common.io.Closeables; import java.io.BufferedWriter; @@ -85,6 +86,8 @@ public class Main extends LintClient { private static final String ARG_URL = "--url"; //$NON-NLS-1$ private static final String ARG_VERSION = "--version"; //$NON-NLS-1$ private static final String ARG_EXITCODE = "--exitcode"; //$NON-NLS-1$ + private static final String ARG_CLASSES = "--classes"; //$NON-NLS-1$ + private static final String ARG_SOURCES = "--sources"; //$NON-NLS-1$ private static final String ARG_NOWARN2 = "--nowarn"; //$NON-NLS-1$ // GCC style flag names for options @@ -118,6 +121,8 @@ public class Main extends LintClient { private boolean mWarnAll; private boolean mNoWarnings; private boolean mAllErrors; + private List<File> mSources; + private List<File> mClasses; private Configuration mDefaultConfiguration; private IssueRegistry mRegistry; @@ -456,6 +461,34 @@ public class Main extends LintClient { mWarnAll = true; } else if (arg.equals(ARG_ALLERROR)) { mAllErrors = true; + } else if (arg.equals(ARG_CLASSES)) { + if (index == args.length - 1) { + System.err.println("Missing class folder name"); + System.exit(ERRNO_INVALIDARGS); + } + File input = getInArgumentPath(args[++index]); + if (!input.exists()) { + System.err.println("Source folder " + input + " does not exist."); + System.exit(ERRNO_INVALIDARGS); + } + if (mClasses == null) { + mClasses = new ArrayList<File>(); + } + mClasses.add(input); + } else if (arg.equals(ARG_SOURCES)) { + if (index == args.length - 1) { + System.err.println("Missing source folder name"); + System.exit(ERRNO_INVALIDARGS); + } + File input = getInArgumentPath(args[++index]); + if (!input.exists()) { + System.err.println("Source folder " + input + " does not exist."); + System.exit(ERRNO_INVALIDARGS); + } + if (mSources == null) { + mSources = new ArrayList<File>(); + } + mSources.add(input); } else if (arg.startsWith("--")) { System.err.println("Invalid argument " + arg + "\n"); printUsage(System.err); @@ -475,6 +508,10 @@ public class Main extends LintClient { if (files.size() == 0) { System.err.println("No files to analyze."); System.exit(ERRNO_INVALIDARGS); + } else if (files.size() > 1 && (mClasses != null || mSources != null)) { + System.err.println("The " + ARG_SOURCES + " and " + ARG_CLASSES + + " can only be used with a single project"); + System.exit(ERRNO_INVALIDARGS); } if (mReporters.isEmpty()) { @@ -905,6 +942,12 @@ public class Main extends LintClient { ARG_SIMPLEHTML + " <filename>", "Create a simple HTML report", ARG_XML + " <filename>", "Create an XML report instead.", + "", "\nProject Options:", + ARG_SOURCES + " <dir>", "Add the given folder as a source directory for the " + + "project. Only valid when running lint on a single project.", + ARG_CLASSES + " <dir>", "Add the given folder (or jar file) as a class directory " + + "for the project. Only valid when running lint on a single project.", + "", "\nExit Status:", "0", "Success.", Integer.toString(ERRNO_ERRORS), "Lint errors detected.", @@ -1131,6 +1174,45 @@ public class Main extends LintClient { return mCheck != null; } + private Map<Project, ClassPathInfo> mProjectInfo; + + @Override + @NonNull + protected ClassPathInfo getClassPath(@NonNull Project project) { + ClassPathInfo classPath = super.getClassPath(project); + + if (mClasses == null && mSources == null) { + return classPath; + } + + ClassPathInfo info; + if (mProjectInfo == null) { + mProjectInfo = Maps.newHashMap(); + info = null; + } else { + info = mProjectInfo.get(project); + } + + if (info == null) { + List<File> sources; + if (mSources != null) { + sources = mSources; + } else { + sources = classPath.getSourceFolders(); + } + List<File> classes; + if (mClasses != null) { + classes = mClasses; + } else { + classes = classPath.getClassFolders(); + } + info = new ClassPathInfo(sources, classes, classPath.getLibraries()); + mProjectInfo.put(project, info); + } + + return info; + } + /** * Consult the lint.xml file, but override with the --enable and --disable * flags supplied on the command line |