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

https://bitbucket.org/mmeinhold/amps · Java · 106 lines · 65 code · 12 blank · 29 comment · 2 complexity · b84e11cfe70b22e1939f4978b4b73c72 MD5 · raw file

  1. package com.atlassian.plugins.codegen;
  2. import static com.atlassian.fugue.Option.some;
  3. import static com.atlassian.plugins.codegen.ArtifactId.artifactId;
  4. import static com.atlassian.plugins.codegen.VersionId.version;
  5. import static com.google.common.base.Preconditions.checkNotNull;
  6. /**
  7. * Describes a dependency on an external artifact that should be added to the POM.
  8. */
  9. public final class ArtifactDependency implements PluginProjectChange
  10. {
  11. public enum Scope
  12. {
  13. DEFAULT,
  14. COMPILE,
  15. PROVIDED,
  16. TEST
  17. };
  18. private ArtifactId artifactId;
  19. private VersionId versionId;
  20. private Scope scope;
  21. /**
  22. * Creates a dependency descriptor whose version string is provided explicitly.
  23. * @param groupId Maven group ID
  24. * @param artifactId Maven artifact ID
  25. * @param version the version identifier
  26. * @param scope dependency scope (use DEfAULT to omit scope declaration)
  27. */
  28. public static ArtifactDependency dependency(String groupId, String artifactId, VersionId versionId, Scope scope)
  29. {
  30. return new ArtifactDependency(artifactId(some(groupId), artifactId), versionId, scope);
  31. }
  32. /**
  33. * Creates a dependency descriptor whose version string is provided explicitly.
  34. * @param groupId Maven group ID
  35. * @param artifactId Maven artifact ID
  36. * @param version the version string
  37. * @param scope dependency scope (use DEfAULT to omit scope declaration)
  38. */
  39. public static ArtifactDependency dependency(String groupId, String artifactId, String version, Scope scope)
  40. {
  41. return new ArtifactDependency(artifactId(some(groupId), artifactId), version(version), scope);
  42. }
  43. /**
  44. * Creates a dependency descriptor whose version string is provided explicitly.
  45. * @param groupAndArtifactId Maven group and artifact ID
  46. * @param versionId the version identifier
  47. * @param scope dependency scope (use DEfAULT to omit scope declaration)
  48. */
  49. public static ArtifactDependency dependency(ArtifactId groupAndArtifactId, VersionId versionId, Scope scope)
  50. {
  51. return new ArtifactDependency(groupAndArtifactId, versionId, scope);
  52. }
  53. /**
  54. * Creates a dependency descriptor whose version string is provided explicitly.
  55. * @param groupAndArtifactId Maven group and artifact ID
  56. * @param version the version string
  57. * @param scope dependency scope (use DEfAULT to omit scope declaration)
  58. */
  59. public static ArtifactDependency dependency(ArtifactId groupAndArtifactId, String version, Scope scope)
  60. {
  61. return new ArtifactDependency(groupAndArtifactId, version(version), scope);
  62. }
  63. private ArtifactDependency(ArtifactId artifactId, VersionId versionId, Scope scope)
  64. {
  65. this.artifactId = checkNotNull(artifactId, "artifactId");
  66. if (!artifactId.getGroupId().isDefined())
  67. {
  68. throw new IllegalArgumentException("Group ID must be specified for dependency");
  69. }
  70. this.versionId = checkNotNull(versionId, "versionId");
  71. if (!versionId.getVersion().isDefined())
  72. {
  73. throw new IllegalArgumentException("Version must be specified for dependency");
  74. }
  75. this.scope = checkNotNull(scope, "scope");
  76. }
  77. public ArtifactId getGroupAndArtifactId()
  78. {
  79. return artifactId;
  80. }
  81. public VersionId getVersionId()
  82. {
  83. return versionId;
  84. }
  85. public Scope getScope()
  86. {
  87. return scope;
  88. }
  89. @Override
  90. public String toString()
  91. {
  92. return "[dependency: " + artifactId + "]";
  93. }
  94. }