From bab8d3fd909f5ba07ec58c6ecc29a1011c94f910 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Mon, 4 Apr 2005 05:23:01 +0000 Subject: [PATCH] fix issues found with a clean repo git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163754 13f79535-47bb-0310-9956-ffa450edef68 --- maven-mboot2/pom.xml | 16 ++++---- maven-mboot2/src/main/java/MBoot.java | 40 +++++++------------ .../java/download/ArtifactDownloader.java | 8 ++-- .../src/main/java/model/Dependency.java | 5 +++ .../src/main/java/model/ModelReader.java | 14 ++++++- .../src/main/java/model/Repository.java | 22 ++++++++-- .../src/main/java/util/AbstractReader.java | 25 +++++------- 7 files changed, 72 insertions(+), 58 deletions(-) diff --git a/maven-mboot2/pom.xml b/maven-mboot2/pom.xml index 7f336b1c72..03bd8d30f8 100644 --- a/maven-mboot2/pom.xml +++ b/maven-mboot2/pom.xml @@ -13,26 +13,26 @@ org.codehaus.modello - modello - core-1.0-alpha-1 + modello-core + 1.0-alpha-1 runtime org.codehaus.modello - modello - xdoc-plugin-1.0-alpha-1 + modello-xdoc-plugin + 1.0-alpha-1 runtime org.codehaus.modello - modello - xml-plugin-1.0-alpha-1 + modello-xml-plugin + 1.0-alpha-1 runtime org.codehaus.modello - modello - xpp3-plugin-1.0-alpha-1 + modello-xpp3-plugin + 1.0-alpha-1 runtime diff --git a/maven-mboot2/src/main/java/MBoot.java b/maven-mboot2/src/main/java/MBoot.java index 4d53e1d089..6b36ee662e 100644 --- a/maven-mboot2/src/main/java/MBoot.java +++ b/maven-mboot2/src/main/java/MBoot.java @@ -254,21 +254,8 @@ public class MBoot } } - 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, - localRepository ); - - reader = new ModelReader( localRepository ); - reader.parse( new File( basedir, "maven-plugins/maven-surefire-plugin/pom.xml" ) ); - List surefireDependencies = reader.getDependencies(); - - reader = new ModelReader( localRepository ); - // Install maven-components POM installPomFile( localRepository, new File( basedir, "pom.xml" ) ); @@ -284,6 +271,19 @@ public class MBoot // Install it-support POM installPomFile( localRepository, new File( basedir, "maven-core-it-support/pom.xml" ) ); + reader = new ModelReader( localRepository ); + + reader.parse( new File( basedir, "maven-mboot2/pom.xml" ) ); + + ClassLoader bootstrapClassLoader = createClassloaderFromDependencies( reader.getDependencies(), null, + localRepository ); + + reader = new ModelReader( localRepository ); + reader.parse( new File( basedir, "maven-plugins/maven-surefire-plugin/pom.xml" ) ); + List surefireDependencies = reader.getDependencies(); + + reader = new ModelReader( localRepository ); + List coreDeps = null; Dependency corePom = null; @@ -452,12 +452,7 @@ public class MBoot ModelReader reader = new ModelReader( localRepository ); - if ( !reader.parse( new File( basedir, "pom.xml" ) ) ) - { - System.err.println( "Could not parse pom.xml" ); - - System.exit( 1 ); - } + reader.parse( new File( basedir, "pom.xml" ) ); String sources = new File( basedir, SOURCES ).getAbsolutePath(); @@ -711,12 +706,7 @@ public class MBoot { ModelReader reader = new ModelReader( localRepository ); - if ( !reader.parse( pomIn ) ) - { - System.err.println( "Could not parse pom.xml" ); - - System.exit( 1 ); - } + reader.parse( pomIn ); installPomFile( reader, localRepository, pomIn ); } diff --git a/maven-mboot2/src/main/java/download/ArtifactDownloader.java b/maven-mboot2/src/main/java/download/ArtifactDownloader.java index 0a15455985..9e96f57b34 100644 --- a/maven-mboot2/src/main/java/download/ArtifactDownloader.java +++ b/maven-mboot2/src/main/java/download/ArtifactDownloader.java @@ -107,8 +107,10 @@ public class ArtifactDownloader if ( repositories.isEmpty() ) { - // TODO: configure layout - remoteRepos.add( new Repository( "http://repo1.maven.org", Repository.LAYOUT_LEGACY ) ); + // TODO: use super POM? + Repository repository = new Repository(); + repository.setBasedir( "http://repo1.maven.org" ); + remoteRepos.add( repository ); } } @@ -122,7 +124,7 @@ public class ArtifactDownloader // The username and password parameters are not being // used here. Those are the "" parameters you see below. - String url = remoteRepo.getArtifactPath( dep ); + String url = remoteRepo.getBasedir() + "/" + remoteRepo.getArtifactPath( dep ); if ( !url.startsWith( "file" ) ) { diff --git a/maven-mboot2/src/main/java/model/Dependency.java b/maven-mboot2/src/main/java/model/Dependency.java index 20bca28262..2a5ffed7cb 100644 --- a/maven-mboot2/src/main/java/model/Dependency.java +++ b/maven-mboot2/src/main/java/model/Dependency.java @@ -194,4 +194,9 @@ public class Dependency return false; } + + public String toString() + { + return getId() + ":" + getVersion() + ":" + getType(); + } } diff --git a/maven-mboot2/src/main/java/model/ModelReader.java b/maven-mboot2/src/main/java/model/ModelReader.java index 2641b8ccd7..8d4e667aba 100644 --- a/maven-mboot2/src/main/java/model/ModelReader.java +++ b/maven-mboot2/src/main/java/model/ModelReader.java @@ -20,6 +20,8 @@ import org.xml.sax.Attributes; import org.xml.sax.SAXException; import util.AbstractReader; +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -169,9 +171,17 @@ public class ModelReader ModelReader p = new ModelReader( localRepository ); - if ( !p.parse( localRepository.getArtifactFile( parentGroupId, parentArtifactId, parentVersion, "pom" ) ) ) + try { - throw new SAXException( "Could not parse parent pom.xml" ); + p.parse( localRepository.getArtifactFile( parentGroupId, parentArtifactId, parentVersion, "pom" ) ); + } + catch ( ParserConfigurationException e ) + { + throw new SAXException( "Error getting parent POM", e ); + } + catch ( IOException e ) + { + throw new SAXException( "Error getting parent POM", e ); } dependencies.addAll( p.getDependencies() ); diff --git a/maven-mboot2/src/main/java/model/Repository.java b/maven-mboot2/src/main/java/model/Repository.java index 2c7b41e409..5baf0939c2 100644 --- a/maven-mboot2/src/main/java/model/Repository.java +++ b/maven-mboot2/src/main/java/model/Repository.java @@ -26,10 +26,12 @@ import java.io.File; */ public class Repository { - private String basedir; - public static final String LAYOUT_LEGACY = "legacy"; + public static final String LAYOUT_DEFAULT = "default"; + + private String basedir; + private String layout = LAYOUT_LEGACY; public Repository() @@ -65,6 +67,12 @@ public class Repository repositoryPath = dependency.getArtifactDirectory() + "/" + dependency.getType() + "s/" + dependency.getArtifact(); } + else if ( LAYOUT_DEFAULT.equals( layout ) ) + { + String pathGroup = dependency.getGroupId().replace( '.', '/' ); + repositoryPath = pathGroup + "/" + dependency.getArtifactId() + "/" + dependency.getVersion(); + repositoryPath = repositoryPath + "/" + dependency.getArtifact(); + } else { throw new IllegalStateException( "Unknown layout: " + layout ); @@ -74,12 +82,18 @@ public class Repository public File getMetadataFile( String groupId, String artifactId, String version, String type, String filename ) { - Dependency d = new Dependency( groupId, artifactId, version, type ); + Dependency dependency = new Dependency( groupId, artifactId, version, type ); String repositoryPath; if ( LAYOUT_LEGACY.equals( layout ) ) { - repositoryPath = d.getArtifactDirectory() + "/poms/" + filename; + repositoryPath = dependency.getArtifactDirectory() + "/poms/" + filename; + } + else if ( LAYOUT_DEFAULT.equals( layout ) ) + { + String pathGroup = dependency.getGroupId().replace( '.', '/' ); + repositoryPath = pathGroup + "/" + dependency.getArtifactId() + "/" + dependency.getVersion(); + repositoryPath = repositoryPath + "/" + filename; } else { diff --git a/maven-mboot2/src/main/java/util/AbstractReader.java b/maven-mboot2/src/main/java/util/AbstractReader.java index b9b164adde..006adabccb 100644 --- a/maven-mboot2/src/main/java/util/AbstractReader.java +++ b/maven-mboot2/src/main/java/util/AbstractReader.java @@ -17,13 +17,16 @@ package util; */ import org.xml.sax.InputSource; +import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; /** * Parse an XML file. @@ -35,26 +38,16 @@ public abstract class AbstractReader { private SAXParserFactory saxFactory; - public boolean parse( File file ) + public void parse( File file ) + throws ParserConfigurationException, SAXException, IOException { - try - { - saxFactory = SAXParserFactory.newInstance(); + saxFactory = SAXParserFactory.newInstance(); - SAXParser parser = saxFactory.newSAXParser(); + SAXParser parser = saxFactory.newSAXParser(); - InputSource is = new InputSource( new FileInputStream( file ) ); + InputSource is = new InputSource( new FileInputStream( file ) ); - parser.parse( is, this ); - - return true; - } - catch ( Exception e ) - { - e.printStackTrace(); - - return false; - } + parser.parse( is, this ); } public void warning( SAXParseException spe )