From b85639283fffaadc8168c68f290bca4ffea15f94 Mon Sep 17 00:00:00 2001 From: Trygve Laugstol Date: Fri, 30 Jul 2004 17:36:52 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@162908 13f79535-47bb-0310-9956-ffa450edef68 --- maven-repository-tools/.cvsignore | 7 + maven-repository-tools/pom.xml | 40 + .../src/main/bash/maven-pom-converter | 42 + maven-repository-tools/src/main/bash/reaper | 12 + .../converter/AbstractMavenRepository.java | 27 + .../java/org/apache/maven/converter/Fix.java | 107 ++ .../java/org/apache/maven/converter/Fix2.java | 71 ++ .../maven/converter/Maven1Repository.java | 67 ++ .../maven/converter/Maven2Repository.java | 161 +++ .../maven/converter/MavenPomConverter.java | 56 + .../maven/converter/MavenPomConverterCli.java | 68 ++ .../MavenPomConvertionException.java | 35 + .../maven/converter/MavenRepository.java | 30 + .../maven/converter/PomV3ToV4Converter.java | 957 ++++++++++++++++++ .../apache/maven/converter/RepoReaper.java | 357 +++++++ .../converter/project/Model300Converter.java | 41 + .../project/ModelConversionException.java | 40 + .../converter/project/ModelConverter.java | 39 + .../maven/converter/tmp/Dependency.java | 85 ++ .../apache/maven/converter/tmp/Project.java | 86 ++ .../apache/maven/converter/ReaperTest.java | 48 + 21 files changed, 2376 insertions(+) create mode 100644 maven-repository-tools/.cvsignore create mode 100644 maven-repository-tools/pom.xml create mode 100755 maven-repository-tools/src/main/bash/maven-pom-converter create mode 100755 maven-repository-tools/src/main/bash/reaper create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/AbstractMavenRepository.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/Fix.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/Fix2.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/Maven1Repository.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/Maven2Repository.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/MavenPomConverter.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/MavenPomConverterCli.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/MavenPomConvertionException.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/MavenRepository.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/PomV3ToV4Converter.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/RepoReaper.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/project/Model300Converter.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/project/ModelConversionException.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/project/ModelConverter.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/tmp/Dependency.java create mode 100644 maven-repository-tools/src/main/java/org/apache/maven/converter/tmp/Project.java create mode 100644 maven-repository-tools/src/test/java/org/apache/maven/converter/ReaperTest.java diff --git a/maven-repository-tools/.cvsignore b/maven-repository-tools/.cvsignore new file mode 100644 index 0000000000..1d2f09980f --- /dev/null +++ b/maven-repository-tools/.cvsignore @@ -0,0 +1,7 @@ +maven +maven2 +ibiblio +target +maven2.tar.gz +poms.tar.gz +reaper.tar.gz diff --git a/maven-repository-tools/pom.xml b/maven-repository-tools/pom.xml new file mode 100644 index 0000000000..2a7e027825 --- /dev/null +++ b/maven-repository-tools/pom.xml @@ -0,0 +1,40 @@ + + + 4.0.0 + maven + maven-reporeaper + 1.0-SNAPSHOT + Maven Repo Reaper + + + maven + maven-core + 2.0-SNAPSHOT + + + maven + maven-model + 2.0-SNAPSHOT + + + xstream + xstream + 1.0-SNAPSHOT + + + dom4j + dom4j + 1.4 + + + xpp3 + xpp3 + 1.1.3.3 + + + plexus + plexus + 0.14-SNAPSHOT + + + diff --git a/maven-repository-tools/src/main/bash/maven-pom-converter b/maven-repository-tools/src/main/bash/maven-pom-converter new file mode 100755 index 0000000000..dd35532597 --- /dev/null +++ b/maven-repository-tools/src/main/bash/maven-pom-converter @@ -0,0 +1,42 @@ +#!/bin/bash + +. $MBOOT_HOME/maven.functions + +findAndSetMavenRepoLocal + +CP= +CP=$CP:$repoLocal/maven/jars/maven-pom-converter-1.0-SNAPSHOT.jar +CP=$CP:$repoLocal/asm/jars/asm-1.3.4.jar +CP=$CP:$repoLocal/classworlds/jars/classworlds-1.1-SNAPSHOT.jar +CP=$CP:$repoLocal/commons-cli/jars/commons-cli-1.0-beta-2.jar +CP=$CP:$repoLocal/commons-httpclient/jars/commons-httpclient-2.0-rc2.jar +CP=$CP:$repoLocal/commons-lang/jars/commons-lang-1.0.1.jar +CP=$CP:$repoLocal/commons-logging/jars/commons-logging-1.0.3.jar +CP=$CP:$repoLocal/jetty/jars/jetty-4.2.10.jar +CP=$CP:$repoLocal/junit/jars/junit-3.8.1.jar +CP=$CP:$repoLocal/log4j/jars/log4j-1.1.3.jar +CP=$CP:$repoLocal/logkit/jars/logkit-1.0.1.jar +CP=$CP:$repoLocal/marmalade/jars/marmalade-core-0.1.jar +CP=$CP:$repoLocal/marmalade/jars/marmalade-el-ognl-0.1.jar +CP=$CP:$repoLocal/maven/jars/maven-artifact-2.0-SNAPSHOT.jar +CP=$CP:$repoLocal/maven/jars/maven-core-2.0-SNAPSHOT.jar +CP=$CP:$repoLocal/maven/jars/maven-model-2.0-SNAPSHOT.jar +CP=$CP:$repoLocal/maven/jars/maven-model-2.0-SNAPSHOT.jar +CP=$CP:$repoLocal/maven/jars/maven-plugin-2.0-SNAPSHOT.jar +CP=$CP:$repoLocal/maven/jars/wagon-api-0.9-SNAPSHOT.jar +CP=$CP:$repoLocal/maven/jars/wagon-http-0.9-SNAPSHOT.jar +CP=$CP:$repoLocal/modello/jars/modello-1.0-SNAPSHOT.jar +CP=$CP:$repoLocal/ognl/jars/ognl-2.5.1.jar +CP=$CP:$repoLocal/plexus/jars/plexus-0.14-SNAPSHOT.jar +CP=$CP:$repoLocal/plexus/jars/plexus-compiler-api-1.0.jar +CP=$CP:$repoLocal/plexus/jars/plexus-compiler-javac-1.0.jar +CP=$CP:$repoLocal/plexus/jars/plexus-i18n-1.0-beta-2-SNAPSHOT.jar +CP=$CP:$repoLocal/plexus/jars/plexus-jetty-httpd-1.0-SNAPSHOT.jar +CP=$CP:$repoLocal/qdox/jars/qdox-1.2.jar +CP=$CP:$repoLocal/servletapi/jars/servletapi-2.3.jar +CP=$CP:$repoLocal/surefire/jars/surefire-booter-1.0.jar +CP=$CP:$repoLocal/tagalog/jars/tagalog-0.1.jar +CP=$CP:$repoLocal/xpp3/jars/xpp3-1.1.3.3.jar +CP=$CP:$repoLocal/xstream/jars/xstream-1.0-SNAPSHOT.jar + +java -classpath $CP org.apache.maven.converter.MavenPomConverterCli "$@" diff --git a/maven-repository-tools/src/main/bash/reaper b/maven-repository-tools/src/main/bash/reaper new file mode 100755 index 0000000000..d6d74c932c --- /dev/null +++ b/maven-repository-tools/src/main/bash/reaper @@ -0,0 +1,12 @@ +#!/bin/bash + +CP= +CP=$CP:target/classes +CP=$CP:lib/plexus-0.14-SNAPSHOT.jar +CP=$CP:lib/dom4j-1.4.jar +CP=$CP:target/maven-reporeaper-1.0-SNAPSHOT.jar +CP=$CP:lib/maven-reporeaper-1.0-SNAPSHOT.jar +CP=$CP:lib/xstream-1.0-SNAPSHOT.jar +CP=$CP:lib/maven-model-2.0-SNAPSHOT.jar + +java -cp $CP org.apache.maven.converter.RepoReaper "$@" diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/AbstractMavenRepository.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/AbstractMavenRepository.java new file mode 100644 index 0000000000..36b646d062 --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/AbstractMavenRepository.java @@ -0,0 +1,27 @@ +package org.apache.maven.converter; + +import java.io.File; + +/* + * LICENSE + */ + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public abstract class AbstractMavenRepository + implements MavenRepository +{ + private File repository; + + public void setRepository( File repository ) + { + this.repository = repository; + } + + public File getRepository() + { + return repository; + } +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/Fix.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/Fix.java new file mode 100644 index 0000000000..f8e3973518 --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/Fix.java @@ -0,0 +1,107 @@ +package org.apache.maven.converter; + +/* ==================================================================== + * Copyright 2001-2004 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; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.OutputStream; +import java.util.Iterator; + +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.io.OutputFormat; +import org.dom4j.io.SAXReader; +import org.dom4j.io.XMLWriter; + +public class Fix +{ + public static void main( String[] args ) + throws Exception + { + SAXReader r = new SAXReader(); + + Document d = r.read( new FileReader( args[0] ) ); + + Element root = d.getRootElement(); + + Element deps = root.element( "dependencies" ); + + for ( Iterator i = deps.elementIterator( "dependency" ); i.hasNext(); ) + { + Element e = (Element) i.next(); + + Element id = e.element( "id" ); + + if ( id != null ) + { + String text = id.getText(); + + id.detach(); + + e.addElement( "groupId" ).addText( text ); + + e.addElement( "artifactId" ).addText( text ); + + Element v = e.element( "version" ); + + v.detach(); + + e.add( v ); + + Element u = e.element( "url" ); + + if ( u != null ) + { + u.detach(); + + e.add( u ); + } + + Element p = e.element( "properties" ); + + if ( p != null ) + { + p.detach(); + + e.add( p ); + } + } + } + + File f = new File( args[0] ); + + f.delete(); + + OutputStream os = new FileOutputStream( args[0] ); + + OutputFormat format = new OutputFormat(); + + format.setIndentSize( 2 ); + + format.setNewlines( true ); + + format.setTrimText( true ); + + XMLWriter writer = new XMLWriter( format ); + + writer.setOutputStream( os ); + + writer.write( d ); + } +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/Fix2.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/Fix2.java new file mode 100644 index 0000000000..fc2d97689a --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/Fix2.java @@ -0,0 +1,71 @@ +package org.apache.maven.converter; + +/* ==================================================================== + * Copyright 2001-2004 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; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.OutputStream; + +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.io.OutputFormat; +import org.dom4j.io.SAXReader; +import org.dom4j.io.XMLWriter; + +public class Fix2 +{ + public static void main( String[] args ) + throws Exception + { + SAXReader r = new SAXReader(); + + Document d = r.read( new FileReader( args[0] ) ); + + Element root = d.getRootElement(); + + Element id = root.element( "id" ); + + if ( id != null ) + { + System.out.println( id.getName() ); + + id.setName( "artifactId" ); + } + + File f = new File( args[0] ); + + f.delete(); + + OutputStream os = new FileOutputStream( args[0] ); + + OutputFormat format = new OutputFormat(); + + format.setIndentSize( 2 ); + + format.setNewlines( true ); + + format.setTrimText( true ); + + XMLWriter writer = new XMLWriter( format ); + + writer.setOutputStream( os ); + + writer.write( d ); + } +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/Maven1Repository.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/Maven1Repository.java new file mode 100644 index 0000000000..17397d959c --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/Maven1Repository.java @@ -0,0 +1,67 @@ +package org.apache.maven.converter; + +/* + * LICENSE + */ + +import java.io.File; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.apache.maven.model.Model; + +import org.codehaus.plexus.util.FileUtils; + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public class Maven1Repository + extends AbstractMavenRepository +{ + public Iterator getArtifactsByType( String type ) + throws Exception + { + List files = FileUtils.getFiles( getRepository(), "*/" + type + "s/*." + type, "" ); + + Collections.sort( files ); + + return files.iterator(); + } + + public String getPomForArtifact( String artifactPath ) + throws Exception + { + int i = artifactPath.indexOf( '/' ); + + String groupId = artifactPath.substring( 0, i ); + + i = artifactPath.indexOf( '/', groupId.length() + 1 ); + + String artifactId = artifactPath.substring( i + 1 ); + + artifactId = artifactId.substring( 0, artifactId.length() - 4 ); + + System.out.println( "groupId: " + groupId ); + + System.out.println( "artifactId: " + artifactId ); + + String pomPath = groupId + "/poms/" + artifactId + ".pom"; + + File pom = new File( getRepository(), pomPath ); + + if ( !pom.exists() ) + { + return null; + } + + return pomPath; + } + + public void installArtifact( File artifact, Model model ) + throws Exception + { + throw new Exception( "Not implemented." ); + } +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/Maven2Repository.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/Maven2Repository.java new file mode 100644 index 0000000000..d9b39d3b0e --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/Maven2Repository.java @@ -0,0 +1,161 @@ +package org.apache.maven.converter; + +/* + * LICENSE + */ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.Writer; +import java.security.MessageDigest; +import java.util.Iterator; + +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; + +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public class Maven2Repository + extends AbstractMavenRepository +{ + public Iterator getArtifactsByType( String type ) + throws Exception + { + throw new Exception( "Not implemented." ); + } + + public void installArtifact( File artifact, Model model ) + throws Exception + { + String type = model.getType(); + + if ( type.equals( "jar" ) ) + { + installJar( artifact, model ); + } + else + { + throw new Exception( "This installer can only handle jars." ); + } + } + + public String getPomForArtifact( String artifactPath ) + throws Exception + { + throw new Exception( "Not implemented" ); + } + + private void installJar( File artifact, Model model ) + throws Exception + { + String groupId = model.getGroupId(); + + String dest = groupId.replace( '.', File.separatorChar ); + + dest += File.separator + model.getArtifactId(); + + dest += File.separator + model.getVersion(); + + dest += File.separator + model.getArtifactId() + "-" + model.getVersion() + ".jar"; + + File destFile = new File( getRepository(), dest ); + + if ( !destFile.getParentFile().mkdirs() ) + { + throw new Exception( "Could not make directories " + dest ); + } + + System.out.println( "Installing " + destFile.getAbsolutePath() ); + + FileUtils.copyFile( artifact, destFile ); + + installMD5( destFile ); + + installPom( destFile, model ); + } + + private void installPom( File artifact, Model model ) + throws Exception + { + File pom = new File( artifact.getAbsolutePath() + ".pom" ); + + System.out.println( "Installing " + pom ); + + MavenXpp3Writer v4Writer = new MavenXpp3Writer(); + + Writer output = new FileWriter( pom ); + + v4Writer.write( output, model ); + + output.close(); + + installMD5( pom ); + } + + private void installMD5( File artifact ) + throws Exception + { + MessageDigest digester = MessageDigest.getInstance( "MD5" ); + + if ( digester == null ) + { + throw new Exception( "Could not get MD5 message digester." ); + } + + byte[] data = IOUtil.toByteArray( new FileInputStream( artifact ) ); + + digester.digest( data ); + + String sum = encode( digester.digest() ); + + File md5 = new File( artifact.getAbsolutePath() + ".md5" ); + + OutputStream output = new FileOutputStream( md5 ); + + PrintWriter writer = new PrintWriter( output ); + + writer.println( sum.getBytes() ); + + writer.close(); + + output.close(); + + System.out.println( "Installing " + md5 ); + } + + protected String encode( byte[] binaryData ) + throws Exception + { + if ( binaryData.length != 16 ) + { + throw new Exception( "Error in input data." ); + } + + String retValue = ""; + + for ( int i = 0; i < 16; i++ ) + { + String t = Integer.toHexString( binaryData[i] & 0xff ); + + if ( t.length() == 1 ) + { + retValue += ( "0" + t ); + } + else + { + retValue += t; + } + } + + return retValue.trim(); + } +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/MavenPomConverter.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/MavenPomConverter.java new file mode 100644 index 0000000000..97362e31f5 --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/MavenPomConverter.java @@ -0,0 +1,56 @@ +package org.apache.maven.converter; + +/* + * Copyright 2001-2004 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. + */ + + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public class MavenPomConverter +{ +/* + private boolean interactive; + + public void setInteractive( boolean interactive ) + { + this.interactive = interactive; + } + + public void convert( String inputFile, String outputFile ) + throws MavenPomConvertionException + { + if ( interactive ) + throw new MavenPomConvertionException( "The tool doesn't do interactive convertion yet." ); + + MavenV300Xpp3Reader v3reader = new MavenV300Xpp3Reader(); + + try + { + v3reader.read( new FileReader( inputFile ) ); + } + catch( FileNotFoundException ex ) + { + throw new MavenPomConvertionException( "Could not read input file: " + inputFile, ex); + } + catch( Exception ex ) + { + throw new MavenPomConvertionException( "Exception while reading the model.", ex ); + } + } +*/ +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/MavenPomConverterCli.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/MavenPomConverterCli.java new file mode 100644 index 0000000000..cae79403bd --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/MavenPomConverterCli.java @@ -0,0 +1,68 @@ +package org.apache.maven.converter; + +/* + * Copyright 2001-2004 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 org.codehaus.plexus.embed.Embedder; + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public class MavenPomConverterCli +{ +/* + private Embedder plexus = new Embedder(); + + public static void main( String[] args ) + { + try + { + new MavenPomConverterCli().execute( args ); + } + catch( Exception ex ) + { + ex.printStackTrace( System.err ); + } + } + + public void execute( String[] args ) + throws Exception + { + start(); + + stop(); + } + + private void start() + throws Exception + { + plexus.start(); + } + + private void stop() + { + try + { + plexus.stop(); + } + catch( Exception ex ) + { + // ignore + } + } +*/ +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/MavenPomConvertionException.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/MavenPomConvertionException.java new file mode 100644 index 0000000000..c672527f1c --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/MavenPomConvertionException.java @@ -0,0 +1,35 @@ +package org.apache.maven.converter; + +/* + * Copyright 2001-2004 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. + */ + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public class MavenPomConvertionException + extends Exception +{ + public MavenPomConvertionException( String msg ) + { + super( msg ); + } + + public MavenPomConvertionException( String msg, Throwable cause ) + { + super( msg, cause ); + } +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/MavenRepository.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/MavenRepository.java new file mode 100644 index 0000000000..176d0ae72e --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/MavenRepository.java @@ -0,0 +1,30 @@ +package org.apache.maven.converter; + +/* + * LICENSE + */ + +import java.io.File; +import java.util.Iterator; + +import org.apache.maven.model.Model; + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public interface MavenRepository +{ + void setRepository( File repository ); + + File getRepository(); + + Iterator getArtifactsByType( String type ) + throws Exception; + + String getPomForArtifact( String artifactPath ) + throws Exception; + + public void installArtifact( File artifact, Model model ) + throws Exception; +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/PomV3ToV4Converter.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/PomV3ToV4Converter.java new file mode 100644 index 0000000000..bf90e3d129 --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/PomV3ToV4Converter.java @@ -0,0 +1,957 @@ +package org.apache.maven.converter; + +/* + * Copyright (c) 2004, Jason van Zyl and Trygve Laugstøl + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.apache.maven.model.Build; +import org.apache.maven.model.CiManagement; +import org.apache.maven.model.Contributor; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Developer; +import org.apache.maven.model.DistributionManagement; +import org.apache.maven.model.IssueManagement; +import org.apache.maven.model.License; +import org.apache.maven.model.MailingList; +import org.apache.maven.model.Model; +import org.apache.maven.model.Organization; +import org.apache.maven.model.Parent; +import org.apache.maven.model.Repository; +import org.apache.maven.model.Resource; +import org.apache.maven.model.Scm; +import org.apache.maven.model.Site; +import org.apache.maven.model.SourceModification; +import org.apache.maven.model.UnitTest; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.apache.maven.model.v300.io.xpp3.MavenV300Xpp3Reader; + +import org.codehaus.plexus.util.FileUtils; + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public class PomV3ToV4Converter +{ + private org.apache.maven.model.v300.Model v3ParentModel; + + public static void main( String[] args ) + { + PomV3ToV4Converter converter = new PomV3ToV4Converter(); + + try + { + converter.work( args ); + + System.exit( 0 ); + } + catch( Exception ex ) + { + ex.printStackTrace( System.err ); + + System.exit( -1 ); + } + } + + public void work( String[] args ) + throws Exception + { + if ( args.length != 1 ) + { + throw new Exception( "Usage: converter | list is removed in the version 4 of the pom." ); + } + + List branches = v3Model.getBranches(); + + if ( branches != null ) + { + warn( "The list is removed in the version 4 of the pom." ); + } + + v4Model.setReports( returnList( v3Model.getReports() ) ); + + v4Model.setScm( getScm( v3Model ) ); + + v4Model.setBuild( getBuild( v3Model ) ); + + v4Model.setDistributionManagement( getDistributionManagement( v3Model ) ); + + v4Model.setPackage( v3Model.getPackage() ); + + return v4Model; + } + + private Parent getParent( File file, org.apache.maven.model.v300.Model v3Model ) + throws Exception + { + Parent parent = new Parent(); + + String extend = v3Model.getExtend(); + + if ( isEmpty( extend ) ) + { + return null; + } + + final String basedir = "${basedir}"; + + int i = extend.indexOf( basedir ); + + if ( i >= 0 ) + { + extend = extend.substring( 0, i ) + + file.getParentFile() + File.separator + + extend.substring( i + basedir.length() + 1 ); + } + + File extendFile = new File( extend ); + + if ( !extendFile.isAbsolute() ) + { + extendFile = new File( file.getParentFile(), extend ); + } + + if ( !extendFile.isFile() ) + { + throw new Exception( "Could not find the file the pom extends: '" + extendFile.getAbsolutePath() + "' is not a file." ); + } + + // try to find the parent pom. + v3ParentModel = loadV3Pom( extendFile ); + + String groupId = v3ParentModel.getGroupId(); + + if ( isEmpty( groupId ) ) + { + throw new Exception( "Missing groupId from the extended pom." ); + } + + parent.setGroupId( groupId ); + + String artifactId = v3ParentModel.getArtifactId(); + + if ( isEmpty( artifactId ) ) + { + throw new Exception( "Missing 'artifactId' from the extended pom." ); + } + + parent.setArtifactId( artifactId ); + + String version = v3ParentModel.getCurrentVersion(); + + if ( isEmpty( version ) ) + { + throw new Exception( "Missing 'currentVersion' from the extended pom." ); + } + + parent.setVersion( version ); + + return parent; + } + + private Organization getOrganization( org.apache.maven.model.v300.Model v3Model ) + { + Organization organization = new Organization(); + + if ( v3Model.getOrganization() == null ) + { + return null; + } + + organization.setName( v3Model.getOrganization().getName() ); + + organization.setUrl( v3Model.getOrganization().getUrl() ); + + organization.setLogo( v3Model.getOrganization().getLogo() ); + + return organization; + } + + private IssueManagement getIssueManagement( org.apache.maven.model.v300.Model v3Model ) + { + String issueTrackingUrl = v3Model.getIssueTrackingUrl(); + + if ( isEmpty( issueTrackingUrl ) ) + { + return null; + } + + IssueManagement issueManagement = new IssueManagement(); + + issueManagement.setUrl( issueTrackingUrl ); + + return issueManagement; + } + + private CiManagement getCiManagement( org.apache.maven.model.v300.Model v3Model ) + { + if ( v3Model.getBuild() == null ) + { + return null; + } + + String nagEmailAddress = v3Model.getBuild().getNagEmailAddress(); + + if ( isEmpty( nagEmailAddress ) ) + { + return null; + } + + CiManagement ciManagement = new CiManagement(); + + ciManagement.setNagEmailAddress( nagEmailAddress ); + + return ciManagement; + } + + // TODO: + // note: these are not SCM repositories but rather artifact repositories + private List getRepositories( org.apache.maven.model.v300.Model v3Model ) + { + List repositories = new ArrayList( 1 ); + +// warn( "" ); + + return returnList( repositories ); + } + + // TODO: + private List getMailingLists( org.apache.maven.model.v300.Model v3Model ) + { + List mailingLists = new ArrayList(); + + List v3MailingLists = v3Model.getMailingLists(); + + if ( isEmpty( v3MailingLists ) ) + { + return null; + } + + for ( Iterator it = v3MailingLists.iterator(); it.hasNext(); ) + { + org.apache.maven.model.v300.MailingList v3MailingList = + (org.apache.maven.model.v300.MailingList) it.next(); + + MailingList mailingList = new MailingList(); + + mailingList.setName( v3MailingList.getName() ); + + mailingList.setSubscribe( v3MailingList.getSubscribe() ); + + mailingList.setUnsubscribe( v3MailingList.getUnsubscribe() ); + + mailingList.setArchive( v3MailingList.getArchive() ); + + mailingLists.add( mailingList ); + } + + return mailingLists; + } + + private List getDevelopers( org.apache.maven.model.v300.Model v3Model ) + { + List developers = new ArrayList(); + + List v3Developers = v3Model.getDevelopers(); + + if ( isEmpty( v3Developers ) ) + { + return null; + } + + for ( Iterator it = v3Developers.iterator(); it.hasNext(); ) + { + org.apache.maven.model.v300.Developer v3Developer = + (org.apache.maven.model.v300.Developer) it.next(); + + Developer developer = new Developer(); + + developer.setId( nullIfEmpty( v3Developer.getId() ) ); + + developer.setName( nullIfEmpty( v3Developer.getName() ) ); + + developer.setEmail( nullIfEmpty( v3Developer.getEmail() ) ); + + developer.setOrganization( nullIfEmpty( v3Developer.getOrganization() ) ); + + developer.setTimezone( nullIfEmpty( v3Developer.getTimezone() ) ); + + developer.setUrl( nullIfEmpty( v3Developer.getUrl() ) ); + + developer.setRoles( returnList( v3Developer.getRoles() ) ); + + developers.add( developer ); + } + + return developers; + } + + private List getContributors( org.apache.maven.model.v300.Model v3Model ) + { + List contributors = new ArrayList(); + + List v3Contributors = v3Model.getContributors(); + + if ( isEmpty( v3Contributors ) ) + { + return null; + } + + for ( Iterator it = v3Contributors.iterator(); it.hasNext(); ) + { + org.apache.maven.model.v300.Contributor v3Contributor = + (org.apache.maven.model.v300.Contributor) it.next(); + + Contributor contributor = new Contributor(); + + contributor.setName( nullIfEmpty( v3Contributor.getName() ) ); + + contributor.setEmail( nullIfEmpty( v3Contributor.getEmail() ) ); + + contributor.setOrganization( nullIfEmpty( v3Contributor.getOrganization() ) ); + + contributor.setTimezone( nullIfEmpty( v3Contributor.getTimezone() ) ); + + contributor.setUrl( nullIfEmpty( v3Contributor.getUrl() ) ); + + contributor.setRoles( returnList( v3Contributor.getRoles() ) ); + + contributors.add( contributor ); + } + + return contributors; + } + + private List getDependencies( org.apache.maven.model.v300.Model v3Model ) + throws Exception + { + List dependencies = new ArrayList(); + + List v3Dependencies = v3Model.getDependencies(); + + if ( isEmpty( v3Dependencies ) ) + { + return null; + } + + for ( Iterator it = v3Dependencies.iterator(); it.hasNext(); ) + { + org.apache.maven.model.v300.Dependency v3Dependency = + (org.apache.maven.model.v300.Dependency) it.next(); + + Dependency dependency = new Dependency(); + + String id = nullIfEmpty( v3Dependency.getId() ); + + String groupId = nullIfEmpty( v3Dependency.getGroupId() ); + + String artifactId = nullIfEmpty( v3Dependency.getArtifactId() ); + + // old school + if ( !isEmpty( id ) ) + { + dependency.setGroupId( id ); + + dependency.setArtifactId( id ); + + if ( !isEmpty( groupId ) ) + { + warn( "Both and is set, using (id: " + id + ", groupId: " + groupId + ")." ); + } + + if ( !isEmpty( artifactId ) ) + { + warn( "Both and is set, using (id: " + id + ", artifactId: " + artifactId + ")." ); + } + } + // new school + else + { + if ( isEmpty( groupId ) ) + { + fatal( "Missing dependency.groupId." ); + } + + if ( isEmpty( artifactId ) ) + { + fatal( "Missing dependency.artifactId." ); + } + + dependency.setGroupId( groupId ); + + dependency.setArtifactId( artifactId ); + } + + dependency.setType( nullIfEmpty( v3Dependency.getType() ) ); + + dependency.setVersion( nullIfEmpty( v3Dependency.getVersion() ) ); + + dependency.setUrl( nullIfEmpty( v3Dependency.getUrl() ) ); + + dependency.setProperties( v3Dependency.getProperties() ); + + dependencies.add( dependency ); + } + + return dependencies; + } + + private List getLicenses( org.apache.maven.model.v300.Model v3Model ) + { + List licenses = new ArrayList(); + + List v3Licenses = v3Model.getLicenses(); + + if ( isEmpty( v3Licenses ) ) + { + return null; + } + + for ( Iterator it = v3Licenses.iterator(); it.hasNext(); ) + { + org.apache.maven.model.v300.License v3License = + (org.apache.maven.model.v300.License) it.next(); + + License license = new License(); + + license.setName( nullIfEmpty( v3License.getName() ) ); + + license.setUrl( nullIfEmpty( v3License.getUrl() ) ); + + license.setComments( nullIfEmpty( v3License.getComments() ) ); + + licenses.add( license ); + } + + return licenses; + } + + private Scm getScm( org.apache.maven.model.v300.Model v3Model ) + { + if ( v3Model.getRepository() == null ) + { + return null; + } + + Scm scm = new Scm(); + +// warn( "connection: " + v3Model.getRepository().getConnection() ); + +// warn( "developerConnection: " + v3Model.getRepository().getDeveloperConnection() ); + +// warn( "url: " + v3Model.getRepository().getUrl() ); + + scm.setConnection( v3Model.getRepository().getConnection() ); + + scm.setDeveloperConnection( v3Model.getRepository().getDeveloperConnection() ); + + scm.setUrl( v3Model.getRepository().getUrl() ); + + return scm; + } + + private Build getBuild( org.apache.maven.model.v300.Model v3Model ) + { + org.apache.maven.model.v300.Build v3Build = v3Model.getBuild(); + + if ( v3Build == null ) + { + return null; + } + + Build build = new Build(); + + build.setSourceDirectory( v3Build.getSourceDirectory() ); + + List v3SourceModifications = v3Build.getSourceModifications(); + + if ( v3SourceModifications != null && v3SourceModifications.size() > 0 ) + { + List sourceModifications = new ArrayList(); + + for ( Iterator it = v3SourceModifications.iterator(); it.hasNext(); ) + { + org.apache.maven.model.v300.SourceModification v3SourceModification = + (org.apache.maven.model.v300.SourceModification) it.next(); + + SourceModification sourceModification = new SourceModification(); + + sourceModification.setClassName( v3SourceModification.getClassName() ); + + sourceModification.setIncludes( getIncludes( v3SourceModification.getIncludes() ) ); + + sourceModification.setExcludes( getExcludes( v3SourceModification.getExcludes() ) ); + + sourceModifications.add( sourceModification ); + } + + build.setSourceModifications( sourceModifications ); + } + + build.setUnitTestSourceDirectory( v3Build.getUnitTestSourceDirectory() ); + + build.setAspectSourceDirectory( v3Build.getAspectSourceDirectory() ); + + org.apache.maven.model.v300.UnitTest v3UnitTest = v3Build.getUnitTest(); + + if ( v3UnitTest != null ) + { + UnitTest unitTest = new UnitTest(); + + unitTest.setIncludes( getIncludes( v3UnitTest.getIncludes() ) ); + + unitTest.setExcludes( getExcludes( v3UnitTest.getExcludes() ) ); + + unitTest.setResources( convertResources( v3UnitTest.getResources() ) ); + + build.setUnitTest( unitTest ); + } + + build.setResources( convertResources( v3Build.getResources() ) ); + + return build; + } + + private DistributionManagement getDistributionManagement( org.apache.maven.model.v300.Model v3Model ) + throws Exception + { + DistributionManagement distributionManagement = new DistributionManagement(); + + Site site = null; + + String siteAddress = v3Model.getSiteAddress(); + + String siteDirectory = v3Model.getSiteDirectory(); + + if ( isEmpty( siteAddress ) ) + { + if ( !isEmpty( siteDirectory ) ) + { + site = new Site(); + + site.setId( "default" ); + + site.setName( "Default Site" ); + + site.setUrl( "file://" + siteDirectory ); + } + } + else + { + if ( isEmpty( siteDirectory ) ) + { + throw new Exception( "Missing 'siteDirectory': Both siteAddress and siteDirectory must be set at the same time." ); + } + + site = new Site(); + + site.setId( "default" ); + + site.setName( "Default Site" ); + + site.setUrl( "scp://" + siteAddress + "/" + siteDirectory ); + } + + distributionManagement.setSite( site ); + + String distributionSite = v3Model.getDistributionSite(); + + String distributionDirectory = v3Model.getDistributionDirectory(); + + Repository repository = null; + + if ( isEmpty( distributionSite ) ) + { + if ( !isEmpty( distributionDirectory ) ) + { + repository = new Repository(); + + repository.setId( "default" ); + + repository.setName( "Default Repository" ); + + repository.setUrl( "file://" + distributionDirectory ); +// throw new Exception( "Missing 'distributionSite': Both distributionSite and distributionDirectory must be set." ); + } + } + else + { + if ( isEmpty( distributionDirectory ) ) + { + throw new Exception( "Missing 'distributionDirectory': must be set is 'distributionSite' is set." ); + } + + repository = new Repository(); + + repository.setId( "default" ); + + repository.setName( "Default Repository" ); + + repository.setUrl( distributionSite + "/" + distributionDirectory ); + } + + distributionManagement.setRepository( repository ); + + if ( site == null && repository == null ) + { + return null; + } + + return distributionManagement; + } + + private org.apache.maven.model.v300.Model loadV3Pom( File inputFile ) + throws Exception + { + MavenV300Xpp3Reader v3Reader = new MavenV300Xpp3Reader(); + + org.apache.maven.model.v300.Model model; + + model = v3Reader.read( new FileReader( inputFile ) ); + + String id = model.getId(); + + String groupId = model.getGroupId(); + + String artifactId = model.getArtifactId(); + + if ( !isEmpty( id ) ) + { + int i = id.indexOf( "+" ); + + int j = id.indexOf( ":" ); + + if ( i > 0 ) + { + model.setGroupId( id.substring( 0, i ) ); + + model.setArtifactId( id.replace( '+', '-' ) ); + } + else if ( j > 0 ) + { + model.setGroupId( id.substring( 0, j ) ); + + model.setArtifactId( id.substring( j + 1 ) ); + } + else + { + model.setGroupId( id ); + + model.setArtifactId( id ); + } + + if ( !isEmpty( groupId ) ) + { + warn( "Both and is set, using ." ); + + model.setGroupId( groupId ); + } + + if ( !isEmpty( artifactId ) ) + { + warn( "Both and is set, using ." ); + + model.setArtifactId( artifactId ); + } + } + + return model; + } + + private List getIncludes( List includes ) + { + if ( includes == null || includes.size() == 0 ) + { + return null; + } + + return includes; + } + + private List getExcludes( List excludes ) + { + if ( excludes == null || excludes.size() == 0 ) + { + return null; + } + + return excludes; + } + + private List convertResources( List v3Resources ) + { + List resources = new ArrayList(); + + if ( v3Resources == null || v3Resources.size() == 0 ) + { + return null; + } + + for ( Iterator it = v3Resources.iterator(); it.hasNext(); ) + { + org.apache.maven.model.v300.Resource v3Resource = + (org.apache.maven.model.v300.Resource) it.next(); + + Resource resource = new Resource(); + + resource.setDirectory( v3Resource.getDirectory() ); + + resource.setTargetPath( v3Resource.getTargetPath() ); + + resource.setIncludes( getIncludes( v3Resource.getIncludes() ) ); + + resource.setExcludes( getExcludes( v3Resource.getExcludes() ) ); + + resources.add( resource ); + } + + return resources; + } +/* + private void assertNotEmpty( String fieldName, String value ) + throws Exception + { + if ( value == null || value.trim().length() == 0 ) + { + throw new Exception( "Missing required field: '" + fieldName + "'." ); + } + } +*/ + private List returnList( List list ) + { + if ( list == null || list.size() == 0 ) + return null; + + return list; + } + + private boolean isEmpty( String value ) + { + return value == null || value.trim().length() == 0; + } + + private boolean isEmpty( List list ) + { + return list == null || list.size() == 0; + } + + private String nullIfEmpty( String string ) + { + if ( string == null || string.trim().length() == 0 ) + { + return null; + } + + return string; + } + + private void fatal( String msg ) + throws Exception + { + System.err.println( "[FATAL] " + msg ); + + throw new Exception( msg ); + } + + private void warn( String msg ) + { + System.err.println( "[WARN] " + msg ); + + System.err.flush(); + } + + private void info( String msg ) + { + System.err.println( msg ); + + System.err.flush(); + } +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/RepoReaper.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/RepoReaper.java new file mode 100644 index 0000000000..5d01d68293 --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/RepoReaper.java @@ -0,0 +1,357 @@ +package org.apache.maven.converter; + +/* + * Copyright 2001-2004 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; +import java.util.Iterator; + +import org.apache.maven.model.Model; + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public class RepoReaper +{ + MavenRepository inRepository = new Maven1Repository(); + + MavenRepository outRepository = new Maven2Repository(); + + public static void main( String[] args ) + throws Exception + { + if ( args.length != 2 ) + { + System.err.println( "Usage: repoReaper " ); + + return; + } + + File inbase = new File( args[0] ); + + File outbase = new File( args[1] ); + + if ( !inbase.exists() ) + { + System.err.println( "input repo doesn't exist: " + args[0] ); + + return; + } + + if ( !outbase.exists() ) + { + System.err.println( "output repo doesn't exist: " + args[0] ); + + return; + } + + new RepoReaper().work( inbase, outbase ); + } + + public void work( File inbase, File outbase ) + throws Exception + { + inRepository.setRepository( inbase ); + + System.out.println( "Input basedir: " + inbase.getAbsolutePath() ); + + outRepository.setRepository( outbase ); + + System.out.println( "Output basedir: " + outbase.getAbsolutePath() ); + + Iterator files = inRepository.getArtifactsByType( "jar" ); + + while( files.hasNext() ) + { + File file = (File) files.next(); + + String filePath = file.getAbsolutePath().substring( inbase.getAbsolutePath().length() + 1 ); + + Model project; + + String pomPath = inRepository.getPomForArtifact( filePath ); + + if ( pomPath == null ) + { + warning( "Missing pom for artifact: " + filePath ); + + continue; + } + + try + { +// project = convertPom( pomPath, new File( inRepository.getRepository(), pomPath ) ); + + PomV3ToV4Converter converter = new PomV3ToV4Converter(); + + project = converter.convertFile( new File( inRepository.getRepository(), pomPath ) ); + } + catch( Exception ex ) + { + warning( "Could not parse: '" + pomPath + "'."); + + Throwable t = ex; + + while ( t != null ) + { + warning( " " + ex.getMessage() ); + + t = t.getCause(); + } + + continue; + } + + if ( project != null ) + { +/* + File tmp = File.createTempFile( "maven-repo-reaper", "tmp" ); + + write( filePath, project ); +*/ + outRepository.installArtifact( new File( inbase, filePath ), project ); + } + } + } +/* + private Model convertPom( String fileName, File file ) + throws Exception + { + System.out.println( "Processing " + fileName ); + + SAXReader r = new SAXReader(); + + Model project = new Model(); + + Document pom = r.read( new FileReader( file ) ); + + Element root = pom.getRootElement(); + + Element modelVersion = root.element( "modelVersion" ); + + if ( modelVersion != null ) + { + if ( modelVersion.getText().equals( "4.0.0") ) + { + System.out.println( "This pom is already v4.0.0: " + fileName ); + + return null; + } + + fatal( "Invalid pom, exists but isn't '4.0.0': " + fileName ); + } + + project.setModelVersion( "4.0.0" ); + + // Fixing => + + Element id = root.element( "id" ); + + Element groupId = root.element( "groupId" ); + + Element artifactId = root.element( "artifactId" ); + + if ( groupId != null ) + { + project.setGroupId( groupId.getText() ); + } + else + { + if ( id == null ) + { + fatal( "Missing both and " ); + } + + project.setGroupId( id.getText() ); + } + + if ( artifactId != null ) + { + project.setArtifactId( artifactId.getText() ); + } + else + { + if ( id == null ) + { + fatal( "Missing both and " ); + } + + project.setArtifactId( id.getText() ); + } + + Element currentVersion = root.element( "currentVersion" ); + + if ( currentVersion == null ) + { + int start = -1; + + for ( int i = 0; i < fileName.length(); i++ ) + { + if ( Character.isDigit( fileName.charAt( i ) ) ) + { + start = i; + + break; + } + } + + if ( start == -1 ) + { + fatal( "Missing ." ); + } + + String ver = fileName.substring( start, fileName.length() - 4 ); + + project.setVersion( ver ); + + warning( "Missing , found the version from the filename, version: " + ver ); + } + else + { + project.setVersion( currentVersion.getText() ); + } + + Element dependencies = root.element( "dependencies" ); + + if ( dependencies != null ) + { + Iterator it = dependencies.elementIterator( "dependency" ); + + while( it.hasNext() ) + { + Dependency d = new Dependency(); + + Element dependency = (Element) it.next(); + + id = dependency.element( "id" ); + + groupId = dependency.element( "groupId" ); + + artifactId = dependency.element( "artifactId" ); + + Element type = dependency.element( "type" ); + + Element version = dependency.element( "version" ); + + if ( groupId == null ) + { + if ( id == null ) + { + warning( "Missing both dependency.id and dependency.groupId." ); + + continue; + } + else + { + d.setGroupId( id.getText() ); + } + } + else + { + d.setGroupId( groupId.getText() ); + } + + if ( artifactId == null ) + { + if ( id == null ) + { + warning( "Missing both dependency.id and dependency.artifactId. groupId: " + groupId.getText() ); + + continue; + } + else + { + d.setArtifactId( id.getText() ); + } + } + else + { + d.setArtifactId( artifactId.getText() ); + } + + if ( type != null ) + { + d.setType( type.getText() ); + } + + if ( version == null ) + { + warning( "Missing dependency.version for " + d.getGroupId() + ":" + d.getArtifactId() ); + + continue; + } + + d.setVersion( version.getText() ); + + if ( d.getGroupId().trim().equals( "${pom.groupId}" ) ) + { + d.setGroupId( project.getGroupId() ); + } + + if ( d.getArtifactId().trim().equals( "${pom.artifactId}" ) ) + { + d.setArtifactId( project.getArtifactId() ); + } + + if ( d.getType().trim().equals( "${pom.type}" ) ) + { + d.setType( project.getType() ); + } + + if ( d.getVersion().trim().equals( "${pom.version}" ) ) + { + d.setVersion( project.getVersion() ); + } + + project.getDependencies().add( d ); + } + } + + return project; + }*/ +/* + private static void write( File output, Model project ) + throws Exception + { + output.getParentFile().mkdirs(); + + XStream xstream = new XStream(); + + xstream.alias( "project", Model.class ); + xstream.alias( "dependency", Dependency.class ); + +// String xml = xstream.toXML( project ); + +// System.out.println( xml ); + + FileWriter writer = new FileWriter( output ); + + xstream.toXML( project, new PrettyPrintXMLWriter( writer ) ); + + writer.close(); + } +*/ + private void fatal( String msg ) + throws Exception + { + throw new Exception( msg ); + } + + private void warning( String msg ) + { + System.err.println( msg ); + } +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/project/Model300Converter.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/project/Model300Converter.java new file mode 100644 index 0000000000..514d4dd81c --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/project/Model300Converter.java @@ -0,0 +1,41 @@ +package org.apache.maven.converter.project; + +/* + * Copyright (c) 2004, Jason van Zyl and Trygve Laugstøl + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public class Model300Converter + implements ModelConverter +{ + // ---------------------------------------------------------------------- + // ModelConverter Implementation + // ---------------------------------------------------------------------- + + public Object convert( Object fromModel ) + throws ModelConversionException + { + return null; + } +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/project/ModelConversionException.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/project/ModelConversionException.java new file mode 100644 index 0000000000..920e3bffa9 --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/project/ModelConversionException.java @@ -0,0 +1,40 @@ +package org.apache.maven.converter.project; + +/* + * Copyright (c) 2004, Jason van Zyl and Trygve Laugstøl + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public class ModelConversionException extends Exception +{ + public ModelConversionException( String msg ) + { + super( msg ); + } + + public ModelConversionException( String msg, Throwable cause ) + { + super( msg, cause ); + } +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/project/ModelConverter.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/project/ModelConverter.java new file mode 100644 index 0000000000..885357286f --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/project/ModelConverter.java @@ -0,0 +1,39 @@ +package org.apache.maven.converter.project; + +/* + * Copyright (c) 2004, Jason van Zyl and Trygve Laugstøl + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public interface ModelConverter +{ + /** + * + * @param model The model to convert from. + * @return Returns the new model. + * @throws ModelConversionException + */ + Object convert( Object model ) + throws ModelConversionException; +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/tmp/Dependency.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/tmp/Dependency.java new file mode 100644 index 0000000000..cd7bcf4b18 --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/tmp/Dependency.java @@ -0,0 +1,85 @@ +package org.apache.maven.converter.tmp; + +/* + * Copyright 2001-2004 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. + */ + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public class Dependency +{ + private String groupId; + private String artifactId; + private String type; + private String version; + /** + * @return Returns the artifactId. + */ + public String getArtifactId() + { + return artifactId; + } + /** + * @param artifactId The artifactId to set. + */ + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + /** + * @return Returns the groupId. + */ + public String getGroupId() + { + return groupId; + } + /** + * @param groupId The groupId to set. + */ + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + /** + * @return Returns the type. + */ + public String getType() + { + return type; + } + /** + * @param type The type to set. + */ + public void setType( String type ) + { + this.type = type; + } + /** + * @return Returns the version. + */ + public String getVersion() + { + return version; + } + /** + * @param version The version to set. + */ + public void setVersion( String version ) + { + this.version = version; + } +} diff --git a/maven-repository-tools/src/main/java/org/apache/maven/converter/tmp/Project.java b/maven-repository-tools/src/main/java/org/apache/maven/converter/tmp/Project.java new file mode 100644 index 0000000000..4b4c6fca36 --- /dev/null +++ b/maven-repository-tools/src/main/java/org/apache/maven/converter/tmp/Project.java @@ -0,0 +1,86 @@ +package org.apache.maven.converter.tmp; + +/* + * Copyright 2001-2004 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. + */ + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public class Project +{ + private String groupId; + private String artifactId; + private String version; + private String type; + + /** + * @return Returns the artifactId. + */ + public String getArtifactId() + { + return artifactId; + } + /** + * @param artifactId The artifactId to set. + */ + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + /** + * @return Returns the groupId. + */ + public String getGroupId() + { + return groupId; + } + /** + * @param groupId The groupId to set. + */ + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + /** + * @return Returns the type. + */ + public String getType() + { + return type; + } + /** + * @param type The type to set. + */ + public void setType( String type ) + { + this.type = type; + } + /** + * @return Returns the version. + */ + public String getVersion() + { + return version; + } + /** + * @param version The version to set. + */ + public void setVersion( String version ) + { + this.version = version; + } +} diff --git a/maven-repository-tools/src/test/java/org/apache/maven/converter/ReaperTest.java b/maven-repository-tools/src/test/java/org/apache/maven/converter/ReaperTest.java new file mode 100644 index 0000000000..cbc1fe9353 --- /dev/null +++ b/maven-repository-tools/src/test/java/org/apache/maven/converter/ReaperTest.java @@ -0,0 +1,48 @@ +package org.apache.maven.converter; + +/* + * Copyright 2001-2004 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; + +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public class ReaperTest + extends PlexusTestCase +{ + public void testReaper() + throws Exception + { + RepoReaper reaper = new RepoReaper(); +/* + File inbase = new File( System.getProperty( "user.home" ), ".maven/repository" ); + + File outbase = new File( getTestFile( "target/outrepo" ) ); +*/ + File inbase = new File( "ibiblio" ); + + File outbase = new File( "maven" ); + + FileUtils.deleteDirectory( outbase ); + + reaper.work( inbase, outbase ); + } +}