Example usage for org.apache.commons.io FileUtils toURLs

List of usage examples for org.apache.commons.io FileUtils toURLs

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils toURLs.

Prototype

public static URL[] toURLs(File[] files) throws IOException 

Source Link

Document

Converts each of an array of File to a URL.

Usage

From source file:org.sonar.api.utils.ManifestUtilsTest.java

@Test
public void emptyManifest() throws Exception {
    Manifest mf = new Manifest();
    File jar = createJar(mf, "emptyManifest.jar");

    URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[] { jar }));
    assertThat(ManifestUtils.getPropertyValues(classloader, "foo").size(), is(0));
}

From source file:org.sonar.api.utils.ManifestUtilsTest.java

@Test
public void singleManifest() throws Exception {
    Manifest mf = new Manifest();
    mf.getMainAttributes().putValue("foo", "bar");
    mf.getMainAttributes().putValue("other", "value");
    File jar = createJar(mf, "singleManifest.jar");

    URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[] { jar }));
    List<String> values = ManifestUtils.getPropertyValues(classloader, "foo");
    assertThat(values.size(), is(1));/*from   w ww. jav  a2s  .  co  m*/
    assertThat(values, hasItem("bar"));
}

From source file:org.sonar.api.utils.ManifestUtilsTest.java

@Test
public void manyManifests() throws Exception {
    Manifest mf1 = new Manifest();
    mf1.getMainAttributes().putValue("foo", "bar");
    File jar1 = createJar(mf1, "manyManifests-one.jar");

    Manifest mf2 = new Manifest();
    mf2.getMainAttributes().putValue("foo", "otherbar");
    File jar2 = createJar(mf2, "manyManifests-two.jar");

    URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[] { jar1, jar2 }));
    List<String> values = ManifestUtils.getPropertyValues(classloader, "foo");
    assertThat(values.size(), is(2));/*from   w  w w .ja  v a  2s  .c o m*/
    assertThat(values, hasItems("bar", "otherbar"));
}