Skip to content

Commit

Permalink
Test case that fails mojohaus#185
Browse files Browse the repository at this point in the history
  • Loading branch information
suztomo committed Aug 9, 2022
1 parent 374abca commit 0d99731
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
@@ -0,0 +1,35 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>flatten-dependency-all-both-test-and-transitive</artifactId>
<version>0.0.1-SNAPSHOT</version>

<build>
<defaultGoal>verify</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<configuration>
<flattenMode>oss</flattenMode>
<flattenDependencyMode>all</flattenDependencyMode>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>core</artifactId>
<!-- This artifact depends on dep:3.2.1 with compile scope -->
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
<version>3.2.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,45 @@
/*
* 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.
*/
File originalPom = new File( basedir, 'pom.xml' )
assert originalPom.exists()

def originalProject = new XmlSlurper().parse( originalPom )
assert 2 == originalProject.dependencies.dependency.size()
assert "dep" == originalProject.dependencies.dependency[1].artifactId.text()
assert "3.2.1" == originalProject.dependencies.dependency[1].version.text()
assert "test" == originalProject.dependencies.dependency[1].scope.text()

File flattenedPom = new File( basedir, '.flattened-pom.xml' )
assert flattenedPom.exists()

def flattenedProject = new XmlSlurper().parse( flattenedPom )

// core and dep should be there. It's because while the test-scope dep (the
// direct dependency), core declares dep as compile-scope (default) dependency.
assert 2 == flattenedProject.dependencies.dependency.size()

assert "core" == originalProject.dependencies.dependency[0].artifactId.text()
assert "3.2.1" == originalProject.dependencies.dependency[0].version.text()
assert "compile" == originalProject.dependencies.dependency[0].scope.text()

// The flattened pom.xml should declare the dep under core as compile scope.
// It's ok to ignore the one in the test-scope dependency.
assert "dep" == originalProject.dependencies.dependency[1].artifactId.text()
assert "3.2.1" == originalProject.dependencies.dependency[1].version.text()
assert "compile" == originalProject.dependencies.dependency[1].scope.text()

1 comment on commit 0d99731

@suztomo
Copy link
Owner Author

@suztomo suztomo commented on 0d99731 Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the test failure:

suztomo@suztomo2:~/flatten-maven-plugin$ mvn install -Dmaven.test.skip -Dinvoker.test=flatten-dependency-all-both-test-and-transitive
[INFO] Scanning for projects...

...

[DEBUG] Property version will be handled using flatten in flattened POM.
[DEBUG] file: /usr/local/google/home/suztomo/flatten-maven-plugin/target/it/flatten-dependency-all-both-test-and-transitive/.flattened-pom.xml,file.length(): 0, binaryData.length: 891
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.814 s
[INFO] Finished at: 2022-08-09T15:43:34-04:00
[INFO] ------------------------------------------------------------------------
Running post-build script: /usr/local/google/home/suztomo/flatten-maven-plugin/target/it/flatten-dependency-all-both-test-and-transitive/verify.groovy
Assertion failed: 

assert 2 ==  flattenedProject.dependencies.dependency.size()
         |   |                |            |          |
         |   |                |            |          1
         |   |                |            org.codehaus.mojo.flatten.itscore3.2.1compiledeporg.codehaus.mojo.flatten.itsfalse
         |   |                org.codehaus.mojo.flatten.itscore3.2.1compiledeporg.codehaus.mojo.flatten.itsfalse
         |   4.0.0org.codehaus.mojo.flatten.itsflatten-dependency-all-both-test-and-transitive0.0.1-SNAPSHOTorg.codehaus.mojo.flatten.itscore3.2.1compiledeporg.codehaus.mojo.flatten.itsfalse
         false

	at org.codehaus.groovy.runtime.InvokerHelper.assertFailed(InvokerHelper.java:436)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.assertFailed(ScriptBytecodeAdapter.java:670)
	at Script1.run(Script1.groovy:35)
	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:427)
	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:461)
	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:436)
	at org.apache.maven.shared.scriptinterpreter.GroovyScriptInterpreter.evaluateScript(GroovyScriptInterpreter.java:76)
	at org.apache.maven.shared.scriptinterpreter.ScriptRunner.executeRun(ScriptRunner.java:236)
	at org.apache.maven.shared.scriptinterpreter.ScriptRunner.run(ScriptRunner.java:161)
	at org.apache.maven.plugins.invoker.AbstractInvokerMojo.runPostBuildHook(AbstractInvokerMojo.java:2154)
	at org.apache.maven.plugins.invoker.AbstractInvokerMojo.runBuild(AbstractInvokerMojo.java:2129)
	at org.apache.maven.plugins.invoker.AbstractInvokerMojo.runBuild(AbstractInvokerMojo.java:1721)
	at org.apache.maven.plugins.invoker.AbstractInvokerMojo.lambda$runBuilds$4(AbstractInvokerMojo.java:1431)
	at org.apache.maven.plugins.invoker.JobExecutor.lambda$null$1(JobExecutor.java:69)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
*** end build.log for: flatten-dependency-all-both-test-and-transitive/pom.xml ***

[ERROR] -------------------------------------------------
[ERROR] 
[INFO] -------------------------------------------------
[INFO] Build Summary:
[INFO]   Passed: 0, Failed: 1, Errors: 0, Skipped: 0
[INFO] -------------------------------------------------
[ERROR] The following builds failed:
[ERROR] *  flatten-dependency-all-both-test-and-transitive/pom.xml
[INFO] -------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.386 s
[INFO] Finished at: 2022-08-09T15:43:35-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-invoker-plugin:3.3.0:verify (default) on project flatten-maven-plugin: 1 build failed. See console output above for details. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
suztomo@suztomo2:~/flatten-maven-plugin$ cat target/it/flatten-dependency-all-both-test-and-transitive/.flattened-pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.codehaus.mojo.flatten.its</groupId>
  <artifactId>flatten-dependency-all-both-test-and-transitive</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>org.codehaus.mojo.flatten.its</groupId>
      <artifactId>core</artifactId>
      <version>3.2.1</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <artifactId>dep</artifactId>
          <groupId>org.codehaus.mojo.flatten.its</groupId>
        </exclusion>
      </exclusions>
      <optional>false</optional>
    </dependency>
  </dependencies>
</project>

Please sign in to comment.