Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
GenerateScriptMojo |
|
| 3.0;3 |
1 | package org.kuali.maven.plugins; | |
2 | ||
3 | import java.io.File; | |
4 | import java.io.FileOutputStream; | |
5 | import java.io.IOException; | |
6 | import java.io.OutputStream; | |
7 | import java.util.List; | |
8 | ||
9 | import org.apache.commons.io.IOUtils; | |
10 | import org.apache.maven.artifact.Artifact; | |
11 | import org.apache.maven.plugin.AbstractMojo; | |
12 | import org.apache.maven.plugin.MojoExecutionException; | |
13 | import org.apache.maven.plugin.MojoFailureException; | |
14 | ||
15 | /** | |
16 | * The Oracle JDBC driver download page groups drivers by release but the filenames do not contain the version. This | |
17 | * mojo recursively inspects a directory containing Oracle JDBC drivers following the Oracle style naming convention and | |
18 | * generates a shell script following the Maven style naming convention. The shell script can then be used to upload the | |
19 | * JDBC drivers to a Maven repository. | |
20 | * | |
21 | * @author Jeff Caddel | |
22 | * @goal genscript | |
23 | */ | |
24 | 0 | public class GenerateScriptMojo extends AbstractMojo { |
25 | /** | |
26 | * Directory on the file system containing Oracle JDBC drivers | |
27 | * | |
28 | * @parameter expression="${oracle.jdbcDriverDirectory}" default-value="${user.home}/.oracle" | |
29 | */ | |
30 | private String jdbcDriverHome; | |
31 | ||
32 | /** | |
33 | * File where the script will be created. | |
34 | * | |
35 | * @parameter expression="${oracle.scriptDirectory}" default-value="${project.build.directory}/deploy-jars.sh" | |
36 | */ | |
37 | private String scriptFile; | |
38 | ||
39 | /** | |
40 | * Default groupId for Oracle JDBC drivers | |
41 | * | |
42 | * @parameter expression="${oracle.groupId}" default-value="com.oracle" | |
43 | */ | |
44 | private String oracleGroupId; | |
45 | ||
46 | @Override | |
47 | public void execute() throws MojoExecutionException, MojoFailureException { | |
48 | 0 | DeployUtils du = new DeployUtils(); |
49 | 0 | OutputStream out = null; |
50 | try { | |
51 | 0 | List<Artifact> artifacts = du.getArtifacts(new File(jdbcDriverHome), oracleGroupId); |
52 | 0 | getLog().info("Located " + artifacts.size() + " artifacts"); |
53 | 0 | getLog().info("Generating script to: " + scriptFile); |
54 | 0 | String s = du.getShellScript(artifacts); |
55 | 0 | out = new FileOutputStream(scriptFile); |
56 | 0 | IOUtils.write(s, out); |
57 | 0 | } catch (IOException e) { |
58 | 0 | throw new MojoExecutionException("Unexpected issue", e); |
59 | } finally { | |
60 | 0 | IOUtils.closeQuietly(out); |
61 | 0 | } |
62 | ||
63 | 0 | } |
64 | } |