| 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 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | 0 | public class ExportFromFilesystemMojo extends AbstractMojo { |
| 21 | |
|
| 22 | |
private static final String REDMINE = "redmine"; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
String restProvider; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
String restRootURI; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
String restUsername; |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
String restPassword; |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
String sourcePath; |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
String sourceExt; |
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 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 | |
} |