-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DirectoryBuilder and renamed FileContent to FileBuilder.
- Loading branch information
Showing
12 changed files
with
152 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...-builder/src/main/java/com/link_intersystems/gradle/project/builder/DirectoryBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.link_intersystems.gradle.project.builder; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class DirectoryBuilder { | ||
|
||
private Path directory; | ||
|
||
public DirectoryBuilder(Path directory) throws IOException { | ||
if (!Files.exists(directory)) { | ||
Files.createDirectories(directory); | ||
} | ||
this.directory = requireNonNull(directory); | ||
} | ||
|
||
public Path getPath() { | ||
return directory; | ||
} | ||
|
||
public DirectoryBuilder directory(String relativePath) throws IOException { | ||
return directory(Paths.get(relativePath), DirectoryBuilder::new); | ||
} | ||
|
||
|
||
public <T extends DirectoryBuilder> T directory(String relativePath, DirectoryBuilderFactory<T> directoryBuilderFactory) throws IOException { | ||
return directory(Paths.get(relativePath), directoryBuilderFactory); | ||
} | ||
|
||
public DirectoryBuilder directory(Path relativePath) throws IOException { | ||
return directory(relativePath, DirectoryBuilder::new); | ||
} | ||
|
||
public <T extends DirectoryBuilder> T directory(Path relativePath, DirectoryBuilderFactory<T> directoryBuilderFactory) throws IOException { | ||
Path nextDirectoryPath = relativePath.subpath(0, 1); | ||
return directoryBuilderFactory.create(directory.resolve(nextDirectoryPath)); | ||
} | ||
|
||
public FileBuilder file(String relativeFilePath) throws IOException { | ||
return file(relativeFilePath, FileBuilder::new); | ||
} | ||
|
||
public <T extends FileBuilder> T file(String relativeFilePath, FileBuilderFactory<T> fileBuilderFactory) throws IOException { | ||
return file(Paths.get(relativeFilePath), fileBuilderFactory); | ||
} | ||
|
||
public FileBuilder file(Path relativeFilePath) throws IOException { | ||
return file(relativeFilePath, FileBuilder::new); | ||
} | ||
|
||
public <T extends FileBuilder> T file(Path relativeFilePath, FileBuilderFactory<T> fileBuilderFactory) throws IOException { | ||
int nameCount = relativeFilePath.getNameCount(); | ||
if (nameCount == 1) { | ||
return fileBuilderFactory.create(directory.resolve(relativeFilePath)); | ||
} | ||
|
||
DirectoryBuilder parentDirectory = directory(relativeFilePath.getParent()); | ||
return parentDirectory.file(relativeFilePath.subpath(1, relativeFilePath.getNameCount()), fileBuilderFactory); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...r/src/main/java/com/link_intersystems/gradle/project/builder/DirectoryBuilderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.link_intersystems.gradle.project.builder; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
public interface DirectoryBuilderFactory<T extends DirectoryBuilder> { | ||
|
||
public T create(Path path) throws IOException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...uilder/src/main/java/com/link_intersystems/gradle/project/builder/FileBuilderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.link_intersystems.gradle.project.builder; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
public interface FileBuilderFactory<T extends FileBuilder> { | ||
|
||
public T create(Path path) throws IOException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...roject/builder/PropertiesFileContent.java → ...roject/builder/PropertiesFileBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...lder/src/test/java/com/link_intersystems/gradle/project/builder/DirectoryBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.link_intersystems.gradle.project.builder; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class DirectoryBuilderTest { | ||
|
||
@Test | ||
void build(@TempDir Path tempDir) throws IOException { | ||
DirectoryBuilder directoryBuilder = new DirectoryBuilder(tempDir); | ||
|
||
FileBuilder fileBuilder = directoryBuilder.file("rootFolder/parentFolder/file.txt"); | ||
fileBuilder.append("Hello"); | ||
|
||
assertThat(tempDir.resolve("rootFolder/parentFolder/file.txt")).hasContent("Hello"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters