summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-06-14 15:25:42 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-06-14 15:25:42 +0000
commit926610fc5362f0725abdb01bf96b88bfb222430f (patch)
tree18a4721708f86486bd49e60e3b539f89ab83f240 /tools
parent5d0863128890af3d4df037df68dd5507909cc127 (diff)
downloadarchiva-926610fc5362f0725abdb01bf96b88bfb222430f.tar.gz
archiva-926610fc5362f0725abdb01bf96b88bfb222430f.zip
[MRM-410] Dependency Tree is not shown in artifact details screen.
Adding support libs. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@547277 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tools')
-rw-r--r--tools/maven-archivadev-plugin/pom.xml96
-rw-r--r--tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/CreateArchivaDependencyResolutionTestCaseMojo.java133
-rw-r--r--tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/functors/ArtifactComparator.java63
-rw-r--r--tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/functors/DependencyNodeToArtifactTransformer.java44
-rw-r--r--tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/functors/MatchingDependencyPredicate.java66
-rw-r--r--tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/AbstractCreator.java349
-rw-r--r--tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/DependencyGraphTestCreator.java366
-rw-r--r--tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/DependencyUtils.java83
-rw-r--r--tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/MemoryRepositoryCreator.java439
-rw-r--r--tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/utils/VariableNames.java50
-rw-r--r--tools/pom.xml37
11 files changed, 1726 insertions, 0 deletions
diff --git a/tools/maven-archivadev-plugin/pom.xml b/tools/maven-archivadev-plugin/pom.xml
new file mode 100644
index 000000000..eff053bc9
--- /dev/null
+++ b/tools/maven-archivadev-plugin/pom.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <prerequisites>
+ <maven>2.0.4</maven>
+ </prerequisites>
+
+ <groupId>org.apache.maven.archiva.tools</groupId>
+ <artifactId>maven-archivadev-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <version>1.0-SNAPSHOT</version>
+
+ <name>Archiva Dev Maven Plugin</name>
+
+ <inceptionYear>2007</inceptionYear>
+
+ <developers>
+ <developer>
+ <id>joakime</id>
+ <name>Joakim Erdfelt</name>
+ <email>joakime@apache.org</email>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ <timezone>-5</timezone>
+ </developer>
+ </developers>
+
+ <dependencies>
+ <!-- maven plugin deps -->
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-common</artifactId>
+ <version>1.0-alpha-1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-api</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-impl</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-dependency-tree</artifactId>
+ <version>1.0-alpha-2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <!-- testing deps -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <version>1.0-beta-1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <properties>
+ <maven.version>2.0.4</maven.version>
+ </properties>
+</project>
diff --git a/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/CreateArchivaDependencyResolutionTestCaseMojo.java b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/CreateArchivaDependencyResolutionTestCaseMojo.java
new file mode 100644
index 000000000..44a5a1c00
--- /dev/null
+++ b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/CreateArchivaDependencyResolutionTestCaseMojo.java
@@ -0,0 +1,133 @@
+package org.apache.maven.archiva.plugins.dev;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.maven.archiva.plugins.dev.testgen.DependencyGraphTestCreator;
+import org.apache.maven.archiva.plugins.dev.testgen.MemoryRepositoryCreator;
+import org.apache.maven.archiva.plugins.dev.utils.VariableNames;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
+
+import java.io.File;
+
+/**
+ * CreateArchivaDependencyResolutionTestCaseMojo
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @goal generate-dependency-tests
+ */
+public class CreateArchivaDependencyResolutionTestCaseMojo
+ extends AbstractMojo
+{
+ /**
+ * The project of the current build.
+ *
+ * @parameter default-value="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
+ /**
+ * The artifact respository to use.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
+ private ArtifactRepository localRepository;
+
+ /**
+ * The destination directory to generate the test files.
+ *
+ * @parameter expression="${archivadev.outputdir}" default-value="${project.build.directory}"
+ * @required
+ */
+ private File destDir;
+
+ /**
+ * The artifact factory to use.
+ *
+ * @component
+ */
+ private ArtifactFactory artifactFactory;
+
+ /**
+ * @component
+ */
+ private DependencyTreeBuilder dependencyTreeBuilder;
+
+ /**
+ * @component
+ */
+ protected ArtifactMetadataSource artifactMetadataSource;
+
+ /**
+ * @component
+ */
+ private ArtifactCollector collector;
+
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+ String classPrefix = VariableNames.toClassName( project.getArtifactId() );
+
+ getLog().info( "Generating into " + destDir );
+
+ createMemoryRepository( classPrefix );
+ createDependencyGraphTest( classPrefix );
+ }
+
+ private void createDependencyGraphTest( String classPrefix ) throws MojoExecutionException
+ {
+ DependencyGraphTestCreator creator = new DependencyGraphTestCreator();
+ creator.setLog( getLog() );
+ creator.setOutputDir( destDir );
+ creator.setProject( project );
+ creator.setArtifactFactory( artifactFactory );
+ creator.setLocalRepository( localRepository );
+ creator.setDependencyTreeBuilder( dependencyTreeBuilder );
+ creator.setArtifactMetadataSource( artifactMetadataSource );
+ creator.setCollector( collector );
+
+ creator.create( classPrefix );
+ }
+
+ private void createMemoryRepository( String classPrefix ) throws MojoExecutionException
+ {
+ MemoryRepositoryCreator creator = new MemoryRepositoryCreator();
+ creator.setLog( getLog() );
+ creator.setOutputDir( destDir );
+ creator.setProject( project );
+ creator.setArtifactFactory( artifactFactory );
+ creator.setLocalRepository( localRepository );
+
+ creator.create( classPrefix );
+ }
+}
diff --git a/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/functors/ArtifactComparator.java b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/functors/ArtifactComparator.java
new file mode 100644
index 000000000..2623b431f
--- /dev/null
+++ b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/functors/ArtifactComparator.java
@@ -0,0 +1,63 @@
+package org.apache.maven.archiva.plugins.dev.functors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.maven.artifact.Artifact;
+
+import java.util.Comparator;
+
+/**
+ * ArtifactComparator
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ArtifactComparator
+ implements Comparator
+{
+
+ public int compare( Object arg0, Object arg1 )
+ {
+ if( arg0 == null || arg1 == null )
+ {
+ return -1;
+ }
+
+ Artifact artifact1 = (Artifact) arg0;
+ Artifact artifact2 = (Artifact) arg1;
+
+ int diff;
+
+ diff = artifact1.getGroupId().compareTo( artifact2.getGroupId() );
+ if( diff != 0 )
+ {
+ return diff;
+ }
+
+ diff = artifact1.getArtifactId().compareTo( artifact2.getArtifactId() );
+ if( diff != 0 )
+ {
+ return diff;
+ }
+
+ return artifact1.getVersion().compareTo( artifact2.getVersion() );
+ }
+
+}
diff --git a/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/functors/DependencyNodeToArtifactTransformer.java b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/functors/DependencyNodeToArtifactTransformer.java
new file mode 100644
index 000000000..df91f6028
--- /dev/null
+++ b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/functors/DependencyNodeToArtifactTransformer.java
@@ -0,0 +1,44 @@
+package org.apache.maven.archiva.plugins.dev.functors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.commons.collections.Transformer;
+import org.apache.maven.shared.dependency.tree.DependencyNode;
+
+/**
+ * DependencyNodeToArtifactTransformer
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class DependencyNodeToArtifactTransformer
+ implements Transformer
+{
+ public Object transform( Object input )
+ {
+ if( input instanceof DependencyNode )
+ {
+ DependencyNode node = (DependencyNode) input;
+ return node.getArtifact();
+ }
+
+ return input;
+ }
+}
diff --git a/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/functors/MatchingDependencyPredicate.java b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/functors/MatchingDependencyPredicate.java
new file mode 100644
index 000000000..e8fb3ad20
--- /dev/null
+++ b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/functors/MatchingDependencyPredicate.java
@@ -0,0 +1,66 @@
+package org.apache.maven.archiva.plugins.dev.functors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.commons.collections.Predicate;
+import org.apache.maven.model.Dependency;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * MatchingDependencyPredicate
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MatchingDependencyPredicate
+ implements Predicate
+{
+ private Dependency selectedDep;
+
+ public MatchingDependencyPredicate( Dependency selectedDep )
+ {
+ this.selectedDep = selectedDep;
+ }
+
+ public boolean evaluate( Object input )
+ {
+ boolean satisfies = false;
+
+ if ( input instanceof Dependency )
+ {
+ Dependency dep = (Dependency) input;
+ if ( StringUtils.equals( dep.getArtifactId(), selectedDep.getArtifactId() )
+ && StringUtils.equals( dep.getGroupId(), selectedDep.getGroupId() )
+ && StringUtils.equals( dep.getType(), selectedDep.getType() ))
+ {
+ // So far, so good. groupId/artifactId/type match.
+ satisfies = true;
+
+ // Test classifier (if defined)
+ if( StringUtils.isNotEmpty( selectedDep.getClassifier() ) )
+ {
+ satisfies = StringUtils.equals( dep.getClassifier(), selectedDep.getClassifier() );
+ }
+ }
+ }
+
+ return satisfies;
+ }
+}
diff --git a/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/AbstractCreator.java b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/AbstractCreator.java
new file mode 100644
index 000000000..3503ebbe4
--- /dev/null
+++ b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/AbstractCreator.java
@@ -0,0 +1,349 @@
+package org.apache.maven.archiva.plugins.dev.testgen;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Exclusion;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Parent;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.interpolation.ModelInterpolator;
+import org.apache.maven.project.interpolation.RegexBasedModelInterpolator;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.PrintWriter;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Properties;
+
+/**
+ * AbstractCreator
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class AbstractCreator
+{
+ protected MavenProject project;
+
+ protected ArtifactFactory artifactFactory;
+
+ protected ArtifactRepository localRepository;
+
+ protected File outputDir;
+
+ private MavenXpp3Reader modelReader = new MavenXpp3Reader();
+
+ private ModelInterpolator modelInterpolator;
+
+ private Log log;
+
+ public abstract void create( String classPrefix )
+ throws MojoExecutionException;
+
+ protected void writeLicense( PrintWriter out )
+ {
+ out.println( "/*" );
+ out.println( " * Licensed to the Apache Software Foundation (ASF) under one" );
+ out.println( " * or more contributor license agreements. See the NOTICE file" );
+ out.println( " * distributed with this work for additional information" );
+ out.println( " * regarding copyright ownership. The ASF licenses this file" );
+ out.println( " * to you under the Apache License, Version 2.0 (the" );
+ out.println( " * \"License\"); you may not use this file except in compliance" );
+ out.println( " * with the License. You may obtain a copy of the License at" );
+ out.println( " *" );
+ out.println( " * http://www.apache.org/licenses/LICENSE-2.0" );
+ out.println( " *" );
+ out.println( " * Unless required by applicable law or agreed to in writing," );
+ out.println( " * software distributed under the License is distributed on an" );
+ out.println( " * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY" );
+ out.println( " * KIND, either express or implied. See the License for the" );
+ out.println( " * specific language governing permissions and limitations" );
+ out.println( " * under the License." );
+ out.println( " */" );
+ out.println( "" );
+ }
+
+ protected boolean isNotEmpty( Properties properties )
+ {
+ return !isEmpty( properties );
+ }
+
+ private boolean isEmpty( Properties properties )
+ {
+ if ( properties == null )
+ {
+ return true;
+ }
+
+ return properties.isEmpty();
+ }
+
+ public Log getLog()
+ {
+ return log;
+ }
+
+ public void setLog( Log log )
+ {
+ this.log = log;
+ }
+
+ public MavenProject getProject()
+ {
+ return project;
+ }
+
+ public void setProject( MavenProject project )
+ {
+ this.project = project;
+ }
+
+ protected Model getModel( Dependency dep )
+ {
+ return getModel( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getType() );
+ }
+
+ protected Model getModel( Parent parent )
+ {
+ return getModel( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), "pom" );
+ }
+
+ protected Model getModel( String groupId, String artifactId, String version, String type )
+ {
+ // getLog().info( ".getModel(" + groupId + ", " + artifactId + ", " + version + ", " + type + ")" );
+ Artifact pomArtifact = artifactFactory.createProjectArtifact( groupId, artifactId, version );
+
+ String path = localRepository.getLayout().pathOf( pomArtifact );
+
+ File pomFile = new File( localRepository.getBasedir(), path );
+
+ if ( pomFile.exists() )
+ {
+ FileReader reader = null;
+ try
+ {
+ reader = new FileReader( pomFile );
+ Model model = modelReader.read( reader );
+
+ // HACK: to allow ${pom.groupId} expressions to work, WITHOUT resolving/merginc parent.
+ // (The merging of parent pom is done elsewhere)
+ if ( StringUtils.isEmpty( model.getGroupId() ) )
+ {
+ if( model.getParent() != null )
+ {
+ model.setGroupId( model.getParent().getGroupId() );
+ }
+ }
+
+ // HACK: to fix bad poms in repo (see jetty:jetty:4.2.10::jar for example)
+ model.setVersion( version );
+
+ // Interpolate the properties?
+ if( modelInterpolator == null )
+ {
+ modelInterpolator = new RegexBasedModelInterpolator();
+ }
+
+ model = modelInterpolator.interpolate( model, Collections.EMPTY_MAP, false );
+
+ return model;
+ }
+ catch ( Exception e )
+ {
+ getLog().warn(
+ "Unable to read pom file " + pomFile.getAbsolutePath() + " : (" + e.getClass().getName()
+ + "): " + e.getMessage() );
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+ }
+
+ // no pom file.
+
+ Model model = new Model();
+ model.setGroupId( groupId );
+ model.setArtifactId( artifactId );
+ model.setVersion( version );
+ model.setPackaging( type );
+
+ return model;
+ }
+
+ private String getGroupId( Model model )
+ {
+ String groupId = model.getGroupId();
+
+ if ( StringUtils.isEmpty( groupId ) )
+ {
+ if ( model.getParent() != null )
+ {
+ groupId = model.getParent().getGroupId();
+ }
+ }
+
+ return groupId;
+ }
+
+ private String getVersion( Model model )
+ {
+ String version = model.getVersion();
+
+ if ( StringUtils.isEmpty( version ) )
+ {
+ if ( model.getParent() != null )
+ {
+ version = model.getParent().getVersion();
+ }
+ }
+
+ return VersionUtil.getBaseVersion( version );
+ }
+
+ protected boolean isNotBlank( String str )
+ {
+ return !isBlank( str );
+ }
+
+ private boolean isBlank( String str )
+ {
+ if ( str == null )
+ {
+ return true;
+ }
+
+ return ( str.trim().length() <= 0 );
+ }
+
+ protected boolean isNotEmpty( Collection coll )
+ {
+ return !isEmpty( coll );
+ }
+
+ protected boolean isEmpty( Collection coll )
+ {
+ if ( coll == null )
+ {
+ return true;
+ }
+
+ return coll.isEmpty();
+ }
+
+ protected String toKey( Parent ref )
+ {
+ StringBuffer key = new StringBuffer();
+
+ key.append( ref.getGroupId() ).append( ":" );
+ key.append( ref.getArtifactId() ).append( ":" );
+ key.append( ref.getVersion() );
+
+ return key.toString();
+ }
+
+ protected String toKey( Exclusion ref )
+ {
+ StringBuffer key = new StringBuffer();
+
+ key.append( ref.getGroupId() ).append( ":" );
+ key.append( ref.getArtifactId() );
+
+ return key.toString();
+ }
+
+ protected String toKey( Model ref )
+ {
+ StringBuffer key = new StringBuffer();
+
+ key.append( getGroupId( ref ) ).append( ":" );
+ key.append( ref.getArtifactId() ).append( ":" );
+ key.append( getVersion( ref ) );
+
+ return key.toString();
+ }
+
+ protected String toKey( Dependency ref )
+ {
+ StringBuffer key = new StringBuffer();
+
+ key.append( ref.getGroupId() ).append( ":" );
+ key.append( ref.getArtifactId() ).append( ":" );
+ key.append( ref.getVersion() ).append( ":" );
+ key.append( StringUtils.defaultString( ref.getClassifier() ) ).append( ":" );
+ key.append( ref.getType() );
+
+ return key.toString();
+ }
+
+ protected String toKey( Artifact ref )
+ {
+ StringBuffer key = new StringBuffer();
+
+ key.append( ref.getGroupId() ).append( ":" );
+ key.append( ref.getArtifactId() ).append( ":" );
+ key.append( ref.getVersion() ).append( ":" );
+ key.append( StringUtils.defaultString( ref.getClassifier() ) ).append( ":" );
+ key.append( ref.getType() );
+
+ return key.toString();
+ }
+
+ public ArtifactFactory getArtifactFactory()
+ {
+ return artifactFactory;
+ }
+
+ public void setArtifactFactory( ArtifactFactory artifactFactory )
+ {
+ this.artifactFactory = artifactFactory;
+ }
+
+ public ArtifactRepository getLocalRepository()
+ {
+ return localRepository;
+ }
+
+ public void setLocalRepository( ArtifactRepository localRepository )
+ {
+ this.localRepository = localRepository;
+ }
+
+ public File getOutputDir()
+ {
+ return outputDir;
+ }
+
+ public void setOutputDir( File outputDir )
+ {
+ this.outputDir = outputDir;
+ }
+}
diff --git a/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/DependencyGraphTestCreator.java b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/DependencyGraphTestCreator.java
new file mode 100644
index 000000000..6597389aa
--- /dev/null
+++ b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/DependencyGraphTestCreator.java
@@ -0,0 +1,366 @@
+package org.apache.maven.archiva.plugins.dev.testgen;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.functors.NotPredicate;
+import org.apache.maven.archiva.plugins.dev.functors.DependencyNodeToArtifactTransformer;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.shared.dependency.tree.DependencyTree;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * DependencyGraphTestCreator
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class DependencyGraphTestCreator
+ extends AbstractCreator
+{
+ private class RootArtifactPredicate
+ implements Predicate
+ {
+ private String rootKey;
+
+ public RootArtifactPredicate( DependencyTree tree )
+ {
+ this.rootKey = toKey( tree.getRootNode().getArtifact() );
+ }
+
+ public boolean evaluate( Object input )
+ {
+ boolean satisfies = false;
+
+ if ( input instanceof Artifact )
+ {
+ Artifact nodeArtifact = (Artifact) input;
+ String key = toKey( nodeArtifact );
+
+ if ( key.equals( rootKey ) )
+ {
+ satisfies = true;
+ }
+ }
+
+ return satisfies;
+ }
+ }
+
+ private File outputFile;
+
+ private PrintWriter out;
+
+ private DependencyTreeBuilder dependencyTreeBuilder;
+
+ private ArtifactMetadataSource artifactMetadataSource;
+
+ private ArtifactCollector collector;
+
+ public void create( String classPrefix )
+ throws MojoExecutionException
+ {
+ String classname = classPrefix + "DependencyGraphTest";
+
+ getLog().info( "Generating " + classname + ".java ..." );
+
+ outputFile = new File( outputDir, classname + ".java" );
+ try
+ {
+ out = new PrintWriter( outputFile );
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new MojoExecutionException( "Unable to open file " + outputFile.getName() + " for output: "
+ + e.getMessage(), e );
+ }
+
+ try
+ {
+ out.println( "package org.apache.maven.archiva.dependency.graph;" );
+ out.println( "" );
+
+ writeLicense( out );
+
+ // Imports
+ out.println( "import org.apache.maven.archiva.dependency.DependencyGraphFactory;" );
+ out.println( "import org.apache.maven.archiva.model.DependencyScope;" );
+ out.println( "import org.apache.maven.archiva.model.VersionedReference;" );
+ out.println( "" );
+ out.println( "import java.util.ArrayList;" );
+ out.println( "import java.util.List;" );
+ out.println( "" );
+
+ String projectKey = toKey( project.getModel() );
+
+ writeJavadoc( classname, projectKey );
+
+ // The class itself.
+ out.println( "public class " + classname );
+ out.println( " extends AbstractDependencyGraphFactoryTestCase" );
+ out.println( "{" );
+
+ DependencyTree dependencyTree = getDependencyTree();
+
+ writeGraphNodesTest( classPrefix, dependencyTree );
+
+ // TODO: enable in future, when resolution between archiva and maven are equal.
+ // writeDirectCompileDepsTest( classPrefix, dependencyTree );
+ // writeDirectTestDepsTest( classPrefix, dependencyTree );
+ // writeTransitiveCompileDepsTest( classPrefix, dependencyTree );
+ // writeTransitiveTestDepsTest( classPrefix, dependencyTree );
+
+ out.println( "}" );
+ }
+ finally
+ {
+ out.flush();
+ IOUtil.close( out );
+ }
+ }
+
+ public ArtifactMetadataSource getArtifactMetadataSource()
+ {
+ return artifactMetadataSource;
+ }
+
+ public ArtifactCollector getCollector()
+ {
+ return collector;
+ }
+
+ public DependencyTreeBuilder getDependencyTreeBuilder()
+ {
+ return dependencyTreeBuilder;
+ }
+
+ public void setArtifactMetadataSource( ArtifactMetadataSource artifactMetadataSource )
+ {
+ this.artifactMetadataSource = artifactMetadataSource;
+ }
+
+ public void setCollector( ArtifactCollector collector )
+ {
+ this.collector = collector;
+ }
+
+ public void setDependencyTreeBuilder( DependencyTreeBuilder dependencyTreeBuilder )
+ {
+ this.dependencyTreeBuilder = dependencyTreeBuilder;
+ }
+
+ private DependencyTree getDependencyTree()
+ throws MojoExecutionException
+ {
+ try
+ {
+ return dependencyTreeBuilder.buildDependencyTree( project, localRepository, artifactFactory,
+ artifactMetadataSource, collector );
+ }
+ catch ( DependencyTreeBuilderException e )
+ {
+ String emsg = "Unable to build dependency tree.";
+ getLog().error( emsg, e );
+ throw new MojoExecutionException( emsg, e );
+ }
+ }
+
+ private void writeDirectCompileDepsTest( String classPrefix, DependencyTree tree )
+ {
+ out.println( " public void testResolveOfDirectCompileDeps()" );
+ out.println( " throws GraphTaskException" );
+ out.println( " {" );
+ writeTestProlog( classPrefix );
+ writeDirectDependenciesCheck( tree, "compile" );
+ out.println( " }" );
+ out.println( "" );
+ }
+
+ private void writeDirectDependenciesCheck( DependencyTree dependencyTree, String scope )
+ {
+ out.println( " // Check for direct dependencies on scope " + scope );
+ out.println( " expectedNodes.clear();" );
+
+ List directDeps = new ArrayList();
+ directDeps.addAll( dependencyTree.getRootNode().getChildren() );
+ CollectionUtils.transform( directDeps, new DependencyNodeToArtifactTransformer() );
+
+ Collections.sort( directDeps );
+
+ writeExpectedNodesAdd( directDeps, scope );
+
+ out.println( " assertDirectNodes( graph, expectedNodes, \"" + scope + "\" );" );
+ }
+
+ private void writeDirectTestDepsTest( String classPrefix, DependencyTree tree )
+ {
+ out.println( " public void testResolveOfDirectTestDeps()" );
+ out.println( " throws GraphTaskException" );
+ out.println( " {" );
+ writeTestProlog( classPrefix );
+ writeDirectDependenciesCheck( tree, "test" );
+ out.println( " }" );
+ out.println( "" );
+ }
+
+ private void writeExpectedNodesAdd( List deps, String scope )
+ {
+ Iterator it = deps.iterator();
+ while ( it.hasNext() )
+ {
+ Artifact artifact = (Artifact) it.next();
+ String depKey = toKey( artifact );
+ if ( StringUtils.equals( scope, artifact.getScope() ) )
+ {
+ out.println( " expectedNodes.add( \"" + depKey + "\" );" );
+ }
+ }
+ }
+
+ private void writeJavadoc( String classname, String projectKey )
+ {
+ out.println( "/**" );
+ out.println( " * " + classname );
+ out.println( " * " );
+ out.println( " * DependencyGraphTest for testing <code>" + projectKey + "</code>" );
+ out.println( " *" );
+ out.println( " * Generated by <code>archivadev:generate-dependency-tests</code> plugin" );
+ out.println( " * @version $Id$" );
+ out.println( " */" );
+ }
+
+ private void writeGraphNodesTest( String classPrefix, final DependencyTree tree )
+ {
+ out.println( " public void testResolvedDepsToNodes()" );
+ out.println( " throws GraphTaskException" );
+ out.println( " {" );
+ writeTestProlog( classPrefix );
+
+ String projectKey = toKey( project.getModel() );
+ out.println( " String expectedRootRef = \"" + projectKey + "\";" );
+ out.println( " List expectedNodes = new ArrayList();" );
+ out.println( "" );
+ out.println( " // Check for all nodes, regardless of scope." );
+ out.println( " expectedNodes.clear();" );
+
+ // Add all deps.
+ List deps = new ArrayList();
+ Predicate notRootNode = NotPredicate.getInstance( new RootArtifactPredicate( tree ) );
+ CollectionUtils.select( tree.getArtifacts(), notRootNode, deps );
+ CollectionUtils.transform( deps, new DependencyNodeToArtifactTransformer() );
+ Collections.sort( deps );
+
+ Iterator it = deps.iterator();
+ while ( it.hasNext() )
+ {
+ Artifact artifact = (Artifact) it.next();
+ String depKey = toKey( artifact );
+ out.println( " expectedNodes.add( \"" + depKey + "\" );" );
+ }
+
+ out.println( "" );
+ out.println( " assertGraph( graph, expectedRootRef, expectedNodes );" );
+
+ out.println( " }" );
+ out.println( "" );
+
+ }
+
+ private void writeTestProlog( String classPrefix )
+ {
+ out.println( " MemoryRepositoryDependencyGraphBuilder graphBuilder = " );
+ out.println( " new MemoryRepositoryDependencyGraphBuilder();" );
+ out.println( " MemoryRepository repository = new " + classPrefix + "MemoryRepository();" );
+ out.println( " graphBuilder.setMemoryRepository( repository );" );
+ out.println( "" );
+ out.println( " // Create the factory, and add the test resolver." );
+ out.println( " DependencyGraphFactory factory = new DependencyGraphFactory();" );
+ out.println( " factory.setGraphBuilder( graphBuilder );" );
+ out.println( " factory.setDesiredScope( DependencyScope.TEST );" );
+ out.println( "" );
+ out.println( " // Get the model to resolve from" );
+ out.println( " VersionedReference rootRef = toVersionedReference( \"" + project.getGroupId() + ":"
+ + project.getArtifactId() + ":" + project.getVersion() + "\"); " );
+ out.println( "" );
+ out.println( " // Perform the resolution." );
+ out.println( " DependencyGraph graph = factory.getGraph( rootRef );" );
+ out.println( "" );
+ out.println( " // Test the results." );
+ out.println( " assertNotNull( \"Graph shouldn't be null.\", graph );" );
+ out.println( "" );
+ }
+
+ private void writeTransientDependenciesCheck( DependencyTree dependencyTree, String scope )
+ {
+ out.println( " // Check for transient dependencies on scope " + scope );
+ out.println( " expectedNodes.clear();" );
+
+ // Add all deps.
+ List deps = new ArrayList( dependencyTree.getArtifacts() );
+ // Remove the direct deps.
+ List directDeps = new ArrayList();
+ directDeps.addAll( dependencyTree.getRootNode().getChildren() );
+ CollectionUtils.transform( directDeps, new DependencyNodeToArtifactTransformer() );
+ deps.removeAll( directDeps );
+
+ Collections.sort( deps );
+
+ writeExpectedNodesAdd( deps, scope );
+
+ out.println( " assertTransientNodes( graph, expectedNodes, \"" + scope + "\" );" );
+ }
+
+ private void writeTransitiveCompileDepsTest( String classPrefix, DependencyTree tree )
+ {
+ out.println( " public void testResolveOfTransitiveCompileDeps()" );
+ out.println( " throws GraphTaskException" );
+ out.println( " {" );
+ writeTestProlog( classPrefix );
+ writeTransientDependenciesCheck( tree, "compile" );
+ out.println( " }" );
+ out.println( "" );
+ }
+
+ private void writeTransitiveTestDepsTest( String classPrefix, DependencyTree tree )
+ {
+ out.println( " public void testResolveOfTransitiveTestDeps()" );
+ out.println( " throws GraphTaskException" );
+ out.println( " {" );
+ writeTestProlog( classPrefix );
+ writeTransientDependenciesCheck( tree, "test" );
+ out.println( " }" );
+ out.println( "" );
+ }
+}
diff --git a/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/DependencyUtils.java b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/DependencyUtils.java
new file mode 100644
index 000000000..4d3b86859
--- /dev/null
+++ b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/DependencyUtils.java
@@ -0,0 +1,83 @@
+package org.apache.maven.archiva.plugins.dev.testgen;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingException;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * DependencyUtils - common utilities for dependencies.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class DependencyUtils
+{
+ public static Map getManagedVersionMap( MavenProject project, ArtifactFactory factory ) throws ProjectBuildingException
+ {
+ DependencyManagement dependencyManagement = project.getDependencyManagement();
+ Map managedVersionMap;
+
+ if ( dependencyManagement != null && dependencyManagement.getDependencies() != null )
+ {
+ managedVersionMap = new HashMap();
+
+ for ( Iterator iterator = dependencyManagement.getDependencies().iterator(); iterator.hasNext(); )
+ {
+ Dependency dependency = (Dependency) iterator.next();
+
+ try
+ {
+ VersionRange versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() );
+
+ Artifact artifact =
+ factory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
+ versionRange, dependency.getType(),
+ dependency.getClassifier(), dependency.getScope() );
+
+ managedVersionMap.put( dependency.getManagementKey(), artifact );
+ }
+ catch ( InvalidVersionSpecificationException exception )
+ {
+ throw new ProjectBuildingException( project.getId(), "Unable to parse version '"
+ + dependency.getVersion() + "' for dependency '" + dependency.getManagementKey()
+ + "': " + exception.getMessage(), exception );
+ }
+ }
+ }
+ else
+ {
+ managedVersionMap = Collections.EMPTY_MAP;
+ }
+
+ return managedVersionMap;
+ }
+}
diff --git a/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/MemoryRepositoryCreator.java b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/MemoryRepositoryCreator.java
new file mode 100644
index 000000000..395f65b20
--- /dev/null
+++ b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/testgen/MemoryRepositoryCreator.java
@@ -0,0 +1,439 @@
+package org.apache.maven.archiva.plugins.dev.testgen;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.iterators.EnumerationIterator;
+import org.apache.maven.archiva.plugins.dev.functors.MatchingDependencyPredicate;
+import org.apache.maven.artifact.InvalidArtifactRTException;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DistributionManagement;
+import org.apache.maven.model.Exclusion;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Relocation;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * MemoryRepositoryCreator
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MemoryRepositoryCreator
+ extends AbstractCreator
+{
+ private File outputFile;
+
+ private PrintWriter out;
+
+ private int modelsProcessed = 0;
+
+ public void create( String classPrefix )
+ throws MojoExecutionException
+ {
+ getLog().info( "Generating " + classPrefix + "MemoryRepository.java ..." );
+ getLog().info( "Please be patient, this can take a few minutes ..." );
+
+ modelsProcessed = 0;
+
+ outputFile = new File( outputDir, classPrefix + "MemoryRepository.java" );
+ try
+ {
+ out = new PrintWriter( outputFile );
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new MojoExecutionException( "Unable to open file " + outputFile.getName() + " for output: "
+ + e.getMessage(), e );
+ }
+
+ try
+ {
+ out.println( "package org.apache.maven.archiva.dependency.graph;" );
+ out.println( "" );
+
+ writeLicense( out );
+
+ // Imports
+ out.println( "import org.apache.maven.archiva.model.ArchivaProjectModel;" );
+ out.println( "import org.apache.maven.archiva.model.Dependency;" );
+ out.println( "import org.apache.maven.archiva.model.VersionedReference;" );
+ out.println( "" );
+
+ String projectKey = toKey( project.getModel() );
+
+ writeJavadoc( classPrefix + "MemoryRepository", projectKey );
+
+ // The class itself.
+ out.println( "public class " + classPrefix + "MemoryRepository" );
+ out.println( " extends AbstractMemoryRepository" );
+ out.println( "{" );
+
+ writeTest();
+
+ out.println( "}" );
+ }
+ finally
+ {
+ out.flush();
+ IOUtil.close( out );
+ }
+
+ }
+
+ private void writeJavadoc( String classname, String projectKey )
+ {
+ out.println( "/**" );
+ out.println( " * " + classname );
+ out.println( " * " );
+ out.println( " * MemoryRepository for testing <code>" + projectKey + "</code>" );
+ out.println( " *" );
+ out.println( " * Generated by <code>archivadev:generate-dependency-tests</code> plugin" );
+ out.println( " * @version $Id$" );
+ out.println( " */" );
+ }
+
+ private void writeTest()
+ {
+ out.println( " public void initialize()" );
+ out.println( " {" );
+ out.println( " ArchivaProjectModel model;" );
+ out.println( " Dependency dep;" );
+ out.println( "" );
+
+ Set seenModels = new HashSet();
+
+ writeModel( seenModels, project.getModel() );
+
+ getLog().info(
+ "Processing done: Processed " + modelsProcessed + " models (" + seenModels.size()
+ + " were unique)" );
+
+ out.println( " }" );
+ }
+
+ private void writeModel( Set seenModels, Model model )
+ {
+ String projectKey = toKey( model );
+
+ modelsProcessed++;
+
+ if ( ( modelsProcessed % 100 ) == 0 )
+ {
+ getLog()
+ .info( "Processed " + modelsProcessed + " models (" + seenModels.size() + " unique) ..." );
+ }
+
+ Relocation relocation = null;
+
+ if ( seenModels.contains( projectKey ) )
+ {
+ return;
+ }
+
+ seenModels.add( projectKey );
+
+ out.println( " model = toModel( \"" + projectKey + "\" );" );
+
+ if ( model.getParent() != null )
+ {
+ String parentKey = toKey( model.getParent() );
+ out.println( " model.setParentProject( toParent( \"" + parentKey + "\" ) );" );
+ }
+
+ if ( isNotEmpty( model.getDependencies() ) )
+ {
+ Iterator it = model.getDependencies().iterator();
+ while ( it.hasNext() )
+ {
+ Dependency dep = applyDepMan( (Dependency) it.next(), model );
+
+ writeAddDependency( "addDependency", dep );
+ }
+ }
+
+ if ( ( model.getDependencyManagement() != null )
+ && isNotEmpty( model.getDependencyManagement().getDependencies() ) )
+ {
+ Iterator it = model.getDependencyManagement().getDependencies().iterator();
+ while ( it.hasNext() )
+ {
+ Dependency dep = (Dependency) it.next();
+
+ writeAddDependency( "addDependencyManagement", dep );
+ }
+ }
+
+ if ( isNotEmpty( model.getProperties() ) )
+ {
+ Iterator it = new EnumerationIterator( model.getProperties().keys() );
+ while ( it.hasNext() )
+ {
+ String key = (String) it.next();
+ String value = model.getProperties().getProperty( key );
+ out.println( " model.addProperty( \"" + key + "\", \"" + value + "\" );" );
+ }
+ }
+
+ if ( model.getDistributionManagement() != null )
+ {
+ DistributionManagement distMgmt = model.getDistributionManagement();
+
+ if ( distMgmt.getRelocation() != null )
+ {
+ relocation = distMgmt.getRelocation();
+
+ out.println( " model.setRelocation( new VersionedReference() );" );
+ if ( StringUtils.isNotEmpty( relocation.getGroupId() ) )
+ {
+ out.println( " model.getRelocation().setGroupId( \"" + relocation.getGroupId() + "\" );" );
+ }
+ if ( StringUtils.isNotEmpty( relocation.getArtifactId() ) )
+ {
+ out
+ .println( " model.getRelocation().setArtifactId( \"" + relocation.getArtifactId()
+ + "\" );" );
+ }
+ if ( StringUtils.isNotEmpty( relocation.getVersion() ) )
+ {
+ out.println( " model.getRelocation().setVersion( \"" + relocation.getVersion() + "\" );" );
+ }
+ }
+ }
+
+ out.println( " addModel( model );" );
+ out.println( "" );
+
+ if ( model.getParent() != null )
+ {
+ Model parentModel = getModel( model.getParent() );
+ writeModel( seenModels, parentModel );
+ }
+
+ if ( relocation != null )
+ {
+ Model relocatedModel = getModel( model, relocation );
+ writeModel( seenModels, relocatedModel );
+ }
+
+ writeModelDependencies( seenModels, projectKey, model );
+ writeModelDependencyManagement( seenModels, projectKey, model );
+ }
+
+ private Model getModel( Model model, Relocation relocation )
+ {
+ String groupId = relocation.getGroupId();
+ String artifactId = relocation.getArtifactId();
+ String version = relocation.getVersion();
+
+ // Set empty groupId.
+ if ( StringUtils.isEmpty( groupId ) )
+ {
+ groupId = model.getGroupId();
+
+ if ( StringUtils.isEmpty( groupId ) )
+ {
+ if ( model.getParent() == null )
+ {
+ throw new IllegalStateException( "BAD POM: GroupId for relocation in " + toKey( model )
+ + " cannot be determined, as there is no Parent Pom reference." );
+ }
+
+ groupId = model.getParent().getGroupId();
+ }
+ }
+
+ // Set empty artifactId.
+ if ( StringUtils.isEmpty( artifactId ) )
+ {
+ artifactId = model.getArtifactId();
+
+ if ( StringUtils.isEmpty( artifactId ) )
+ {
+ if ( model.getParent() == null )
+ {
+ throw new IllegalStateException( "BAD POM: ArtifactId for relocation in " + toKey( model )
+ + " cannot be determined, as there is no Parent Pom reference." );
+ }
+
+ artifactId = model.getParent().getArtifactId();
+ }
+ }
+
+ // Set empty version.
+ if ( StringUtils.isEmpty( version ) )
+ {
+ version = model.getVersion();
+
+ if ( StringUtils.isEmpty( version ) )
+ {
+ if ( model.getParent() == null )
+ {
+ throw new IllegalStateException( "BAD POM: version for relocation in " + toKey( model )
+ + " cannot be determined, as there is no Parent Pom reference." );
+ }
+
+ version = model.getParent().getVersion();
+ }
+ }
+
+ return getModel( groupId, artifactId, version, "pom" );
+ }
+
+ private void writeAddDependency( String addMethod, Dependency dep )
+ {
+ boolean useShortForm = true;
+ String depKey = toKey( dep );
+
+ useShortForm = isEmpty( dep.getExclusions() ) && !dep.isOptional();
+
+ String scopePart = "";
+
+ if ( isNotBlank( dep.getScope() ) )
+ {
+ scopePart = ", \"" + dep.getScope() + "\"";
+ }
+
+ if ( useShortForm )
+ {
+ out.println( " model." + addMethod + "( toDependency( \"" + depKey + "\"" + scopePart + " ) );" );
+ return;
+ }
+
+ out.println( " dep = toDependency( \"" + depKey + "\"" + scopePart + " );" );
+
+ if ( isNotEmpty( dep.getExclusions() ) )
+ {
+ Iterator it = dep.getExclusions().iterator();
+ while ( it.hasNext() )
+ {
+ Exclusion exclusion = (Exclusion) it.next();
+ String exkey = toKey( exclusion );
+ out.println( " addExclusion( dep, \"" + exkey + "\" );" );
+ }
+ }
+
+ if ( dep.isOptional() )
+ {
+ out.println( " dep.setOptional( true );" );
+ }
+
+ out.println( " model." + addMethod + "( dep );" );
+ }
+
+ private void writeModelDependencies( Set seenModels, String projectKey, Model model )
+ {
+ if ( model.getDependencies() == null )
+ {
+ return;
+ }
+
+ Iterator it = model.getDependencies().iterator();
+
+ while ( it.hasNext() )
+ {
+ Dependency dep = applyDepMan( (Dependency) it.next(), model );
+
+ Model rawModel = getModel( dep );
+
+ try
+ {
+ writeModel( seenModels, rawModel );
+ }
+ catch ( InvalidArtifactRTException e )
+ {
+ getLog().error(
+ "Encountered invalid dependency/artifact during [" + projectKey + "] : "
+ + e.getMessage(), e );
+ throw e;
+ }
+ }
+ }
+
+ private void writeModelDependencyManagement( Set seenModels, String projectKey, Model model )
+ {
+ if ( model.getDependencyManagement() == null )
+ {
+ return;
+ }
+
+ Iterator it = model.getDependencyManagement().getDependencies().iterator();
+
+ while ( it.hasNext() )
+ {
+ Dependency dep = (Dependency) it.next();
+
+ Model rawModel = getModel( dep );
+
+ try
+ {
+ writeModel( seenModels, rawModel );
+ }
+ catch ( InvalidArtifactRTException e )
+ {
+ getLog().error(
+ "Encountered invalid dependency/artifact during [" + projectKey + "] : "
+ + e.getMessage(), e );
+ throw e;
+ }
+ }
+ }
+
+ private Dependency applyDepMan( Dependency dependency, Model model )
+ {
+ if ( model.getDependencyManagement() != null )
+ {
+ if ( model.getDependencyManagement().getDependencies() != null )
+ {
+ // Attempt to find matching dep.
+ Predicate matchingDep = new MatchingDependencyPredicate( dependency );
+ Dependency depman = (Dependency) CollectionUtils.find( model.getDependencyManagement()
+ .getDependencies(), matchingDep );
+
+ if ( depman != null )
+ {
+ dependency.setVersion( depman.getVersion() );
+ dependency.setScope( StringUtils.defaultString( depman.getScope(), dependency.getScope() ) );
+
+ // Found it!
+ return dependency;
+ }
+ }
+ }
+
+ if ( model.getParent() != null )
+ {
+ Model parentModel = getModel( model.getParent() );
+ return applyDepMan( dependency, parentModel );
+ }
+
+ return dependency;
+ }
+}
diff --git a/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/utils/VariableNames.java b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/utils/VariableNames.java
new file mode 100644
index 000000000..70440d12a
--- /dev/null
+++ b/tools/maven-archivadev-plugin/src/main/java/org/apache/maven/archiva/plugins/dev/utils/VariableNames.java
@@ -0,0 +1,50 @@
+package org.apache.maven.archiva.plugins.dev.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.util.StringUtils;
+
+/**
+ * VariableNames
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class VariableNames
+{
+ public static String toClassName( String raw )
+ {
+ return StringUtils.capitalise( toVariableName( raw ) );
+ }
+
+ public static String toVariableName( String raw )
+ {
+ StringBuffer sb = new StringBuffer();
+
+ String parts[] = StringUtils.split( raw, "-_:." );
+ for ( int i = 0; i < parts.length; i++ )
+ {
+ String part = parts[i];
+ sb.append( StringUtils.capitalise( part ) );
+ }
+
+ return StringUtils.uncapitalise( sb.toString() );
+ }
+}
diff --git a/tools/pom.xml b/tools/pom.xml
new file mode 100644
index 000000000..3896ba82b
--- /dev/null
+++ b/tools/pom.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2005-2006 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-parent</artifactId>
+ <version>1.0-alpha-1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.maven.archiva.tools</groupId>
+ <artifactId>tools-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>Archiva Tools :: Parent</name>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>maven-archivadev-plugin</module>
+ </modules>
+</project>