1 package com.atlassian.maven.plugins.amps;
2
3 import org.apache.commons.io.FileUtils;
4 import org.apache.maven.plugin.MojoExecutionException;
5 import org.apache.maven.plugin.MojoFailureException;
6 import org.jfrog.maven.annomojo.annotations.MojoGoal;
7 import org.jfrog.maven.annomojo.annotations.MojoParameter;
8
9 import java.io.File;
10 import java.io.IOException;
11
12 import static com.atlassian.maven.plugins.amps.util.FileUtils.file;
13
14
15
16
17
18
19
20
21
22
23
24 @MojoGoal("test-jar")
25 public class TestJarMojo extends AbstractAmpsMojo
26 {
27
28
29
30
31
32 @MojoParameter
33 private Boolean buildTestPlugin;
34
35
36
37
38 @MojoParameter(expression = "${project.build.finalName}")
39 private String finalName;
40
41 public void execute() throws MojoExecutionException, MojoFailureException
42 {
43 boolean shouldBuild = false;
44 if (buildTestPlugin != null)
45 {
46 if (buildTestPlugin.booleanValue())
47 {
48 shouldBuild = true;
49 }
50 }
51 else if (file(getMavenContext().getProject().getBuild().getTestOutputDirectory(), "atlassian-plugin.xml").exists())
52 {
53 shouldBuild = true;
54 }
55
56 if (shouldBuild)
57 {
58 File mf = file(getMavenContext().getProject().getBuild().getTestOutputDirectory(), "META-INF", "MANIFEST.MF");
59 if (!mf.exists())
60 {
61 try
62 {
63 FileUtils.writeStringToFile(mf,
64 "Manifest-Version: 1.0\n" +
65 "Bundle-SymbolicName: plugin-tests\n" +
66 "Bundle-Version: 1.0\n" +
67 "DynamicImport-Package: *\n");
68 }
69 catch (IOException e)
70 {
71 throw new MojoFailureException("Unable to write manifest");
72 }
73 }
74 getMavenGoals().jarTests(finalName);
75 }
76 }
77 }
78