Search in sources :

Example 21 with ResolvedModuleRevision

use of org.apache.ivy.core.resolve.ResolvedModuleRevision in project ant-ivy by apache.

the class FileSystemResolverTest method testNoRevision.

@Test
public void testNoRevision() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    settings.addResolver(resolver);
    assertEquals("test", resolver.getName());
    resolver.addIvyPattern(settings.getBaseDir() + FS + "test" + FS + "repositories" + FS + "norevision" + FS + "ivy-[module].xml");
    resolver.addArtifactPattern(settings.getBaseDir() + FS + "test" + FS + "repositories" + FS + "norevision" + FS + "[artifact].[ext]");
    File modify = new File("test/repositories/norevision/ivy-mod1.1.xml");
    File artifact = new File("test/repositories/norevision/mod1.1.jar");
    // 'publish' 'before' version
    FileUtil.copy(new File("test/repositories/norevision/ivy-mod1.1-before.xml"), modify, null, true);
    FileUtil.copy(new File("test/repositories/norevision/mod1.1-before.jar"), artifact, null, true);
    Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
    modify.setLastModified(pubdate.getTime());
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "latest.integration");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), rmr.getId());
    assertEquals(pubdate, rmr.getPublicationDate());
    Artifact[] artifacts = rmr.getDescriptor().getArtifacts("default");
    File archiveFileInCache = cacheManager.getArchiveFileInCache(artifacts[0]);
    resolver.download(artifacts, getDownloadOptions());
    assertTrue(archiveFileInCache.exists());
    BufferedReader r = new BufferedReader(new FileReader(archiveFileInCache));
    assertEquals("before", r.readLine());
    r.close();
    // updates ivy file and artifact in repository
    FileUtil.copy(new File("test/repositories/norevision/ivy-mod1.1-after.xml"), modify, null, true);
    FileUtil.copy(new File("test/repositories/norevision/mod1.1-after.jar"), artifact, null, true);
    pubdate = new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime();
    modify.setLastModified(pubdate.getTime());
    // no need to update new artifact timestamp cause it isn't used
    // should get the new version even if checkModified is false, because we ask a
    // latest.integration
    resolver.setCheckmodified(false);
    rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1", "1.1"), rmr.getId());
    assertEquals(pubdate, rmr.getPublicationDate());
    artifacts = rmr.getDescriptor().getArtifacts("default");
    archiveFileInCache = cacheManager.getArchiveFileInCache(artifacts[0]);
    assertFalse(archiveFileInCache.exists());
    // should download the new artifact
    artifacts = rmr.getDescriptor().getArtifacts("default");
    resolver.download(artifacts, getDownloadOptions());
    assertTrue(archiveFileInCache.exists());
    r = new BufferedReader(new FileReader(archiveFileInCache));
    assertEquals("after", r.readLine());
    r.close();
}
Also used : GregorianCalendar(java.util.GregorianCalendar) BufferedReader(java.io.BufferedReader) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) FileReader(java.io.FileReader) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) File(java.io.File) Date(java.util.Date) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 22 with ResolvedModuleRevision

use of org.apache.ivy.core.resolve.ResolvedModuleRevision in project ant-ivy by apache.

the class IBiblioResolverTest method testErrorReport.

@Test
public void testErrorReport() throws Exception {
    IBiblioResolver resolver = new IBiblioResolver();
    resolver.setRoot("http://unknown.host.comx/");
    resolver.setName("test");
    resolver.setM2compatible(true);
    resolver.setSettings(settings);
    assertEquals("test", resolver.getName());
    MockMessageLogger mockMessageImpl = new MockMessageLogger();
    IvyContext.getContext().getIvy().getLoggerEngine().setDefaultLogger(mockMessageImpl);
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "commons-fileupload", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNull(rmr);
    mockMessageImpl.assertLogContains("tried http://unknown.host.comx/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.pom");
    mockMessageImpl.assertLogContains("tried http://unknown.host.comx/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.jar");
}
Also used : ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) MockMessageLogger(org.apache.ivy.util.MockMessageLogger) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Test(org.junit.Test)

Example 23 with ResolvedModuleRevision

use of org.apache.ivy.core.resolve.ResolvedModuleRevision in project ant-ivy by apache.

the class JarResolverTest method testSubdirInFile.

@Test
public void testSubdirInFile() throws Exception {
    JarResolver resolver = new JarResolver();
    resolver.setName("jarresolver1_subdir");
    resolver.setFile(new File("test/jar-repos/jarrepo1_subdir.jar").getAbsolutePath());
    resolver.addIvyPattern("1/[organisation]/[module]/ivys/ivy-[revision].xml");
    resolver.addArtifactPattern("1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
    resolver.setSettings(settings);
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
}
Also used : ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) File(java.io.File) Test(org.junit.Test)

Example 24 with ResolvedModuleRevision

use of org.apache.ivy.core.resolve.ResolvedModuleRevision in project ant-ivy by apache.

the class BintrayResolverTest method testBintrayArtifacts.

@Test
public void testBintrayArtifacts() throws Exception {
    BintrayResolver resolver = new BintrayResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    assertEquals("test", resolver.getName());
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache.ant", "ant-antunit", "1.2");
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mrid, false);
    dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), "ant-antunit", "javadoc", "jar"), ExactPatternMatcher.INSTANCE, null));
    dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), "ant-antunit", "sources", "jar"), ExactPatternMatcher.INSTANCE, null));
    ResolvedModuleRevision rmr = resolver.getDependency(dd, data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    DefaultArtifact profiler = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit", "javadoc", "jar");
    DefaultArtifact trace = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit", "sources", "jar");
    DownloadReport report = resolver.download(new Artifact[] { profiler, trace }, downloadOptions());
    assertNotNull(report);
    assertEquals(2, report.getArtifactsReports().length);
    ArtifactDownloadReport ar = report.getArtifactReport(profiler);
    assertNotNull(ar);
    assertEquals(profiler, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    ar = report.getArtifactReport(trace);
    assertNotNull(ar);
    assertEquals(trace, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    // test to ask to download again, should use cache
    report = resolver.download(new Artifact[] { profiler, trace }, downloadOptions());
    assertNotNull(report);
    assertEquals(2, report.getArtifactsReports().length);
    ar = report.getArtifactReport(profiler);
    assertNotNull(ar);
    assertEquals(profiler, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
    ar = report.getArtifactReport(trace);
    assertNotNull(ar);
    assertEquals(trace, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactId(org.apache.ivy.core.module.id.ArtifactId) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultIncludeRule(org.apache.ivy.core.module.descriptor.DefaultIncludeRule) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 25 with ResolvedModuleRevision

use of org.apache.ivy.core.resolve.ResolvedModuleRevision in project ant-ivy by apache.

the class BintrayResolverTest method testErrorReport.

@Test
public void testErrorReport() throws Exception {
    BintrayResolver resolver = new BintrayResolver();
    resolver.setSubject("unknown");
    resolver.setRepo("unknown");
    resolver.setName("test");
    resolver.setM2compatible(true);
    resolver.setSettings(settings);
    assertEquals("test", resolver.getName());
    MockMessageLogger mockMessageImpl = new MockMessageLogger();
    IvyContext.getContext().getIvy().getLoggerEngine().setDefaultLogger(mockMessageImpl);
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "commons-fileupload", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNull(rmr);
    mockMessageImpl.assertLogContains("trying https://dl.bintray.com/unknown/unknown/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.jar");
    mockMessageImpl.assertLogContains("tried https://dl.bintray.com/unknown/unknown/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.jar");
}
Also used : ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) MockMessageLogger(org.apache.ivy.util.MockMessageLogger) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Test(org.junit.Test)

Aggregations

ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)89 Test (org.junit.Test)63 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)61 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)45 Artifact (org.apache.ivy.core.module.descriptor.Artifact)25 GregorianCalendar (java.util.GregorianCalendar)24 File (java.io.File)19 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)19 Date (java.util.Date)18 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)18 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)18 DownloadReport (org.apache.ivy.core.report.DownloadReport)18 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)17 IOException (java.io.IOException)14 ParseException (java.text.ParseException)14 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)13 ResolveData (org.apache.ivy.core.resolve.ResolveData)11 MockResolver (org.apache.ivy.plugins.resolver.MockResolver)9 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)8 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)8