Skip to content

Commit 841e6ef

Browse files
committed
Feature Validation
1 parent 4469a02 commit 841e6ef

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ public class PDEUIMessages extends NLS {
247247
public static String ContainerRenameParticipant_renameBundleId;
248248

249249
public static String ControlValidationUtility_errorMsgFilterInvalidSyntax;
250+
public static String ControlValidationUtility_errorMsgFeatureFilterInvalidSyntax;
250251
public static String ControlValidationUtility_errorMsgKeyNotFound;
251252
public static String ControlValidationUtility_errorMsgNotOnClasspath;
252253
public static String ControlValidationUtility_errorMsgPluginUnresolved;

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/MatchSection.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
3434
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
3535
import org.eclipse.pde.internal.ui.editor.PDESection;
36+
import org.eclipse.pde.internal.ui.editor.validation.ControlValidationUtility;
37+
import org.eclipse.pde.internal.ui.editor.validation.TextValidator;
3638
import org.eclipse.pde.internal.ui.parts.ComboPart;
3739
import org.eclipse.pde.internal.ui.parts.FormEntry;
3840
import org.eclipse.swt.SWT;
@@ -56,6 +58,7 @@ public class MatchSection extends PDESection implements IPartSelectionListener {
5658

5759
private FormEntry fVersionText;
5860
private FormEntry fFilterText;
61+
private TextValidator fFilterEntryValidator;
5962

6063
private ComboPart fMatchCombo;
6164
protected IPluginReference fCurrentImport;
@@ -159,6 +162,12 @@ public void textDirty(FormEntry text) {
159162
fBlockChanges = false;
160163
}
161164
});
165+
fFilterEntryValidator = new TextValidator(getManagedForm(), fFilterText.getText(), getProject(), true) {
166+
@Override
167+
protected boolean validateControl() {
168+
return validateFilter();
169+
}
170+
};
162171
update((IPluginReference) null);
163172

164173
section.setClient(container);
@@ -168,6 +177,16 @@ public void textDirty(FormEntry text) {
168177
section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
169178
}
170179

180+
private boolean validateFilter() {
181+
// No validation required for an optional field
182+
if (fFilterText.getText().getText().length() == 0) {
183+
return true;
184+
}
185+
// Value must match the current environment and contain valid syntax
186+
return ControlValidationUtility.validateFilterField(fFilterText.getText().getText(),
187+
fFilterEntryValidator);
188+
}
189+
171190
private void createReexportButton(FormToolkit toolkit, Composite container) {
172191
fReexportButton = toolkit.createButton(container, PDEUIMessages.ManifestEditor_MatchSection_reexport, SWT.CHECK);
173192
fReexportButton.addSelectionListener(widgetSelectedAdapter(e -> {
@@ -236,7 +255,6 @@ private void applyFilter(String filter) {
236255
((IFeatureImport) fCurrentImport).setFilter(filter);
237256
}
238257
} catch (InvalidSyntaxException e) {
239-
PDEPlugin.logException(e);
240258
} catch (CoreException e) {
241259
PDEPlugin.logException(e);
242260
}

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/validation/ControlValidationUtility.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ public static boolean validatePlatformFilterField(String value, IValidatorMessag
9595
return true;
9696
}
9797

98+
public static boolean validateFilterField(String value, IValidatorMessageHandler validator) {
99+
// Check to see if the platform filter syntax is valid
100+
try {
101+
PDECore.getDefault().getBundleContext().createFilter(value);
102+
} catch (InvalidSyntaxException ise) {
103+
validator.addMessage(PDEUIMessages.ControlValidationUtility_errorMsgFeatureFilterInvalidSyntax,
104+
IMessageProvider.ERROR);
105+
return false;
106+
}
107+
108+
return true;
109+
}
110+
98111
public static boolean validateActivatorField(String value, IValidatorMessageHandler validator, IProject project) {
99112

100113
// Check the compiler flag and translate it into a message type

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,6 +2524,7 @@ ControlValidationUtility_errorMsgValueMustBeSpecified=A value must be specified
25242524
ControlValidationUtility_errorMsgValueNotExternalized=The specified value is not externalized
25252525
ControlValidationUtility_errorMsgKeyNotFound=The specified key is not present in the plug-in's properties file
25262526
ControlValidationUtility_errorMsgFilterInvalidSyntax=The specified platform filter contains invalid syntax
2527+
ControlValidationUtility_errorMsgFeatureFilterInvalidSyntax=The specified feature filter contains invalid syntax
25272528
PackageFinder_taskName=Searching class files for package references
25282529

25292530
UpdateSingleton_dir_label=Update ''{0}'' to 'singleton' directive true

0 commit comments

Comments
 (0)