KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > script > beanshell > BeanshellMojoAdapter


1 package org.apache.maven.script.beanshell;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import bsh.EvalError;
20 import bsh.Interpreter;
21 import org.apache.maven.plugin.AbstractMojo;
22 import org.apache.maven.plugin.Mojo;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.plugin.MojoFailureException;
25 import org.codehaus.plexus.component.factory.bsh.BshComponent;
26
27 /**
28  * Mojo adapter for a Beanshell Mojo.
29  *
30  * @todo should log be passed in, or rely on getLog() ?
31  *
32  * @author <a HREF="mailto:brett@apache.org">Brett Porter</a>
33  * @version $Id: BeanshellMojoAdapter.java 293233 2005-10-03 04:24:11Z brett $
34  */

35 public class BeanshellMojoAdapter
36     extends AbstractMojo
37     implements BshComponent
38 {
39     private Mojo mojo;
40
41     private Interpreter interpreter;
42
43     public BeanshellMojoAdapter( Mojo mojo, Interpreter interpreter )
44     {
45         this.mojo = mojo;
46         this.interpreter = interpreter;
47     }
48
49     public void execute()
50         throws MojoExecutionException, MojoFailureException
51     {
52         try
53         {
54             interpreter.set( "logger", getLog() );
55
56             // TODO: set out, err to a print stream that will log at info, error respectively
57
}
58         catch ( EvalError evalError )
59         {
60             throw new MojoExecutionException( "Unable to establish mojo", evalError );
61         }
62
63         mojo.execute();
64     }
65
66     public Interpreter getInterpreter()
67     {
68         return interpreter;
69     }
70 }
71
Popular Tags