1 package com.atlassian.plugins.codegen;
2
3 import java.nio.charset.Charset;
4
5 import static com.google.common.base.Preconditions.checkNotNull;
6
7
8
9
10 public class ResourceFile implements PluginProjectChange
11 {
12 private final String relativePath;
13 private final String name;
14 private final byte[] content;
15
16 public static ResourceFile resourceFile(String relativePath, String name, String content)
17 {
18 return new ResourceFile(relativePath, name, content.getBytes(Charset.forName("UTF-8")));
19 }
20
21 public static ResourceFile resourceFile(String relativePath, String name, byte[] content)
22 {
23 return new ResourceFile(relativePath, name, content);
24 }
25
26 private ResourceFile(String relativePath, String name, byte[] content)
27 {
28 this.relativePath = normalizePath(checkNotNull(relativePath, "relativePath"));
29 this.name = checkNotNull(name, "name");
30 this.content = checkNotNull(content, "content");
31 }
32
33 public String getRelativePath()
34 {
35 return relativePath;
36 }
37
38 public String getName()
39 {
40 return name;
41 }
42
43 public byte[] getContent()
44 {
45 return content;
46 }
47
48 private String normalizePath(String path)
49 {
50 return (path.endsWith("/")) ? path.substring(0, path.length() - 1) : path;
51 }
52
53 @Override
54 public String toString()
55 {
56 return "[resource: " + name + "]";
57 }
58 }