1 package com.atlassian.maven.plugins.amps;
2
3 import org.apache.maven.plugin.MojoExecutionException;
4 import org.apache.maven.plugin.MojoFailureException;
5 import org.jfrog.maven.annomojo.annotations.MojoExecute;
6 import org.jfrog.maven.annomojo.annotations.MojoGoal;
7 import org.jfrog.maven.annomojo.annotations.MojoParameter;
8 import org.jfrog.maven.annomojo.annotations.MojoRequiresDependencyResolution;
9 import com.atlassian.maven.plugins.amps.product.ProductHandlerFactory;
10
11
12
13
14 @MojoGoal ("debug")
15 @MojoExecute (phase = "package")
16 @MojoRequiresDependencyResolution
17 public class DebugMojo extends RunMojo
18 {
19 private static final String DEFAULT_JVM_ARGS = "-Xmx512m -XX:MaxPermSize=160m";
20
21
22
23
24 @MojoParameter (expression = "${jvm.debug.port}", defaultValue = "5005")
25 protected int jvmDebugPort;
26
27
28
29
30 @MojoParameter (expression = "${jvm.debug.suspend}")
31 protected boolean jvmDebugSuspend = false;
32
33
34 @Override
35 protected void doExecute() throws MojoExecutionException, MojoFailureException
36 {
37 String debugArgs = " -Xdebug -Xrunjdwp:transport=dt_socket,address=" +
38 String.valueOf(jvmDebugPort) + ",suspend=" + (jvmDebugSuspend ? "y" : "n") + ",server=y ";
39
40 if (jvmArgs == null)
41 {
42 jvmArgs = DEFAULT_JVM_ARGS;
43 }
44
45
46 jvmArgs += debugArgs;
47
48
49 for (Product product : products)
50 {
51 if (product.getJvmArgs() == null)
52 {
53 product.setJvmArgs(jvmArgs);
54 }
55 else
56 {
57 product.setJvmArgs(product.getJvmArgs() + debugArgs);
58 }
59 }
60
61 if (writePropertiesToFile)
62 {
63 properties.put("debug.port", String.valueOf(jvmDebugPort));
64 }
65
66 if (ProductHandlerFactory.FECRU.equals(getDefaultProductId()) && debugNotSet()) {
67 String message = "You must set the ATLAS_OPTS environment variable to the following string:'" + jvmArgs + "' when calling atlas-debug to enable Fisheye/Crucible debugging.";
68 getLog().error(message);
69 throw new MojoFailureException(message);
70 }
71
72 super.doExecute();
73 }
74
75 private boolean debugNotSet()
76 {
77 String atlasOpts = System.getenv("ATLAS_OPTS");
78 return atlasOpts == null || !atlasOpts.contains("-Xdebug");
79 }
80 }