Search in sources :

Example 16 with DefaultDependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor in project ant-ivy by apache.

the class FileSystemResolverTest method testChanging.

@Test
public void testChanging() 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 + "checkmodified" + FS + "ivy-[revision].xml");
    resolver.addArtifactPattern(settings.getBaseDir() + FS + "test" + FS + "repositories" + FS + "checkmodified" + FS + "[artifact]-[revision].[ext]");
    File modify = new File("test/repositories/checkmodified/ivy-1.0.xml");
    File artifact = new File("test/repositories/checkmodified/mod1.1-1.0.jar");
    // 'publish' 'before' version
    FileUtil.copy(new File("test/repositories/checkmodified/ivy-1.0-before.xml"), modify, null, true);
    FileUtil.copy(new File("test/repositories/checkmodified/mod1.1-1.0-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", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    assertEquals(pubdate, rmr.getPublicationDate());
    Artifact[] artifacts = rmr.getDescriptor().getArtifacts("default");
    resolver.download(artifacts, getDownloadOptions());
    File archiveFileInCache = cacheManager.getArchiveFileInCache(artifacts[0]);
    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/checkmodified/ivy-1.0-after.xml"), modify, null, true);
    FileUtil.copy(new File("test/repositories/checkmodified/mod1.1-1.0-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 not get the new version: checkmodified is false and dependency is not told to be a
    // changing one
    resolver.setCheckmodified(false);
    rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    assertEquals(new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(), rmr.getPublicationDate());
    assertTrue(archiveFileInCache.exists());
    r = new BufferedReader(new FileReader(archiveFileInCache));
    assertEquals("before", r.readLine());
    r.close();
    // should now get the new version cause we say it's a changing one
    rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false, true), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    assertEquals(pubdate, rmr.getPublicationDate());
    assertFalse(archiveFileInCache.exists());
    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 17 with DefaultDependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor 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 18 with DefaultDependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor 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 19 with DefaultDependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor 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 20 with DefaultDependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor 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)

Aggregations

DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)80 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)61 Test (org.junit.Test)60 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)47 GregorianCalendar (java.util.GregorianCalendar)25 Date (java.util.Date)23 Artifact (org.apache.ivy.core.module.descriptor.Artifact)23 File (java.io.File)22 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)19 DownloadReport (org.apache.ivy.core.report.DownloadReport)18 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)16 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)12 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)9 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)9 LatestRevisionStrategy (org.apache.ivy.plugins.latest.LatestRevisionStrategy)7 Configuration (org.apache.ivy.core.module.descriptor.Configuration)6 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)5 ModuleId (org.apache.ivy.core.module.id.ModuleId)5 BufferedReader (java.io.BufferedReader)3 Locale (java.util.Locale)3