You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ca...@apache.org on 2006/02/20 23:51:55 UTC

svn commit: r379268 - in /maven/components/trunk/maven-core-it: ./ it0094/ it0094/mojo/ it0094/mojo/src/ it0094/mojo/src/main/ it0094/mojo/src/main/java/ it0094/mojo/src/main/java/org/ it0094/mojo/src/main/java/org/codehaus/ it0094/mojo/src/main/java/o...

Author: carlos
Date: Mon Feb 20 14:51:50 2006
New Revision: 379268

URL: http://svn.apache.org/viewcvs?rev=379268&view=rev
Log:
Added test case it0094 for classloading issues in plugins
PR: MNG-1898

Added:
    maven/components/trunk/maven-core-it/it0094/
    maven/components/trunk/maven-core-it/it0094/goals.txt   (with props)
    maven/components/trunk/maven-core-it/it0094/mojo/
    maven/components/trunk/maven-core-it/it0094/mojo/pom.xml   (with props)
    maven/components/trunk/maven-core-it/it0094/mojo/src/
    maven/components/trunk/maven-core-it/it0094/mojo/src/main/
    maven/components/trunk/maven-core-it/it0094/mojo/src/main/java/
    maven/components/trunk/maven-core-it/it0094/mojo/src/main/java/org/
    maven/components/trunk/maven-core-it/it0094/mojo/src/main/java/org/codehaus/
    maven/components/trunk/maven-core-it/it0094/mojo/src/main/java/org/codehaus/mojo/
    maven/components/trunk/maven-core-it/it0094/mojo/src/main/java/org/codehaus/mojo/kodo/
    maven/components/trunk/maven-core-it/it0094/mojo/src/main/java/org/codehaus/mojo/kodo/Enhance.java   (with props)
    maven/components/trunk/maven-core-it/it0094/pom.xml   (with props)
    maven/components/trunk/maven-core-it/it0094/test/
    maven/components/trunk/maven-core-it/it0094/test/pom.xml   (with props)
Modified:
    maven/components/trunk/maven-core-it/README.txt

Modified: maven/components/trunk/maven-core-it/README.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/README.txt?rev=379268&r1=379267&r2=379268&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/README.txt (original)
+++ maven/components/trunk/maven-core-it/README.txt Mon Feb 20 14:51:50 2006
@@ -255,7 +255,10 @@
 it0092: Test that legacy repositories with legacy snapshots download correctly.
 
 it0093: A test that ensures that an exception is thrown when two artifacts
-with the same id are present in the reactor.
+        with the same id are present in the reactor.
+
+it0094: Test classloading issues with mojos after 2.0 (MNG-1898).
+
 -------------------------------------------------------------------------------
 
 - generated sources

Added: maven/components/trunk/maven-core-it/it0094/goals.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0094/goals.txt?rev=379268&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0094/goals.txt (added)
+++ maven/components/trunk/maven-core-it/it0094/goals.txt Mon Feb 20 14:51:50 2006
@@ -0,0 +1 @@
+install

Propchange: maven/components/trunk/maven-core-it/it0094/goals.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0094/goals.txt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it0094/mojo/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0094/mojo/pom.xml?rev=379268&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0094/mojo/pom.xml (added)
+++ maven/components/trunk/maven-core-it/it0094/mojo/pom.xml Mon Feb 20 14:51:50 2006
@@ -0,0 +1,65 @@
+<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>
+  <parent>
+    <groupId>org.codehaus.mojo</groupId>
+    <artifactId>mojo</artifactId>
+    <version>5</version>
+  </parent>
+  <groupId>org.apache.maven.it</groupId>
+  <artifactId>maven-core-it0094-mojo</artifactId>
+  <packaging>maven-plugin</packaging>
+  <version>1.0-SNAPSHOT</version>
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-model</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <version>[1.2.9,]</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+      <version>1.0.5</version>
+    </dependency>
+    <dependency>
+      <groupId>xalan</groupId>
+      <artifactId>xalan</artifactId>
+      <version>2.5.1</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>xerces</groupId>
+      <artifactId>xercesImpl</artifactId>
+      <version>2.5.0</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>xml-apis</groupId>
+      <artifactId>xml-apis</artifactId>
+      <version>2.0.0</version>
+      <scope>compile</scope>
+    </dependency>
+
+  </dependencies>
+
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-plugin-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </reporting>
+</project>

Propchange: maven/components/trunk/maven-core-it/it0094/mojo/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0094/mojo/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it0094/mojo/src/main/java/org/codehaus/mojo/kodo/Enhance.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0094/mojo/src/main/java/org/codehaus/mojo/kodo/Enhance.java?rev=379268&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0094/mojo/src/main/java/org/codehaus/mojo/kodo/Enhance.java (added)
+++ maven/components/trunk/maven-core-it/it0094/mojo/src/main/java/org/codehaus/mojo/kodo/Enhance.java Mon Feb 20 14:51:50 2006
@@ -0,0 +1,147 @@
+/*
+ *  Copyright 2005-2006 Brian Fox (brianefox@gmail.com)
+ *
+ * Licensed 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.codehaus.mojo.kodo;
+
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.xerces.jaxp.SAXParserFactoryImpl;
+import org.codehaus.classworlds.ClassRealm;
+
+/**
+ * Goal that enhances persistant classes
+ * 
+ * @requiresDependancyResolution test
+ * @goal enhance
+ * 
+ * @phase compile
+ */
+public class Enhance
+    extends AbstractMojo
+
+{
+    public Enhance()
+    {
+        super();
+    }
+
+    public void execute()
+        throws MojoExecutionException
+    {
+        printClassPath();
+
+        ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
+        System.out.println( originalLoader.getClass() );
+
+        setupClassloader();
+        originalLoader = Thread.currentThread().getContextClassLoader();
+        System.out.println( originalLoader.getClass() );
+        
+        SAXParserFactoryImpl spi = new SAXParserFactoryImpl();
+        SAXParserFactory spf = SAXParserFactory.newInstance();
+        this.getLog().info( spf.toString() );
+        String t = "org/apache/xerces/jaxp/SAXParserFactoryImpl.class";
+        this.getLog().info(t);
+        URL url = originalLoader.getResource(t);
+        //URL url = spf.getClass().getClassLoader().getResource("javax/xml/parsers/SAXParserFactory.class");
+        this.getLog().info("Loaded from: "+url.toString());
+        
+    }
+
+    /**
+     * Adds nessessary items to the classloader.
+     * 
+     * @return ClassLoader original Classloader.
+     * @throws MojoExecutionException
+     */
+    public ClassLoader setupClassloader()
+        throws MojoExecutionException
+    {
+
+        URLClassLoader loader = null;
+        ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
+        this.getLog().info( originalLoader.toString() );
+        URL[] urls = new URL[0];
+        loader = new URLClassLoader( urls, originalLoader );
+
+        Thread.currentThread().setContextClassLoader( loader );
+        printURLClassPath();
+        return originalLoader;
+
+    }
+
+    public void printURLClassPath()
+    {
+        //Get the Classloader
+        ClassLoader sysClassLoader = Thread.currentThread().getContextClassLoader();
+        //Get the URLs
+        URL[] urls = ( (URLClassLoader) sysClassLoader ).getURLs();
+        this.getLog().info( "Added to Classpath:" );
+        for ( int i = 0; i < urls.length; i++ )
+        {
+            this.getLog().info( urls[i].getFile() );
+        }
+    }
+
+    public void printClassPath()
+    {
+        ClassLoader sysClassLoader = Thread.currentThread().getContextClassLoader();
+        URL[] urls = null;
+        Field field;
+        try
+        {
+
+            field = sysClassLoader.getClass().getDeclaredField( "realm" );
+            field.setAccessible( true );
+            ClassRealm realm = (ClassRealm) field.get( sysClassLoader );
+
+            urls = realm.getConstituents();
+        }
+        catch ( SecurityException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        catch ( NoSuchFieldException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        catch ( IllegalArgumentException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        catch ( IllegalAccessException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        //URL[] urls = ( (URLClassLoader) sysClassLoader ).getURLs();
+        this.getLog().info( "Initial Classpath:" );
+        for ( int i = 0; i < urls.length; i++ )
+        {
+            this.getLog().info( urls[i].getFile() );
+        }
+    }
+}

Propchange: maven/components/trunk/maven-core-it/it0094/mojo/src/main/java/org/codehaus/mojo/kodo/Enhance.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0094/mojo/src/main/java/org/codehaus/mojo/kodo/Enhance.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it0094/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0094/pom.xml?rev=379268&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0094/pom.xml (added)
+++ maven/components/trunk/maven-core-it/it0094/pom.xml Mon Feb 20 14:51:50 2006
@@ -0,0 +1,15 @@
+<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.it</groupId>
+  <artifactId>maven-core-it0094</artifactId>
+  <packaging>pom</packaging>
+  <version>1.0-SNAPSHOT</version>
+
+  <modules>
+    <module>mojo</module>
+    <module>test</module>
+  </modules>  
+
+</project>

Propchange: maven/components/trunk/maven-core-it/it0094/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0094/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it0094/test/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0094/test/pom.xml?rev=379268&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0094/test/pom.xml (added)
+++ maven/components/trunk/maven-core-it/it0094/test/pom.xml Mon Feb 20 14:51:50 2006
@@ -0,0 +1,33 @@
+<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>
+  <parent>
+    <groupId>org.apache.maven.it</groupId>
+    <artifactId>maven-core-it0094</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>maven-core-it0094-test</artifactId>
+
+  <dependencies>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.it</groupId>
+        <artifactId>maven-core-it0094-mojo</artifactId>
+        <executions>
+          <execution>
+            <id>process-classes</id>
+            <phase>process-classes</phase>
+            <goals>
+              <goal>enhance</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: maven/components/trunk/maven-core-it/it0094/test/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0094/test/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"