1 19 20 package org.netbeans.modules.apisupport.project.ui.customizer; 21 22 import java.text.Collator ; 23 import java.util.Comparator ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 import org.netbeans.modules.apisupport.project.universe.ModuleEntry; 28 import org.netbeans.spi.project.support.ant.PropertyUtils; 29 import org.openide.util.Utilities; 30 31 44 public final class ModuleDependency implements Comparable <ModuleDependency> { 45 46 private String releaseVersion; 48 private String specVersion; 49 52 private static final String SPEC_VERSION_LAZY = "<lazy>"; private boolean implDep; 54 private boolean compileDep; 55 56 private ModuleEntry me; 57 58 private Set <String > filterTokensNotFriend; 59 private Set <String > filterTokensFriend; 60 61 public static final Comparator <ModuleDependency> LOCALIZED_NAME_COMPARATOR; 62 public static final Comparator <ModuleDependency> CNB_COMPARATOR; 63 64 static { 65 LOCALIZED_NAME_COMPARATOR = new Comparator <ModuleDependency>() { 66 public int compare(ModuleDependency d1, ModuleDependency d2) { 67 ModuleEntry me1 = d1.getModuleEntry(); 68 ModuleEntry me2 = d2.getModuleEntry(); 69 int result = Collator.getInstance().compare( 70 me1.getLocalizedName(), me2.getLocalizedName()); 71 return result != 0 ? result : 72 me1.getCodeNameBase().compareTo(me2.getCodeNameBase()); 73 } 74 }; 75 CNB_COMPARATOR = new Comparator <ModuleDependency>() { 76 public int compare(ModuleDependency d1, ModuleDependency d2) { 77 return d1.getCodeNameBase().compareTo(d2.getCodeNameBase()); 78 } 79 }; 80 } 81 82 88 public ModuleDependency(ModuleEntry me) { 89 this(me, me.getReleaseVersion(), SPEC_VERSION_LAZY, me.getPublicPackages().length > 0, false); 90 } 91 92 public ModuleDependency(ModuleEntry me, String releaseVersion, 93 String specVersion, boolean compileDep, boolean implDep) { 94 this.me = me; 95 96 this.compileDep = compileDep; 98 this.implDep = implDep; 99 this.releaseVersion = releaseVersion; 100 this.specVersion = specVersion; 101 } 102 103 107 public String getReleaseVersion() { 108 return releaseVersion; 109 } 110 111 public String getSpecificationVersion() { 112 if (specVersion == SPEC_VERSION_LAZY) { 113 specVersion = me.getSpecificationVersion(); 114 } 115 return specVersion; 116 } 117 118 public ModuleEntry getModuleEntry() { 119 return me; 120 } 121 122 private String getCodeNameBase() { 123 return getModuleEntry().getCodeNameBase(); 124 } 125 126 public int compareTo(ModuleDependency other) { 127 int result = getCodeNameBase().compareTo(other.getCodeNameBase()); 128 if (result != 0) { return result; } 129 130 String relVersion = other.getReleaseVersion(); 133 result = getReleaseVersion() == null ? (relVersion == null ? 0 : -1) 135 : (relVersion == null ? 1 : getReleaseVersion().compareTo(relVersion)); 136 if (result != 0) { return result; } 137 138 if (specVersion != SPEC_VERSION_LAZY || other.specVersion != SPEC_VERSION_LAZY) { 140 String otherSpec = other.getSpecificationVersion(); 141 String spec = getSpecificationVersion(); 142 result = spec == null ? (otherSpec == null ? 0 : -1) 144 : (otherSpec == null ? 1 : spec.compareTo(otherSpec)); 145 if (result != 0) { return result; } 146 } 147 148 result = hasImplementationDepedendency() == other.hasImplementationDepedendency() ? 0 : (implDep ? 1 : -1); 149 if (result != 0) { return result; } 150 151 result = hasCompileDependency() == other.hasCompileDependency() ? 0 : (compileDep ? 1 : -1); 152 return result; 153 } 154 155 public boolean equals(Object o) { 156 if (o instanceof ModuleDependency) { 157 ModuleDependency other = (ModuleDependency) o; 158 return getCodeNameBase().equals(other.getCodeNameBase()) && 159 Utilities.compareObjects(getReleaseVersion(), other.getReleaseVersion()) && 160 ((specVersion == SPEC_VERSION_LAZY && other.specVersion == SPEC_VERSION_LAZY) || 161 Utilities.compareObjects(getSpecificationVersion(), other.getSpecificationVersion())) && 162 (hasImplementationDepedendency() == other.hasImplementationDepedendency()) && 163 (hasCompileDependency() == other.hasCompileDependency()); 164 } else { 165 return false; 166 } 167 } 168 169 public int hashCode() { 170 return getCodeNameBase().hashCode(); 172 } 173 174 public boolean hasCompileDependency() { 175 return compileDep; 176 } 177 178 public boolean hasImplementationDepedendency() { 179 return implDep; 180 } 181 182 197 Set <String > getFilterTokens(String dependingModuleCNB) { 198 boolean friend = me.isDeclaredAsFriend(dependingModuleCNB); 199 Set <String > filterTokens = friend ? filterTokensFriend : filterTokensNotFriend; 200 if (filterTokens == null) { 201 filterTokens = new HashSet <String >(); 202 filterTokens.add(me.getCodeNameBase()); 203 filterTokens.add(me.getLocalizedName()); 204 filterTokens.add(me.getJarLocation().getAbsolutePath()); 205 String [] cpext = PropertyUtils.tokenizePath(me.getClassPathExtensions()); 206 for (int i = 0; i < cpext.length; i++) { 207 filterTokens.add(cpext[i]); 208 } 209 if (friend) { 210 Iterator it = me.getPublicClassNames().iterator(); 211 while (it.hasNext()) { 212 String clazz = (String ) it.next(); 213 filterTokens.add(clazz.replace('$', '.')); 214 } 215 } 216 if (friend) { 217 filterTokensFriend = filterTokens; 218 } else { 219 filterTokensNotFriend = filterTokens; 220 } 221 } 222 return filterTokens; 223 } 224 225 public String toString() { 226 return "ModuleDependency[me: " + getModuleEntry() + ", relVer: " + getReleaseVersion() + ", specVer: " + getSpecificationVersion() + ", implDep: " + hasImplementationDepedendency() + ", compDep: " + hasCompileDependency() + "]"; } 233 } 234 | Popular Tags |