Skip to content

Commit c7e8c7f

Browse files
committed
Add delete() methods for environment deletion
1 parent d1c4244 commit c7e8c7f

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/main/java/org/apposed/appose/Builder.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,26 @@ public interface Builder<T extends Builder<T>> {
7878
* using the current builder configuration. This is more robust than trying to
7979
* update an existing environment in place.
8080
* </p>
81+
* <p>
82+
* This method is a shorthand for {@link #delete()} then {@link #build()}.
83+
* </p>
8184
*
8285
* @return The newly rebuilt {@link Environment}.
8386
* @throws IOException If something goes wrong during rebuild.
8487
*/
85-
Environment rebuild() throws IOException;
88+
default Environment rebuild() throws IOException {
89+
delete();
90+
return build();
91+
}
8692

8793
/**
94+
* Deletes the builder's linked environment directory, if any.
95+
*
96+
* @throws IOException If something goes wrong during deletion.
97+
*/
98+
void delete() throws IOException;
99+
100+
/**
88101
* Wraps an existing environment directory, detecting and using any
89102
* configuration files present for future rebuild() calls.
90103
* <p>

src/main/java/org/apposed/appose/Environment.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ default Environment rebuild() throws IOException {
8787
return builder().rebuild();
8888
}
8989

90+
/**
91+
* Deletes the existing environment directory, if any.
92+
*
93+
* @return This environment, for fluid chaining.
94+
* @throws IOException If something goes wrong during deletion.
95+
*/
96+
default Environment delete() throws IOException {
97+
builder().delete();
98+
return this;
99+
}
100+
90101
/**
91102
* Creates a Python script service.
92103
* <p>

src/main/java/org/apposed/appose/builder/BaseBuilder.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,9 @@ public abstract class BaseBuilder<T extends BaseBuilder<T>> implements Builder<T
6868
// -- Builder methods --
6969

7070
@Override
71-
public Environment rebuild() throws IOException {
71+
public void delete() throws IOException {
7272
File dir = envDir();
73-
if (dir.exists()) {
74-
FilePaths.deleteRecursively(dir);
75-
}
76-
return build();
73+
if (dir.exists()) FilePaths.deleteRecursively(dir);
7774
}
7875

7976
@Override

0 commit comments

Comments
 (0)