Skip to content

Commit

Permalink
Tristan feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanemerson authored and tristantarrant committed Oct 1, 2024
1 parent 708eb7a commit caffddb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Stream;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand Down Expand Up @@ -50,6 +48,9 @@ public class ProtoCompatibilityMojo extends AbstractMojo {
@Parameter
private String remoteLockFiles;

@Parameter(defaultValue = "${session}")
private MavenSession session;

@Parameter(defaultValue = "false")
private boolean skip;

Expand All @@ -67,8 +68,7 @@ public void execute() throws MojoExecutionException {

Path lockFile = Paths.get(protoLockRoot, "proto.lock");
boolean lockFileExists = Files.exists(lockFile);
boolean remoteCheck = !remoteLockFiles.isEmpty();
if (!commitProtoLock && !lockFileExists && !remoteCheck) {
if (!commitProtoLock && !lockFileExists && !remoteCheck()) {
getLog().info("Ignoring protolock check as there isn't an existing proto.lock file, commitProtoLock=false and no remoteLockFiles are specified.");
return;
}
Expand Down Expand Up @@ -115,8 +115,13 @@ private ProtoLock protoLockFromDir(Path protoRoot) throws IOException {
}

private void checkRemoteCompatibility(ProtoLock currentState) throws IOException {
if (remoteLockFiles.isEmpty())
if (!remoteCheck())
return;

if (session.isOffline()) {
getLog().info("Skipping backwards compatibility check against remote files as maven is in Offline mode");
return;
}

for (String file : remoteLockFiles.split(",")) {
getLog().info(String.format("Checking backwards compatibility check against remote file '%s'", file));
Expand All @@ -127,4 +132,8 @@ private void checkRemoteCompatibility(ProtoLock currentState) throws IOException
getLog().info(String.format("Backwards compatibility check against remote file '%s' passed", file));
}
}

private boolean remoteCheck() {
return remoteLockFiles != null && !remoteLockFiles.isEmpty();
}
}
6 changes: 6 additions & 0 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${version.plugin.api}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand Down

0 comments on commit caffddb

Please sign in to comment.