Skip to content

Commit

Permalink
Add a project config option to have validators for all features
Browse files Browse the repository at this point in the history
Currently a validator has to be configured for each feature, if one
wants to validate all features in a project this become cumbersome.

This adds a configuration option to enable validators for the whole
project.
  • Loading branch information
Christoph Läubrich committed Jun 2, 2024
1 parent 115f900 commit 1e269a4
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import org.eclipse.jdt.launching.JavaRuntime;

import cucumber.api.TypeRegistryConfigurer;
import cucumber.eclipse.backends.java.properties.JavaBackendPropertyPage;
import cucumber.eclipse.steps.integration.KeyWordProvider;
import cucumber.runtime.DefaultTypeRegistryConfiguration;
import cucumber.runtime.Reflections;
import cucumber.runtime.io.MultiLoader;
import cucumber.runtime.io.ResourceLoaderClassFinder;
import io.cucumber.cucumberexpressions.ExpressionFactory;
import io.cucumber.eclipse.java.properties.JavaBackendPropertyPage;
import io.cucumber.stepexpression.TypeRegistry;

public class JavaBackendAdapterFactory implements IAdapterFactory, IResourceChangeListener {
Expand Down

This file was deleted.

This file was deleted.

2 changes: 2 additions & 0 deletions examples/java-datatable/.settings/cucumber.backend.java.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
validationPlugins=cucumber.examples.datatable.GlobalValidator
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cucumber.examples.datatable;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import io.cucumber.plugin.Plugin;

/**
* This validator is enabled globally in the preferences
*/
public class GlobalValidator implements Plugin {

private ConcurrentHashMap<Integer, String> errors = new ConcurrentHashMap<>();

public GlobalValidator() {
errors.put(1, "Tis is an error from the global validator, but you can't do anything about it!");
}

// This is a magic method called by cucumber-eclipse to fetch the final errors and display them in the document
public Map<Integer, String> getValidationErrors() {
return errors;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#language: en
#This Feature has no validator enabled in the feature file but in the project preferences!
Feature: Connection between DataTable Key and a specific Step Value


Scenario: All Keys are related to a Step Value. Example 1
Given the animal "Cat"
| Key | Value |
| Color | Black |
| Lifespan | 3 |
| Whiskers | 24 |

Then the food is "fish"


Scenario: All Keys are related to a Step Value. Example 2
Given the animal "Elephant"
| Key | Value |
| Color | Grey |
| Lifespan | 70 |
| Trunk | 1.8 |
| Tusk | 1.3 |

Then the food is "leaves"


Scenario: There are some unrelated Keys to a Step Value. This Keys are available for other Step Value
Given the animal "Cat"
| Key | Value |
| Color | Black |
| Lifespan | 3 |
| Whiskers | 24 |
| Trunk | 1.8 |

Then the food is "fish"


Scenario: There are some unrelated Keys to a Step Value. This Keys are not available for each Step Value
Given the animal "Cat"
| Key | Value |
| Color | Black |
| Lifespan | 3 |
| Whiskers | 24 |
| Wings | 2 |

Then the food is "fish"

10 changes: 9 additions & 1 deletion io.cucumber.eclipse.editor/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@
</action>
</viewerContribution>
</extension>

<extension
point="org.eclipse.ui.propertyPages">
<page
class="io.cucumber.eclipse.editor.properties.CucumberPropertiesPage"
icon="icons/cukes.gif"
id="cucumber.eclipse.editor.properties.main"
name="Cucumber">
</page>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.cucumber.eclipse.editor.properties;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.PropertyPage;

import io.cucumber.eclipse.editor.Images;

public class CucumberPropertiesPage extends PropertyPage {

private static final String NAMESPACE = "io.cucumber.eclipse.editor";
private Text validationPlugins;

public CucumberPropertiesPage() {
setTitle("Cucumber");
setDescription("You can configure Cucumber related properties for your project here");
setImageDescriptor(Images.getCukesIconDescriptor());
noDefaultAndApplyButton();
}

/**
* @see PreferencePage#createContents(Composite)
*/
@Override
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
composite.setLayout(layout);
return composite;
}

private IResource getResource() {
return getElement().getAdapter(IResource.class);
}

public static IEclipsePreferences getNode(IResource resource) {
ProjectScope scope = new ProjectScope(resource.getProject());
IEclipsePreferences node = scope.getNode(NAMESPACE);
return node;
}

}
9 changes: 9 additions & 0 deletions io.cucumber.eclipse.java/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,13 @@
name="Java">
</page>
</extension>
<extension
point="org.eclipse.ui.propertyPages">
<page
category="cucumber.eclipse.editor.properties.main"
class="io.cucumber.eclipse.java.properties.JavaBackendPropertyPage"
id="cucumber.eclipse.backends.java.properties.samplePropertyPage"
name="Java Backend">
</page>
</extension>
</plugin>
Loading

0 comments on commit 1e269a4

Please sign in to comment.