]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/deploy/LocalFilesDeployment.java
Improve deployment
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / deploy / LocalFilesDeployment.java
1 package org.argeo.slc.core.deploy;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.OutputStream;
7 import java.util.Map;
8
9 import org.apache.commons.io.FileUtils;
10 import org.apache.commons.io.IOUtils;
11 import org.argeo.slc.SlcException;
12 import org.springframework.core.io.Resource;
13
14 public class LocalFilesDeployment implements Runnable {
15 private String targetBase = "";
16 private ResourceSet resourceSet;
17
18 public LocalFilesDeployment() {
19 }
20
21 public LocalFilesDeployment(ResourceSet resourceSet) {
22 this.resourceSet = resourceSet;
23 }
24
25 public void run() {
26 Map<String, Resource> resources = resourceSet.listResources();
27 for (String relPath : resources.keySet()) {
28 File targetFile = new File(targetBase + File.separator + relPath);
29 File parentDir = targetFile.getParentFile();
30 if (!parentDir.exists())
31 parentDir.mkdirs();
32
33 Resource resource = resources.get(relPath);
34
35 InputStream in = null;
36 OutputStream out = null;
37 try {
38 in = resource.getInputStream();
39 out = FileUtils.openOutputStream(targetFile);
40 IOUtils.copy(in, out);
41 } catch (IOException e) {
42 throw new SlcException("Cannot extract " + resource + " to "
43 + targetFile, e);
44 } finally {
45 IOUtils.closeQuietly(in);
46 IOUtils.closeQuietly(out);
47 }
48 }
49 }
50
51 public void setTargetBase(String targetBase) {
52 this.targetBase = targetBase;
53 }
54
55 public void setResourceSet(ResourceSet resourceSet) {
56 this.resourceSet = resourceSet;
57 }
58
59 }