Polish contribution and rework to use default attribute rather than macro
Rather than introducing a custom macro, this commit opts to implicitly configure the snippets attribute instead. The attribute is configured will the path into which snippets are generated, relative to the directory that contains the Asciidoctor document that is being rendered. The samples and documentation have been updated to use the new spring-restdocs-asciidoctor module and the implicitly configured snippets attribute. Closes gh-297
This commit is contained in:
@@ -17,8 +17,6 @@
|
||||
package org.springframework.restdocs;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* {@code ManualRestDocumentation} is used to manually manage the
|
||||
@@ -33,11 +31,6 @@ import java.nio.file.Paths;
|
||||
*/
|
||||
public final class ManualRestDocumentation implements RestDocumentationContextProvider {
|
||||
|
||||
private static final String GENERATED_SNIPPETS_PATH = "generated-snippets";
|
||||
private static final String MAVEN_TARGET_PATH = "target" + File.separator + GENERATED_SNIPPETS_PATH;
|
||||
private static final String GRADLE_BUILD_PATH = "build" + File.separator + GENERATED_SNIPPETS_PATH;
|
||||
private static final String MAVEN_POM = "pom.xml";
|
||||
|
||||
private final File outputDirectory;
|
||||
|
||||
private RestDocumentationContext context;
|
||||
@@ -57,7 +50,11 @@ public final class ManualRestDocumentation implements RestDocumentationContextPr
|
||||
* @param outputDirectory the output directory
|
||||
*/
|
||||
public ManualRestDocumentation(String outputDirectory) {
|
||||
this.outputDirectory = new File(outputDirectory);
|
||||
this(new File(outputDirectory));
|
||||
}
|
||||
|
||||
private ManualRestDocumentation(File outputDirectory) {
|
||||
this.outputDirectory = outputDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,12 +91,11 @@ public final class ManualRestDocumentation implements RestDocumentationContextPr
|
||||
return this.context;
|
||||
}
|
||||
|
||||
private static String getDefaultOutputDirectory() {
|
||||
String executingDirectory = Paths.get(".").toFile().getAbsolutePath();
|
||||
|
||||
if (Files.exists(Paths.get(MAVEN_POM))) {
|
||||
return executingDirectory + File.separator + MAVEN_TARGET_PATH;
|
||||
private static File getDefaultOutputDirectory() {
|
||||
if (new File("pom.xml").exists()) {
|
||||
return new File("target/generated-snippets");
|
||||
}
|
||||
return executingDirectory + File.separator + GRADLE_BUILD_PATH;
|
||||
return new File("build/generated-snippets");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -195,7 +195,8 @@ public class RestDocumentationConfigurerTests {
|
||||
}
|
||||
|
||||
private RestDocumentationContext createContext() {
|
||||
ManualRestDocumentation manualRestDocumentation = new ManualRestDocumentation("build");
|
||||
ManualRestDocumentation manualRestDocumentation = new ManualRestDocumentation(
|
||||
"build");
|
||||
manualRestDocumentation.beforeTest(null, null);
|
||||
RestDocumentationContext context = manualRestDocumentation.beforeOperation();
|
||||
return context;
|
||||
|
||||
@@ -83,7 +83,8 @@ public class RestDocumentationContextPlaceholderResolverTests {
|
||||
}
|
||||
|
||||
private RestDocumentationContext createContext(String methodName) {
|
||||
ManualRestDocumentation manualRestDocumentation = new ManualRestDocumentation("build");
|
||||
ManualRestDocumentation manualRestDocumentation = new ManualRestDocumentation(
|
||||
"build");
|
||||
manualRestDocumentation.beforeTest(getClass(), methodName);
|
||||
RestDocumentationContext context = manualRestDocumentation.beforeOperation();
|
||||
return context;
|
||||
|
||||
@@ -70,7 +70,8 @@ public class StandardWriterResolverTests {
|
||||
}
|
||||
|
||||
private RestDocumentationContext createContext(String outputDir) {
|
||||
ManualRestDocumentation manualRestDocumentation = new ManualRestDocumentation(outputDir);
|
||||
ManualRestDocumentation manualRestDocumentation = new ManualRestDocumentation(
|
||||
outputDir);
|
||||
manualRestDocumentation.beforeTest(getClass(), null);
|
||||
RestDocumentationContext context = manualRestDocumentation.beforeOperation();
|
||||
return context;
|
||||
|
||||
@@ -123,7 +123,8 @@ public class OperationBuilder extends OperationTestRule {
|
||||
}
|
||||
|
||||
private RestDocumentationContext createContext() {
|
||||
ManualRestDocumentation manualRestDocumentation = new ManualRestDocumentation(this.outputDirectory.getAbsolutePath());
|
||||
ManualRestDocumentation manualRestDocumentation = new ManualRestDocumentation(
|
||||
this.outputDirectory.getAbsolutePath());
|
||||
manualRestDocumentation.beforeTest(null, null);
|
||||
RestDocumentationContext context = manualRestDocumentation.beforeOperation();
|
||||
return context;
|
||||
|
||||
Reference in New Issue
Block a user