From 703652ab6e6ea9796608b489d5a661ea60f1503d Mon Sep 17 00:00:00 2001 From: Mathias de Riese Date: Thu, 29 Sep 2022 16:15:07 +0200 Subject: [PATCH] MDEPLOY-118: integration test for `comparePomWithDeployed`. --- src/it/compare-pom/altered-pom.xml | 72 ++++++++++++++++++++++++ src/it/compare-pom/invoker.properties | 26 +++++++++ src/it/compare-pom/pom.xml | 72 ++++++++++++++++++++++++ src/it/compare-pom/setup.bsh | 33 +++++++++++ src/it/compare-pom/verify.groovy | 79 +++++++++++++++++++++++++++ 5 files changed, 282 insertions(+) create mode 100644 src/it/compare-pom/altered-pom.xml create mode 100644 src/it/compare-pom/invoker.properties create mode 100644 src/it/compare-pom/pom.xml create mode 100644 src/it/compare-pom/setup.bsh create mode 100644 src/it/compare-pom/verify.groovy diff --git a/src/it/compare-pom/altered-pom.xml b/src/it/compare-pom/altered-pom.xml new file mode 100644 index 00000000..1dc5badc --- /dev/null +++ b/src/it/compare-pom/altered-pom.xml @@ -0,0 +1,72 @@ + + + + + + 4.0.0 + + org.apache.maven.its.deploy.comparepom + test + 1.0 + pom + + + Tests deployment comparing with a deployed POM. Parameter comparePomWithDeployed. Modified POM! + + + + true + + + + + it + file:///${basedir}/repo + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + ${m-deploy-p.version} + + true + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1 + + + + jar + + + ${classifier} + + + + + + + diff --git a/src/it/compare-pom/invoker.properties b/src/it/compare-pom/invoker.properties new file mode 100644 index 00000000..3f29adb2 --- /dev/null +++ b/src/it/compare-pom/invoker.properties @@ -0,0 +1,26 @@ +# 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.debug = false + +invoker.goals = -Dclassifier=first clean deploy + +invoker.goals.2 = -Dclassifier=second clean deploy + +invoker.project.3 = altered-pom.xml +invoker.goals.3 = -Dclassifier=third -Dm-deploy-p.version=${project.version} clean deploy +invoker.buildResult.3 = failure diff --git a/src/it/compare-pom/pom.xml b/src/it/compare-pom/pom.xml new file mode 100644 index 00000000..f7410fd7 --- /dev/null +++ b/src/it/compare-pom/pom.xml @@ -0,0 +1,72 @@ + + + + + + 4.0.0 + + org.apache.maven.its.deploy.comparepom + test + 1.0 + pom + + + Tests deployment comparing with a deployed POM. Parameter comparePomWithDeployed. + + + + true + + + + + it + file:///${basedir}/repo + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + @project.version@ + + true + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1 + + + + jar + + + ${classifier} + + + + + + + diff --git a/src/it/compare-pom/setup.bsh b/src/it/compare-pom/setup.bsh new file mode 100644 index 00000000..c33e81d8 --- /dev/null +++ b/src/it/compare-pom/setup.bsh @@ -0,0 +1,33 @@ +/* + * 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 org.codehaus.plexus.util.*; + +File file = new File( localRepositoryPath, "org/apache/maven/its/deploy/comparepom" ); +System.out.println( "Deleting " + file ); +FileUtils.deleteDirectory( file ); + +file = new File( basedir, "repo" ); +System.out.println( "Deleting " + file ); +FileUtils.deleteDirectory( file ); + +return true; diff --git a/src/it/compare-pom/verify.groovy b/src/it/compare-pom/verify.groovy new file mode 100644 index 00000000..e2791c11 --- /dev/null +++ b/src/it/compare-pom/verify.groovy @@ -0,0 +1,79 @@ +/* + * 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. + */ + +class LogInspector +{ + File log; + int index; + LogInspector( File log ) + { + this.log = log; + this.index = 0; + } + boolean containsAfter( CharSequence text ) + { + int newIdx = log.text.indexOf( text, index + 1 ) + if ( newIdx > index) + { + index = newIdx + return true + } + return false + } + String toString () + { + return "Log file ${log} after index ${index}." + } +} + + +assert new File( basedir, "repo/org/apache/maven/its/deploy/comparepom/test/maven-metadata.xml" ).exists() +assert new File( basedir, "repo/org/apache/maven/its/deploy/comparepom/test/1.0/test-1.0-first.jar" ).exists() +assert new File( basedir, "repo/org/apache/maven/its/deploy/comparepom/test/1.0/test-1.0-second.jar").exists() + +File deployedPom = new File( basedir, "repo/org/apache/maven/its/deploy/comparepom/test/1.0/test-1.0.pom" ) +assert deployedPom.exists() +assert ! deployedPom.text.contains("Modified POM!") + +File installedPom = new File( localRepositoryPath, "org/apache/maven/its/deploy/comparepom/test/1.0/test-1.0.pom" ) +assert installedPom.exists() +assert installedPom.text.contains("Modified POM!") + +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.exists() + +// Inspect log +LogInspector li = new LogInspector( buildLog ) +String groupUrl = "file:///${basedir}/repo/org/apache/maven/its/deploy/comparepom" + +// First run: The POM tried to be downloaded and uploaded: +assert li.containsAfter( "[INFO] Downloading from it: ${groupUrl}/test/1.0/test-1.0.pom" ) +assert li.containsAfter( "[INFO] Uploaded to it: ${groupUrl}/test/1.0/test-1.0.pom" ) + +// After that, it is never tried to be uploaded: +assert -1 == buildLog.text.indexOf( "[INFO] Uploading to it: ${groupUrl}/test/1.0/test-1.0.pom", li.index + 1 ) + +// Second run: POM is downloaded and not uploaded: +assert li.containsAfter( "[INFO] Downloaded from it: ${groupUrl}/test/1.0/test-1.0.pom" ) +assert li.containsAfter( "[INFO] Not deploying POM, since deployed POM is equal to current POM." ) + +// Third run: POM is downloaded, nothing is tried to be uploaded after that, and the build fails with error: +assert li.containsAfter( "[INFO] Downloaded from it: ${groupUrl}/test/1.0/test-1.0.pom" ) +assert -1 == buildLog.text.indexOf( "[INFO] Uploading to", li.index + 1 ) +assert li.containsAfter( "[ERROR] Project version org.apache.maven.its.deploy.comparepom:test:1.0 already deployed with a differing POM." )