1 6 package fr.jayasoft.ivy; 7 8 import java.util.LinkedHashSet ; 9 import java.util.Set ; 10 11 import fr.jayasoft.ivy.extendable.DefaultExtendableItem; 12 13 14 17 public class Configuration extends DefaultExtendableItem { 18 public static class Visibility { 19 public static Visibility PUBLIC = new Visibility("public"); 20 public static Visibility PRIVATE = new Visibility("private"); 21 public static Visibility getVisibility(String name) { 22 if ("private".equals(name)) { 23 return PRIVATE; 24 } else if ("public".equals(name)) { 25 return PUBLIC; 26 } else { 27 throw new IllegalArgumentException ("unknwon visibility "+name); 28 } 29 } 30 private String _name; 31 private Visibility(String name) { 32 _name = name; 33 } 34 public String toString() { 35 return _name; 36 } 37 } 38 39 private String _name; 40 private String _description; 41 private String [] _extends; 42 private Visibility _visibility; 43 private boolean _transitive = true; 44 45 51 public Configuration(String name, Visibility visibility, 52 String description, String [] ext) { 53 this(name, visibility, description, ext, true); 54 } 55 56 63 public Configuration(String name, Visibility visibility, 64 String description, String [] ext, boolean transitive) { 65 if (name == null) { 66 throw new NullPointerException ("null configuration name not allowed"); 67 } 68 if (visibility == null) { 69 throw new NullPointerException ("null visibility not allowed"); 70 } 71 _name = name; 72 _visibility = visibility; 73 _description = description; 74 if (ext == null) { 75 _extends = new String [0]; 76 } else { 77 _extends = new String [ext.length]; 78 for (int i = 0; i < ext.length; i++) { 79 _extends[i] = ext[i].trim(); 80 } 81 } 82 _transitive=transitive; 83 } 84 85 88 public Configuration(String name) { 89 this(name, Visibility.PUBLIC, null, null); 90 } 91 92 95 public String getDescription() { 96 return _description; 97 } 98 101 public String [] getExtends() { 102 return _extends; 103 } 104 107 public String getName() { 108 return _name; 109 } 110 113 public Visibility getVisibility() { 114 return _visibility; 115 } 116 117 120 public final boolean isTransitive() { 121 return _transitive; 122 } 123 124 public String toString() { 125 return _name; 126 } 127 128 public boolean equals(Object obj) { 129 if (! (obj instanceof Configuration)) { 130 return false; 131 } 132 return ((Configuration)obj).getName().equals(getName()); 133 } 134 135 public int hashCode() { 136 return getName().hashCode(); 137 } 138 139 public void replaceWildcards(ModuleDescriptor md) { 140 if (this != md.getConfiguration(_name)) { 141 throw new IllegalArgumentException ( 142 "The given ModuleDescriptor doesn't own this configuration!"); 143 } 144 145 Configuration[] configs = md.getConfigurations(); 146 147 Set newExtends = new LinkedHashSet (); 148 for (int j = 0; j < _extends.length; j++) { 149 if ("*".equals(_extends[j])) { 150 addOther(configs, null, newExtends); 151 } else if ("*(public)".equals(_extends[j])) { 152 addOther(configs, Visibility.PUBLIC, newExtends); 153 } else if ("*(private)".equals(_extends[j])) { 154 addOther(configs, Visibility.PRIVATE, newExtends); 155 } else { 156 newExtends.add(_extends[j]); 157 } 158 } 159 160 this._extends = (String []) newExtends.toArray(new String [newExtends.size()]); 161 } 162 163 private void addOther(Configuration[] allConfigs, Visibility visibility, Set configs) { 164 for (int i = 0; i < allConfigs.length; i++) { 165 String currentName = allConfigs[i].getName(); 166 if (!_name.equals(currentName) 167 && ((visibility == null) || visibility.equals(allConfigs[i].getVisibility()))) { 168 configs.add(currentName); 169 } 170 } 171 } 172 173 } 174 | Popular Tags |