Added missing mkdirs for template generation; fixes #36
This commit is contained in:
@@ -19,13 +19,23 @@ public class TemplateGenerator {
|
||||
private static final String EMAIL_TEMPLATE = "email";
|
||||
private static final String BLOG_TEMPLATE = "blog";
|
||||
private static final String TWITTER_TEMPLATE = "tweet";
|
||||
private final File emailOutput = new File("target/email.txt");
|
||||
private final File blogOutput = new File("target/blog.md");
|
||||
private final File tweetOutput = new File("target/tweet.txt");
|
||||
private final File emailOutput;
|
||||
private final File blogOutput;
|
||||
private final File tweetOutput;
|
||||
private final ReleaserProperties props;
|
||||
|
||||
public TemplateGenerator(ReleaserProperties props) {
|
||||
this.props = props;
|
||||
this.emailOutput = new File("target/email.txt");
|
||||
this.blogOutput = new File("target/blog.md");
|
||||
this.tweetOutput = new File("target/tweet.txt");
|
||||
}
|
||||
|
||||
TemplateGenerator(ReleaserProperties props, File output) {
|
||||
this.props = props;
|
||||
this.emailOutput = output;
|
||||
this.blogOutput = output;
|
||||
this.tweetOutput = output;
|
||||
}
|
||||
|
||||
public File email() {
|
||||
@@ -40,6 +50,11 @@ public class TemplateGenerator {
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
File parentFile = file.getParentFile();
|
||||
boolean mkdirs = parentFile.mkdirs();
|
||||
if (!mkdirs) {
|
||||
throw new IllegalStateException("Failed to create the parent directory [" + parentFile + "]");
|
||||
}
|
||||
if (!file.createNewFile()) {
|
||||
throw new IllegalStateException("Couldn't create a file [" + file + "]");
|
||||
}
|
||||
|
||||
@@ -27,6 +27,16 @@ public class TemplateGeneratorTests {
|
||||
then(generatedMail).hasContent(expectedEmail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_generate_email_from_template_when_output_folder_is_missing() {
|
||||
ReleaserProperties props = new ReleaserProperties();
|
||||
props.getPom().setBranch("vDalston.RELEASE");
|
||||
|
||||
File generatedMail = new TemplateGenerator(props, new File("target/foo/bar/baz/template.txt")).email();
|
||||
|
||||
then(generatedMail).hasContent(expectedEmail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_generate_email_from_template_for_tag_without_v_prefix() {
|
||||
ReleaserProperties props = new ReleaserProperties();
|
||||
|
||||
Reference in New Issue
Block a user