Skip to content

Commit

Permalink
Merge pull request #193 from gradle/wolfs/replace-impldep
Browse files Browse the repository at this point in the history
Remove shaded gradle API imports
  • Loading branch information
wolfs authored Feb 5, 2020
2 parents 85a8f14 + 1c3b954 commit 8be0f12
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
16 changes: 12 additions & 4 deletions src/main/java/org/gradle/profiler/AndroidStudioSyncAction.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.gradle.profiler;

import com.android.builder.model.AndroidProject;

import org.gradle.internal.impldep.org.apache.commons.lang.StringUtils;
import org.gradle.tooling.BuildController;
import org.gradle.tooling.events.ProgressListener;
import org.gradle.tooling.model.gradle.BasicGradleProject;
import org.gradle.tooling.model.gradle.GradleBuild;

import java.io.Serializable;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
* A mock-up of Android studio sync.
Expand Down Expand Up @@ -51,12 +53,18 @@ public void run(GradleInvoker buildInvoker, List<String> gradleArgs, List<String
if (skipSourceGeneration) {
tasks = Collections.emptyList();
} else {
String taskName = String.join("", "generate", StringUtils.capitalize(buildFlavor), "Sources");
String taskName = String.join("", "generate", capitalize(buildFlavor), "Sources");
tasks = Collections.singletonList(taskName);
}
buildInvoker.runToolingAction(tasks, gradleArgs, jvmArgs, new GetModel(), (builder) -> builder.addProgressListener(noOpListener()));
}

private static String capitalize(String input) {
return input.isEmpty()
? input
: Character.toUpperCase(input.charAt(0)) + input.substring(1);
}

private static ProgressListener noOpListener() {
return event -> {
// Ignore, just measure the impact of receiving the events
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.gradle.profiler;

import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.io.Files;
import org.gradle.tooling.GradleConnector;
import org.gradle.tooling.ProjectConnection;
import org.gradle.tooling.model.build.BuildEnvironment;
Expand All @@ -14,6 +12,8 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -97,7 +97,7 @@ private GradleConnector connector() {

private List<String> readBuildDetails() {
try {
return Files.readLines(buildDetails, Charsets.UTF_8);
return Files.readAllLines(buildDetails.toPath(), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException("Could not read the build's configuration.", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
package org.gradle.profiler.flamegraph;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;

import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;

import java.io.*;
import java.util.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;

/**
* Simplifies stacks to make flame graphs more readable.
*/
Expand Down Expand Up @@ -112,7 +122,7 @@ public List<String> map(List<String> stack) {
private static abstract class FrameWiseSanitizeFunction implements SanitizeFunction {
@Override
public final List<String> map(List<String> stack) {
List<String> result = Lists.newArrayListWithCapacity(stack.size());
List<String> result = new ArrayList<>(stack.size());
for (String frame : stack) {
result.add(mapFrame(frame));
}
Expand Down Expand Up @@ -170,7 +180,7 @@ protected String mapFrame(String frame) {
private static class CollapseDuplicateFrames implements SanitizeFunction {
@Override
public List<String> map(List<String> stack) {
List<String> result = Lists.newArrayList(stack);
List<String> result = new ArrayList<>(stack);
ListIterator<String> iterator = result.listIterator();
String previous = null;
while (iterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.gradle.profiler.jfr;

import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files;
import org.gradle.internal.impldep.com.google.common.base.Charsets;
import org.openjdk.jmc.common.IMCFrame;
import org.openjdk.jmc.common.IMCStackTrace;
import org.openjdk.jmc.common.item.IItem;
Expand All @@ -23,6 +21,8 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -54,7 +54,7 @@ private Map<String, Long> foldStacks(IItemCollection recording, Options options)

private void writeFoldedStacks(Map<String, Long> foldedStacks, File targetFile) {
targetFile.getParentFile().mkdirs();
try (BufferedWriter writer = Files.newWriter(targetFile, Charsets.UTF_8)) {
try (BufferedWriter writer = Files.newBufferedWriter(targetFile.toPath(), StandardCharsets.UTF_8)) {
for (Map.Entry<String, Long> entry : foldedStacks.entrySet()) {
writer.write(String.format("%s %d%n", entry.getKey(), entry.getValue()));
}
Expand Down

0 comments on commit 8be0f12

Please sign in to comment.