View Javadoc

1   package com.atlassian.plugin.test;
2   
3   import org.apache.commons.io.FileUtils;
4   
5   import java.io.File;
6   import java.io.IOException;
7   import java.net.URISyntaxException;
8   import java.net.URI;
9   
10  /**
11   *
12   */
13  public class PluginTestUtils
14  {
15      public static final String PROJECT_VERSION;
16      public static final String SIMPLE_TEST_JAR;
17      public static final String INNER1_TEST_JAR;
18      public static final String INNER2_TEST_JAR;
19      public static final String FILTER_TEST_JAR;
20  
21      static
22      {
23          PROJECT_VERSION = System.getProperty("project.version");
24          SIMPLE_TEST_JAR = "atlassian-plugins-simpletest-" + PROJECT_VERSION + ".jar";
25          INNER1_TEST_JAR = "atlassian-plugins-innerjarone-" + PROJECT_VERSION + ".jar";
26          INNER2_TEST_JAR = "atlassian-plugins-innerjartwo-" + PROJECT_VERSION + ".jar";
27          FILTER_TEST_JAR = "atlassian-plugins-filtertest-" + PROJECT_VERSION + ".jar";
28      }
29  
30      public static File getFileForResource(final String resourceName) throws URISyntaxException
31      {
32          return new File(new URI(PluginTestUtils.class.getClassLoader().getResource(resourceName).toString()));
33      }
34  
35      public static File createTempDirectory(Class source) throws IOException
36      {
37          return createTempDirectory(source.getName());
38      }
39      public static File createTempDirectory(String name) throws IOException
40      {
41          File tmpDir = new File("target" + File.separator + "tmp" + File.separator + name).getAbsoluteFile();
42          if (tmpDir.exists())
43          {
44              FileUtils.cleanDirectory(tmpDir);
45          }
46          else
47          {
48              tmpDir.mkdirs();
49          }
50          return tmpDir;
51      }
52  }