diff options
8 files changed, 119 insertions, 89 deletions
diff --git a/anttasks/src/com/android/ant/LintExecTask.java b/anttasks/src/com/android/ant/LintExecTask.java index 64a6c00..3d687cb 100644 --- a/anttasks/src/com/android/ant/LintExecTask.java +++ b/anttasks/src/com/android/ant/LintExecTask.java @@ -28,6 +28,8 @@ public class LintExecTask extends ExecTask { private String mExecutable; private String mHtml; private String mXml; + private Path mSourcePath; + private Path mClassPath; /** * Sets the value of the "executable" attribute. @@ -37,6 +39,16 @@ public class LintExecTask extends ExecTask { mExecutable = TaskHelper.checkSinglePath("executable", executable); } + /** Sets the path where Java source code should be found */ + public void setSrc(Path path) { + mSourcePath = path; + } + + /** Sets the path where class files should be found */ + public void setClasspath(Path path) { + mClassPath = path; + } + /** * Sets the value of the "html" attribute: a path to a file or directory name * where the HTML report should be written. @@ -80,6 +92,16 @@ public class LintExecTask extends ExecTask { task.createArg().setValue(mXml); } + if (mSourcePath != null) { + task.createArg().setValue("--sources"); + task.createArg().setValue(mSourcePath.toString()); + } + + if (mClassPath != null) { + task.createArg().setValue("--classpath"); + task.createArg().setValue(mClassPath.toString()); + } + task.createArg().setValue(getProject().getBaseDir().getAbsolutePath()); task.execute(); } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java index b34e7ed..d6ca12a 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java @@ -30,8 +30,6 @@ import com.android.sdklib.AndroidVersion; import com.android.sdklib.IAndroidTarget; import com.android.sdklib.repository.PkgProps; import com.android.util.XmlUtils; -import com.google.common.base.Splitter; -import com.google.common.collect.Iterables; import com.google.common.io.ByteStreams; import com.google.common.io.Closeables; @@ -981,41 +979,6 @@ public class AdtUtils { } /** - * Splits the given path into its individual parts, attempting to be - * tolerant about path separators (: or ;). It can handle possibly ambiguous - * paths, such as {@code c:\foo\bar:\other}, though of course these are to - * be avoided if possible. - * - * @param path the path variable to split, which can use both : and ; as - * path separators. - * @return the individual path components as an iterable of strings - */ - public static Iterable<String> splitPath(String path) { - if (path.indexOf(';') != -1) { - return Splitter.on(';').omitEmptyStrings().trimResults().split(path); - } - - List<String> combined = new ArrayList<String>(); - Iterables.addAll(combined, Splitter.on(':').omitEmptyStrings().trimResults().split(path)); - for (int i = 0, n = combined.size(); i < n; i++) { - String p = combined.get(i); - if (p.length() == 1 && i < n - 1 && Character.isLetter(p.charAt(0)) - // Technically, Windows paths do not have to have a \ after the :, - // which means it would be using the current directory on that drive, - // but that's unlikely to be the case in a path since it would have - // unpredictable results - && !combined.get(i+1).isEmpty() && combined.get(i+1).charAt(0) == '\\') { - combined.set(i, p + ':' + combined.get(i+1)); - combined.remove(i+1); - n--; - continue; - } - } - - return combined; - } - - /** * Reads the contents of an {@link IFile} and return it as a byte array * * @param file the file to be read diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ExportHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ExportHelper.java index 467602f..022857e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ExportHelper.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ExportHelper.java @@ -20,7 +20,6 @@ import static com.android.sdklib.internal.project.ProjectProperties.PROPERTY_SDK import com.android.ide.eclipse.adt.AdtConstants; import com.android.ide.eclipse.adt.AdtPlugin; -import com.android.ide.eclipse.adt.AdtUtils; import com.android.ide.eclipse.adt.AndroidPrintStream; import com.android.ide.eclipse.adt.internal.build.BuildHelper; import com.android.ide.eclipse.adt.internal.build.DexException; @@ -36,6 +35,7 @@ import com.android.sdklib.build.ApkCreationException; import com.android.sdklib.build.DuplicateFileException; import com.android.sdklib.internal.project.ProjectProperties; import com.android.sdklib.xml.AndroidManifest; +import com.android.tools.lint.detector.api.LintUtils; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -177,7 +177,7 @@ public final class ExportHelper { proguardConfig = proguardConfig.replace('/', File.separatorChar); } - Iterable<String> paths = AdtUtils.splitPath(proguardConfig); + Iterable<String> paths = LintUtils.splitPath(proguardConfig); for (String path : paths) { if (path.startsWith(SDK_PROPERTY_REF)) { path = AdtPrefs.getPrefs().getOsSdkFolder() + diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java index b2b6787..e0ebdbc 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java @@ -15,9 +15,6 @@ */ package com.android.ide.eclipse.adt; -import com.google.common.collect.Iterables; - -import java.util.Arrays; import java.util.Locale; import junit.framework.TestCase; @@ -148,31 +145,6 @@ public class AdtUtilsTest extends TestCase { assertEquals("Foo", AdtUtils.stripSuffix("Foo", "Bar")); } - public void testSplitPath() throws Exception { - assertTrue(Arrays.equals(new String[] { "/foo", "/bar", "/baz" }, - Iterables.toArray(AdtUtils.splitPath("/foo:/bar:/baz"), String.class))); - - assertTrue(Arrays.equals(new String[] { "/foo", "/bar" }, - Iterables.toArray(AdtUtils.splitPath("/foo;/bar"), String.class))); - - assertTrue(Arrays.equals(new String[] { "/foo", "/bar:baz" }, - Iterables.toArray(AdtUtils.splitPath("/foo;/bar:baz"), String.class))); - - assertTrue(Arrays.equals(new String[] { "\\foo\\bar", "\\bar\\foo" }, - Iterables.toArray(AdtUtils.splitPath("\\foo\\bar;\\bar\\foo"), String.class))); - - assertTrue(Arrays.equals(new String[] { "${sdk.dir}\\foo\\bar", "\\bar\\foo" }, - Iterables.toArray(AdtUtils.splitPath("${sdk.dir}\\foo\\bar;\\bar\\foo"), - String.class))); - - assertTrue(Arrays.equals(new String[] { "${sdk.dir}/foo/bar", "/bar/foo" }, - Iterables.toArray(AdtUtils.splitPath("${sdk.dir}/foo/bar:/bar/foo"), - String.class))); - - assertTrue(Arrays.equals(new String[] { "C:\\foo", "/bar" }, - Iterables.toArray(AdtUtils.splitPath("C:\\foo:/bar"), String.class))); - } - public void testFormatFloatValue() throws Exception { assertEquals("1", AdtUtils.formatFloatAttribute(1.0f)); assertEquals("2", AdtUtils.formatFloatAttribute(2.0f)); diff --git a/files/ant/build.xml b/files/ant/build.xml index 769889c..0c486e6 100644 --- a/files/ant/build.xml +++ b/files/ant/build.xml @@ -1295,7 +1295,9 @@ description="Runs lint on the project to look for potential bugs" > <lint executable="${lint}" html="${lint.out.html}" - xml="${lint.out.xml}" /> + xml="${lint.out.xml}" + src="${source.absolute.dir}:${gen.absolute.dir}" + classpath="${out.classes.absolute.dir}" /> </target> <!-- ******************************************************* --> diff --git a/lint/cli/src/com/android/tools/lint/Main.java b/lint/cli/src/com/android/tools/lint/Main.java index 8ca3c50..6cdb689 100644 --- a/lint/cli/src/com/android/tools/lint/Main.java +++ b/lint/cli/src/com/android/tools/lint/Main.java @@ -86,7 +86,7 @@ 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_CLASSES = "--classpath"; //$NON-NLS-1$ private static final String ARG_SOURCES = "--sources"; //$NON-NLS-1$ private static final String ARG_NOWARN2 = "--nowarn"; //$NON-NLS-1$ @@ -466,29 +466,35 @@ public class Main extends LintClient { 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>(); + String paths = args[++index]; + for (String path : LintUtils.splitPath(paths)) { + File input = getInArgumentPath(path); + if (!input.exists()) { + System.err.println("Class path entry " + input + " does not exist."); + System.exit(ERRNO_INVALIDARGS); + } + if (mClasses == null) { + mClasses = new ArrayList<File>(); + } + mClasses.add(input); } - 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>(); + String paths = args[++index]; + for (String path : LintUtils.splitPath(paths)) { + File input = getInArgumentPath(path); + 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); } - mSources.add(input); } else if (arg.startsWith("--")) { System.err.println("Invalid argument " + arg + "\n"); printUsage(System.err); @@ -943,10 +949,10 @@ public class Main extends LintClient { 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.", + ARG_SOURCES + " <dir>", "Add the given folder (or path) 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, or path) as a class " + + "directory for the project. Only valid when running lint on a single project.", "", "\nExit Status:", "0", "Success.", 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 ce64fe3..85995b1 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 @@ -30,6 +30,8 @@ import com.android.resources.ResourceType; import com.android.tools.lint.client.api.LintClient; import com.android.util.PositionXmlParser; import com.google.common.annotations.Beta; +import com.google.common.base.Splitter; +import com.google.common.collect.Iterables; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.AbstractInsnNode; @@ -324,6 +326,41 @@ public class LintUtils { } /** + * Splits the given path into its individual parts, attempting to be + * tolerant about path separators (: or ;). It can handle possibly ambiguous + * paths, such as {@code c:\foo\bar:\other}, though of course these are to + * be avoided if possible. + * + * @param path the path variable to split, which can use both : and ; as + * path separators. + * @return the individual path components as an iterable of strings + */ + public static Iterable<String> splitPath(String path) { + if (path.indexOf(';') != -1) { + return Splitter.on(';').omitEmptyStrings().trimResults().split(path); + } + + List<String> combined = new ArrayList<String>(); + Iterables.addAll(combined, Splitter.on(':').omitEmptyStrings().trimResults().split(path)); + for (int i = 0, n = combined.size(); i < n; i++) { + String p = combined.get(i); + if (p.length() == 1 && i < n - 1 && Character.isLetter(p.charAt(0)) + // Technically, Windows paths do not have to have a \ after the :, + // which means it would be using the current directory on that drive, + // but that's unlikely to be the case in a path since it would have + // unpredictable results + && !combined.get(i+1).isEmpty() && combined.get(i+1).charAt(0) == '\\') { + combined.set(i, p + ':' + combined.get(i+1)); + combined.remove(i+1); + n--; + continue; + } + } + + return combined; + } + + /** * Computes the shared parent among a set of files (which may be null). * * @param files the set of files to be checked diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/detector/api/LintUtilsTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/detector/api/LintUtilsTest.java index 4765f41..b1ee6d6 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/detector/api/LintUtilsTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/detector/api/LintUtilsTest.java @@ -16,7 +16,10 @@ package com.android.tools.lint.detector.api; +import static com.android.tools.lint.detector.api.LintUtils.splitPath; + import com.android.tools.lint.Main; +import com.google.common.collect.Iterables; import java.io.BufferedOutputStream; import java.io.File; @@ -92,6 +95,31 @@ public class LintUtilsTest extends TestCase { assertEquals(6, LintUtils.editDistance("radiobutton", "bitton")); } + public void testSplitPath() throws Exception { + assertTrue(Arrays.equals(new String[] { "/foo", "/bar", "/baz" }, + Iterables.toArray(splitPath("/foo:/bar:/baz"), String.class))); + + assertTrue(Arrays.equals(new String[] { "/foo", "/bar" }, + Iterables.toArray(splitPath("/foo;/bar"), String.class))); + + assertTrue(Arrays.equals(new String[] { "/foo", "/bar:baz" }, + Iterables.toArray(splitPath("/foo;/bar:baz"), String.class))); + + assertTrue(Arrays.equals(new String[] { "\\foo\\bar", "\\bar\\foo" }, + Iterables.toArray(splitPath("\\foo\\bar;\\bar\\foo"), String.class))); + + assertTrue(Arrays.equals(new String[] { "${sdk.dir}\\foo\\bar", "\\bar\\foo" }, + Iterables.toArray(splitPath("${sdk.dir}\\foo\\bar;\\bar\\foo"), + String.class))); + + assertTrue(Arrays.equals(new String[] { "${sdk.dir}/foo/bar", "/bar/foo" }, + Iterables.toArray(splitPath("${sdk.dir}/foo/bar:/bar/foo"), + String.class))); + + assertTrue(Arrays.equals(new String[] { "C:\\foo", "/bar" }, + Iterables.toArray(splitPath("C:\\foo:/bar"), String.class))); + } + public void testCommonParen1() { assertEquals(new File("/a"), (LintUtils.getCommonParent( new File("/a/b/c/d/e"), new File("/a/c")))); |