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-invoker-plugin.git
commit 375f375abcc621ae294f21176c2a56832b27e094 Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Wed Nov 4 19:28:46 2026 +0000 Replace eight ITs with unit tests Raise cloneProjects, writeJunitReport and setupBuildLogFile from private to package-private so the tests can call them; nothing outside the class uses them. clone-clean and pom-filtering-reactor stay ITs: they assert behavior of addMissingDotMvnDirectory and collectProjects, which are not exposed. --- src/it/MINVOKER-190-logDirectory/pom.xml | 65 -------- .../src/it/module/pom.xml | 32 ---- src/it/MINVOKER-190-logDirectory/verify.groovy | 21 --- src/it/MINVOKER-196_junit_report_file/pom.xml | 75 --------- .../src/it/project/verify.groovy | 44 ----- .../src/it/project_2/pom.xml | 71 -------- .../src/it/project_2/verify.groovy | 20 --- .../src/it/settings.xml | 31 ---- .../MINVOKER-196_junit_report_file/verify.groovy | 51 ------ src/it/clone-none/invoker.properties | 18 --- src/it/clone-none/pom.xml | 64 -------- src/it/clone-none/verify.groovy | 24 --- src/it/filtering-extensions/pom.xml | 67 -------- .../src/it/no-pom-project/invoker.properties | 19 --- src/it/filtering-extensions/verify.groovy | 35 ---- src/it/pom-filtering-encoding/pom.xml | 68 -------- .../pom-filtering-encoding/src/it/latin-1/pom.xml | 54 ------- src/it/pom-filtering-encoding/src/it/utf-8/pom.xml | 54 ------- src/it/pom-filtering-encoding/verify.groovy | 73 --------- src/it/pom-filtering/pom.xml | 78 --------- src/it/pom-filtering/src/it/settings.xml | 55 ------- src/it/pom-filtering/verify.groovy | 93 ----------- src/it/skip-install/pom.xml | 58 ------- src/it/skip-install/test.properties | 19 --- src/it/skip-install/verify.groovy | 32 ---- src/it/skip-run/pom.xml | 66 -------- src/it/skip-run/src/it/project/pom.xml | 33 ---- src/it/skip-run/src/it/project/prebuild.groovy | 26 --- src/it/skip-run/test.properties | 19 --- src/it/skip-run/verify.groovy | 41 ----- .../maven/plugins/invoker/AbstractInvokerMojo.java | 6 +- .../plugins/invoker/BuildOutputFilesTest.java | 178 +++++++++++++++++++++ .../maven/plugins/invoker/InstallMojoTest.java | 47 ++++++ .../maven/plugins/invoker/InvokerMojoTest.java | 15 ++ .../maven/plugins/invoker/ProjectCloningTest.java | 160 ++++++++++++++++++ .../extensions}/no-pom-project/.mvn/extensions.xml | 0 .../extensions}/project/.mvn/extensions.xml | 0 .../filtering/extensions}/project/pom.xml | 0 .../pom-filtering-encoding/latin-1}/pom.xml | 7 +- .../pom-filtering-encoding/utf-8}/pom.xml | 5 +- .../filtering/pom-filtering}/project/pom.xml | 19 --- 41 files changed, 412 insertions(+), 1431 deletions(-) diff --git a/src/it/MINVOKER-190-logDirectory/pom.xml b/src/it/MINVOKER-190-logDirectory/pom.xml deleted file mode 100644 index 46237d9..0000000 --- a/src/it/MINVOKER-190-logDirectory/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<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> - - <groupId>org.apache.maven.plugins.invoker</groupId> - <artifactId>project-cloning</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>pom</packaging> - - <description>Test to check for proper project cloning</description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-invoker-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> - <pomIncludes> - <pomInclude>**/pom.xml</pomInclude> - </pomIncludes> - <logDirectory>${project.build.directory}/it-logs</logDirectory> - <goals> - <goal>validate</goal> - </goals> - </configuration> - <executions> - <execution> - <id>integration-test</id> - <phase>initialize</phase> - <goals> - <goal>run</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> diff --git a/src/it/MINVOKER-190-logDirectory/src/it/module/pom.xml b/src/it/MINVOKER-190-logDirectory/src/it/module/pom.xml deleted file mode 100644 index 5badb32..0000000 --- a/src/it/MINVOKER-190-logDirectory/src/it/module/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<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> - <groupId>org.apache.maven.test</groupId> - <artifactId>unit</artifactId> - <version>0.1-SNAPSHOT</version> - <packaging>pom</packaging> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> -</project> diff --git a/src/it/MINVOKER-190-logDirectory/verify.groovy b/src/it/MINVOKER-190-logDirectory/verify.groovy deleted file mode 100644 index 514b93d..0000000 --- a/src/it/MINVOKER-190-logDirectory/verify.groovy +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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. - */ - -assert !(new File(basedir,'target/it/module/build.log').exists()) -assert new File(basedir,'target/it-logs/module/build.log').exists() diff --git a/src/it/MINVOKER-196_junit_report_file/pom.xml b/src/it/MINVOKER-196_junit_report_file/pom.xml deleted file mode 100644 index b6d11cc..0000000 --- a/src/it/MINVOKER-196_junit_report_file/pom.xml +++ /dev/null @@ -1,75 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<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> - - <groupId>org.apache.maven.plugins.invoker</groupId> - <artifactId>junit-report-file</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>jar</packaging> - - <description> - Test to check for proper generation of junit report files - </description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <build> - <plugins> - <plugin> - <!-- This triggers the download of a known version of this plugin which can then be safely invoked by the IT project --> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-resources-plugin</artifactId> - <version>@version.maven-resources-plugin@</version> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-invoker-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <ignoreFailures>true</ignoreFailures> - <writeJunitReport>true</writeJunitReport> - <postBuildHookScript>verify</postBuildHookScript> - <localRepositoryPath>${project.build.directory}/it-repo</localRepositoryPath> - <settingsFile>src/it/settings.xml</settingsFile> - <goals> - <!-- Maven 4 require strict checksum by default, so relax here --> - <goal>-c</goal> - <goal>validate</goal> - </goals> - </configuration> - <executions> - <execution> - <id>integration-test</id> - <phase>initialize</phase> - <goals> - <goal>run</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> diff --git a/src/it/MINVOKER-196_junit_report_file/src/it/project/verify.groovy b/src/it/MINVOKER-196_junit_report_file/src/it/project/verify.groovy deleted file mode 100644 index a3406a7..0000000 --- a/src/it/MINVOKER-196_junit_report_file/src/it/project/verify.groovy +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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. - */ - -import groovy.xml.XmlSlurper - -// ensure script context contains localRepositoryPath -assert new File( basedir, "../../../target/it-repo" ).canonicalFile.equals( localRepositoryPath ) - -File interpolatedSettings = new File( basedir, "../interpolated-settings.xml" ) -assert interpolatedSettings.isFile() - -def filename = new File( basedir, "../../../../../local-repo" ).canonicalPath -// Convert URL, see org.apache.maven.plugins.invoker.AbstractInvokerMojo.toUrl(String) -String url = "file://" + new File( filename ).toURI().path -if ( url.endsWith( "/" ) ) -{ - url = url.substring( 0, url.length() - 1 ) -} - -def settings = new XmlSlurper().parse( interpolatedSettings ) - -// ensure right settings and mirror are picked up -def sandboxMirror = settings.mirrors.mirror[0] -assert sandboxMirror.id.text() == "sandbox" -assert sandboxMirror.url.text() != "@localRepositoryUrl@" - -// sandboxMirror.url is NOT filled with localRepositoryPath, but with the localRepository of the parent Settings -assert sandboxMirror.url.text() == url diff --git a/src/it/MINVOKER-196_junit_report_file/src/it/project_2/pom.xml b/src/it/MINVOKER-196_junit_report_file/src/it/project_2/pom.xml deleted file mode 100644 index 1268201..0000000 --- a/src/it/MINVOKER-196_junit_report_file/src/it/project_2/pom.xml +++ /dev/null @@ -1,71 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<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> - <groupId>test</groupId> - <artifactId>pom-filtering-junit-report</artifactId> - <version>0.1-SNAPSHOT</version> - <packaging>jar</packaging> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <!-- ${...} must be left unfiltered --> - <prop0>${project.version}</prop0> - <!-- these must be filtered --> - <prop1>@project.version@</prop1> - <prop2>@propertyFromPluginConfig@</prop2> - <prop3>@propertyFromPropertiesSection@</prop3> - <!-- this must not be resolved to project.version, i.e. the prefix matters --> - <prop4>@project-is-not-the-pom.version@</prop4> - <!-- POM values must precede other properties --> - <prop5>@project.name@</prop5> - <prop6>@pom.name@</prop6> - <!-- properties from the plugin config must precede values from the POM's <properties> section --> - <prop7>@itProperty@</prop7> - <!-- properties with prefix "project"/"pom" must fallback to plugin config if no matching POM value exists --> - <prop8>@project.nonExistingPomValue@</prop8> - <!-- built-in properties must not be overridden by properties from the plugin configuration --> - <prop9>@basedir@</prop9> - <prop10>@baseurl@</prop10> - <prop11>@localRepository@</prop11> - <prop12>@localRepositoryUrl@</prop12> - </properties> - - <build> - <!-- using the Resources Plugin to create a backup of the executed POM for later inspection by the parent build --> - <resources> - <resource> - <directory>${basedir}</directory> - <filtering>false</filtering> - <includes> - <include>*.xml</include> - </includes> - </resource> - </resources> - <plugins> - <plugin> - <artifactId>maven-resources-plugin</artifactId> - <version>@version.maven-resources-plugin@</version> - </plugin> - </plugins> - </build> -</project> diff --git a/src/it/MINVOKER-196_junit_report_file/src/it/project_2/verify.groovy b/src/it/MINVOKER-196_junit_report_file/src/it/project_2/verify.groovy deleted file mode 100644 index ddf46fe..0000000 --- a/src/it/MINVOKER-196_junit_report_file/src/it/project_2/verify.groovy +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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. - */ - -assert new File( basedir, "../../../target/it-repo_not_here" ).canonicalFile.equals( localRepositoryPath ) diff --git a/src/it/MINVOKER-196_junit_report_file/src/it/settings.xml b/src/it/MINVOKER-196_junit_report_file/src/it/settings.xml deleted file mode 100644 index ca7b8ab..0000000 --- a/src/it/MINVOKER-196_junit_report_file/src/it/settings.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<settings> - <mirrors> - <mirror> - <id>sandbox</id> - <name>A completely isolated repo to test the interpolation of "localRepositoryUrl"</name> - <url>@localRepositoryUrl@</url> - <mirrorOf>*</mirrorOf> - </mirror> - </mirrors> -</settings> diff --git a/src/it/MINVOKER-196_junit_report_file/verify.groovy b/src/it/MINVOKER-196_junit_report_file/verify.groovy deleted file mode 100644 index d0b4ca7..0000000 --- a/src/it/MINVOKER-196_junit_report_file/verify.groovy +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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. - */ -import groovy.xml.XmlSlurper - -File invokerReports = new File(new File(basedir, "target"), 'invoker-reports-test') -assert invokerReports.exists() - -// test on first project -def testsuite = new XmlSlurper().parse(new File(invokerReports, "TEST-project.xml")) - -assert [email protected]() != null -assert [email protected]() != null -assert [email protected]() == "1" -assert [email protected]() == "0" -assert [email protected]() == "0" -assert [email protected]() == "0" - -assert [email protected]() == "project" -def systemOut = testsuite.testcase.'**'.findAll {node -> node.name() == 'system-out'}.get(0) -assert !systemOut.text().isEmpty() - - -// test on second project -testsuite = new XmlSlurper().parse(new File(invokerReports, "TEST-project_2.xml")) - -assert [email protected]() != null -assert [email protected]() != null -assert [email protected]() == "1" -assert [email protected]() == "0" -assert [email protected]() == "0" -assert [email protected]() == "1" - -assert [email protected]() == "project_2" -def failureMessage = testsuite.testcase.failure.@message -assert !failureMessage.text().isEmpty() diff --git a/src/it/clone-none/invoker.properties b/src/it/clone-none/invoker.properties deleted file mode 100644 index 1e1876a..0000000 --- a/src/it/clone-none/invoker.properties +++ /dev/null @@ -1,18 +0,0 @@ -# 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. - -invoker.goals = initialize diff --git a/src/it/clone-none/pom.xml b/src/it/clone-none/pom.xml deleted file mode 100644 index 675f153..0000000 --- a/src/it/clone-none/pom.xml +++ /dev/null @@ -1,64 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<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> - - <groupId>org.apache.maven.plugins.invoker</groupId> - <artifactId>clone-none-invocation</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>pom</packaging> - - <description>Test to check for special value none for cloneProjectsTo</description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-invoker-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <cloneProjectsTo>none</cloneProjectsTo> - <pomIncludes> - <pomInclude>*/pom.xml</pomInclude> - </pomIncludes> - <goals> - <goal>validate</goal> - </goals> - </configuration> - <executions> - <execution> - <id>integration-test</id> - <phase>initialize</phase> - <goals> - <goal>run</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> diff --git a/src/it/clone-none/verify.groovy b/src/it/clone-none/verify.groovy deleted file mode 100644 index 35c76c0..0000000 --- a/src/it/clone-none/verify.groovy +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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. - */ - - -assert !new File(basedir, "target/it/clone-none").exists() - -// without clone, the build log should be created in the source directory -assert new File(basedir, "src/it/clone-none/build.log").exists() diff --git a/src/it/filtering-extensions/pom.xml b/src/it/filtering-extensions/pom.xml deleted file mode 100644 index 973cb41..0000000 --- a/src/it/filtering-extensions/pom.xml +++ /dev/null @@ -1,67 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<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> - - <groupId>org.apache.maven.plugins.invoker</groupId> - <artifactId>pom-filtering</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>pom</packaging> - - <name>PASSED</name> - <description>Test to check for proper filtering of .mvn/extensions.xml, also for a project without a POM</description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-invoker-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <debug>true</debug> - <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> - <pomIncludes> - <pomInclude>*/pom.xml</pomInclude> - <pomInclude>no-pom-project</pomInclude> - </pomIncludes> - <goals> - <goal>validate</goal> - </goals> - </configuration> - <executions> - <execution> - <id>integration-test</id> - <phase>initialize</phase> - <goals> - <goal>run</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> diff --git a/src/it/filtering-extensions/src/it/no-pom-project/invoker.properties b/src/it/filtering-extensions/src/it/no-pom-project/invoker.properties deleted file mode 100644 index 8fd9cb9..0000000 --- a/src/it/filtering-extensions/src/it/no-pom-project/invoker.properties +++ /dev/null @@ -1,19 +0,0 @@ -# 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. - -# a project without a pom.xml - Maven is executed on a mere directory -invoker.goals = --version diff --git a/src/it/filtering-extensions/verify.groovy b/src/it/filtering-extensions/verify.groovy deleted file mode 100644 index 941b4e3..0000000 --- a/src/it/filtering-extensions/verify.groovy +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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. - */ - -// 'project' has a pom.xml, 'no-pom-project' has not - in both cases .mvn/extensions.xml must be filtered -for ( String project : [ 'project', 'no-pom-project' ] ) { - - File extensionsFile = new File( basedir, "target/it/${project}/.mvn/extensions.xml" ) - assert extensionsFile.isFile() : "filtered extensions.xml not found: ${extensionsFile}" - - String xml = extensionsFile.getText( 'UTF-8' ) - - assert xml.contains( '<groupId>org.apache.maven.plugins.invoker</groupId>' ) - assert xml.contains( '<artifactId>pom-filtering</artifactId>' ) - assert xml.contains( '<version>1.0-SNAPSHOT</version>' ) - - assert !xml.contains( '@project.groupId@' ) - assert !xml.contains( '@project.artifactId@' ) - assert !xml.contains( '@project.version@' ) -} diff --git a/src/it/pom-filtering-encoding/pom.xml b/src/it/pom-filtering-encoding/pom.xml deleted file mode 100644 index d07c139..0000000 --- a/src/it/pom-filtering-encoding/pom.xml +++ /dev/null @@ -1,68 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<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> - - <groupId>org.apache.maven.plugins.invoker</groupId> - <artifactId>pom-filtering-encoding</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>pom</packaging> - - <description>Test to check for proper handling of file encoding during POM filtering.</description> - - <properties> - <version.maven-resources-plugin>@version.maven-resources-plugin@</version.maven-resources-plugin> - </properties> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-invoker-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <debug>true</debug> - <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> - <pomIncludes> - <pomInclude>*/pom.xml</pomInclude> - </pomIncludes> - <goals> - <goal>process-resources</goal> - </goals> - <filterProperties> - <latin1Chars>©®ÄÖÜäöüß</latin1Chars> - </filterProperties> - </configuration> - <executions> - <execution> - <id>integration-test</id> - <phase>initialize</phase> - <goals> - <goal>run</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> diff --git a/src/it/pom-filtering-encoding/src/it/latin-1/pom.xml b/src/it/pom-filtering-encoding/src/it/latin-1/pom.xml deleted file mode 100644 index 236d1bd..0000000 --- a/src/it/pom-filtering-encoding/src/it/latin-1/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> - -<!-- -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. ---> - -<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> - <groupId>test</groupId> - <artifactId>pom-filtering-encoding-latin1</artifactId> - <version>0.1-SNAPSHOT</version> - <packaging>jar</packaging> - - <!-- NOTE: This file's encoding is ISO-8859-1 by test design --> - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <prop0>���������</prop0> - <prop1>@latin1Chars@</prop1> - </properties> - - <build> - <!-- using the Resources Plugin to create a backup of the executed POM for later inspection by the parent build --> - <resources> - <resource> - <directory>${basedir}</directory> - <filtering>false</filtering> - <includes> - <include>*.xml</include> - </includes> - </resource> - </resources> - <plugins> - <plugin> - <artifactId>maven-resources-plugin</artifactId> - <version>@version.maven-resources-plugin@</version> - </plugin> - </plugins> - </build> -</project> diff --git a/src/it/pom-filtering-encoding/src/it/utf-8/pom.xml b/src/it/pom-filtering-encoding/src/it/utf-8/pom.xml deleted file mode 100644 index 069c1c2..0000000 --- a/src/it/pom-filtering-encoding/src/it/utf-8/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<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> - <groupId>test</groupId> - <artifactId>pom-filtering-encoding-utf8</artifactId> - <version>0.1-SNAPSHOT</version> - <packaging>jar</packaging> - - <!-- NOTE: This file's encoding is UTF-8 by test design --> - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <prop0>©®ÄÖÜäöüß</prop0> - <prop1>@latin1Chars@</prop1> - </properties> - - <build> - <!-- using the Resources Plugin to create a backup of the executed POM for later inspection by the parent build --> - <resources> - <resource> - <directory>${basedir}</directory> - <filtering>false</filtering> - <includes> - <include>*.xml</include> - </includes> - </resource> - </resources> - <plugins> - <plugin> - <artifactId>maven-resources-plugin</artifactId> - <version>@version.maven-resources-plugin@</version> - </plugin> - </plugins> - </build> -</project> diff --git a/src/it/pom-filtering-encoding/verify.groovy b/src/it/pom-filtering-encoding/verify.groovy deleted file mode 100644 index b0784ee..0000000 --- a/src/it/pom-filtering-encoding/verify.groovy +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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. - */ - -import java.io.*; -import java.util.*; -import java.util.regex.*; - -import org.codehaus.plexus.util.*; - -boolean check( String project, String encoding ) -{ - File pomFile = new File( basedir, "target/it/" + project + "/pom.xml" ); - System.out.println( "Checking for existence of original IT POM: " + pomFile ); - if ( !pomFile.exists() ) - { - System.out.println( "FAILED!" ); - return false; - } - - pomFile = new File( basedir, "target/it/" + project + "/target/classes/pom.xml" ); - System.out.println( "Checking for existence of interpolated IT POM: " + pomFile ); - if ( !pomFile.exists() ) - { - System.out.println( "FAILED!" ); - return false; - } - - String xml = FileUtils.fileRead( pomFile, encoding ); - - String[] values = [ - "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>", - "<prop0>\u00A9\u00AE\u00C4\u00D6\u00DC\u00E4\u00F6\u00FC\u00DF</prop0>", - "<prop1>\u00A9\u00AE\u00C4\u00D6\u00DC\u00E4\u00F6\u00FC\u00DF</prop1>", - ]; - for ( String value : values ) - { - System.out.println( "Checking for occurrence of: " + value ); - if ( xml.indexOf( value ) < 0 ) - { - System.out.println( "FAILED!" ); - return false; - } - } - return true; -} - -try -{ - return check( "latin-1", "ISO-8859-1" ) && check( "utf-8", "UTF-8" ); -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} - -return true; diff --git a/src/it/pom-filtering/pom.xml b/src/it/pom-filtering/pom.xml deleted file mode 100644 index 047e5a5..0000000 --- a/src/it/pom-filtering/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<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> - - <groupId>org.apache.maven.plugins.invoker</groupId> - <artifactId>pom-filtering</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>pom</packaging> - - <name>PASSED</name> - <description>Test to check for proper filtering of IT POMs</description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <propertyFromPropertiesSection>PROPERTY-FROM-PROPERTIES-SECTION</propertyFromPropertiesSection> - <itProperty>FAILED</itProperty> - <version.maven-resources-plugin>@version.maven-resources-plugin@</version.maven-resources-plugin> - </properties> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-invoker-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <debug>true</debug> - <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> - <pomIncludes> - <pomInclude>*/pom.xml</pomInclude> - </pomIncludes> - <goals> - <goal>process-resources</goal> - </goals> - <filterProperties> - <propertyFromPluginConfig>PROPERTY-FROM-PLUGIN-CONFIG</propertyFromPluginConfig> - <project-is-not-the-pom.version>PASSED</project-is-not-the-pom.version> - <project.name>FAILED</project.name> - <itProperty>PASSED</itProperty> - <project.nonExistingPomValue>PASSED</project.nonExistingPomValue> - <basedir>FAILED</basedir> - <baseurl>FAILED</baseurl> - </filterProperties> - </configuration> - <executions> - <execution> - <id>integration-test</id> - <phase>initialize</phase> - <goals> - <goal>run</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> diff --git a/src/it/pom-filtering/src/it/settings.xml b/src/it/pom-filtering/src/it/settings.xml deleted file mode 100644 index 79c5dc1..0000000 --- a/src/it/pom-filtering/src/it/settings.xml +++ /dev/null @@ -1,55 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<settings> - <profiles> - <profile> - <id>it-repo</id> - <activation> - <activeByDefault>true</activeByDefault> - </activation> - <repositories> - <repository> - <id>local.central</id> - <url>file://@localRepository@</url> - <releases> - <enabled>true</enabled> - </releases> - <snapshots> - <enabled>true</enabled> - </snapshots> - </repository> - </repositories> - <pluginRepositories> - <pluginRepository> - <id>local.central</id> - <url>file://@localRepository@</url> - <releases> - <enabled>true</enabled> - </releases> - <snapshots> - <enabled>true</enabled> - </snapshots> - </pluginRepository> - </pluginRepositories> - </profile> - </profiles> -</settings> diff --git a/src/it/pom-filtering/verify.groovy b/src/it/pom-filtering/verify.groovy deleted file mode 100644 index 0525f3c..0000000 --- a/src/it/pom-filtering/verify.groovy +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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. - */ - -import java.io.*; -import java.util.*; -import java.util.regex.*; - -import org.codehaus.plexus.util.*; - -try -{ - File pomFile = new File( basedir, "target/it/project/pom.xml" ); - System.out.println( "Checking for existence of original IT POM: " + pomFile ); - if ( !pomFile.exists() ) - { - System.out.println( "FAILED!" ); - return false; - } - - pomFile = new File( basedir, "target/it/project/target/classes/pom.xml" ); - System.out.println( "Checking for existence of interpolated IT POM: " + pomFile ); - if ( !pomFile.exists() ) - { - System.out.println( "FAILED!" ); - return false; - } - - String xml = FileUtils.fileRead( pomFile, "UTF-8" ); - - String[] values = [ - '<prop0>${project.version}</prop0>', - "<prop1>1.0-SNAPSHOT</prop1>", - "<prop2>PROPERTY-FROM-PLUGIN-CONFIG</prop2>", - "<prop3>PROPERTY-FROM-PROPERTIES-SECTION</prop3>", - "<prop4>PASSED</prop4>", - "<prop5>PASSED</prop5>", - "<prop6>PASSED</prop6>", - "<prop7>PASSED</prop7>", - "<prop8>PASSED</prop8>", - "<prop10>file:///", - "<prop12>file:///", - ]; - for ( String value : values ) - { - System.out.println( "Checking for occurrence of: " + value ); - if ( xml.indexOf( value ) < 0 ) - { - System.out.println( "FAILED!" ); - return false; - } - } - - String[] badValues = [ - "<prop9>@basedir@</prop9>", - "<prop9>FAILED</prop9>", - "<prop10>@baseurl@</prop10>", - "<prop10>FAILED</prop10>", - "<prop11>@localRepository@</prop11>", - "<prop12>@localRepositoryUrl@</prop12>", - ]; - for ( String value : badValues ) - { - System.out.println( "Checking for absence of: " + value ); - if ( xml.indexOf( value ) >= 0 ) - { - System.out.println( "FAILED!" ); - return false; - } - } -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} - -return true; diff --git a/src/it/skip-install/pom.xml b/src/it/skip-install/pom.xml deleted file mode 100644 index f82147e..0000000 --- a/src/it/skip-install/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<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> - - <groupId>org.apache.maven.plugins.invoker</groupId> - <artifactId>skip-install</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>pom</packaging> - - <description>Test to check that invoker.skip=true will skip all installations</description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-invoker-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <localRepositoryPath>${project.build.directory}/it-repo</localRepositoryPath> - </configuration> - <executions> - <execution> - <id>integration-test</id> - <phase>initialize</phase> - <goals> - <goal>install</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> diff --git a/src/it/skip-install/test.properties b/src/it/skip-install/test.properties deleted file mode 100644 index 55c9712..0000000 --- a/src/it/skip-install/test.properties +++ /dev/null @@ -1,19 +0,0 @@ -# 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. - -# NOTE: Skipping from the CLI is the primary use case so we prefer the system property over the direct POM configuration -invoker.skip = true diff --git a/src/it/skip-install/verify.groovy b/src/it/skip-install/verify.groovy deleted file mode 100644 index 6e7049b..0000000 --- a/src/it/skip-install/verify.groovy +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ - -import java.io.*; -import java.util.*; -import java.util.regex.*; - -File itRepoDir = new File( basedir, "target/it-repo" ); -System.out.println( "Checking for absence of: " + itRepoDir ); -if ( itRepoDir.isDirectory() ) -{ - throw new IllegalStateException( "Creation of staging repository was not skipped: " + itRepoDir ); - return false; -} - -return true; diff --git a/src/it/skip-run/pom.xml b/src/it/skip-run/pom.xml deleted file mode 100644 index c09f180..0000000 --- a/src/it/skip-run/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<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> - - <groupId>org.apache.maven.plugins.invoker</groupId> - <artifactId>skip-run</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>pom</packaging> - - <description>Test to check that invoker.skip=true will skip all invocations</description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-invoker-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <writeJunitReport>true</writeJunitReport> - <debug>true</debug> - <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> - <pomIncludes> - <pomInclude>*/pom.xml</pomInclude> - </pomIncludes> - <goals> - <goal>validate</goal> - </goals> - </configuration> - <executions> - <execution> - <id>integration-test</id> - <phase>initialize</phase> - <goals> - <goal>run</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> diff --git a/src/it/skip-run/src/it/project/pom.xml b/src/it/skip-run/src/it/project/pom.xml deleted file mode 100644 index 584300c..0000000 --- a/src/it/skip-run/src/it/project/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<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"> - <!-- invalid model version to make build fail --> - <modelVersion>99.0.0</modelVersion> - <groupId>test</groupId> - <artifactId>skip-invoker</artifactId> - <version>0.1-SNAPSHOT</version> - <packaging>jar</packaging> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> -</project> diff --git a/src/it/skip-run/src/it/project/prebuild.groovy b/src/it/skip-run/src/it/project/prebuild.groovy deleted file mode 100644 index 7391f5a..0000000 --- a/src/it/skip-run/src/it/project/prebuild.groovy +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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. - */ - -import java.io.*; - -// marker for parent build that this sub build was indeed run -File touchFile = new File( basedir, "touch.txt" ); -touchFile.createNewFile(); - -return true; diff --git a/src/it/skip-run/test.properties b/src/it/skip-run/test.properties deleted file mode 100644 index 55c9712..0000000 --- a/src/it/skip-run/test.properties +++ /dev/null @@ -1,19 +0,0 @@ -# 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. - -# NOTE: Skipping from the CLI is the primary use case so we prefer the system property over the direct POM configuration -invoker.skip = true diff --git a/src/it/skip-run/verify.groovy b/src/it/skip-run/verify.groovy deleted file mode 100644 index 718cf1f..0000000 --- a/src/it/skip-run/verify.groovy +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - */ - -import java.io.*; -import java.util.*; -import java.util.regex.*; - -try -{ - // make sure the Invoker Plugin was indeed NOT run and the build didn't fail somewhere else - File touchFile = new File( basedir, "target/it/project/touch.txt" ); - System.out.println( "Checking for non-existence of touch file: " + touchFile ); - if ( touchFile.exists() ) - { - System.out.println( "FAILED!" ); - return false; - } -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} - -return true; diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java index 48384ed..fc62411 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java +++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java @@ -1169,7 +1169,7 @@ public abstract class AbstractInvokerMojo extends AbstractMojo { * <code>null</code> nor contain <code>null</code> elements. * @throws org.apache.maven.plugin.MojoExecutionException If the projects could not be copied/filtered. */ - private void cloneProjects(Collection<String> projectPaths) throws MojoExecutionException { + void cloneProjects(Collection<String> projectPaths) throws MojoExecutionException { if (!cloneProjectsTo.mkdirs() && cloneClean) { try { FileUtils.cleanDirectory(cloneProjectsTo); @@ -1832,7 +1832,7 @@ public abstract class AbstractInvokerMojo extends AbstractMojo { } } - private void writeJunitReport(BuildJob buildJob, String safeFileName) throws MojoExecutionException { + void writeJunitReport(BuildJob buildJob, String safeFileName) throws MojoExecutionException { File reportFile = new File(reportsDirectory, "TEST-" + safeFileName + ".xml"); Xpp3Dom testsuite = new Xpp3Dom("testsuite"); testsuite.setAttribute("name", junitPackageName + "." + safeFileName); @@ -2123,7 +2123,7 @@ public abstract class AbstractInvokerMojo extends AbstractMojo { * @return The build logger or <code>null</code> if logging has been disabled. * @throws org.apache.maven.plugin.MojoExecutionException If the log file could not be created. */ - private FileLogger setupBuildLogFile(File basedir, int executionCount) throws MojoExecutionException { + FileLogger setupBuildLogFile(File basedir, int executionCount) throws MojoExecutionException { FileLogger logger = null; if (!noLog) { diff --git a/src/test/java/org/apache/maven/plugins/invoker/BuildOutputFilesTest.java b/src/test/java/org/apache/maven/plugins/invoker/BuildOutputFilesTest.java new file mode 100644 index 0000000..7f81b7a --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/invoker/BuildOutputFilesTest.java @@ -0,0 +1,178 @@ +/* + * 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. + */ +package org.apache.maven.plugins.invoker; + +import javax.xml.parsers.DocumentBuilderFactory; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.maven.plugins.invoker.model.BuildJob; +import org.codehaus.plexus.util.ReflectionUtils; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.w3c.dom.Element; + +import static org.apache.maven.plugins.invoker.TestUtil.setVariableValueToObject; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests the files the invoker writes next to or about a build: the build log and the JUnit report. + */ +class BuildOutputFilesTest { + + @TempDir + Path tempDir; + + private final InvokerMojo mojo = new InvokerMojo(null, null, null, null); + + @BeforeEach + void setUp() throws Exception { + setVariableValueToObject( + mojo, "projectsDirectory", tempDir.resolve("src/it").toFile()); + } + + private void closeLogger(FileLogger logger) { + if (logger != null) { + logger.close(); + } + } + + @Test + void buildLogGoesToLogDirectoryNotToTheClone() throws Exception { + File clone = tempDir.resolve("target/it").toFile(); + File module = new File(clone, "module"); + module.mkdirs(); + mojo.setCloneProjectsTo(clone); + setVariableValueToObject( + mojo, "logDirectory", tempDir.resolve("target/it-logs").toFile()); + + closeLogger(mojo.setupBuildLogFile(module, 1)); + + assertThat(tempDir.resolve("target/it-logs/module/build.log")).isRegularFile(); + assertThat(tempDir.resolve("target/it/module/build.log")).doesNotExist(); + } + + @Test + void noCloneMeansTheBuildLogStaysInTheSourceProject() throws Exception { + File project = tempDir.resolve("src/it/clone-none").toFile(); + project.mkdirs(); + // "none" is the special value that switches cloning off + mojo.setCloneProjectsTo(new File("none")); + assertThat(ReflectionUtils.getValueIncludingSuperclasses("cloneProjectsTo", mojo)) + .isNull(); + + closeLogger(mojo.setupBuildLogFile(project, 1)); + + assertThat(tempDir.resolve("src/it/clone-none/build.log")).isRegularFile(); + assertThat(tempDir.resolve("target/it")).doesNotExist(); + } + + private BuildJob buildJob(String result, String failureMessage, File buildLog) { + BuildJob job = new BuildJob("project/pom.xml"); + job.setResult(result); + job.setFailureMessage(failureMessage); + job.setTime(1.5f); + job.setBuildlog(buildLog.getPath()); + return job; + } + + private Element readReport(String name) throws Exception { + File report = tempDir.resolve("reports/TEST-" + name + ".xml").toFile(); + assertThat(report).isFile(); + return DocumentBuilderFactory.newInstance() + .newDocumentBuilder() + .parse(report) + .getDocumentElement(); + } + + private Element child(Element parent, String name) { + assertThat(parent.getElementsByTagName(name).getLength()).as(name).isEqualTo(1); + return (Element) parent.getElementsByTagName(name).item(0); + } + + private void writeReport(BuildJob job, String name) throws Exception { + setVariableValueToObject( + mojo, "reportsDirectory", tempDir.resolve("reports").toFile()); + setVariableValueToObject(mojo, "junitPackageName", "org.apache.maven.plugins.invoker"); + Files.createDirectories(tempDir.resolve("reports")); + mojo.writeJunitReport(job, name); + } + + @Test + void junitReportOfSuccessfulBuildCarriesTheBuildLog() throws Exception { + Path log = tempDir.resolve("build.log"); + Files.write(log, "BUILD SUCCESS".getBytes(StandardCharsets.UTF_8)); + + writeReport(buildJob(BuildJob.Result.SUCCESS, null, log.toFile()), "project"); + + Element suite = readReport("project"); + assertThat(suite.getAttribute("name")).isEqualTo("org.apache.maven.plugins.invoker.project"); + assertThat(suite.getAttribute("time")).isEqualTo("1.5"); + assertThat(suite.getAttribute("tests")).isEqualTo("1"); + assertThat(suite.getAttribute("errors")).isEqualTo("0"); + assertThat(suite.getAttribute("skipped")).isEqualTo("0"); + assertThat(suite.getAttribute("failures")).isEqualTo("0"); + Element testcase = child(suite, "testcase"); + assertThat(testcase.getAttribute("name")).isEqualTo("project"); + assertThat(child(testcase, "system-out").getTextContent()).isEqualTo("BUILD SUCCESS"); + assertThat(testcase.getElementsByTagName("failure").getLength()).isZero(); + } + + @Test + void junitReportOfFailedBuildHasFailureMessage() throws Exception { + Path log = tempDir.resolve("build.log"); + Files.write(log, "BUILD FAILURE".getBytes(StandardCharsets.UTF_8)); + + writeReport(buildJob(BuildJob.Result.FAILURE_BUILD, "script failed", log.toFile()), "project_2"); + + Element suite = readReport("project_2"); + assertThat(suite.getAttribute("tests")).isEqualTo("1"); + assertThat(suite.getAttribute("errors")).isEqualTo("0"); + assertThat(suite.getAttribute("skipped")).isEqualTo("0"); + assertThat(suite.getAttribute("failures")).isEqualTo("1"); + Element testcase = child(suite, "testcase"); + assertThat(testcase.getAttribute("name")).isEqualTo("project_2"); + assertThat(child(testcase, "failure").getAttribute("message")).isEqualTo("script failed"); + assertThat(child(testcase, "system-out").getTextContent()).isEqualTo("BUILD FAILURE"); + } + + @Test + void junitReportCountsSkippedAndErroredBuilds() throws Exception { + File missingLog = tempDir.resolve("missing.log").toFile(); + + writeReport(buildJob(BuildJob.Result.SKIPPED, "not applicable", missingLog), "skipped"); + writeReport(buildJob(BuildJob.Result.ERROR, null, missingLog), "errored"); + + Element skipped = readReport("skipped"); + assertThat(skipped.getAttribute("skipped")).isEqualTo("1"); + assertThat(skipped.getAttribute("failures")).isEqualTo("0"); + assertThat(child(child(skipped, "testcase"), "skipped").getTextContent()) + .isEqualTo("not applicable"); + Element errored = readReport("errored"); + assertThat(errored.getAttribute("errors")).isEqualTo("1"); + assertThat(errored.getAttribute("failures")).isEqualTo("0"); + // a build without log file still gets an (empty) system-out + assertThat(child(child(errored, "testcase"), "system-out").getTextContent()) + .isEmpty(); + } +} diff --git a/src/test/java/org/apache/maven/plugins/invoker/InstallMojoTest.java b/src/test/java/org/apache/maven/plugins/invoker/InstallMojoTest.java new file mode 100644 index 0000000..dfe7efb --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/invoker/InstallMojoTest.java @@ -0,0 +1,47 @@ +/* + * 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. + */ +package org.apache.maven.plugins.invoker; + +import java.io.File; +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import static org.apache.maven.plugins.invoker.TestUtil.setVariableValueToObject; +import static org.assertj.core.api.Assertions.assertThat; + +class InstallMojoTest { + + @TempDir + Path tempDir; + + @Test + void skipInstallationDoesNotCreateTheStagingRepository() throws Exception { + File itRepo = tempDir.resolve("target/it-repo").toFile(); + // no project, session or repository system: a skipped installation must not touch any of them + InstallMojo mojo = new InstallMojo(null, null, null); + setVariableValueToObject(mojo, "localRepositoryPath", itRepo); + setVariableValueToObject(mojo, "skipInstallation", true); + + mojo.execute(); + + assertThat(itRepo).doesNotExist(); + } +} diff --git a/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java b/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java index 935ccdd..bb5a2a7 100644 --- a/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java @@ -20,6 +20,7 @@ package org.apache.maven.plugins.invoker; import java.io.File; import java.lang.reflect.Method; +import java.nio.file.Path; import java.util.Collections; import java.util.List; import java.util.Map; @@ -31,6 +32,7 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; import org.codehaus.plexus.util.ReflectionUtils; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import static org.apache.maven.plugins.invoker.TestUtil.getBasedir; import static org.apache.maven.plugins.invoker.TestUtil.setVariableValueToObject; @@ -357,4 +359,17 @@ class InvokerMojoTest { assertThat(expectedParallelThreads).isEqualTo(invokerMojo.getParallelThreadsCount()); } } + + @Test + void skipInvocationReturnsBeforeAnythingIsRun(@TempDir Path tempDir) throws Exception { + File reportsDirectory = tempDir.resolve("invoker-reports").toFile(); + setVariableValueToObject(invokerMojo, "skipInvocation", true); + setVariableValueToObject(invokerMojo, "reportsDirectory", reportsDirectory); + setVariableValueToObject(invokerMojo, "projectsDirectory", new File(getBasedir(), "src/test/resources/unit")); + + // no project, invoker or settings are set, so any attempt to run a build would fail + invokerMojo.execute(); + + assertThat(reportsDirectory).doesNotExist(); + } } diff --git a/src/test/java/org/apache/maven/plugins/invoker/ProjectCloningTest.java b/src/test/java/org/apache/maven/plugins/invoker/ProjectCloningTest.java new file mode 100644 index 0000000..704efab --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/invoker/ProjectCloningTest.java @@ -0,0 +1,160 @@ +/* + * 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. + */ +package org.apache.maven.plugins.invoker; + +import java.io.File; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.Properties; + +import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Settings; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import static org.apache.maven.plugins.invoker.TestUtil.getBasedir; +import static org.apache.maven.plugins.invoker.TestUtil.setVariableValueToObject; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests the cloning of IT projects into {@code cloneProjectsTo} and the filtering of their POMs. + */ +class ProjectCloningTest { + + private static final File FILTERING = new File(getBasedir(), "src/test/resources/filtering"); + + @TempDir + Path tempDir; + + private final InvokerMojo mojo = new InvokerMojo(null, null, null, null); + + private File outerBasedir; + + private File cloneTo; + + @BeforeEach + void setUp() throws Exception { + outerBasedir = tempDir.resolve("outer").toFile(); + cloneTo = tempDir.resolve("outer/target/it").toFile(); + + // the project that configures the invoker plugin, its values feed the filtering of the cloned IT projects + MavenProject project = new MavenProject(); + project.setGroupId("org.apache.maven.plugins.invoker"); + project.setArtifactId("outer-project"); + project.setVersion("1.0-SNAPSHOT"); + project.setName("PASSED"); + project.setFile(new File(outerBasedir, "pom.xml")); + project.getModel().getProperties().setProperty("propertyFromPropertiesSection", "PROPERTY-FROM-POM"); + project.getModel().getProperties().setProperty("itProperty", "FAILED"); + + Settings settings = new Settings(); + settings.setLocalRepository(tempDir.resolve("local-repo").toString()); + + setVariableValueToObject(mojo, "project", project); + setVariableValueToObject(mojo, "settings", settings); + setVariableValueToObject(mojo, "cloneProjectsTo", cloneTo); + } + + private void cloneFrom(String projectsDirectory, String... projectPaths) throws Exception { + setVariableValueToObject(mojo, "projectsDirectory", new File(FILTERING, projectsDirectory)); + mojo.cloneProjects(Arrays.asList(projectPaths)); + } + + private String read(String path, Charset charset) throws Exception { + return new String(Files.readAllBytes(new File(cloneTo, path).toPath()), charset); + } + + @Test + void pomIsFilteredWithTheDocumentedPrecedence() throws Exception { + Properties filterProperties = new Properties(); + filterProperties.setProperty("propertyFromPluginConfig", "PROPERTY-FROM-PLUGIN-CONFIG"); + filterProperties.setProperty("project-is-not-the-pom.version", "PASSED"); + filterProperties.setProperty("project.name", "FAILED"); + filterProperties.setProperty("itProperty", "PASSED"); + filterProperties.setProperty("project.nonExistingPomValue", "PASSED"); + filterProperties.setProperty("basedir", "FAILED"); + filterProperties.setProperty("baseurl", "FAILED"); + filterProperties.setProperty("localRepository", "FAILED"); + setVariableValueToObject(mojo, "filterProperties", filterProperties); + + cloneFrom("pom-filtering", "project/pom.xml"); + + String xml = read("project/pom.xml", StandardCharsets.UTF_8); + // Maven expressions are left for Maven itself + assertThat(xml).contains("<prop0>${project.version}</prop0>"); + assertThat(xml).contains("<prop1>1.0-SNAPSHOT</prop1>"); + assertThat(xml).contains("<prop2>PROPERTY-FROM-PLUGIN-CONFIG</prop2>"); + assertThat(xml).contains("<prop3>PROPERTY-FROM-POM</prop3>"); + // the prefix matters, project-is-not-the-pom.version is not project.version + assertThat(xml).contains("<prop4>PASSED</prop4>"); + // values of the POM precede filterProperties + assertThat(xml).contains("<prop5>PASSED</prop5>"); + assertThat(xml).contains("<prop6>PASSED</prop6>"); + // filterProperties precede the properties of the POM + assertThat(xml).contains("<prop7>PASSED</prop7>"); + // project.* falls back to filterProperties when the POM has no such value + assertThat(xml).contains("<prop8>PASSED</prop8>"); + // built-in values are not overridden by filterProperties + assertThat(xml).contains("<prop9>" + outerBasedir.getAbsolutePath() + "</prop9>"); + assertThat(xml).containsPattern("<prop10>file:///[^<]+</prop10>"); + assertThat(xml).contains("<prop11>" + tempDir.resolve("local-repo") + "</prop11>"); + assertThat(xml).containsPattern("<prop12>file:///[^<]+</prop12>"); + assertThat(xml).doesNotContain("FAILED").doesNotContain("@"); + } + + @ParameterizedTest + @CsvSource({"latin-1, ISO-8859-1", "utf-8, UTF-8"}) + void pomKeepsItsEncodingWhileFiltering(String project, String encoding) throws Exception { + Properties filterProperties = new Properties(); + filterProperties.setProperty("latin1Chars", "©®ÄÖÜäöüß"); + setVariableValueToObject(mojo, "filterProperties", filterProperties); + + cloneFrom("pom-filtering-encoding", project + "/pom.xml"); + + String xml = read(project + "/pom.xml", Charset.forName(encoding)); + assertThat(xml).contains("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>"); + assertThat(xml).contains("<prop0>©®ÄÖÜäöüß</prop0>"); + assertThat(xml).contains("<prop1>©®ÄÖÜäöüß</prop1>"); + } + + @ParameterizedTest + @CsvSource({"project/pom.xml", "no-pom-project"}) + void mavenExtensionsAreFiltered(String projectPath) throws Exception { + // 'project' has a pom.xml, 'no-pom-project' has none: in both cases .mvn/extensions.xml must be filtered + cloneFrom("extensions", projectPath); + + String project = projectPath.split("/")[0]; + File extensions = new File(cloneTo, project + "/.mvn/extensions.xml"); + assertThat(extensions).as("filtered extensions.xml").isFile(); + String xml = read(project + "/.mvn/extensions.xml", StandardCharsets.UTF_8); + assertThat(xml) + .contains("<groupId>org.apache.maven.plugins.invoker</groupId>") + .contains("<artifactId>outer-project</artifactId>") + .contains("<version>1.0-SNAPSHOT</version>") + .doesNotContain("@project.groupId@") + .doesNotContain("@project.artifactId@") + .doesNotContain("@project.version@"); + } +} diff --git a/src/it/filtering-extensions/src/it/no-pom-project/.mvn/extensions.xml b/src/test/resources/filtering/extensions/no-pom-project/.mvn/extensions.xml similarity index 100% rename from src/it/filtering-extensions/src/it/no-pom-project/.mvn/extensions.xml rename to src/test/resources/filtering/extensions/no-pom-project/.mvn/extensions.xml diff --git a/src/it/filtering-extensions/src/it/project/.mvn/extensions.xml b/src/test/resources/filtering/extensions/project/.mvn/extensions.xml similarity index 100% rename from src/it/filtering-extensions/src/it/project/.mvn/extensions.xml rename to src/test/resources/filtering/extensions/project/.mvn/extensions.xml diff --git a/src/it/filtering-extensions/src/it/project/pom.xml b/src/test/resources/filtering/extensions/project/pom.xml similarity index 100% rename from src/it/filtering-extensions/src/it/project/pom.xml rename to src/test/resources/filtering/extensions/project/pom.xml diff --git a/src/it/MINVOKER-196_junit_report_file/src/it/project/pom.xml b/src/test/resources/filtering/pom-filtering-encoding/latin-1/pom.xml similarity index 84% rename from src/it/MINVOKER-196_junit_report_file/src/it/project/pom.xml rename to src/test/resources/filtering/pom-filtering-encoding/latin-1/pom.xml index 0d15cde..9247082 100644 --- a/src/it/MINVOKER-196_junit_report_file/src/it/project/pom.xml +++ b/src/test/resources/filtering/pom-filtering-encoding/latin-1/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="ISO-8859-1"?> <!-- Licensed to the Apache Software Foundation (ASF) under one @@ -22,11 +22,14 @@ under the License. <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> <groupId>test</groupId> - <artifactId>test-junit-report</artifactId> + <artifactId>pom-filtering-encoding-latin1</artifactId> <version>0.1-SNAPSHOT</version> <packaging>jar</packaging> + <!-- NOTE: This file's encoding is ISO-8859-1 by test design --> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <prop0>���������</prop0> + <prop1>@latin1Chars@</prop1> </properties> </project> diff --git a/src/it/clone-none/src/it/clone-none/pom.xml b/src/test/resources/filtering/pom-filtering-encoding/utf-8/pom.xml similarity index 86% rename from src/it/clone-none/src/it/clone-none/pom.xml rename to src/test/resources/filtering/pom-filtering-encoding/utf-8/pom.xml index a3b5143..5349fa2 100644 --- a/src/it/clone-none/src/it/clone-none/pom.xml +++ b/src/test/resources/filtering/pom-filtering-encoding/utf-8/pom.xml @@ -22,11 +22,14 @@ under the License. <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> <groupId>test</groupId> - <artifactId>clone-none</artifactId> + <artifactId>pom-filtering-encoding-utf8</artifactId> <version>0.1-SNAPSHOT</version> <packaging>jar</packaging> + <!-- NOTE: This file's encoding is UTF-8 by test design --> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <prop0>©®ÄÖÜäöüß</prop0> + <prop1>@latin1Chars@</prop1> </properties> </project> diff --git a/src/it/pom-filtering/src/it/project/pom.xml b/src/test/resources/filtering/pom-filtering/project/pom.xml similarity index 81% rename from src/it/pom-filtering/src/it/project/pom.xml rename to src/test/resources/filtering/pom-filtering/project/pom.xml index cc98e82..6093188 100644 --- a/src/it/pom-filtering/src/it/project/pom.xml +++ b/src/test/resources/filtering/pom-filtering/project/pom.xml @@ -49,23 +49,4 @@ under the License. <prop11>@localRepository@</prop11> <prop12>@localRepositoryUrl@</prop12> </properties> - - <build> - <!-- using the Resources Plugin to create a backup of the executed POM for later inspection by the parent build --> - <resources> - <resource> - <directory>${basedir}</directory> - <filtering>false</filtering> - <includes> - <include>*.xml</include> - </includes> - </resource> - </resources> - <plugins> - <plugin> - <artifactId>maven-resources-plugin</artifactId> - <version>@version.maven-resources-plugin@</version> - </plugin> - </plugins> - </build> </project>
