PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/plugin-module-codegen-engine/src/test/java/com/atlassian/plugins/codegen/ProjectHelper.java

https://bitbucket.org/mmeinhold/amps
Java | 61 lines | 52 code | 9 blank | 0 comment | 0 complexity | d6cf40de22d5b76dc6f0c04a315791cb MD5 | raw file
 1package com.atlassian.plugins.codegen;
 2
 3import java.io.File;
 4import java.io.InputStream;
 5import java.io.OutputStream;
 6import java.util.UUID;
 7
 8import com.atlassian.plugins.codegen.modules.PluginModuleLocation;
 9
10import org.apache.commons.io.FileUtils;
11import org.apache.commons.io.IOUtils;
12
13import static org.apache.commons.io.FileUtils.deleteDirectory;
14
15public class ProjectHelper
16{
17    public static final String GROUP_ID = "myGroupId";
18    public static final String ARTIFACT_ID = "myArtifactId";
19    public static final String PLUGIN_KEY = "myGroupId.myArtifactId";
20
21    public PluginModuleLocation location;
22    public File pluginXml;
23    public File tempDir;
24    public File srcDir;
25    public File testDir;
26    public File resourcesDir;
27    
28    public ProjectHelper() throws Exception
29    {
30        final File buildRoot = new File("target");
31        String dirName = UUID.randomUUID().toString();
32        tempDir = new File(buildRoot, dirName);
33        srcDir = new File(tempDir, "src");
34        testDir = new File(tempDir, "test");
35        resourcesDir = new File(tempDir, "resources");
36        pluginXml = new File(resourcesDir, "atlassian-plugin.xml");
37        tempDir.mkdirs();
38        srcDir.mkdirs();
39        testDir.mkdirs();
40        resourcesDir.mkdirs();
41        location = new PluginModuleLocation.Builder(srcDir)
42            .testDirectory(testDir)
43            .resourcesDirectory(resourcesDir)
44            .groupAndArtifactId(GROUP_ID, ARTIFACT_ID)
45            .build();
46    }
47    
48    public void usePluginXml(String path) throws Exception
49    {
50        InputStream is = this.getClass().getClassLoader().getResourceAsStream(path);
51        OutputStream os = FileUtils.openOutputStream(pluginXml);
52        IOUtils.copy(is, os);
53        is.close();
54        os.close();
55    }
56    
57    public void destroy() throws Exception
58    {
59        deleteDirectory(tempDir);
60    }
61}