Skip to content

Commit

Permalink
Merge pull request #4 from StringCare/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
efraespada authored Jan 24, 2018
2 parents a4d3567 + 738bb74 commit fae371c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ root_project/build.gradle
buildscript {
ext {
stringcare_version = '0.4'
stringcare_version = '0.5'
}
repositories {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ apply plugin: 'java'
apply plugin: 'com.jfrog.bintray'

group 'com.stringcare'
version '0.4'
version '0.5'

sourceCompatibility = 1.8

Expand Down
3 changes: 2 additions & 1 deletion src/main/groovy/CredentialUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ private static void parseTrace(String module, String variant, String line, boole
until = key;
}
} else if (debug){
PrintUtils.print(module, "Variant:" + variant, true);
PrintUtils.print(module, "Module: " + module, true);
PrintUtils.print(module, "Variant: " + variant, true);
}

} else if (line.toLowerCase().contains("sha") && moduleLocated && variantLocated) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/groovy/GradleHandlerCallback.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

public interface GradleHandlerCallback {

boolean debug();

void onDataFound(String module, String variant);

void onMergeResourcesStarts(String module, String variant);
Expand Down
1 change: 1 addition & 0 deletions src/main/groovy/PrintUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static void init(String module, String variant) {
public static void print(String message) {
print(message, false);
}

public static void print(String message, boolean tab) {
if (variant != null && module != null) {
if (!tab) {
Expand Down
8 changes: 7 additions & 1 deletion src/main/groovy/StringCarePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ class StringCare implements Plugin<Project> {
}
}
}
this.project.gradle.addBuildListener(new TimingRecorder(this, new GradleHandlerCallback() {
this.project.gradle.addBuildListener(new TListener(this, new GradleHandlerCallback() {

@Override
boolean debug() {
return debug
}

@Override
void onDataFound(String module, String variant) {
// nothing to do here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Timing {
}
}

class TimingRecorder extends BuildAndTaskExecutionListenerAdapter implements TaskExecutionListener {
class TListener extends BuildAndTaskExecutionListenerAdapter implements TaskExecutionListener {
private ClockT clock
private List<Timing> timings = []
private StringCare plugin
Expand All @@ -32,7 +32,7 @@ class TimingRecorder extends BuildAndTaskExecutionListenerAdapter implements Tas
private static final String MERGE = "merge";
private static final String RESOURCES = "Resources";

TimingRecorder(StringCare plugin, GradleHandlerCallback callback) {
TListener(StringCare plugin, GradleHandlerCallback callback) {
this.plugin = plugin
this.callback = callback
}
Expand All @@ -41,16 +41,31 @@ class TimingRecorder extends BuildAndTaskExecutionListenerAdapter implements Tas
void beforeExecute(Task task) {
clock = new ClockT()
if (task.name.contains(PRE) && task.name.contains(BUILD) && !task.name.equals(PRE + BUILD) && !task.name.contains(TEST)) {
callback.onDataFound(task.project.name, PrintUtils.uncapitalize(task.name.substring(PRE.length()).substring(0, task.name.substring(PRE.length()).length() - BUILD.length())));
String module = getName(task)
if (module != null) {
callback.onDataFound(module, PrintUtils.uncapitalize(task.name.substring(PRE.length()).substring(0, task.name.substring(PRE.length()).length() - BUILD.length())));
}
} else if (task.name.contains(MERGE) && task.name.contains(RESOURCES) && !task.name.contains(TEST)) {
callback.onMergeResourcesStarts(task.project.name, PrintUtils.uncapitalize(task.name.substring(MERGE.length()).substring(0, task.name.substring(MERGE.length()).length() - RESOURCES.length())));
String module = getName(task)
if (module != null) {
if (callback.debug()) {
// PrintUtils.print(module, "Module: " + module, true)
}
callback.onMergeResourcesStarts(module, PrintUtils.uncapitalize(task.name.substring(MERGE.length()).substring(0, task.name.substring(MERGE.length()).length() - RESOURCES.length())));

} else {
PrintUtils.print("not_needed", "🤖 module path not found, report an issue", true)
}
}
}

@Override
void afterExecute(Task task, TaskState taskState) {
if (task.name.contains(MERGE) && task.name.contains(RESOURCES) && !task.name.contains(TEST)) {
callback.onMergeResourcesFinish(task.project.name, PrintUtils.uncapitalize(task.name.substring(MERGE.length()).substring(0, task.name.substring(MERGE.length()).length() - RESOURCES.length())));
String module = getName(task)
if (module != null) {
callback.onMergeResourcesFinish(module, PrintUtils.uncapitalize(task.name.substring(MERGE.length()).substring(0, task.name.substring(MERGE.length()).length() - RESOURCES.length())));
}
}
timings << new Timing(
clock.getTimeInMs(),
Expand All @@ -73,4 +88,10 @@ class TimingRecorder extends BuildAndTaskExecutionListenerAdapter implements Tas
Timing getTiming(String path) {
timings.find { it.path == path }
}

String getName(Task task) {
String path = task.project.getPath()
return path == null || path.length() == 0 ? null : path.split(":")[path.split(":").length - 1]
}

}

0 comments on commit fae371c

Please sign in to comment.