From 4bab3bde4523fdfbc69377d1ae0213fd9f103770 Mon Sep 17 00:00:00 2001 From: sainath chinta <89763037+sainathchinta@users.noreply.github.com> Date: Mon, 2 Mar 2026 09:59:51 -0800 Subject: [PATCH 1/2] feat: add VersionFileProjectType to support VERSION file (#124) Add a new ProjectType implementation that reads and writes a plain VERSION file. If a VERSION file exists in the project root, the plugin will use its contents as the current version and update the file with the next calculated version. This change enables projects without standard build files to specify their version in a VERSION file as requested in issue #124. --- .../utils/VersionFileProjectType.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/main/java/io/jenkins/plugins/conventionalcommits/utils/VersionFileProjectType.java diff --git a/src/main/java/io/jenkins/plugins/conventionalcommits/utils/VersionFileProjectType.java b/src/main/java/io/jenkins/plugins/conventionalcommits/utils/VersionFileProjectType.java new file mode 100644 index 0000000..95f1a9e --- /dev/null +++ b/src/main/java/io/jenkins/plugins/conventionalcommits/utils/VersionFileProjectType.java @@ -0,0 +1,58 @@ +package io.jenkins.plugins.conventionalcommits.utils; + +import com.github.zafarkhaja.semver.Version; +import io.jenkins.plugins.conventionalcommits.process.ProcessHelper; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * ProjectType implementation that uses a simple VERSION file. + * + * This class detects a plain text file named VERSION (or a custom file + * name passed to the constructor) in the project root directory. The file + * must contain a single semantic version (e.g. "1.0.0"). When present, + * this ProjectType returns the current version from the file and writes + * the next version back to the same file after a bump. + */ +public class VersionFileProjectType extends ProjectType { + + private final String versionFileName; + + /** Creates a VersionFileProjectType that looks for a file named "VERSION". */ + public VersionFileProjectType() { + this("VERSION"); + } + + /** + * Creates a VersionFileProjectType with a custom version file name. + * + * @param versionFileName name of the file containing the version string + */ + public VersionFileProjectType(String versionFileName) { + this.versionFileName = versionFileName; + } + + @Override + public boolean check(File directory) { + return new File(directory, versionFileName).exists(); + } + + @Override + public Version getCurrentVersion(File directory, ProcessHelper processHelper) + throws IOException, InterruptedException { + // Ignore the processHelper parameter as this project type does not need it + Path path = new File(directory, versionFileName).toPath(); + String content = Files.readString(path).trim(); + return Version.valueOf(content); + } + + @Override + public void writeVersion(File directory, Version nextVersion, ProcessHelper processHelper) + throws IOException, InterruptedException { + // Ignore the processHelper parameter; simply write the version string + Path path = new File(directory, versionFileName).toPath(); + Files.writeString(path, nextVersion.toString() + System.lineSeparator()); + } +} From d7eca767115afaeb58e8ec43f4b6bd79f4445139 Mon Sep 17 00:00:00 2001 From: sainath chinta <89763037+sainathchinta@users.noreply.github.com> Date: Mon, 2 Mar 2026 10:49:59 -0800 Subject: [PATCH 2/2] Add VersionFileProjectType to ProjectTypeFactory (#124) Register the new VersionFileProjectType in ProjectTypeFactory so that the plugin can detect and write to a VERSION file. This change allows projects without build files to specify their version in a VERSION file. Addresses issue #124. --- .../plugins/conventionalcommits/utils/ProjectTypeFactory.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/io/jenkins/plugins/conventionalcommits/utils/ProjectTypeFactory.java b/src/main/java/io/jenkins/plugins/conventionalcommits/utils/ProjectTypeFactory.java index b8a8bad..73d4682 100644 --- a/src/main/java/io/jenkins/plugins/conventionalcommits/utils/ProjectTypeFactory.java +++ b/src/main/java/io/jenkins/plugins/conventionalcommits/utils/ProjectTypeFactory.java @@ -3,6 +3,7 @@ import java.io.File; import java.util.HashMap; import java.util.Map; +import io.jenkins.plugins.conventionalcommits.utils.VersionFileProjectType; /** Factory class to support multiple project types. */ public class ProjectTypeFactory { @@ -18,6 +19,7 @@ public class ProjectTypeFactory { projectTypeMap.put("helm", new HelmProjectType()); projectTypeMap.put("go", new GoProjectType()); projectTypeMap.put("php", new PhpProjectType()); + projectTypeMap.put("version", new VersionFileProjectType()); } /**