Skip to content

Commit

Permalink
more work on JavaDoc (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmck3516 authored Dec 10, 2023
1 parent c289a13 commit 0d0bf99
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 71 deletions.
51 changes: 0 additions & 51 deletions skippy-gradle/src/main/java/io/skippy/gradle/Profiler.java

This file was deleted.

10 changes: 7 additions & 3 deletions skippy-gradle/src/main/java/io/skippy/gradle/SkippyPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@
import org.gradle.api.tasks.SourceSetContainer;

/**
* Adds the {@code skippyClean} and {@code skippyAnalyze} tasks to a project.
* Adds Skippy support for Gradle:
* <ul>
* <li>Add the {@code skippyClean} and {@code skippyAnalyze} tasks if the build has been triggered "normally".</li>
* <li>If the build was triggered by the {@link AnalyzeTask} to capture coverage data for a skippified test,
* the plugin performs the necessary configuration changes.</li>
* </ul>
*
* @author Florian McKee
*/
public final class SkippyPlugin implements org.gradle.api.Plugin<Project> {


@Override
@Override
public void apply(Project project) {
project.getPlugins().apply(JavaPlugin.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.gradle.tooling.BuildLauncher;

/**
* API that is used by plugins and task to detect, configure and run coverage builds.
*
* @author Florian McKee
*/
Expand All @@ -37,10 +38,22 @@ public static boolean isCoverageBuild(Project project) {
return project.hasProperty("skippyCoverageBuild");
}

/**
* Configures the {@param project} for the execution of a coverage build for a skippified test.
*
* @param project
*/
public static void configure(Project project) {
CoverageBuildProjectConfigurer.configure(project);
}

/**
* Runs a coverage build for the {@code skippifiedTest}.
*
* @param project
* @param buildLauncher
* @param skippifiedTest
*/
public static void run(Project project, BuildLauncher buildLauncher, SkippifiedTest skippifiedTest) {
CoverageBuildRunner.run(project, buildLauncher, skippifiedTest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@
import static java.util.Arrays.asList;

/**
* Configures a {@code project} for the execution of a coverage build.
* Configures a {@code project} for the execution of a coverage build for a skippified tests.
*
* @author Florian McKee
*/
final class CoverageBuildProjectConfigurer {

/**
* Configures the {@code project} for the execution of a coverage build.
* Configures the {@code project} for the execution of a coverage build for a skippified test.
* <br /><br />
* Note: The skippified test is inferred from the build arguments.
*
* @param project
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,27 @@

import java.io.ByteArrayOutputStream;

import static io.skippy.gradle.Profiler.stopWatch;
import static io.skippy.gradle.util.StopWatch.measureInMs;
import static io.skippy.gradle.SkippyConstants.SKIPPY_DIRECTORY;
import static java.util.stream.Collectors.joining;

/**
* Runs coverage builds for skippified tests.
*
* @author Florian McKee
*/
final class CoverageBuildRunner {

/**
* Runs a coverage build for the {@code skippifiedTest}.
*
* @param project
* @param buildLauncher
* @param skippifiedTest
*/
static void run(Project project, BuildLauncher buildLauncher, SkippifiedTest skippifiedTest) {
try {
var args = CoverageBuildArguments.forSkippifiedTest(skippifiedTest);
var args = CoverageBuildTasksAndArguments.forSkippifiedTest(skippifiedTest);
var csvFile = project.getProjectDir().toPath().resolve(SKIPPY_DIRECTORY).resolve(skippifiedTest.getFullyQualifiedClassName() + ".csv");
var fqn = skippifiedTest.getFullyQualifiedClassName();

Expand All @@ -47,7 +56,7 @@ static void run(Project project, BuildLauncher buildLauncher, SkippifiedTest ski
));
project.getLogger().lifecycle("%s".formatted(skippifiedTest.getFullyQualifiedClassName()));

long ms = stopWatch(() -> runInternal(project.getLogger(), buildLauncher, skippifiedTest));
long ms = measureInMs(() -> runInternal(project.getLogger(), buildLauncher, skippifiedTest));
project.getLogger().lifecycle("%s".formatted(skippifiedTest.getFullyQualifiedClassName()));
project.getLogger().lifecycle("%s Build executed in %sms.".formatted(skippifiedTest.getFullyQualifiedClassName(), ms));
} catch (Exception e) {
Expand All @@ -58,7 +67,7 @@ static void run(Project project, BuildLauncher buildLauncher, SkippifiedTest ski

private static void runInternal(Logger logger, BuildLauncher buildLauncher, SkippifiedTest skippifiedTest) {
// configure tasks and arguments
var args = CoverageBuildArguments.forSkippifiedTest(skippifiedTest);
var args = CoverageBuildTasksAndArguments.forSkippifiedTest(skippifiedTest);
buildLauncher.forTasks(args.getTasks().toArray(new String[0]));
buildLauncher.addArguments(args.getArguments().toArray(new String[0]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,27 @@
import static java.util.Arrays.asList;

/**
* Represents the tasks and build arguments used to run a coverage build for a skippified test.
*
* @author Florian McKee
*/
final class CoverageBuildArguments {
final class CoverageBuildTasksAndArguments {

private final List<String> tasks;
private final List<String> arguments;

private CoverageBuildArguments(List<String> tasks, List<String> arguments) {
private CoverageBuildTasksAndArguments(List<String> tasks, List<String> arguments) {
this.tasks = tasks;
this.arguments = arguments;
}

static CoverageBuildArguments forSkippifiedTest(SkippifiedTest skippifiedTest) {
/**
* Creates a new instance for a {@link SkippifiedTest}.
*
* @param skippifiedTest
* @return a new instance for a {@link SkippifiedTest}
*/
static CoverageBuildTasksAndArguments forSkippifiedTest(SkippifiedTest skippifiedTest) {
var tasks = asList(
skippifiedTest.getTestTask(),
"jacocoTestReport"
Expand All @@ -45,13 +53,23 @@ static CoverageBuildArguments forSkippifiedTest(SkippifiedTest skippifiedTest) {
"-PskippyClassFile=" + skippifiedTest.getRelativePath(),
"-PskippyTestTask=" + skippifiedTest.getTestTask()
);
return new CoverageBuildArguments(tasks, arguments);
return new CoverageBuildTasksAndArguments(tasks, arguments);
}

/**
* Returns the tasks that need to be executed for the coverage build for the skippified test.
*
* @return the tasks that need to be executed for the coverage build for the skippified test
*/
List<String> getTasks() {
return tasks;
}

/**
* Returns the arguments that need to be passed to the coverage build for the skippified test.
*
* @return the arguments that need to be passed to the coverage build for the skippified test
*/
List<String> getArguments() {
return arguments;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@

package io.skippy.gradle.model;

import org.gradle.api.Project;

import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

import static java.util.Arrays.asList;

/**
* Thin wrapper around a skippified test that stores
Expand Down Expand Up @@ -54,7 +48,6 @@ public SkippifiedTest(ClassFile test, String testTask) {
*
* @return the fully qualified class name (e.g., com.example.FooTest)
*/

public String getFullyQualifiedClassName() {
return testClassFile.getFullyQualifiedClassName();
}
Expand Down
20 changes: 20 additions & 0 deletions skippy-gradle/src/main/java/io/skippy/gradle/util/StopWatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.skippy.gradle.util;

public class StopWatch {

/**
* Measures the runtime of the {@code runnable} in milliseconds.
*
* @param runnable
* @return the runtime of the {@code runnable} in milliseconds
*/
public static long measureInMs(Runnable runnable) {
var then = System.currentTimeMillis();
try {
runnable.run();
} finally {
return System.currentTimeMillis() - then;
}
}

}

0 comments on commit 0d0bf99

Please sign in to comment.