You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by og...@apache.org on 2009/04/23 00:57:04 UTC

svn commit: r767705 [5/31] - in /maven/mercury/trunk/mercury-core: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/maven/ src/main/java/org/apache/maven/mercury/ src/main/java/org/apache/maven/merc...

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/MercuryEvent.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/MercuryEvent.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/MercuryEvent.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/MercuryEvent.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,165 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.event;
+
+import java.util.BitSet;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+/**
+ * 
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public interface MercuryEvent
+{
+
+  @SuppressWarnings("serial")
+  class EventMask
+  extends BitSet
+  {
+    public EventMask( EventTypeEnum... bits )
+    {
+      super();
+      
+      for( EventTypeEnum bit : bits )
+        set( bit.bitNo );
+    }
+
+    public EventMask( String bits )
+    {
+      super();
+      
+      setBits( bits );
+    }
+    
+    public final void setBits( String bits )
+    {
+      if( bits == null )
+        return;
+      
+      StringTokenizer st = new StringTokenizer( bits, ",");
+      
+      while( st.hasMoreTokens() )
+      {
+        String bit = st.nextToken();
+        
+        int bitNo = Integer.valueOf( bit );
+        
+        set( bitNo, true );
+      }
+    }
+  }
+
+  /**
+   * event type 
+   * 
+   * @return 
+   */
+  EventTypeEnum getType();
+
+  /**
+   * event name inside type 
+   * 
+   * @return
+   */
+  String getName();
+  
+  /**
+   * aggregation tag of this event. Used to trace event propagation in the system 
+   * 
+   * @return
+   */
+  String getTag();
+  void setTag( String tag );
+  
+  /**
+   * information for this event. Used to trace event propagation in the system 
+   * 
+   * @return
+   */
+  String getInfo();
+  void setInfo( String info );
+  
+  /**
+   * get the event start time as UTC timestapm
+   * 
+   * @return start time as UTC timestamp
+   */
+  long getStart();
+  
+  /**
+   * start the event
+   */
+  void start();
+  
+  /**
+   * stop the event and calculate the duration
+   */
+  void stop();
+  
+
+  /**
+   * result field
+   * 
+   * @return
+   */
+  public String getResult();
+
+  public void setResult( String result );
+
+  public boolean hasResult();
+  
+  /**
+   * duration of this event in millis
+   * 
+   * @return duration of this event
+   */
+  long getDuration();
+  
+  /**
+   * event's payload
+   *  
+   * @return results, associated with this event
+   */
+  Map<String,Object> getPayload();
+  
+  /**
+   * get one of payload values
+   *  
+   * @param name element name  
+   * @return results, associated with this event
+   */
+  Object getPayload( String name );
+  
+  /**
+   * set the whole payload
+   * @param payload
+   */
+  void setPayload( Map<String,Object> payload );
+  
+  /**
+   * set the whole payload
+   * @param name
+   * @param value
+   */
+  void setPayload( String name, Object value );
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/MercuryEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/MercuryEvent.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/MercuryEventListener.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/MercuryEventListener.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/MercuryEventListener.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/MercuryEventListener.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,43 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.event;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public interface MercuryEventListener
+{
+  /**
+   * identifies what events this listrener is interested in. 
+   * 
+   * @return the mask - BitSet of event type bits, or null, if this listener wants to be notified of all events 
+   */
+  MercuryEvent.EventMask getMask();
+  
+  /**
+   * this is called when an event matching the listener mask is generated
+   * 
+   * @param event
+   */
+  void fire( MercuryEvent event );
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/MercuryEventListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/MercuryEventListener.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/Messages.properties
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/Messages.properties?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/Messages.properties (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/Messages.properties Wed Apr 22 22:56:48 2009
@@ -0,0 +1,19 @@
+#
+#  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.
+#
+listener.error=event listener threw an exception: {0}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/Messages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/Messages.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/AbstractMercuryLogger.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/AbstractMercuryLogger.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/AbstractMercuryLogger.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/AbstractMercuryLogger.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,65 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.logging;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public abstract class AbstractMercuryLogger
+{
+  protected String _className;
+  
+  MercuryLoggingLevelEnum _threshold = MercuryLoggerManager.getThreshold();
+  
+  
+  @SuppressWarnings("unchecked")
+  public AbstractMercuryLogger( Class clazz )
+  {
+    _className = clazz.getName();
+  }
+  
+  public boolean isDebugEnabled()
+  {
+    return _threshold.getId() <= MercuryLoggingLevelEnum.debug.getId();
+  }
+
+  public boolean isErrorEnabled()
+  {
+    return _threshold.getId() <= MercuryLoggingLevelEnum.error.getId();
+  }
+
+  public boolean isFatalEnabled()
+  {
+    return _threshold.getId() <= MercuryLoggingLevelEnum.error.getId();
+  }
+
+  public boolean isInfoEnabled()
+  {
+    return _threshold.getId() <= MercuryLoggingLevelEnum.info.getId();
+  }
+
+  public boolean isWarnEnabled()
+  {
+    return _threshold.getId() <= MercuryLoggingLevelEnum.warn.getId();
+  }
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/AbstractMercuryLogger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/AbstractMercuryLogger.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/IMercuryLogger.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/IMercuryLogger.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/IMercuryLogger.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/IMercuryLogger.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,59 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.logging;
+
+/**
+ * A copy of plexus default container logger interface. Need it to externalize the logging system
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public interface IMercuryLogger
+{
+  void debug( String message );
+
+  void debug( String message, Throwable throwable );
+
+  boolean isDebugEnabled();
+
+  void info( String message );
+
+  void info( String message, Throwable throwable );
+
+  boolean isInfoEnabled();
+
+  void warn( String message );
+
+  void warn( String message, Throwable throwable );
+
+  boolean isWarnEnabled();
+
+  void error( String message );
+
+  void error( String message, Throwable throwable );
+
+  boolean isErrorEnabled();
+
+  void fatal( String message );
+
+  void fatal( String message, Throwable throwable );
+
+  boolean isFatalEnabled();
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/IMercuryLogger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/IMercuryLogger.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/IMercuryLoggerFactory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/IMercuryLoggerFactory.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/IMercuryLoggerFactory.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/IMercuryLoggerFactory.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,35 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.logging;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public interface IMercuryLoggerFactory
+{
+  @SuppressWarnings("unchecked")
+  IMercuryLogger getLogger( Class clazz );
+  
+  /** is not used for now */
+  void setThreshold( MercuryLoggingLevelEnum threshold );
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/IMercuryLoggerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/IMercuryLoggerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/MercuryLoggerManager.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/MercuryLoggerManager.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/MercuryLoggerManager.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/MercuryLoggerManager.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,67 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.logging;
+
+import org.apache.maven.mercury.logging.console.MercuryConsoleLoggerFactory;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class MercuryLoggerManager
+{
+  public static final String SYSTEM_PROPERTY_MERCURY_LOG_FACTORY = "mercury.log.factory";
+  public static final String _loggerFactoryClassName = System.getProperty( SYSTEM_PROPERTY_MERCURY_LOG_FACTORY, MercuryConsoleLoggerFactory.class.getName() );
+  
+  public static final String SYSTEM_PROPERTY_MERCURY_LOG_THRESHOLD = "mercury.log.level";
+  public static final String _loggerThresholdName = System.getProperty( SYSTEM_PROPERTY_MERCURY_LOG_THRESHOLD
+                                                                        , MercuryLoggingLevelEnum.DEFAULT_LEVEL.name()
+                                                                      );
+  
+  static MercuryLoggingLevelEnum _threshold = MercuryLoggingLevelEnum.valueOf( _loggerThresholdName );
+
+  static IMercuryLoggerFactory _loggerFactory;
+  
+  @SuppressWarnings("unchecked")
+  public static final IMercuryLogger getLogger( Class clazz )
+  {
+    if( _loggerFactory == null )
+    {
+      try
+      {
+        _loggerFactory = (IMercuryLoggerFactory)Class.forName( _loggerFactoryClassName ).newInstance();
+      }
+      catch( Exception e )
+      {
+        _loggerFactory = new MercuryConsoleLoggerFactory();
+        _loggerFactory.getLogger( MercuryLoggerManager.class ).error( "cannot create logger factory "+_loggerFactoryClassName, e );
+      }
+    }
+    
+    return _loggerFactory.getLogger( clazz );
+  }
+  
+  public static MercuryLoggingLevelEnum getThreshold()
+  {
+    return _threshold;
+  }
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/MercuryLoggerManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/MercuryLoggerManager.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/MercuryLoggingLevelEnum.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/MercuryLoggingLevelEnum.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/MercuryLoggingLevelEnum.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/MercuryLoggingLevelEnum.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,53 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.logging;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public enum MercuryLoggingLevelEnum
+{
+    debug(0)
+  , info(1)
+  , warn(2)
+  , error(3)
+  , fatal(4)
+  , disabled(5)
+  ;
+
+  public static final MercuryLoggingLevelEnum DEFAULT_LEVEL = info;
+
+  private int id;
+
+  // Constructor
+  MercuryLoggingLevelEnum( int id )
+  {
+      this.id = id;
+  }
+
+  int getId()
+  {
+      return id;
+  }
+  
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/MercuryLoggingLevelEnum.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/MercuryLoggingLevelEnum.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/console/MercuryConsoleLogger.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/console/MercuryConsoleLogger.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/console/MercuryConsoleLogger.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/console/MercuryConsoleLogger.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,113 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.logging.console;
+
+import org.apache.maven.mercury.logging.AbstractMercuryLogger;
+import org.apache.maven.mercury.logging.IMercuryLogger;
+import org.apache.maven.mercury.logging.MercuryLoggingLevelEnum;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class MercuryConsoleLogger
+extends AbstractMercuryLogger
+implements IMercuryLogger
+{
+  
+  @SuppressWarnings("unchecked")
+  public MercuryConsoleLogger( Class clazz )
+  {
+    super( clazz );
+  }
+  
+  private static final void say( MercuryLoggingLevelEnum level, String message, Throwable throwable )
+  {
+    System.out.print( "["+level.name()+"] " );
+    System.out.println( message );
+    if( throwable != null )
+    {
+      throwable.printStackTrace( System.out );
+    }
+  }
+
+  public void debug( String message )
+  {
+    if( isDebugEnabled() )
+      say( MercuryLoggingLevelEnum.debug, message, null );
+  }
+
+  public void debug( String message, Throwable throwable )
+  {
+    if( isDebugEnabled() )
+      say( MercuryLoggingLevelEnum.debug, message, throwable );
+  }
+
+  public void error( String message )
+  {
+      if( isErrorEnabled() )
+          say( MercuryLoggingLevelEnum.error, message, null );
+  }
+
+  public void error( String message, Throwable throwable )
+  {
+      if( isErrorEnabled() )
+          say( MercuryLoggingLevelEnum.error, message, throwable );
+  }
+
+  public void fatal( String message )
+  {
+      if( isErrorEnabled() )
+          say( MercuryLoggingLevelEnum.error, message, null );
+  }
+
+  public void fatal( String message, Throwable throwable )
+  {
+      if( isErrorEnabled() )
+          say( MercuryLoggingLevelEnum.error, message, throwable );
+  }
+
+  public void info( String message )
+  {
+      if( isInfoEnabled() )
+          say( MercuryLoggingLevelEnum.info, message, null );
+  }
+
+  public void info( String message, Throwable throwable )
+  {
+      if( isInfoEnabled() )
+          say( MercuryLoggingLevelEnum.info, message, throwable );
+  }
+
+  public void warn( String message )
+  {
+      if( isWarnEnabled() )
+          say( MercuryLoggingLevelEnum.warn, message, null );
+  }
+
+  public void warn( String message, Throwable throwable )
+  {
+      if( isWarnEnabled() )
+          say( MercuryLoggingLevelEnum.warn, message, throwable );
+  }
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/console/MercuryConsoleLogger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/console/MercuryConsoleLogger.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/console/MercuryConsoleLoggerFactory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/console/MercuryConsoleLoggerFactory.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/console/MercuryConsoleLoggerFactory.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/console/MercuryConsoleLoggerFactory.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,49 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.logging.console;
+
+import org.apache.maven.mercury.logging.IMercuryLogger;
+import org.apache.maven.mercury.logging.IMercuryLoggerFactory;
+import org.apache.maven.mercury.logging.MercuryLoggerManager;
+import org.apache.maven.mercury.logging.MercuryLoggingLevelEnum;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class MercuryConsoleLoggerFactory
+implements IMercuryLoggerFactory
+{
+  MercuryLoggingLevelEnum _threshold = MercuryLoggerManager.getThreshold();
+  
+  @SuppressWarnings("unchecked")
+  public IMercuryLogger getLogger( Class clazz )
+  {
+    return new MercuryConsoleLogger(clazz);
+  }
+
+  public void setThreshold( MercuryLoggingLevelEnum threshold )
+  {
+    _threshold = threshold;
+  }
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/console/MercuryConsoleLoggerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/logging/console/MercuryConsoleLoggerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ArtifactFilterList.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ArtifactFilterList.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ArtifactFilterList.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ArtifactFilterList.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,52 @@
+/*
+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.
+*/
+
+package org.apache.maven.mercury.metadata;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.mercury.util.Util;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class ArtifactFilterList
+{
+    List<MetadataTreeArtifactFilter> _filters = new ArrayList<MetadataTreeArtifactFilter>(4);
+
+    public ArtifactFilterList()
+    {
+    }
+
+    public ArtifactFilterList( Map<String, Collection<String>> filter )
+    {
+        if( Util.isEmpty( filter ) )
+            return;
+        
+        _filters.add( new MetadataTreeArtifactFilterMap(filter) );
+    }
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ArtifactFilterList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ArtifactFilterList.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClassicDepthComparator.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClassicDepthComparator.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClassicDepthComparator.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClassicDepthComparator.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,50 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.metadata;
+
+import java.util.Comparator;
+
+import org.apache.maven.mercury.artifact.MetadataTreeNode;
+
+/**
+ * classical depth comparator: shallower is better by default, but that could 
+ * be changed by appropriate constructor
+ * 
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class ClassicDepthComparator
+implements Comparator<MetadataTreeNode>
+{
+  boolean _closerBetter = true;
+  
+  public ClassicDepthComparator()
+  {
+  }
+
+  public ClassicDepthComparator( boolean closerBetter )
+  {
+    _closerBetter = closerBetter;
+  }
+  
+  public int compare( MetadataTreeNode n1, MetadataTreeNode n2 )
+  {
+    return _closerBetter ? n2.getDepth() - n1.getDepth() : n1.getDepth() - n2.getDepth() ;
+  }
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClassicDepthComparator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClassicDepthComparator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClassicVersionComparator.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClassicVersionComparator.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClassicVersionComparator.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClassicVersionComparator.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,59 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.metadata;
+
+import java.util.Comparator;
+
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.artifact.MetadataTreeNode;
+import org.apache.maven.mercury.artifact.version.DefaultArtifactVersion;
+
+/**
+ * classical version comparator: newer is better by default, but that could 
+ * be changed by appropriate constructor
+ * 
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class ClassicVersionComparator
+implements Comparator<MetadataTreeNode>
+{
+  boolean _newerBetter = true;
+  
+  public ClassicVersionComparator()
+  {
+  }
+
+  public ClassicVersionComparator( boolean newerBetter )
+  {
+    _newerBetter = newerBetter;
+  }
+  
+  public int compare( MetadataTreeNode n1, MetadataTreeNode n2 )
+  {
+    ArtifactMetadata md1 = n1.getMd();
+    DefaultArtifactVersion v1 = new DefaultArtifactVersion( md1.getVersion() );
+    
+    ArtifactMetadata md2 = n2.getMd();
+    DefaultArtifactVersion v2 = new DefaultArtifactVersion( md2.getVersion() );
+    
+    return _newerBetter ? v1.compareTo(v2) : v2.compareTo(v1) ;
+  }
+  
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClassicVersionComparator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClassicVersionComparator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClasspathContainer.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClasspathContainer.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClasspathContainer.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClasspathContainer.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,141 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.metadata;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.artifact.ArtifactScopeEnum;
+import org.apache.maven.mercury.artifact.MetadataTreeNode;
+
+/*
+ * classpath container that is aware of the classpath scope
+ * 
+ * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
+ */
+public class ClasspathContainer
+    implements Iterable<ArtifactMetadata>
+{
+    private List<ArtifactMetadata> classpath;
+
+    private ArtifactScopeEnum scope;
+
+    //-------------------------------------------------------------------------------------------
+    public ClasspathContainer( ArtifactScopeEnum scope )
+    {
+        this.scope = ArtifactScopeEnum.checkScope( scope );
+    }
+
+    //-------------------------------------------------------------------------------------------
+    public ClasspathContainer( List<ArtifactMetadata> classpath, ArtifactScopeEnum scope )
+    {
+        this( scope );
+        this.classpath = classpath;
+    }
+
+    //-------------------------------------------------------------------------------------------
+    public Iterator<ArtifactMetadata> iterator()
+    {
+        return classpath == null ? null : classpath.iterator();
+    }
+
+    //-------------------------------------------------------------------------------------------
+    public ClasspathContainer add( ArtifactMetadata md )
+    {
+        if ( classpath == null )
+        {
+            classpath = new ArrayList<ArtifactMetadata>( 16 );
+        }
+
+        classpath.add( md );
+
+        return this;
+    }
+
+    //-------------------------------------------------------------------------------------------
+    public List<ArtifactMetadata> getClasspath()
+    {
+        return classpath;
+    }
+
+    //-------------------------------------------------------------------------------------------
+    public MetadataTreeNode getClasspathAsTree()
+    {
+        if ( classpath == null || classpath.size() < 1 )
+            return null;
+
+        MetadataTreeNode tree = null;
+        MetadataTreeNode parent = null;
+        MetadataTreeNode node = null;
+
+        for ( ArtifactMetadata md : classpath )
+        {
+          // TODO Oleg: is null for query good here ??
+            node = new MetadataTreeNode( md, parent, null );
+            
+            if ( tree == null )
+            {
+                tree = node;
+            }
+
+            if ( parent != null )
+            {
+                parent.addChild( node );
+            }
+
+            parent = node;
+
+        }
+        return tree;
+    }
+
+    public void setClasspath( List<ArtifactMetadata> classpath )
+    {
+        this.classpath = classpath;
+    }
+
+    public ArtifactScopeEnum getScope()
+    {
+        return scope;
+    }
+
+    public void setScope( ArtifactScopeEnum scope )
+    {
+        this.scope = scope;
+    }
+
+    //-------------------------------------------------------------------------------------------
+    @Override
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder( 256 );
+        sb.append( "[scope=" + scope.getScope() );
+        if ( classpath != null )
+            for ( ArtifactMetadata md : classpath )
+            {
+                sb.append( ": " + md.toString() + '{' + md.getArtifactUri() + '}' );
+            }
+        sb.append( ']' );
+        return sb.toString();
+    }
+    //-------------------------------------------------------------------------------------------
+    //-------------------------------------------------------------------------------------------
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClasspathContainer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/ClasspathContainer.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyBuilder.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyBuilder.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyBuilder.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyBuilder.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,139 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.metadata;
+
+import java.util.List;
+
+import org.apache.maven.mercury.artifact.ArtifactExclusionList;
+import org.apache.maven.mercury.artifact.ArtifactInclusionList;
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.artifact.ArtifactQueryList;
+import org.apache.maven.mercury.artifact.ArtifactScopeEnum;
+import org.apache.maven.mercury.artifact.MetadataTreeNode;
+import org.apache.maven.mercury.artifact.api.Configurable;
+import org.apache.maven.mercury.event.MercuryEventListener;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public interface DependencyBuilder
+extends Configurable
+{
+  public static final String TREE_BUILD_EVENT = "tree.build";
+  public static final String TREE_NODE_BUILD_EVENT = "tree.node.build";
+  public static final String TREE_NODE_VERSION_REPLACE_EVENT = "tree.node.build.version.replace";
+
+  public static final String SYSTEM_PROPERTY_ALLOW_CIRCULAR_DEPENDENCIES = "mercury.circular.allow";
+
+  public static final String CONFIGURATION_PROPERTY_VERSION_MAP = "mercury.version.map";
+  //------------------------------------------------------------------------
+  /**
+   * build the tree, using the repositories specified in the
+   * constructor
+   * 
+   * @param startMD - root of the tree to build
+   * @param targetPlatform - limitations to use when retrieving metadata. Format is G:A=V, where V is Version Range
+   * @return the root of the tree built
+   * @throws MetadataTreeException
+   */
+  public abstract MetadataTreeNode buildTree( ArtifactMetadata startMD, ArtifactScopeEnum scope )
+  throws MetadataTreeException;
+
+  /**
+   * hard to believe, but this actually resolves the conflicts, removing all duplicate GAVs from the tree
+   * 
+   * @param root the tree to resolve conflicts on
+   * @return list of resolved GAVs
+   * @throws MetadataTreeException
+   */
+  public abstract List<ArtifactMetadata> resolveConflicts( MetadataTreeNode root )
+  throws MetadataTreeException;
+
+  /**
+   * consolidated entry point: give it a collection of GAVs, it 
+   * will create a classpath out of it
+   * 
+   * @param root the tree to resolve conflicts on
+   * @return list of resolved GAVs
+   * @throws MetadataTreeException
+   */
+  public abstract List<ArtifactMetadata> resolveConflicts( 
+                                          ArtifactScopeEnum   scope
+                                        , ArtifactQueryList artifacts
+                                        , ArtifactInclusionList inclusions
+                                        , ArtifactExclusionList exclusions
+                                        )
+
+  throws MetadataTreeException;
+
+  /**
+   * consolidated entry point: give it a collection of GAVs, it 
+   * will create a tree out of it
+   * 
+   * @param root the tree to resolve conflicts on
+   * @return resolved metadata tree
+   * @throws MetadataTreeException
+   */
+  public abstract MetadataTreeNode resolveConflictsAsTree( 
+                                          ArtifactScopeEnum   scope
+                                        , ArtifactQueryList artifacts
+                                        , ArtifactInclusionList inclusions
+                                        , ArtifactExclusionList exclusions
+                                        )
+
+  throws MetadataTreeException;
+
+  /**
+   *  this one resolves the conflicts, removing all duplicate GAVs from the tree and
+   *  returning a copy of the resulting subtree - original tree should be intact
+   * 
+   * @param root the tree to resolve conflicts on
+   * @return resolved subtree
+   * @throws MetadataTreeException
+   */
+  public abstract MetadataTreeNode resolveConflictsAsTree( MetadataTreeNode root )
+  throws MetadataTreeException;
+  
+  /**
+   * register a listener for dependency events 
+   * 
+   * @param listener
+   */
+  public abstract void register( MercuryEventListener listener );
+  
+  /**
+   * remove a listener 
+   * 
+   * @param listener
+   */
+  public abstract void unRegister( MercuryEventListener listener );
+  
+  /**
+   * release all resources 
+   * 
+   */
+  public abstract void close();
+  //-----------------------------------------------------
+  //-----------------------------------------------------
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyBuilderFactory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyBuilderFactory.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyBuilderFactory.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyBuilderFactory.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,100 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.metadata;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.mercury.artifact.MetadataTreeNode;
+import org.apache.maven.mercury.artifact.api.ArtifactListProcessor;
+import org.apache.maven.mercury.artifact.api.Configurable;
+import org.apache.maven.mercury.artifact.api.ConfigurationException;
+import org.apache.maven.mercury.artifact.api.ConfigurationUtil;
+import org.apache.maven.mercury.repository.api.Repository;
+import org.apache.maven.mercury.repository.api.RepositoryException;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class DependencyBuilderFactory
+{
+  public static final String JAVA_DEPENDENCY_MODEL = "java";
+  public static final String OSGI_DEPENDENCY_MODEL = "osgi";
+
+  private static final Language LANG = new DefaultLanguage( DependencyBuilderFactory.class);
+  
+  public static final DependencyBuilder create(
+        String dependencyModel
+      , Collection<Repository> repositories
+                     )
+  throws RepositoryException
+  {
+      return create( dependencyModel, repositories, null, null, null );
+  }
+  
+  public static final DependencyBuilder create(
+        String dependencyModel
+      , Collection<Repository> repositories
+      , Collection<MetadataTreeArtifactFilter> filters
+      , List<Comparator<MetadataTreeNode>> comparators
+      , Map<String,ArtifactListProcessor> processors
+                     )
+  throws RepositoryException
+  {
+      return create( dependencyModel, repositories, null, null, null, null );
+  }
+  
+  public static final DependencyBuilder create(
+        String dependencyModel
+      , Collection<Repository> repositories
+      , Collection<MetadataTreeArtifactFilter> filters
+      , List<Comparator<MetadataTreeNode>> comparators
+      , Map<String,ArtifactListProcessor> processors
+      , Map<String,Object> config 
+                     )
+  throws RepositoryException
+  {
+    if( JAVA_DEPENDENCY_MODEL.equals( dependencyModel ) )
+    {
+        DependencyBuilder db = new DependencyTreeBuilder( repositories,  filters, comparators, processors );
+        
+        try
+        {
+            ConfigurationUtil.configure( db, config );
+        }
+        catch ( ConfigurationException e )
+        {
+            throw new RepositoryException( e );
+        }
+        
+        return db;
+    }
+    
+    throw new IllegalArgumentException( LANG.getMessage( "dependency.model.not.implemented", dependencyModel ) );
+  }
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyBuilderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyBuilderFactory.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,730 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.metadata;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.mercury.artifact.ArtifactExclusionList;
+import org.apache.maven.mercury.artifact.ArtifactInclusionList;
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.artifact.ArtifactQueryList;
+import org.apache.maven.mercury.artifact.ArtifactScopeEnum;
+import org.apache.maven.mercury.artifact.MetadataTreeNode;
+import org.apache.maven.mercury.artifact.api.ArtifactListProcessor;
+import org.apache.maven.mercury.artifact.api.ConfigurationException;
+import org.apache.maven.mercury.artifact.version.VersionException;
+import org.apache.maven.mercury.event.EventGenerator;
+import org.apache.maven.mercury.event.EventManager;
+import org.apache.maven.mercury.event.EventTypeEnum;
+import org.apache.maven.mercury.event.GenericEvent;
+import org.apache.maven.mercury.event.MercuryEventListener;
+import org.apache.maven.mercury.logging.IMercuryLogger;
+import org.apache.maven.mercury.logging.MercuryLoggerManager;
+import org.apache.maven.mercury.metadata.sat.DefaultSatSolver;
+import org.apache.maven.mercury.metadata.sat.SatException;
+import org.apache.maven.mercury.repository.api.MetadataResults;
+import org.apache.maven.mercury.repository.api.Repository;
+import org.apache.maven.mercury.repository.api.RepositoryException;
+import org.apache.maven.mercury.repository.virtual.VirtualRepositoryReader;
+import org.apache.maven.mercury.util.Util;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * This is the new entry point into Artifact resolution process.
+ * 
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+class DependencyTreeBuilder
+    implements DependencyBuilder, EventGenerator
+{
+    public static final ArtifactMetadata DUMMY_ROOT = new ArtifactMetadata( "__fake:__fake:1.0" );
+
+    private static final Language LANG = new DefaultLanguage( DependencyTreeBuilder.class );
+    
+    public static final String SYSTEM_PROPERTY_DUMP_DEPENDENCY_TREE = "mercury.dump.tree";
+    
+    private static final String _depTreeDumpFileName = System.getProperty( SYSTEM_PROPERTY_DUMP_DEPENDENCY_TREE );
+
+    private static final boolean _dumpDepTree = _depTreeDumpFileName != null;
+    
+    private static final DependencyTreeDumper _dumper = _dumpDepTree ? new DependencyTreeDumper(_depTreeDumpFileName ) : null;
+    
+    private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( DependencyTreeBuilder.class );
+
+    private Collection<MetadataTreeArtifactFilter> _filters;
+
+    private List<Comparator<MetadataTreeNode>> _comparators;
+
+    private Map<String, ArtifactListProcessor> _processors;
+
+    private VirtualRepositoryReader _reader;
+
+    private Map<String, MetadataTreeNode> _existingNodes;
+
+    private EventManager _eventManager;
+    
+    private boolean _buildIndividualTrees = true;
+    
+    private boolean _allowCircularDependencies = Boolean.parseBoolean( System.getProperty( SYSTEM_PROPERTY_ALLOW_CIRCULAR_DEPENDENCIES, "false" ) );
+    
+    /** mandated versions in the format G:A -> V */
+    private Map<String, ArtifactMetadata> _versionMap;
+    
+    class TruckLoad
+    {
+        List<ArtifactMetadata> cp;
+        MetadataTreeNode root;
+        
+        public TruckLoad()
+        {
+        }
+        
+        public TruckLoad( List<ArtifactMetadata> cp )
+        {
+            this.cp = cp;
+        }
+        
+        public TruckLoad( MetadataTreeNode root )
+        {
+            this.root = root;
+        }
+    }
+
+    /**
+     * creates an instance of MetadataTree. Use this instance to
+     * <ul>
+     * <li>buildTree - process all the dependencies</li>
+     * <li>resolveConflicts</li>
+     * <ul>
+     * 
+     * @param filters - can veto any artifact before it's added to the tree
+     * @param comparators - used to define selection policies. If null is passed, classic comparators - nearest/newest
+     *            first - will be used.
+     * @param repositories - order is <b>very</b> important. Ordering allows m2eclipse, for instance, insert a workspace
+     *            repository
+     * @throws RepositoryException
+     */
+    protected DependencyTreeBuilder( Collection<Repository> repositories,
+                                     Collection<MetadataTreeArtifactFilter> filters,
+                                     List<Comparator<MetadataTreeNode>> comparators,
+                                     Map<String, ArtifactListProcessor> processors )
+        throws RepositoryException
+    {
+        this._filters = filters;
+        this._comparators = comparators;
+
+        // if used does not want to bother.
+        // if it's an empty list - user does not want any comparators - so be it
+        if ( _comparators == null )
+        {
+            _comparators = new ArrayList<Comparator<MetadataTreeNode>>( 2 );
+            _comparators.add( new ClassicDepthComparator() );
+            _comparators.add( new ClassicVersionComparator() );
+        }
+
+        if ( processors != null )
+            _processors = processors;
+
+        this._reader = new VirtualRepositoryReader( repositories );
+    }
+
+    // ------------------------------------------------------------------------
+    public MetadataTreeNode buildTree( ArtifactMetadata startMD, ArtifactScopeEnum treeScope )
+        throws MetadataTreeException
+    {
+        if ( startMD == null )
+            throw new MetadataTreeException( "null start point" );
+
+        try
+        {
+            _reader.setEventManager( _eventManager );
+            _reader.setProcessors( _processors );
+            _reader.init();
+        }
+        catch ( RepositoryException e )
+        {
+            throw new MetadataTreeException( e );
+        }
+
+        _existingNodes = new HashMap<String, MetadataTreeNode>( 256 );
+
+        GenericEvent treeBuildEvent = null;
+        if ( _eventManager != null )
+            treeBuildEvent = new GenericEvent( EventTypeEnum.dependencyBuilder, TREE_BUILD_EVENT, startMD.getGAV() );
+
+        MetadataTreeNode root = createNode( startMD, null, startMD, treeScope );
+
+        if ( _eventManager != null )
+            treeBuildEvent.stop();
+
+        if ( _eventManager != null )
+            _eventManager.fireEvent( treeBuildEvent );
+
+        MetadataTreeNode.reNumber( root, 1 );
+
+        return root;
+    }
+
+    // ------------------------------------------------------------------------
+    public List<ArtifactMetadata> resolveConflicts( 
+                                        ArtifactScopeEnum     scope
+                                      , ArtifactQueryList     artifacts
+                                      , ArtifactInclusionList inclusions
+                                      , ArtifactExclusionList exclusions
+                                                  )
+    throws MetadataTreeException
+    {
+        TruckLoad tl = resolveConflictsInternally( scope, artifacts, inclusions, exclusions, false );
+        
+        return tl == null ? null : tl.cp;
+    }
+    // ------------------------------------------------------------------------
+    public MetadataTreeNode resolveConflictsAsTree( 
+                                        ArtifactScopeEnum     scope
+                                      , ArtifactQueryList     artifacts
+                                      , ArtifactInclusionList inclusions
+                                      , ArtifactExclusionList exclusions
+                                                  )
+    throws MetadataTreeException
+    {
+        TruckLoad tl = resolveConflictsInternally( scope, artifacts, inclusions, exclusions, true );
+        
+        return tl == null ? null : tl.root;
+    }
+    // ------------------------------------------------------------------------
+    public TruckLoad resolveConflictsInternally( 
+                                        ArtifactScopeEnum     scope
+                                      , ArtifactQueryList     artifacts
+                                      , ArtifactInclusionList inclusions
+                                      , ArtifactExclusionList exclusions
+                                      , boolean asTree
+                                                  )
+
+    throws MetadataTreeException
+    {
+        if ( artifacts == null )
+            throw new MetadataTreeException( LANG.getMessage( "empty.md.collection" ) );
+
+        List<ArtifactMetadata> startMDs = artifacts.getMetadataList();
+        
+        if ( Util.isEmpty( startMDs ) )
+            throw new MetadataTreeException( LANG.getMessage( "empty.md.collection" ) );
+
+        int nodeCount = startMDs.size();
+
+        if ( nodeCount == 1 && inclusions == null && exclusions == null )
+        {
+            ArtifactMetadata bmd = startMDs.get( 0 );
+            MetadataTreeNode rooty = buildTree( bmd, scope );
+
+            TruckLoad tl = null;
+            
+            if( asTree )
+            {
+                MetadataTreeNode tr = resolveConflictsAsTree( rooty );
+                
+                tl = new TruckLoad( tr );
+            }
+            else
+            {
+                List<ArtifactMetadata> res = resolveConflicts( rooty );
+                
+                tl = new TruckLoad( res );
+    
+                if(_dumpDepTree )
+                    _dumper.dump( scope, artifacts, inclusions, exclusions, rooty, res );
+            }
+
+            return tl;
+        }
+
+        DUMMY_ROOT.setDependencies( startMDs );
+        DUMMY_ROOT.setInclusions( inclusions == null ? null : inclusions.getMetadataList() );
+        DUMMY_ROOT.setExclusions( exclusions == null ? null : exclusions.getMetadataList() );
+        
+        MetadataTreeNode root = null;
+        
+        if( _buildIndividualTrees )
+        {
+            List<MetadataTreeNode> deps = new ArrayList<MetadataTreeNode>( nodeCount );
+           
+            for ( ArtifactMetadata bmd : startMDs )
+            {
+                if( scope != null && !scope.encloses( bmd.getArtifactScope() ) )
+                    continue;
+                
+                try
+                {
+                    if( ! DUMMY_ROOT.allowDependency( bmd ) )
+                        continue;
+                }
+                catch ( VersionException e )
+                {
+                    throw new MetadataTreeException(e);
+                }
+           
+                if( inclusions != null )
+                {
+                    List<ArtifactMetadata> inc = inclusions.getMetadataList();
+                    
+                    if( bmd.hasInclusions() )
+                        bmd.getInclusions().addAll( inc );
+                    else
+                        bmd.setInclusions( inc );
+                }
+    
+                if( exclusions != null )
+                {
+                    List<ArtifactMetadata> excl = exclusions.getMetadataList();
+                    
+                    if( bmd.hasExclusions() )
+                        bmd.getExclusions().addAll( excl );
+                    else
+                        bmd.setExclusions( excl );
+                }
+                
+                MetadataTreeNode rooty = buildTree( bmd, scope );
+    
+                deps.add( rooty );
+            }
+            
+            if( Util.isEmpty( deps ) ) // all dependencies are filtered out 
+                return null;
+    
+            // combine into one tree
+            root = new MetadataTreeNode( DUMMY_ROOT, null, null );
+    
+            for ( MetadataTreeNode kid : deps )
+                root.addChild( kid );
+    
+        }
+        else
+        {
+            DUMMY_ROOT.setDependencies( startMDs );
+            root = buildTree( DUMMY_ROOT, scope );
+        }
+        
+        
+        TruckLoad tl = null;
+        
+        if( asTree )
+        {
+            MetadataTreeNode tr = resolveConflictsAsTree( root );
+            
+            tl = new TruckLoad( tr );
+        }
+        else
+        {
+            List<ArtifactMetadata> cp = resolveConflicts( root ); 
+
+            if( cp != null )
+                cp.remove( DUMMY_ROOT );
+    
+                if(_dumpDepTree )
+                    _dumper.dump( scope, artifacts, inclusions, exclusions, root, cp );
+                
+                tl = new TruckLoad( cp );
+        }
+
+        return tl;
+    }
+    // -----------------------------------------------------
+    private MetadataTreeNode createNode( ArtifactMetadata nodeMD, MetadataTreeNode parent
+                                         , ArtifactMetadata nodeQuery, ArtifactScopeEnum globalScope
+                                       )
+        throws MetadataTreeException
+    {
+        GenericEvent nodeBuildEvent = null;
+
+        if ( _eventManager != null )
+            nodeBuildEvent = new GenericEvent( EventTypeEnum.dependencyBuilder, TREE_NODE_BUILD_EVENT, nodeMD.getGAV() );
+
+        try
+        {
+            try
+            {
+                checkForCircularDependency( nodeMD, parent );
+            }
+            catch ( MetadataTreeCircularDependencyException e )
+            {
+                if( _allowCircularDependencies )
+                {
+                    String line = LANG.getMessage( "attention.line" );
+                    LOG.info( line + e.getMessage() + line );
+                    return null;
+                }
+                else
+                    throw e;
+            }
+
+            ArtifactMetadata mr;
+
+            MetadataTreeNode existingNode = _existingNodes.get( nodeQuery.toString() );
+
+            if ( existingNode != null )
+                return MetadataTreeNode.deepCopy( existingNode );
+
+            if( DUMMY_ROOT.equals( nodeMD ))
+                mr = DUMMY_ROOT;
+            else
+                mr = _reader.readDependencies( nodeMD );
+
+            if ( mr == null )
+                throw new MetadataTreeException( LANG.getMessage( "artifact.md.not.found", nodeMD.toString() ) );
+
+            MetadataTreeNode node = new MetadataTreeNode( mr, parent, nodeQuery );
+
+            List<ArtifactMetadata> allDependencies = mr.getDependencies();
+
+            if ( allDependencies == null || allDependencies.size() < 1 )
+                return node;
+            
+            if( !Util.isEmpty( _versionMap ) )
+                for( ArtifactMetadata am :  allDependencies )
+                {
+                    String key = am.toManagementString();
+                    ArtifactMetadata ver = _versionMap.get( key );
+                    if( ver != null )
+                    {
+                        if( LOG.isDebugEnabled() )
+                            LOG.debug( "managed replacement: "+am+" -> "+ver );
+                        
+                        if ( _eventManager != null )
+                        {
+                            GenericEvent replaceEvent = new GenericEvent( EventTypeEnum.dependencyBuilder, TREE_NODE_VERSION_REPLACE_EVENT, "managed replacement: "+am+" -> "+ver );
+                            replaceEvent.stop();
+                            _eventManager.fireEvent( replaceEvent );
+                        }
+ 
+                        am.setVersion( ver.getVersion() );
+                        am.setInclusions( ver.getInclusions() );
+                        am.setExclusions( ver.getExclusions() );
+                        am.setOptional( ver.isOptional() );
+                    }
+                }
+
+            List<ArtifactMetadata> dependencies = new ArrayList<ArtifactMetadata>( allDependencies.size() );
+            if ( globalScope != null )
+                for ( ArtifactMetadata md : allDependencies )
+                {
+                    ArtifactScopeEnum mdScope = md.getArtifactScope();
+                    if ( globalScope.encloses( mdScope ) )
+                        dependencies.add( md );
+                }
+            else
+                dependencies.addAll( allDependencies );
+
+            if ( Util.isEmpty( dependencies ) )
+                return node;
+
+            MetadataResults res = _reader.readVersions( dependencies );
+            
+            if( res == null )
+                throw new MetadataTreeException( LANG.getMessage( "no.versions", dependencies.toString() ) );
+
+            Map<ArtifactMetadata, List<ArtifactMetadata>> expandedDeps = res.getResults();
+
+            for ( ArtifactMetadata md : dependencies )
+            {
+
+                if ( LOG.isDebugEnabled() )
+                    LOG.debug( "node " + nodeQuery + ", dep " + md );
+
+                List<ArtifactMetadata> versions = expandedDeps.get( md );
+                if ( versions == null || versions.size() < 1 )
+                {
+                    if ( md.isOptional() || checkOptional( node) )
+                        continue;
+
+                    throw new MetadataTreeException( LANG.getMessage( "not.optional.missing" ) + md + " <== "+ showPath( node ) );
+                }
+
+                boolean noVersions = true;
+                boolean noGoodVersions = true;
+
+                for ( ArtifactMetadata ver : versions )
+                {
+                    if ( veto( ver, _filters ) || vetoInclusionsExclusions( node, ver ) )
+                    {
+                        // there were good versions, but this one is filtered out
+                        noGoodVersions = false;
+                        continue;
+                    }
+
+                    MetadataTreeNode kid = createNode( ver, node, md, globalScope );
+                    if( kid != null )
+                        node.addChild( kid );
+
+                    noVersions = false;
+
+                    noGoodVersions = false;
+                }
+
+                if ( noVersions && !noGoodVersions )
+                {
+                    // there were good versions, but they were all filtered out
+                    continue;
+                }
+                else if ( noGoodVersions )
+                {
+                    if ( md.isOptional() )
+                        continue;
+                    
+                    throw new MetadataTreeException( LANG.getMessage( "not.optional.missing" ) + md + " <== "+ showPath( node ) );
+                }
+                else
+                    node.addQuery( md );
+            }
+
+            _existingNodes.put( nodeQuery.toString(), node );
+
+            return node;
+        }
+        catch ( RepositoryException e )
+        {
+            if ( _eventManager != null )
+                nodeBuildEvent.setResult( e.getMessage() );
+
+            throw new MetadataTreeException( e );
+        }
+        catch ( VersionException e )
+        {
+            if ( _eventManager != null )
+                nodeBuildEvent.setResult( e.getMessage() );
+
+            throw new MetadataTreeException( e );
+        }
+        catch ( MetadataTreeException e )
+        {
+            if ( _eventManager != null )
+                nodeBuildEvent.setResult( e.getMessage() );
+            throw e;
+        }
+        finally
+        {
+            if ( _eventManager != null )
+            {
+                nodeBuildEvent.stop();
+                _eventManager.fireEvent( nodeBuildEvent );
+            }
+        }
+    }
+
+    // -----------------------------------------------------
+    private void checkForCircularDependency( ArtifactMetadata md, MetadataTreeNode parent )
+        throws MetadataTreeCircularDependencyException
+    {
+        MetadataTreeNode p = parent;
+        int count = 0;
+        while ( p != null )
+        {
+            count++;
+            // System.out.println("circ "+md+" vs "+p.md);
+            if ( md.sameGA( p.getMd() ) )
+            {
+                p = parent;
+                StringBuilder sb = new StringBuilder( 128 );
+                sb.append( md.toString() );
+                while ( p != null )
+                {
+                    sb.append( " <- " + p.getMd().toString() );
+
+                    if ( md.sameGA( p.getMd() ) )
+                    {
+                        throw new MetadataTreeCircularDependencyException( "circular dependency " + count
+                            + " levels up. " + sb.toString() + " <= " + ( p.getParent() == null ? "no parent" : p.getParent().getMd() ) );
+                    }
+                    p = p.getParent();
+                }
+            }
+            p = p.getParent();
+        }
+    }
+
+    // -----------------------------------------------------
+    private boolean veto( ArtifactMetadata md, Collection<MetadataTreeArtifactFilter> filters )
+    {
+        if ( filters != null && filters.size() > 1 )
+            for ( MetadataTreeArtifactFilter filter : filters )
+                if ( filter.veto( md ) )
+                    return true;
+        return false;
+    }
+
+    // -----------------------------------------------------
+    private boolean vetoInclusionsExclusions( MetadataTreeNode node, ArtifactMetadata ver )
+        throws VersionException
+    {
+        for ( MetadataTreeNode n = node; n != null; n = n.getParent() )
+        {
+            ArtifactMetadata md = n.getQuery();
+
+            if ( !md.allowDependency( ver ) ) // veto it
+                return true;
+        }
+        return false; // allow because all parents are OK with it
+    }
+
+    // -----------------------------------------------------
+    public List<ArtifactMetadata> resolveConflicts( MetadataTreeNode root )
+        throws MetadataTreeException
+    {
+        if ( root == null )
+            throw new MetadataTreeException( LANG.getMessage( "empty.tree" ) );
+        
+        root.createNames( 0, 0 );
+
+        try
+        {
+            DefaultSatSolver solver = new DefaultSatSolver( root, _eventManager );
+
+            solver.applyPolicies( getComparators() );
+
+            List<ArtifactMetadata> res = solver.solve();
+
+            return res;
+        }
+        catch ( SatException e )
+        {
+            throw new MetadataTreeException( e );
+        }
+
+    }
+
+    // -----------------------------------------------------
+    public MetadataTreeNode resolveConflictsAsTree( MetadataTreeNode root )
+        throws MetadataTreeException
+    {
+        if ( root == null )
+            throw new MetadataTreeException( LANG.getMessage( "empty.tree" ) );
+
+        try
+        {
+            DefaultSatSolver solver = new DefaultSatSolver( root, _eventManager );
+
+            solver.applyPolicies( getComparators() );
+
+            MetadataTreeNode res = solver.solveAsTree();
+
+            return res;
+        }
+        catch ( SatException e )
+        {
+            throw new MetadataTreeException( e );
+        }
+
+    }
+
+    // -----------------------------------------------------
+    private List<Comparator<MetadataTreeNode>> getComparators()
+    {
+        if ( Util.isEmpty( _comparators ) )
+            _comparators = new ArrayList<Comparator<MetadataTreeNode>>( 2 );
+
+        if ( _comparators.size() < 1 )
+        {
+            _comparators.add( new ClassicDepthComparator() );
+            _comparators.add( new ClassicVersionComparator() );
+        }
+
+        return _comparators;
+    }
+
+    // -----------------------------------------------------
+    private boolean checkOptional( MetadataTreeNode node )
+    {
+        MetadataTreeNode p = node;
+
+        while ( p != null )
+        {
+            if( p.getMd() != null && p.getMd().isOptional() )
+                return true;
+            
+            p = p.getParent();
+        }
+
+        return false;
+    }
+    // -----------------------------------------------------
+    private String showPath( MetadataTreeNode node )
+    {
+        StringBuilder sb = new StringBuilder( 256 );
+
+        String comma = "";
+
+        MetadataTreeNode p = node;
+
+        while ( p != null )
+        {
+            sb.append( comma + p.getMd().toString() );
+
+            comma = " <== ";
+
+            p = p.getParent();
+        }
+
+        return sb.toString();
+    }
+
+    public void register( MercuryEventListener listener )
+    {
+        if ( _eventManager == null )
+            _eventManager = new EventManager();
+
+        _eventManager.register( listener );
+    }
+
+    public void unRegister( MercuryEventListener listener )
+    {
+        if ( _eventManager != null )
+            _eventManager.unRegister( listener );
+    }
+
+    public void setEventManager( EventManager eventManager )
+    {
+        if ( _eventManager == null )
+            _eventManager = eventManager;
+        else
+            _eventManager.getListeners().addAll( eventManager.getListeners() );
+
+    }
+    
+    public void close()
+    {
+        if( _reader != null )
+            _reader.close();
+    }
+
+    @SuppressWarnings("unchecked")
+    public void setOption( String name, Object val )
+        throws ConfigurationException
+    {
+        if( SYSTEM_PROPERTY_ALLOW_CIRCULAR_DEPENDENCIES.equals( name ) )
+            _allowCircularDependencies = Boolean.parseBoolean( (String)val );
+        else if( CONFIGURATION_PROPERTY_VERSION_MAP.equals( name ) )
+            _versionMap = (Map<String, ArtifactMetadata>) val;
+    }
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision