tinydtproject.java
来自「plugin for eclipse」· Java 代码 · 共 626 行 · 第 1/2 页
JAVA
626 行
{
try
{
System.out.println("*********** makeApplication started ****************");
// create command that makes the project
Path appPath = new Path(app.configurationFileName);
String makeCmd = "cd ";
makeCmd += Utils.getLocationFromFullResourcePath( appPath.removeLastSegments(1).toString());
makeCmd += "; make ";
makeCmd += app.platform;
// makeCmd += "\"";
String[] cmd = {getBashPath(), "--login", "-c", makeCmd};
MessageConsoleStream out = TinydtPlugin.getDefault().getConsole().newMessageStream();
MessageConsoleStream err = TinydtPlugin.getDefault().getConsole().newMessageStream();
Executor.exec(null, err, out, cmd, null, null);
System.out.println("*********** makeApplication ended ****************");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void makeCurrentApp()
{
// get application
Application app = (Application) applications.get(currentApp);
if(app == null)
{
System.out.println("no current application!");
return;
}
// app.generateMakeFile();
makeApplication(app);
}
public void rebuildAll()
{
parseAll();
makeCurrentApp();
}
public void parseAll()
{
// no application selected
if(currentApp == null) {
System.err.println("No application selected");
return;
}
// get application
Application app = (Application) applications.get(currentApp);
if(app == null)
{
System.err.println("Consitency error: application is null");
return;
}
// create temp dir
IPath pluginStatePath = TinydtPlugin.getDefault().getStateLocation();
File tmpDir = pluginStatePath.append("nescparser_temp_"+System.currentTimeMillis()).toFile();
if (!Dir.mkDirs(tmpDir)) {
System.err.println("Cannot create temporary direcory: "+tmpDir.toString());
return;
}
String configFileName = Utils.getLocationFromFullResourcePath(app.configurationFileName);
NesCObjectTreeBuilderContext builderCtx_new = null;
String tosDir = project.getLocation().toString() + "/tos";
String programFile = new Path(configFileName).lastSegment().toString();
ParserMessage messageContainer = new ParserMessage(ParserMessage.INFO, "TinyDT: Component file: "+programFile, null, null);
// Create parser configration.
ParserConfiguration parserConfig = null;
try {
parserConfig = ParserConfigurationFactory
.create(tosDir, tmpDir.toString(), getPlatformProfile(app), getSensorBoardProfile(app), getSearchPathList(app), null);
} catch (IOException e) {
messageContainer.addException(e);
}
builderCtx_new = new NesCObjectTreeBuilderContext(parserConfig);
builderCtx_new.pushMessages(messageContainer);
try
{
NesCFile nesCFile = builderCtx_new.getObjectTree(programFile);
}
catch(ParserMessage m)
{
builderCtx_new.addMsg(m);
}
builderCtx = builderCtx_new;
updateErrorMarkers();
updateEditors();
// primitive update view
final TinydtView v = TinydtView.getTinydtView();
if(v != null)
v.primitiveUpdate();
// recursively delete temporary files
Dir.rmDir(tmpDir, true);
}
private void updateEditors()
{
IWorkbench workbench = TinydtPlugin.getDefault().getWorkbench();
IWorkbenchWindow windows[] = workbench.getWorkbenchWindows();
for(int k=0; k<windows.length; ++k)
{
IWorkbenchPage pages[] = windows[k].getPages();
for(int i=0; i<pages.length; ++i)
{
IEditorReference editors[] = pages[i].getEditorReferences();
for(int j=0; j<editors.length; ++j)
{
IEditorPart editorPart = editors[j].getEditor(false);
if( editorPart instanceof NesCEditor )
{
// TODO: we need to create a diff thread for this
//((NesCEditor)editorPart).updateConfigStatus();
}
}
}
}
}
private void updateErrorMarkers()
{
try
{
project.deleteMarkers(IMarker.PROBLEM,true,IResource.DEPTH_INFINITE);
Iterator it = builderCtx.getMessages().getFlatMessageList(ParserMessage.ERROR.getLevel() | ParserMessage.WARNING.getLevel() | ParserMessage.INTERNAL_ERROR.getLevel()).iterator();
while( it.hasNext() )
{
ParserMessage msg = (ParserMessage)it.next();
IResource res = project;
if( msg.getLocation()!=null )
{
String fileName = Utils.removeDotFromFileName(msg.getLocation().getFileName());
//System.out.println("err="+fileName);
res = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName));
if( res==null || !res.exists() )
res = project;
}
IMarker m = res.createMarker(IMarker.PROBLEM);
m.setAttribute(IMarker.MESSAGE, msg.getMessage());
if( msg.getLocation()!=null )
m.setAttribute(IMarker.LINE_NUMBER, msg.getLocation().getLineNum());
if(msg.getLevel() == ParserMessage.ERROR || msg.getLevel() == ParserMessage.INTERNAL_ERROR)
m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
else if(msg.getLevel() == ParserMessage.WARNING)
m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
else
m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
}
}
catch( Exception e )
{
e.printStackTrace();
}
}
public void writeTinydtFile()
{
IFile file = project.getFile(TINYDT_FILENAME);
String input = new String();
// write applications
Iterator it = applications.entrySet().iterator();
while(it.hasNext())
{
Map.Entry e = (Map.Entry) it.next();
Application app = (Application) e.getValue();
input = input.concat("APP=");
input = input.concat(app.configurationFileName);
input = input.concat("\n");
input = input.concat("PLATFORM=");
input = input.concat(app.platform);
input = input.concat("\n");
input = input.concat("SENSORBOARD=");
input = input.concat(app.sensorBoard);
input = input.concat("\n");
Iterator it2 = app.additionalIncludeFolders.iterator();
while(it2.hasNext())
{
String folder = (String) it2.next();
input = input.concat("FOLDER=");
input = input.concat(folder);
input = input.concat("\n");
}
input = input.concat("APPEND\n\n");
}
// write current app
input = input.concat("CURRENTAPP=" + currentApp + "\n");
// write input to the file
InputStream i = new ByteArrayInputStream(input.getBytes());
try
{
if(file.exists())
file.setContents(i, IResource.FORCE, null);
else
file.create(i, IResource.FORCE, null);
}
catch(CoreException e)
{
e.printStackTrace();
}
}
public void readTinydtFile()
{
IFile file = project.getFile(TINYDT_FILENAME);
if(file.exists())
{
try
{
BufferedReader r = new BufferedReader(new InputStreamReader(file.getContents()));
Application app = null;
applications.clear();
// read lines
String line = r.readLine();
while(line != null)
{
if(line.length() > 0)
{
StringTokenizer tokenizer = new StringTokenizer(line, "=");
String token = tokenizer.nextToken();
if(token.equalsIgnoreCase("APP"))
{
token = tokenizer.nextToken();
// start appliation
app = new Application();
app.configurationFileName = new String(token);
app.additionalIncludeFolders = new ArrayList();
}
else if(token.equalsIgnoreCase("PLATFORM"))
{
token = tokenizer.nextToken();
app.platform = new String(token);
}
else if(token.equalsIgnoreCase("SENSORBOARD"))
{
token = tokenizer.nextToken();
app.sensorBoard = new String(token);
}
else if(token.equalsIgnoreCase("FOLDER"))
{
// add new folder to the list
token = tokenizer.nextToken();
app.additionalIncludeFolders.add(new String(token));
}
else if(token.equalsIgnoreCase("APPEND"))
{
// add application
applications.put(app.configurationFileName, app);
}
else if(token.equalsIgnoreCase("CURRENTAPP"))
{
token = tokenizer.nextToken();
currentApp = new String(token);
}
}
line = r.readLine();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
public HashMap getApplications()
{
return applications;
}
public void setApplications(HashMap apps)
{
applications = apps;
}
public String getCurrentApp()
{
return currentApp;
}
public void setCurrentApp(String currApp)
{
currentApp = currApp;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?