1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.pyx4me.maven.j2me;
22
23 import java.io.File;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Vector;
27
28 import net.sf.jour.PreProcessor;
29
30 import org.apache.maven.artifact.Artifact;
31 import org.apache.maven.plugin.MojoExecutionException;
32 import org.apache.maven.plugin.MojoFailureException;
33 import org.apache.tools.ant.Project;
34 import org.apache.tools.ant.Task;
35
36 import com.pyx4j.log4j.MavenLogAppender;
37
38 import de.pleumann.antenna.misc.Utility;
39
40
41
42
43
44
45
46
47
48
49 public abstract class PreprocessMojo extends AbstractJadWtkMojo {
50
51
52
53
54
55
56 private String jourConfig;
57
58
59
60
61
62
63
64 protected String output;
65
66 public void execute() throws MojoExecutionException, MojoFailureException {
67 PreprocessMojo.executeClassPreprocessor(jourConfig, getJarFile(classifier), output, this);
68 }
69
70 public static File executeClassPreprocessor(String jourConfig, File jarFileOrClassesDirectory, String output,
71 AbstractJadWtkMojo mojo) throws MojoExecutionException, MojoFailureException {
72 MavenLogAppender.startPluginLog(mojo);
73 try {
74
75 mojo.getLog().info(jourConfig);
76
77 File out = new File(mojo.outputDirectory, output);
78
79 List classpath = new Vector();
80
81 if (mojo.useWtkLibs) {
82
83 Project antProject = mojo.getAntProject();
84 Task dummyTaks = new Task() {
85 };
86 dummyTaks.setTaskName("jour");
87 dummyTaks.setProject(antProject);
88
89 Utility utility = Utility.getInstance(antProject, dummyTaks);
90
91 String mdipClassPath = utility.getMidpApi();
92 classpath.add(mdipClassPath);
93 } else {
94 List dependancy = mojo.mavenProject.getCompileArtifacts();
95 for (Iterator i = dependancy.iterator(); i.hasNext();) {
96 Artifact artifact = (Artifact) i.next();
97 File file = getClasspathElement(artifact, mojo.mavenProject);
98 classpath.add(file.toString());
99 }
100 if (mojo.libs != null) {
101 for (Iterator i = mojo.libs.iterator(); i.hasNext();) {
102 Object lib = i.next();
103 classpath.add(lib.toString());
104 }
105 }
106 }
107
108 PreProcessor pp = new PreProcessor(jourConfig, jarFileOrClassesDirectory, out, classpath);
109
110 pp.setCopyClasses(true);
111 pp.setCopyResources(true);
112
113 try {
114 pp.process();
115 } catch (Exception e) {
116 mojo.getLog().error("PreProcessing error", e);
117 throw new MojoExecutionException("PreProcessing error", e);
118 }
119
120 return out;
121
122 } finally {
123 MavenLogAppender.endPluginLog(mojo);
124 }
125 }
126
127 }