1 package org.codehaus.mojo.gwt.eclipse;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.io.Writer;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.HashMap;
28 import java.util.LinkedList;
29 import java.util.List;
30 import java.util.Map;
31
32 import org.apache.maven.plugin.MojoExecutionException;
33 import org.apache.maven.plugin.MojoFailureException;
34 import org.apache.maven.plugins.annotations.Component;
35 import org.apache.maven.plugins.annotations.Execute;
36 import org.apache.maven.plugins.annotations.LifecyclePhase;
37 import org.apache.maven.plugins.annotations.Mojo;
38 import org.apache.maven.plugins.annotations.Parameter;
39 import org.apache.maven.project.MavenProject;
40 import org.codehaus.mojo.gwt.shell.TestMojo;
41 import org.codehaus.mojo.gwt.test.TestTemplate;
42 import org.codehaus.plexus.util.WriterFactory;
43
44 import freemarker.template.Configuration;
45 import freemarker.template.Template;
46 import freemarker.template.TemplateException;
47
48
49
50
51
52
53
54
55 @Deprecated
56 @Mojo(name = "eclipseTest")
57 @Execute(phase = LifecyclePhase.GENERATE_TEST_RESOURCES)
58 public class EclipseTestMojo
59 extends TestMojo
60 {
61 @Component
62 private EclipseUtil eclipseUtil;
63
64
65
66
67 @Parameter(defaultValue = "${executedProject}", readonly = true)
68 private MavenProject executedProject;
69
70
71
72
73 @Parameter(defaultValue = "${project.build.directory}/www-test")
74 private File testOutputDirectory;
75
76
77
78
79
80
81 @Override
82 public void doExecute()
83 throws MojoExecutionException, MojoFailureException
84 {
85
86 new TestTemplate( getProject(), includes, excludes, new TestTemplate.CallBack()
87 {
88 public void doWithTest( File sourceDir, String test )
89 throws MojoExecutionException
90 {
91 createLaunchConfigurationForGwtTestCase( sourceDir, test );
92 }
93 } );
94 }
95
96
97
98
99
100
101
102 private void createLaunchConfigurationForGwtTestCase( File testSrc, String test )
103 throws MojoExecutionException
104 {
105 File testFile = new File( testSrc, test );
106
107 String fqcn = test.replace( File.separatorChar, '.' ).substring( 0, test.lastIndexOf( '.' ) );
108 File launchFile = new File( getProject().getBasedir(), fqcn + ".launch" );
109 if ( launchFile.exists() && launchFile.lastModified() > testFile.lastModified() )
110 {
111 return;
112 }
113
114 Configuration cfg = new Configuration();
115 cfg.setClassForTemplateLoading( EclipseTestMojo.class, "" );
116
117 Map < String, Object > context = new HashMap < String, Object > ();
118 List < String > sources = new LinkedList < String >();
119 sources.addAll( executedProject.getTestCompileSourceRoots() );
120 sources.addAll( executedProject.getCompileSourceRoots() );
121 context.put( "sources", sources );
122 context.put( "test", fqcn );
123 int basedir = getProject().getBasedir().getAbsolutePath().length();
124 context.put( "out", testOutputDirectory.getAbsolutePath().substring( basedir + 1 ) );
125 context.put( "extraJvmArgs", getExtraJvmArgs() );
126 context.put( "project", eclipseUtil.getProjectName( getProject() ) );
127
128
129 try
130 {
131 Collection<String> gwtDevJarPath = new ArrayList<String>();
132 for (File f : getJarFiles(GWT_DEV, false))
133 {
134 gwtDevJarPath.add( f.getAbsolutePath().replace( '\\', '/' ) );
135 }
136 context.put( "gwtDevJarPath", gwtDevJarPath );
137
138 Writer configWriter = WriterFactory.newXmlWriter( launchFile );
139 Template template = cfg.getTemplate( "test-launch.fm", "UTF-8" );
140 template.process( context, configWriter );
141 configWriter.flush();
142 configWriter.close();
143 getLog().info( "Write launch configuration for GWT test : " + launchFile.getAbsolutePath() );
144 }
145 catch ( IOException ioe )
146 {
147 throw new MojoExecutionException( "Unable to write launch configuration", ioe );
148 }
149 catch ( TemplateException te )
150 {
151 throw new MojoExecutionException( "Unable to merge freemarker template", te );
152 }
153 }
154
155 }