1   package com.atlassian.plugins.codegen;
2   
3   import com.atlassian.fugue.Option;
4   
5   import static com.atlassian.fugue.Option.none;
6   import static com.atlassian.fugue.Option.some;
7   import static com.google.common.base.Preconditions.checkNotNull;
8   
9   /**
10   * Describes a line item in a bundle instruction element, such as <Import-Package>,
11   * that should be added to the POM.
12   */
13  public final class BundleInstruction implements PluginProjectChange, SummarizeAsGroup
14  {
15      public enum Category
16      {
17          IMPORT("Import-Package"),
18          PRIVATE("Private-Package"),
19          DYNAMIC_IMPORT("DynamicImport-Package");
20          
21          private String elementName;
22          
23          private Category(String elementName)
24          {
25              this.elementName = elementName;
26          }
27          
28          public String getElementName()
29          {
30              return elementName;
31          }
32      }
33      
34      private Category category;
35      private String packageName;
36      private Option<String> version;
37      
38      public static BundleInstruction importPackage(String packageName, String version)
39      {
40          return new BundleInstruction(Category.IMPORT, packageName, some(version));
41      }
42      
43      public static BundleInstruction dynamicImportPackage(String packageName, String version)
44      {
45          return new BundleInstruction(Category.DYNAMIC_IMPORT, packageName, some(version));
46      }
47      
48      public static BundleInstruction privatePackage(String packageName)
49      {
50          return new BundleInstruction(Category.PRIVATE, packageName, none(String.class));
51      }
52      
53      public BundleInstruction(Category category, String packageName, Option<String> version)
54      {
55          this.category = checkNotNull(category, "category");
56          this.packageName = checkNotNull(packageName, "packageName");
57          this.version = checkNotNull(version, "version");
58      }
59      
60      public Category getCategory()
61      {
62          return category;
63      }
64  
65      public String getPackageName()
66      {
67          return packageName;
68      }
69  
70      public Option<String> getVersion()
71      {
72          return version;
73      }
74      
75      @Override
76      public String getGroupName()
77      {
78          return "bundle instructions";
79      }
80      
81      @Override
82      public String toString()
83      {
84          return "[bundle instruction: " + category.getElementName() + " " + packageName + "]";
85      }
86  }