views:

1635

answers:

10

My plugin has to write to the eclipse console - for testing purpose I simplified my code, so that I only have the following:

public void start(BundleContext context) throws Exception {
        super.start(context);
        plugin = this;
        System.out.println("Tecomp Plugin is running");

        MessageConsole myConsole = new MessageConsole("My Console", null);
        //myConsole.activate();
        ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{ myConsole });
        ConsolePlugin.getDefault().getConsoleManager().showConsoleView(myConsole);
        final MessageConsoleStream stream = myConsole.newMessageStream();
        stream.setActivateOnWrite(true);
        stream.println("Hi there!");
        stream.close();
    }

It's a simple plugin, the method start belogs to the class extending AbstractUIPlugin - it't no rcp application. Code works fine inside the runtime workbench - once the plugin is installed, the output gets lost somewhere. The rest of the plugin is working properly.

Is there perhaps a problem with the ConsolePlugin? Or are streams handled differently in the runtime workbench and the development workbench?

I tried both - a feature project and directly copying the plugin jar to the eclipse directory - for installing the plugin - same result for both...

Any help is welcome, because I'm struggeling with that problem for a while now...

Regards, Kathi

Edit:

it doesn't seem to be a problem of the Console... I provided my own view for printing the output, but although declard in the plugin.xml there is no view after installing the plugin... here is what I did: -export the plugin with the ExportWizard into a jar-archive -copied this archive to /usr/share/eclipse/plugins -restarted eclipse

or with a feature project: -exported the feature-project containing my plugin with the ExportWizard -removed the above jar archive from the eclipse dir -installed the feature -restarted eclipse

both didn't word - did I get something wrong with installing the plugin? The jar-archive is ok, I checked it - it's the latest version. But somehow it seems that eclipse is still working with some older plugin without the changes I made

regards, Kathi

Edit:

I implemented the IStartup Interface end extended the org.eclipse.ui.startup point, but nothing changed... I really thinks it's an installation problem somehow. I commented out some output but it's still printed to the debug console. Is there some sort of plugin cache in eclipse? So that the new code doesn't get read?

Edit:

Thanks for the suggestions, but starting eclipse with the -clean option didn't help - I'll try to install the plugin in some other environment next week - perhaps there is something wrong with mine...

A: 

You need to show us more details. Where is the MessageConsoleStream defined? Your MessageConsole should probably inherit from the IOConsole class, which has a method "newOutputStream()" (I think) which gets you an OutputStream object to which you can print.

JesperE
A: 

the code in the class calling the compilier looks as follows:

private MessageConsole findConsole(String name){
 ConsolePlugin plugin = ConsolePlugin.getDefault();
 IConsoleManager conMan = plugin.getConsoleManager();
 IConsole[] existing = conMan.getConsoles();
 for (int i = 0; i<existing.length; i++){
  if (name.equals(existing[i].getName())){
   return (MessageConsole)existing[i];
  }
 }
 //no console found -> create new one
 MessageConsole newConsole = new MessageConsole(name, null);
 conMan.addConsoles(new IConsole[]{newConsole});
 return newConsole;
}



public void run(){
     MessageConsole console = findConsole("tecompConsole");
     //display the tecomp Console
     IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
     String id = IConsoleConstants.ID_CONSOLE_VIEW;
     try {
      IConsoleView view = (IConsoleView) page.showView(id);
      view.display(console);
     } catch (PartInitException e) {
      e.printStackTrace();
     }
     MessageConsoleStream output = console.newMessageStream();
     String tecompPath = TecompPlugin.getDefault().getPreferenceStore().getString(IEiffelConstants.TECOMP_PATH);
     if (checkTecompPath(tecompPath)){
      String line;
      String[] cmd = {tecompPath, pathToAceFile};
      try{
       output.println("calling tecomp");
       Process tecomp = Runtime.getRuntime().exec(cmd);
       //capture stdout und stderr from tecomp
       BufferedReader input = new BufferedReader(
         new InputStreamReader(tecomp.getInputStream()));
       BufferedReader err = new BufferedReader(
         new InputStreamReader(tecomp.getErrorStream()));
       while ((line = input.readLine()) != null ){
        output.println(line);
       } 
       input.close();
       while ((line = err.readLine()) != null){
        output.println(line);
       }
       err.close();
       output.close();
       tecomp.waitFor();
       //System.out.println(tecomp.exitValue());
      }catch (Exception err){
       err.printStackTrace();
      }
     } else {
      try{
      output.println("please specify a tecomp path");
      output.close();
      }catch (Exception err){}
     }
    }

but the first test example should work, shouldn't it? I create a new MessageConsoleStream and write to it manually. Thats exactely like the examples I found...

regards, Kathi

+1  A: 

Did you check "Displaying the console in your RCP application" ?

Would the follwoing small code (done in the Application.java run() before creating and running the workbench) begin to at least behave like what you want ?

MessageConsole console = new MessageConsole(”System Output”, null);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console);
MessageConsoleStream stream = console.newMessageStream();

System.setOut(new PrintStream(stream));
System.setErr(new PrintStream(stream));

logger = LoggerFactory.getLogger(Application.class); // Previously declared.

(I.e. does a console display itself when your plugin is installed in eclipse ?)

VonC
A: 

Hi,

the code doesn't belog to an rcp application - it's just a plugin, extending the eclipse ide with support for the eiffel programming language. So I think your suggestion doesn't work for my plugin - VonC, at least I don't know where to put your code... My first sample code in the initial question gets called inside the Plugin class extending AbstractUIPlugin within the start(BundleContext context) method. My plugin in running, so somewhere this method gets called. And as I mentioned - plugin works fine inside the runtime workbench... I'm sorry if this is not the right place for an additional explanation of my question - but it seemed to be the only place the system allows me to post some further lines. Comments to your answers are not allowed for me, because I just signed in and for that I don't have enough reputation points... so, please correct me, if I'm using the system wrong :) thx

regards, Kathi

A: 

The Eclipse console has a list that is shown when a small triangle (pointing down) at the top left is clicked. Does your console appear there? I believe it should. If it is then select the console to see the contents that you are logging there.

daanish.rumani
no, my console does not appear there
A: 

Sounds to me the eclipse application where you try to install your plugin into might not have the org.eclipse.ui.console plugin installed that you need to have as a plugin dependency. Did you check that your plugin has the correct plugin dependencies and that it is installed without a problem?

lothar
org.eclipse.ui.console is listed as dependency in my plugin and is also installed inside the eclipse application. Plugin installs without problems...
A: 

I think the problem is that your plugin is not being started. The code you show won't be activated until some other plug-in tries to access something within your plugin. It seems like this is the case with your debug launch configuration, but not with the packaged application.

You could try to implement the IStartup interface, and use the org.eclipse.ui.startup extension point in your plugin to force the initialization as soon as the UI is loaded. This should activate your plugin and execute the console code that you have.

Can you maybe add some logging statement or breakpoint in the start() method to ensure that it is being invoked on your deployed application?

Mario Ortegón
didn't help at all - see my edit above. runtime-workbench works fine - as before. And the plugin definitely IS running after installation, syntax highlighting etc. is working - but somehow it seems to be some older version running... don't know where the problem is
A: 

You probably have to clear the cached data used by OSGI and the eclipse runtime. You can do that by adding the -clean argument to your eclipse command line.

Here is the relevant information from the Plug-in Dev Guide:

Cleans cached data used by the OSGi framework and Eclipse runtime. Try to run Eclipse once with this option if you observe startup errors after install, update, or using a shared configuration.

See the Eclipse runtime options for more information.

You might also want to check into using update sites. I routinely use a local update site to install plugins while testing as it seems less error prone. The Eclipse FAQ has a quick article on how to create an update site.

gcastro
A: 

Another possibility then is that the plugin you are installed is cached in the installation. You can start eclipse with the -clean option to remove all the cached plugins from the workspace

Mario Ortegón
A: 

Probably should've commented on this one instead of the other one, see my comment on the other thread.

gcastro