Skip to content

Commit

Permalink
fix: lockfile should not be generated or validate if skip option is true
Browse files Browse the repository at this point in the history
  • Loading branch information
massimeddu-sj committed Oct 1, 2024
1 parent 3fd58a4 commit 582a5e5
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class GenerateLockFileMojo extends AbstractLockfileMojo {
public void execute() throws MojoExecutionException {
if (Boolean.parseBoolean(skip)) {
getLog().info("Skipping maven-lockfile");
return;
}
try {
LockFile lockFileFromFile =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ public class ValidateChecksumMojo extends AbstractLockfileMojo {
* @throws MojoExecutionException if the lock file is invalid or could not be read.
*/
public void execute() throws MojoExecutionException {
getLog().info("Validating lock file ...");
if (Boolean.parseBoolean(skip)) {
getLog().info("Skipping maven-lockfile");
return;
}
try {
getLog().info("Validating lock file ...");
Environment environment = generateMetaInformation();

LockFile lockFileFromFile = LockFile.readLockFile(getLockFilePath(project));
Expand Down
13 changes: 13 additions & 0 deletions maven_plugin/src/test/java/it/IntegrationTestsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,17 @@ public void orderedLockfile(MavenExecutionResult result) throws Exception {
boolean sorted = Ordering.natural().isOrdered(dependencyList);
assertThat(sorted).isTrue();
}

@MavenTest
public void skipLockfile(MavenExecutionResult result) throws Exception {
// contract: the dependency list should be ordered
assertThat(result).isSuccessful();
var fileExists = Files.find(
result.getMavenProjectResult().getTargetBaseDirectory(),
Integer.MAX_VALUE,
(path, attr) -> path.getFileName().toString().contains("lockfile.json"))
.findAny()
.isPresent();
assertThat(fileExists).isFalse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<project>
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1</version>
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.2</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.2</version>
<classifier>javadoc</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.github.chains-project</groupId>
<artifactId>
maven-lockfile</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package simpleProject.src.main.java;

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

0 comments on commit 582a5e5

Please sign in to comment.