forked from orhanobut/logger
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kale
committed
Dec 26, 2016
1 parent
a0690ca
commit a010e57
Showing
16 changed files
with
209 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apply plugin: 'java' | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
|
||
compile 'com.android.tools.lint:lint-api:25.0.0' | ||
compile 'com.android.tools.lint:lint-checks:25.0.0' | ||
} | ||
|
||
sourceCompatibility = "1.7" | ||
targetCompatibility = "1.7" | ||
|
||
jar { | ||
manifest { | ||
attributes("Lint-Registry": "kale.log.lint.IssueRegister") | ||
} | ||
} | ||
|
||
configurations { | ||
lintJarOutput | ||
} | ||
|
||
dependencies { | ||
lintJarOutput files(jar) | ||
} | ||
|
||
defaultTasks 'assemble' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package kale.log.lint; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import com.android.tools.lint.client.api.IssueRegistry; | ||
import com.android.tools.lint.detector.api.Issue; | ||
|
||
/** | ||
* @author Kale | ||
* @date 2016/12/26 | ||
*/ | ||
public class IssueRegister extends IssueRegistry { | ||
|
||
@Override | ||
public List<Issue> getIssues() { | ||
return Collections.singletonList( | ||
LogDetector.ISSUE | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package kale.log.lint; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import com.android.tools.lint.client.api.JavaParser; | ||
import com.android.tools.lint.detector.api.Category; | ||
import com.android.tools.lint.detector.api.Detector; | ||
import com.android.tools.lint.detector.api.Implementation; | ||
import com.android.tools.lint.detector.api.Issue; | ||
import com.android.tools.lint.detector.api.JavaContext; | ||
import com.android.tools.lint.detector.api.Scope; | ||
import com.android.tools.lint.detector.api.Severity; | ||
|
||
import lombok.ast.AstVisitor; | ||
import lombok.ast.ForwardingAstVisitor; | ||
import lombok.ast.MethodInvocation; | ||
import lombok.ast.Node; | ||
|
||
/** | ||
* @author Kale | ||
* @date 2016/12/26 | ||
*/ | ||
public class LogDetector extends Detector implements Detector.JavaScanner { | ||
|
||
private static final String ISSUE_DESCRIPTION = "You should use our {AppLog}"; | ||
|
||
public static final Issue ISSUE = Issue.create( | ||
"LogUseError", | ||
"避免使用Log/System.out.println", | ||
"使用{AppLog},防止在正式包打印log", | ||
Category.SECURITY, | ||
5, | ||
Severity.ERROR, | ||
new Implementation(LogDetector.class, Scope.JAVA_FILE_SCOPE) | ||
); | ||
|
||
@Override | ||
public List<Class<? extends Node>> getApplicableNodeTypes() { | ||
return Collections.<Class<? extends Node>>singletonList(MethodInvocation.class); | ||
} | ||
|
||
@Override | ||
public AstVisitor createJavaVisitor(final JavaContext context) { | ||
return new ForwardingAstVisitor() { | ||
@Override | ||
public boolean visitMethodInvocation(MethodInvocation node) { | ||
|
||
if (node.toString().startsWith("System.out.println")) { | ||
context.report(ISSUE, node, context.getLocation(node), ISSUE_DESCRIPTION); | ||
return true; | ||
} | ||
|
||
JavaParser.ResolvedNode resolve = context.resolve(node); | ||
if (resolve instanceof JavaParser.ResolvedMethod) { | ||
JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) resolve; | ||
JavaParser.ResolvedClass containingClass = method.getContainingClass(); | ||
if (containingClass.matches("android.util.Log")) { | ||
context.report(ISSUE, node, context.getLocation(node), ISSUE_DESCRIPTION); | ||
return true; | ||
} | ||
} | ||
return super.visitMethodInvocation(node); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.0" | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 25 | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile 'com.android.support:appcompat-v7:25.1.0' | ||
} | ||
|
||
/** | ||
* rules for including "lint.jar" in aar | ||
*/ | ||
|
||
configurations { | ||
lintJarImport | ||
} | ||
dependencies { | ||
lintJarImport project(path: ":lint", configuration: "lintJarOutput") | ||
} | ||
task copyLintJar(type: Copy) { | ||
from(configurations.lintJarImport) { | ||
rename { | ||
String fileName -> | ||
'lint.jar' | ||
} | ||
} | ||
into 'build/intermediates/lint/' | ||
} | ||
|
||
project.afterEvaluate { | ||
def compileLintTask = project.tasks.find { it.name == 'compileLint' } | ||
compileLintTask.dependsOn(copyLintJar) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in H:\Android\Sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<manifest package="kale.log.lint" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application> | ||
|
||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">lintAar</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
82 changes: 0 additions & 82 deletions
82
logger/src/test/java/com.orhanobut.logger/SettingsTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
include ':app', ':logger' | ||
include ':app', ':logger', ':lint', ':lintaar' |