Coverage Report - org.jbehave.core.io.rest.mojo.ExportFromFilesystemMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ExportFromFilesystemMojo
0%
0/20
0%
0/4
3
 
 1  
 package org.jbehave.core.io.rest.mojo;
 2  
 
 3  
 import org.apache.maven.plugin.AbstractMojo;
 4  
 import org.apache.maven.plugin.MojoExecutionException;
 5  
 import org.apache.maven.plugin.MojoFailureException;
 6  
 import org.jbehave.core.io.rest.RESTClient.Type;
 7  
 import org.jbehave.core.io.rest.ResourceExporter;
 8  
 import org.jbehave.core.io.rest.ResourceIndexer;
 9  
 import org.jbehave.core.io.rest.ResourceUploader;
 10  
 import org.jbehave.core.io.rest.filesystem.ExportFromFilesystem;
 11  
 import org.jbehave.core.io.rest.redmine.IndexFromRedmine;
 12  
 import org.jbehave.core.io.rest.redmine.UploadToRedmine;
 13  
 
 14  
 /**
 15  
  * Mojo to export resources to REST root path from filesystem source path.
 16  
  * 
 17  
  * @goal export-from-filesystem
 18  
  * @requiresProject false
 19  
  */
 20  0
 public class ExportFromFilesystemMojo extends AbstractMojo {
 21  
 
 22  
     private static final String REDMINE = "redmine";
 23  
 
 24  
     /**
 25  
      * The REST provider
 26  
      * 
 27  
      * @parameter default-value="redmine" expression="${jbehave.restProvider}
 28  
      */
 29  
     String restProvider;
 30  
 
 31  
     /**
 32  
      * The root URI of the REST API
 33  
      * 
 34  
      * @parameter expression="${jbehave.restRootURI}
 35  
      * @required
 36  
      */
 37  
     String restRootURI;
 38  
 
 39  
     /**
 40  
      * The username to access the REST API. May be null if no security enabled.
 41  
      * 
 42  
      * @parameter expression="${jbehave.restUsername}
 43  
      */
 44  
     String restUsername;
 45  
 
 46  
     /**
 47  
      * The password to access the REST API. May be null if no security enabled.
 48  
      * 
 49  
      * @parameter expression="${jbehave.restPassword}
 50  
      */
 51  
     String restPassword;
 52  
 
 53  
     /**
 54  
      * The source path of the filesystem from which the resources are read
 55  
      * 
 56  
      * @parameter default-value="target/stories"
 57  
      *            expression="${jbehave.sourcePath}
 58  
      */
 59  
     String sourcePath;
 60  
 
 61  
     /**
 62  
      * The extension of the files read
 63  
      * 
 64  
      * @parameter default-value=".story" expression="${jbehave.sourceExt}
 65  
      */
 66  
     String sourceExt;
 67  
 
 68  
     /**
 69  
      * The path to the resource index
 70  
      * 
 71  
      * @parameter expression="${jbehave.indexPath}
 72  
      */
 73  
     String indexPath;
 74  
 
 75  
     public void execute() throws MojoExecutionException, MojoFailureException {
 76  
         try {
 77  0
             getLog().info("Exporting from filesystem resources to REST root URI " + restRootURI);
 78  0
             ResourceExporter exporter = createExporter();
 79  0
             exporter.exportResources(restRootURI);
 80  0
         } catch (Exception e) {
 81  0
             String message = "Failed to export from filesystem resources to REST root URI " + restRootURI;
 82  0
             getLog().warn(message);
 83  0
             throw new MojoExecutionException(message, e);
 84  0
         }
 85  0
     }
 86  
 
 87  
     private ResourceExporter createExporter() {
 88  0
         ResourceIndexer indexer = newResourceIndexer();
 89  0
         ResourceUploader uploader = newResourceUploader();
 90  0
         getLog().info(
 91  
                 "Creating exporter from filesystem with with indexer " + indexer.getClass() + ", uploader "
 92  
                         + uploader.getClass() + ", sourcePath " + sourcePath + ", sourceExt " + sourceExt
 93  
                         + " and indexPath " + indexPath);
 94  0
         return new ExportFromFilesystem(indexer, uploader, sourcePath, sourceExt, indexPath);
 95  
     }
 96  
 
 97  
     ResourceIndexer newResourceIndexer() {
 98  0
         if (restProvider.equals(REDMINE)) {
 99  0
             return new IndexFromRedmine(restUsername, restPassword);
 100  
         }
 101  0
         throw new RuntimeException("Unsupported REST provider " + restProvider);
 102  
     }
 103  
 
 104  
     ResourceUploader newResourceUploader() {
 105  0
         if (restProvider.equals(REDMINE)) {
 106  0
             return new UploadToRedmine(Type.JSON, restUsername, restPassword);
 107  
         }
 108  0
         throw new RuntimeException("Unsupported REST provider " + restProvider);
 109  
     }
 110  
 
 111  
 }