| 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.ResourceLoader; |
| 7 | |
import org.jbehave.core.io.rest.RESTClient.Type; |
| 8 | |
import org.jbehave.core.io.rest.ResourceImporter; |
| 9 | |
import org.jbehave.core.io.rest.ResourceIndexer; |
| 10 | |
import org.jbehave.core.io.rest.filesystem.ImportToFilesystem; |
| 11 | |
import org.jbehave.core.io.rest.redmine.IndexFromRedmine; |
| 12 | |
import org.jbehave.core.io.rest.redmine.LoadFromRedmine; |
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | 1 | public class ImportToFilesystemMojo 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 targetPath; |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
String targetExt; |
| 67 | |
|
| 68 | |
public void execute() throws MojoExecutionException, MojoFailureException { |
| 69 | |
try { |
| 70 | 1 | getLog().info("Importing to filesystem resources from REST root URI " + restRootURI); |
| 71 | 1 | ResourceImporter importer = createImporter(); |
| 72 | 1 | importer.importResources(restRootURI); |
| 73 | 0 | } catch (Exception e) { |
| 74 | 0 | String message = "Failed to import to filesystem resources from REST root URI " + restRootURI; |
| 75 | 0 | getLog().warn(message); |
| 76 | 0 | throw new MojoExecutionException(message, e); |
| 77 | 1 | } |
| 78 | 1 | } |
| 79 | |
|
| 80 | |
private ResourceImporter createImporter() { |
| 81 | 1 | ResourceIndexer indexer = newResourceIndexer(); |
| 82 | 1 | ResourceLoader loader = newResourceLoader(); |
| 83 | 1 | getLog().info( |
| 84 | |
"Creating importer to filesystem with indexer " + indexer.getClass() + ", loader " + loader.getClass() |
| 85 | |
+ ", targetPath " + targetPath + ", targetExt " + targetExt); |
| 86 | 1 | return new ImportToFilesystem(indexer, loader, targetPath, targetExt); |
| 87 | |
} |
| 88 | |
|
| 89 | |
ResourceIndexer newResourceIndexer() { |
| 90 | 0 | if (restProvider.equals(REDMINE)) { |
| 91 | 0 | return new IndexFromRedmine(restUsername, restPassword); |
| 92 | |
} |
| 93 | 0 | throw new RuntimeException("Unsupported REST provider " + restProvider); |
| 94 | |
} |
| 95 | |
|
| 96 | |
ResourceLoader newResourceLoader() { |
| 97 | 0 | if (restProvider.equals(REDMINE)) { |
| 98 | 0 | return new LoadFromRedmine(Type.JSON, restUsername, restPassword); |
| 99 | |
} |
| 100 | 0 | throw new RuntimeException("Unsupported REST provider " + restProvider); |
| 101 | |
} |
| 102 | |
|
| 103 | |
} |