From bcc085b585e1edd559574700e636c9dfd0e52298 Mon Sep 17 00:00:00 2001 From: Stefan Wolf Date: Wed, 5 Feb 2020 10:08:11 +0100 Subject: [PATCH 1/2] Remove imports for shaded GradleApi classes Those will not work at runtime. --- .../gradle/profiler/AndroidStudioSyncAction.java | 16 ++++++++++++---- .../profiler/jfr/JfrToStacksConverter.java | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gradle/profiler/AndroidStudioSyncAction.java b/src/main/java/org/gradle/profiler/AndroidStudioSyncAction.java index 521de590..994a85d2 100644 --- a/src/main/java/org/gradle/profiler/AndroidStudioSyncAction.java +++ b/src/main/java/org/gradle/profiler/AndroidStudioSyncAction.java @@ -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. @@ -51,12 +53,18 @@ public void run(GradleInvoker buildInvoker, List gradleArgs, List 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 diff --git a/src/main/java/org/gradle/profiler/jfr/JfrToStacksConverter.java b/src/main/java/org/gradle/profiler/jfr/JfrToStacksConverter.java index 8f9b8762..df87a637 100644 --- a/src/main/java/org/gradle/profiler/jfr/JfrToStacksConverter.java +++ b/src/main/java/org/gradle/profiler/jfr/JfrToStacksConverter.java @@ -2,7 +2,6 @@ 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; @@ -23,6 +22,7 @@ import java.io.BufferedWriter; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; @@ -54,7 +54,7 @@ private Map foldStacks(IItemCollection recording, Options options) private void writeFoldedStacks(Map foldedStacks, File targetFile) { targetFile.getParentFile().mkdirs(); - try (BufferedWriter writer = Files.newWriter(targetFile, Charsets.UTF_8)) { + try (BufferedWriter writer = Files.newWriter(targetFile, StandardCharsets.UTF_8)) { for (Map.Entry entry : foldedStacks.entrySet()) { writer.write(String.format("%s %d%n", entry.getKey(), entry.getValue())); } From 1c3b9546be688e901baa69a83fc808955dc4405a Mon Sep 17 00:00:00 2001 From: Stefan Wolf Date: Wed, 5 Feb 2020 10:13:54 +0100 Subject: [PATCH 2/2] Use more java.nio instead of Guava --- ...DefaultGradleBuildConfigurationReader.java | 6 ++--- .../flamegraph/FlameGraphSanitizer.java | 26 +++++++++++++------ .../profiler/jfr/JfrToStacksConverter.java | 4 +-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/gradle/profiler/DefaultGradleBuildConfigurationReader.java b/src/main/java/org/gradle/profiler/DefaultGradleBuildConfigurationReader.java index 7168b296..2c99f5ad 100644 --- a/src/main/java/org/gradle/profiler/DefaultGradleBuildConfigurationReader.java +++ b/src/main/java/org/gradle/profiler/DefaultGradleBuildConfigurationReader.java @@ -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; @@ -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; @@ -97,7 +97,7 @@ private GradleConnector connector() { private List 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); } diff --git a/src/main/java/org/gradle/profiler/flamegraph/FlameGraphSanitizer.java b/src/main/java/org/gradle/profiler/flamegraph/FlameGraphSanitizer.java index 288f845f..ed8ac194 100644 --- a/src/main/java/org/gradle/profiler/flamegraph/FlameGraphSanitizer.java +++ b/src/main/java/org/gradle/profiler/flamegraph/FlameGraphSanitizer.java @@ -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. */ @@ -112,7 +122,7 @@ public List map(List stack) { private static abstract class FrameWiseSanitizeFunction implements SanitizeFunction { @Override public final List map(List stack) { - List result = Lists.newArrayListWithCapacity(stack.size()); + List result = new ArrayList<>(stack.size()); for (String frame : stack) { result.add(mapFrame(frame)); } @@ -170,7 +180,7 @@ protected String mapFrame(String frame) { private static class CollapseDuplicateFrames implements SanitizeFunction { @Override public List map(List stack) { - List result = Lists.newArrayList(stack); + List result = new ArrayList<>(stack); ListIterator iterator = result.listIterator(); String previous = null; while (iterator.hasNext()) { diff --git a/src/main/java/org/gradle/profiler/jfr/JfrToStacksConverter.java b/src/main/java/org/gradle/profiler/jfr/JfrToStacksConverter.java index df87a637..dbf82e1c 100644 --- a/src/main/java/org/gradle/profiler/jfr/JfrToStacksConverter.java +++ b/src/main/java/org/gradle/profiler/jfr/JfrToStacksConverter.java @@ -1,7 +1,6 @@ package org.gradle.profiler.jfr; import com.google.common.collect.ImmutableSet; -import com.google.common.io.Files; import org.openjdk.jmc.common.IMCFrame; import org.openjdk.jmc.common.IMCStackTrace; import org.openjdk.jmc.common.item.IItem; @@ -23,6 +22,7 @@ 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; @@ -54,7 +54,7 @@ private Map foldStacks(IItemCollection recording, Options options) private void writeFoldedStacks(Map foldedStacks, File targetFile) { targetFile.getParentFile().mkdirs(); - try (BufferedWriter writer = Files.newWriter(targetFile, StandardCharsets.UTF_8)) { + try (BufferedWriter writer = Files.newBufferedWriter(targetFile.toPath(), StandardCharsets.UTF_8)) { for (Map.Entry entry : foldedStacks.entrySet()) { writer.write(String.format("%s %d%n", entry.getKey(), entry.getValue())); }