1
22
23 package com.liferay.portal.deploy;
24
25 import com.liferay.portal.kernel.util.ServerDetector;
26 import com.liferay.portal.kernel.util.StringPool;
27 import com.liferay.portal.kernel.util.StringUtil;
28 import com.liferay.portal.kernel.util.Validator;
29 import com.liferay.portal.util.PrefsPropsUtil;
30 import com.liferay.portal.util.PropsUtil;
31 import com.liferay.util.FileUtil;
32 import com.liferay.util.SystemProperties;
33
34 import java.io.File;
35 import java.io.FileOutputStream;
36 import java.io.IOException;
37 import java.io.OutputStream;
38
39
45 public class DeployUtil {
46
47 public static String getAutoDeployDestDir() throws Exception {
48 String destDir = PrefsPropsUtil.getString(
49 PropsUtil.AUTO_DEPLOY_DEST_DIR);
50
51 if (Validator.isNull(destDir)) {
52 destDir = getAutoDeployServerDestDir();
53 }
54
55 return destDir;
56 }
57
58 public static String getAutoDeployServerDestDir() throws Exception {
59 String destDir = PrefsPropsUtil.getString(
60 "auto.deploy." + ServerDetector.getServerId() + ".dest.dir");
61
62 if (Validator.isNull(destDir)) {
63 destDir = PrefsPropsUtil.getString(
64 PropsUtil.AUTO_DEPLOY_DEFAULT_DEST_DIR);
65 }
66
67 destDir = StringUtil.replace(
68 destDir, StringPool.BACK_SLASH, StringPool.SLASH);
69
70 return destDir;
71 }
72
73 public static String getResourcePath(String resource)
74 throws Exception {
75
76 return _instance._getResourcePath(resource);
77 }
78
79 private DeployUtil() {
80 }
81
82 private String _getResourcePath(String resource) throws IOException {
83 String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR);
84
85 File file = new File(
86 tmpDir + "/liferay/com/liferay/portal/deploy/dependencies/" +
87 resource);
88
89 File parentFile = file.getParentFile();
90
91 if (parentFile != null) {
92 parentFile.mkdirs();
93 }
94
95 byte[] byteArray = FileUtil.getBytes(
96 getClass().getResourceAsStream("dependencies/" + resource));
97
98 OutputStream os = new FileOutputStream(file);
99
100 os.write(byteArray);
101
102 return FileUtil.getAbsolutePath(file);
103 }
104
105 private static DeployUtil _instance = new DeployUtil();
106
107 }