Debian Codegraph @

src/main/java/org/freehep/graphics2d/font/encoding/CharTableConverterMojo.java

raw
1 // Copyright FreeHEP, 2005.
2 package org.freehep.graphics2d.font.encoding;
3
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.apache.maven.plugin.AbstractMojo;
8 import org.apache.maven.plugin.MojoExecutionException;
9 import org.apache.maven.project.MavenProject;
10 import org.codehaus.plexus.util.FileUtils;
11
12 /**
13 * @goal generate
14 * @description Generates lookup tables from 16 bit Unicode text files.
15 * @phase generate-sources
16 * @author <a href="[email protected]">Mark Donszelmann</a>
17 * @version $Id: CharTableConverterMojo.java 8584 2006-08-10 23:06:37Z duns $
18 */
19 public class CharTableConverterMojo extends AbstractMojo {
20
21 /**
22 * The target directory into which to generate the output
23 *
24 * @parameter expression="${project.build.directory}/generated-sources/encoding"
25 * @required
26 */
27 private String targetDirectory;
28
29 /**
30 * The name of the package to be used in the generated lookup classes.
31 *
32 * @parameter expression=""
33 * @required
34 */
35 private String packageName;
36
37 /**
38 * The configuration file directory.
39 *
40 * @parameter expression="${basedir}/src/main/encoding"
41 * @required
42 */
43 private String sourceDirectory;
44
45 /**
46 * The 16 bit Unicode text file.
47 *
48 * @parameter expression=""
49 * @required
50 */
51 private String source;
52
53 /**
54 * The 16 bit Unicode text file.
55 *
56 * @parameter expression=""
57 */
58 private String encodingType = null;
59
60 /**
61 * @parameter expression="${project}"
62 * @required
63 */
64 private MavenProject project;
65
66 public void execute() throws MojoExecutionException {
67 if (!FileUtils.fileExists(targetDirectory)) {
68 FileUtils.mkdir( targetDirectory );
69 }
70
71 try {
72 org.freehep.graphics2d.font.encoding.CharTableConverter.main(generateArgumentList());
73 } catch (Exception e) {
74 throw new MojoExecutionException( "CHarTableConverter execution failed", e );
75 }
76
77 if (project != null) {
78 project.addCompileSourceRoot(targetDirectory);
79 }
80 }
81
82
83 private String[] generateArgumentList() throws MojoExecutionException {
84
85 List argList = new ArrayList();
86
87 argList.add(targetDirectory);
88 argList.add(packageName);
89
90 // FIXME, check for source out-of-date
91 if (!sourceDirectory.endsWith("/")) {
92 sourceDirectory = sourceDirectory+"/";
93 }
94
95 argList.add(sourceDirectory+source);
96
97 if (encodingType != null) argList.add(encodingType);
98
99 getLog().debug("CharTableConverter " + argList.toString());
100
101 return (String[])argList.toArray(new String[argList.size()]);
102 }
103 }