FELIX-4442 : Lifecycle methods with wrong arguments should be treated as an error
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1572876 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/generator/changelog.txt b/scrplugin/generator/changelog.txt
index cbd4545..556432c 100644
--- a/scrplugin/generator/changelog.txt
+++ b/scrplugin/generator/changelog.txt
@@ -1,9 +1,14 @@
Changes from 1.8.4 to 1.8.2
---------------------------
+** Improvement
+ * [FELIX-4378] - Generate a metatype properties file if label/description are missing on @Component or @Property
** Bug
+ * [FELIX-4379] - Properties, references and services from inherited classes are only used if the class has the component annotation
+ * [FELIX-4383] - Metatype generation should use component name (and not classname)
* [FELIX-4441] - The default value is not escaped correctly.
+ * [FELIX-4442] - Lifecycle methods with wrong arguments should be treated as an error
-#
+
Changes from 1.8.2 to 1.8.0
---------------------------
** Improvement
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/Validator.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/Validator.java
index baddef9..b15c9e5 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/Validator.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/Validator.java
@@ -121,8 +121,8 @@
final String deactivateName = component.getDeactivate() == null ? "deactivate" : component.getDeactivate();
// check activate and deactivate methods
- this.checkLifecycleMethod(activateName, true);
- this.checkLifecycleMethod(deactivateName, false);
+ this.checkLifecycleMethod(activateName, true, component.getActivate() != null);
+ this.checkLifecycleMethod(deactivateName, false, component.getDeactivate() != null);
if (component.getModified() != null) {
if ( this.options.getSpecVersion().ordinal() >= SpecVersion.VERSION_1_1.ordinal() ) {
@@ -227,17 +227,15 @@
/**
* Check for existence of lifecycle methods.
*
- * @param specVersion
- * The spec version
- * @param javaClass
- * The java class to inspect.
* @param methodName
* The method name.
- * @param warnings
- * The list of warnings used to add new warnings.
+ * @param isActivate Whether this is the activate or deactivate method.
+ * @param isSpecified Whether this method has explicitely been specified or is just
+ * the default
*/
private void checkLifecycleMethod(final String methodName,
- final boolean isActivate)
+ final boolean isActivate,
+ final boolean isSpecified)
throws SCRDescriptorException {
// first candidate is (de)activate(ComponentContext)
Method method = this.getMethod(methodName, new String[] { TYPE_COMPONENT_CONTEXT });
@@ -313,17 +311,26 @@
}
}
}
- // if no method is found, we check for any method with that name to print some warnings!
+ // if no method is found, we check for any method with that name to print some warnings or errors!
if (method == null) {
final Method[] methods = this.container.getClassDescription().getDescribedClass().getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
if (methodName.equals(methods[i].getName())) {
if (methods[i].getParameterTypes() == null || methods[i].getParameterTypes().length != 1) {
- this.logWarn(container.getComponentDescription(), "Lifecycle method " + methods[i].getName() + " has wrong number of arguments");
+ final String msg = "Lifecycle method " + methods[i].getName() + " has wrong number of arguments";
+ if ( isSpecified ) {
+ this.logError(container.getComponentDescription(), msg);
+ } else {
+ this.logWarn(container.getComponentDescription(), msg);
+ }
} else {
- this.logWarn(container.getComponentDescription(),
- "Lifecycle method " + methods[i].getName() + " has wrong argument "
- + methods[i].getParameterTypes()[0].getName());
+ final String msg = "Lifecycle method " + methods[i].getName() + " has wrong argument "
+ + methods[i].getParameterTypes()[0].getName();
+ if ( isSpecified ) {
+ this.logError(container.getComponentDescription(), msg);
+ } else {
+ this.logWarn(container.getComponentDescription(), msg);
+ }
}
}
}