1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jdtaus.core.container.mojo;
22
23 import java.util.Locale;
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugin.MojoFailureException;
26 import org.jdtaus.core.container.ContainerError;
27 import org.jdtaus.core.container.ContextError;
28 import org.jdtaus.core.container.Implementations;
29 import org.jdtaus.core.container.ModelError;
30 import org.jdtaus.core.container.Module;
31 import org.jdtaus.core.container.Specifications;
32
33
34
35
36
37
38
39
40
41
42 public class JavaContainerTestsMojo extends JavaContainerMojo
43 {
44
45
46 public JavaContainerTestsMojo()
47 {
48 super();
49 }
50
51
52 public void execute() throws MojoExecutionException, MojoFailureException
53 {
54 final ClassLoader mavenLoader = Thread.currentThread().
55 getContextClassLoader();
56
57 try
58 {
59 this.model = null;
60
61 Thread.currentThread().setContextClassLoader(
62 this.getTestClassLoader( mavenLoader ) );
63
64 enableThreadContextClassLoader();
65
66 final Module testMod = this.getTestModule();
67
68 if ( testMod != null )
69 {
70 final Specifications specs = testMod.getSpecifications();
71 final Implementations impls = testMod.getImplementations();
72
73 for ( int i = specs.size() - 1; i >= 0; i-- )
74 {
75 this.generateSpecification(
76 this.getMavenProject().getTestCompileSourceRoots(),
77 specs.getSpecification( i ) );
78
79 }
80
81 for ( int i = impls.size() - 1; i >= 0; i-- )
82 {
83 this.generateImplementation(
84 this.getMavenProject().getTestCompileSourceRoots(),
85 impls.getImplementation( i ) );
86
87 }
88
89 this.writeContainerReport( this.getModel(),
90 "container-tests-report.xml" );
91
92 this.getLog().info( JavaContainerMojoBundle.getInstance().
93 getProcessingModuleMessage( Locale.getDefault(),
94 testMod.getName() ) );
95
96 }
97 }
98 catch ( final ContextError e )
99 {
100 throw new MojoExecutionException( e.getMessage(), e );
101 }
102 catch ( final ContainerError e )
103 {
104 throw new MojoExecutionException( e.getMessage(), e );
105 }
106 catch ( final ModelError e )
107 {
108 throw new MojoExecutionException( e.getMessage(), e );
109 }
110 catch ( final Exception e )
111 {
112 throw new MojoExecutionException( e.getMessage(), e );
113 }
114 finally
115 {
116 disableThreadContextClassLoader();
117 Thread.currentThread().setContextClassLoader( mavenLoader );
118 }
119 }
120
121 }