1 6 package fr.jayasoft.ivy.resolver; 7 8 import java.io.File ; 9 import java.text.ParseException ; 10 import java.util.Collections ; 11 import java.util.Date ; 12 import java.util.List ; 13 import java.util.Map ; 14 15 import fr.jayasoft.ivy.Artifact; 16 import fr.jayasoft.ivy.DefaultArtifact; 17 import fr.jayasoft.ivy.DependencyDescriptor; 18 import fr.jayasoft.ivy.Ivy; 19 import fr.jayasoft.ivy.ModuleRevisionId; 20 import fr.jayasoft.ivy.ResolveData; 21 import fr.jayasoft.ivy.ResolvedModuleRevision; 22 import fr.jayasoft.ivy.report.DownloadReport; 23 import fr.jayasoft.ivy.util.IvyPatternHelper; 24 25 30 public class IBiblioResolver extends URLResolver { 31 public static final String DEFAULT_PATTERN = "[module]/[type]s/[artifact]-[revision].[ext]"; 32 public static final String DEFAULT_ROOT = "http://www.ibiblio.org/maven/"; 33 private String _root = null; 34 private String _pattern = null; 35 36 private boolean _usepoms = true; 38 39 public IBiblioResolver() { 40 } 41 42 protected ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data) { 43 if (isM2compatible() && isUsepoms()) { 44 ModuleRevisionId mrid = dd.getDependencyRevisionId(); 45 mrid = convertM2IdForResourceSearch(mrid); 46 ResolvedResource rres = findResourceUsingPatterns(mrid, getIvyPatterns(), DefaultArtifact.newPomArtifact(mrid, data.getDate()), getRMDParser(dd, data), data.getDate()); 47 return rres; 48 } else { 49 return null; 50 } 51 } 52 53 protected void logIvyNotFound(ModuleRevisionId mrid) { 54 if (isM2compatible() && isUsepoms()) { 55 Artifact artifact = DefaultArtifact.newPomArtifact(mrid, null); 56 logMdNotFound(mrid, artifact); 57 } 58 } 59 60 public void setM2compatible(boolean m2compatible) { 61 super.setM2compatible(m2compatible); 62 if (m2compatible) { 63 _root = "http://www.ibiblio.org/maven2/"; 64 _pattern = "[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"; 65 updateWholePattern(); 66 } 67 } 68 69 public void ensureConfigured(Ivy ivy) { 70 if (ivy != null && (_root == null || _pattern == null)) { 71 if (_root == null) { 72 String root = ivy.getVariable("ivy.ibiblio.default.artifact.root"); 73 if (root != null) { 74 _root = root; 75 } else { 76 ivy.configureRepositories(true); 77 _root = ivy.getVariable("ivy.ibiblio.default.artifact.root"); 78 } 79 } 80 if (_pattern == null) { 81 String pattern = ivy.getVariable("ivy.ibiblio.default.artifact.pattern"); 82 if (pattern != null) { 83 _pattern = pattern; 84 } else { 85 ivy.configureRepositories(false); 86 _pattern = ivy.getVariable("ivy.ibiblio.default.artifact.pattern"); 87 } 88 } 89 updateWholePattern(); 90 } 91 } 92 93 private String getWholePattern() { 94 return _root + _pattern; 95 } 96 public String getPattern() { 97 return _pattern; 98 } 99 public void setPattern(String pattern) { 100 if (pattern == null) { 101 throw new NullPointerException ("pattern must not be null"); 102 } 103 _pattern = pattern; 104 ensureConfigured(getIvy()); 105 updateWholePattern(); 106 } 107 public String getRoot() { 108 return _root; 109 } 110 116 public void setRoot(String root) { 117 if (root == null) { 118 throw new NullPointerException ("root must not be null"); 119 } 120 if (!root.endsWith("/")) { 121 _root = root + "/"; 122 } else { 123 _root = root; 124 } 125 ensureConfigured(getIvy()); 126 updateWholePattern(); 127 } 128 129 private void updateWholePattern() { 130 if (isM2compatible() && isUsepoms()) { 131 setIvyPatterns(Collections.singletonList(getWholePattern())); 132 } 133 setArtifactPatterns(Collections.singletonList(getWholePattern())); 134 } 135 public void publish(Artifact artifact, File src) { 136 throw new UnsupportedOperationException ("publish not supported by IBiblioResolver"); 137 } 138 public String [] listTokenValues(String token, Map otherTokenValues) { 140 if (IvyPatternHelper.ORGANISATION_KEY.equals(token)) { 141 return new String [0]; 142 } 143 if (IvyPatternHelper.MODULE_KEY.equals(token) && !isM2compatible()) { 144 return new String [0]; 145 } 146 ensureConfigured(getIvy()); 147 return super.listTokenValues(token, otherTokenValues); 148 } 149 public OrganisationEntry[] listOrganisations() { 150 return new OrganisationEntry[0]; 151 } 152 public ModuleEntry[] listModules(OrganisationEntry org) { 153 if (isM2compatible()) { 154 ensureConfigured(getIvy()); 155 return super.listModules(org); 156 } 157 return new ModuleEntry[0]; 158 } 159 public RevisionEntry[] listRevisions(ModuleEntry mod) { 160 ensureConfigured(getIvy()); 161 return super.listRevisions(mod); 162 } 163 public String getTypeName() { 164 return "ibiblio"; 165 } 166 167 public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException { 169 ensureConfigured(data.getIvy()); 170 return super.getDependency(dd, data); 171 } 172 173 protected ResolvedResource findArtifactRef(Artifact artifact, Date date) { 174 ensureConfigured(getIvy()); 175 return super.findArtifactRef(artifact, date); 176 } 177 178 public DownloadReport download(Artifact[] artifacts, Ivy ivy, File cache, boolean useOrigin) { 179 ensureConfigured(ivy); 180 return super.download(artifacts, ivy, cache, useOrigin); 181 } 182 public boolean exists(Artifact artifact) { 183 ensureConfigured(getIvy()); 184 return super.exists(artifact); 185 } 186 public List getArtifactPatterns() { 187 ensureConfigured(getIvy()); 188 return super.getArtifactPatterns(); 189 } 190 191 public boolean isUsepoms() { 192 return _usepoms; 193 } 194 195 public void setUsepoms(boolean usepoms) { 196 _usepoms = usepoms; 197 updateWholePattern(); 198 } 199 } 200 | Popular Tags |