Prepare for Asciidoctor Gradle Plugin 2.0 by looking for gradle-projectdir
Closes gh-562
This commit is contained in:
@@ -21,6 +21,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Resolves the directory from which snippets can be read for inclusion in an Asciidoctor
|
||||
@@ -57,13 +58,23 @@ class SnippetsDirectoryResolver {
|
||||
}
|
||||
|
||||
private File getGradleSnippetsDirectory(Map<String, Object> attributes) {
|
||||
return new File(getRequiredAttribute(attributes, "projectdir"),
|
||||
return new File(
|
||||
getRequiredAttribute(attributes, "gradle-projectdir",
|
||||
() -> getRequiredAttribute(attributes, "projectdir")),
|
||||
"build/generated-snippets");
|
||||
}
|
||||
|
||||
private String getRequiredAttribute(Map<String, Object> attributes, String name) {
|
||||
return getRequiredAttribute(attributes, name, null);
|
||||
}
|
||||
|
||||
private String getRequiredAttribute(Map<String, Object> attributes, String name,
|
||||
Supplier<String> fallback) {
|
||||
String attribute = (String) attributes.get(name);
|
||||
if (attribute == null || attribute.length() == 0) {
|
||||
if (fallback != null) {
|
||||
return fallback.get();
|
||||
}
|
||||
throw new IllegalStateException(name + " attribute not found");
|
||||
}
|
||||
return attribute;
|
||||
|
||||
@@ -78,7 +78,30 @@ public class SnippetsDirectoryResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gradleProjectsUseBuildGeneratedSnippetsBeneathProjectDir()
|
||||
public void gradleProjectsUseBuildGeneratedSnippetsBeneathGradleProjectdir()
|
||||
throws IOException {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
attributes.put("gradle-projectdir", "project/dir");
|
||||
File snippetsDirectory = new SnippetsDirectoryResolver()
|
||||
.getSnippetsDirectory(attributes);
|
||||
assertThat(snippetsDirectory)
|
||||
.isEqualTo(new File("project/dir/build/generated-snippets"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gradleProjectsUseBuildGeneratedSnippetsBeneathGradleProjectdirWhenBothItAndProjectdirAreSet()
|
||||
throws IOException {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
attributes.put("gradle-projectdir", "project/dir");
|
||||
attributes.put("projectdir", "fallback/dir");
|
||||
File snippetsDirectory = new SnippetsDirectoryResolver()
|
||||
.getSnippetsDirectory(attributes);
|
||||
assertThat(snippetsDirectory)
|
||||
.isEqualTo(new File("project/dir/build/generated-snippets"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gradleProjectsUseBuildGeneratedSnippetsBeneathProjectdirWhenGradleProjectdirIsNotSet()
|
||||
throws IOException {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
attributes.put("projectdir", "project/dir");
|
||||
@@ -89,7 +112,7 @@ public class SnippetsDirectoryResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void illegalStateWhenProjectdirAttributeIsNotSetInGradleProject()
|
||||
public void illegalStateWhenGradleProjectdirAndProjectdirAttributesAreNotSetInGradleProject()
|
||||
throws IOException {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
|
||||
Reference in New Issue
Block a user