Author: mkleint
Date: Wed Nov 21 09:49:21 2007
New Revision: 597160

URL: http://svn.apache.org/viewvc?rev=597160&view=rev
Log:
rewrite toolchains to use MavenSession plugin context instead of build-context 
artifact.

Modified:
    maven/shared/trunk/maven-toolchain/pom.xml
    
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java
    
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/DefaultToolchainManager.java
    
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/Toolchain.java
    
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainFactory.java
    
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainManager.java
    
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainManagerPrivate.java
    
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainPrivate.java
    
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolChain.java
    
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolchainFactory.java

Modified: maven/shared/trunk/maven-toolchain/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-toolchain/pom.xml?rev=597160&r1=597159&r2=597160&view=diff
==============================================================================
--- maven/shared/trunk/maven-toolchain/pom.xml (original)
+++ maven/shared/trunk/maven-toolchain/pom.xml Wed Nov 21 09:49:21 2007
@@ -19,7 +19,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.maven</groupId>
-            <artifactId>maven-build-context</artifactId>
+            <artifactId>maven-core</artifactId>
             <version>2.1-SNAPSHOT</version>
         </dependency>
         <dependency>

Modified: 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java?rev=597160&r1=597159&r2=597160&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java
 (original)
+++ 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/DefaultToolchain.java
 Wed Nov 21 09:49:21 2007
@@ -21,6 +21,7 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import org.apache.maven.toolchain.model.ToolchainModel;
 
 /**
  *
@@ -35,13 +36,17 @@
     private Map provides = new HashMap /*<String,RequirementMatcher>*/ (  );
 
     public static final String KEY_TYPE = "type"; //NOI18N
+    
+    private ToolchainModel model;
 
-    protected DefaultToolchain( )
+    protected DefaultToolchain( ToolchainModel model ) 
     {
+        this.model = model;
     }
 
-    protected DefaultToolchain( String type )
+    protected DefaultToolchain( ToolchainModel model, String type )
     {
+        this(model);
         this.type = type;
     }
 
@@ -50,22 +55,10 @@
         return type;
     }
 
-    public final String getStorageKey( )
+    
+    public final ToolchainModel getModel( ) 
     {
-        return "toolchain-" + type; //NOI18N
-    }
-
-    public Map getData( )
-    {
-        Map data = new HashMap( 2 );
-        data.put( KEY_TYPE, type );
-
-        return data;
-    }
-
-    public void setData( Map data )
-    {
-        type = (String) data.get( KEY_TYPE );
+        return model;
     }
 
     public final void addProvideToken( String type,

Modified: 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/DefaultToolchainManager.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/DefaultToolchainManager.java?rev=597160&r1=597159&r2=597160&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/DefaultToolchainManager.java
 (original)
+++ 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/DefaultToolchainManager.java
 Wed Nov 21 09:49:21 2007
@@ -27,7 +27,8 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import org.apache.maven.context.BuildContext;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.toolchain.model.PersistedToolchains;
 import org.apache.maven.toolchain.model.ToolchainModel;
 import org.apache.maven.toolchain.model.io.xpp3.MavenToolchainsXpp3Reader;
@@ -70,7 +71,7 @@
     {
         try
         {
-            PersistedToolchains pers = readToolchainSettings();
+            PersistedToolchains pers = readToolchainSettings ();
             Map factories = container.lookupMap( ToolchainFactory.ROLE );
             List toRet = new ArrayList(  );
             if ( pers != null )
@@ -82,7 +83,7 @@
                     while ( it.hasNext() )
                     {
                         ToolchainModel toolchainModel = (ToolchainModel) 
it.next();
-                        ToolchainFactory fact = (ToolchainFactory) 
factories.get(toolchainModel.getType());
+                        ToolchainFactory fact = (ToolchainFactory) 
factories.get( toolchainModel.getType() );
                         if ( fact != null )
                         {
                             toRet.add( fact.createToolchain( toolchainModel ) 
);
@@ -104,7 +105,7 @@
                     toRet.add( tool );
                 }
             }
-            ToolchainPrivate[] tc = new ToolchainPrivate[toRet.size(  )];
+            ToolchainPrivate[] tc = new ToolchainPrivate[ toRet.size() ];
             return (ToolchainPrivate[]) toRet.toArray(tc);
         }
         catch ( ComponentLookupException ex )
@@ -115,34 +116,58 @@
     }
 
     public Toolchain getToolchainFromBuildContext( String type,
-                                                   BuildContext context )
+                                                   MavenSession session )
     {
-        try
+        Map context = retrieveContext(session);
+        if ( "javac".equals( type )) 
         {
-            ToolchainFactory fact = (ToolchainFactory) 
container.lookup(ToolchainFactory.ROLE, type);
-            Toolchain dt = fact.createToolchain( context );
-            if ( dt != null )
-            {
-                return dt;
-            }
-            return null;
+            //HACK to make compiler plugin happy
+            type = "jdk";
         }
-        catch ( ComponentLookupException ex )
+        Object obj = context.get( getStorageKey( type ) );
+        ToolchainModel model = (ToolchainModel)obj;
+        
+        if ( model != null ) 
         {
-            getLogger().fatalError("Error in component lookup", ex);
-        }
-        catch ( MisconfiguredToolchainException ex )
-        {
-            getLogger().error("Misconfigured toolchain.", ex);
+            try
+            {
+                ToolchainFactory fact = (ToolchainFactory) 
container.lookup(ToolchainFactory.ROLE, type);
+                return fact.createToolchain( model );
+            }
+            catch ( ComponentLookupException ex )
+            {
+                getLogger().fatalError("Error in component lookup", ex);
+            }
+            catch ( MisconfiguredToolchainException ex )
+            {
+                getLogger().error("Misconfigured toolchain.", ex);
+            }
         }
         return null;
     }
+    
+    private Map retrieveContext( MavenSession session ) 
+    {
+        PluginDescriptor desc = new PluginDescriptor();
+        desc.setGroupId( PluginDescriptor.getDefaultPluginGroupId() );
+        desc.setArtifactId( PluginDescriptor.getDefaultPluginArtifactId 
("toolchains") );
+        
+        return  session.getPluginContext( desc, session.getCurrentProject() );
+        
+    }
 
     public void storeToolchainToBuildContext( ToolchainPrivate toolchain,
-                                              BuildContext context )
+                                              MavenSession session )
+    {
+        Map context = retrieveContext( session );
+        context.put( getStorageKey( toolchain.getType() ), toolchain.getModel 
() );
+    }
+    
+    public static final String getStorageKey( String type )
     {
-        context.store( toolchain );
+        return "toolchain-" + type; //NOI18N
     }
+    
 
     private PersistedToolchains readToolchainSettings( )
         throws MisconfiguredToolchainException

Modified: 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/Toolchain.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/Toolchain.java?rev=597160&r1=597159&r2=597160&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/Toolchain.java
 (original)
+++ 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/Toolchain.java
 Wed Nov 21 09:49:21 2007
@@ -19,14 +19,12 @@
 
 package org.apache.maven.toolchain;
 
-import org.apache.maven.context.ManagedBuildData;
 
 /**
  * @author Milos Kleint
  * @author Jason van Zyl
  */
 public interface Toolchain
-    extends ManagedBuildData
 {
 
     String getType( );

Modified: 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainFactory.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainFactory.java?rev=597160&r1=597159&r2=597160&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainFactory.java
 (original)
+++ 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainFactory.java
 Wed Nov 21 09:49:21 2007
@@ -19,7 +19,6 @@
 
 package org.apache.maven.toolchain;
 
-import org.apache.maven.context.BuildContext;
 import org.apache.maven.toolchain.model.ToolchainModel;
 
 /**
@@ -29,10 +28,7 @@
 public interface ToolchainFactory
 {
 
-    String ROLE = ToolchainFactory.class.getName(  );
-
-    Toolchain createToolchain( BuildContext context )
-        throws MisconfiguredToolchainException;
+    String ROLE = ToolchainFactory.class.getName();
 
     /**
      * Create instance of toolchain.

Modified: 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainManager.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainManager.java?rev=597160&r1=597159&r2=597160&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainManager.java
 (original)
+++ 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainManager.java
 Wed Nov 21 09:49:21 2007
@@ -19,7 +19,8 @@
 
 package org.apache.maven.toolchain;
 
-import org.apache.maven.context.BuildContext;
+import org.apache.maven.execution.MavenSession;
+
 
 /**
  *
@@ -35,6 +36,6 @@
      * to be used from plugins capable of working with toolchains.
      */
     Toolchain getToolchainFromBuildContext( String type,
-                                            BuildContext context );
+                                            MavenSession context );
 
 }

Modified: 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainManagerPrivate.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainManagerPrivate.java?rev=597160&r1=597159&r2=597160&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainManagerPrivate.java
 (original)
+++ 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainManagerPrivate.java
 Wed Nov 21 09:49:21 2007
@@ -20,7 +20,8 @@
 
 package org.apache.maven.toolchain;
 
-import org.apache.maven.context.BuildContext;
+import org.apache.maven.execution.MavenSession;
+
 
 /**
  * Component for use by the maven-toolchains-plugin only.
@@ -40,6 +41,6 @@
      * Stores the toolchain into build context.
      */
     void storeToolchainToBuildContext( ToolchainPrivate toolchain,
-                                       BuildContext context );
+                                       MavenSession context );
     
 }

Modified: 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainPrivate.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainPrivate.java?rev=597160&r1=597159&r2=597160&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainPrivate.java
 (original)
+++ 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/ToolchainPrivate.java
 Wed Nov 21 09:49:21 2007
@@ -20,6 +20,7 @@
 package org.apache.maven.toolchain;
 
 import java.util.Map;
+import org.apache.maven.toolchain.model.ToolchainModel;
 
 /**
  * a private contract between the toolchains plugin and the components.
@@ -30,4 +31,7 @@
 {
 
     Map getRequirementMatchers( );
+    
+    ToolchainModel getModel( );
+    
 }

Modified: 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolChain.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolChain.java?rev=597160&r1=597159&r2=597160&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolChain.java
 (original)
+++ 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolChain.java
 Wed Nov 21 09:49:21 2007
@@ -22,6 +22,7 @@
 import java.io.File;
 import java.util.Map;
 import org.apache.maven.toolchain.DefaultToolchain;
+import org.apache.maven.toolchain.model.ToolchainModel;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.Os;
 import org.codehaus.plexus.util.Os;
@@ -38,9 +39,9 @@
 
     public static final String KEY_JAVAHOME = "jdkHome"; //NOI18N
 
-    public DefaultJavaToolChain( )
+    public DefaultJavaToolChain( ToolchainModel model)
     {
-        super( "jdk" );
+        super( model, "jdk" );
     }
 
     public String getJavaHome( )
@@ -69,18 +70,6 @@
         return null;
     }
 
-    public Map getData( )
-    {
-        Map map = super.getData(  );
-        map.put( KEY_JAVAHOME, javaHome );
-        return map;
-    }
-
-    public void setData( Map data )
-    {
-        super.setData( data );
-        javaHome = (String) data.get(KEY_JAVAHOME);
-    }
 
     private static File findTool( String toolName, File installFolder )
     {

Modified: 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolchainFactory.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolchainFactory.java?rev=597160&r1=597159&r2=597160&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolchainFactory.java
 (original)
+++ 
maven/shared/trunk/maven-toolchain/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolchainFactory.java
 Wed Nov 21 09:49:21 2007
@@ -20,7 +20,7 @@
 package org.apache.maven.toolchain.java;
 
 import java.io.File;
-import org.apache.maven.context.BuildContext;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.toolchain.MisconfiguredToolchainException;
 import org.apache.maven.toolchain.RequirementMatcherFactory;
 import org.apache.maven.toolchain.Toolchain;
@@ -45,7 +45,10 @@
     public ToolchainPrivate createToolchain( ToolchainModel model )
         throws MisconfiguredToolchainException
     {
-        DefaultJavaToolChain jtc = new DefaultJavaToolChain(  );
+        if (model == null) {
+            return null;
+        }
+        DefaultJavaToolChain jtc = new DefaultJavaToolChain( model );
         Xpp3Dom dom = (Xpp3Dom) model.getConfiguration();
         Xpp3Dom javahome = dom.getChild( DefaultJavaToolChain.KEY_JAVAHOME );
         if ( javahome == null )
@@ -92,18 +95,6 @@
     {
         //not sure it's necessary to provide a default toolchain here.
         //only version can be eventually supplied, and 
-        return null;
-    }
-
-    public Toolchain createToolchain( BuildContext context )
-        throws MisconfiguredToolchainException
-    {
-        DefaultJavaToolChain jtc = new DefaultJavaToolChain();
-        boolean retrieve = context.retrieve( jtc );
-        if ( retrieve )
-        {
-            return jtc;
-        }
         return null;
     }
 }


Reply via email to