Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repositories {
}
}

version = '2024.0.0'
version = '2025.0.0'
group = 'edu.wpi.first.wpilib.versioning'

pluginBundle {
Expand Down Expand Up @@ -61,5 +61,5 @@ tasks.withType(JavaCompile) {
}

wrapper {
gradleVersion = '7.5.1'
gradleVersion = '8.11.1'
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
38 changes: 25 additions & 13 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +82,12 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +134,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,11 +201,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
23 changes: 13 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand All @@ -26,6 +28,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -42,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -56,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,60 @@
import org.ajoberstar.grgit.Grgit;
import org.ajoberstar.grgit.Tag;
import org.gradle.api.Project;
import org.gradle.api.problems.ProblemReporter;
import org.gradle.api.problems.Severity;

import java.io.File;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GitVersionProvider implements WPILibVersionProvider {
// A valid version string from git describe takes the form of v1.0.0-beta-2-1-gbd478ea, where
// everything after the v1.0.0 part is optional. Below, I break each piece out in it's own string, and then put
private final ProblemReporter problemReporter;

public GitVersionProvider(ProblemReporter reporter) {
this.problemReporter = reporter;
}

// A valid version string from git describe takes the form of
// v1.0.0-beta-2-1-gbd478ea, where
// everything after the v1.0.0 part is optional. Below, I break each piece out
// in it's own string, and then put
// the final regex together

// This is the only required part of the version. This captures a 'v', then 3 numbers separated by '.'.
// This introduces a capturing group for the major version number called 'major' and the remainder called 'minor'.
// This is the only required part of the version. This captures a 'v', then 3
// numbers separated by '.'.
// This introduces a capturing group for the major version number called 'major'
// and the remainder called 'minor'.
static final String majorVersion = "major";
static final String minorVersion = "minor";
private static final String mainVersionRegex = "v(?<" + majorVersion + ">[0-9]+)(?<" + minorVersion + ">\\.[0-9]+\\.[0-9]+)";
private static final String mainVersionRegex = "v(?<" + majorVersion + ">[0-9]+)(?<" + minorVersion
+ ">\\.[0-9]+\\.[0-9]+)";

public static String getMainVersionRegex() {
return mainVersionRegex;
}

// This is the alpha/beta/rc qualifier. It is a '-', followed by 'alpha', 'beta', or 'rc', followed by another '-', finally
// followed by the alpha/beta/rc number. This introduces a capturing group for the qualifier number, called 'qualifier'.
// This is the alpha/beta/rc qualifier. It is a '-', followed by 'alpha',
// 'beta', or 'rc', followed by another '-', finally
// followed by the alpha/beta/rc number. This introduces a capturing group for
// the qualifier number, called 'qualifier'.
static final String qualifier = "qualifier";
private static final String qualifierRegex = "-(?<" + qualifier + ">(alpha|beta|rc)-[0-9]+)";

public static String getQualifierRegex() {
return qualifierRegex;
}

// This is the number of commits since the last annotated tag, and the commit hash of the latest commit. This is
// a '-', followed by a number, the number of commits, followed by a '-', followed by a 'g', followed by the git
// abbreviation of the hash of the current commit. This introduces 2 capturing groups, one for the number of
// This is the number of commits since the last annotated tag, and the commit
// hash of the latest commit. This is
// a '-', followed by a number, the number of commits, followed by a '-',
// followed by a 'g', followed by the git
// abbreviation of the hash of the current commit. This introduces 2 capturing
// groups, one for the number of
// commits, 'commits', and one for the commit hash, 'sha'.
static final String commits = "commits";
static final String sha = "sha";
Expand All @@ -46,10 +66,12 @@ public static String getCommitsRegex() {
return commitsRegex;
}

// This is the final regex. mainVersion is the only element that is required. Each subpart, if it shows up, must
// This is the final regex. mainVersion is the only element that is required.
// Each subpart, if it shows up, must
// show up in full. A fully expanded version of the regex is copied below:
// ^v(?<major>[0-9]+)(?<minor>\.[0-9]+\.[0-9]+)(-(?<qualifier>(alpha|beta|rc)-[0-9]+))?(-(?<commits>[0-9]+)-(?<sha>g[a-f0-9]+))?$
static final Pattern versionRegex = Pattern.compile( "^" + mainVersionRegex + "(" + qualifierRegex + ")?(" + commitsRegex + ")?$");
static final Pattern versionRegex = Pattern
.compile("^" + mainVersionRegex + "(" + qualifierRegex + ")?(" + commitsRegex + ")?$");

public static Pattern getVersionRegex() {
return versionRegex;
Expand All @@ -65,7 +87,8 @@ private File getGitDir(File currentDir) {
return getGitDir(currentDir.getParentFile());
}

public String getVersion(WPILibVersioningPluginExtension extension, Project project, boolean allTags, List<String> matchGlobs) {
public String getVersion(WPILibVersioningPluginExtension extension, Project project, boolean allTags,
List<String> matchGlobs) {
String tag = null;
boolean isDirty = false;

Expand All @@ -85,15 +108,17 @@ public String getVersion(WPILibVersioningPluginExtension extension, Project proj
// We are not on CI or CI failed to provide a tag, need to use git
// Determine the version number and make it available on our plugin extension
File gitDir = getGitDir(project.getRootProject().getRootDir());
// If no git directory was found, print a message to the console and return an empty string
// If no git directory was found, print a message to the console and return an
// empty string
if (gitDir == null) {
System.out.println("No .git was found in " + project.getRootProject().getRootDir() + ", or any parent directories of that directory.");
System.out.println("No .git was found in " + project.getRootProject().getRootDir()
+ ", or any parent directories of that directory.");
System.out.println("No version number generated.");
return "";
}

Map<String, Object> openArgs = Map.of("currentDir", (Object)gitDir.getAbsolutePath());
Map<String, Object> describeArgs = Map.of("tags", (Object)allTags, "match", (Object)matchGlobs);
Map<String, Object> openArgs = Map.of("currentDir", (Object) gitDir.getAbsolutePath());
Map<String, Object> describeArgs = Map.of("tags", (Object) allTags, "match", (Object) matchGlobs);

Grgit git = Grgit.open(openArgs);
// Get the tag given by describe
Expand All @@ -116,14 +141,33 @@ public String getVersion(WPILibVersioningPluginExtension extension, Project proj

}

Set<String> nonAnnotatedTags = new HashSet<>();

if (tags != null) {
for (Tag tg : tags) {
if (tg.getDateTime() == null) {
nonAnnotatedTags.add(tg.getCommit().getId());
}
}
}

if (!nonAnnotatedTags.isEmpty()) {
String failedCommits = String.join(",", nonAnnotatedTags);
throw this.problemReporter.throwing(builder -> builder
.id("non-annotated-tag", "Repository with non annotated tags are not supported")
.details("Commit hashes [" + failedCommits + "] have non annotated tag")
.withException(new IllegalStateException("Commit hashes [" + failedCommits + "] have non annotated tag"))
.solution("Please remove all annotated tags").severity(Severity.ERROR));
}

// If we found the tag matching describe
if (describeTag != null) {
String commitId = describeTag.getCommit().getId();

Tag newestTag = tags.stream()
.filter(x -> x.getCommit().getId().equals(commitId))
.sorted((x, y) -> x.getDateTime().compareTo(y.getDateTime()))
.reduce(null, (x, y) -> y);
.filter(x -> x.getCommit().getId().equals(commitId))
.sorted((x, y) -> x.getDateTime().compareTo(y.getDateTime()))
.reduce(null, (x, y) -> y);

// Replace describe tag with newest
tag = tag.replace(describeTag.getName(), newestTag.getName());
Expand All @@ -147,7 +191,8 @@ public String getVersion(WPILibVersioningPluginExtension extension, Project proj

versionBuilder.append(match.group(majorVersion));

// If this is a local build, we'll prepend 424242 to the minor version. This means that locally built versions will
// If this is a local build, we'll prepend 424242 to the minor version. This
// means that locally built versions will
// always resolve first in the tree
if (!extension.isBuildServerMode()) {
versionBuilder.append(".424242");
Expand All @@ -159,13 +204,15 @@ public String getVersion(WPILibVersioningPluginExtension extension, Project proj
versionBuilder.append('-').append(match.group(qualifier));
}

// For official builds, stop here. No date or repo status accounted for. Otherwise, keep appending new
// For official builds, stop here. No date or repo status accounted for.
// Otherwise, keep appending new
// version elements
if (extension.isReleaseMode())
return versionBuilder.toString();

// For jenkins builds, do not append the date
// This simplifies jenkins publishing because multiple commit builds can't happen.
// This simplifies jenkins publishing because multiple commit builds can't
// happen.
if (!extension.isBuildServerMode()) {
versionBuilder.append('-').append(extension.getTime().get());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
package edu.wpi.first.wpilib.versioning;

import javax.inject.Inject;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.problems.ProblemReporter;
import org.gradle.api.problems.Problems;

/**
* Determines the remote WPILib repository to use as well as determining the version of published artifacts. This is
* determined based on git
*/
public class WPILibVersioningPlugin implements Plugin<Project> {
private final ProblemReporter problemReporter;

@Inject
public WPILibVersioningPlugin(Problems problems) {
this.problemReporter = problems.getReporter();
}

@Override
public void apply(Project project) {
WPILibVersionProvider provider = new GitVersionProvider();
WPILibVersionProvider provider = new GitVersionProvider(problemReporter);
project.getExtensions().create("wpilibVersioning", WPILibVersioningPluginExtension.class, project, provider);
}
}
Loading