This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-resources-plugin.git
commit 8da665d23433b14ba3357573dc9bf104acd5a842 Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Wed Nov 4 18:39:03 2026 +0000 Make the MRESOURCES-99 and MRESOURCES-105 ITs fail on wrong output `return false` inside the `.each` closure only left the closure, so a missing key never failed MRESOURCES-99; its timestamp check also accepted an unreplaced expression. MRESOURCES-105 had no verify script at all. Fixes #569 --- src/it/MRESOURCES-105/verify.groovy | 27 +++++++ src/it/MRESOURCES-99/verify.groovy | 142 ++++++++---------------------------- 2 files changed, 56 insertions(+), 113 deletions(-) diff --git a/src/it/MRESOURCES-105/verify.groovy b/src/it/MRESOURCES-105/verify.groovy new file mode 100644 index 0000000..7b84fe7 --- /dev/null +++ b/src/it/MRESOURCES-105/verify.groovy @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def lines = new File(basedir, 'target/classes/test.properties').readLines() + +// the first line has to survive: it is the reason for the bug report +assert lines.contains('#init test value (true|false) LINE IS essential for this bug report.#') +// $toto.value$ is replaced +assert lines.contains('toto.value=foo') +// #test.value# and @test.value@ are replaced +assert lines.findAll { it.startsWith('test.value=') }.take(2) == ['test.value=true', 'test.value=true'] diff --git a/src/it/MRESOURCES-99/verify.groovy b/src/it/MRESOURCES-99/verify.groovy index b0b2e7d..1c7bf5d 100644 --- a/src/it/MRESOURCES-99/verify.groovy +++ b/src/it/MRESOURCES-99/verify.groovy @@ -17,120 +17,36 @@ * under the License. */ -import java.io.*; +def resource = new File(basedir, 'target/classes/SomeResource.txt') +assert resource.isFile() : 'target/classes/SomeResource.txt is missing' -import java.util.List; -import java.util.Collections; -import java.util.Arrays; - -boolean result = true; - -File target = new File( basedir, "target" ); -if ( !target.exists() || !target.isDirectory() ) -{ - System.err.println( "target folder is missing or not a directory." ); - return false; -} - -File someResource = new File( target, "/classes/SomeResource.txt" ); -if ( !someResource.exists() || someResource.isDirectory() ) -{ - System.err.println( "SomeResource.txt is missing or not a file." ); - return false; -} - -Properties props = new Properties(); - -try (FileInputStream fis = new FileInputStream( someResource )) { - props.load( fis ); -} -catch ( IOException ex ) -{ - System.err.println( "Failure during reading the properties " + someResource.getAbsolutePath() ); - return false; -} +def props = new Properties() +resource.withReader('ISO-8859-1') { reader -> props.load(reader) } +// each of these keys has to be present in the filtered file def keysWhichHaveToExist = [ - "timestamp", - "at.timestamp", - "build.timestamp", - "project.build.timestamp", - "baseUri", - "project.baseUri", - "pom.baseUri", - "at.baseUri", - "groupId", - "basedir", - "project.basedir", + 'timestamp', 'at.timestamp', 'build.timestamp', 'project.build.timestamp', + 'baseUri', 'project.baseUri', 'pom.baseUri', 'at.baseUri', + 'groupId', 'basedir', 'project.basedir', ] - - -keysWhichHaveToExist.each { key -> - if (!props.containsKey(key)) { - println "Missing the key '" + key + "'" - return false - } -} - -currentTimestamp = props.get("timestamp") -currentAtTimeStamp = props.get("at.timestamp") -if ( !currentTimestamp.equals (currentAtTimeStamp) - && !currentTimestamp.equals('${maven.build.timestamp}') - && !currentAtTimeStamp.equals('@maven.build.timestamp@') ) { - println 'The ${maven.build.timestamp} has not correctly being replaced.' - return false -} - -buildTimeStamp = props.get("build.timestamp") -if ( !buildTimeStamp.equals ('${build.timestamp}') ) { - println 'The ${build.timestamp} has been replaced.' - return false -} - -currentProjectBuildTimeStamp = props.get('project.build.timestamp') -if ( !currentProjectBuildTimeStamp.equals ('${project.build.timestamp}') ) { - println 'The ${project.build.timestamp} has been replaced.' - return false -} - -currentBaseUri = props.get('baseUri') -if ( !currentBaseUri.equals ('${baseUri}') ) { - println 'The ${baseUri} has been replaced.' - return false -} - -currentProjectBaseUri = props.get('project.baseUri') -if ( currentProjectBaseUri.equals ('${project.baseUri}') ) { - println 'The ${project.baseUri} has not been replaced.' - return false -} - -currentPomBaseUri = props.get('pom.baseUri') -if ( !currentPomBaseUri.equals ('${pom.baseUri}') ) { - println 'The ${pom.baseUri} has been replaced.' - return false -} - -currentAtBaseUri = props.get('at.baseUri') -if ( !currentAtBaseUri.equals ('@baseUri@') ) { - println 'The @baseUri@ has been replaced.' - return false -} - -currentGroupId = props.get('project.groupId') -if ( currentGroupId.equals ('${project.groupId}') ) { - println 'The ${project.groupId} has not been replaced.' - return false -} -currentBaseDir = props.get('basedir') -if ( currentBaseDir.equals ('${basedir}') ) { - println 'The ${basedir} has not been replaced.' - return false -} -currentProjectBaseDir = props.get('project.basedir') -if ( currentBaseDir.equals ('${project.basedir}') ) { - println 'The ${project.basedir} has not been replaced.' - return false -} - -return result; +for (key in keysWhichHaveToExist) { + assert props.containsKey(key) : "Missing the key '${key}'" +} + +// ${maven.build.timestamp} and @maven.build.timestamp@ are replaced by the plugin +def timestampFormat = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/ +assert props['timestamp'] ==~ timestampFormat : "\${maven.build.timestamp} was not replaced: ${props['timestamp']}" +assert props['at.timestamp'] == props['timestamp'] : "@maven.build.timestamp@ was not replaced the same way: ${props['at.timestamp']}" + +// only these expressions are replaced +assert props['project.baseUri'] == basedir.getAbsoluteFile().toURI().toString() +assert props['groupId'] == 'org.apache.maven.plugins' +assert props['basedir'] == basedir.getAbsolutePath() +assert props['project.basedir'] == basedir.getAbsolutePath() + +// these have no value in the filtering context and stay as they are +assert props['build.timestamp'] == '${build.timestamp}' +assert props['project.build.timestamp'] == '${project.build.timestamp}' +assert props['baseUri'] == '${baseUri}' +assert props['pom.baseUri'] == '${pom.baseUri}' +assert props['at.baseUri'] == '@baseUri@'
