Skip to content

Update to Gradle 3.0, and update tests to new DSL #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,26 @@
apply plugin: 'java'

repositories {
google()
jcenter()
maven {
url "http://dl.bintray.com/android/android-tools"
}
}

ext {
lintVersion = '26.0.0-beta2'
}

dependencies {
compile 'com.android.tools.lint:lint-api:25.3.0'
compile 'com.android.tools.lint:lint-checks:25.3.0'
testCompile 'junit:junit:4.11'
testCompile 'com.android.tools.lint:lint:25.3.0'
testCompile 'com.android.tools.lint:lint-tests:25.3.0'
testCompile 'com.android.tools:testutils:25.3.0'
compile "com.android.tools.lint:lint-api:$lintVersion"
compile "com.android.tools.lint:lint-checks:$lintVersion"
testCompile "junit:junit:4.11"
testCompile "com.android.tools.lint:lint:$lintVersion"
testCompile "com.android.tools.lint:lint-tests:$lintVersion"
testCompile "com.android.tools:testutils:$lintVersion"
}

jar {
manifest {
attributes("Lint-Registry": "com.example.google.lint.MyIssueRegistry")
attributes("Lint-Registry-v2": "com.example.google.lint.MyIssueRegistry")
}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Aug 21 14:39:26 PDT 2015
#Wed Aug 09 14:33:29 PDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
156 changes: 67 additions & 89 deletions src/test/java/com/example/google/lint/MainActivityDetectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@

package com.example.google.lint;

import com.android.annotations.NonNull;
import com.android.tools.lint.checks.infrastructure.LintDetectorTest;
import com.android.tools.lint.client.api.LintClient;
import com.android.tools.lint.detector.api.Detector;
import com.android.tools.lint.detector.api.Issue;
import com.android.tools.lint.detector.api.Project;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static com.android.SdkConstants.FN_ANDROID_MANIFEST_XML;

Expand All @@ -35,11 +30,6 @@
* to adjust your code for the next tools release.</b>
*/
public class MainActivityDetectorTest extends LintDetectorTest {
/**
* The set of enabled issues for a given test.
*/
private Set<Issue> mEnabled = new HashSet<Issue>();

@Override
protected Detector getDetector() {
return new MainActivityDetector();
Expand All @@ -50,103 +40,91 @@ protected List<Issue> getIssues() {
return Collections.singletonList(MainActivityDetector.ISSUE);
}

/**
* Gets the configuration for the test.
* Each test can have a set of enabled issues by assigning the member field {@link #mEnabled}.
*/
@Override
protected TestConfiguration getConfiguration(LintClient client, Project project) {
return new TestConfiguration(client, project, null) {
@Override
public boolean isEnabled(@NonNull Issue issue) {
return super.isEnabled(issue) && mEnabled.contains(issue);
}
};
}

/**
* Test that a manifest with an activity with a launcher intent has no warnings.
*/
public void testHasMainActivity() throws Exception {
mEnabled = Collections.singleton(MainActivityDetector.ISSUE);
String expected = "No warnings.";
String result = lintProject(xml(FN_ANDROID_MANIFEST_XML, "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<manifest package=\"com.example.android.custom-lint-rules\"\n" +
" xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
" <application>\n" +
" <activity android:name=\"com.example.android.custom-lint-rules" +
".OtherActivity\">\n" +
" </activity>\n" +
"\n" +
" <activity android:name=\"com.example.android.custom-lint-rules" +
".MainActivity\">\n" +
" <intent-filter>\n" +
" <action android:name=\"android.intent.action.MAIN\"/>\n" +
" <category android:name=\"android.intent.category.LAUNCHER\"/>\n" +
" </intent-filter>\n" +
" </activity>\n" +
" </application>\n" +
"</manifest>"));
assertEquals(expected, result);
public void testHasMainActivity() {
lint().files(
xml(FN_ANDROID_MANIFEST_XML, "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<manifest package=\"com.example.android.custom-lint-rules\"\n" +
" xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
" <application>\n" +
" <activity android:name=\"com.example.android.custom-lint-rules" +
".OtherActivity\">\n" +
" </activity>\n" +
"\n" +
" <activity android:name=\"com.example.android.custom-lint-rules" +
".MainActivity\">\n" +
" <intent-filter>\n" +
" <action android:name=\"android.intent.action.MAIN\"/>\n" +
" <category android:name=\"android.intent.category.LAUNCHER\"/>\n" +
" </intent-filter>\n" +
" </activity>\n" +
" </application>\n" +
"</manifest>"))
.run()
.expectClean();
}

/**
* Test that a manifest <em>without</em> an activity with a launcher intent reports an error.
*/
public void testMissingMainActivity() throws Exception {
mEnabled = Collections.singleton(MainActivityDetector.ISSUE);
public void testMissingMainActivity() {
String expected = "AndroidManifest.xml: Error: Expecting AndroidManifest.xml to have an " +
"activity with a launcher intent. [MainActivityDetector]\n" +
"1 errors, 0 warnings\n";
String result = lintProject(xml(FN_ANDROID_MANIFEST_XML, "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<manifest package=\"com.example.android.custom-lint-rules\"\n" +
" xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
" <application>\n" +
" <activity android:name=\"com.example.android.custom-lint-rules" +
".Activity1\">\n" +
" <intent-filter>\n" +
" <action android:name=\"android.intent.action.VIEW\" />\n" +
"\n" +
" <category android:name=\"android.intent.category.HOME\" />\n" +
" <category android:name=\"android.intent.category.LAUNCHER\" />\n" +
" <category android:name=\"android.intent.category.DEFAULT\" />\n" +
" <category android:name=\"android.intent.category.BROWSABLE\" " +
"/>\n" +
" </intent-filter>\n" +
" </activity>\n" +
"\n" +
" <activity android:name=\"com.example.android.custom-lint-rules" +
".Activity2\">\n" +
" </activity>\n" +
"\n" +
" <activity android:name=\"com.example.android.custom-lint-rules" +
".Activity3\">\n" +
" <intent-filter>\n" +
" <action android:name=\"android.intent.action.SEND\"/>\n" +
" <category android:name=\"android.intent.category.DEFAULT\"/>\n" +
" <data android:mimeType=\"text/plain\"/>\n" +
" </intent-filter>\n" +
" </activity>\n" +
" </application>\n" +
"</manifest>"));
assertEquals(expected, result);
lint().files(
xml(FN_ANDROID_MANIFEST_XML, "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<manifest package=\"com.example.android.custom-lint-rules\"\n" +
" xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
" <application>\n" +
" <activity android:name=\"com.example.android.custom-lint-rules" +
".Activity1\">\n" +
" <intent-filter>\n" +
" <action android:name=\"android.intent.action.VIEW\" />\n" +
"\n" +
" <category android:name=\"android.intent.category.HOME\" />\n" +
" <category android:name=\"android.intent.category.LAUNCHER\" />\n" +
" <category android:name=\"android.intent.category.DEFAULT\" />\n" +
" <category android:name=\"android.intent.category.BROWSABLE\" " +
"/>\n" +
" </intent-filter>\n" +
" </activity>\n" +
"\n" +
" <activity android:name=\"com.example.android.custom-lint-rules" +
".Activity2\">\n" +
" </activity>\n" +
"\n" +
" <activity android:name=\"com.example.android.custom-lint-rules" +
".Activity3\">\n" +
" <intent-filter>\n" +
" <action android:name=\"android.intent.action.SEND\"/>\n" +
" <category android:name=\"android.intent.category.DEFAULT\"/>\n" +
" <data android:mimeType=\"text/plain\"/>\n" +
" </intent-filter>\n" +
" </activity>\n" +
" </application>\n" +
"</manifest>"))
.run()
.expect(expected);
}

/**
* Test that a manifest without an <code>&lt;application&gt;</code> tag reports an error.
*/
public void testMissingApplication() throws Exception {
mEnabled = Collections.singleton(MainActivityDetector.ISSUE);
public void testMissingApplication() {
String expected = "AndroidManifest.xml: Error: Expecting AndroidManifest.xml to have an " +
"<activity> tag. [MainActivityDetector]\n" +
"1 errors, 0 warnings\n";
String result = lintProject(xml(FN_ANDROID_MANIFEST_XML, "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<manifest package=\"com.example.android.custom-lint-rules\"\n" +
" xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
"</manifest>"));
assertEquals(expected, result);
lint().files(
xml(FN_ANDROID_MANIFEST_XML, "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<manifest package=\"com.example.android.custom-lint-rules\"\n" +
" xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
"</manifest>"))
.run()
.expect(expected);
}
}