Skip to content
Merged
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
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,12 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>git-commit-id-plugin-core</artifactId>
<version>6.1.5</version>
<version>6.2.0</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
<optional>true</optional>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down Expand Up @@ -326,8 +325,8 @@
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
</dependency>

<!-- dependencies to annotations -->
Expand Down
60 changes: 49 additions & 11 deletions src/main/java/pl/project13/maven/git/GitCommitIdMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecution;
Expand All @@ -44,7 +44,8 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.joda.time.DateTime;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.sonatype.plexus.build.incremental.BuildContext;
import pl.project13.core.CommitIdGenerationMode;
import pl.project13.core.CommitIdPropertiesOutputFormat;
Expand Down Expand Up @@ -1279,25 +1280,25 @@ public Supplier<String> supplyProjectVersion() {
return () -> project.getVersion();
}

@Nonnull
@NonNull
@Override
public LogInterface getLogInterface() {
return log;
}

@Nonnull
@NonNull
@Override
public String getDateFormat() {
return dateFormat;
}

@Nonnull
@NonNull
@Override
public String getDateFormatTimeZone() {
return dateFormatTimeZone;
}

@Nonnull
@NonNull
@Override
public String getPrefixDot() {
String trimmedPrefix = prefix.trim();
Expand Down Expand Up @@ -1443,8 +1444,8 @@ public boolean isPerModuleVersions() {
}

private void publishToAllSystemEnvironments(
@Nonnull LogInterface log,
@Nonnull Properties propertiesToPublish,
@NonNull LogInterface log,
@NonNull Properties propertiesToPublish,
@Nullable Properties contextProperties) {
publishPropertiesInto(propertiesToPublish, project.getProperties());
// some plugins rely on the user properties (e.g. flatten-maven-plugin)
Expand Down Expand Up @@ -1505,7 +1506,44 @@ protected static Date parseOutputTimestamp(String outputTimestamp) {
// no timestamp configured
return null;
}
return new DateTime(outputTimestamp).toDate();
// Normalize the timestamp to handle common variations
String normalized = outputTimestamp.trim();

// Handle lowercase designators
normalized = normalized.replace('t', 'T').replace('z', 'Z');

// Handle hours-only offsets by adding :00 minutes if needed
if (normalized.matches(".*[+-]\\d{2}$")) {
normalized = normalized.substring(0, normalized.length() - 3)
+ normalized.substring(normalized.length() - 3) + ":00";
}

// Try parsing with different formatters in order of preference
DateTimeFormatter[] formatters = {
DateTimeFormatter.ISO_INSTANT, // 2022-02-12T15:30:00Z
DateTimeFormatter.ISO_OFFSET_DATE_TIME, // 2022-02-12T15:30+00:00
DateTimeFormatter.ISO_LOCAL_DATE_TIME, // 2022-02-12T15:30:00
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mmZ"), // 2019-03-26T10:00-0400
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ"), // 2019-03-26T10:00:00-0400
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm") // 2022-02-12T15:30
};

for (DateTimeFormatter formatter : formatters) {
try {
if (
formatter == DateTimeFormatter.ISO_LOCAL_DATE_TIME
&&
(normalized.contains("+") || normalized.contains("-") || normalized.endsWith("Z"))
) {
continue; // Skip local formatter for timestamps with timezones
}
return Date.from(Instant.from(formatter.parse(normalized)));
} catch (DateTimeParseException ignore) {
// Try next formatter
}
}

throw new IllegalArgumentException("Unable to parse timestamp: " + outputTimestamp);
}

private void publishPropertiesInto(Properties propertiesToPublish, Properties propertiesTarget) {
Expand Down Expand Up @@ -1536,7 +1574,7 @@ private void logProperties(LogInterface log, Properties propertiesToPublish) {
}
}

private boolean isPomProject(@Nonnull MavenProject project) {
private boolean isPomProject(@NonNull MavenProject project) {
return project.getPackaging().equalsIgnoreCase("pom");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

import java.util.Collections;
import java.util.Optional;
import javax.annotation.Nonnull;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ResetCommand;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.jspecify.annotations.NonNull;
import org.junit.jupiter.api.Test;
import pl.project13.log.DummyTestLoggerBridge;
import pl.project13.maven.git.AvailableGitTestRepo;
Expand Down Expand Up @@ -448,11 +448,11 @@ public void shouldReturnJustTheNearestTagWhenAbbrevIsZero() throws Exception {
}
}

String abbrev(@Nonnull String id) {
String abbrev(@NonNull String id) {
return abbrev(id, DEFAULT_ABBREV_LEN);
}

String abbrev(@Nonnull String id, int n) {
String abbrev(@NonNull String id, int n) {
return id.substring(0, n);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package pl.project13.maven.git;

import java.io.File;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;

/**
* List of available git repositories that we can use to perform tests with.
Expand Down Expand Up @@ -168,7 +168,7 @@ public enum AvailableGitTestRepo {
this.dir = dir;
}

@Nonnull
@NonNull
public File getDir() {
return new File(dir);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package pl.project13.maven.git;

import java.util.Map;
import javax.annotation.Nonnull;
import org.assertj.core.api.Condition;
import org.jspecify.annotations.NonNull;

class ContainsKeyCondition extends Condition<Map<?, ?>> {

Expand All @@ -31,7 +31,7 @@ public ContainsKeyCondition(String key) {
}

@Override
public boolean matches(@Nonnull Map<?, ?> map) {
public boolean matches(@NonNull Map<?, ?> map) {
boolean containsKey = map.containsKey(key);
if (!containsKey) {
throw new RuntimeException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package pl.project13.maven.git;

import java.util.Map;
import javax.annotation.Nonnull;
import org.assertj.core.api.Condition;
import org.jspecify.annotations.NonNull;

class DoesNotContainKeyCondition extends Condition<Map<?, ?>> {

Expand All @@ -31,7 +31,7 @@ public DoesNotContainKeyCondition(String key) {
}

@Override
public boolean matches(@Nonnull Map<?, ?> map) {
public boolean matches(@NonNull Map<?, ?> map) {
boolean containsKey = map.containsKey(key);
if (containsKey) {
System.out.println(String.format("Map contained [%s] key! Map is: %s", key, map));
Expand Down
30 changes: 15 additions & 15 deletions src/test/java/pl/project13/maven/git/FileSystemMavenSandbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.io.FileUtils;
import org.apache.maven.project.MavenProject;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
* Quick and dirty maven projects tree structure to create on disk during integration tests. Can
Expand All @@ -50,57 +50,57 @@ public FileSystemMavenSandbox(String rootSandboxPath) {
this.rootSandboxPath = rootSandboxPath;
}

@Nonnull
@NonNull
public FileSystemMavenSandbox withParentProject(String parentProjectDirName, String packaging) {
parentProject =
createProject(new File(rootSandboxPath + File.separator + parentProjectDirName), packaging);
return this;
}

@Nonnull
@NonNull
public FileSystemMavenSandbox withNoChildProject() {
// no-op: marker for better tests readability
return this;
}

@Nonnull
@NonNull
public FileSystemMavenSandbox withChildProject(String childProjectDirName, String packaging) {
childProject =
createProject(new File(parentProject.getBasedir(), childProjectDirName), packaging);
childProject.setParent(parentProject);
return this;
}

@Nonnull
public FileSystemMavenSandbox withGitRepoInParent(@Nonnull AvailableGitTestRepo repo) {
@NonNull
public FileSystemMavenSandbox withGitRepoInParent(@NonNull AvailableGitTestRepo repo) {
System.out.println("TEST: Will prepare sandbox repository based on: [" + repo.getDir() + "]");

gitRepoSourceDir = repo.getDir();
gitRepoTargetDir = parentProject.getBasedir();
return this;
}

@Nonnull
public FileSystemMavenSandbox withGitRepoInChild(@Nonnull AvailableGitTestRepo repo) {
@NonNull
public FileSystemMavenSandbox withGitRepoInChild(@NonNull AvailableGitTestRepo repo) {
gitRepoSourceDir = repo.getDir();
gitRepoTargetDir = childProject.getBasedir();
return this;
}

@Nonnull
public FileSystemMavenSandbox withGitRepoAboveParent(@Nonnull AvailableGitTestRepo repo) {
@NonNull
public FileSystemMavenSandbox withGitRepoAboveParent(@NonNull AvailableGitTestRepo repo) {
gitRepoSourceDir = repo.getDir();
gitRepoTargetDir = new File(rootSandboxPath);
return this;
}

@Nonnull
@NonNull
public FileSystemMavenSandbox withNoGitRepoAvailable() {
gitRepoTargetDir = null;
return this;
}

@Nonnull
@NonNull
public FileSystemMavenSandbox create() throws RuntimeException {
try {
createParentDir();
Expand Down Expand Up @@ -145,7 +145,7 @@ public MavenProject getChildProject() {
return childProject;
}

@Nonnull
@NonNull
private MavenProject createProject(File basedir, String packaging) {
MavenProject project = new MavenProject();
project.setFile(new File(basedir + File.separator + "pom.xml"));
Expand All @@ -166,7 +166,7 @@ public String toString() {
+ '}';
}

@Nonnull
@NonNull
public FileSystemMavenSandbox withKeepSandboxWhenFinishedTest(
boolean keepSandboxWhenFinishedTest) {
// if we want to keep the generated sandbox for overwiew the content of it
Expand Down
12 changes: 5 additions & 7 deletions src/test/java/pl/project13/maven/git/GitIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package pl.project13.maven.git;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
Expand All @@ -27,18 +26,17 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import org.apache.commons.io.FileUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.eclipse.jgit.api.Git;
import org.jspecify.annotations.NonNull;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -115,8 +113,8 @@ protected Optional<String> projectDir() {
return Optional.empty();
}

@Nonnull
protected File dotGitDir(@Nonnull Optional<String> projectDir) {
@NonNull
protected File dotGitDir(@NonNull Optional<String> projectDir) {
if (projectDir.isPresent()) {
return new File(currSandbox + File.separator + projectDir.get() + File.separator + ".git");
} else {
Expand All @@ -143,7 +141,7 @@ public static void initializeMojoWithDefaults(GitCommitIdMojo mojo) {
mojo.settings = mockSettings();
}

public void setProjectToExecuteMojoIn(@Nonnull MavenProject project) {
public void setProjectToExecuteMojoIn(@NonNull MavenProject project) {
mojo.project = project;
mojo.dotGitDirectory = new File(project.getBasedir(), ".git");
mojo.reactorProjects = getReactorProjects(project);
Expand All @@ -162,7 +160,7 @@ private static Settings mockSettings() {
return settings;
}

private static List<MavenProject> getReactorProjects(@Nonnull MavenProject project) {
private static List<MavenProject> getReactorProjects(@NonNull MavenProject project) {
List<MavenProject> reactorProjects = new ArrayList<>();
MavenProject mavenProject = project;
while (mavenProject != null) {
Expand Down
Loading