goclipse 修改
无    2014-03-03 17:11:27    751    0    0
life

编译

eclipse编译go不显示编译语句, 有时会出现莫名其妙的错误.

目标: 修改后显示编译语句, 详细错误信息, 如下图:

修改方法:

svn checkout goclipse源码 https://code.google.com/p/goclipse/source/checkout, trunk/goclipse-n就是goclipse项目, 直接导入到eclipse中.

修改文件:

添加console变量

	static MessageConsole console;
	static MessageConsoleStream consoleOut;
	static MessageConsoleStream consoleOutRed;
	static MessageConsoleStream consoleOutGreen;
	
	static Boolean hasPrintPath = false;
	public static MessageConsoleStream getConsole() {
		if(consoleOut == null) {
			console = GoConstants.findConsole("Go-Life");
//		    console.clearConsole();
	    	console.activate();
	    	consoleOut = console.newMessageStream();
	    	
	    	consoleOutRed = console.newMessageStream();
	    	consoleOutRed.setColor(new Color(Display.getDefault(), 255, 0, 0));
	    	
	    	consoleOutGreen = console.newMessageStream();
	    	consoleOutGreen.setColor(new Color(Display.getDefault(), 19, 119, 62));
		}
		return consoleOut;
	}

方法compileAll(), compileCmd(), compilePkg(), installAll()也是类似修改

	/**
	 * @param project
	 * @param pmonitor
	 * @param fileList
	 */
	public void compileAll(final IProject project, IProgressMonitor pmonitor, IFolder target) {
		
		final IPath  projectLocation = project.getLocation();
		
		final IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
		final String           compilerPath    = preferenceStore.getString(PreferenceConstants.GO_TOOL_PATH);

		try {
			// the path exist to find the cc
			String   path    = System.getenv("PATH");
			String[] cmd     = {};
			
			MarkerUtilities.deleteFileMarkers(target);
			cmd = new String[] {
		        compilerPath,
		        GoConstants.GO_BUILD_COMMAND
		    };
			
			String goPath = buildGoPath(project, projectLocation, false);

			File file = new File(target.getLocation().toOSString());
 			ProcessBuilder builder = new ProcessBuilder(cmd).directory(file);
			builder.environment().put(GoConstants.GOROOT, Environment.INSTANCE.getGoRoot(project));
			builder.environment().put(GoConstants.GOPATH, goPath);
			builder.environment().put("PATH", path);
			Process p = builder.start();
			
			String cmdStr = "";
		    for(String each : cmd) {
		    	cmdStr += each + " ";
		    }
		    
		    consoleOut.flush();
		    consoleOutGreen.write("\n");
		    consoleOutGreen.write("in : " + file);
		    consoleOutGreen.write("\n");
		    consoleOutGreen.write("cmd: " + cmdStr);
		    consoleOutGreen.write("\n");
		    consoleOutGreen.flush();

			try {
				p.waitFor();

			} catch (InterruptedException e) {
				Activator.logInfo(e);
			}
			
			refreshProject(project, pmonitor);
		    InputStream is = p.getInputStream();
		    InputStream es = p.getErrorStream();
		    StreamAsLines sal = new StreamAsLines();
		    sal.setCombineLines(true);
		    sal.process(is);
		    sal.process(es);
		    
		    String currentPackage = "";
		    for ( String line : sal.getLines()) {
		    	System.out.println(line);
		    	if(line.startsWith("#")) {
		    		currentPackage = line.replace("#", "").trim();
		    		continue;
		    	}
		    	String[] elements = line.split(":");
		    	String message = line.substring(elements[0].length()+elements[1].length()+2);
		    	path = target.getName()+File.separator+elements[0];
		    	IResource res = project.findMember(path);
		    	MarkerUtilities.addMarker(res, Integer.parseInt(elements[1]), message, IMarker.SEVERITY_ERROR);
		    }

		} catch (IOException e1) {
			Activator.logInfo(e1);
		}
	}

项目配置

解决配置Go Project Configuration 的Source总是要重新添加问题, 如下图, 重启eclipse后还要重新添加src

修改:

Environment.java

	/**
	 * @param project
	 * @return
	 */
	private void saveProperties(IProject project) {
		if(project==null){
			Activator.logError("Null project given while atempting to save properties.");
			return;
		}
		
		Properties properties = getProperties(project);
		IPath path = project.getWorkingLocation(Activator.PLUGIN_ID);
		
		try {
			Activator.logInfo("writing to "
					+ path.toOSString()
					+ "/properties.xml");
			
// 修改这里 Properties properties2 = new Properties(); for ( Map.Entry<Object, Object> o : properties.entrySet()) { properties2.setProperty(o.getKey().toString(), o.getValue().toString()); } properties2.storeToXML(new FileOutputStream(path.toOSString() + "/properties.xml", false), project.getName()+" properties", "utf-8"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }

上一篇: golang从stdin中读取一行

下一篇: goeclipse不能保存项目配置

751 人读过
立即登录, 发表评论.
没有帐号? 立即注册
0 条评论