2012-07-31 126 views
1

我试图运行一个无头蚀的构建,但我陷入困境。我的背景是,我想使用PyDev代码分析,而不必启动Eclipse的GUI。我知道其他命令行工具来执行代码分析(pyflakes,pylint等)。是否可以从命令行运行PyDev代码分析?

我到目前为止的命令是:

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 

我的Java版本1.6.0_31,我的Eclipse版本是3.7.2,和我的PyDev的版本是2.5.0。

当我运行该命令时,它看起来像在工作,但它从不捕获任何错误或警告。

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

如果我tail -f /path/to/workspace/.metadata/.log,我得到一个巨大的堆栈跟踪:

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

我怀疑是PyDev的需要GUI渲染错误/警告。

回答

2

PyDev需要gui来显示错误/警告,并且通常不会在命令行中使用它......现在,它已经有单元测试运行代码分析,而不需要一个gui(甚至不会加载eclipse),但是你必须配置内存中的解释器/项目才能工作。

参见:

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

该做代码分析,而不需要Eclipse工作台测试,在所有被加载(即:甚至不需要Eclipse来运行无头 - 它可以作为一个简单的java程序运行,但是你仍然需要在CLASSPATH中使用PyDev来完成java main([]),并使用它的API来正确设置PyDev中使用的解释器以及projects/pythonpath) 。

您可以看看测试的setUp(即:不要忘记也要看像CodeCompletionTestsBase/AnalysisTestsBase这样的超类)。

注意:如果你创建这样一个main([]),请提供PyDev的补丁,因为它可能被别人利用...

作为实现注意,这样的主也许应该收集所有来自shell的当前PYTHONPATH条目将被启动并配置解释器中的所有条目......另外,它应该可能会接收一个目录作为参数,以便分析树中的所有文件(启动可能会占用最多的的时间来配置事物,所以理想情况下可以从单次运行中分析尽可能多的文件,因为PyDev代码分析可以在启动时缓存大量内容,然后使用RAM中的信息 - 或者可以创建一直活着的服务器进程?)。

相关问题