1   package com.atlassian.maven.plugins.amps.util;
2   
3   import java.io.File;
4   
5   import com.atlassian.maven.plugins.amps.MavenContext;
6   import static com.atlassian.maven.plugins.amps.util.FileUtils.file;
7   
8   /**
9    * Utility methods dealing with Maven projects
10   *
11   * @since 3.3
12   */
13  public class ProjectUtils
14  {
15  
16      /**
17       * @return If the test jar should be built based on atlassian-plugin.xml residing in src/test/resources
18       */
19      public static boolean shouldDeployTestJar(MavenContext context)
20      {
21          return file(context.getProject().getBuild().getTestOutputDirectory(), "atlassian-plugin.xml").exists();
22      }
23  
24      /**
25       * Returns the first non null value. Use this to default values.
26       * @return the first non null value of values
27       * @throws NullPointerException if all values are null
28       *
29       * Note: this is a copy of Objects#firstNonNull in Guava release 03.
30       */
31      public static <T> T firstNotNull(T... values)
32      {
33          for (T value : values)
34          {
35              if (value != null)
36              {
37                  return value;
38              }
39          }
40          throw new NullPointerException("All values are null");
41      }
42  
43      public final static File createDirectory(File dir)
44      {
45          if (!dir.exists() && !dir.mkdirs())
46          {
47              throw new RuntimeException("Failed to create directory " + dir.getAbsolutePath());
48          }
49          return dir;
50      }
51  }