-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into hessjcg-patch-1
- Loading branch information
Showing
27 changed files
with
2,199 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
liquibase-core/src/main/java/liquibase/resource/AbstractPathHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package liquibase.resource; | ||
|
||
/** | ||
* Convenience base class for {@link PathHandler}s. | ||
*/ | ||
public abstract class AbstractPathHandler implements PathHandler { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
liquibase-core/src/main/java/liquibase/resource/FileSystemPathHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package liquibase.resource; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.NoSuchFileException; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* {@link PathHandler} that converts the path into a {@link FileSystemResourceAccessor}. | ||
*/ | ||
public class FileSystemPathHandler extends AbstractPathHandler { | ||
|
||
/** | ||
* Returns {@link #PRIORITY_DEFAULT} for all paths except for ones that are for a non-"file:" protocol. | ||
*/ | ||
public int getPriority(String root) { | ||
if (root == null) { | ||
return PRIORITY_NOT_APPLICABLE; | ||
} | ||
|
||
if (!root.startsWith("/") && root.contains(":")) { | ||
if (root.startsWith("file:") || root.matches("^[A-Za-z]:.*")) { | ||
return PRIORITY_DEFAULT; | ||
} else { | ||
return PRIORITY_NOT_APPLICABLE; | ||
} | ||
} | ||
return PRIORITY_DEFAULT; | ||
} | ||
|
||
public ResourceAccessor getResourceAccessor(String root) { | ||
return new FileSystemResourceAccessor(new File(root.replace("\\", "/"))); | ||
} | ||
@Override | ||
public InputStream open(String path) throws IOException { | ||
try { | ||
return Files.newInputStream(Paths.get(path)); | ||
} catch (NoSuchFileException e) { | ||
throw new IOException("File '"+path+"' does not exist"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
liquibase-core/src/main/java/liquibase/resource/PathHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package liquibase.resource; | ||
|
||
import liquibase.plugin.Plugin; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* Interface for extensions that can translate path strings into {@link ResourceAccessor}s and {@link java.io.InputStream}s. | ||
*/ | ||
public interface PathHandler extends Plugin { | ||
|
||
/** | ||
* Priority of this parser for the given path. The implementation with the highest priority will be used. | ||
*/ | ||
int getPriority(String root); | ||
|
||
/** | ||
* Parse the given path and return a {@link ResourceAccessor} for it. | ||
* | ||
* @throws IOException if the path is invalid | ||
*/ | ||
ResourceAccessor getResourceAccessor(String root) throws IOException; | ||
|
||
/** | ||
* Parse the given path and return an {@link java.io.InputStream} for it. | ||
* | ||
* @throws IOException if the path is invalid | ||
*/ | ||
InputStream open(String path) throws IOException; | ||
} |
35 changes: 35 additions & 0 deletions
35
liquibase-core/src/main/java/liquibase/resource/PathHandlerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package liquibase.resource; | ||
|
||
import liquibase.plugin.AbstractPluginFactory; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Singleton for working with {@link PathHandler}s. | ||
*/ | ||
public class PathHandlerFactory extends AbstractPluginFactory<PathHandler> { | ||
|
||
private PathHandlerFactory() { | ||
} | ||
|
||
@Override | ||
protected Class<PathHandler> getPluginClass() { | ||
return PathHandler.class; | ||
} | ||
|
||
@Override | ||
protected int getPriority(PathHandler obj, Object... args) { | ||
return obj.getPriority((String) args[0]); | ||
} | ||
|
||
/** | ||
* Creates the {@link ResourceAccessor} for the given path. | ||
*/ | ||
public ResourceAccessor getResourceAccessor(String root) throws IOException { | ||
final PathHandler plugin = getPlugin(root); | ||
if (plugin == null) { | ||
throw new IOException("Cannot parse resource location: '" + root + "'"); | ||
} | ||
return plugin.getResourceAccessor(root); | ||
} | ||
} |
Oops, something went wrong.