/plugin-module-codegen-api/src/main/java/com/atlassian/plugins/codegen/ResourceFile.java

https://bitbucket.org/mmeinhold/amps · Java · 58 lines · 44 code · 11 blank · 3 comment · 0 complexity · 33cc793eb84f0ecff855b5cf5c3fe40b MD5 · raw file

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