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, or null if all values are null
27       */
28      public static <T> T firstNotNull(T... values)
29      {
30          for (T value : values)
31          {
32              if (value != null)
33              {
34                  return value;
35              }
36          }
37          return null;
38      }
39  
40      public final static File createDirectory(File dir)
41      {
42          if (!dir.exists() && !dir.mkdirs())
43          {
44              throw new RuntimeException("Failed to create directory " + dir.getAbsolutePath());
45          }
46          return dir;
47      }
48  }