001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.plugins.resolver;
019:
020: import java.io.File;
021: import java.util.List;
022:
023: import org.apache.ivy.core.event.EventManager;
024: import org.apache.ivy.core.module.descriptor.Artifact;
025: import org.apache.ivy.core.module.descriptor.DefaultArtifact;
026: import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor;
027: import org.apache.ivy.core.module.id.ModuleRevisionId;
028: import org.apache.ivy.core.report.ArtifactDownloadReport;
029: import org.apache.ivy.core.report.DownloadReport;
030: import org.apache.ivy.core.report.DownloadStatus;
031: import org.apache.ivy.core.resolve.ResolveData;
032: import org.apache.ivy.core.resolve.ResolveEngine;
033: import org.apache.ivy.core.resolve.ResolveOptions;
034: import org.apache.ivy.core.resolve.ResolvedModuleRevision;
035: import org.apache.ivy.core.settings.IvySettings;
036: import org.apache.ivy.core.sort.SortEngine;
037: import org.apache.tools.ant.Project;
038: import org.apache.tools.ant.taskdefs.Delete;
039:
040: /**
041: *
042: */
043: public class IvyRepResolverTest extends AbstractDependencyResolverTest {
044: private IvySettings _settings;
045:
046: private ResolveEngine _engine;
047:
048: private ResolveData _data;
049:
050: private File _cache;
051:
052: protected void setUp() throws Exception {
053: _settings = new IvySettings();
054: _engine = new ResolveEngine(_settings, new EventManager(),
055: new SortEngine(_settings));
056: _cache = new File("build/cache");
057: _data = new ResolveData(_engine, new ResolveOptions());
058: _cache.mkdirs();
059: _settings.setDefaultCache(_cache);
060: }
061:
062: protected void tearDown() throws Exception {
063: Delete del = new Delete();
064: del.setProject(new Project());
065: del.setDir(_cache);
066: del.execute();
067: }
068:
069: public void testDefaults() {
070: IvyRepResolver resolver = new IvyRepResolver();
071: _settings.setVariable("ivy.ivyrep.default.ivy.root",
072: "http://www.jayasoft.fr/myivyrep/");
073: _settings.setVariable("ivy.ivyrep.default.ivy.pattern",
074: "[organisation]/[module]/ivy-[revision].[ext]");
075: _settings.setVariable("ivy.ivyrep.default.artifact.root",
076: "http://www.ibiblio.org/mymaven/");
077: _settings.setVariable("ivy.ivyrep.default.artifact.pattern",
078: "[module]/jars/[artifact]-[revision].jar");
079: resolver.setSettings(_settings);
080: List l = resolver.getIvyPatterns();
081: assertNotNull(l);
082: assertEquals(1, l.size());
083: assertEquals(
084: "http://www.jayasoft.fr/myivyrep/[organisation]/[module]/ivy-[revision].[ext]",
085: l.get(0));
086: l = resolver.getArtifactPatterns();
087: assertNotNull(l);
088: assertEquals(1, l.size());
089: assertEquals(
090: "http://www.ibiblio.org/mymaven/[module]/jars/[artifact]-[revision].jar",
091: l.get(0));
092: }
093:
094: public void testMandatoryRoot() throws Exception {
095: // IVY-625: should fail if no ivyroot specified
096: IvyRepResolver resolver = new IvyRepResolver();
097: resolver.setName("test");
098: resolver.setSettings(_settings);
099:
100: ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache",
101: "commons-cli", "1.0");
102: try {
103: resolver.getDependency(new DefaultDependencyDescriptor(
104: mrid, false), _data);
105: fail("using ivyrep resolver without ivyroot should raise an exception");
106: } catch (IllegalStateException ex) {
107: assertTrue(
108: "exception thrown when using ivyrep with no ivyroot should talk about the root",
109: ex.getMessage().indexOf("ivyroot") != -1);
110: }
111: }
112:
113: public void testIvyRepWithLocalURL() throws Exception {
114: IvyRepResolver resolver = new IvyRepResolver();
115: String rootpath = new File("test/repositories/1")
116: .getAbsolutePath();
117:
118: resolver.setName("testLocal");
119: resolver.setIvyroot("file:" + rootpath);
120: resolver
121: .setIvypattern("[organisation]/[module]/ivys/ivy-[revision].xml");
122: resolver.setArtroot("file:" + rootpath);
123: resolver
124: .setArtpattern("[organisation]/[module]/jars/[artifact]-[revision].[ext]");
125: resolver.setSettings(_settings);
126:
127: ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
128: "mod1.1", "1.0");
129: ResolvedModuleRevision rmr = resolver.getDependency(
130: new DefaultDependencyDescriptor(mrid, false), _data);
131: assertNotNull(rmr);
132:
133: DefaultArtifact artifact = new DefaultArtifact(mrid, rmr
134: .getPublicationDate(), "mod1.1", "jar", "jar");
135: DownloadReport report = resolver.download(
136: new Artifact[] { artifact }, downloadOptions());
137: assertNotNull(report);
138:
139: assertEquals(1, report.getArtifactsReports().length);
140:
141: ArtifactDownloadReport ar = report.getArtifactReport(artifact);
142: assertNotNull(ar);
143:
144: assertEquals(artifact, ar.getArtifact());
145: assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
146:
147: // test to ask to download again, should use cache
148: report = resolver.download(new Artifact[] { artifact },
149: downloadOptions());
150: assertNotNull(report);
151:
152: assertEquals(1, report.getArtifactsReports().length);
153:
154: ar = report.getArtifactReport(artifact);
155: assertNotNull(ar);
156:
157: assertEquals(artifact, ar.getArtifact());
158: assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
159: }
160: }
|