diff options
author | Xavier Ducrohet <xav@google.com> | 2012-03-01 17:43:59 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-03-01 17:43:59 -0800 |
commit | f49f01b5cc0ca90c6a87bcd634d34e19b0e2a071 (patch) | |
tree | 9261d280debe934aefac052729e28648f7287afa /lint/libs | |
parent | 84136806d31ef98df5f0ce2360c73e6818ef8d73 (diff) | |
parent | 04151c36bf1aad3b9b919930b79d1d7391bca9f1 (diff) | |
download | sdk-f49f01b5cc0ca90c6a87bcd634d34e19b0e2a071.zip sdk-f49f01b5cc0ca90c6a87bcd634d34e19b0e2a071.tar.gz sdk-f49f01b5cc0ca90c6a87bcd634d34e19b0e2a071.tar.bz2 |
Merge "Update lint custom view rule to reflect new res-auto namespace"
Diffstat (limited to 'lint/libs')
4 files changed, 46 insertions, 7 deletions
diff --git a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintConstants.java b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintConstants.java index 6788652..326326d 100644 --- a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintConstants.java +++ b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintConstants.java @@ -33,6 +33,9 @@ public class LintConstants { /** Namespace used in XML files for Android Tooling attributes */ public static final String TOOLS_URI = "http://schemas.android.com/tools"; //$NON-NLS-1$ + /** Namespace used for auto-adjusting namespaces */ + public final static String AUTO_URI = + "http://schemas.android.com/apk/res-auto"; //$NON-NLS-1$ /** Default prefix used for tools attributes */ public static final String TOOLS_PREFIX = "tools"; //$NON-NLS-1$ public static final String XMLNS_PREFIX = "xmlns:"; //$NON-NLS-1$ diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/NamespaceDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/NamespaceDetector.java index 60ae3a3..52c3763 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/NamespaceDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/NamespaceDetector.java @@ -18,6 +18,7 @@ package com.android.tools.lint.checks; import static com.android.tools.lint.detector.api.LintConstants.ANDROID_PKG_PREFIX; import static com.android.tools.lint.detector.api.LintConstants.ANDROID_URI; +import static com.android.tools.lint.detector.api.LintConstants.AUTO_URI; import static com.android.tools.lint.detector.api.LintConstants.XMLNS_PREFIX; import com.android.tools.lint.detector.api.Category; @@ -74,11 +75,13 @@ public class NamespaceDetector extends LayoutDetector { /** Using custom namespace attributes in a library project */ public static final Issue CUSTOMVIEW = Issue.create( "LibraryCustomView", //$NON-NLS-1$ - "Flags custom views in libraries, which currently do not work", + "Flags custom attributes in libraries, which must use the res-auto-namespace instead", - "Using a custom view in a library project (where the custom view " + - "requires XML attributes from a custom namespace) does not yet " + - "work.", + "When using a custom view with custom attributes in a library project, the layout " + + "must use the special namespace " + AUTO_URI + " instead of a URI which includes " + + "the library project's own package. This will be used to automatically adjust the " + + "namespace of the attributes when the library resources are merged into the " + + "application project.", Category.CORRECTNESS, 6, Severity.ERROR, @@ -190,8 +193,8 @@ public class NamespaceDetector extends LayoutDetector { if (uri != null && uri.length() > 0 && uri.startsWith(URI_PREFIX) && !uri.equals(ANDROID_URI)) { context.report(CUSTOMVIEW, attribute, context.getLocation(attribute), - "Using a custom namespace attributes in a library project does " + - "not yet work", null); + "When using a custom namespace attribute in a library project, " + + "use the namespace \"" + AUTO_URI + "\" instead.", null); } } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NamespaceDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NamespaceDetectorTest.java index 3570f5c..560db91 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NamespaceDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NamespaceDetectorTest.java @@ -27,7 +27,8 @@ public class NamespaceDetectorTest extends AbstractCheckTest { public void testCustom() throws Exception { assertEquals( - "customview.xml:16: Error: Using a custom namespace attributes in a library project does not yet work", + "customview.xml:16: Error: When using a custom namespace attribute in a library " + + "project, use the namespace \"http://schemas.android.com/apk/res-auto\" instead.", lintProject( "multiproject/library-manifest.xml=>AndroidManifest.xml", @@ -51,6 +52,18 @@ public class NamespaceDetectorTest extends AbstractCheckTest { )); } + public void testCustomOk2() throws Exception { + assertEquals( + "No warnings.", + + lintProject( + "multiproject/library-manifest.xml=>AndroidManifest.xml", + "multiproject/library.properties=>project.properties", + // This project already uses the res-auto package + "res/layout/customview2.xml" + )); + } + public void testTypo() throws Exception { assertEquals( "wrong_namespace.xml:2: Warning: Unexpected namespace URI bound to the " + diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/layout/customview2.xml b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/layout/customview2.xml new file mode 100644 index 0000000..fcd43e6 --- /dev/null +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/layout/customview2.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + xmlns:other="http://schemas.foo.bar.com/other" + xmlns:foo="http://schemas.android.com/apk/res-auto" + android:id="@+id/newlinear" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + + <foo.bar.Baz + android:id="@+id/button1" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Button1" + foo:misc="Custom attribute" + tools:ignore="HardcodedText" > + </foo.bar.Baz> + +</LinearLayout> |