-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from chali/ImproveJarCachingWithPropertiesFile…
…Metadata Metadata properties file content is ignored for up-to-date checks of jar tasks
- Loading branch information
Showing
6 changed files
with
109 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/groovy/nebula/plugin/info/reporting/PropertiesWriter.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package nebula.plugin.info.reporting | ||
|
||
import nebula.plugin.info.InfoBrokerPlugin | ||
import org.gradle.api.Project | ||
|
||
class PropertiesWriter { | ||
|
||
void writeProperties(File location, Project project) { | ||
InfoBrokerPlugin basePlugin = project.plugins.getPlugin(InfoBrokerPlugin) as InfoBrokerPlugin | ||
|
||
// Gather all values, in contrast to buildNonChangingManifest | ||
Map<String, String> attrs = basePlugin.buildManifest() | ||
|
||
String manifestStr = attrs.collect { "${it.key}=${it.value}"}.join('\n') | ||
location.text = manifestStr | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/test/groovy/nebula/plugin/info/reporting/InfoPropertiesFilePluginLauncherSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package nebula.plugin.info.reporting | ||
|
||
import nebula.plugin.info.InfoBrokerPlugin | ||
import nebula.plugin.info.basic.BasicInfoPlugin | ||
import nebula.test.IntegrationSpec | ||
|
||
import java.util.jar.JarFile | ||
|
||
|
||
class InfoPropertiesFilePluginLauncherSpec extends IntegrationSpec { | ||
def 'jar task is marked UP-TO-DATE if ran before successfully and metadata changes are ignored'() { | ||
writeHelloWorld('nebula.test') | ||
buildFile << """ | ||
${applyPlugin(InfoBrokerPlugin)} | ||
${applyPlugin(BasicInfoPlugin)} | ||
${applyPlugin(InfoJarPropertiesFilePlugin)} | ||
apply plugin: 'java' | ||
status = 'release' | ||
""".stripIndent() | ||
|
||
when: | ||
// Make sure we have some history already in place | ||
def result = runTasksSuccessfully('jar') | ||
runTasksSuccessfully('clean') | ||
|
||
result = runTasks('jar') | ||
|
||
then: | ||
File jarFile = new File(projectDir, "build/libs/${moduleName}.jar") | ||
jarFile.exists() | ||
Properties metadata = getPropertiesFromJar(jarFile) | ||
metadata['Built-Status'] == 'release' | ||
!result.wasUpToDate(':jar') | ||
|
||
when: 'Nothing has changed' | ||
def secondResult = runTasksSuccessfully('jar') | ||
|
||
then: | ||
secondResult.wasUpToDate(':jar') | ||
|
||
when: 'A manifest field was changed' | ||
buildFile << """ | ||
status = 'integration' | ||
""".stripIndent() | ||
def thirdResult = runTasksSuccessfully('jar') | ||
|
||
then: | ||
File reusedJar = new File(projectDir, "build/libs/${moduleName}.jar") | ||
reusedJar.exists() | ||
Properties staleMetadata = getPropertiesFromJar(reusedJar) | ||
//metadata change is ignored and cache is reused | ||
staleMetadata['Built-Status'] == 'release' | ||
thirdResult.wasUpToDate(':jar') | ||
} | ||
|
||
Properties getPropertiesFromJar(File jar) { | ||
def file = new JarFile(jar) | ||
def propertiesEntry = file.getEntry("META-INF/${moduleName}.properties") | ||
def result = new Properties() | ||
result.load(file.getInputStream(propertiesEntry)) | ||
result.each { | ||
println it | ||
} | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters