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 {
def versionFile = file("build/resources/main/assets/plan/WebAssetVersion.yml")
versionFile.parentFile.mkdirs()
versionFile.text = "" // Clear previous build
ConfigurableFileTree tree = fileTree(dir: 'src/main/resources/assets/plan/web')
tree.forEach { File f ->
def gitModified = new ByteArrayOutputStream()
exec {
commandLine 'git', 'log', '-1', '--pretty=%ct', f.toString()
standardOutput = gitModified
doLast {
mkdir "build/resources/main/assets/plan"
def versionFile = file("build/resources/main/assets/plan/WebAssetVersion.yml")
versionFile.text = "" // Clear previous build
ConfigurableFileTree tree = fileTree(dir: 'src/main/resources/assets/plan/web')
tree.forEach { File f ->
def gitModified = new ByteArrayOutputStream()
exec {
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 {
dependsOn determineWebAssetModifications
duplicatesStrategy = DuplicatesStrategy.INCLUDE
dependsOn updateVersion
from 'build/sources/resources'
}
shadowJar {
dependsOn determineWebAssetModifications
dependsOn processResources
// Exclude these files

View File

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