Kathi
Kathi

Reputation:

Writing to the Eclipse console

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...

Edit:

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 exactly like the examples I found.

Edit:

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

Upvotes: 5

Views: 14430

Answers (5)

VonC
VonC

Reputation: 1324178

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 ?)

Upvotes: 3

Mario Orteg&#243;n
Mario Orteg&#243;n

Reputation: 18900

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

Upvotes: 0

gcastro
gcastro

Reputation: 6276

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.

Upvotes: 0

Mario Orteg&#243;n
Mario Orteg&#243;n

Reputation: 18900

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?

Upvotes: 1

lothar
lothar

Reputation: 20209

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?

Upvotes: 0

Related Questions