Junwei's profileHappy here, love here!PhotosBlogListsMore Tools Help

Blog


    April 27

    是否应该珍惜

    曾几何时,幻想自己成为一个都市白领。如今,迷茫在上海这座繁华的大都市
    也许很多人认为我找到了一份心仪的好工作,拿着比起同龄人不扉的工资,但是我不快乐。
    我就是不快乐……
     
    想着逃逸,就像当初进入医学院的心情,不是它不好,但的确不是自己所喜欢的
    记得当时,我对自己说,一定要离开医学院,大一不行就大二,再不行还可以考研。
    最终的成功,运气+不懈的努力
     
    可如今,再没有锋芒的锐气,似乎宁愿在这里窒息。想要离开,但没有勇气和信心,想要努力,但一切毫无头绪。如今的自己,宛如迷失在茫茫大海里的一叶孤舟,不知道正确的航线。
     
    也不知从何时起,有了自卑。丧失了好强与那种不认输的劲头,丧失了为前途拼搏的那份热情。认真的告诉过自己,不要对任何困难低头,不要惧怕任何挑战,但最终,还是退缩拉……不知道自己什么时候才可以去尝试一下那种挑战,即使是失败,那也可以无愧的告诉自己,我努力过,奋斗过
    April 11

    Java eclipse plugin

    最近研究了一点点eclipse plugin 的小问题,感觉最辛苦的就是在google上搜索,总是找不到合适的解决方法。还好在我的胡乱蒙撞加上天才般的测试和各种不懈的推敲,终于搞定了几个对于我这种初学者来说比较困难的问题。
    写在我的space上,这样其他人google的时候也算可以看到吧。想想我们部门的老外说他的爱好是open source,在加上这些日子在论坛上逛,发现很多程序员很是热心的帮助大家解答问题,梦想自己是编程牛人的那一天…… 不再潜水
     
    1,在代码里实现新建一个C的项目(programmatically create c project)在同事做的基础之上,稍加修改,成功测试通过。
     IProgressMonitor monitor=new  NullProgressMonitor();
      monitor.beginTask("Creating C Project...", 3);
        try{
        IWorkspace ws=ResourcesPlugin.getWorkspace();
       IProject newProjectHandle=ws.getRoot().getProject("test");
         IWorkspace workspace=ResourcesPlugin.getWorkspace();
      IProjectDescription description=workspace.newProjectDescription(newProjectHandle.getName());
       description.setLocation(new Path("/home/ejunguo/workspace"));
       CCorePlugin.getDefault().createCProject(description,newProjectHandle,monitor,MakeCorePlugin.MAKE_PROJECT_ID);
      MakeProjectNature.addNature(newProjectHandle, new SubProgressMonitor(monitor,1));
      } catch (OperationCanceledException e) {
       e.printStackTrace();
      } catch (CoreException e) {
       e.printStackTrace();
      } catch (Exception e){
       e.printStackTrace();
      }
     }
    2,在代码里实现switch workspace( programmatically switch workspace)
    由于在eclipse的平台部分的功能,那eclipse的source code里肯定有,但是自己又懒得去搜索,于是乎在eclipse 社区经高人指点:
     
     看如果是平台的部分就把eclipse的代码全import到工作空间,然后在.properties文件里搜那个菜单项的label,比如 “Switch Workspace”,那就搜Switch(如果不确定那个下划线怎么表示),搜出来一堆,找。。。在ui.ide的某 messages.properties里有Switch &Workspace...,再用key(OpenWorkspaceAction_text)搜,范围在这个包里,然后就找到 OpenWorkspaceAction.java
     
    这个确实实用,直接告诉我是 OpenWorkspaceAction 这个类,把自己的环境配到此类中,之后还遇到一个小小的问题,在runtime的plugin里,switch workspace是用不起来的,总是报这样的错误: Unable to relaunch the patform because the eclipse.vm property has not been set。 只得把项目打包,装载再测,便顺利通过。
     
    package plugin.actions;
    import org.eclipse.jface.action.Action;
    import org.eclipse.jface.dialogs.MessageDialog;
    import org.eclipse.osgi.util.NLS;
    import org.eclipse.ui.IWorkbenchWindow;
    import org.eclipse.ui.actions.ActionFactory;
    import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
    public class test extends Action implements
            ActionFactory.IWorkbenchAction {
        private static final String PROP_VM = "eclipse.vm"; //$NON-NLS-1$
        private static final String PROP_VMARGS = "eclipse.vmargs"; //$NON-NLS-1$
        private static final String PROP_COMMANDS = "eclipse.commands"; //$NON-NLS-1$
        private static final String PROP_EXIT_CODE = "eclipse.exitcode"; //$NON-NLS-1$
        private static final String PROP_EXIT_DATA = "eclipse.exitdata"; //$NON-NLS-1$
        private static final String CMD_DATA = "-data"; //$NON-NLS-1$
        private static final String CMD_VMARGS = "-vmargs"; //$NON-NLS-1$
        private static final String NEW_LINE = "\n"; //$NON-NLS-1$
        private IWorkbenchWindow window;
         public test(IWorkbenchWindow window) {
              MessageDialog.openInformation(
           window.getShell(),
           "Plugin Plug-in",
           "Hello first");
            if (window == null)
                throw new IllegalArgumentException();
            this.window = window;
             run();
        }
         public void run() {
            String path = "/var/tmp/rwtest";
            if (path == null)
                return;
            String command_line = buildCommandLine(path);
            if (command_line == null)
                return;
            System.setProperty(PROP_EXIT_CODE, Integer.toString(24));
            System.setProperty(PROP_EXIT_DATA, command_line);
            window.getWorkbench().restart();
        }
        
            private String buildCommandLine(String workspace) {
            String property = System.getProperty(PROP_VM);
            if (property == null) {
                MessageDialog
                        .openError(
                                window.getShell(),
                                IDEWorkbenchMessages.OpenWorkspaceAction_errorTitle,
                                NLS.bind(IDEWorkbenchMessages.OpenWorkspaceAction_errorMessage, PROP_VM));
                return null;
            }
            StringBuffer result = new StringBuffer(512);
            result.append(property);
            result.append(NEW_LINE);
            // append the vmargs and commands. Assume that these already end in \n
            String vmargs = System.getProperty(PROP_VMARGS);
            if (vmargs != null)
                result.append(vmargs);
            // append the rest of the args, replacing or adding -data as required
            property = System.getProperty(PROP_COMMANDS);
            if (property == null) {
                result.append(CMD_DATA);
                result.append(NEW_LINE);
                result.append(workspace);
                result.append(NEW_LINE);
            } else {
                // find the index of the arg to replace its value
                int cmd_data_pos = property.lastIndexOf(CMD_DATA);
                if (cmd_data_pos != -1) {
                    cmd_data_pos += CMD_DATA.length() + 1;
                    result.append(property.substring(0, cmd_data_pos));
                    result.append(workspace);
                    result.append(property.substring(property.indexOf('\n',
                            cmd_data_pos)));
                } else {
                    result.append(CMD_DATA);
                    result.append(NEW_LINE);
                    result.append(workspace);
                    result.append(NEW_LINE);
                    result.append(property);
                }
            }
             if (vmargs != null) {
                result.append(CMD_VMARGS);
                result.append(NEW_LINE);
                result.append(vmargs);
            }
            return result.toString();
        }
           public void dispose() {
            window = null;
        }
    }
    3,这个是很久以前解决的啦,就是有关java里进程问题,由于要和clearcase相连,在clearcase里setview时,必定要New 一个进程的,以后所有的工作要在这个新进程中去进行,如何实现process之间的通信,或是实现在其子进程中继续工作,这个问题苦恼了很久,因为大家对java的了解都很肤浅,所以一直认为无力解决,还好,在大家共同努力下,还是迎刃而解啦。(代码是同事修改过的,我的被自己不小心删掉了,汗)
     
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.util.ArrayList;
    import org.eclipse.ui.console.ConsolePlugin;
    import org.eclipse.ui.console.IConsole;
    import org.eclipse.ui.console.MessageConsole;
    import org.eclipse.ui.console.MessageConsoleStream;

    public class XProcess {
     Runtime runtime;
     Process process;
     BufferedReader in;
     BufferedWriter out;
     BufferedReader err;
     boolean flag;
     Thread erroutput;
     Thread stdoutput;
     String[] resultlist = null;
     ArrayList list = new ArrayList();
     String endflag = "";
     MessageConsoleStream consoleStream;
      MessageConsole console;
      public XProcess() {
      }
     
     public boolean initial() {
      runtime = Runtime.getRuntime();
      try {
       process = runtime.exec("tcsh");
          in = new BufferedReader(new InputStreamReader(process
         .getInputStream()));
       err = new BufferedReader(new InputStreamReader(process
         .getErrorStream()));
       out = new BufferedWriter(new OutputStreamWriter(process
         .getOutputStream()));
       flag = false;
       stdoutput = new Thread() {
        public void run() {
         try {
          String line;
                while ((line = in.readLine()) != null && flag == false) {
               list.add(line);
          }
         } catch (IOException e) {
          System.err.println(e);
         }
        }
       };
       stdoutput.start();
       return true;
      } catch (Exception e) {
       e.printStackTrace();
       return false;
      }
     }
     public String[] listen(int SleepSeconds,String flag) throws Exception {
      endflag = flag;
      int timeout = SleepSeconds;
      Thread.sleep(SleepSeconds);
      
      while (true) {
         Thread.sleep(SleepSeconds);
       timeout = timeout + SleepSeconds;
       if (timeout > 360000) {
        list.add("Time Out!");
        break;
       }
      }
      String[] stringlist = new String[list.size()];
      list.toArray(stringlist);
      resultlist = stringlist;
      list.clear();
      return resultlist;
     }
     public void launch(String cmd) {
      try {
       
       out.write(cmd);
       out.newLine();
       out.flush();
      } catch (IOException e) {
       e.printStackTrace();
      }
     }
      }
    就这么多吧,主要给大伙(初级入门的人)搜索时方便一些吧。