-
Notifications
You must be signed in to change notification settings - Fork 156
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
Allow copy-file and delete-file to be scheduled #574
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,8 +312,8 @@ A scenario can define changes that should be applied to the source before each b | |
- `clear-jars-cache-before`: Deletes the contents of the instrumented jars cache before the scenario is executed (`SCENARIO`), before cleanup (`CLEANUP`) or before the build is executed (`BUILD`). | ||
- `clear-project-cache-before`: Deletes the contents of the `.gradle` and `buildSrc/.gradle` project cache directories before the scenario is executed (`SCENARIO`), before cleanup (`CLEANUP`) or before the build is executed (`BUILD`). | ||
- `clear-transform-cache-before`: Deletes the contents of the transform cache before the scenario is executed (`SCENARIO`), before cleanup (`CLEANUP`) or before the build is executed (`BUILD`). | ||
- `copy-file`: Copies a file or a directory from one location to another. Has to specify a `source` and a `target` path; relative paths are resolved against the project directory. Can take an array of operations. | ||
- `delete-file`: Deletes a file or a directory. Has to specify a `target` path; when relative it is resolved against the project directory. Can take an array of operations. | ||
- `copy-file`: Copies a file or a directory from one location to another. Has to specify a `source` and a `target` path; relative paths are resolved against the project directory. Can also specify a schedule (defaults `SCENARIO`). Can take an array of operations. | ||
- `delete-file`: Deletes a file or a directory. Has to specify a `target` path; when relative it is resolved against the project directory. Can also specify a schedule (defaults `SCENARIO`). Can take an array of operations. | ||
- `git-checkout`: Checks out a specific commit for the build step, and a different one for the cleanup step. | ||
- `git-revert`: Reverts a given set of commits before the build and resets it afterward. | ||
- `iterations`: Number of builds to actually measure | ||
|
@@ -352,8 +352,10 @@ They can be added to a scenario file like this: | |
} | ||
delete-file = [{ | ||
target = ".mvn/develocity.xml" | ||
schedule = CLEANUP | ||
}, { | ||
target = ".gradle" | ||
schedule = CLEANUP | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ This then runs at the start of schedule, right? Can we maybe add this detail also do README.md that it means at start/before a schedule, or should that be obvious? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I've extracted some words about scheduling mutators. |
||
}] | ||
git-checkout = { | ||
cleanup = "efb43a1" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,43 +11,43 @@ | |
import java.io.IOException; | ||
import java.nio.file.Files; | ||
|
||
public abstract class AbstractCleanupMutator implements BuildMutator { | ||
public abstract class AbstractScheduledMutator implements BuildMutator { | ||
|
||
private final CleanupSchedule schedule; | ||
private final Schedule schedule; | ||
|
||
public AbstractCleanupMutator(CleanupSchedule schedule) { | ||
public AbstractScheduledMutator(Schedule schedule) { | ||
this.schedule = schedule; | ||
} | ||
|
||
@Override | ||
public void validate(BuildInvoker invoker) { | ||
if (schedule != CleanupSchedule.SCENARIO && !invoker.allowsCleanupBetweenBuilds()) { | ||
if (schedule != Schedule.SCENARIO && !invoker.allowsMutationBetweenBuilds()) { | ||
throw new IllegalStateException(this + " is not allowed to be executed between builds with invoker " + invoker); | ||
} | ||
} | ||
|
||
@Override | ||
public void beforeBuild(BuildContext context) { | ||
if (schedule == CleanupSchedule.BUILD) { | ||
cleanup(); | ||
if (schedule == Schedule.BUILD) { | ||
executeOnSchedule(); | ||
} | ||
} | ||
|
||
@Override | ||
public void beforeScenario(ScenarioContext context) { | ||
if (schedule == CleanupSchedule.SCENARIO) { | ||
cleanup(); | ||
if (schedule == Schedule.SCENARIO) { | ||
executeOnSchedule(); | ||
} | ||
} | ||
|
||
@Override | ||
public void beforeCleanup(BuildContext context) { | ||
if (schedule == CleanupSchedule.CLEANUP) { | ||
cleanup(); | ||
if (schedule == Schedule.CLEANUP) { | ||
executeOnSchedule(); | ||
} | ||
} | ||
|
||
abstract protected void cleanup(); | ||
abstract protected void executeOnSchedule(); | ||
|
||
protected static void delete(File f) { | ||
try { | ||
|
@@ -64,22 +64,22 @@ protected static void delete(File f) { | |
protected static abstract class Configurator implements BuildMutatorConfigurator { | ||
@Override | ||
public BuildMutator configure(String key, BuildMutatorConfiguratorSpec spec) { | ||
CleanupSchedule schedule = ConfigUtil.enumValue(spec.getScenario(), key, CleanupSchedule.class, null); | ||
Schedule schedule = ConfigUtil.enumValue(spec.getScenario(), key, Schedule.class, null); | ||
if (schedule == null) { | ||
throw new IllegalArgumentException("Schedule for cleanup is not specified"); | ||
throw new IllegalArgumentException("Schedule is not specified"); | ||
} | ||
return newInstance(spec, key, schedule); | ||
} | ||
|
||
protected abstract BuildMutator newInstance(BuildMutatorConfiguratorSpec spec, String key, CleanupSchedule schedule); | ||
protected abstract BuildMutator newInstance(BuildMutatorConfiguratorSpec spec, String key, Schedule schedule); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "(" + schedule + ")"; | ||
} | ||
|
||
public enum CleanupSchedule { | ||
public enum Schedule { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 Also this change will require some changes in It's not a problem but we should be aware of that when we upgrade a profiler. |
||
SCENARIO, CLEANUP, BUILD | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,16 @@ | |
import java.io.UncheckedIOException; | ||
import java.nio.file.Files; | ||
|
||
public class ClearGradleUserHomeMutator extends AbstractCleanupMutator { | ||
public class ClearGradleUserHomeMutator extends AbstractScheduledMutator { | ||
private final File gradleUserHome; | ||
|
||
public ClearGradleUserHomeMutator(File gradleUserHome, CleanupSchedule schedule) { | ||
public ClearGradleUserHomeMutator(File gradleUserHome, Schedule schedule) { | ||
super(schedule); | ||
this.gradleUserHome = gradleUserHome; | ||
} | ||
|
||
@Override | ||
protected void cleanup() { | ||
protected void executeOnSchedule() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 Note: This change will require also a change of some logic in It's not a problem but we should be aware of that when we upgrade a profiler. |
||
System.out.println(String.format("> Cleaning Gradle user home: %s", gradleUserHome.getAbsolutePath())); | ||
if (!gradleUserHome.exists()) { | ||
throw new IllegalArgumentException(String.format( | ||
|
@@ -34,9 +34,9 @@ protected void cleanup() { | |
} | ||
} | ||
|
||
public static class Configurator extends AbstractCleanupMutator.Configurator { | ||
public static class Configurator extends AbstractScheduledMutator.Configurator { | ||
@Override | ||
protected BuildMutator newInstance(BuildMutatorConfiguratorSpec spec, String key, CleanupSchedule schedule) { | ||
protected BuildMutator newInstance(BuildMutatorConfiguratorSpec spec, String key, Schedule schedule) { | ||
return new ClearGradleUserHomeMutator(spec.getGradleUserHome(), schedule); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Nice