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