Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Spotless #316

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import io.sdkman.vendors.tasks.SdkmanVendorBaseTask
import java.net.URI

plugins {
id("profiler.java-library")
groovy
id("profiler.java-library")
application
`maven-publish`
id("profiler.publication")
Expand Down
6 changes: 6 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ plugins {
repositories {
jcenter()
}

dependencies {
implementation("com.diffplug.spotless:spotless-plugin-gradle:5.9.0") {
exclude(group = "org.codehaus.groovy", module = "groovy-xml")
}
}
14 changes: 14 additions & 0 deletions buildSrc/src/main/kotlin/profiler.java-library.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("java-library")
id("com.diffplug.spotless")
}

repositories {
Expand All @@ -15,6 +16,19 @@ java {
}
}

spotless {
java {
googleJavaFormat("1.8").aosp()
importOrder("", "javax", "java", "\\#")
removeUnusedImports()
}
pluginManager.withPlugin("groovy") {
groovy {
importOrder("", "groovy", "javax", "java", "\\#")
}
}
}

project.extensions.create<Versions>("versions")

abstract class Versions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,29 @@

public class AdhocGradleScenarioDefinition extends GradleScenarioDefinition {
public AdhocGradleScenarioDefinition(
GradleBuildConfiguration version,
GradleBuildInvoker invoker,
BuildAction buildAction,
Map<String, String> systemProperties,
int warmUpCount,
int buildCount,
File outputDir,
List<String> measuredBuildOperations
) {
GradleBuildConfiguration version,
GradleBuildInvoker invoker,
BuildAction buildAction,
Map<String, String> systemProperties,
int warmUpCount,
int buildCount,
File outputDir,
List<String> measuredBuildOperations) {
super(
"default",
null,
invoker,
version,
buildAction,
BuildAction.NO_OP,
Collections.emptyList(),
systemProperties,
Collections.emptyList(),
warmUpCount,
buildCount,
outputDir,
Collections.emptyList(),
measuredBuildOperations
);
"default",
null,
invoker,
version,
buildAction,
BuildAction.NO_OP,
Collections.emptyList(),
systemProperties,
Collections.emptyList(),
warmUpCount,
buildCount,
outputDir,
Collections.emptyList(),
measuredBuildOperations);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
import java.time.Duration;
import java.util.List;

/**
* A mock-up of Android studio sync.
*/
/** A mock-up of Android studio sync. */
public class AndroidStudioSyncAction implements BuildAction {
public AndroidStudioSyncAction() {
}
public AndroidStudioSyncAction() {}

@Override
public String getShortDisplayName() {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/gradle/profiler/ArgumentsSplitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
public class ArgumentsSplitter {

/**
* Splits the arguments string (for example, a program command line) into a collection.
* Only supports space-delimited and/or quoted command line arguments. This currently does not handle escaping characters such as quotes.
* Splits the arguments string (for example, a program command line) into a collection. Only
* supports space-delimited and/or quoted command line arguments. This currently does not handle
* escaping characters such as quotes.
*
* @param arguments the arguments, for example command line args.
* @return separate command line arguments.
Expand Down
28 changes: 18 additions & 10 deletions src/main/java/org/gradle/profiler/BazelScenarioDefinition.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package org.gradle.profiler;

import javax.annotation.Nullable;

import java.io.File;
import java.util.List;

public class BazelScenarioDefinition extends BuildToolCommandLineScenarioDefinition {
public BazelScenarioDefinition(
String scenarioName,
@Nullable String title,
List<String> targets,
List<BuildMutator> buildMutators,
int warmUpCount,
int buildCount,
File outputDir,
@Nullable File bazelHome
) {
super(scenarioName, title, targets, buildMutators, warmUpCount, buildCount, outputDir, bazelHome);
String scenarioName,
@Nullable String title,
List<String> targets,
List<BuildMutator> buildMutators,
int warmUpCount,
int buildCount,
File outputDir,
@Nullable File bazelHome) {
super(
scenarioName,
title,
targets,
buildMutators,
warmUpCount,
buildCount,
outputDir,
bazelHome);
}

@Override
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/gradle/profiler/BazelScenarioInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import java.util.List;
import java.util.function.Consumer;

public class BazelScenarioInvoker extends BuildToolCommandLineInvoker<BazelScenarioDefinition, BuildInvocationResult> {
public class BazelScenarioInvoker
extends BuildToolCommandLineInvoker<BazelScenarioDefinition, BuildInvocationResult> {
@Override
void doRun(BazelScenarioDefinition scenario, InvocationSettings settings, Consumer<BuildInvocationResult> resultConsumer) {
void doRun(
BazelScenarioDefinition scenario,
InvocationSettings settings,
Consumer<BuildInvocationResult> resultConsumer) {
List<String> targets = scenario.getTargets();

List<String> commandLine = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public BenchmarkResultCollector(AbstractGenerator... generators) {
this.generators = Arrays.asList(generators);
}

public <S extends ScenarioDefinition, T extends BuildInvocationResult> Consumer<T> scenario(S scenario, List<Sample<? super T>> samples) {
public <S extends ScenarioDefinition, T extends BuildInvocationResult> Consumer<T> scenario(
S scenario, List<Sample<? super T>> samples) {
BuildScenarioResultImpl<T> buildScenario = new BuildScenarioResultImpl<>(scenario, samples);
allBuilds.add(buildScenario);
return buildScenario;
Expand All @@ -32,9 +33,7 @@ public void write(InvocationSettings settings) throws IOException {
}
}

/**
* Summarize the results for the user.
*/
/** Summarize the results for the user. */
public void summarizeResults(Consumer<String> consumer) {
for (AbstractGenerator generator : generators) {
generator.summarizeResults(consumer);
Expand Down
30 changes: 19 additions & 11 deletions src/main/java/org/gradle/profiler/BuckScenarioDefinition.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.gradle.profiler;

import javax.annotation.Nullable;

import java.io.File;
import java.io.PrintStream;
import java.util.List;
Expand All @@ -9,17 +10,24 @@ public class BuckScenarioDefinition extends BuildToolCommandLineScenarioDefiniti
private final String type;

public BuckScenarioDefinition(
String scenarioName,
@Nullable String title,
List<String> targets,
String type,
List<BuildMutator> buildMutators,
int warmUpCount,
int buildCount,
File outputDir,
@Nullable File buckHome
) {
super(scenarioName, title, targets, buildMutators, warmUpCount, buildCount, outputDir, buckHome);
String scenarioName,
@Nullable String title,
List<String> targets,
String type,
List<BuildMutator> buildMutators,
int warmUpCount,
int buildCount,
File outputDir,
@Nullable File buckHome) {
super(
scenarioName,
title,
targets,
buildMutators,
warmUpCount,
buildCount,
outputDir,
buckHome);
this.type = type;
}

Expand Down
18 changes: 14 additions & 4 deletions src/main/java/org/gradle/profiler/BuckScenarioInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

public class BuckScenarioInvoker extends BuildToolCommandLineInvoker<BuckScenarioDefinition, BuildInvocationResult> {
public class BuckScenarioInvoker
extends BuildToolCommandLineInvoker<BuckScenarioDefinition, BuildInvocationResult> {
@Override
void doRun(BuckScenarioDefinition scenario, InvocationSettings settings, Consumer<BuildInvocationResult> resultConsumer) {
void doRun(
BuckScenarioDefinition scenario,
InvocationSettings settings,
Consumer<BuildInvocationResult> resultConsumer) {
String buckwExe = settings.getProjectDir() + "/buckw";
List<String> targets = new ArrayList<>(scenario.getTargets());
if (scenario.getType() != null) {
Expand All @@ -22,8 +26,14 @@ void doRun(BuckScenarioDefinition scenario, InvocationSettings settings, Consume
commandLine.add("--type");
commandLine.add(scenario.getType());
}
String output = new CommandExec().inDir(settings.getProjectDir()).runAndCollectOutput(commandLine);
targets.addAll(Arrays.stream(output.split("\\n")).filter(s -> s.matches("//\\w+.*")).collect(Collectors.toList()));
String output =
new CommandExec()
.inDir(settings.getProjectDir())
.runAndCollectOutput(commandLine);
targets.addAll(
Arrays.stream(output.split("\\n"))
.filter(s -> s.matches("//\\w+.*"))
.collect(Collectors.toList()));
}

Logging.detailed().println("* Buck targets: " + targets);
Expand Down
60 changes: 27 additions & 33 deletions src/main/java/org/gradle/profiler/BuildAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,40 @@
import java.time.Duration;
import java.util.List;

/**
* Runs some particular action against a Gradle build.
*/
/** Runs some particular action against a Gradle build. */
public interface BuildAction {
BuildAction NO_OP = new BuildAction() {
@Override
public boolean isDoesSomething() {
return false;
}

@Override
public String getDisplayName() {
return "do nothing";
}

@Override
public String getShortDisplayName() {
return "nothing";
}

@Override
public Duration run(GradleClient gradleClient, List<String> gradleArgs, List<String> jvmArgs) {
return Duration.ZERO;
}
};
BuildAction NO_OP =
new BuildAction() {
@Override
public boolean isDoesSomething() {
return false;
}

@Override
public String getDisplayName() {
return "do nothing";
}

@Override
public String getShortDisplayName() {
return "nothing";
}

@Override
public Duration run(
GradleClient gradleClient, List<String> gradleArgs, List<String> jvmArgs) {
return Duration.ZERO;
}
};

boolean isDoesSomething();

/**
* A human consumable display name for this action.
*/
/** A human consumable display name for this action. */
String getDisplayName();

/**
* A human consumable display name for this action.
*/
/** A human consumable display name for this action. */
String getShortDisplayName();

/**
* Runs the work of this action and returns the result.
*/
/** Runs the work of this action and returns the result. */
Duration run(GradleClient gradleClient, List<String> gradleArgs, List<String> jvmArgs);
}
Loading