Fix WebAssetVersion.yml not being written with 'clean shadowJar'

This commit is contained in:
Risto Lahtela 2021-07-24 09:09:05 +03:00
parent a90f003462
commit 750428a033
2 changed files with 34 additions and 32 deletions

View File

@ -30,33 +30,35 @@ task updateVersion(type: Copy) {
} }
task determineWebAssetModifications { task determineWebAssetModifications {
def versionFile = file("build/resources/main/assets/plan/WebAssetVersion.yml") doLast {
versionFile.parentFile.mkdirs() mkdir "build/resources/main/assets/plan"
versionFile.text = "" // Clear previous build def versionFile = file("build/resources/main/assets/plan/WebAssetVersion.yml")
ConfigurableFileTree tree = fileTree(dir: 'src/main/resources/assets/plan/web') versionFile.text = "" // Clear previous build
tree.forEach { File f -> ConfigurableFileTree tree = fileTree(dir: 'src/main/resources/assets/plan/web')
def gitModified = new ByteArrayOutputStream() tree.forEach { File f ->
exec { def gitModified = new ByteArrayOutputStream()
commandLine 'git', 'log', '-1', '--pretty=%ct', f.toString() exec {
standardOutput = gitModified commandLine 'git', 'log', '-1', '--pretty=%ct', f.toString()
standardOutput = gitModified
}
// git returns UNIX time in seconds, but most things in Java use UNIX time in milliseconds
def modified = Long.parseLong(gitModified.toString().strip()) * 1000
def relativePath = tree.getDir().toPath().relativize(f.toPath()) // File path relative to the tree
versionFile.text += String.format( // writing YAML as raw text probably isn't the best idea
"%s: %s\n", relativePath.toString().replace('.', ','), modified
)
} }
// git returns UNIX time in seconds, but most things in Java use UNIX time in milliseconds
def modified = Long.parseLong(gitModified.toString().strip()) * 1000
def relativePath = tree.getDir().toPath().relativize(f.toPath()) // File path relative to the tree
versionFile.text += String.format( // writing YAML as raw text probably isn't the best idea
"%s: %s\n", relativePath.toString().replace('.', ','), modified
)
} }
} }
processResources { processResources {
dependsOn determineWebAssetModifications
duplicatesStrategy = DuplicatesStrategy.INCLUDE duplicatesStrategy = DuplicatesStrategy.INCLUDE
dependsOn updateVersion dependsOn updateVersion
from 'build/sources/resources' from 'build/sources/resources'
} }
shadowJar { shadowJar {
dependsOn determineWebAssetModifications
dependsOn processResources dependsOn processResources
// Exclude these files // Exclude these files

View File

@ -72,7 +72,7 @@ public class WebAssetVersionCheckTask extends TaskSystem.Task {
try { try {
webAssetVersions.prepare(); webAssetVersions.prepare();
} catch (IOException e) { } catch (IOException e) {
logger.warn("Could not read web asset versions, ", e); logger.warn(String.format("Could not read web asset versions, %s", e.toString()));
logger.warn("Web asset version check will be skipped!"); logger.warn("Web asset version check will be skipped!");
return; return;
} }
@ -92,27 +92,27 @@ public class WebAssetVersionCheckTask extends TaskSystem.Task {
} }
for (AssetInfo asset : outdated) { for (AssetInfo asset : outdated) {
logger.warn(String.format("- %s was modified %s, but the plugin contains a version from %s", logger.warn(String.format("- %s was modified %s, but the plugin contains a version from %s",
asset.filename, asset.filename,
formatters.secondLong().apply(asset.modifiedAt), formatters.secondLong().apply(asset.modifiedAt),
formatters.secondLong().apply(asset.expectedModifiedAt) formatters.secondLong().apply(asset.expectedModifiedAt)
)); ));
} }
} }
} }
private Optional<AssetInfo> findOutdatedResource(String resource) { private Optional<AssetInfo> findOutdatedResource(String resource) {
Optional<File> resourceFile = files.attemptToFind(resource); Optional<File> resourceFile = files.attemptToFind(resource);
Optional<Long> webAssetVersion = webAssetVersions.getWebAssetVersion(resource); Optional<Long> webAssetVersion = webAssetVersions.getWebAssetVersion(resource);
if (resourceFile.isPresent() && webAssetVersion.isPresent()) { if (resourceFile.isPresent() && webAssetVersion.isPresent()) {
if (webAssetVersion.get() > resourceFile.get().lastModified()) { if (webAssetVersion.get() > resourceFile.get().lastModified()) {
return Optional.of(new AssetInfo( return Optional.of(new AssetInfo(
resource, resource,
resourceFile.get().lastModified(), resourceFile.get().lastModified(),
webAssetVersion.get() webAssetVersion.get()
)); ));
} }
} }
return Optional.empty(); return Optional.empty();
} }
private Optional<ConfigNode> getPlanCustomizationNode() { private Optional<ConfigNode> getPlanCustomizationNode() {