【问题标题】:Eclipse: saved LaunchConfiguration overrides LaunchTypeEclipse:保存的 LaunchConfiguration 会覆盖 LaunchType
【发布时间】:2013-10-03 10:53:05
【问题描述】:

不确定是 Eclipse 还是 Eclipse-plugin-dev 答案。

open-source Nodeclipse 项目中plugin.xml defines that .coffee file can be launched coffeecoffee --compileNode with monitor(有3 defined LaunchShortcuts)。

第一次它工作正常,但随后的启动只重复以前的 LaunchType。我发现删除已保存的 LaunchConfiguration(从运行 -> 运行配置)将让它再次运行(然后仅作为这种类型再次运行)

有问题的代码是LaunchShortcut(参见下面的sn-p),但是没有任何if 检查,所以这个行为应该在Eclipse org.eclipse.debug 模块中更深入。

如何保存 LaunchConfiguration 覆盖 LaunchType ?

/**
* Launch an file,using the file information, which means using default
* launch configurations.
*
* @param file
* @param mode
*/
private void launchFile(IFile file, String mode) throws CoreException {
    // check for an existing launch config for the file
    String path = file.getFullPath().toString();
    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(Constants.LAUNCH_CONFIGURATION_TYPE_ID);
    ILaunchConfiguration configuration = createLaunchConfiguration(type, path, file);
    DebugUITools.launch(configuration, mode);
    // then execution goes in LaunchConfigurationDelegate.java launch() method
}

/**
* Create a new configuration and set useful data.
*
* @param type
* @param path
* @param file
* @return
* @throws CoreException
*/

private ILaunchConfiguration createLaunchConfiguration(ILaunchConfigurationType type, String path, IFile file) throws CoreException {
 String configname = file.getFullPath().toString().replace('/', '-');
 if(configname.startsWith("-")) {
 configname = configname.substring(1);
 }

 ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(type);
 for(ILaunchConfiguration config : configs) {
 if(configname.equals(config.getName())) {
 return config;
 }
 }

 // create a new configuration for the file
    ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, configname);
    workingCopy.setAttribute(Constants.KEY_FILE_PATH, path);
    setMoreAttributes(workingCopy);
    return workingCopy.doSave();
}

protected void setMoreAttributes(ILaunchConfigurationWorkingCopy workingCopy) {
// stub for extension
}

帮助!代码 sn-p 可能不足以回答问题,但引用文件和所有内容都在 Github 存储库中。提出了这个问题,因为我不确定是否有可能为同一个文件设置多个运行配置。那么代码sn-ps就无所谓了。

更新:看了一段时间plugin.xml defines that .coffee file can be launched ,我注意到我实际上在所有 5 个案例中都使用了相同的 <configurationType id= "org.nodeclipse.debug.launch.LaunchConfigurationType" >。但是,为每次启动添加唯一的 LaunchConfigurationType id 并没有什么区别。

【问题讨论】:

  • 到目前为止您尝试过什么?是否可以选择覆盖默认启动配置文件?
  • 你的意思是在文件系统级别?找到 Eclipse 存储这些数据的位置,然后删除这些文件?嗯...是的,这是个主意。
  • Problem delete 不会解决因为有一个默认配置可以在删除数据的情况下重建它们,我的意思是找到默认配置文件并在其中进行更改,因此您不会丢失数据 cos该文件已创建
  • 我不清楚你到底是什么意思。您能否添加答案,以便讨​​论。

标签: java launch eclipse-plugin nodeclipse


【解决方案1】:

您可以使用以下命令创建启动配置:

Creating a Java application launch configuration

也可以通过以下帮助设置启动组:

Launch Group

到这里为止,我很确定您对此有所了解,所以让我们继续前进;您可以为同一个文件设置不同的启动配置,这由启动组工具处理,我不知道您是否需要针对同一环境使用不同的配置。

也可以在这里Launch Configuration TypesAdding launchers to the platform 找到有关启动类型文件结构的信息

到此结束Interface ILaunchConfigurationTabGroup是启动类型标签组的界面;

我在代码行中的建议:

<extension point="org.eclipse.debug.ui.launchConfigurationTabGroups">
   <launchConfigurationTabGroup 

        <"launchConfigurationType1"

        <"/launchConfigurationType1"> 

             <"launchConfigurationType2"

             <"/launchConfigurationType2">

       //and so on... 

   </launchConfigurationTabGroup>
 </extension>

【讨论】:

  • 这是我的 plugin.xml github.com/Nodeclipse/nodeclipse-1/blob/master/… 它为 .coffee 定义了 2 次启动,与 .js 类似,但在几个 plugin.xml 文件中。问题是 Eclipse 会记住第一次使用的启动,而忽略之后使用的启动。
  • 我仍然不明白为什么要打扰,我的意思是,如果您的第一个文件按您想要的方式工作,那么问题是什么?您是否需要“动态地”更改它(每次打开时)?或者您想创建这样的功能?
  • 假设有 .js 文件是 Node.js 应用程序。它们可以使用node 可执行文件或某些监视器(如forever)运行。第一次启动后启动类型的问题已修复。或者考虑一下可以与 node、mozilla rhino、java 8 nashorn 和其他 JS 引擎一起运行的一般 .js 文件。
猜你喜欢
  • 2011-08-19
  • 1970-01-01
  • 2011-08-17
  • 2015-07-02
  • 1970-01-01
  • 2018-07-26
  • 2014-08-24
  • 1970-01-01
相关资源
最近更新 更多