Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Creating custom JUnit launch configuration in eclipse(This topic deals with creating custom run/debug JUnit launch configuration in eclipse for Plugins)
Creating custom JUnit launch configuration in eclipse [message #1793995] Wed, 22 August 2018 05:55
prithivraj s is currently offline prithivraj sFriend
Messages: 1
Registered: August 2018
Junior Member
I am trying to create a custom JUnit plugin test launch configuration.

I have extended the class JUnitWorkbenchLaunchShortcut and overridden the method createLaunchConfiguration() to write my custom configuration.

@Override
protected ILaunchConfigurationWorkingCopy createLaunchConfiguration(final IJavaElement element)
        throws CoreException {
    ILaunchConfigurationWorkingCopy configuration = super.createLaunchConfiguration(element);
    configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
            XMX2048M_XX_USE_PARALLEL_GC_DOSGI_FRAMEWORK_EXTENSIONS_ORG_ECLIPSE_EQUINOX_WEAVING_HOOK_DEQUINOX_USE_DS_TRUE);
    configuration.setAttribute(IPDELauncherConstants.USE_PRODUCT, false);
    configuration.setAttribute(IPDELauncherConstants.APPLICATION, "org.eclipse.ui.ide.workbench");
    configuration.setAttribute(IPDELauncherConstants.USE_DEFAULT, false);
    configuration.setAttribute(IPDELauncherConstants.AUTOMATIC_ADD, false);
    addDependencies(configuration);
    return configuration;
}


private void addDependencies(final ILaunchConfigurationWorkingCopy configuration) throws CoreException {
    PluginModelNameBuffer wBuffer = new PluginModelNameBuffer();
    PluginModelNameBuffer tBuffer = new PluginModelNameBuffer();
    Set<IPluginModelBase> addedModels = new HashSet<>();

    String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    IPluginModelBase model = PluginRegistry.findModel(project);
    wBuffer.add(model);
    addedModels.add(model);

    IPluginModelBase[] externalModels = PluginRegistry.getExternalModels();
    for (IPluginModelBase externalModel : externalModels) {
        String id = externalModel.getPluginBase().getId();
        if (id != null) {
            switch (id) {
            case "org.eclipse.ui.ide.application":
            case "org.eclipse.equinox.ds":
            case "org.eclipse.equinox.event":
                tBuffer.add(externalModel);
                addedModels.add(externalModel);
                break;
            default:
                break;
            }
        }
    }

    TreeSet<String> checkedWorkspace = new TreeSet<>();
    IPluginModelBase[] workspaceModels = PluginRegistry.getWorkspaceModels();
    for (IPluginModelBase workspaceModel : workspaceModels) {
        checkedWorkspace.add(workspaceModel.getPluginBase().getId());
    }

    EclipsePluginValidationOperation eclipsePluginValidationOperation = new EclipsePluginValidationOperation(
            configuration);
    eclipsePluginValidationOperation.run(null);

    while (eclipsePluginValidationOperation.hasErrors()) {
        Set<String> additionalIds = DependencyManager.getDependencies(addedModels.toArray(), true, null);
        if (additionalIds.isEmpty()) {
            break;
        }
        additionalIds.stream().map(PluginRegistry::findEntry).filter(Objects::nonNull).map(ModelEntry::getModel)
                .forEach(addedModels::add);

        for (String id : additionalIds) {
            IPluginModelBase plugin = findPlugin(id);
            if (!plugin.getPluginBase().getId().endsWith("tests")) {
                if (checkedWorkspace.contains(plugin.getPluginBase().getId())) {
                    wBuffer.add(plugin);
                } else {
                    tBuffer.add(plugin);
                }
            }
        }
        eclipsePluginValidationOperation.run(null);
    }

    configuration.setAttribute(IPDELauncherConstants.SELECTED_WORKSPACE_PLUGINS, wBuffer.toString());
    configuration.setAttribute(IPDELauncherConstants.SELECTED_TARGET_PLUGINS, tBuffer.toString());
}

protected IPluginModelBase findPlugin(final String id) {
    ModelEntry entry = PluginRegistry.findEntry(id);
    if (entry != null) {
        return entry.getModel();
      }
    return null;
   }
}



Problem is that the launch configuration is created exactly how its supposed to be but plugin test does not run when the workbench is opened. The tests are executed only when the run configuration dialog is opened and the run button inside it is clicked.
Previous Topic:TextEditor AnnotationModel not supporting multiple Documents ?
Next Topic:IWorkbenchBrowserSupport plugin is not working in Oxygen4.7.3a
Goto Forum:
  


Current Time: Fri Sep 21 21:35:21 GMT 2018

Powered by FUDForum. Page generated in 0.02149 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top