You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2011/08/17 16:29:32 UTC

svn commit: r1158739 - in /maven/indexer/trunk/indexer-core/src: main/java/org/apache/maven/index/ main/java/org/apache/maven/index/context/ main/java/org/apache/maven/index/creator/ main/java/org/apache/maven/index/util/ test/java/org/apache/maven/ind...

Author: cstamas
Date: Wed Aug 17 14:29:32 2011
New Revision: 1158739

URL: http://svn.apache.org/viewvc?rev=1158739&view=rev
Log:
MINDEXER-34: Order of IndexCreator's passed to NexusIndexer.addIndexingContext...() matters and may produce wrong results.

Maven Indexer provides a set of "core" creators, and while there is interdependency between them, it was never handled programatically. As Jesse points out in issue, the container returned list (lookupList()) ordering is not guaranteed at all.

Now, the IndexCreator interface is extended to be able to topologically sort creators before they are added to newly created contexts. A runtime exception IllegalArgumentException is newly introduced on NexusIndexer.addIndexingContext... methods, to prevent creation of IndexingContexts with non-satisfiable list of IndexCreators.

Added:
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/IndexCreatorSorter.java   (with props)
    maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/
    maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/IndexCreatorSorterTest.java   (with props)
    maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/SpoofIndexCreator.java   (with props)
Modified:
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/IndexCreator.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/AbstractIndexCreator.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MavenArchetypeArtifactInfoIndexCreator.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreator.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MinimalArtifactInfoIndexCreator.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/OSGIArtifactIndexCreator.java

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java?rev=1158739&r1=1158738&r2=1158739&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java Wed Aug 17 14:29:32 2011
@@ -44,6 +44,7 @@ import org.apache.maven.index.context.Me
 import org.apache.maven.index.context.StaticContextMemberProvider;
 import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
 import org.apache.maven.index.expr.SearchExpression;
+import org.apache.maven.index.util.IndexCreatorSorter;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
@@ -91,7 +92,7 @@ public class DefaultNexusIndexer
     {
         IndexingContext context =
             new DefaultIndexingContext( id, repositoryId, repository, indexDirectory, repositoryUrl, indexUpdateUrl,
-                indexers, false );
+                IndexCreatorSorter.sort( indexers ), false );
 
         indexingContexts.put( context.getId(), context );
 
@@ -109,7 +110,7 @@ public class DefaultNexusIndexer
         {
             context =
                 new DefaultIndexingContext( id, repositoryId, repository, indexDirectory, repositoryUrl,
-                    indexUpdateUrl, indexers, true );
+                    indexUpdateUrl, IndexCreatorSorter.sort( indexers ), true );
 
             indexingContexts.put( context.getId(), context );
         }
@@ -128,7 +129,7 @@ public class DefaultNexusIndexer
     {
         IndexingContext context =
             new DefaultIndexingContext( id, repositoryId, repository, directory, repositoryUrl, indexUpdateUrl,
-                indexers, false );
+                IndexCreatorSorter.sort( indexers ), false );
 
         indexingContexts.put( context.getId(), context );
 
@@ -146,7 +147,7 @@ public class DefaultNexusIndexer
         {
             context =
                 new DefaultIndexingContext( id, repositoryId, repository, directory, repositoryUrl, indexUpdateUrl,
-                    indexers, true );
+                    IndexCreatorSorter.sort( indexers ), true );
 
             indexingContexts.put( context.getId(), context );
         }

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java?rev=1158739&r1=1158738&r2=1158739&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java Wed Aug 17 14:29:32 2011
@@ -104,6 +104,7 @@ public interface NexusIndexer
      * @throws UnsupportedExistingLuceneIndexException if a Lucene index already exists where location is specified, but
      *             it has no Nexus descriptor record or it has, but the embedded repoId differs from the repoId
      *             specified from the supplied one.
+     * @throws IllegalArgumentException in case the supplied list of IndexCreators are not satisfiable
      */
     IndexingContext addIndexingContext( String id, String repositoryId, File repository, File indexDirectory,
                                         String repositoryUrl, String indexUpdateUrl,
@@ -124,6 +125,7 @@ public interface NexusIndexer
      * @param indexers the set of indexers to apply to this context.
      * @return
      * @throws IOException in case of some serious IO problem.
+     * @throws IllegalArgumentException in case the supplied list of IndexCreators are not satisfiable
      */
     IndexingContext addIndexingContextForced( String id, String repositoryId, File repository, File indexDirectory,
                                               String repositoryUrl, String indexUpdateUrl,
@@ -145,6 +147,7 @@ public interface NexusIndexer
      * @throws UnsupportedExistingLuceneIndexException if a Lucene index already exists where location is specified, but
      *             it has no Nexus descriptor record or it has, but the embedded repoId differs from the repoId
      *             specified from the supplied one.
+     * @throws IllegalArgumentException in case the supplied list of IndexCreators are not satisfiable
      */
     IndexingContext addIndexingContext( String id, String repositoryId, File repository, Directory directory,
                                         String repositoryUrl, String indexUpdateUrl,
@@ -165,6 +168,7 @@ public interface NexusIndexer
      * @param indexers the set of indexers to apply to this context.
      * @return
      * @throws IOException in case of some serious IO problem.
+     * @throws IllegalArgumentException in case the supplied list of IndexCreators are not satisfiable
      */
     IndexingContext addIndexingContextForced( String id, String repositoryId, File repository, Directory directory,
                                               String repositoryUrl, String indexUpdateUrl,

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/IndexCreator.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/IndexCreator.java?rev=1158739&r1=1158738&r2=1158739&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/IndexCreator.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/IndexCreator.java Wed Aug 17 14:29:32 2011
@@ -21,6 +21,7 @@ package org.apache.maven.index.context;
 
 import java.io.IOException;
 import java.util.Collection;
+import java.util.List;
 
 import org.apache.lucene.document.Document;
 import org.apache.maven.index.ArtifactContext;
@@ -39,6 +40,22 @@ import org.apache.maven.index.creator.Mi
 public interface IndexCreator
 {
     /**
+     * Returns IndexCreator ID, that has to be unique across all existing creators.
+     * 
+     * @return
+     */
+    String getId();
+
+    /**
+     * Returns list of IndexCreator IDs that this creator depends on. Needed to perform a topological sort on
+     * IndexCreators to guarantee proper ordering of them, as some IndexCreators might rely on informations already
+     * extracted by some other IndexCreator.
+     * 
+     * @return
+     */
+    List<String> getCreatorDependencies();
+
+    /**
      * Returns the indexer fields that this IndexCreator introduces to index.
      * 
      * @return

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/AbstractIndexCreator.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/AbstractIndexCreator.java?rev=1158739&r1=1158738&r2=1158739&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/AbstractIndexCreator.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/AbstractIndexCreator.java Wed Aug 17 14:29:32 2011
@@ -19,6 +19,10 @@ package org.apache.maven.index.creator;
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
 import org.apache.maven.index.context.IndexCreator;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 
@@ -31,6 +35,38 @@ public abstract class AbstractIndexCreat
     extends AbstractLogEnabled
     implements IndexCreator
 {
+    private final String id;
+
+    private final List<String> creatorDependencies;
+
+    protected AbstractIndexCreator( final String id )
+    {
+        this( id, null );
+    }
+
+    protected AbstractIndexCreator( final String id, final List<String> creatorDependencies )
+    {
+        this.id = id;
+
+        final ArrayList<String> deps = new ArrayList<String>();
+
+        if ( creatorDependencies != null && !creatorDependencies.isEmpty() )
+        {
+            deps.addAll( creatorDependencies );
+        }
+
+        this.creatorDependencies = Collections.unmodifiableList( deps );
+    }
+
+    public String getId()
+    {
+        return id;
+    }
+
+    public List<String> getCreatorDependencies()
+    {
+        return creatorDependencies;
+    }
 
     public static String bos( boolean b )
     {
@@ -41,5 +77,4 @@ public abstract class AbstractIndexCreat
     {
         return b.equals( "1" );
     }
-
 }

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java?rev=1158739&r1=1158738&r2=1158739&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/JarFileContentsIndexCreator.java Wed Aug 17 14:29:32 2011
@@ -60,6 +60,11 @@ public class JarFileContentsIndexCreator
     public static final IndexerField FLD_CLASSNAMES_KW = new IndexerField( MAVEN.CLASSNAMES, IndexerFieldVersion.V1,
         "c", "Artifact Classes (tokenized on newlines only)", Store.YES, Index.ANALYZED );
 
+    public JarFileContentsIndexCreator()
+    {
+        super( ID );
+    }
+
     public void populateArtifactInfo( ArtifactContext artifactContext )
         throws IOException
     {

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MavenArchetypeArtifactInfoIndexCreator.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MavenArchetypeArtifactInfoIndexCreator.java?rev=1158739&r1=1158738&r2=1158739&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MavenArchetypeArtifactInfoIndexCreator.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MavenArchetypeArtifactInfoIndexCreator.java Wed Aug 17 14:29:32 2011
@@ -21,6 +21,7 @@ package org.apache.maven.index.creator;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 
@@ -52,6 +53,11 @@ public class MavenArchetypeArtifactInfoI
     private static final String[] ARCHETYPE_XML_LOCATIONS = { "META-INF/maven/archetype.xml", "META-INF/archetype.xml",
         "META-INF/maven/archetype-metadata.xml" };
 
+    public MavenArchetypeArtifactInfoIndexCreator()
+    {
+        super( ID, Arrays.asList( MinimalArtifactInfoIndexCreator.ID ) );
+    }
+
     public void populateArtifactInfo( ArtifactContext ac )
     {
         File artifact = ac.getArtifact();

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreator.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreator.java?rev=1158739&r1=1158738&r2=1158739&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreator.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreator.java Wed Aug 17 14:29:32 2011
@@ -65,6 +65,11 @@ public class MavenPluginArtifactInfoInde
     public static final IndexerField FLD_PLUGIN_GOALS = new IndexerField( MAVEN.PLUGIN_GOALS, IndexerFieldVersion.V1,
         "gx", "MavenPlugin goals (as keyword, stored)", Store.YES, Index.ANALYZED );
 
+    public MavenPluginArtifactInfoIndexCreator()
+    {
+        super( ID, Arrays.asList( MinimalArtifactInfoIndexCreator.ID ) );
+    }
+
     public void populateArtifactInfo( ArtifactContext ac )
     {
         File artifact = ac.getArtifact();

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MinimalArtifactInfoIndexCreator.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MinimalArtifactInfoIndexCreator.java?rev=1158739&r1=1158738&r2=1158739&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MinimalArtifactInfoIndexCreator.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/MinimalArtifactInfoIndexCreator.java Wed Aug 17 14:29:32 2011
@@ -112,6 +112,11 @@ public class MinimalArtifactInfoIndexCre
 
     private Locator sha1l = new Sha1Locator();
 
+    public MinimalArtifactInfoIndexCreator()
+    {
+        super( ID );
+    }
+
     public void populateArtifactInfo( ArtifactContext ac )
     {
         File artifact = ac.getArtifact();

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/OSGIArtifactIndexCreator.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/OSGIArtifactIndexCreator.java?rev=1158739&r1=1158738&r2=1158739&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/OSGIArtifactIndexCreator.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/creator/OSGIArtifactIndexCreator.java Wed Aug 17 14:29:32 2011
@@ -94,6 +94,11 @@ public class OSGIArtifactIndexCreator
         return Arrays.asList( FLD_BUNDLE_SYMBOLIC_NAME, FLD_BUNDLE_VERSION, FLD_BUNDLE_EXPORT_PACKAGE,
                               FLD_BUNDLE_EXPORT_SERVIVE );
     }
+    
+    public OSGIArtifactIndexCreator()
+    {
+        super( ID );
+    }
 
     public void populateArtifactInfo( ArtifactContext artifactContext )
         throws IOException

Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/IndexCreatorSorter.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/IndexCreatorSorter.java?rev=1158739&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/IndexCreatorSorter.java (added)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/IndexCreatorSorter.java Wed Aug 17 14:29:32 2011
@@ -0,0 +1,82 @@
+package org.apache.maven.index.util;
+
+/*
+ * 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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.maven.index.context.IndexCreator;
+import org.codehaus.plexus.util.dag.CycleDetectedException;
+import org.codehaus.plexus.util.dag.DAG;
+import org.codehaus.plexus.util.dag.TopologicalSorter;
+
+public class IndexCreatorSorter
+{
+    public static List<IndexCreator> sort( List<? extends IndexCreator> creators )
+        throws IllegalArgumentException
+    {
+        try
+        {
+            final HashMap<String, IndexCreator> creatorsById = new HashMap<String, IndexCreator>( creators.size() );
+
+            DAG dag = new DAG();
+
+            for ( IndexCreator creator : creators )
+            {
+                creatorsById.put( creator.getId(), creator );
+
+                dag.addVertex( creator.getId() );
+
+                for ( String depId : creator.getCreatorDependencies() )
+                {
+                    dag.addEdge( creator.getId(), depId );
+                }
+            }
+
+            List<String> sortedIds = TopologicalSorter.sort( dag );
+
+            final ArrayList<IndexCreator> sortedCreators = new ArrayList<IndexCreator>( creators.size() );
+
+            for ( String id : sortedIds )
+            {
+                final IndexCreator creator = creatorsById.get( id );
+
+                if ( creator != null )
+                {
+                    sortedCreators.add( creator );
+                }
+                else
+                {
+                    throw new IllegalArgumentException( String.format(
+                        "IndexCreator with ID=\"%s\" does not exists, the present creator ID=\"%s\" depends on it!",
+                        id, dag.getParentLabels( id ) ) );
+                }
+            }
+
+            return sortedCreators;
+        }
+        catch ( CycleDetectedException e )
+        {
+            throw new IllegalArgumentException( "Supplied IndexCreator inter-dependencies", e );
+        }
+
+    }
+}

Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/IndexCreatorSorter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/util/IndexCreatorSorter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/IndexCreatorSorterTest.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/IndexCreatorSorterTest.java?rev=1158739&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/IndexCreatorSorterTest.java (added)
+++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/IndexCreatorSorterTest.java Wed Aug 17 14:29:32 2011
@@ -0,0 +1,105 @@
+package org.apache.maven.index.util;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.maven.index.context.IndexCreator;
+import org.codehaus.plexus.PlexusTestCase;
+import org.junit.Assert;
+
+public class IndexCreatorSorterTest
+    extends PlexusTestCase
+{
+    public void testLookupList()
+        throws Exception
+    {
+        final List<IndexCreator> creators = getContainer().lookupList( IndexCreator.class );
+
+        final List<IndexCreator> sortedCreators = IndexCreatorSorter.sort( creators );
+
+        // we are interested in IDs only
+        final List<String> sortedCreatorIds = new ArrayList<String>();
+        for ( IndexCreator creator : sortedCreators )
+        {
+            sortedCreatorIds.add( creator.getId() );
+        }
+
+        // ensure we fulfil some basic conditions
+        Assert.assertTrue( "min should be present", sortedCreatorIds.contains( "min" ) );
+        Assert.assertTrue( "maven-plugin should be present", sortedCreatorIds.contains( "maven-plugin" ) );
+        Assert.assertTrue( "maven-archetype should be present", sortedCreatorIds.contains( "maven-archetype" ) );
+
+        // currently, both "maven-plugin" and "maven-archetype" creator depend on "min" creator
+        Assert.assertTrue( "maven-archetype depends on min",
+            sortedCreatorIds.indexOf( "min" ) < sortedCreatorIds.indexOf( "maven-archetype" ) );
+        Assert.assertTrue( "maven-plugin depends on min",
+            sortedCreatorIds.indexOf( "min" ) < sortedCreatorIds.indexOf( "maven-plugin" ) );
+    }
+
+    public void testLookupListWithSpoofedCreator()
+        throws Exception
+    {
+        final List<IndexCreator> creators =
+            new ArrayList<IndexCreator>( getContainer().lookupList( IndexCreator.class ) );
+
+        // now we add spoofs to it, this one depends on ALL creators. Note: we add it as 1st intentionally
+        creators.add( 0,
+            new SpoofIndexCreator( "depend-on-all", new ArrayList<String>(
+                getContainer().lookupMap( IndexCreator.class ).keySet() ) ) );
+
+        // now we add spoofs to it, this one depends on only one, the "depend-on-all" creator Note: we add it as 1st
+        // intentionally
+        creators.add( 0, new SpoofIndexCreator( "last", Arrays.asList( "depend-on-all" ) ) );
+
+        final List<IndexCreator> sortedCreators = IndexCreatorSorter.sort( creators );
+
+        // we are interested in IDs only
+        final List<String> sortedCreatorIds = new ArrayList<String>();
+        for ( IndexCreator creator : sortedCreators )
+        {
+            sortedCreatorIds.add( creator.getId() );
+        }
+
+        // ensure we fulfil some basic conditions
+        Assert.assertTrue( "min should be present", sortedCreatorIds.contains( "min" ) );
+        Assert.assertTrue( "maven-plugin should be present", sortedCreatorIds.contains( "maven-plugin" ) );
+        Assert.assertTrue( "maven-archetype should be present", sortedCreatorIds.contains( "maven-archetype" ) );
+        Assert.assertTrue( "depend-on-all should be present", sortedCreatorIds.contains( "depend-on-all" ) );
+        Assert.assertTrue( "last should be present", sortedCreatorIds.contains( "last" ) );
+
+        // "last" has to be last
+        Assert.assertTrue( "last creator should be last",
+            sortedCreatorIds.indexOf( "last" ) == sortedCreatorIds.size() - 1 );
+        Assert.assertTrue( "depend-on-all should be next to last",
+            sortedCreatorIds.indexOf( "depend-on-all" ) == sortedCreatorIds.size() - 2 );
+    }
+
+    public void testLookupListWithNonExistentCreatorDependency()
+        throws Exception
+    {
+        final List<IndexCreator> creators =
+            new ArrayList<IndexCreator>( getContainer().lookupList( IndexCreator.class ) );
+
+        // now we add spoofs to it, this one depends on non existent creator. Note: we add it as 1st intentionally
+        creators.add( 0,
+            new SpoofIndexCreator( "non-satisfyable", Arrays.asList( "this-creator-i-depend-on-does-not-exists" ) ) );
+
+        try
+        {
+            final List<IndexCreator> sortedCreators = IndexCreatorSorter.sort( creators );
+
+            Assert.fail( "IndexCreator list is not satisfyable!" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            // good, check message
+            final String message = e.getMessage();
+
+            Assert.assertTrue( "Exception message should mention the problematic creator's ID",
+                message.contains( "non-satisfyable" ) );
+            Assert.assertTrue( "Exception message should mention the missing creator's ID",
+                message.contains( "this-creator-i-depend-on-does-not-exists" ) );
+        }
+    }
+}

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/IndexCreatorSorterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/IndexCreatorSorterTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/SpoofIndexCreator.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/SpoofIndexCreator.java?rev=1158739&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/SpoofIndexCreator.java (added)
+++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/SpoofIndexCreator.java Wed Aug 17 14:29:32 2011
@@ -0,0 +1,43 @@
+package org.apache.maven.index.util;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.lucene.document.Document;
+import org.apache.maven.index.ArtifactContext;
+import org.apache.maven.index.ArtifactInfo;
+import org.apache.maven.index.IndexerField;
+import org.apache.maven.index.creator.AbstractIndexCreator;
+
+public class SpoofIndexCreator
+    extends AbstractIndexCreator
+{
+    protected SpoofIndexCreator( final String id, final List<String> creatorDependencies )
+    {
+        super( id, creatorDependencies );
+    }
+
+    public Collection<IndexerField> getIndexerFields()
+    {
+        return Collections.emptyList();
+    }
+
+    public void populateArtifactInfo( ArtifactContext artifactContext )
+        throws IOException
+    {
+        // TODO Auto-generated method stub
+    }
+
+    public void updateDocument( ArtifactInfo artifactInfo, Document document )
+    {
+        // TODO Auto-generated method stub
+    }
+
+    public boolean updateArtifactInfo( Document document, ArtifactInfo artifactInfo )
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+}

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/SpoofIndexCreator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/util/SpoofIndexCreator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision