[228382] Add junit tests to catch early activation
diff --git a/features/org.eclipse.wst.common_tests.feature/feature.xml b/features/org.eclipse.wst.common_tests.feature/feature.xml index 069a97c..9df70ac 100644 --- a/features/org.eclipse.wst.common_tests.feature/feature.xml +++ b/features/org.eclipse.wst.common_tests.feature/feature.xml
@@ -104,4 +104,11 @@ install-size="0" version="0.0.0"/> + <plugin + id="org.eclipse.wst.common.tests.validation.guard" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + </feature>
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/.classpath b/tests/org.eclipse.wst.common.tests.validation.guard/.classpath new file mode 100644 index 0000000..304e861 --- /dev/null +++ b/tests/org.eclipse.wst.common.tests.validation.guard/.classpath
@@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath>
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/.project b/tests/org.eclipse.wst.common.tests.validation.guard/.project new file mode 100644 index 0000000..0e255c9 --- /dev/null +++ b/tests/org.eclipse.wst.common.tests.validation.guard/.project
@@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.wst.common.tests.validation.guard</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.wst.common.tests.validation.guard/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..73e4b8d --- /dev/null +++ b/tests/org.eclipse.wst.common.tests.validation.guard/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@ +#Sat Mar 29 07:53:31 EDT 2008 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/META-INF/MANIFEST.MF b/tests/org.eclipse.wst.common.tests.validation.guard/META-INF/MANIFEST.MF new file mode 100644 index 0000000..554f63a --- /dev/null +++ b/tests/org.eclipse.wst.common.tests.validation.guard/META-INF/MANIFEST.MF
@@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name.0 +Bundle-SymbolicName: org.eclipse.wst.common.tests.validation.guard;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.wst.common.tests.validation.guard.Activator +Bundle-Vendor: %Bundle-Vendor.0 +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.wst.validation;bundle-version="[1.1.103,1.3.0)", + org.eclipse.core.resources +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-Localization: plugin +Bundle-ActivationPolicy: lazy
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/build.properties b/tests/org.eclipse.wst.common.tests.validation.guard/build.properties new file mode 100644 index 0000000..30b2fc4 --- /dev/null +++ b/tests/org.eclipse.wst.common.tests.validation.guard/build.properties
@@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties,\ + plugin.xml
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/plugin.properties b/tests/org.eclipse.wst.common.tests.validation.guard/plugin.properties new file mode 100644 index 0000000..0b223e4 --- /dev/null +++ b/tests/org.eclipse.wst.common.tests.validation.guard/plugin.properties
@@ -0,0 +1,3 @@ +Bundle-Name.0 = Validation Framework Guard Test cases +Bundle-Vendor.0 = Eclipse.org +
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/plugin.xml b/tests/org.eclipse.wst.common.tests.validation.guard/plugin.xml new file mode 100644 index 0000000..384d64b --- /dev/null +++ b/tests/org.eclipse.wst.common.tests.validation.guard/plugin.xml
@@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.2"?> +<plugin> + <extension + point="org.eclipse.wst.validation.validatorV2" + id="T3A" name="T3A Validator"> + <validator + build="false" + class="org.eclipse.wst.common.tests.validation.guard.T3A" + manual="false"> + </validator> + </extension> + +</plugin>
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/Activator.java b/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/Activator.java new file mode 100644 index 0000000..e512afe --- /dev/null +++ b/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/Activator.java
@@ -0,0 +1,67 @@ +package org.eclipse.wst.common.tests.validation.guard; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; +import org.osgi.framework.BundleContext; + +/** + * The purpose of this plug-in is to ensure that it never gets loaded. If it does it means that we are + * activating validators too early. + */ +public class Activator extends Plugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.wst.common.tests.validation.guard"; + + // The shared instance + private static Activator plugin; + + public Activator() { + RuntimeException re = new RuntimeException("This plug-in should never be loaded. If it is it means that we are loading " + + "validators too early, and causing unneccessary plug-in activation."); + handleException(re); + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Write this exception to the log. + * <p> + * We are in the transition of moving to a new approach for localized messages. This is the new + * approach for exceptions. + * + * @param e the throwable, this can be null in which case it is a nop. + */ + public void handleException(Throwable e){ + if (e == null)return; + Status status = new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e); + getLog().log(status); + } + +}
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/T3A.java b/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/T3A.java new file mode 100644 index 0000000..0dc6b03 --- /dev/null +++ b/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/T3A.java
@@ -0,0 +1,28 @@ +package org.eclipse.wst.common.tests.validation.guard; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.wst.validation.AbstractValidator; +import org.eclipse.wst.validation.ValidationResult; +import org.eclipse.wst.validation.ValidationState; + +/** + * A test validator that we never expect to be activated. + * @author karasiuk + * + */ +public class T3A extends AbstractValidator { + + private boolean _invoked; + + public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor){ + if (!_invoked){ + _invoked = true; + throw new RuntimeException("The T3A validator should never be activated or called."); + } + + return null; + } + + +}