-
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
Add delete-file and copy-file mutators #570
Conversation
bdemers
commented
Aug 30, 2024
- Add delete-file and copy-file mutators
- Add system property support for MavenScenarioInvoker
Individual files can be copied or file/directories deleted. I needed to get benchmarks running for a Maven build, and replace the .mvn/extensions.xml and related configuration files
src/main/java/org/gradle/profiler/mutations/CopyFileMutator.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gradle/profiler/mutations/CopyFileMutator.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gradle/profiler/mutations/CopyFileMutator.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gradle/profiler/mutations/DeleteFileMutator.java
Outdated
Show resolved
Hide resolved
private static final String DELETE_FILE = "delete-file"; | ||
private static final String COPY_FILE = "copy-file"; |
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.
Considering that these should be able to take directories, too, I think delete
and copy
would be better names, WDYT?
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.
I've been rethinking this, and I think it's okay to include -file
; it's good to disambiguate that this is about the file system.
src/main/java/org/gradle/profiler/mutations/CopyFileMutator.java
Outdated
Show resolved
Hide resolved
Also resolve target directory based on the project directory.
9d9a6ca
to
5bed2b9
Compare
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.
LGTM overall. It would be good we add some documentation for this
@@ -91,6 +94,8 @@ class ScenarioLoader { | |||
private static final String ANDROID_STUDIO_JVM_ARGS = "studio-jvm-args"; | |||
private static final String ANDROID_STUDIO_IDEA_PROPERTIES = "idea-properties"; | |||
private static final String JVM_ARGS = "jvm-args"; | |||
private static final String DELETE_FILE = "delete-file"; |
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.
❓ Do we plan to add a documentation in README.md in a separate PR? If not it would be good we add it now
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.
Good point.
this.target = target; | ||
} | ||
|
||
@SuppressWarnings("UnstableApiUsage") |
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.
❔ Which API is unstable, maybe there is a stable replacement?
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.
It's Guava. I think upgrading Guava is the right solution here. Let me take a look.
} | ||
Files.copy(source, target); | ||
} catch (IOException e) { | ||
throw new IllegalStateException("Failed to copy '" + source.getAbsolutePath() + "' to '" + target.getAbsolutePath() + "'", e); |
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.
❔ Should we throw UncheckedIOException here, instead of IllegalStateException?
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.
You're right.
def target = new File(testDir, "nested/target.txt") | ||
|
||
def spec = mockConfigSpec("""{ | ||
copy-file { |
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.
❔ Can we copy also multiple files or we can copy just one?
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.
We can copy one source (a file or a directory) to a target location.
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.
LGTM overall
README.md
Outdated
- `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`). | ||
- `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-android-studio-cache-before`: Invalidates the Android Studio caches before the scenario is executed (`SCENARIO`) or before the build is executed (`BUILD`). Due to Android Studio client specifics before cleanup (`CLEANUP`) is not supported. Note: cleaning the Android Studio caches is run only when Android Studio sync (`android-studio-sync`) is used. | ||
- `copy-file`: Copies files from one location to another. Has to specify a `source` and a `target` path, both are resolved against the project directory. |
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.
❓ Should we mention that copy-file
and delete-file
works also with directories and not just files?
Also should we mention that relative paths are resolved agains project directories, but absolute paths can also be specified?
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.
I've added some language to clarify.
78d4085
to
40cfff2
Compare