Skip to content

Commit

Permalink
#194 Overwrite file if overwrite=true regardless of skipCache
Browse files Browse the repository at this point in the history
  • Loading branch information
longtimeago committed Aug 23, 2021
1 parent 05a6dc7 commit 8910347
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/it/overwriteWithSkippedCache/invoke.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = clean verify
invoker.buildResult = success
99 changes: 99 additions & 0 deletions src/it/overwriteWithSkippedCache/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<!-- Build description -->
<groupId>com.googlecode.maven-download-plugin.it</groupId>
<artifactId>testBasic</artifactId>
<packaging>pom</packaging>
<version>${testing.versionUnderTest}</version>
<name>Test</name>

<!-- Build plugins and extensions -->
<build>
<plugins>
<!-- Download the file first time -->
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>first-download</id>
<phase>generate-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>${test.img.file.url}</url>
<skipCache>true</skipCache>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
</plugin>
<!--
Store last modification timestamp of downloaded file into 'stamp' file
to be compared on verification stage.
-->
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>3.0.8</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<executions>
<execution>
<id>save-timestamp</id>
<phase>process-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
<target>${project.build.directory}</target>
<testfilename>${test.img.file.name}</testfilename>
</properties>
<scripts>
<script>
<![CDATA[
File file = new File(target, testfilename);
File stamp = new File(target, "stamp");
stamp << file.lastModified();
assert true;
]]>
</script>
</scripts>
</configuration>
</execution>
</executions>
</plugin>
<!-- Download the file second time -->
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>second-download</id>
<phase>prepare-package</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>${test.img.file.url}</url>
<skipCache>false</skipCache>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
21 changes: 21 additions & 0 deletions src/it/overwriteWithSkippedCache/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Covers the bug https://github.com/maven-download-plugin/maven-download-plugin/issues/194
*
* Scenario:
* Given plugin configuration:
* - skipCache = false (default)
* - overwrite = true
* - no checksum specified
* When Run the plugin to download the zip
* And Save timestamp into "stamp" file
* And Run the plugin to download the same zip
* Then the file should be overwritten
*
* `img_file_name` is injected through scriptVariables
*/
File target = new File(basedir, "target")
File zip = new File(target, img_file_name)
assert zip.exists()
File stamp = new File(target, "stamp")
assert stamp.exists() : "Timestamp file should exist"
assert stamp.text != String.valueOf(zip.lastModified()) : "File expected to be modified but it wasn't"
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
checksumMatch = false;
}
}
if (!checksumMatch) {
if (!checksumMatch || overwrite) {
outputFile.delete();
haveFile = false;
} else if (!overwrite) {
getLog().info("File already exist, skipping");
} else {
// If no checksum provided and owerwriting requested we
// will treat the fact as if there is no file in the cache.
haveFile = false;
getLog().info("File already exist, skipping");
}
}

Expand Down

0 comments on commit 8910347

Please sign in to comment.