4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
7 * Hyeongseok Heo <hyeongseok.heo@samsung.com>
8 * Gun Kim <gune.kim@samseung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
26 package org.tizen.nativecore.enventor.executer;
30 import org.eclipse.cdt.managedbuilder.core.IConfiguration;
31 import org.eclipse.core.resources.IFile;
32 import org.eclipse.core.resources.IProject;
33 import org.eclipse.core.resources.ResourcesPlugin;
34 import org.eclipse.core.runtime.IPath;
35 import org.eclipse.core.runtime.Path;
36 import org.eclipse.osgi.util.NLS;
37 import org.tizen.common.core.application.InstallPathConfig;
38 import org.tizen.common.core.application.TizenProjectDescription;
39 import org.tizen.common.util.FileUtil;
40 import org.tizen.common.util.HostUtil;
41 import org.tizen.nativecommon.ProjectUtil;
42 import org.tizen.nativecore.build.NativeCoreConfigurationManager;
43 import org.tizen.nativecore.enventor.Messages;
45 public class EDCEditorExecuter {
46 // The format is "environment executable <edc file>".
47 private static final String cmdFormat = "%s %s %s %s";
48 private static final String templateWizardArg = "--to";
50 public static void executeTool(final IPath path, final boolean withTemplateWizard) {
51 new Thread(new Runnable() {
54 HostUtil.returnExecute(getCommand(path, withTemplateWizard), null, false);
56 * String result = HostUtil.returnExecute(getCommand(path) +
57 * TizenPlatformConstants.CMD_SUFFIX, null, true);
59 * if ( !result.endsWith(TizenPlatformConstants.CMD_SUCCESS) ) {
60 * SWTUtil.asyncExec(new Runnable() {
62 * @Override public void run() {
63 * DialogUtil.openErrorDialog(Messages.CANNOT_EXECUTE_TOOL); } }); logger.error(
64 * "Enventor's result: " + result); }
71 public static String checkTool() {
74 String tool = getFullpathOfTool();
75 if (!isInstallation(tool)) {
76 return NLS.bind(Messages.CANNOT_FIND_TOOL, tool);
79 tool = getFullpathOfEflTool();
80 if (!isInstallation(tool)) {
81 return NLS.bind(Messages.CANNOT_FIND_TOOL, tool);
87 private static boolean isInstallation(String tool) {
88 if (new File(tool).exists()) {
95 private static String getCommand(IPath path, boolean withTemplateWizard) {
96 final String fullpathOfTool = getFullpathOfTool();
97 final String env = getEnv();
98 final IPath edj_path = path.removeFileExtension().addFileExtension("edj");
99 String redirectStream = null;
101 if (System.getProperty("os.name").startsWith("Windows")) {
102 redirectStream = " 1> NUL 2> NUL";
104 redirectStream = " 1> /dev/null 2> /dev/null";
107 if (withTemplateWizard) {
108 return String.format(cmdFormat, env, fullpathOfTool, path.toOSString(), edj_path.toOSString()) + " " + getOptions(path) + " " + templateWizardArg
111 return String.format(cmdFormat, env, fullpathOfTool, path.toOSString(), edj_path.toOSString()) + " " + getOptions(path) + redirectStream;
115 private static String[] trimOption(String[] option) {
116 String[] trimOptions = new String[option.length];
118 for (int i = 0; i < option.length; i++) {
119 trimOptions[i] = option[i].trim();
125 private static String getOptions(IPath path) {
127 IFile projectFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
128 if (projectFile == null) return null;
130 IProject project = projectFile.getProject();
132 // Set workspace path option with "-w <workspace path>".
133 String workspaceDir = project.getLocation().toOSString();
134 if (!workspaceDir.isEmpty())
135 option += "-w " + workspaceDir + " ";
137 IConfiguration config = ProjectUtil.getDefaultConfiguration(project);
139 IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
140 IPath projectRelativePath = null;
141 if (file != null) projectRelativePath = file.getProjectRelativePath();
143 if ((config != null) && (projectRelativePath != null)) {
144 String[] fontDirs = trimOption(NativeCoreConfigurationManager.getEdcFontDirs(config, projectRelativePath));
145 String[] imageDirs = trimOption(NativeCoreConfigurationManager.getEdcImageDirs(config, projectRelativePath));
146 String[] soundDirs = trimOption(NativeCoreConfigurationManager.getEdcSoundDirs(config, projectRelativePath));
148 for (int i = 0; i < fontDirs.length; i++) {
149 if (!fontDirs[i].isEmpty()) {
150 if (System.getProperty("os.name").startsWith("Windows")) {
151 if ((fontDirs[i].charAt(0) == '\\') ||
152 ((fontDirs[i].charAt(0) == '"') && (fontDirs[i].charAt(1) == '\\')) ||
153 ((fontDirs[i].length() >= 3) && (fontDirs[i].charAt(1) == ':') && (fontDirs[i].charAt(2) == '\\')) ||
154 ((fontDirs[i].length() >= 4) && (fontDirs[i].charAt(0) == '"') && (fontDirs[i].charAt(2) == ':')
155 && (fontDirs[i].charAt(3) == '\\')))
156 option += "--fd " + fontDirs[i] + " ";
158 option += "--fd " + path.removeLastSegments(1) + "\\" + fontDirs[i] + " ";
160 if ((fontDirs[i].charAt(0) == '/') ||
161 ((fontDirs[i].charAt(0) == '"') && (fontDirs[i].charAt(1) == '/')))
162 option += "--fd " + fontDirs[i] + " ";
164 option += "--fd " + path.removeLastSegments(1) + "/" + fontDirs[i] + " ";
168 for (int i = 0; i < imageDirs.length; i++) {
169 if (!imageDirs[i].isEmpty()) {
170 if (System.getProperty("os.name").startsWith("Windows")) {
171 if ((imageDirs[i].charAt(0) == '\\') ||
172 ((imageDirs[i].charAt(0) == '"') && (imageDirs[i].charAt(1) == '\\')) ||
173 ((imageDirs[i].length() >= 3) && (imageDirs[i].charAt(1) == ':') && (imageDirs[i].charAt(2) == '\\')) ||
174 ((imageDirs[i].length() >= 4) && (imageDirs[i].charAt(0) == '"') && (imageDirs[i].charAt(2) == ':')
175 && (imageDirs[i].charAt(3) == '\\')))
176 option += "--id " + imageDirs[i] + " ";
178 option += "--id " + path.removeLastSegments(1) + "\\" + imageDirs[i] + " ";
180 if ((imageDirs[i].charAt(0) == '/') ||
181 ((imageDirs[i].charAt(0) == '"') && (imageDirs[i].charAt(1) == '/')))
182 option += "--id " + imageDirs[i] + " ";
184 option += "--id " + path.removeLastSegments(1) + "/" + imageDirs[i] + " ";
188 for (int i = 0; i < soundDirs.length; i++) {
189 if (!soundDirs[i].isEmpty()) {
190 if (System.getProperty("os.name").startsWith("Windows")) {
191 if ((soundDirs[i].charAt(0) == '\\') ||
192 ((soundDirs[i].charAt(0) == '"') && (soundDirs[i].charAt(1) == '\\')) ||
193 ((soundDirs[i].length() >= 3) && (soundDirs[i].charAt(1) == ':') && (soundDirs[i].charAt(2) == '\\')) ||
194 ((soundDirs[i].length() >= 4) && (soundDirs[i].charAt(0) == '"') && (soundDirs[i].charAt(2) == ':')
195 && (soundDirs[i].charAt(3) == '\\')))
196 option += "--sd " + soundDirs[i] + " ";
198 option += "--sd " + path.removeLastSegments(1) + "\\" + soundDirs[i] + " ";
200 if ((soundDirs[i].charAt(0) == '/') ||
201 ((soundDirs[i].charAt(0) == '"') && (soundDirs[i].charAt(1) == '/')))
202 option += "--sd " + soundDirs[i] + " ";
204 option += "--sd " + path.removeLastSegments(1) + "/" + soundDirs[i] + " ";
210 // Get edje_cc path of platform efl-tools
211 TizenProjectDescription tizenDesc = org.tizen.common.util.ProjectUtil.getTizenProjectDescription(project);
212 if (tizenDesc == null) return null;
214 String platformToolsPath = InstallPathConfig.getPlatformToolsPath(tizenDesc.getProfileName(), tizenDesc.getVersion());
215 if (platformToolsPath == null) return null;
217 String edje_ccDirPath = FileUtil.appendPath(platformToolsPath, "efl-tool/efl-tools/bin");
218 String edje_ccPath = "";
219 if (System.getProperty("os.name").startsWith("Windows"))
220 edje_ccPath = FileUtil.appendPath(edje_ccDirPath, "edje_cc.exe");
222 edje_ccPath = FileUtil.appendPath(edje_ccDirPath, "edje_cc");
224 // Set edje_cc path option
225 if (!edje_ccPath.isEmpty())
226 option += "-e" + new Path(edje_ccPath).toOSString() + " ";
228 // Get autocomp eet path of platform version
229 String autocompDirPath = FileUtil.appendPath(getFullpathOfEnventor(), "share/enventor/autocomp");
230 String autocompEet = tizenDesc.getVersion() + "-autocomp.eet";
231 String autocompEetPath = FileUtil.appendPath(autocompDirPath, autocompEet);
233 // Set autocomp eet path option
234 if (!autocompEetPath.isEmpty())
235 option += "-a" + new Path(autocompEetPath).toOSString() + " ";
238 if ((tizenDesc.getVersion() != null) && (!tizenDesc.getVersion().isEmpty()))
239 option += "-z" + tizenDesc.getVersion() + " ";
244 private static String getDirectoryOfTool() {
245 String dir = FileUtil.appendPath(InstallPathConfig.getToolsPath(), "edc-editor/bin");
246 IPath path = new Path(dir);
247 return path.toOSString();
250 private static String getFullpathOfTool() {
251 if (System.getProperty("os.name").startsWith("Windows"))
252 return FileUtil.appendPath(getDirectoryOfTool(), "enventor.exe");
254 return FileUtil.appendPath(getDirectoryOfTool(), "enventor");
257 private static String getFullpathOfEflTool() {
258 String dir = FileUtil.appendPath(InstallPathConfig.getToolsPath(), "efl-tools");
259 IPath path = new Path(dir);
260 return path.toOSString();
263 private static String getFullpathOfEnventor() {
264 String dir = FileUtil.appendPath(InstallPathConfig.getToolsPath(), "edc-editor");
265 IPath path = new Path(dir);
266 return path.toOSString();
269 private static String getEnv() {
270 String fullpathOfEflTool = getFullpathOfEflTool();
271 String fullpathOfEnventor = getFullpathOfEnventor();
273 if (System.getProperty("os.name").startsWith("Windows")) {
274 String envFormat = "set path=%s;%s;%s && set FONTCONFIG_PATH=%s &&";
275 String eflToolBin = FileUtil.appendPath(fullpathOfEflTool, "bin");
276 String enventorBin = FileUtil.appendPath(fullpathOfEnventor, "bin");
277 String fontconfigDir = FileUtil.appendPath(fullpathOfEflTool, "etc/fonts");
278 return String.format(envFormat, eflToolBin, enventorBin, "%path%", fontconfigDir);
279 } else if (System.getProperty("os.name").contains("OS X")) {
280 String envFormat = "PATH=%s:$PATH DYLD_LIBRARY_PATH=%s:%s:$DYLD_LIBRARY_PATH FONTCONFIG_PATH=%s";
281 String eflToolBin = FileUtil.appendPath(fullpathOfEflTool, "bin");
282 String eflToolLib = FileUtil.appendPath(fullpathOfEflTool, "lib");
283 String enventorLib = FileUtil.appendPath(fullpathOfEnventor, "lib");
284 String fontconfigDir = FileUtil.appendPath(fullpathOfEflTool, "etc/fonts");
285 return String.format(envFormat, eflToolBin, eflToolLib, enventorLib, fontconfigDir);
287 String envFormat = "PATH=%s:$PATH LD_LIBRARY_PATH=%s:%s:$LD_LIBRARY_PATH";
288 String eflToolBin = FileUtil.appendPath(fullpathOfEflTool, "bin");
289 String eflToolLib = FileUtil.appendPath(fullpathOfEflTool, "lib");
290 String enventorLib = FileUtil.appendPath(fullpathOfEnventor, "lib");
291 return String.format(envFormat, eflToolBin, eflToolLib, enventorLib);