]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/deploy/LocalFilesDeployment.java
Rename resource set
[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 void run() {
19 Map<String, Resource> resources = resourceSet.listResources();
20 for (String relPath : resources.keySet()) {
21 File targetFile = new File(targetBase + File.separator + relPath);
22 File parentDir = targetFile.getParentFile();
23 if (!parentDir.exists())
24 parentDir.mkdirs();
25
26 Resource resource = resources.get(relPath);
27
28 InputStream in = null;
29 OutputStream out = null;
30 try {
31 in = resource.getInputStream();
32 out = FileUtils.openOutputStream(targetFile);
33 IOUtils.copy(in, out);
34 } catch (IOException e) {
35 throw new SlcException("Cannot extract " + resource + " to "
36 + targetFile, e);
37 } finally {
38 IOUtils.closeQuietly(in);
39 IOUtils.closeQuietly(out);
40 }
41 }
42 }
43
44 public void setTargetBase(String targetBase) {
45 this.targetBase = targetBase;
46 }
47
48 public void setResourceSet(ResourceSet resourceSet) {
49 this.resourceSet = resourceSet;
50 }
51
52 }