Coverage Report - org.apache.maven.tools.plugin.extractor.beanshell.BeanshellMojoDescriptorExtractor
 
Classes in this File Line Coverage Branch Coverage Complexity
BeanshellMojoDescriptorExtractor
0% 
0% 
2.667
 
 1  
 package org.apache.maven.tools.plugin.extractor.beanshell;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import bsh.EvalError;
 23  
 import bsh.Interpreter;
 24  
 import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
 25  
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 26  
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
 27  
 import org.apache.maven.tools.plugin.extractor.AbstractScriptedMojoDescriptorExtractor;
 28  
 import org.apache.maven.tools.plugin.extractor.ExtractionException;
 29  
 
 30  
 import java.io.File;
 31  
 import java.io.InputStreamReader;
 32  
 import java.util.ArrayList;
 33  
 import java.util.Iterator;
 34  
 import java.util.List;
 35  
 import java.util.Map;
 36  
 import java.util.Set;
 37  
 
 38  
 /**
 39  
  * @todo share constants
 40  
  * @todo add example usage tag that can be shown in the doco
 41  
  * @todo need to add validation directives so that systems embedding maven2 can
 42  
  * get validation directives to help users in IDEs.
 43  
  */
 44  0
 public class BeanshellMojoDescriptorExtractor
 45  
     extends AbstractScriptedMojoDescriptorExtractor
 46  
 {
 47  
     private MojoDescriptor createMojoDescriptor( String basedir, String resource, PluginDescriptor pluginDescriptor )
 48  
         throws InvalidPluginDescriptorException
 49  
     {
 50  0
         MojoDescriptor mojoDescriptor = new MojoDescriptor();
 51  0
         mojoDescriptor.setPluginDescriptor( pluginDescriptor );
 52  
 
 53  0
         mojoDescriptor.setLanguage( "bsh" );
 54  0
         mojoDescriptor.setComponentConfigurator( "bsh" );
 55  
 
 56  0
         mojoDescriptor.setImplementation( resource );
 57  
 
 58  0
         Interpreter interpreter = new Interpreter();
 59  
 
 60  
         try
 61  
         {
 62  0
             interpreter.set( "file", new File( basedir, resource ) );
 63  
 
 64  0
             interpreter.set( "mojoDescriptor", mojoDescriptor );
 65  
 
 66  0
             interpreter.eval( new InputStreamReader( getClass().getResourceAsStream( "/extractor.bsh" ) ) );
 67  
         }
 68  0
         catch ( EvalError evalError )
 69  
         {
 70  0
             throw new InvalidPluginDescriptorException( "Error scanning beanshell script", evalError );
 71  0
         }
 72  
 
 73  0
         return mojoDescriptor;
 74  
     }
 75  
 
 76  
     protected String getScriptFileExtension()
 77  
     {
 78  0
         return ".bsh";
 79  
     }
 80  
 
 81  
     protected List extractMojoDescriptors( Map scriptFilesKeyedByBasedir, PluginDescriptor pluginDescriptor )
 82  
         throws ExtractionException, InvalidPluginDescriptorException
 83  
     {
 84  0
         List descriptors = new ArrayList();
 85  
 
 86  0
         for ( Iterator mapIterator = scriptFilesKeyedByBasedir.entrySet().iterator(); mapIterator.hasNext(); )
 87  
         {
 88  0
             Map.Entry entry = (Map.Entry) mapIterator.next();
 89  
 
 90  0
             String basedir = (String) entry.getKey();
 91  0
             Set metadataFiles = (Set) entry.getValue();
 92  
 
 93  0
             for ( Iterator it = metadataFiles.iterator(); it.hasNext(); )
 94  
             {
 95  0
                 File scriptFile = (File) it.next();
 96  
 
 97  0
                 String relativePath = null;
 98  
 
 99  0
                 if ( basedir.endsWith( "/" ) )
 100  
                 {
 101  0
                     basedir = basedir.substring( 0, basedir.length() - 2 );
 102  
                 }
 103  
 
 104  0
                 relativePath = scriptFile.getPath().substring( basedir.length() );
 105  
 
 106  0
                 relativePath = relativePath.replace( '\\', '/' );
 107  
 
 108  0
                 MojoDescriptor mojoDescriptor = createMojoDescriptor( basedir, relativePath, pluginDescriptor );
 109  0
                 descriptors.add( mojoDescriptor );
 110  0
             }
 111  0
         }
 112  
 
 113  0
         return descriptors;
 114  
     }
 115  
 }