Skip to content

Commit

Permalink
v0.2.1. Filters and package-name are mandatory.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzaitsev committed Jul 21, 2019
1 parent 1029004 commit b48ec9a
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ before_deploy: # Create Archive
# - rm -fr build/classes/ # Uncomment line if used ant for buld
- mkdir build/jar
- ln build/libs/apk-dependency-graph.jar build/jar/apk-dependency-graph.jar
- zip -r apk-dependency-graph-scripts-$TRAVIS_TAG.zip build/ gui/ filters/ run.bat run.sh
- zip -r apk-dependency-graph-scripts-$TRAVIS_TAG.zip build/jar/apk-dependency-graph.jar gui/ filters/ run.bat run.sh
deploy:
provider: releases
api_key: $GITHUB_TOKEN # More options > Settings > Environment Variables
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Apk Dependency Graph (ADG)

[![Build Status](https://travis-ci.org/alexzaitsev/apk-dependency-graph.svg?branch=master)](https://travis-ci.org/alexzaitsev/apk-dependency-graph)
[![version](https://img.shields.io/badge/version-0.2.0-brightgreen.svg)](https://github.com/alexzaitsev/apk-dependency-graph/releases/tag/0.2.0) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-apk--dependency--graph-blue.svg?style=flat)](http://android-arsenal.com/details/1/4411)
[![version](https://img.shields.io/badge/version-0.2.1-brightgreen.svg)](https://github.com/alexzaitsev/apk-dependency-graph/releases/tag/0.2.1) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-apk--dependency--graph-blue.svg?style=flat)](http://android-arsenal.com/details/1/4411)

Class dependency visualizer. Only `apk` file is needed.
Class coupling is one of the significant code metrics that shows how easy is to change, maintain and test the code. This tool helps to view whole picture of the project.
Expand Down
10 changes: 7 additions & 3 deletions filters/instructions.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'default.json' is a default filterset that is shipped with the releases.

It consists of the next filters:
package-name - Java package to filter by, e.g. "com.mysite.myandroidapp". Empty by default.
show-inner-classes - If true it will contain inner class processing (the ones creating ClassName$InnerClass files). False by default.
package-name - Java package to filter by, e.g. "com.mysite.myandroidapp".
Mandatory. Empty by default.
ATTENTION: It's very important to use that option otherwise the graph contains
A LOT of Android and other dependencies and is almost unusable.
show-inner-classes - If true it will contain inner class processing (the ones creating ClassName$InnerClass files).
Optional. False by default.
ignored-classes - The list of regexps that will be applied to class names.
If class name matches any of provided regexps - it will be ignored.
By default it filters Dagger, ButterKnife, R and some generated classes.
Optional. By default it filters Dagger, ButterKnife, R and some generated classes.

You may extend this file or create a set of your own filter files for each project.

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/alex_zaitsev/adg/FilterProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ public FilterProvider(Filters inputFilters) {
}

public Filter<String> makePathFilter() {
if (inputFilters.getPackageName() == null || inputFilters.getPackageName().isEmpty()) {
return null;
}

String replacement = Matcher.quoteReplacement(File.separator);
replacement = Matcher.quoteReplacement(replacement);
String packageNameAsPath = inputFilters.getPackageName().replaceAll("\\.", replacement);
Expand All @@ -30,6 +26,10 @@ public Filter<String> makePathFilter() {

public Filter<String> makeClassFilter() {
String[] ignoredClasses = inputFilters.getIgnoredClasses();
if (ignoredClasses == null) {
return null;
}

InverseRegexFilter ignoredClassesFilter = new InverseRegexFilter(ignoredClasses);

return ignoredClassesFilter;
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/com/alex_zaitsev/adg/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@
public class Main {

public static void main(String[] args) {
// parse arguments
Arguments arguments = new ArgumentReader(args).read();
if (arguments == null) {
System.err.println("Arguments cannot be null!");
return;
}
Filters filters = arguments.getFiltersPath() == null ? null :
new FiltersReader(arguments.getFiltersPath()).read();
if (arguments.getFiltersPath() == null) {
System.err.println("Please specify path to filter.json file.");
return;
}
// parse filters
Filters filters = new FiltersReader(arguments.getFiltersPath()).read();
if (filters == null) {
return;
}

// Delete the output directory for a better decoding result.
if (FileUtils.deleteDir(arguments.getProjectPath())) {
Expand All @@ -34,8 +42,8 @@ public static void main(String[] args) {

// Analyze the decoded files and create the result file.
FilterProvider filterProvider = new FilterProvider(filters);
Filter<String> pathFilter = filters == null ? null : filterProvider.makePathFilter();
Filter<String> classFilter = filters == null ? null : filterProvider.makeClassFilter();
Filter<String> pathFilter = filterProvider.makePathFilter();
Filter<String> classFilter = filterProvider.makeClassFilter();
SmaliAnalyzer analyzer = new SmaliAnalyzer(arguments, filters,
pathFilter, classFilter);

Expand Down
17 changes: 11 additions & 6 deletions src/main/java/com/alex_zaitsev/adg/io/FiltersReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ public Filters read() {
showInnerClasses = Boolean.valueOf(rawParam.trim().split(":")[1].trim().replace("\"", ""));
}
}
String ignoredClasses = mainObject.substring(mainObject.indexOf('[') + 1, mainObject.lastIndexOf(']'));
ignoredClassesArr = ignoredClasses.split(",");
for (int i = 0; i < ignoredClassesArr.length; i++) {
ignoredClassesArr[i] = ignoredClassesArr[i].replace("\"", "").trim();
if (mainObject.contains(FILTER_IGNORED_CLASSES)) {
String ignoredClasses = mainObject.substring(mainObject.indexOf('[') + 1, mainObject.lastIndexOf(']'));
ignoredClassesArr = ignoredClasses.split(",");
for (int i = 0; i < ignoredClassesArr.length; i++) {
ignoredClassesArr[i] = ignoredClassesArr[i].replace("\"", "").trim();
}
}
} catch (Exception e) {
System.err.println("An error happened during " + filtersFilePath + " processing!");
Expand All @@ -49,12 +51,15 @@ public Filters read() {
}

if (packageName == null || packageName.isEmpty()) {
packageName = null;
System.out.println("Warning! Processing without package filter.");
System.err.println("'package-name' option cannot be empty. Check " + filtersFilePath);
return null;
}
if (showInnerClasses) {
System.out.println("Warning! Processing including inner classes.");
}
if (ignoredClassesArr == null) {
System.out.println("Warning! Processing without class filtering.");
}

return new Filters(packageName, showInnerClasses, ignoredClassesArr);
}
Expand Down
37 changes: 13 additions & 24 deletions src/test/java/FilterProviderTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,6 @@ public void setUp() throws IOException {
defaultFilters = new Filters(packageName, Filters.DEFAULT_PROCESS_INNER, ignoredClasses);
}

/**
* If package name is null, `makePathFilter` returns null.
*/
@Test
public void makePathFilterReturnsNullIfPackageNameIsNull() {
defaultFilters.setPackageName(null);
FilterProvider sut = new FilterProvider(defaultFilters);
Filter<String> filter = sut.makePathFilter();

assertThat(filter, nullValue());
}

/**
* If package name is empty, `makePathFilter` returns null.
*/
@Test
public void makePathFilterReturnsNullIfPackageNameIsEmpty() {
defaultFilters.setPackageName("");
FilterProvider sut = new FilterProvider(defaultFilters);
Filter<String> filter = sut.makePathFilter();

assertThat(filter, nullValue());
}

/**
* If provided filters are ok, `makePathFilter` returns expected Filter.
*/
Expand Down Expand Up @@ -86,6 +62,19 @@ public void makePathFilterReturnsFilterThatFiltersAsExpected() {
assertThat(filter.filter(wrongPath2), is(false));
}

/**
* If ignored classes option is null, `makeClassFilter` returns null.
*/
@Test
public void makeClassFilterReturnsNullIfIgnoredClassesAreNull() {
defaultFilters.setIgnoredClasses(null);
FilterProvider sut = new FilterProvider(defaultFilters);

Filter<String> filter = sut.makeClassFilter();

assertThat(filter, nullValue());
}

/**
* If provided filters are ok, `makeClassFilter` returns AndFilter with
* InverseRegexFilter and RegexFilter.
Expand Down
Loading

0 comments on commit b48ec9a

Please sign in to comment.