|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +class LogInspector |
| 21 | +{ |
| 22 | + File log; |
| 23 | + int index; |
| 24 | + LogInspector( File log ) |
| 25 | + { |
| 26 | + this.log = log; |
| 27 | + this.index = 0; |
| 28 | + } |
| 29 | + boolean containsAfter( CharSequence text ) |
| 30 | + { |
| 31 | + int newIdx = log.text.indexOf( text, index + 1 ) |
| 32 | + if ( newIdx > index) |
| 33 | + { |
| 34 | + index = newIdx |
| 35 | + return true |
| 36 | + } |
| 37 | + return false |
| 38 | + } |
| 39 | + String toString () |
| 40 | + { |
| 41 | + return "Log file ${log} after index ${index}." |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | +assert new File( basedir, "repo/org/apache/maven/its/deploy/comparepom/test/maven-metadata.xml" ).exists() |
| 47 | +assert new File( basedir, "repo/org/apache/maven/its/deploy/comparepom/test/1.0/test-1.0-first.jar" ).exists() |
| 48 | +assert new File( basedir, "repo/org/apache/maven/its/deploy/comparepom/test/1.0/test-1.0-second.jar").exists() |
| 49 | + |
| 50 | +File deployedPom = new File( basedir, "repo/org/apache/maven/its/deploy/comparepom/test/1.0/test-1.0.pom" ) |
| 51 | +assert deployedPom.exists() |
| 52 | +assert ! deployedPom.text.contains("Modified POM!") |
| 53 | + |
| 54 | +File installedPom = new File( localRepositoryPath, "org/apache/maven/its/deploy/comparepom/test/1.0/test-1.0.pom" ) |
| 55 | +assert installedPom.exists() |
| 56 | +assert installedPom.text.contains("Modified POM!") |
| 57 | + |
| 58 | +File buildLog = new File( basedir, 'build.log' ) |
| 59 | +assert buildLog.exists() |
| 60 | + |
| 61 | +// Inspect log |
| 62 | +LogInspector li = new LogInspector( buildLog ) |
| 63 | +String groupUrl = "file:///${basedir}/repo/org/apache/maven/its/deploy/comparepom" |
| 64 | + |
| 65 | +// First run: The POM tried to be downloaded and uploaded: |
| 66 | +assert li.containsAfter( "[INFO] Downloading from it: ${groupUrl}/test/1.0/test-1.0.pom" ) |
| 67 | +assert li.containsAfter( "[INFO] Uploaded to it: ${groupUrl}/test/1.0/test-1.0.pom" ) |
| 68 | + |
| 69 | +// After that, it is never tried to be uploaded: |
| 70 | +assert -1 == buildLog.text.indexOf( "[INFO] Uploading to it: ${groupUrl}/test/1.0/test-1.0.pom", li.index + 1 ) |
| 71 | + |
| 72 | +// Second run: POM is downloaded and not uploaded: |
| 73 | +assert li.containsAfter( "[INFO] Downloaded from it: ${groupUrl}/test/1.0/test-1.0.pom" ) |
| 74 | +assert li.containsAfter( "[INFO] Not deploying POM, since deployed POM is equal to current POM." ) |
| 75 | + |
| 76 | +// Third run: POM is downloaded, nothing is tried to be uploaded after that, and the build fails with error: |
| 77 | +assert li.containsAfter( "[INFO] Downloaded from it: ${groupUrl}/test/1.0/test-1.0.pom" ) |
| 78 | +assert -1 == buildLog.text.indexOf( "[INFO] Uploading to", li.index + 1 ) |
| 79 | +assert li.containsAfter( "[ERROR] Project version org.apache.maven.its.deploy.comparepom:test:1.0 already deployed with a differing POM." ) |
0 commit comments