Search in sources :

Example 6 with BasicResource

use of org.apache.ivy.plugins.repository.BasicResource in project ant-ivy by apache.

the class XmlModuleUpdaterTest method testUpdateWithExcludeConfigurations1.

@Test
public void testUpdateWithExcludeConfigurations1() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs1.xml").toURI().toURL();
    XmlModuleDescriptorUpdater.update(settingsUrl, buffer, getUpdateOptions("release", "mynewrev").setConfsToExclude(new String[] { "myconf2" }));
    XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
    ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
    // test the number of configurations
    Configuration[] configs = updatedMd.getConfigurations();
    assertNotNull("Configurations shouldn't be null", configs);
    assertEquals("Number of configurations incorrect", 3, configs.length);
    // test that the correct configuration has been removed
    assertNull("myconf2 hasn't been removed", updatedMd.getConfiguration("myconf2"));
    // test that the other configurations aren't removed
    assertNotNull("myconf1 has been removed", updatedMd.getConfiguration("myconf1"));
    assertNotNull("myconf3 has been removed", updatedMd.getConfiguration("myconf3"));
    assertNotNull("myconf4 has been removed", updatedMd.getConfiguration("myconf4"));
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) IvySettings(org.apache.ivy.core.settings.IvySettings) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BasicResource(org.apache.ivy.plugins.repository.BasicResource) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 7 with BasicResource

use of org.apache.ivy.plugins.repository.BasicResource in project ant-ivy by apache.

the class XmlModuleUpdaterTest method testUpdateWithExcludeConfigurations4.

@Test
public void testUpdateWithExcludeConfigurations4() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs4.xml").toURI().toURL();
    XmlModuleDescriptorUpdater.update(settingsUrl, buffer, getUpdateOptions("release", "mynewrev").setConfsToExclude(new String[] { "myconf2" }));
    XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
    ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
    // test the number of configurations
    Artifact[] artifacts = updatedMd.getAllArtifacts();
    assertNotNull("Published artifacts shouldn't be null", artifacts);
    assertEquals("Number of published artifacts incorrect", 4, artifacts.length);
    // test that the correct configuration has been removed
    for (Artifact current : artifacts) {
        List<String> currentConfs = Arrays.asList(current.getConfigurations());
        assertTrue("myconf2 hasn't been removed for artifact " + current.getName(), !currentConfs.contains("myconf2"));
    }
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ByteArrayInputStream(java.io.ByteArrayInputStream) IvySettings(org.apache.ivy.core.settings.IvySettings) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BasicResource(org.apache.ivy.plugins.repository.BasicResource) File(java.io.File) URL(java.net.URL) Artifact(org.apache.ivy.core.module.descriptor.Artifact) Test(org.junit.Test)

Example 8 with BasicResource

use of org.apache.ivy.plugins.repository.BasicResource 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 9 with BasicResource

use of org.apache.ivy.plugins.repository.BasicResource in project ant-ivy by apache.

the class XmlModuleUpdaterTest method testUpdateWithExcludeConfigurations3.

@Test
public void testUpdateWithExcludeConfigurations3() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs3.xml").toURI().toURL();
    XmlModuleDescriptorUpdater.update(settingsUrl, buffer, getUpdateOptions("release", "mynewrev").setConfsToExclude(new String[] { "myconf2", "conf2" }));
    XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
    ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
    // test the number of configurations
    Configuration[] configs = updatedMd.getConfigurations();
    assertNotNull("Configurations shouldn't be null", configs);
    assertEquals("Number of configurations incorrect", 4, configs.length);
    // test that the correct configuration has been removed
    assertNull("myconf2 hasn't been removed", updatedMd.getConfiguration("myconf2"));
    assertNull("conf2 hasn't been removed", updatedMd.getConfiguration("conf2"));
    // test that the other configurations aren't removed
    assertNotNull("conf1 has been removed", updatedMd.getConfiguration("conf1"));
    assertNotNull("myconf1 has been removed", updatedMd.getConfiguration("myconf1"));
    assertNotNull("myconf3 has been removed", updatedMd.getConfiguration("myconf3"));
    assertNotNull("myconf4 has been removed", updatedMd.getConfiguration("myconf4"));
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) IvySettings(org.apache.ivy.core.settings.IvySettings) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BasicResource(org.apache.ivy.plugins.repository.BasicResource) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 10 with BasicResource

use of org.apache.ivy.plugins.repository.BasicResource in project ant-ivy by apache.

the class XmlModuleUpdaterTest method testMergedUpdateWithExtendsAndDefaultConfMappings.

/**
 * Test case for IVY-1420.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1420">IVY-1420</a>
 */
@Test
public void testMergedUpdateWithExtendsAndDefaultConfMappings() throws Exception {
    URL url = XmlModuleUpdaterTest.class.getResource("test-extends-configurations-defaultconfmapping.xml");
    XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
    ModuleDescriptor md = parser.parseDescriptor(new IvySettings(), url, true);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    XmlModuleDescriptorUpdater.update(url, buffer, getUpdateOptions("release", "mynewrev").setMerge(true).setMergedDescriptor(md));
    ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
    Configuration[] configurations = updatedMd.getConfigurations();
    assertNotNull("Configurations shouldn't be null", configurations);
    assertEquals("Number of configurations is incorrect", 3, configurations.length);
    String updatedXml = buffer.toString();
    System.out.println(updatedXml);
    assertTrue(updatedXml.contains("configurations defaultconfmapping=\"conf1,default->@()\""));
    assertTrue(updatedXml.contains("dependencies defaultconfmapping=\"conf1,default->@()\""));
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) IvySettings(org.apache.ivy.core.settings.IvySettings) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BasicResource(org.apache.ivy.plugins.repository.BasicResource) URL(java.net.URL) Test(org.junit.Test)

Aggregations

BasicResource (org.apache.ivy.plugins.repository.BasicResource)12 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)11 Test (org.junit.Test)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 URL (java.net.URL)10 IvySettings (org.apache.ivy.core.settings.IvySettings)10 File (java.io.File)6 Configuration (org.apache.ivy.core.module.descriptor.Configuration)6 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)4 Artifact (org.apache.ivy.core.module.descriptor.Artifact)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Date (java.util.Date)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