1

I'm trying to run a headless eclipse build but I'm getting stuck. My context is that I want to use the PyDev code analysis without having to fire up the eclipse gui. I am aware of the other command line tools to do code analysis (pyflakes, pylint, etc).

The command I have so far is:

java -jar /path/to/eclipse/plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar -noSplash -data "/path/to/workspace" -application org.eclipse.jdt.apt.core.aptBuild

My java version 1.6.0_31, my eclipse version is 3.7.2, and my pydev version is 2.5.0.

When I run the command, it looks like it is working, but it never catches any errors or warnings.

...
PyDev: Analyzing 29 of 33 (forms.py)
PyDev: Analyzing 29 of 33 (forms.py)
PyDev: Analyzing 29 of 33 (forms.py)
PyDev: Analyzing 29 of 33 (forms.py)
...

If I tail -f /path/to/workspace/.metadata/.log, I get a huge stack trace:

!ENTRY org.eclipse.equinox.preferences 4 2 2012-07-30 17:48:39.612
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.equinox.preferences".
!STACK 0
java.lang.ExceptionInInitializerError
    at org.eclipse.debug.internal.ui.DebugUIPreferenceInitializer.setDefault(DebugUIPreferenceInitializer.java:186)
    at org.eclipse.debug.internal.ui.DebugUIPreferenceInitializer.setThemeBasedPreferences(DebugUIPreferenceInitializer.java:204)
    at org.eclipse.debug.internal.ui.DebugUIPreferenceInitializer.initializeDefaultPreferences(DebugUIPreferenceInitializer.java:79)
    at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper$1.run(PreferenceServiceRegistryHelper.java:281)
..... TRUNCATED ......

!ENTRY org.eclipse.osgi 4 0 2012-07-30 17:48:39.622
!MESSAGE An error occurred while automatically activating bundle org.eclipse.debug.ui (42).
!STACK 0
org.osgi.framework.BundleException: Exception in org.eclipse.debug.internal.ui.DebugUIPlugin.start() of bundle org.eclipse.debug.ui.
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:299)
..... TRUNCATED .......

java.lang.IllegalStateException: Workbench has not been created yet.
    at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:92)
    at org.eclipse.debug.internal.ui.contextlaunching.LaunchingResourceManager.startup(LaunchingResourceManager.java:546)
    at org.eclipse.debug.internal.ui.DebugUIPlugin.getLaunchingResourceManager(DebugUIPlugin.java:315)
    at org.eclipse.debug.internal.ui.DebugUIPlugin.start(DebugUIPlugin.java:516)
..... TRUNCATED ......

!ENTRY org.eclipse.osgi 4 0 2012-07-30 17:48:39.624
!MESSAGE An error occurred while automatically activating bundle org.eclipse.debug.core (41).
!STACK 0
org.osgi.framework.BundleException: Exception in org.eclipse.debug.core.DebugPlugin.start() of bundle org.eclipse.debug.core.
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:299)
..... TRUNCATED ......

My suspicion is that PyDev needs the gui to render the errors/warnings.

almostflan
  • 640
  • 4
  • 15

1 Answers1

2

PyDev needs the gui to render errors/warnings and in general it was not done to be used in the command line... now, having said that, it does have unit-tests that run the code-analysis without requiring a gui (nor even eclipse loaded), but you have to configure the interpreter/projects in-memory for that to work.

See:

https://github.com/aptana/Pydev/blob/development/plugins/com.python.pydev.analysis/tests/com/python/pydev/analysis/OccurrencesAnalyzerTest.java

https://github.com/aptana/Pydev/blob/development/plugins/com.python.pydev.analysis/tests/com/python/pydev/analysis/AnalysisTestsBase.java

for tests that do code-analysis without requiring the eclipse workbench to be loaded at all (i.e.: doesn't even need eclipse to be run headless -- it could be run as a simple java program, but you still have to do the java main([]) using PyDev in the CLASSPATH and using its API to properly set the interpreter used in PyDev as well as the projects/pythonpath).

You can take a look at the setUp of the tests (i.e.: don't forget to also look superclasses such as CodeCompletionTestsBase/AnalysisTestsBase).

Note: if you do create such a main([]), please provide a patch for PyDev as it may be used by others...

As an implementation note, such a main should probably gather all the current PYTHONPATH entries from the shell being launched and configure all of those in the interpreter... Also, it should probably receive a directory as a parameter so that it analyzes all files in the tree (the startup is probably going to take the most of your time to configure things, so, ideally analyze as much files as you can from a single run, as the PyDev code-analysis was done to cache lots of things in the startup and then use the information from RAM -- or maybe create a server process that's always live?).

Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78