org.apache.ivy.core.resolve.ResolvedModuleRevision Java Examples

The following examples show how to use org.apache.ivy.core.resolve.ResolvedModuleRevision. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OsgiLatestStrategy.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private ModuleRevisionId getImplMrid(ArtifactInfo o) {
    if (!(o instanceof MDResolvedResource)) {
        return null;
    }
    MDResolvedResource mdrr = (MDResolvedResource) o;
    ResolvedModuleRevision rmr = mdrr.getResolvedModuleRevision();
    if (rmr == null) {
        return null;
    }
    ModuleDescriptor md = rmr.getDescriptor();
    if (md == null) {
        return null;
    }
    if (!md.getModuleRevisionId().getOrganisation().equals(BundleInfo.PACKAGE_TYPE)) {
        return null;
    }
    DependencyDescriptor[] dds = md.getDependencies();
    if (dds == null || dds.length != 1) {
        return null;
    }
    return dds[0].getDependencyRevisionId();
}
 
Example #2
Source File: ChainResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolveOrder() throws Exception {
    ChainResolver chain = new ChainResolver();
    chain.setName("chain");
    chain.setSettings(settings);
    MockResolver[] resolvers = new MockResolver[] {
            MockResolver.buildMockResolver(settings, "1", false, null),
            MockResolver.buildMockResolver(settings, "2", true, null),
            MockResolver.buildMockResolver(settings, "3", true, null)};
    for (MockResolver resolver : resolvers) {
        chain.add(resolver);
    }
    assertResolversSizeAndNames(chain, resolvers.length);

    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
            ModuleRevisionId.newInstance("org", "mod", "rev"), false);
    ResolvedModuleRevision rmr = chain.getDependency(dd, data);
    assertNotNull(rmr);
    assertEquals("2", rmr.getResolver().getName());
    assertEquals(Collections.<DependencyDescriptor> singletonList(dd), resolvers[0].askedDeps);
    assertEquals(Collections.<DependencyDescriptor> singletonList(dd), resolvers[1].askedDeps);
    assertTrue(resolvers[2].askedDeps.isEmpty());
}
 
Example #3
Source File: ChainResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Test case for IVY-389.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-389">IVY-389</a>
 */
@Test
public void testReturnFirstWithDefaultAndCacheAndRealResolver() throws Exception {
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
            ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), false);

    // 1 ---- we first do a first resolve which puts a default file in cache
    chainToPutDefaultModuleInCache().getDependency(dd, data);

    // 2 ---- now we ask to resolve dependencies with a chain in return first mode with check
    // modified = false, in which the first resolver is not able to find the module, but the
    // second is
    ChainResolver chain = returnFirstChain();

    ResolvedModuleRevision rmr = chain.getDependency(dd, data);
    assertNotNull(rmr);
    // the module returned should be the default one found in cache since check modified is
    // false
    assertTrue(rmr.getDescriptor().isDefault());
}
 
Example #4
Source File: FileSystemResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormattedLatestTime() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    assertEquals("test", resolver.getName());

    resolver.addIvyPattern(IVY_PATTERN);
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/"
            + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");

    resolver.setLatestStrategy(new LatestTimeStrategy());

    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.1");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(
            ModuleRevisionId.newInstance("org1", "mod1.1", "1+"), false), data);
    assertNotNull(rmr);

    assertEquals(mrid, rmr.getId());
    Date pubdate = new GregorianCalendar(2005, 0, 2, 11, 0, 0).getTime();
    assertEquals(pubdate, rmr.getPublicationDate());
}
 
Example #5
Source File: DualResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolve() throws Exception {
    DualResolver dual = new DualResolver();
    MockResolver ivyResolver = MockResolver.buildMockResolver(settings, "ivy", true,
        new GregorianCalendar(2005, 1, 20).getTime());
    MockResolver artifactResolver = MockResolver.buildMockResolver(settings, "artifact",
        false, new GregorianCalendar(2005, 1, 20).getTime());
    dual.setIvyResolver(ivyResolver);
    dual.setArtifactResolver(artifactResolver);
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
            ModuleRevisionId.newInstance("org", "mod", "rev"), false);
    ResolvedModuleRevision rmr = dual.getDependency(dd, data);

    assertNotNull(rmr);
    assertEquals(dual, rmr.getArtifactResolver());
    assertEquals(Collections.<DependencyDescriptor> singletonList(dd), ivyResolver.askedDeps);
    assertTrue(artifactResolver.askedDeps.isEmpty());
}
 
Example #6
Source File: UpdateSiteAndIbiblioResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testArtifactRef() throws ParseException {

    // Simple Dependency for ibiblio
    ModuleRevisionId mrid1 = ModuleRevisionId.newInstance("log4j", "log4j", "1.2.16");
    ResolvedModuleRevision rmr1 = chain.getDependency(new DefaultDependencyDescriptor(mrid1,
            false), data);

    // Simple Dependency for updatesite
    ModuleRevisionId mrid2 = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE,
        "org.apache.ivy", "2.0.0.final_20090108225011");
    ResolvedModuleRevision rmr2 = chain.getDependency(new DefaultDependencyDescriptor(mrid2,
            false), data);

    assertNotNull(rmr1);
    assertNotNull(rmr2);

    Artifact[] artifacts1 = rmr1.getDescriptor().getArtifacts("default");
    Artifact[] artifacts2 = rmr2.getDescriptor().getArtifacts("default");

    chain.exists(artifacts2[0]);
    chain.exists(artifacts1[0]);
}
 
Example #7
Source File: DualResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolveFromArtifact() throws Exception {
    DualResolver dual = new DualResolver();
    MockResolver ivyResolver = MockResolver.buildMockResolver(settings, "ivy", false,
        new GregorianCalendar(2005, 1, 20).getTime());
    MockResolver artifactResolver = MockResolver.buildMockResolver(settings, "artifact", true,
        new GregorianCalendar(2005, 1, 20).getTime());
    dual.setIvyResolver(ivyResolver);
    dual.setArtifactResolver(artifactResolver);
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
            ModuleRevisionId.newInstance("org", "mod", "rev"), false);
    ResolvedModuleRevision rmr = dual.getDependency(dd, data);

    assertNotNull(rmr);
    assertEquals(artifactResolver, rmr.getResolver());
    assertEquals(Collections.<DependencyDescriptor> singletonList(dd), ivyResolver.askedDeps);
    assertEquals(Collections.<DependencyDescriptor> singletonList(dd), artifactResolver.askedDeps);
}
 
Example #8
Source File: FileSystemResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testMaven2() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    resolver.setM2compatible(true);
    assertEquals("test", resolver.getName());

    resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/m2/"
            + "[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/m2/"
            + "[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");

    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid,
            false), data);
    assertNotNull(rmr);

    mrid = ModuleRevisionId.newInstance("org.apache.unknown", "test", "1.0");
    rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNull(rmr);
    resolver.reportFailure();
}
 
Example #9
Source File: FileSystemResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testLatestTime() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    assertEquals("test", resolver.getName());

    resolver.addIvyPattern(IVY_PATTERN);
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/"
            + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");

    resolver.setLatestStrategy(new LatestTimeStrategy());

    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "2.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(
            ModuleRevisionId.newInstance("org1", "mod1.1", "latest.integration"), false), data);
    assertNotNull(rmr);

    assertEquals(mrid, rmr.getId());
    Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0).getTime();
    assertEquals(pubdate, rmr.getPublicationDate());
}
 
Example #10
Source File: LoopbackDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ResolvedModuleRevision getDependency(final DependencyDescriptor dd, final ResolveData data) throws ParseException {
    final DependencyResolver loopback = this;
    return cacheLockingManager.useCache(String.format("Resolve %s", dd), new Factory<ResolvedModuleRevision>() {
        public ResolvedModuleRevision create() {
            DefaultBuildableComponentResolveResult result = new DefaultBuildableComponentResolveResult();
            DefaultDependencyMetaData dependency = new DefaultDependencyMetaData(dd);
            IvyContext ivyContext = IvyContext.pushNewCopyContext();
            try {
                ivyContext.setResolveData(data);
                dependencyResolver.resolve(dependency, result);
            } finally {
                IvyContext.popContext();
            }
            return new ResolvedModuleRevision(loopback, loopback, result.getMetaData().getDescriptor(), null);
        }
    });
}
 
Example #11
Source File: EndResolveDependencyEvent.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public EndResolveDependencyEvent(DependencyResolver resolver, DependencyDescriptor dd,
        ModuleRevisionId requestedRevisionId, ResolvedModuleRevision module, long duration) {
    super(NAME, resolver, dd, requestedRevisionId);
    this.module = module;
    this.duration = duration;
    addAttribute("duration", String.valueOf(duration));
    if (this.module != null) {
        // override revision from the dependency descriptor
        addAttribute("revision", this.module.getDescriptor().getResolvedModuleRevisionId()
                .getRevision());
        // now that we have loaded the dependency descriptor, we can put the extra attributes
        // contained in the descriptor too
        addAttributes(this.module.getDescriptor().getResolvedModuleRevisionId()
                .getQualifiedExtraAttributes());
        addAttributes(this.module.getDescriptor().getResolvedModuleRevisionId()
                .getExtraAttributes());

        addAttribute("resolved", "true");
    } else {
        addAttribute("resolved", "false");
    }
}
 
Example #12
Source File: URLResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testLatestFileWithOpaqueURL() throws Exception {
    URLResolver resolver = new URLResolver();
    resolver.setSettings(settings);
    String rootpath = new File("test/repositories/1").getAbsoluteFile().toURI().toURL()
            .toExternalForm();
    resolver.addIvyPattern(rootpath + "/[organisation]/[module]/ivys/ivy-[revision].xml");
    resolver.addArtifactPattern(rootpath
            + "/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
    resolver.setName("test");
    assertEquals("test", resolver.getName());

    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "2.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(
            ModuleRevisionId.newInstance("org1", "mod1.1", "latest.integration"), false), data);
    assertNotNull(rmr);

    assertEquals(mrid, rmr.getId());
    Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0).getTime();
    assertEquals(pubdate, rmr.getPublicationDate());
}
 
Example #13
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
protected ResourceMDParser getRMDParser(final DependencyDescriptor dd, final ResolveData data) {
    return new ResourceMDParser() {
        public MDResolvedResource parse(Resource resource, String rev) {
            try {
                ResolvedModuleRevision rmr = BasicResolver.this.parse(new ResolvedResource(
                        resource, rev), dd, data);
                if (rmr != null) {
                    return new MDResolvedResource(resource, rev, rmr);
                }
            } catch (ParseException e) {
                Message.warn("Failed to parse the file '" + resource + "'", e);
            }
            return null;
        }

    };
}
 
Example #14
Source File: FileSystemResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that <code>SHA-256</code> algorithm can be used for checksums on resolvers
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testSHA256Checksum() throws Exception {
    final FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("sha256-checksum-resolver");
    resolver.setSettings(settings);

    resolver.addIvyPattern(settings.getBaseDir()
            + "/test/repositories/checksums/[module]/[revision]/[artifact]-[revision].[ext]");
    resolver.addArtifactPattern(settings.getBaseDir()
            + "/test/repositories/checksums/[module]/[revision]/[artifact]-[revision].[ext]");

    resolver.setChecksums("SHA-256");
    final ModuleRevisionId mrid = ModuleRevisionId.newInstance("test", "allright", "2.0");
    final ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull("Resolved module revision was null for " + mrid, rmr);
    final DownloadReport dr = resolver.download(rmr.getDescriptor().getAllArtifacts(), getDownloadOptions());
    final ArtifactDownloadReport[] successfulDownloadReports = dr.getArtifactsReports(DownloadStatus.SUCCESSFUL);
    assertNotNull("No artifacts were downloaded successfully", successfulDownloadReports);
    assertEquals("Unexpected number of successfully downloaded artifacts", 1, successfulDownloadReports.length);
    final ArtifactDownloadReport successfulDownloadReport = successfulDownloadReports[0];
    final Artifact downloadedArtifact = successfulDownloadReport.getArtifact();
    assertEquals("Unexpected organization of downloaded artifact", "test", downloadedArtifact.getModuleRevisionId().getOrganisation());
    assertEquals("Unexpected module of downloaded artifact", "allright", downloadedArtifact.getModuleRevisionId().getModuleId().getName());
    assertEquals("Unexpected revision of downloaded artifact", "2.0", downloadedArtifact.getModuleRevisionId().getRevision());
}
 
Example #15
Source File: LocalFileRepositoryCacheManager.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ResolvedModuleRevision cacheModuleDescriptor(DependencyResolver resolver, ResolvedResource resolvedResource, DependencyDescriptor dd, Artifact moduleArtifact, ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException {
    if (!moduleArtifact.isMetadata()) {
        return null;
    }

    assert resolvedResource.getResource().isLocal();
    File file = new File(resolvedResource.getResource().getName());
    assert file.isFile();

    ArtifactOrigin origin = new ArtifactOrigin(moduleArtifact, true, file.getAbsolutePath());
    MetadataArtifactDownloadReport report = new MetadataArtifactDownloadReport(moduleArtifact);
    report.setDownloadStatus(DownloadStatus.NO);
    report.setArtifactOrigin(origin);
    report.setSize(file.length());
    report.setLocalFile(file);
    report.setSearched(false);
    report.setOriginalLocalFile(file);

    ModuleDescriptor descriptor = parseModuleDescriptor(resolver, moduleArtifact, options, file, resolvedResource.getResource());
    return new ResolvedModuleRevision(resolver, resolver, descriptor, report);
}
 
Example #16
Source File: DualResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolveFail() throws Exception {
    DualResolver dual = new DualResolver();
    MockResolver ivyResolver = MockResolver.buildMockResolver(settings, "ivy", false,
        new GregorianCalendar(2005, 1, 20).getTime());
    MockResolver artifactResolver = MockResolver.buildMockResolver(settings, "artifact",
        false, new GregorianCalendar(2005, 1, 20).getTime());
    dual.setIvyResolver(ivyResolver);
    dual.setArtifactResolver(artifactResolver);
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
            ModuleRevisionId.newInstance("org", "mod", "rev"), false);
    ResolvedModuleRevision rmr = dual.getDependency(dd, data);

    assertNull(rmr);
    assertEquals(Collections.<DependencyDescriptor> singletonList(dd), ivyResolver.askedDeps);
    assertEquals(Collections.<DependencyDescriptor> singletonList(dd), artifactResolver.askedDeps);
}
 
Example #17
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public ResolvedModuleRevision findModuleInCache(DependencyDescriptor dd,
        ModuleRevisionId requestedRevisionId, CacheMetadataOptions options,
        String expectedResolver) {
    if (isCheckmodified(dd, requestedRevisionId, options)) {
        Message.verbose("don't use cache for " + requestedRevisionId + ": checkModified=true");
        return null;
    }
    if (!options.isUseCacheOnly() && isChanging(dd, requestedRevisionId, options)) {
        Message.verbose("don't use cache for " + requestedRevisionId + ": changing=true");
        return null;
    }
    return doFindModuleInCache(requestedRevisionId, options, expectedResolver);
}
 
Example #18
Source File: PomModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void addTo(PomModuleDescriptorBuilder mdBuilder, PomDependencyMgt dep,
        ParserSettings ivySettings) throws ParseException, IOException {
    if ("import".equals(dep.getScope())) {
        // In Maven, "import" scope semantics are equivalent to getting (only) the
        // dependency management section of the imported module, into the current
        // module, so that those "managed dependency versions" are usable/applicable
        // in the current module's dependencies
        ModuleRevisionId importModRevID = ModuleRevisionId.newInstance(dep.getGroupId(),
                dep.getArtifactId(), dep.getVersion());
        ResolvedModuleRevision importModule = parseOtherPom(ivySettings, importModRevID, false);
        if (importModule == null) {
            throw new IOException("Impossible to import module for "
                    + mdBuilder.getModuleDescriptor().getResource().getName() + ". Import="
                    + importModRevID);
        }
        ModuleDescriptor importDescr = importModule.getDescriptor();

        // add dependency management info from imported module
        for (PomDependencyMgt importedDepMgt : getDependencyManagements(importDescr)) {
            mdBuilder.addDependencyMgt(new DefaultPomDependencyMgt(importedDepMgt.getGroupId(),
                    importedDepMgt.getArtifactId(), importedDepMgt.getVersion(),
                    importedDepMgt.getScope(), importedDepMgt.getExcludedModules()));
        }
    } else {
        mdBuilder.addDependencyMgt(dep);
    }

}
 
Example #19
Source File: PublishEngineTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private ResolvedModuleRevision resolveModule(IvySettings settings, FileSystemResolver resolver,
        String module) throws ParseException {
    return resolver.getDependency(
        new DefaultDependencyDescriptor(ModuleRevisionId.parse(module), false),
        new ResolveData(new ResolveEngine(settings, new EventManager(),
                new SortEngine(settings)), new ResolveOptions()));
}
 
Example #20
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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
}
 
Example #21
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testParentBomImport() 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(
                                String.format("depmgt/%s.pom", dd.getDependencyId().getName())),
                            false);
                return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
    });
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("depmgt/child.pom"), false);
    assertNotNull(md);
    assertEquals("1.0", md.getRevision());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(1, dds.length);

    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
        dds[0].getDependencyRevisionId());
}
 
Example #22
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private ResolvedModuleRevision checkForcedResolvedModuleRevision(ResolvedModuleRevision rmr) {
    if (rmr == null) {
        return null;
    }
    if (!isForce() || rmr.isForce()) {
        return rmr;
    }
    return new ResolvedModuleRevision(rmr.getResolver(), rmr.getArtifactResolver(),
            rmr.getDescriptor(), rmr.getReport(), true);
}
 
Example #23
Source File: ChainResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Test case for IVY-206.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-206">IVY-206</a>
 */
@Test
public void testFixedWithDefaultAndRealResolver() throws Exception {
    ChainResolver chain = new ChainResolver();
    chain.setName("chain");
    chain.setSettings(settings);

    // no ivy pattern for first resolver: will only find a 'default' module
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("1");
    resolver.setSettings(settings);

    resolver.addArtifactPattern(settings.getBaseDir()
            + "/test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
    chain.add(resolver);

    // second resolver has an ivy pattern and will thus find the real module, which should be
    // kept
    resolver = new FileSystemResolver();
    resolver.setName("2");
    resolver.setSettings(settings);

    resolver.addIvyPattern(settings.getBaseDir()
            + "/test/repositories/1/[organisation]/[module]/ivys/ivy-[revision].xml");
    resolver.addArtifactPattern(settings.getBaseDir()
            + "/test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
    chain.add(resolver);

    settings.addResolver(chain);

    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
            ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), false);
    ResolvedModuleRevision rmr = chain.getDependency(dd, data);
    assertNotNull(rmr);
    assertEquals("2", rmr.getResolver().getName());
}
 
Example #24
Source File: MockResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
static MockResolver buildMockResolver(ResolverSettings settings, String name,
        boolean findRevision, final ModuleRevisionId mrid, final Date publicationDate,
        final boolean isdefault) {
    final MockResolver r = new MockResolver();
    r.setName(name);
    r.setSettings(settings);
    if (findRevision) {
        DefaultModuleDescriptor md = new DefaultModuleDescriptor(mrid, "integration",
                publicationDate, isdefault);
        r.rmr = new ResolvedModuleRevision(r, r, md, new MetadataArtifactDownloadReport(
                md.getMetadataArtifact()));
    }
    return r;
}
 
Example #25
Source File: FileSystemResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDownloadWithUseOriginIsTrue() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    ((DefaultRepositoryCacheManager) resolver.getRepositoryCacheManager()).setUseOrigin(true);
    assertEquals("test", resolver.getName());

    resolver.addIvyPattern(IVY_PATTERN);
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/"
            + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");

    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid,
            false), data);
    assertNotNull(rmr);

    assertEquals(mrid, rmr.getId());
    Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
    assertEquals(pubdate, rmr.getPublicationDate());

    // test to ask to download
    DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar");
    DownloadReport report = resolver.download(new Artifact[] {artifact}, getDownloadOptions());
    assertNotNull(report);

    assertEquals(1, report.getArtifactsReports().length);

    ArtifactDownloadReport ar = report.getArtifactReport(artifact);
    assertNotNull(ar);

    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
 
Example #26
Source File: P2DescriptorTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolvePacked() throws Exception {
    settings.setDefaultResolver("p2-with-packed");

    ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE, "org.junit",
        "4.10.0.v4_10_0_v20120426-0900");

    ResolvedModuleRevision rmr = p2WithPackedResolver.getDependency(
        new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());

    assertEquals(1, rmr.getDescriptor().getAllArtifacts().length);

    DownloadOptions options = new DownloadOptions();
    DownloadReport report = p2WithPackedResolver.download(
        rmr.getDescriptor().getAllArtifacts(), options);
    assertNotNull(report);

    assertEquals(1, report.getArtifactsReports().length);

    Artifact artifact = rmr.getDescriptor().getAllArtifacts()[0];
    ArtifactDownloadReport ar = report.getArtifactReport(artifact);
    assertNotNull(ar);

    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    assertNotNull(ar.getUnpackedLocalFile());
}
 
Example #27
Source File: P2DescriptorTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolveZipped() throws Exception {
    settings.setDefaultResolver("p2-zipped");

    ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE,
        "org.apache.ant", "1.8.3.v20120321-1730");

    ResolvedModuleRevision rmr = p2ZippedResolver.getDependency(
        new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());

    assertEquals(2, rmr.getDescriptor().getAllArtifacts().length);

    DownloadOptions options = new DownloadOptions();
    DownloadReport report = p2ZippedResolver.download(rmr.getDescriptor().getAllArtifacts(),
        options);
    assertNotNull(report);

    assertEquals(2, report.getArtifactsReports().length);

    for (int i = 0; i < 2; i++) {
        Artifact artifact = rmr.getDescriptor().getAllArtifacts()[i];
        ArtifactDownloadReport ar = report.getArtifactReport(artifact);
        assertNotNull(ar);

        assertEquals(artifact, ar.getArtifact());
        assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
        // only the binary get unpacked
        if (ar.getArtifact().getType().equals("source")) {
            assertNull(ar.getUnpackedLocalFile());
        } else {
            assertNotNull(ar.getUnpackedLocalFile());
        }
    }
}
 
Example #28
Source File: P2DescriptorTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolveNotZipped() throws Exception {
    settings.setDefaultResolver("p2-zipped");

    ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE,
        "org.eclipse.e4.core.services", "1.0.0.v20120521-2346");

    ResolvedModuleRevision rmr = p2ZippedResolver.getDependency(
        new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());

    assertEquals(1, rmr.getDescriptor().getAllArtifacts().length);

    DownloadOptions options = new DownloadOptions();
    DownloadReport report = p2ZippedResolver.download(rmr.getDescriptor().getAllArtifacts(),
        options);
    assertNotNull(report);

    assertEquals(1, report.getArtifactsReports().length);

    Artifact artifact = rmr.getDescriptor().getAllArtifacts()[0];
    ArtifactDownloadReport ar = report.getArtifactReport(artifact);
    assertNotNull(ar);

    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    assertNull(ar.getUnpackedLocalFile());
}
 
Example #29
Source File: AbstractResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private String describe(ResolvedModuleRevision rmr) {
    if (rmr == null) {
        return "[none]";
    }
    return rmr.getId() + (rmr.getDescriptor().isDefault() ? "[default]" : "") + " from "
            + rmr.getResolver().getName();
}
 
Example #30
Source File: BintrayResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testBintray() throws Exception {
    BintrayResolver resolver = new BintrayResolver();
    resolver.setSettings(settings);
    ModuleRevisionId mrid = ModuleRevisionId
            .newInstance("org.apache.ant", "ant-antunit", "1.2");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid,
            false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());

    DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(),
            "ant-antunit", "jar", "jar");
    DownloadReport report = resolver.download(new Artifact[] {artifact}, downloadOptions());
    assertNotNull(report);

    assertEquals(1, report.getArtifactsReports().length);

    ArtifactDownloadReport ar = report.getArtifactReport(artifact);
    assertNotNull(ar);

    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());

    // test to ask to download again, should use cache
    report = resolver.download(new Artifact[] {artifact}, downloadOptions());
    assertNotNull(report);

    assertEquals(1, report.getArtifactsReports().length);

    ar = report.getArtifactReport(artifact);
    assertNotNull(ar);

    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}