You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by ev...@apache.org on 2004/01/13 18:38:31 UTC

cvs commit: maven-components/maven-mboot/src/main ArtifactDownloader.java IsolatedClassLoader.java TestRunnerBooter.java Bootstrapper.java

evenisse    2004/01/13 09:38:31

  Modified:    maven-mboot build
               maven-mboot/src/bash maven.functions
               maven-mboot/src/main Bootstrapper.java
  Added:       maven-mboot/src/main ArtifactDownloader.java
                        IsolatedClassLoader.java TestRunnerBooter.java
  Log:
  Complete refactoring of mboot. We can now add easily tests execution with includes and excludes
  
  Revision  Changes    Path
  1.3       +18 -1     maven-components/maven-mboot/build
  
  Index: build
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-mboot/build,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- build	3 Jan 2004 23:49:45 -0000	1.2
  +++ build	13 Jan 2004 17:38:30 -0000	1.3
  @@ -4,7 +4,23 @@
   
   . src/bash/maven.functions
   
  -compile . target/classes src/main
  +mkdir -p target/src
  +
  +cp src/main/ArtifactDownloader.java src/main/HttpUtils.java target/src
  +
  +compile . target/classes target/src
  +
  +runJava target/classes ArtifactDownloader junit/jars/junit-3.8.1.jar
  +runJava target/classes ArtifactDownloader maven/jars/surefire-runner-1.0.jar
  +runJava target/classes ArtifactDownloader plexus/jars/plexus-utils-1.0-beta-1.jar
  +
  +repoLocal=`cat bootstrap.repo`
  +
  +if $cygwin = true; then
  +  repoLocal=`cygpath -pu "$repoLocal"`
  +fi
  +
  +compile .:$repoLocal/junit/jars/junit-3.8.1.jar:$repoLocal/maven/jars/surefire-runner-1.0.jar:$repoLocal/plexus/jars/plexus-utils-1.0-beta-1.jar target/classes src/main
   
   isCommandSuccessful $? "Failed compiling Maven bootstrapper classes!"
   
  @@ -26,3 +42,4 @@
     
   chmod +x target/mboot-install.sh
   
  +rm -f bootstrap.repo > /dev/null 2>&1
  
  
  
  1.7       +1 -0      maven-components/maven-mboot/src/bash/maven.functions
  
  Index: maven.functions
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-mboot/src/bash/maven.functions,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- maven.functions	12 Jan 2004 17:14:43 -0000	1.6
  +++ maven.functions	13 Jan 2004 17:38:30 -0000	1.7
  @@ -173,6 +173,7 @@
           rm -f bootstrap.libs > /dev/null 2>&1
           rm -f bootstrap.resources > /dev/null 2>&1
           rm -f bootstrap.repo > /dev/null 2>&1
  +        rm -f bootstrap.test > /dev/null 2>&1
         fi
       )
   }
  
  
  
  1.6       +7 -279    maven-components/maven-mboot/src/main/Bootstrapper.java
  
  Index: Bootstrapper.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-mboot/src/main/Bootstrapper.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Bootstrapper.java	10 Jan 2004 13:53:10 -0000	1.5
  +++ Bootstrapper.java	13 Jan 2004 17:38:30 -0000	1.6
  @@ -22,30 +22,13 @@
   
   public class Bootstrapper
   {
  -    public static final String SNAPSHOT_SIGNATURE = "-SNAPSHOT";
  -
  +    private ArtifactDownloader downloader;
       private BootstrapPomParser bootstrapPomParser;
   
       private List dependencies;
   
       private List resources;
   
  -    private File mavenRepoLocal;
  -
  -    private boolean useTimestamp = true;
  -
  -    private boolean ignoreErrors = true;
  -
  -    private List remoteRepos = new ArrayList();
  -
  -    private String proxyHost;
  -
  -    private String proxyPort;
  -
  -    private String proxyUserName;
  -
  -    private String proxyPassword;
  -
       public static void main( String[] args )
           throws Exception
       {
  @@ -58,38 +41,8 @@
           throws Exception
       {
           String basedir = args[0];
  -
  -        Properties properties = loadProperties( new File( System.getProperty( "user.home" ), "build.properties" ) );
  -
  -        setRemoteRepo( properties.getProperty( "maven.repo.remote" ) );
  -
  -        String mavenRepoLocalProperty = properties.getProperty( "maven.repo.local" );
  -
  -        if ( mavenRepoLocalProperty == null )
  -        {
  -            mavenRepoLocalProperty = System.getProperty( "user.home" ) + "/.maven/repository";
  -        }
  -
  -        mavenRepoLocal = new File( mavenRepoLocalProperty );
  -
  -        if ( !mavenRepoLocal.exists() )
  -        {
  -            if ( !mavenRepoLocal.mkdirs() )
  -            {
  -                System.err.println( "Cannot create the specified maven.repo.local: " + mavenRepoLocal );
  -
  -                System.exit( 1 );
  -            }
  -        }
  -
  -        if ( !mavenRepoLocal.canWrite() )
  -        {
  -            System.err.println( "Can't write to " + mavenRepoLocal.getAbsolutePath() );
  -
  -            System.exit( 1 );
  -        }
  -
  -        System.out.println( "Using the following for your maven.repo.local: " + mavenRepoLocal );
  +        
  +        downloader = new ArtifactDownloader();
   
           bootstrapPomParser = new BootstrapPomParser();
   
  @@ -106,7 +59,7 @@
               list.add( getArtifactPath( d, "/" ) );
           }
   
  -        downloadDependencies( list );
  +        downloader.downloadDependencies( list );
   
           StringBuffer classPath = new StringBuffer();
   
  @@ -116,9 +69,9 @@
           {
               Dependency d = (Dependency) i.next();
   
  -            classPath.append( mavenRepoLocal + "/" + getArtifactPath( d, "/" ) + ":" );
  +            classPath.append( downloader.getMavenRepoLocal() + "/" + getArtifactPath( d, "/" ) + ":" );
   
  -            libs.append( mavenRepoLocal + "/" + getArtifactPath( d, "/" ) + "\n" );
  +            libs.append( downloader.getMavenRepoLocal() + "/" + getArtifactPath( d, "/" ) + "\n" );
           }
   
           writeFile( "bootstrap.classpath", classPath.toString() );
  @@ -178,7 +131,7 @@
   
           writeFile( "bootstrap.resources", res.toString() );
   
  -        writeFile( "bootstrap.repo", mavenRepoLocal.getPath() );
  +        writeFile( "bootstrap.repo", downloader.getMavenRepoLocal().getPath() );
       }
   
       private void writeFile( String name, String contents )
  @@ -194,231 +147,6 @@
       private String getArtifactPath( Dependency d, String pathSeparator )
       {
           return d.getArtifactDirectory() + pathSeparator + "jars" + pathSeparator + d.getArtifact();
  -    }
  -
  -    private void downloadDependencies( List files )
  -        throws Exception
  -    {
  -        for ( Iterator j = files.iterator(); j.hasNext(); )
  -        {
  -            try
  -            {
  -                String file = (String) j.next();
  -
  -                File destinationFile = new File( mavenRepoLocal, file );
  -
  -                // The directory structure for this project may
  -                // not exists so create it if missing.
  -                File directory = destinationFile.getParentFile();
  -
  -                if ( directory.exists() == false )
  -                {
  -                    directory.mkdirs();
  -                }
  -
  -                if ( destinationFile.exists() && !file.endsWith( SNAPSHOT_SIGNATURE ) )
  -                {
  -                    continue;
  -                }
  -
  -                log( "Downloading dependency: " + file );
  -
  -                getRemoteArtifact( file, destinationFile );
  -
  -                if ( !destinationFile.exists() )
  -                {
  -                    throw new Exception( "Failed to download " + file );
  -                }
  -            }
  -            catch ( Exception e )
  -            {
  -                throw new Exception( e );
  -            }
  -        }
  -    }
  -
  -    private void setRemoteRepo( String repos )
  -    {
  -        remoteRepos = new ArrayList();
  -
  -        if ( repos == null )
  -        {
  -            remoteRepos.add( "http://www.ibiblio.org/maven/" );
  -            return;
  -        }
  -
  -        StringTokenizer st = new StringTokenizer( repos, "," );
  -        while ( st.hasMoreTokens() )
  -        {
  -            remoteRepos.add( st.nextToken().trim() );
  -        }
  -    }
  -
  -    private List getRemoteRepo()
  -    {
  -        return remoteRepos;
  -    }
  -
  -    private boolean getRemoteArtifact( String file, File destinationFile )
  -    {
  -        boolean fileFound = false;
  -
  -        for ( Iterator i = getRemoteRepo().iterator(); i.hasNext(); )
  -        {
  -            String remoteRepo = (String) i.next();
  -
  -            // The username and password parameters are not being
  -            // used here. Those are the "" parameters you see below.
  -            String url = remoteRepo + "/" + file;
  -
  -            if ( !url.startsWith( "file" ) )
  -            {
  -                url = replace( url, "//", "/" );
  -                if ( url.startsWith( "https" ) )
  -                {
  -                    url = replace( url, "https:/", "https://" );
  -                }
  -                else
  -                {
  -                    url = replace( url, "http:/", "http://" );
  -                }
  -            }
  -
  -            // Attempt to retrieve the artifact and set the checksum if retrieval
  -            // of the checksum file was successful.
  -            try
  -            {
  -                HttpUtils.getFile( url,
  -                                   destinationFile,
  -                                   ignoreErrors,
  -                                   useTimestamp,
  -                                   proxyHost,
  -                                   proxyPort,
  -                                   proxyUserName,
  -                                   proxyPassword,
  -                                   true );
  -
  -                // Artifact was found, continue checking additional remote repos (if any)
  -                // in case there is a newer version (i.e. snapshots) in another repo
  -                fileFound = true;
  -            }
  -            catch ( FileNotFoundException e )
  -            {
  -                // Ignore
  -            }
  -            catch ( Exception e )
  -            {
  -                // If there are additional remote repos, then ignore exception
  -                // as artifact may be found in another remote repo. If there
  -                // are no more remote repos to check and the artifact wasn't found in
  -                // a previous remote repo, then artifactFound is false indicating
  -                // that the artifact could not be found in any of the remote repos
  -                //
  -                // arguably, we need to give the user better control (another command-
  -                // line switch perhaps) of what to do in this case? Maven already has
  -                // a command-line switch to work in offline mode, but what about when
  -                // one of two or more remote repos is unavailable? There may be multiple
  -                // remote repos for redundancy, in which case you probably want the build
  -                // to continue. There may however be multiple remote repos because some
  -                // artifacts are on one, and some are on another. In this case, you may
  -                // want the build to break.
  -                //
  -                // print a warning, in any case, so user catches on to mistyped
  -                // hostnames, or other snafus
  -                log( "Error retrieving artifact from [" + url + "]: " );
  -            }
  -        }
  -
  -        return fileFound;
  -    }
  -
  -    /**
  -     * <p>Replaces all occurrences of a String within another String.</p>
  -     *
  -     * This methods comes from Commons Lang
  -     *
  -     * <p>A <code>null</code> reference passed to this method is a no-op.</p>
  -     *
  -     * <pre>
  -     * StringUtils.replace(null, *, *)        = null
  -     * StringUtils.replace("", *, *)          = ""
  -     * StringUtils.replace("any", null, *)    = "any"
  -     * StringUtils.replace("any", *, null)    = "any"
  -     * StringUtils.replace("any", "", *)      = "any"
  -     * StringUtils.replace("aba", "a", null)  = "aba"
  -     * StringUtils.replace("aba", "a", "")    = "b"
  -     * StringUtils.replace("aba", "a", "z")   = "zbz"
  -     * </pre>
  -     *
  -     * @param text  text to search and replace in, may be null
  -     * @param repl  the String to search for, may be null
  -     * @param with  the String to replace with, may be null
  -     * @return the text with any replacements processed,
  -     *  <code>null</code> if null String input
  -     */
  -    private String replace( String text, String repl, String with )
  -    {
  -        StringBuffer buf = new StringBuffer( text.length() );
  -        int start = 0, end = 0;
  -        while ( ( end = text.indexOf( repl, start ) ) != -1 )
  -        {
  -            buf.append( text.substring( start, end ) ).append( with );
  -            start = end + repl.length();
  -        }
  -        buf.append( text.substring( start ) );
  -        return buf.toString();
  -    }
  -
  -    private void log( String message )
  -    {
  -        System.out.println( message );
  -    }
  -
  -    private Properties loadProperties( File file )
  -    {
  -        try
  -        {
  -            return loadProperties( new FileInputStream( file ) );
  -        }
  -        catch ( Exception e )
  -        {
  -            // ignore
  -        }
  -
  -        return new Properties();
  -    }
  -
  -    private static Properties loadProperties( InputStream is )
  -    {
  -        Properties properties = new Properties();
  -
  -        try
  -        {
  -            if ( is != null )
  -            {
  -                properties.load( is );
  -            }
  -        }
  -        catch ( IOException e )
  -        {
  -            // ignore
  -        }
  -        finally
  -        {
  -            try
  -            {
  -                if ( is != null )
  -                {
  -                    is.close();
  -                }
  -            }
  -            catch ( IOException e )
  -            {
  -                // ignore
  -            }
  -        }
  -
  -        return properties;
       }
   
       static class BootstrapPomParser
  
  
  
  1.1                  maven-components/maven-mboot/src/main/ArtifactDownloader.java
  
  Index: ArtifactDownloader.java
  ===================================================================
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.FileWriter;
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.Writer;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Properties;
  import java.util.StringTokenizer;
  
  public class ArtifactDownloader
  {
      public static final String SNAPSHOT_SIGNATURE = "-SNAPSHOT";
      
      private File mavenRepoLocal;
      
      private List remoteRepos;
      
      private boolean useTimestamp = true;
  
      private boolean ignoreErrors = true;
      
      private String proxyHost;
  
      private String proxyPort;
  
      private String proxyUserName;
  
      private String proxyPassword;
      
      public ArtifactDownloader() throws Exception
      {
          Properties properties = loadProperties( new File( System.getProperty( "user.home" ), "build.properties" ) );
  
          setRemoteRepo( properties.getProperty( "maven.repo.remote" ) );
  
          String mavenRepoLocalProperty = properties.getProperty( "maven.repo.local" );
  
          if ( mavenRepoLocalProperty == null )
          {
              mavenRepoLocalProperty = System.getProperty( "user.home" ) + "/.maven/repository";
          }
  
          mavenRepoLocal = new File( mavenRepoLocalProperty );
  
          if ( !mavenRepoLocal.exists() )
          {
              if ( !mavenRepoLocal.mkdirs() )
              {
                  System.err.println( "Cannot create the specified maven.repo.local: " + mavenRepoLocal );
  
                  System.exit( 1 );
              }
          }
  
          if ( !mavenRepoLocal.canWrite() )
          {
              System.err.println( "Can't write to " + mavenRepoLocal.getAbsolutePath() );
  
              System.exit( 1 );
          }
  
          writeFile( "bootstrap.repo", mavenRepoLocal.getPath() );
  
          System.out.println( "Using the following for your maven.repo.local: " + mavenRepoLocal );
      }
      
      public static void main(String[] args) throws Exception
      {
          ArtifactDownloader dl =new ArtifactDownloader();
          List tmp = new ArrayList();
          tmp.add(args[0]);
          dl.downloadDependencies(tmp);
      }
      
      private void writeFile( String name, String contents )
          throws Exception
      {
          Writer writer = new FileWriter( name );
  
          writer.write( contents );
  
          writer.close();
      }
  
      public File getMavenRepoLocal()
      {
          return mavenRepoLocal;
      }
      
      public void downloadDependencies( List files )
          throws Exception
      {
          for ( Iterator j = files.iterator(); j.hasNext(); )
          {
              try
              {
                  String file = (String) j.next();
  
                  File destinationFile = new File( mavenRepoLocal, file );
  
                  // The directory structure for this project may
                  // not exists so create it if missing.
                  File directory = destinationFile.getParentFile();
  
                  if ( directory.exists() == false )
                  {
                      directory.mkdirs();
                  }
  
                  if ( destinationFile.exists() && !file.endsWith( SNAPSHOT_SIGNATURE ) )
                  {
                      continue;
                  }
  
                  log( "Downloading dependency: " + file );
  
                  getRemoteArtifact( file, destinationFile );
  
                  if ( !destinationFile.exists() )
                  {
                      throw new Exception( "Failed to download " + file );
                  }
              }
              catch ( Exception e )
              {
                  throw new Exception( e );
              }
          }
      }
  
      private void setRemoteRepo( String repos )
      {
          remoteRepos = new ArrayList();
  
          if ( repos == null )
          {
              remoteRepos.add( "http://www.ibiblio.org/maven/" );
              return;
          }
          
          StringTokenizer st = new StringTokenizer( repos, "," );
          while ( st.hasMoreTokens() )
          {
              remoteRepos.add( st.nextToken().trim() );
          }
      }
  
      private List getRemoteRepo()
      {
          return remoteRepos;
      }
  
      private boolean getRemoteArtifact( String file, File destinationFile )
      {
          boolean fileFound = false;
  
          for ( Iterator i = getRemoteRepo().iterator(); i.hasNext(); )
          {
              String remoteRepo = (String) i.next();
  
              // The username and password parameters are not being
              // used here. Those are the "" parameters you see below.
              String url = remoteRepo + "/" + file;
  
              if ( !url.startsWith( "file" ) )
              {
                  url = replace( url, "//", "/" );
                  if ( url.startsWith( "https" ) )
                  {
                      url = replace( url, "https:/", "https://" );
                  }
                  else
                  {
                      url = replace( url, "http:/", "http://" );
                  }
              }
  
              // Attempt to retrieve the artifact and set the checksum if retrieval
              // of the checksum file was successful.
              try
              {
                  HttpUtils.getFile( url,
                                     destinationFile,
                                     ignoreErrors,
                                     useTimestamp,
                                     proxyHost,
                                     proxyPort,
                                     proxyUserName,
                                     proxyPassword,
                                     true );
  
                  // Artifact was found, continue checking additional remote repos (if any)
                  // in case there is a newer version (i.e. snapshots) in another repo
                  fileFound = true;
              }
              catch ( FileNotFoundException e )
              {
                  // Ignore
              }
              catch ( Exception e )
              {
                  // If there are additional remote repos, then ignore exception
                  // as artifact may be found in another remote repo. If there
                  // are no more remote repos to check and the artifact wasn't found in
                  // a previous remote repo, then artifactFound is false indicating
                  // that the artifact could not be found in any of the remote repos
                  //
                  // arguably, we need to give the user better control (another command-
                  // line switch perhaps) of what to do in this case? Maven already has
                  // a command-line switch to work in offline mode, but what about when
                  // one of two or more remote repos is unavailable? There may be multiple
                  // remote repos for redundancy, in which case you probably want the build
                  // to continue. There may however be multiple remote repos because some
                  // artifacts are on one, and some are on another. In this case, you may
                  // want the build to break.
                  //
                  // print a warning, in any case, so user catches on to mistyped
                  // hostnames, or other snafus
                  log( "Error retrieving artifact from [" + url + "]: " );
              }
          }
  
          return fileFound;
      }
  
      /**
       * <p>Replaces all occurrences of a String within another String.</p>
       *
       * This methods comes from Commons Lang
       *
       * <p>A <code>null</code> reference passed to this method is a no-op.</p>
       *
       * <pre>
       * StringUtils.replace(null, *, *)        = null
       * StringUtils.replace("", *, *)          = ""
       * StringUtils.replace("any", null, *)    = "any"
       * StringUtils.replace("any", *, null)    = "any"
       * StringUtils.replace("any", "", *)      = "any"
       * StringUtils.replace("aba", "a", null)  = "aba"
       * StringUtils.replace("aba", "a", "")    = "b"
       * StringUtils.replace("aba", "a", "z")   = "zbz"
       * </pre>
       *
       * @param text  text to search and replace in, may be null
       * @param repl  the String to search for, may be null
       * @param with  the String to replace with, may be null
       * @return the text with any replacements processed,
       *  <code>null</code> if null String input
       */
      private String replace( String text, String repl, String with )
      {
          StringBuffer buf = new StringBuffer( text.length() );
          int start = 0, end = 0;
          while ( ( end = text.indexOf( repl, start ) ) != -1 )
          {
              buf.append( text.substring( start, end ) ).append( with );
              start = end + repl.length();
          }
          buf.append( text.substring( start ) );
          return buf.toString();
      }
  
      private void log( String message )
      {
          System.out.println( message );
      }
      
      private Properties loadProperties( File file )
      {
          try
          {
              return loadProperties( new FileInputStream( file ) );
          }
          catch ( Exception e )
          {
              // ignore
          }
  
          return new Properties();
      }
  
      private static Properties loadProperties( InputStream is )
      {
          Properties properties = new Properties();
  
          try
          {
              if ( is != null )
              {
                  properties.load( is );
              }
          }
          catch ( IOException e )
          {
              // ignore
          }
          finally
          {
              try
              {
                  if ( is != null )
                  {
                      is.close();
                  }
              }
              catch ( IOException e )
              {
                  // ignore
              }
          }
  
          return properties;
      }
  }
  
  
  1.1                  maven-components/maven-mboot/src/main/IsolatedClassLoader.java
  
  Index: IsolatedClassLoader.java
  ===================================================================
  import java.net.URLClassLoader;
  import java.net.URL;
  
  /**
   *
   * 
   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
   *
   * @version $Id: IsolatedClassLoader.java,v 1.1 2004/01/13 17:38:30 evenisse Exp $
   */
  public class IsolatedClassLoader
      extends URLClassLoader
  {
      private ClassLoader parent = ClassLoader.getSystemClassLoader();
  
      public IsolatedClassLoader()
      {
          super( new URL[0], null );
      }
  
      public void addURL( URL url )
      {
          super.addURL( url );
      }
  
      public synchronized Class loadClass( String className )
          throws ClassNotFoundException
      {
          Class c = findLoadedClass( className );
  
          ClassNotFoundException ex = null;
  
          if ( c == null )
          {
              try
              {
                  c = findClass( className );
              }
              catch ( ClassNotFoundException e )
              {
                  ex = e;
  
                  if ( parent != null )
                  {
                      c = parent.loadClass( className );
                  }
              }
          }
  
          if ( c == null )
          {
              throw ex;
          }
  
          return c;
      }
  }
  
  
  
  1.1                  maven-components/maven-mboot/src/main/TestRunnerBooter.java
  
  Index: TestRunnerBooter.java
  ===================================================================
  import org.apache.maven.test.TestRunner;
  import org.codehaus.plexus.util.DirectoryScanner;
  import org.codehaus.plexus.util.StringUtils;
  
  import java.io.File;
  import java.lang.reflect.Method;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  public class TestRunnerBooter
  {
      public static void main(String[] args) throws Exception
      {
          TestRunnerBooter booter = new TestRunnerBooter();
          booter.execute(args);
      }
      
      public void execute(String[] args) throws Exception
      {
          File basedir = new File(args[0]);
          System.setProperty( "basedir", basedir.getPath() );
  
          String mavenRepoLocal = args[1];
  
          IsolatedClassLoader classLoader = new IsolatedClassLoader();
  
          Thread.currentThread().setContextClassLoader( classLoader );
  
          classLoader.addURL( new File ( mavenRepoLocal, "junit/jars/junit-3.8.1.jar" ).toURL() );
          classLoader.addURL( new File ( mavenRepoLocal, "maven/jars/surefire-runner-1.0.jar" ).toURL() );
          classLoader.addURL( new File( basedir, "target/classes/" ).toURL() );
          classLoader.addURL( new File( basedir, "target/test-classes/" ).toURL() );
          
          File dependenciesFile = new File(args[2]);
          
          processDependencies( dependencies, classLoader );
  
          File includesFile = new File(args[3]);
  
          File excludesFile = new File(args[4]);
          
          List includes = new ArrayList();
  
          List excludes = new ArrayList();
          
          String[] tests = collectTests( basedir,
                                         includes,
                                         excludes );
  
          Class testRunnerClass = classLoader.loadClass( "org.apache.maven.test.TestRunner" );
  
          Object testRunner = testRunnerClass.newInstance();
  
          Method m = testRunnerClass.getMethod( "runTestClasses", new Class[] {
              ClassLoader.class,
              String[].class
          } );
  
          m.invoke( testRunner, new Object[]{
              classLoader,
              tests
          } );
      }
      
      private void processDependencies(List dependencies, IsolatedClassLoader classLoader)
      {
          for (Iterator i=dependencies.iterator(); i.hasNext(); )
          {
              String dep = (String)i.next();
              classLoader.addURL( new File( dep ).toURL() );
          }
      }
      
      public String[] collectTests( File basedir, List includes, List excludes )
          throws Exception
      {
          DirectoryScanner scanner = new DirectoryScanner();
  
          scanner.setBasedir( new File( basedir, "target/test-classes" ) );
  
          String[] incs = new String[includes.size()];
  
          for ( int i = 0; i < incs.length; i++ )
          {
              incs[i] = StringUtils.replace( (String) includes.get( i ), "java", "class" );
          }
  
          scanner.setIncludes( incs );
  
          String[] excls = new String[excludes.size() + 1];
  
          for ( int i = 0; i < excls.length - 1; i++ )
          {
              excls[i] = StringUtils.replace( (String) excludes.get( i ), "java", "class" );
          }
  
          // Exclude inner classes
  
          excls[excludes.size()] = "**/*$*";
  
          scanner.setExcludes( excls );
  
          scanner.scan();
  
          return scanner.getIncludedFiles();
      }
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org