Example usage for org.springframework.core.io ClassPathResource getFile

List of usage examples for org.springframework.core.io ClassPathResource getFile

Introduction

In this page you can find the example usage for org.springframework.core.io ClassPathResource getFile.

Prototype

@Override
public File getFile() throws IOException 

Source Link

Document

This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system.

Usage

From source file:de.brands4friends.daleq.integration.beans.PrepareMysqlSchema.java

@Override
public void afterPropertiesSet() throws IOException {
    final ClassPathResource script = new ClassPathResource("schema-mysql.sql");
    logger.info("Preparing Schema with file {}", script.getFile().getAbsolutePath());
    JdbcTestUtils.executeSqlScript(new JdbcTemplate(dataSource), script, false);
}

From source file:be.jacobsvanroy.springsqlunit.sql.SqlRunner.java

private File getFile(ClassPathResource resource) {
    File scriptFile;/*  w  w  w  . j  a  v  a  2s  .co  m*/
    try {
        scriptFile = resource.getFile();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return scriptFile;
}

From source file:de.openity.xmlworks.parsers.ParseXMLTest.java

@Test
public void testParse() throws Exception {
    final ClassPathResource classPathResource = new ClassPathResource("testXMLs/TestRSS.xml");
    Collection<RSSEntity> entity = new ParserImpl<RSSEntity>(RSSEntity.class)
            .parse(classPathResource.getFile());
    System.out.println(entity.toString());
    System.out.println(entity.size());
}

From source file:au.id.hazelwood.xmltvguidebuilder.config.ConfigFactoryUnitTest.java

@Test(expected = InvalidConfigException.class)
public void invalidConfigWithDupChannel() throws Exception {
    final ClassPathResource resource = new ClassPathResource(
            "/au/id/hazelwood/xmltvguidebuilder/config/invalid-config-dup-channel.xml");
    configFactory.create(resource.getFile());
}

From source file:oz.hadoop.yarn.api.core.ApplicationMasterLauncherImplTests.java

@Test
public void validateWithMissingClasspathFilters() throws Exception {
    ClassPathResource res = new ClassPathResource("classpath.filters");
    File cpFilterFile = res.getFile();
    File backup = new File("classpath.filters.old");
    try {/*from   w  w w  .  j  a v a  2  s . com*/
        cpFilterFile.renameTo(backup);
        Map<String, Object> applicationSpecification = new HashMap<>();
        applicationSpecification.put(YayaConstants.CONTAINER_SPEC, new HashMap<>());
        ApplicationMasterLauncherImpl<Void> launcher = new ApplicationMasterLauncherImpl<>(
                applicationSpecification);

        Method excludedMethod = ReflectionUtils.getMethodAndMakeAccessible(ApplicationMasterLauncherImpl.class,
                "excluded", String.class);
        String[] cp = System.getProperty("java.class.path").split(":");
        for (String v : cp) {
            File f = new File(v);
            if (!f.isDirectory()) {
                boolean excluded = (boolean) excludedMethod.invoke(launcher, f.getName());
                assertFalse(f.getName(), excluded);
            }
        }
    } finally {
        backup.renameTo(cpFilterFile);
    }
}

From source file:au.id.hazelwood.xmltvguidebuilder.config.ConfigFactoryUnitTest.java

@Test
public void testCreate() throws Exception {
    final ClassPathResource resource = new ClassPathResource(
            "/au/id/hazelwood/xmltvguidebuilder/config/valid-config.xml");
    Config config = configFactory.create(resource.getFile());
    assertEquals(1, config.getOffset());
    assertEquals(13, config.getDays());/*from   ww w .  jav a 2 s  . co m*/
    assertEquals(2, config.getChannelConfigs().size());
}

From source file:oz.hadoop.yarn.api.core.ApplicationMasterLauncherImplTests.java

@Test
public void validateWithEmptyClasspathFilters() throws Exception {
    ClassPathResource res = new ClassPathResource("classpath.filters");
    File cpFilterFile = res.getFile();
    File parentFile = cpFilterFile.getParentFile();
    File backup = new File("classpath.filters.old");
    try {/*from w  w w.j  a v a2 s.  c  o m*/
        cpFilterFile.renameTo(backup);
        File file = new File(parentFile, "classpath.filters");
        file.createNewFile();
        Map<String, Object> applicationSpecification = new HashMap<>();
        applicationSpecification.put(YayaConstants.CONTAINER_SPEC, new HashMap<>());
        ApplicationMasterLauncherImpl<Void> launcher = new ApplicationMasterLauncherImpl<>(
                applicationSpecification);

        Method excludedMethod = ReflectionUtils.getMethodAndMakeAccessible(ApplicationMasterLauncherImpl.class,
                "excluded", String.class);
        String[] cp = System.getProperty("java.class.path").split(":");
        for (String v : cp) {
            File f = new File(v);
            if (!f.isDirectory()) {
                boolean excluded = (boolean) excludedMethod.invoke(launcher, f.getName());
                assertFalse(f.getName(), excluded);
            }
        }
    } finally {
        cpFilterFile.delete();
        File file = new File(parentFile, "classpath.filters");
        backup.renameTo(file);
        assertTrue(file.exists());
        assertTrue(file.length() > 0);
    }
}

From source file:de.ingrid.admin.security.IngridRealm.java

public IngridRealm() throws IOException {
    ClassPathResource authFile = new ClassPathResource("ingrid.auth");
    System.setProperty("java.security.auth.login.config", authFile.getFile().getPath());
}

From source file:org.apereo.services.persondir.support.GroovyPersonAttributeDaoTest.java

private IPersonAttributeScriptDao loadGroovyClass(String filename) {
    try {//  w  w  w . j  a  v a2  s .c  o  m
        final ClassPathResource scriptFile = new ClassPathResource(filename);
        final Class<?> groovyClass = loader.parseClass(scriptFile.getFile());

        final IPersonAttributeScriptDao groovyObject = (IPersonAttributeScriptDao) groovyClass.newInstance();
        return groovyObject;
    } catch (IOException e) {
        logger.error("Unable to load groovy file {} ", e);
    } catch (InstantiationException e) {
        logger.error("Unable to instantiate groovy class specified in file {}", filename, e);
    } catch (IllegalAccessException e) {
        logger.error("Unable to instantiate groovy class specified in file {}", filename, e);
    }
    fail("Unable to instantiate groovy class from file " + filename);
    return null;
}

From source file:com.thoughtworks.go.config.GoRepoConfigDataSourceIntegrationTest.java

private String setupExternalConfigRepo(File configRepo, String configRepoTestResource) throws IOException {
    ClassPathResource resource = new ClassPathResource(configRepoTestResource);
    FileUtils.copyDirectory(resource.getFile(), configRepo);
    CommandLine.createCommandLine("git").withEncoding("utf-8").withArg("init")
            .withArg(configRepo.getAbsolutePath()).runOrBomb(null);
    CommandLine.createCommandLine("git").withEncoding("utf-8").withArgs("config", "commit.gpgSign", "false")
            .withWorkingDir(configRepo.getAbsoluteFile()).runOrBomb(null);
    gitAddDotAndCommit(configRepo);/*from w  ww.  ja v a2s .c  om*/
    ConsoleResult consoleResult = CommandLine.createCommandLine("git").withEncoding("utf-8").withArg("log")
            .withArg("-1").withArg("--pretty=format:%h").withWorkingDir(configRepo).runOrBomb(null);

    return consoleResult.outputAsString();
}