brett       2005/04/03 22:08:45

  Modified:    maven-mboot2/src/main/java/download ArtifactDownloader.java
               maven-mboot2/src/main/java/model Dependency.java
                        ModelReader.java
               maven-mboot2/src/main/java MBoot.java
  Added:       maven-mboot2/src/main/java/model Repository.java
  Log:
  isolate path generation in Repository class
  
  Revision  Changes    Path
  1.5       +14 -40    
maven-components/maven-mboot2/src/main/java/download/ArtifactDownloader.java
  
  Index: ArtifactDownloader.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-mboot2/src/main/java/download/ArtifactDownloader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ArtifactDownloader.java   4 Apr 2005 01:40:16 -0000       1.4
  +++ ArtifactDownloader.java   4 Apr 2005 05:08:45 -0000       1.5
  @@ -1,6 +1,7 @@
   package download;
   
   import model.Dependency;
  +import model.Repository;
   
   import java.io.File;
   import java.io.FileNotFoundException;
  @@ -14,8 +15,6 @@
   {
       public static final String SNAPSHOT_SIGNATURE = "-SNAPSHOT";
   
  -    private File mavenRepoLocal;
  -
       private List remoteRepos;
   
       private boolean useTimestamp = true;
  @@ -30,7 +29,9 @@
   
       private String proxyPassword;
   
  -    public ArtifactDownloader( String localRepository, List 
remoteRepositories )
  +    private Repository localRepository;
  +
  +    public ArtifactDownloader( Repository localRepository, List 
remoteRepositories )
           throws Exception
       {
           setRemoteRepos( remoteRepositories );
  @@ -42,34 +43,12 @@
               System.exit( 1 );
           }
   
  -        mavenRepoLocal = new File( localRepository );
  -
  -        if ( !mavenRepoLocal.exists() )
  -        {
  -            if ( !mavenRepoLocal.mkdirs() )
  -            {
  -                System.err.println( "Cannot create the specified local 
repository: " + mavenRepoLocal );
  -
  -                System.exit( 1 );
  -            }
  -        }
  -
  -        if ( !mavenRepoLocal.canWrite() )
  -        {
  -            System.err.println( "Can't write to " + 
mavenRepoLocal.getAbsolutePath() );
  +        this.localRepository = localRepository;
   
  -            System.exit( 1 );
  -        }
  -
  -        System.out.println( "Using the following for your local repository: 
" + mavenRepoLocal );
  +        System.out.println( "Using the following for your local repository: 
" + localRepository );
           System.out.println( "Using the following for your remote 
repositories: " + remoteRepos );
       }
   
  -    public File getMavenRepoLocal()
  -    {
  -        return mavenRepoLocal;
  -    }
  -
       private Set downloadedArtifacts = new HashSet();
   
       public void setProxy( String host, String port, String userName, String 
password )
  @@ -90,8 +69,7 @@
   
               if ( !downloadedArtifacts.contains( dep.getId() ) )
               {
  -                String repositoryPath = dep.getRepositoryPath();
  -                File destinationFile = new File( mavenRepoLocal, 
repositoryPath );
  +                File destinationFile = localRepository.getArtifactFile( dep 
);
                   // The directory structure for this project may
                   // not exists so create it if missing.
                   File directory = destinationFile.getParentFile();
  @@ -106,7 +84,7 @@
                       continue;
                   }
   
  -                getRemoteArtifact( repositoryPath, destinationFile );
  +                getRemoteArtifact( dep, destinationFile );
   
                   if ( !destinationFile.exists() )
                   {
  @@ -129,26 +107,22 @@
   
           if ( repositories.isEmpty() )
           {
  -            remoteRepos.add( "http://repo1.maven.org"; );
  +            // TODO: configure layout
  +            remoteRepos.add( new Repository( "http://repo1.maven.org";, 
Repository.LAYOUT_LEGACY ) );
           }
       }
   
  -    private List getRemoteRepos()
  -    {
  -        return remoteRepos;
  -    }
  -
  -    private boolean getRemoteArtifact( String file, File destinationFile )
  +    private boolean getRemoteArtifact( Dependency dep, File destinationFile )
       {
           boolean fileFound = false;
   
  -        for ( Iterator i = getRemoteRepos().iterator(); i.hasNext(); )
  +        for ( Iterator i = remoteRepos.iterator(); i.hasNext(); )
           {
  -            String remoteRepo = (String) i.next();
  +            Repository remoteRepo = (Repository) i.next();
   
               // The username and password parameters are not being
               // used here. Those are the "" parameters you see below.
  -            String url = remoteRepo + "/" + file;
  +            String url = remoteRepo.getArtifactPath( dep );
   
               if ( !url.startsWith( "file" ) )
               {
  
  
  
  1.5       +3 -12     
maven-components/maven-mboot2/src/main/java/model/Dependency.java
  
  Index: Dependency.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-mboot2/src/main/java/model/Dependency.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Dependency.java   4 Apr 2005 02:57:27 -0000       1.4
  +++ Dependency.java   4 Apr 2005 05:08:45 -0000       1.5
  @@ -43,11 +43,12 @@
       {
       }
   
  -    public Dependency( String groupId, String artifactId, String version )
  +    public Dependency( String groupId, String artifactId, String version, 
String type )
       {
           this.version = version;
           this.artifactId = artifactId;
           this.groupId = groupId;
  +        this.type = type;
       }
   
       public void setId( String id )
  @@ -193,14 +194,4 @@
   
           return false;
       }
  -
  -    public String getRepositoryPath()
  -    {
  -        return getArtifactDirectory() + "/" + getType() + "s/" + 
getArtifact();
  -    }
  -
  -    public String toString()
  -    {
  -        return getRepositoryPath();
  -    }
   }
  
  
  
  1.3       +29 -26    
maven-components/maven-mboot2/src/main/java/model/ModelReader.java
  
  Index: ModelReader.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-mboot2/src/main/java/model/ModelReader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ModelReader.java  4 Apr 2005 02:01:49 -0000       1.2
  +++ ModelReader.java  4 Apr 2005 05:08:45 -0000       1.3
  @@ -16,12 +16,10 @@
    * limitations under the License.
    */
   
  -import download.ArtifactDownloader;
   import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
   import util.AbstractReader;
   
  -import java.io.File;
   import java.util.ArrayList;
   import java.util.List;
   
  @@ -51,7 +49,7 @@
   
       private List dependencies = new ArrayList();
   
  -    private List remoteRepositories = new ArrayList();
  +    private List repositories = new ArrayList();
   
       private List resources = new ArrayList();
   
  @@ -71,16 +69,18 @@
   
       private StringBuffer bodyText = new StringBuffer();
   
  -    private final ArtifactDownloader downloader;
  +    private final Repository localRepository;
   
  -    public ModelReader( ArtifactDownloader downloader )
  +    private Repository currentRepository;
  +
  +    public ModelReader( Repository downloader )
       {
  -        this.downloader = downloader;
  +        this.localRepository = downloader;
       }
   
       public List getRemoteRepositories()
       {
  -        return remoteRepositories;
  +        return repositories;
       }
   
       public List getDependencies()
  @@ -101,6 +101,8 @@
           }
           else if ( rawName.equals( "repository" ) )
           {
  +            currentRepository = new Repository();
  +
               insideRepository = true;
           }
           else if ( rawName.equals( "dependency" ) )
  @@ -140,8 +142,6 @@
           // support both v3 <extend> and v4 <parent>
           if ( rawName.equals( "parent" ) )
           {
  -            File f;
  -
               if ( parentArtifactId == null || 
parentArtifactId.trim().length() == 0 )
               {
                   throw new SAXException( "Missing required element in 
<parent>: artifactId." );
  @@ -167,12 +167,9 @@
                   version = parentVersion;
               }
   
  -            f = new File( downloader.getMavenRepoLocal(), parentGroupId + 
"/poms/" + parentArtifactId + "-" +
  -                                                          parentVersion + 
".pom" );
  +            ModelReader p = new ModelReader( localRepository );
   
  -            ModelReader p = new ModelReader( downloader );
  -
  -            if ( !p.parse( f ) )
  +            if ( !p.parse( localRepository.getArtifactFile( parentGroupId, 
parentArtifactId, parentVersion, "pom" ) ) )
               {
                   throw new SAXException( "Could not parse parent pom.xml" );
               }
  @@ -201,6 +198,12 @@
   
               insideResource = false;
           }
  +        else if ( rawName.equals( "repository" ) )
  +        {
  +            repositories.add( currentRepository );
  +
  +            insideRepository = false;
  +        }
           else if ( insideParent )
           {
               if ( rawName.equals( "groupId" ) )
  @@ -262,6 +265,17 @@
                   currentResource.addExclude( getBodyText() );
               }
           }
  +        else if ( insideRepository )
  +        {
  +            if ( rawName.equals( "url" ) )
  +            {
  +                currentRepository.setBasedir( getBodyText() );
  +            }
  +            else if ( rawName.equals( "layout" ) )
  +            {
  +                currentRepository.setLayout( getBodyText() );
  +            }
  +        }
           else if ( depth == 2 )
           {
               if ( rawName.equals( "artifactId" ) )
  @@ -280,17 +294,6 @@
               {
                   packaging = getBodyText();
               }
  -            else if ( rawName.equals( "repository" ) )
  -            {
  -                insideRepository = false;
  -            }
  -        }
  -        else if ( insideRepository )
  -        {
  -            if ( rawName.equals( "url" ) )
  -            {
  -                remoteRepositories.add( getBodyText() );
  -            }
           }
   
           bodyText = new StringBuffer();
  
  
  
  1.1                  
maven-components/maven-mboot2/src/main/java/model/Repository.java
  
  Index: Repository.java
  ===================================================================
  package model;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   *
   * 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.
   */
  
  import java.io.File;
  
  /**
   * Repository path management.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
   * @version $Id: Repository.java,v 1.1 2005/04/04 05:08:45 brett Exp $
   */
  public class Repository
  {
      private String basedir;
  
      public static final String LAYOUT_LEGACY = "legacy";
  
      private String layout = LAYOUT_LEGACY;
  
      public Repository()
      {
      }
  
      public Repository( String basedir, String layout )
      {
          this.basedir = basedir;
          this.layout = layout;
      }
  
      public File getArtifactFile( String groupId, String artifactId, String 
version, String type )
      {
          Dependency d = new Dependency( groupId, artifactId, version, type );
  
          return getArtifactFile( d );
  
      }
  
      public File getArtifactFile( Dependency dependency )
      {
          String repositoryPath = getArtifactPath( dependency );
  
          return new File( basedir, repositoryPath );
      }
  
      public String getArtifactPath( Dependency dependency )
      {
          String repositoryPath;
          if ( LAYOUT_LEGACY.equals( layout ) )
          {
              repositoryPath = dependency.getArtifactDirectory() + "/" + 
dependency.getType() + "s/" +
                  dependency.getArtifact();
          }
          else
          {
              throw new IllegalStateException( "Unknown layout: " + layout );
          }
          return repositoryPath;
      }
  
      public File getMetadataFile( String groupId, String artifactId, String 
version, String type, String filename )
      {
          Dependency d = new Dependency( groupId, artifactId, version, type );
  
          String repositoryPath;
          if ( LAYOUT_LEGACY.equals( layout ) )
          {
              repositoryPath = d.getArtifactDirectory() + "/poms/" + filename;
          }
          else
          {
              throw new IllegalStateException( "Unknown layout: " + layout );
          }
  
          return new File( basedir, repositoryPath );
      }
  
      public String toString()
      {
          return basedir;
      }
  
      public String getBasedir()
      {
          return basedir;
      }
  
      public void setBasedir( String basedir )
      {
          this.basedir = basedir;
      }
  
      public void setLayout( String layout )
      {
          this.layout = layout;
      }
  
  }
  
  
  
  1.86      +86 -67    maven-components/maven-mboot2/src/main/java/MBoot.java
  
  Index: MBoot.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-mboot2/src/main/java/MBoot.java,v
  retrieving revision 1.85
  retrieving revision 1.86
  diff -u -r1.85 -r1.86
  --- MBoot.java        4 Apr 2005 02:57:27 -0000       1.85
  +++ MBoot.java        4 Apr 2005 05:08:45 -0000       1.86
  @@ -5,6 +5,7 @@
   import jar.JarMojo;
   import model.Dependency;
   import model.ModelReader;
  +import model.Repository;
   import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
   import test.SurefirePlugin;
  @@ -18,6 +19,7 @@
   import java.io.File;
   import java.io.FileNotFoundException;
   import java.io.FileWriter;
  +import java.io.IOException;
   import java.io.StringReader;
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
  @@ -91,10 +93,6 @@
   
       private ArtifactDownloader downloader;
   
  -    private String repoLocal;
  -
  -    private List coreDeps;
  -
       private boolean online = true;
   
       private static final String SCOPE_TEST = "test";
  @@ -138,8 +136,6 @@
       public void run( String[] args )
           throws Exception
       {
  -        ModelReader reader = new ModelReader( downloader );
  -
           String mavenRepoLocal = System.getProperty( "maven.repo.local" );
   
           SettingsReader userModelReader = new SettingsReader();
  @@ -202,7 +198,16 @@
               System.out.println( "HOWEVER, since you did not specify a 
repository path, maven will use: " +
                                   repoDir.getAbsolutePath() + " to store 
artifacts locally." );
           }
  -        repoLocal = mavenRepoLocal;
  +
  +        File repoLocalFile = new File( mavenRepoLocal );
  +        repoLocalFile.mkdirs();
  +
  +        if ( !repoLocalFile.canWrite() )
  +        {
  +            System.err.println( "Can't write to " + mavenRepoLocal );
  +
  +            System.exit( 1 );
  +        }
   
           String mavenHome = null;
   
  @@ -235,9 +240,13 @@
               online = false;
           }
   
  +        Repository localRepository = new Repository( mavenRepoLocal, 
Repository.LAYOUT_LEGACY );
  +
  +        ModelReader reader = new ModelReader( localRepository );
  +
           if ( online )
           {
  -            downloader = new ArtifactDownloader( repoLocal, 
reader.getRemoteRepositories() );
  +            downloader = new ArtifactDownloader( localRepository, 
reader.getRemoteRepositories() );
               if ( userModelReader.getActiveProxy() != null )
               {
                   Proxy proxy = userModelReader.getActiveProxy();
  @@ -245,34 +254,38 @@
               }
           }
   
  -        reader = new ModelReader( downloader );
  +        reader = new ModelReader( localRepository );
   
           String basedir = System.getProperty( "user.dir" );
   
           reader.parse( new File( basedir, "maven-mboot2/pom.xml" ) );
   
  -        ClassLoader bootstrapClassLoader = 
createClassloaderFromDependencies( reader.getDependencies(), null );
  +        ClassLoader bootstrapClassLoader = 
createClassloaderFromDependencies( reader.getDependencies(), null,
  +                                                                             
 localRepository );
   
  -        reader = new ModelReader( downloader );
  +        reader = new ModelReader( localRepository );
           reader.parse( new File( basedir, 
"maven-plugins/maven-surefire-plugin/pom.xml" ) );
           List surefireDependencies = reader.getDependencies();
   
  -        reader = new ModelReader( downloader );
  +        reader = new ModelReader( localRepository );
   
           // Install maven-components POM
  -        installPomFile( repoLocal, new File( basedir, "pom.xml" ) );
  +        installPomFile( localRepository, new File( basedir, "pom.xml" ) );
   
           // Install plugin-parent POM
  -        installPomFile( repoLocal, new File( basedir, 
"maven-plugins/pom.xml" ) );
  +        installPomFile( localRepository, new File( basedir, 
"maven-plugins/pom.xml" ) );
   
           // Install plugin-tools-parent POM
  -        installPomFile( repoLocal, new File( basedir, 
"maven-plugin-tools/pom.xml" ) );
  +        installPomFile( localRepository, new File( basedir, 
"maven-plugin-tools/pom.xml" ) );
   
           // Install maven-script-parent POM
  -        installPomFile( repoLocal, new File( basedir, "maven-script/pom.xml" 
) );
  +        installPomFile( localRepository, new File( basedir, 
"maven-script/pom.xml" ) );
   
           // Install it-support POM
  -        installPomFile( repoLocal, new File( basedir, 
"maven-core-it-support/pom.xml" ) );
  +        installPomFile( localRepository, new File( basedir, 
"maven-core-it-support/pom.xml" ) );
  +
  +        List coreDeps = null;
  +        Dependency corePom = null;
   
           for ( int i = 0; i < builds.length; i++ )
           {
  @@ -284,21 +297,25 @@
   
               System.setProperty( "basedir", directory );
   
  -            reader = buildProject( directory, builds[i], 
bootstrapClassLoader, surefireDependencies );
  +            reader = buildProject( directory, builds[i], 
bootstrapClassLoader, surefireDependencies, localRepository );
   
               if ( reader.getArtifactId().equals( "maven-core" ) )
               {
                   coreDeps = reader.getDependencies();
  +                corePom = new Dependency( reader.getGroupId(), 
reader.getArtifactId(), reader.getVersion(),
  +                                          reader.getPackaging() );
               }
   
               System.out.println( 
"--------------------------------------------------------------------" );
           }
   
  -        reader = new ModelReader( downloader );
  +        reader = new ModelReader( localRepository );
           reader.parse( new File( basedir, 
"maven-plugin-tools/maven-plugin-tools-pluggy/pom.xml" ) );
           List dependencies = new ArrayList( reader.getDependencies() );
  -        dependencies.add( new Dependency( reader.getGroupId(), 
reader.getArtifactId(), reader.getVersion() ) );
  -        IsolatedClassLoader cl = createClassloaderFromDependencies( 
dependencies, bootstrapClassLoader );
  +        dependencies.add(
  +            new Dependency( reader.getGroupId(), reader.getArtifactId(), 
reader.getVersion(), reader.getPackaging() ) );
  +        IsolatedClassLoader cl = createClassloaderFromDependencies( 
dependencies, bootstrapClassLoader,
  +                                                                    
localRepository );
   
           for ( int i = 0; i < pluginBuilds.length; i++ )
           {
  @@ -310,7 +327,7 @@
   
               System.setProperty( "basedir", directory );
   
  -            reader = buildProject( directory, pluginBuilds[i], cl, 
surefireDependencies );
  +            reader = buildProject( directory, pluginBuilds[i], cl, 
surefireDependencies, localRepository );
   
               System.out.println( 
"--------------------------------------------------------------------" );
           }
  @@ -370,7 +387,7 @@
           {
               Dependency d = (Dependency) i.next();
   
  -            File source = new File( repoLocal, d.getRepositoryPath() );
  +            File source = localRepository.getArtifactFile( d );
               if ( d.getArtifactId().equals( "classworlds" ) )
               {
                   FileUtils.copyFileToDirectory( source, boot );
  @@ -386,9 +403,7 @@
           }
   
           // Copy maven itself
  -
  -        // TODO: create a dependency object
  -        FileUtils.copyFileToDirectory( new File( repoLocal, 
"org.apache.maven/jars/maven-core-2.0-SNAPSHOT.jar" ), lib );
  +        FileUtils.copyFileToDirectory( localRepository.getArtifactFile( 
corePom ), lib );
   
           System.out.println();
   
  @@ -429,13 +444,13 @@
           System.out.println( "Finished at: " + fullStop );
       }
   
  -    public ModelReader buildProject( String basedir, String projectId, 
ClassLoader classLoader,
  -                                     List surefireDependencies )
  +    private ModelReader buildProject( String basedir, String projectId, 
ClassLoader classLoader,
  +                                      List surefireDependencies, Repository 
localRepository )
           throws Exception
       {
           System.out.println( "Building project in " + basedir );
   
  -        ModelReader reader = new ModelReader( downloader );
  +        ModelReader reader = new ModelReader( localRepository );
   
           if ( !reader.parse( new File( basedir, "pom.xml" ) ) )
           {
  @@ -532,11 +547,12 @@
   
           if ( new File( generatedSources ).exists() )
           {
  -            compile( reader.getDependencies(), sources, classes, null, 
generatedSources, SCOPE_COMPILE );
  +            compile( reader.getDependencies(), sources, classes, null, 
generatedSources, SCOPE_COMPILE,
  +                     localRepository );
           }
           else
           {
  -            compile( reader.getDependencies(), sources, classes, null, null, 
SCOPE_COMPILE );
  +            compile( reader.getDependencies(), sources, classes, null, null, 
SCOPE_COMPILE, localRepository );
           }
   
           // 
----------------------------------------------------------------------
  @@ -548,7 +564,7 @@
               System.out.println( "Generating maven plugin descriptor ..." );
   
               generatePluginDescriptor( sources, new File( classes, 
"META-INF/maven" ).getAbsolutePath(),
  -                                      new File( basedir, "pom.xml" 
).getAbsolutePath(), classLoader );
  +                                      new File( basedir, "pom.xml" 
).getAbsolutePath(), classLoader, localRepository );
           }
   
           // 
----------------------------------------------------------------------
  @@ -567,7 +583,7 @@
   
           List testDependencies = reader.getDependencies();
   
  -        compile( testDependencies, testSources, testClasses, classes, null, 
SCOPE_TEST );
  +        compile( testDependencies, testSources, testClasses, classes, null, 
SCOPE_TEST, localRepository );
   
           // 
----------------------------------------------------------------------
           // Test resources
  @@ -581,7 +597,7 @@
           // Run tests
           // 
----------------------------------------------------------------------
   
  -        runTests( basedir, classes, testClasses, reader, 
surefireDependencies );
  +        runTests( basedir, classes, testClasses, reader, 
surefireDependencies, localRepository );
   
           // 
----------------------------------------------------------------------
           // Create JAR
  @@ -589,30 +605,32 @@
   
           createJar( classes, buildDir, reader );
   
  -        installPom( basedir, repoLocal, reader );
  +        installPom( basedir, localRepository, reader );
   
           String artifactId = reader.getArtifactId();
   
           if ( !artifactId.equals( "maven-plugin" ) && artifactId.endsWith( 
"plugin" ) )
           {
  -            install( basedir, repoLocal, reader, "maven-plugin" );
  +            install( basedir, localRepository, reader, "maven-plugin" );
           }
           else
           {
  -            install( basedir, repoLocal, reader, "jar" );
  +            install( basedir, localRepository, reader, "jar" );
           }
   
           return reader;
       }
   
  -    private void generatePluginDescriptor( String sourceDirectory, String 
outputDirectory, String pom, ClassLoader cl )
  +    private void generatePluginDescriptor( String sourceDirectory, String 
outputDirectory, String pom, ClassLoader cl,
  +                                           Repository localRepository )
           throws Exception
       {
           Class cls = cl.loadClass( 
"org.apache.maven.tools.plugin.pluggy.Main" );
   
           Method m = cls.getMethod( "main", new Class[]{String[].class} );
   
  -        String[] args = {"descriptor", sourceDirectory, outputDirectory, 
pom, repoLocal};
  +        // Can pluggy really cope with the layout?
  +        String[] args = {"descriptor", sourceDirectory, outputDirectory, 
pom, localRepository.getBasedir()};
   
           m.invoke( null, new Object[]{args} );
       }
  @@ -638,7 +656,8 @@
           Thread.currentThread().setContextClassLoader( old );
       }
   
  -    private IsolatedClassLoader createClassloaderFromDependencies( List 
dependencies, ClassLoader parent )
  +    private IsolatedClassLoader createClassloaderFromDependencies( List 
dependencies, ClassLoader parent,
  +                                                                   
Repository localRepository )
           throws Exception
       {
           if ( online )
  @@ -662,7 +681,7 @@
           {
               Dependency dependency = (Dependency) i.next();
   
  -            File f = new File( repoLocal, dependency.getRepositoryPath() );
  +            File f = localRepository.getArtifactFile( dependency );
               if ( !f.exists() )
               {
                   String msg = ( !online ? "; run again online" : "; there was 
a problem downloading it earlier" );
  @@ -687,10 +706,10 @@
           jarMojo.execute( new File( classes ), buildDir, artifactId + "-" + 
version );
       }
   
  -    private void installPomFile( String repoLocal, File pomIn )
  +    private void installPomFile( Repository localRepository, File pomIn )
           throws Exception
       {
  -        ModelReader reader = new ModelReader( downloader );
  +        ModelReader reader = new ModelReader( localRepository );
   
           if ( !reader.parse( pomIn ) )
           {
  @@ -699,21 +718,18 @@
               System.exit( 1 );
           }
   
  -        String artifactId = reader.getArtifactId();
  -
  -        String version = reader.getVersion();
  -
  -        String groupId = reader.getGroupId();
  -
  -        File pom = new File( repoLocal, "/" + groupId + "/poms/" + 
artifactId + "-" + version + ".pom" );
  +        installPomFile( reader, localRepository, pomIn );
  +    }
   
  -        System.out.println( "Installing POM: " + pom );
  +    private void installPom( String basedir, Repository localRepository, 
ModelReader reader )
  +        throws Exception
  +    {
  +        installPomFile( reader, localRepository, new File( basedir, 
"pom.xml" ) );
   
  -        FileUtils.copyFile( pomIn, pom );
       }
   
  -    private void installPom( String basedir, String repoLocal, ModelReader 
reader )
  -        throws Exception
  +    private void installPomFile( ModelReader reader, Repository 
localRepository, File source )
  +        throws IOException
       {
           String artifactId = reader.getArtifactId();
   
  @@ -721,14 +737,14 @@
   
           String groupId = reader.getGroupId();
   
  -        File pom = new File( repoLocal, "/" + groupId + "/poms/" + 
artifactId + "-" + version + ".pom" );
  +        File pom = localRepository.getArtifactFile( groupId, artifactId, 
version, "pom" );
   
           System.out.println( "Installing POM: " + pom );
   
  -        FileUtils.copyFile( new File( basedir, "pom.xml" ), pom );
  +        FileUtils.copyFile( source, pom );
       }
   
  -    private void install( String basedir, String repoLocal, ModelReader 
reader, String type )
  +    private void install( String basedir, Repository localRepository, 
ModelReader reader, String type )
           throws Exception
       {
           String artifactId = reader.getArtifactId();
  @@ -739,22 +755,24 @@
   
           String finalName = artifactId + "-" + version;
   
  -        File file = new File( repoLocal, "/" + groupId + "/" + type + "s/" + 
finalName + ".jar" );
  +        File file = localRepository.getArtifactFile( groupId, artifactId, 
version, type );
   
           System.out.println( "Installing: " + file );
   
  -        FileUtils.copyFile( new File( basedir, BUILD_DIR + "/" + finalName + 
".jar" ), file );
  -
           if ( version.indexOf( "SNAPSHOT" ) >= 0 )
           {
  -            File metadata = new File( repoLocal, "/" + groupId + "/poms/" + 
finalName + ".version.txt" );
  +            File metadata = localRepository.getMetadataFile( groupId, 
artifactId, version, type,
  +                                                             finalName + 
".version.txt" );
   
               IOUtil.copy( new StringReader( version ), new FileWriter( 
metadata ) );
           }
  +
  +        FileUtils.copyFile( new File( basedir, BUILD_DIR + "/" + finalName + 
".jar" ), file );
  +
       }
   
       private void runTests( String basedir, String classes, String 
testClasses, ModelReader reader,
  -                           List surefireDependencies )
  +                           List surefireDependencies, Repository 
localRepository )
           throws Exception
       {
           SurefirePlugin testRunner = new SurefirePlugin();
  @@ -776,7 +794,7 @@
           List depList = new ArrayList( reader.getDependencies() );
           depList.addAll( surefireDependencies );
   
  -        List classpath = classpath( depList, null, SCOPE_TEST );
  +        List classpath = classpath( depList, null, SCOPE_TEST, 
localRepository );
           classpath.add( classes );
           classpath.add( testClasses );
           boolean success = testRunner.execute( basedir, includes, excludes, 
classpath, reportsDir );
  @@ -791,7 +809,7 @@
       // Compile
       // ----------------------------------------------------------------------
   
  -    private List classpath( List dependencies, String extraClasspath, String 
scope )
  +    private List classpath( List dependencies, String extraClasspath, String 
scope, Repository localRepository )
       {
           List classpath = new ArrayList( dependencies.size() + 1 );
   
  @@ -799,7 +817,7 @@
           {
               Dependency d = (Dependency) dependencies.get( i );
   
  -            String element = repoLocal + "/" + d.getRepositoryPath();
  +            String element = localRepository.getArtifactFile( d 
).getAbsolutePath();
   
               if ( SCOPE_COMPILE.equals( scope ) )
               {
  @@ -827,7 +845,7 @@
       }
   
       private void compile( List dependencies, String sourceDirectory, String 
outputDirectory, String extraClasspath,
  -                          String generatedSources, String scope )
  +                          String generatedSources, String scope, Repository 
localRepository )
           throws Exception
       {
           JavacCompiler compiler = new JavacCompiler();
  @@ -861,7 +879,8 @@
               CompilerConfiguration compilerConfiguration = new 
CompilerConfiguration();
   
               compilerConfiguration.setOutputLocation( outputDirectory );
  -            compilerConfiguration.setClasspathEntries( classpath( 
dependencies, extraClasspath, scope ) );
  +            compilerConfiguration.setClasspathEntries(
  +                classpath( dependencies, extraClasspath, scope, 
localRepository ) );
               compilerConfiguration.setSourceLocations( Arrays.asList( 
sourceDirectories ) );
   
               /* Compile with debugging info */
  
  
  

Reply via email to