You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/01/26 12:51:22 UTC

[maven-integration-testing] branch MNG-5669 created (now 973d03a)

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a change to branch MNG-5669
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git.


      at 973d03a  [MNG-5669] same pom.xml is read multiple times

This branch includes the following new commits:

     new 973d03a  [MNG-5669] same pom.xml is read multiple times

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-integration-testing] 01/01: [MNG-5669] same pom.xml is read multiple times

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-5669
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git

commit 973d03a5a8976689f0d7be4f1049ddec9c5579bc
Author: rfscholte <rf...@apache.org>
AuthorDate: Sun Jan 26 13:51:12 2020 +0100

    [MNG-5669] same pom.xml is read multiple times
---
 .gitignore                                         |   1 +
 .../org/apache/maven/it/IntegrationTestSuite.java  |   1 +
 .../maven/it/MavenITmng5669ReadPomsOnce.java       |  85 ++++++++++++++++
 .../mng-5669-read-poms-once/.mvn/jvm.config        |   1 +
 .../mng-5669-read-poms-once/module1/pom.xml        |  32 ++++++
 .../mng-5669-read-poms-once/module2/pom.xml        |  39 ++++++++
 .../mng-5669-read-poms-once/module3/pom.xml        |  40 ++++++++
 .../test/resources/mng-5669-read-poms-once/pom.xml |  36 +++++++
 core-it-support/core-it-javaagent/pom.xml          |  79 +++++++++++++++
 .../maven/coreits/javaagent/mng5669/Premain.java   | 109 +++++++++++++++++++++
 core-it-support/pom.xml                            |   1 +
 11 files changed, 424 insertions(+)

diff --git a/.gitignore b/.gitignore
index aa380b5..c00d32a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,4 @@ bin
 jvz-*
 .flattened-pom.xml
 .checkstyle
+dependency-reduced-pom.xml
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
index 10951b6..f81f6d2 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
@@ -107,6 +107,7 @@ public class IntegrationTestSuite
         // -------------------------------------------------------------------------------------------------------------
         // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
 
+        suite.addTestSuite( MavenITmng5669ReadPomsOnce.class );
         suite.addTestSuite( MavenITmng6759TransitiveDependencyRepositoriesTest.class );
         suite.addTestSuite( MavenITmng6720FailFastTest.class );
         suite.addTestSuite( MavenITmng6506PackageAnnotationTest.class );
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5669ReadPomsOnce.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5669ReadPomsOnce.java
new file mode 100644
index 0000000..24b9147
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5669ReadPomsOnce.java
@@ -0,0 +1,85 @@
+package org.apache.maven.it;
+
+/*
+ * 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.File;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.it.util.ResourceExtractor;
+
+/**
+ * An integration test to ensure any pomfile is only read once.
+ * This is confirmed by adding a Java Agent to the DefaultModelReader and output the options, including the source location
+ *
+ * <a href="https://issues.apache.org/jira/browse/MNG-5669">MNG-5669</a>.
+ *
+ */
+public class MavenITmng5669ReadPomsOnce
+    extends AbstractMavenIntegrationTestCase
+{
+
+    public MavenITmng5669ReadPomsOnce()
+    {
+        super( "[3.7.0,)" );
+    }
+
+    public void test()
+        throws Exception
+    {
+        // prepare JAvaAgent
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5669-read-poms-once" );
+
+        Verifier verifier = newVerifier( testDir.getAbsolutePath(), false );
+        verifier.setForkJvm( true ); // pick up agent
+        verifier.setMavenDebug( false );
+        verifier.setAutoclean( false );
+        verifier.addCliOption( "-q" );
+        verifier.addCliOption( "-U" );
+        verifier.executeGoals( Arrays.asList( "verify" ) );
+        verifier.resetStreams();
+        
+        List<String> logTxt = verifier.loadLines( "log.txt", "utf-8" );
+        assertEquals( 168, logTxt.size() );
+        
+        // analyze lines. It is a Hashmap, so we can't rely on the order
+        Set<String> uniqueBuildingSources = new HashSet<>( 168 );
+        final String buildSourceKey = "org.apache.maven.model.building.source=";
+        final int keyLength = buildSourceKey.length();
+        for( String line : logTxt )
+        {
+            int start = line.indexOf( buildSourceKey );
+            if ( start < 0 )
+            {
+                continue;
+            }
+            
+            int end = line.indexOf(", ", start);
+            if ( end < 0) 
+            {
+                end = line.length() - 1; // is the }
+            }
+            uniqueBuildingSources.add( line.substring( start + keyLength, end ) );
+        }
+        assertEquals( uniqueBuildingSources.size(), 167 /* is 168 minus superpom */ );
+    }
+}
diff --git a/core-it-suite/src/test/resources/mng-5669-read-poms-once/.mvn/jvm.config b/core-it-suite/src/test/resources/mng-5669-read-poms-once/.mvn/jvm.config
new file mode 100644
index 0000000..46fefcc
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5669-read-poms-once/.mvn/jvm.config
@@ -0,0 +1 @@
+-javaagent:../../../../repo/mng-coreit/javaagent/1.0-SNAPSHOT/javaagent-1.0-SNAPSHOT.jar
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-5669-read-poms-once/module1/pom.xml b/core-it-suite/src/test/resources/mng-5669-read-poms-once/module1/pom.xml
new file mode 100644
index 0000000..6010dbc
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5669-read-poms-once/module1/pom.xml
@@ -0,0 +1,32 @@
+<?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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>mng5669</groupId>
+    <artifactId>project</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+  </parent>
+  <artifactId>module1</artifactId>
+
+</project>
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-5669-read-poms-once/module2/pom.xml b/core-it-suite/src/test/resources/mng-5669-read-poms-once/module2/pom.xml
new file mode 100644
index 0000000..7983fbd
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5669-read-poms-once/module2/pom.xml
@@ -0,0 +1,39 @@
+<?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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>mng5669</groupId>
+    <artifactId>project</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+  </parent>
+  <artifactId>module2</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>mng5669</groupId>
+      <artifactId>module1</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-5669-read-poms-once/module3/pom.xml b/core-it-suite/src/test/resources/mng-5669-read-poms-once/module3/pom.xml
new file mode 100644
index 0000000..155046c
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5669-read-poms-once/module3/pom.xml
@@ -0,0 +1,40 @@
+<?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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>mng5669</groupId>
+    <artifactId>project</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+  </parent>
+  <artifactId>module3</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>mng5669</groupId>
+      <artifactId>module2</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-5669-read-poms-once/pom.xml b/core-it-suite/src/test/resources/mng-5669-read-poms-once/pom.xml
new file mode 100644
index 0000000..bf11d6b
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5669-read-poms-once/pom.xml
@@ -0,0 +1,36 @@
+<?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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>mng5669</groupId>
+  <artifactId>project</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <modules>
+    <module>module1</module>
+    <module>module2</module>
+    <module>module3</module>
+  </modules>
+
+</project>
\ No newline at end of file
diff --git a/core-it-support/core-it-javaagent/pom.xml b/core-it-support/core-it-javaagent/pom.xml
new file mode 100644
index 0000000..3f852f6
--- /dev/null
+++ b/core-it-support/core-it-javaagent/pom.xml
@@ -0,0 +1,79 @@
+<?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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.maven.its</groupId>
+    <artifactId>core-it-support</artifactId>
+    <version>2.1-SNAPSHOT</version>
+  </parent>
+  <groupId>mng-coreit</groupId>
+  <artifactId>javaagent</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifestEntries>
+              <Premain-Class>org.apache.maven.coreits.javaagent.mng5669.Premain</Premain-Class>
+              <Can-Retransform-Classes>true</Can-Retransform-Classes>
+            </manifestEntries>
+          </archive>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm</artifactId>
+      <version>7.3.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm-commons</artifactId>
+      <version>7.3.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm-util</artifactId>
+      <version>7.3.1</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file
diff --git a/core-it-support/core-it-javaagent/src/main/java/org/apache/maven/coreits/javaagent/mng5669/Premain.java b/core-it-support/core-it-javaagent/src/main/java/org/apache/maven/coreits/javaagent/mng5669/Premain.java
new file mode 100644
index 0000000..ea4420f
--- /dev/null
+++ b/core-it-support/core-it-javaagent/src/main/java/org/apache/maven/coreits/javaagent/mng5669/Premain.java
@@ -0,0 +1,109 @@
+package org.apache.maven.coreits.javaagent.mng5669;
+
+/*
+ * 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.lang.instrument.ClassFileTransformer;
+import java.lang.instrument.IllegalClassFormatException;
+import java.lang.instrument.Instrumentation;
+import java.security.ProtectionDomain;
+
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.commons.AdviceAdapter;
+
+/**
+ * 
+ * @author Robert Scholte
+ *
+ */
+public class Premain
+{
+    public static void premain( String agentArgs, Instrumentation inst )
+    {
+        inst.addTransformer( new ClassFileTransformer()
+        {
+
+            public byte[] transform( ClassLoader loader, String className, Class<?> classBeingRedefined,
+                                     ProtectionDomain protectionDomain, byte[] classfileBuffer )
+                throws IllegalClassFormatException
+            {
+                if ( "org/apache/maven/model/io/DefaultModelReader".equals( className ) )
+                {
+                    ClassReader r = new ClassReader( classfileBuffer );
+                    final ClassWriter w = new ClassWriter( Opcodes.ASM6 );
+
+                    ClassVisitor v = new DefaultModelReaderVisitior( Opcodes.ASM6, w );
+
+                    r.accept( v, ClassReader.EXPAND_FRAMES );
+                    return w.toByteArray();
+                }
+                else
+                {
+                    return classfileBuffer;
+                }
+            }
+        } );
+    }
+
+    private static class DefaultModelReaderVisitior
+        extends ClassVisitor
+    {
+        DefaultModelReaderVisitior( int api, org.objectweb.asm.ClassVisitor cv )
+        {
+            super( api, cv );
+        }
+
+        @Override
+        public MethodVisitor visitMethod( int access, String name, String desc, String signature, String[] exceptions )
+        {
+            MethodVisitor mv = cv.visitMethod( access, name, desc, signature, exceptions );
+            if ( "getSource".equals( name ) )
+            {
+                return new GetSourceMethodAdvice( Opcodes.ASM6, mv, access, name, desc );
+            }
+            else
+            {
+                return mv;
+            }
+        }
+    }
+
+    // org.apache.maven.model.io.DefaultModelReader.getSource(Map<String, ?>)
+    private static class GetSourceMethodAdvice
+        extends AdviceAdapter
+    {
+        GetSourceMethodAdvice( int api, MethodVisitor mv, int access, String name, String desc )
+        {
+            super( api, mv, access, name, desc );
+        }
+
+        @Override
+        protected void onMethodEnter()
+        {
+            // System.out.println( options ),
+            mv.visitFieldInsn( GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;" );
+            mv.visitVarInsn( ALOAD, 1 );
+            mv.visitMethodInsn( INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/Object;)V", false );
+        }
+    }
+}
diff --git a/core-it-support/pom.xml b/core-it-support/pom.xml
index f9479e1..83367ed 100644
--- a/core-it-support/pom.xml
+++ b/core-it-support/pom.xml
@@ -40,6 +40,7 @@ under the License.
     <module>core-it-support-artifacts</module>
     <module>maven-it-helper</module>
     <module>core-it-extension</module>
+    <module>core-it-javaagent</module>
   </modules>
 
   <!-- TODO this needs to be improved, right now it doesn't deploy to releases repo -->