001    /*
002     * Copyright (C) 2006-2007 the original author or authors.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.codehaus.gmaven.plugin.tools;
018    
019    import org.apache.maven.artifact.DependencyResolutionRequiredException;
020    import org.codehaus.gmaven.feature.Component;
021    import org.codehaus.gmaven.plugin.ComponentMojoSupport;
022    import org.codehaus.gmaven.runtime.Console;
023    import org.codehaus.gmaven.runtime.loader.realm.RealmManager;
024    import org.codehaus.plexus.classworlds.realm.ClassRealm;
025    
026    import java.util.List;
027    
028    /**
029     * Launches the Groovy GUI console.
030     *
031     * @goal console
032     * @requiresProject false
033     * @requiresDependencyResolution test
034     * @since 1.0-beta-2
035     * 
036     * @version $Id: ConsoleMojo.java 11 2009-07-16 09:25:38Z user57 $
037     * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
038     */
039    public class ConsoleMojo
040        extends ComponentMojoSupport
041    {
042        /**
043         * @component
044         *
045         * @noinspection UnusedDeclaration
046         */
047        private RealmManager realmManager;
048    
049        public ConsoleMojo() {
050            super(Console.KEY);
051        }
052    
053        protected List getProjectClasspathElements() throws DependencyResolutionRequiredException {
054            return project.getTestClasspathElements();
055        }
056        
057        protected void process(final Component component) throws Exception {
058            assert component != null;
059    
060            Console console = (Console) component;
061    
062            ClassRealm realm = realmManager.createComponentRealm(provider(), createClassPath());
063    
064            console.execute(realm);
065    
066            realmManager.releaseComponentRealm(realm);
067        }
068    }