📄 cheddarrunner.java
字号:
package com.thalesgroup.cheddar.MARTE2cheddar;
import java.io.InputStream;
import org.eclipse.core.resources.IFile;
import com.thalesgroup.cheddar.MARTE2cheddar.preferences.MARTE2CheddarPreferencePage;
import com.thalesgroup.java.log.Log;
/**
* Utility class for running Cheddar.
*
* <copyright>
* Thales MARTE to Cheddar (Copyright (c) THALES 2007 All rights reserved) is free software; you can redistribute itand/or modify
* it under the terms of the Eclipse Public License as published in http://www.eclipse.org/legal/epl-v10.html
*
* Thales MARTE to Cheddar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Eclipse Public License for more details.
* </copyright>
*
* @author Nicolas Vienne
*
*/
public class CheddarRunner {
/**
* Launches Cheddar with the specified file as parameter
* @param file IFile to be launched in Cheddar
*/
public static void Exec(IFile file){
if(file != null) {
String cheddarpath = MARTE2CheddarPreferencePage.getCheddarPath();
if(cheddarpath.equals("")) {
Log.errorMessage(Activator.PLUGIN_ID,"Cheddar path is not set in the preferences page.");
}
else {
try {
String os_name = System.getProperty("os.name");
Process p = null;
if(os_name.contains("Windows")) {
//String[] cmd = {"cmd.exe", "/c", "\""+cheddarpath +" "+file.getLocation().toString()+"\""};
String[] cmd = {"\""+cheddarpath +"\"",file.getLocation().toString()};
p = Runtime.getRuntime().exec(cmd);
} else if(os_name.contains("Linux")) {
// WARNING :
//[root@trtp0948 lib]# cd /usr/lib
//[root@trtp0948 lib]# ln -s /usr/local/lib/libgtkada-1.2.so.12
//String[] cmd = {"/bin/sh", "-c", cheddarpath+file.getLocation().toString()};
String[] cmd = {"\""+cheddarpath +"\",\""+file.getLocation().toString()+"\""};
p = Runtime.getRuntime().exec(cmd);
} else {
System.out.println("I don't know how to start Cheddar on " + os_name +".");
}
if(p != null) {
InputStream is = p.getInputStream();
String r = "";
int c;
do {
c = is.read();
if(c != 1) {
r += (char)c;
}
} while( c != -1);
r = r.substring(0, r.length()-1);
String[] rs = r.split("\n");
r = "";
for(int i=6; i< rs.length; i++) r += rs[i]+"\n";
if(r != "") {
r = r.substring(0, r.length()-1);
Log.debugMessage(Activator.PLUGIN_ID,"Cheddar said :");
Log.debugMessage(Activator.PLUGIN_ID,r);
}
}
} catch (Exception exception) {
Log.errorMessage(Activator.PLUGIN_ID,"Error in CheddarRunner execution",exception);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -