use of org.springframework.core.io.ContextResource in project liquibase by liquibase.
the class SpringResourceAccessor method getResourcePath.
/**
* Returns the lookup path to the given resource.
*/
protected String getResourcePath(Resource resource) {
if (resource instanceof ContextResource) {
return ((ContextResource) resource).getPathWithinContext();
}
if (resource instanceof ClassPathResource) {
return ((ClassPathResource) resource).getPath();
}
// have to fall back to figuring out the path as best we can
try {
String url = resource.getURL().toExternalForm();
if (url.contains("!")) {
return url.replaceFirst(".*!", "");
} else {
while (!resourceLoader.getResource("classpath:" + url).exists()) {
String newUrl = url.replaceFirst("^/?.*?/", "");
if (newUrl.equals(url)) {
throw new UnexpectedLiquibaseException("Could determine path for " + resource.getURL().toExternalForm());
}
url = newUrl;
}
return url;
}
} catch (IOException e) {
// so throw a breaking error now rather than wait for bigger problems down the line
throw new UnexpectedLiquibaseException("Cannot determine resource path for " + resource.getDescription());
}
}
use of org.springframework.core.io.ContextResource in project camunda-bpm-platform by camunda.
the class SpringTransactionsProcessEngineConfiguration method autoDeployResources.
protected void autoDeployResources(ProcessEngine processEngine) {
if (deploymentResources != null && deploymentResources.length > 0) {
RepositoryService repositoryService = processEngine.getRepositoryService();
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering(false).name(deploymentName).tenantId(deploymentTenantId);
for (Resource resource : deploymentResources) {
String resourceName = null;
if (resource instanceof ContextResource) {
resourceName = ((ContextResource) resource).getPathWithinContext();
} else if (resource instanceof ByteArrayResource) {
resourceName = resource.getDescription();
} else {
try {
resourceName = resource.getFile().getAbsolutePath();
} catch (IOException e) {
resourceName = resource.getFilename();
}
}
try {
if (resourceName.endsWith(".bar") || resourceName.endsWith(".zip") || resourceName.endsWith(".jar")) {
deploymentBuilder.addZipInputStream(new ZipInputStream(resource.getInputStream()));
} else {
deploymentBuilder.addInputStream(resourceName, resource.getInputStream());
}
} catch (IOException e) {
throw new ProcessEngineException("couldn't auto deploy resource '" + resource + "': " + e.getMessage(), e);
}
}
deploymentBuilder.deploy();
}
}
Aggregations