All Downloads are FREE. Search and download functionalities are using the official Maven repository.

liquibase.resource.FileSystemResourceAccessor Maven / Gradle / Ivy

There is a newer version: 4.30.0
Show newest version
package liquibase.resource;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;

/**
 * A FileOpener implementation which finds Files in the
 * File System.
 * 

* FileSystemFileOpeners can use a BaseDirectory to determine * where relative paths should be resolved from. * * @author getResources(String packageName) throws IOException { String directoryPath = (new File(packageName).isAbsolute() || baseDirectory == null) ? packageName : baseDirectory + File.separator + packageName; File directoryFile = new File(directoryPath); if (!directoryFile.exists()) { return new Vector().elements(); } if (!directoryFile.isDirectory()) { return new Vector(Arrays.asList(directoryFile.toURL())).elements(); } File[] files = directoryFile.listFiles(); List results = new ArrayList(); if (files != null) { for (File f : files) { if (!f.isDirectory()) results.add(f.toURI().toURL()); } } final Iterator it = results.iterator(); return new Enumeration() { @Override public boolean hasMoreElements() { return it.hasNext(); } @Override public URL nextElement() { return it.next(); } }; } @Override public ClassLoader toClassLoader() { try { return new URLClassLoader(new URL[]{new URL("file://" + baseDirectory)}); } catch (MalformedURLException e) { throw new RuntimeException(e); } } @Override public String toString() { String dir = baseDirectory; if (dir == null) { dir = new File(".").getAbsolutePath(); } return getClass().getName()+"("+ dir +")"; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy