I'm currently experimenting with code generation via XSLT. For that, I am using the Eclipse Web Developer Tools (WDT), which not only allow you to run XSL-Transformations from within the IDE, but also let you define them using Run Configurations, where you can specify things like input and output files quite conveniently.

Setting up a run configuration for a XSL transformation

The idea is to bundle these transformation steps into a "Launch Group", so that they all can be executed at once. However, as we are talking about code generation, it would be nice if this Launch Group (which is nothing but another run configuration, exportable as .launch file) would be executed automatically, whenever these files might have changed.

My current approach is to do this during the build phase, meaning: Adding a builder to the project that runs right before the java builder and that executes a given run configuration. I know how to add an additional builder, but I have no idea how get to the run configuration from there on. So: Is it possible to execute a run configuration from one of the project's builders?

Additional Notes: I found Ant4Eclipse, which could be capable of what I want, but it hasn't been updated in a really long time and it seems to focus on the ability to read data from run configurations, not to simply execute them.

Additionally, there could be other approaches, like triggering the XSL transformations from the builder "manually" using an external, command line driven tool. I'd be grateful for such solutions as well, however, the more generic the solution, the better.

有帮助吗?

解决方案

Technically, it should be possible.

You can add code to your build logic to call the given launch configuration. This is an example of how to get and launch a given run configuration:

ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfiguration launchConfiguration = launchManager.getLaunchConfiguration("launchConfigName");
ILaunchConfigurationWorkingCopy launchConfigWorkingCopy = launchConfiguration.getWorkingCopy();
launchConfigWorkingCopy.setAttributes(launchAttributes); // launchAttributes is a Map<String,String>
ILaunchConfiguration newLaunchConfig = launchConfigWorkingCopy.doSave();
ILaunch launch = newLaunchConfig.launch(launchMode, new NullProgressMonitor(), true);

The code above is from a project I worked on recently. I allows you to get a particular launch configuration and customize it as you wish. You could add this code in your build method in your builder.

The only drawback is that it requires that the launch configuration exists already. Alternatively, you could "create" one if it does no exist, by putting the .launch file in the .metadata/.plugins/org.eclipse.debug.core/.launches/ folder. This way, the LaunchManager will be able to find it.

其他提示

Maybe I misunderstood, but I think you're looking for a way to import a launch configuration as a builder. Here's how to do it:

Open the properties for your project, then choose Builders on the left. Clicking Import displays the list of launch configurations. Select your configuration and click OK twice.

Select the new builder from the list and click Edit, then on the Build Options tab:

  • Specify working set of relevant resources - these are the files that Eclipse will monitor for changes and automatically launch the builder
  • Clear the Launch in background checkbox to have Eclipse wait for this builder to finish before starting the next one
  • If needed, you can also redirect the standard output to a file for debugging

Note: Changes made to the launch configuration after importing it as a builder will not propagate into the builder, you will most likely have to re-import it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top