Make things less Gradle-specific and provide Maven config in samples

Previously, the project provided a Gradle plugin and was only really
intended for use with Gradle. This had influenced a number of design
choices that have proven to be less than ideal when attempting to
use the project with Maven.

This commit backs off from a number of design decisions that worked
well with Gradle but less so with Maven. Part of this is that the
Gradle plugin is (temporarily?) no more. It's been removed in favour
of configuring things directly in build.gradle. While this slightly
increases the amount of configuration required it makes things far
more flexible.

Both samples have been updated with modified Gradle configuration and
new Maven configuration. The README has also been updated to reflect
these changes.
This commit is contained in:
Andy Wilkinson
2015-01-08 16:51:47 +00:00
parent f67b74304c
commit 6ec522069a
26 changed files with 467 additions and 561 deletions

View File

@@ -21,13 +21,13 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.springframework.util.StringUtils;
class DocumentationProperties {
private final Properties properties = new Properties();
DocumentationProperties() {
this.properties.putAll(System.getProperties());
InputStream stream = getClass().getClassLoader().getResourceAsStream(
"documentation.properties");
if (stream != null) {
@@ -47,11 +47,14 @@ class DocumentationProperties {
}
}
}
this.properties.putAll(System.getProperties());
}
File getOutputDir() {
return new File(this.properties.getProperty(
"org.springframework.restdocs.outputDir", "generated-documentation"))
.getAbsoluteFile();
String outputDir = this.properties.getProperty("org.springframework.restdocs.outputDir");
if (StringUtils.hasText(outputDir)) {
return new File(outputDir).getAbsoluteFile();
}
return null;
}
}

View File

@@ -205,14 +205,21 @@ public abstract class RestDocumentationResultHandlers {
if (!outputFile.isAbsolute()) {
outputFile = makeAbsolute(outputFile);
}
outputFile.getParentFile().mkdirs();
return new PrintStream(new FileOutputStream(outputFile));
if (outputFile != null) {
outputFile.getParentFile().mkdirs();
return new PrintStream(new FileOutputStream(outputFile));
}
return System.out;
}
private static File makeAbsolute(File outputFile) {
return new File(new DocumentationProperties().getOutputDir(),
outputFile.getPath());
File outputDir = new DocumentationProperties().getOutputDir();
if (outputDir != null) {
return new File(outputDir, outputFile.getPath());
}
return null;
}
}