Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from marwin1991/generate_empty_changelog_with_g…
Browse files Browse the repository at this point in the history
…itkeep

Implementing empty changelog
  • Loading branch information
marwin1991 committed Mar 28, 2021
2 parents eb99ee3 + 62f4185 commit cce48c3
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 28 deletions.
17 changes: 0 additions & 17 deletions CHANGELOG.md

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ TODO



Requirements:
- set up the JAVA_HOME system variable
7 changes: 7 additions & 0 deletions changelog/unreleased/0002-init-project-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Added maven command to initilize project with changelog/unreleased directory and empty CHANGELOG.md
authors:
nick: Glukasze
url: https://github.com/Glukasze
type: added # [added/changed/deprecated/removed/fixed/security]
merge_request: 3

1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,21 @@ public class GenerateChangelogMojo extends AbstractMojo {
@Parameter(defaultValue = "", property = "header")
private String header;

@Parameter(defaultValue = "changelog", property = "changelogDirectory")
private String changelogDirectoryName;
@Parameter(defaultValue = "changelog", property = "yamlFilesDirectory")
private String yamlFilesDirectory;

@Parameter(defaultValue = "CHANGELOG.md", property = "finalChangelogName")
@Parameter(defaultValue = "src/CHANGELOG.md", property = "finalChangelogName")
private String finalChangelogName;

@Parameter(defaultValue = "${project}", required = true, readonly = true)
private MavenProject project;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Started generating " + finalChangelogName);
File changelogDirectory = findChangelogDirectory(project.getFile().getParent());

generate(changelogDirectory, finalChangelogName);

getLog().info("HELLO WORLD");
getLog().info("Generating " + finalChangelogName + " successful");
}

public void generate(File changelogDirectory, String finalChangelogName) {
Expand Down Expand Up @@ -106,17 +105,17 @@ private OffsetDateTime getReleaseDate(File version) {


private File findChangelogDirectory(String directoryPath) {
File changelogDirectory = new File(directoryPath + "/" + changelogDirectoryName);
if (!changelogDirectory.exists()) {
File changelogDir = new File(directoryPath + "/" + yamlFilesDirectory);
if (!changelogDir.exists()) {
getLog().error("There is no 'changelog' directory in this project !!!");
throw new RuntimeException("No changelog directory");
}

if (!changelogDirectory.isDirectory()) {
if (!changelogDir.isDirectory()) {
getLog().error("File 'changelog' is not a directory !!!");
throw new RuntimeException("File changelog is not a directory");
}

return changelogDirectory;
return changelogDir;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.github.marwin1991.keep_changelog;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;
import java.io.IOException;

@Mojo(name = "init", defaultPhase = LifecyclePhase.NONE)
public class InitProjectMojo extends AbstractMojo {

private static final String GIT_KEEP = ".gitkeep";

@Parameter(defaultValue = "CHANGELOG.md", property = "finalChangelogName")
private String finalChangelogName;

@Parameter(defaultValue = "changelog", property = "yamlFilesDirectory")
private String yamlFilesDirectory;

@Parameter(defaultValue = "unreleased", property = "unreleasedVersionDirectory")
private String unreleasedVersionDirectory;

@Override
public void execute() {
getLog().info("Initialize project for keep-changelog maven plugin");
generateChangelog(finalChangelogName);
generateChangelogDirUnreleasedDirGitKeep(yamlFilesDirectory + "/" + unreleasedVersionDirectory + "/");
getLog().info("Initialize project successful");
}

public void generateChangelog(String path) {

try {
File changelog = new File(path);
if (changelog.createNewFile()) {
getLog().info("Created: " + changelog.getName());
} else {
getLog().warn(changelog.getName() + " already exists.");
}
} catch (IOException e) {
getLog().error("An error occurred while creating empty changelog.");
}
}

public void generateChangelogDirUnreleasedDirGitKeep(String path) {

try {
File gitKeep = new File(path + GIT_KEEP);
if (gitKeep.createNewFile()) {
getLog().info("Created: " + gitKeep.getName());
} else {
getLog().warn(gitKeep.getName() + " already exists.");
}
} catch (IOException e) {
getLog().error("An error occurred while creating empty .gitkeep.");
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.marwin1991.keep_changelog.test;

import com.github.marwin1991.keep_changelog.InitProjectMojo;

public class TestInitProject {

public static void main(String[] args) {
new InitProjectMojo().generateChangelog("CHANGELOG.md");
new InitProjectMojo().generateChangelogDirUnreleasedDirGitKeep("changelog/unreleased/");
}
}

0 comments on commit cce48c3

Please sign in to comment.