Search in sources :

Example 6 with MockResolver

use of org.apache.ivy.plugins.resolver.MockResolver in project ant-ivy by apache.

the class XmlSettingsParserTest method testTypedef.

@Test
public void testTypedef() throws Exception {
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-typedef.xml"));
    DependencyResolver mock = settings.getResolver("mock3");
    assertNotNull(mock);
    assertTrue(mock instanceof MockResolver);
    DependencyResolver internal = settings.getResolver("internal");
    assertNotNull(internal);
    assertTrue(internal instanceof ChainResolver);
    ChainResolver chain = (ChainResolver) internal;
    List<DependencyResolver> subresolvers = chain.getResolvers();
    assertNotNull(subresolvers);
    assertEquals(2, subresolvers.size());
    assertEquals("mock1", subresolvers.get(0).getName());
    assertEquals("mock2", subresolvers.get(1).getName());
    assertTrue(subresolvers.get(0) instanceof MockResolver);
    assertTrue(subresolvers.get(1) instanceof MockResolver);
}
Also used : ChainResolver(org.apache.ivy.plugins.resolver.ChainResolver) MockResolver(org.apache.ivy.plugins.resolver.MockResolver) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) Test(org.junit.Test) ModuleDescriptorParserRegistryTest(org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)

Example 7 with MockResolver

use of org.apache.ivy.plugins.resolver.MockResolver in project ant-ivy by apache.

the class DefaultRepositoryCacheManagerTest method testLatestIntegrationIsCachedPerResolver.

@Test
@Ignore
public void testLatestIntegrationIsCachedPerResolver() throws Exception {
    // given a module org#module
    ModuleId mi = new ModuleId("org", "module");
    // and a latest.integration mrid/dd
    ModuleRevisionId mridLatest = new ModuleRevisionId(mi, "trunk", "latest.integration");
    DependencyDescriptor ddLatest = new DefaultDependencyDescriptor(mridLatest, false);
    // and some random options
    CacheMetadataOptions options = new CacheMetadataOptions().setCheckTTL(false);
    // setup resolver1 to download the static content so we can call cacheModuleDescriptor
    MockResolver resolver = new MockResolver();
    resolver.setName("resolver1");
    resolver.setSettings(ivy.getSettings());
    ivy.getSettings().addResolver(resolver);
    ResourceDownloader downloader = new ResourceDownloader() {

        public void download(Artifact artifact, Resource resource, File dest) throws IOException {
            String content = "<ivy-module version=\"2.0\"><info organisation=\"org\" module=\"module\" status=\"integration\" revision=\"1.1\" branch=\"trunk\"/></ivy-module>";
            dest.getParentFile().mkdirs();
            FileOutputStream out = new FileOutputStream(dest);
            PrintWriter pw = new PrintWriter(out);
            pw.write(content);
            pw.flush();
            out.close();
        }
    };
    ModuleDescriptorWriter writer = new ModuleDescriptorWriter() {

        public void write(ResolvedResource originalMdResource, ModuleDescriptor md, File src, File dest) throws IOException {
            XmlModuleDescriptorWriter.write(md, dest);
        }
    };
    // latest.integration will resolve to 1.1 in resolver1
    ModuleRevisionId mrid11 = new ModuleRevisionId(mi, "trunk", "1.1");
    DefaultArtifact artifact11 = new DefaultArtifact(mrid11, new Date(), "module-1.1.ivy", "ivy", "ivy", true);
    DependencyDescriptor dd11 = new DefaultDependencyDescriptor(mrid11, false);
    BasicResource resource11 = new BasicResource("/module-1-1.ivy", true, 1, 0, true);
    ResolvedResource mdRef11 = new ResolvedResource(resource11, "1.1");
    // tell the cache about 1.1
    ResolvedModuleRevision rmr11 = cacheManager.cacheModuleDescriptor(resolver, mdRef11, dd11, artifact11, downloader, options);
    cacheManager.originalToCachedModuleDescriptor(resolver, mdRef11, artifact11, rmr11, writer);
    // and use the new overload that passes in resolver name
    cacheManager.saveResolvedRevision("resolver1", mridLatest, "1.1");
    ResolvedModuleRevision rmrFromCache = cacheManager.findModuleInCache(ddLatest, mridLatest, options, "resolver1");
    assertEquals(rmr11, rmrFromCache);
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) BasicResource(org.apache.ivy.plugins.repository.BasicResource) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) Resource(org.apache.ivy.plugins.repository.Resource) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) MockResolver(org.apache.ivy.plugins.resolver.MockResolver) ResourceDownloader(org.apache.ivy.plugins.repository.ResourceDownloader) BasicResource(org.apache.ivy.plugins.repository.BasicResource) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Date(java.util.Date) ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) FileOutputStream(java.io.FileOutputStream) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) XmlModuleDescriptorWriter(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter) File(java.io.File) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) PrintWriter(java.io.PrintWriter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with MockResolver

use of org.apache.ivy.plugins.resolver.MockResolver in project ant-ivy by apache.

the class PomModuleDescriptorParserTest method testParentProperties.

@Test
public void testParentProperties() throws ParseException, IOException {
    settings.setDictatorResolver(new MockResolver() {

        public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
            try {
                ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-version.pom"), false);
                return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
    });
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-parent-properties.pom"), false);
    assertNotNull(md);
    assertEquals("1.0", md.getRevision());
    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(3, dds.length);
    // 2 are inherited from parent. Only the first one is important for this test
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-version-other", "5.76"), dds[0].getDependencyRevisionId());
// present in the pom using a property defined in the parent
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) MockResolver(org.apache.ivy.plugins.resolver.MockResolver) ParseException(java.text.ParseException) IOException(java.io.IOException) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Example 9 with MockResolver

use of org.apache.ivy.plugins.resolver.MockResolver in project ant-ivy by apache.

the class PomModuleDescriptorParserTest method testParentDependencyMgt.

@Test
public void testParentDependencyMgt() throws ParseException, IOException {
    settings.setDictatorResolver(new MockResolver() {

        public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
            try {
                ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-dependencyMgt.pom"), false);
                return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
    });
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-parentDependencyMgt.pom"), false);
    assertNotNull(md);
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-parentdep", "1.0"), md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(2, dds.length);
    assertEquals(ModuleRevisionId.newInstance("commons-collection", "commons-collection", "1.0.5"), dds[0].getDependencyRevisionId());
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), dds[1].getDependencyRevisionId());
    ExcludeRule[] excludes = dds[0].getAllExcludeRules();
    assertNotNull(excludes);
    assertEquals(2, excludes.length);
    assertEquals("javax.mail", excludes[0].getId().getModuleId().getOrganisation());
    assertEquals("mail", excludes[0].getId().getModuleId().getName());
    assertEquals("javax.jms", excludes[1].getId().getModuleId().getOrganisation());
    assertEquals("jms", excludes[1].getId().getModuleId().getName());
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) MockResolver(org.apache.ivy.plugins.resolver.MockResolver) ParseException(java.text.ParseException) IOException(java.io.IOException) ExcludeRule(org.apache.ivy.core.module.descriptor.ExcludeRule) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Example 10 with MockResolver

use of org.apache.ivy.plugins.resolver.MockResolver in project ant-ivy by apache.

the class PomModuleDescriptorParserTest method testOverrideParentProperties.

@Test
public void testOverrideParentProperties() throws ParseException, IOException {
    settings.setDictatorResolver(new MockResolver() {

        public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
            try {
                ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-version.pom"), false);
                return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
    });
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-override-parent-properties.pom"), false);
    assertNotNull(md);
    assertEquals("1.0", md.getRevision());
    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(2, dds.length);
    // 2 are inherited from parent. Only the first one is important for this test
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-yet-other", "5.79"), dds[1].getDependencyRevisionId());
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) MockResolver(org.apache.ivy.plugins.resolver.MockResolver) ParseException(java.text.ParseException) IOException(java.io.IOException) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Aggregations

MockResolver (org.apache.ivy.plugins.resolver.MockResolver)10 Test (org.junit.Test)10 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)9 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)9 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)9 IOException (java.io.IOException)8 ParseException (java.text.ParseException)8 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)8 ResolveData (org.apache.ivy.core.resolve.ResolveData)8 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)8 ExcludeRule (org.apache.ivy.core.module.descriptor.ExcludeRule)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 PrintWriter (java.io.PrintWriter)1 Date (java.util.Date)1 Artifact (org.apache.ivy.core.module.descriptor.Artifact)1 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)1 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)1 ModuleId (org.apache.ivy.core.module.id.ModuleId)1 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)1