Search in sources :

Example 11 with ResolveOptions

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

the class Maven2LocalTest method setUp.

@Before
public void setUp() {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    cache = new File("build/cache");
    data = new ResolveData(engine, new ResolveOptions());
    cache.mkdirs();
    settings.setDefaultCache(cache);
}
Also used : ResolveEngine(org.apache.ivy.core.resolve.ResolveEngine) SortEngine(org.apache.ivy.core.sort.SortEngine) ResolveData(org.apache.ivy.core.resolve.ResolveData) EventManager(org.apache.ivy.core.event.EventManager) IvySettings(org.apache.ivy.core.settings.IvySettings) File(java.io.File) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) Before(org.junit.Before)

Example 12 with ResolveOptions

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

the class URLResolverTest method setUp.

@Before
public void setUp() {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    data = new ResolveData(engine, new ResolveOptions());
    TestHelper.createCache();
    settings.setDefaultCache(TestHelper.cache);
}
Also used : ResolveEngine(org.apache.ivy.core.resolve.ResolveEngine) SortEngine(org.apache.ivy.core.sort.SortEngine) ResolveData(org.apache.ivy.core.resolve.ResolveData) EventManager(org.apache.ivy.core.event.EventManager) IvySettings(org.apache.ivy.core.settings.IvySettings) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) Before(org.junit.Before)

Example 13 with ResolveOptions

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

the class RetrieveTest method testUnpack.

@Test
public void testUnpack() throws Exception {
    ResolveOptions roptions = getResolveOptions(new String[] { "*" });
    URL url = new File("test/repositories/1/packaging/module1/ivys/ivy-1.0.xml").toURI().toURL();
    // normal resolve, the file goes in the cache
    ResolveReport report = ivy.resolve(url, roptions);
    assertFalse(report.hasError());
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);
    String pattern = "build/test/retrieve/[organization]/[module]/[conf]/[type]s/[artifact]-[revision](.[ext])";
    ivy.retrieve(md.getModuleRevisionId(), getRetrieveOptions().setDestArtifactPattern(pattern));
    File dest = new File("build/test/retrieve/packaging/module2/default/jars/module2-1.0");
    assertTrue(dest.exists());
    assertTrue(dest.isDirectory());
    File[] jarContents = dest.listFiles();
    Arrays.sort(jarContents);
    assertEquals(new File(dest, "META-INF"), jarContents[0]);
    assertEquals(new File(dest, "test.txt"), jarContents[1]);
    assertEquals(new File(dest, "META-INF/MANIFEST.MF"), jarContents[0].listFiles()[0]);
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolveReport(org.apache.ivy.core.report.ResolveReport) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 14 with ResolveOptions

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

the class RetrieveTest method testUnpackSync.

@Test
public void testUnpackSync() throws Exception {
    ResolveOptions roptions = getResolveOptions(new String[] { "*" });
    URL url = new File("test/repositories/1/packaging/module1/ivys/ivy-1.0.xml").toURI().toURL();
    // normal resolve, the file goes in the cache
    ResolveReport report = ivy.resolve(url, roptions);
    assertFalse(report.hasError());
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);
    String pattern = "build/test/retrieve/[organization]/[module]/[conf]/[type]s/[artifact]-[revision](.[ext])";
    ivy.retrieve(md.getModuleRevisionId(), getRetrieveOptions().setSync(true).setDestArtifactPattern(pattern));
    File dest = new File("build/test/retrieve/packaging/module2/default/jars/module2-1.0");
    assertTrue(dest.exists());
    assertTrue(dest.isDirectory());
    File[] jarContents = dest.listFiles();
    Arrays.sort(jarContents);
    assertEquals(new File(dest, "META-INF"), jarContents[0]);
    assertEquals(new File(dest, "test.txt"), jarContents[1]);
    assertEquals(new File(dest, "META-INF/MANIFEST.MF"), jarContents[0].listFiles()[0]);
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolveReport(org.apache.ivy.core.report.ResolveReport) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 15 with ResolveOptions

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

the class OBRResolverTest method genericTestResolve.

private void genericTestResolve(String jarName, String conf, ModuleRevisionId[] expectedMrids, ModuleRevisionId[] expected2Mrids) throws Exception {
    JarInputStream jis = new JarInputStream(new FileInputStream("test/test-repo/bundlerepo/" + jarName));
    Manifest manifest = jis.getManifest();
    jis.close();
    BundleInfo bundleInfo = ManifestParser.parseManifest(manifest);
    bundleInfo.addArtifact(new BundleArtifact(false, new File("test/test-repo/bundlerepo/" + jarName).toURI(), null));
    DefaultModuleDescriptor md = BundleInfoAdapter.toModuleDescriptor(OSGiManifestParser.getInstance(), null, bundleInfo, profileProvider);
    ResolveReport resolveReport = ivy.resolve(md, new ResolveOptions().setConfs(new String[] { conf }).setOutputReport(false));
    assertFalse("resolve failed " + resolveReport.getAllProblemMessages(), resolveReport.hasError());
    Set<ModuleRevisionId> actual = new HashSet<>();
    for (Artifact artifact : resolveReport.getArtifacts()) {
        actual.add(artifact.getModuleRevisionId());
    }
    Set<ModuleRevisionId> expected = new HashSet<>(Arrays.asList(expectedMrids));
    if (expected2Mrids != null) {
        // in this use case, we have two choices, let's try the second one
        try {
            Set<ModuleRevisionId> expected2 = new HashSet<>(Arrays.asList(expected2Mrids));
            assertEquals(expected2, actual);
            // test passed
            return;
        } catch (AssertionError e) {
        // too bad, let's continue
        }
    }
    assertEquals(expected, actual);
}
Also used : JarInputStream(java.util.jar.JarInputStream) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Manifest(java.util.jar.Manifest) FileInputStream(java.io.FileInputStream) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact) Artifact(org.apache.ivy.core.module.descriptor.Artifact) ResolveReport(org.apache.ivy.core.report.ResolveReport) BundleInfo(org.apache.ivy.osgi.core.BundleInfo) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) File(java.io.File) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) HashSet(java.util.HashSet)

Aggregations

ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)36 File (java.io.File)23 IvySettings (org.apache.ivy.core.settings.IvySettings)21 ResolveData (org.apache.ivy.core.resolve.ResolveData)19 Before (org.junit.Before)16 ResolveReport (org.apache.ivy.core.report.ResolveReport)13 ResolveEngine (org.apache.ivy.core.resolve.ResolveEngine)13 EventManager (org.apache.ivy.core.event.EventManager)12 SortEngine (org.apache.ivy.core.sort.SortEngine)12 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)10 IOException (java.io.IOException)7 ParseException (java.text.ParseException)6 Ivy (org.apache.ivy.Ivy)6 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)6 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)6 URL (java.net.URL)5 HashSet (java.util.HashSet)5 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)5 BuildException (org.apache.tools.ant.BuildException)5 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)3