You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2008/09/10 00:21:02 UTC
svn commit: r693636 - in /tapestry/tapestry5/trunk/tapestry-ioc/src:
main/java/org/apache/tapestry5/ioc/internal/
main/resources/org/apache/tapestry5/ioc/internal/
test/java/org/apache/tapestry5/ioc/internal/
Author: hlship
Date: Tue Sep 9 15:21:00 2008
New Revision: 693636
URL: http://svn.apache.org/viewvc?rev=693636&view=rev
Log:
TAPESTRY-2655: Services defined with the bind() method may conflict with services from service builder methods without error
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBinderImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceDefAccumulator.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplTest.java
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java?rev=693636&r1=693635&r2=693636&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java Tue Sep 9 15:21:00 2008
@@ -325,10 +325,7 @@
ServiceDef existing = serviceDefs.get(serviceId);
if (existing != null)
- {
- logger.warn(buildMethodConflict(serviceDef.toString(), existing.toString()));
- return;
- }
+ throw new RuntimeException(buildMethodConflict(serviceId, serviceDef.toString(), existing.toString()));
serviceDefs.put(serviceId, serviceDef);
}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java?rev=693636&r1=693635&r2=693636&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java Tue Sep 9 15:21:00 2008
@@ -35,9 +35,9 @@
{
private static final Messages MESSAGES = MessagesImpl.forClass(IOCMessages.class);
- static String buildMethodConflict(String conflict, String existing)
+ static String buildMethodConflict(String serviceId, String conflict, String existing)
{
- return MESSAGES.format("build-method-conflict", conflict, existing);
+ return MESSAGES.format("build-method-conflict", serviceId, conflict, existing);
}
static String buildMethodWrongReturnType(Method method)
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBinderImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBinderImpl.java?rev=693636&r1=693635&r2=693636&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBinderImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBinderImpl.java Tue Sep 9 15:21:00 2008
@@ -119,7 +119,9 @@
public String getDescription()
{
- return classFactory.getConstructorLocation(constructor).toString();
+ return String.format("%s via %s",
+ classFactory.getConstructorLocation(constructor),
+ classFactory.getMethodLocation(bindMethod));
}
};
}
@@ -257,5 +259,4 @@
return this;
}
-
}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceDefAccumulator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceDefAccumulator.java?rev=693636&r1=693635&r2=693636&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceDefAccumulator.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceDefAccumulator.java Tue Sep 9 15:21:00 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -16,6 +16,11 @@
import org.apache.tapestry5.ioc.def.ServiceDef;
+/**
+ * Simple interface used when invoking a bind() method on a module class.
+ *
+ * @see org.apache.tapestry5.ioc.internal.ServiceBinderImpl
+ */
public interface ServiceDefAccumulator
{
void addServiceDef(ServiceDef serviceDef);
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties?rev=693636&r1=693635&r2=693636&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties Tue Sep 9 15:21:00 2008
@@ -12,8 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-build-method-conflict=Service building method %s conflicts with (has the same name as, but different parameters than) \
- previously seen method %s and has been ignored.
+build-method-conflict=Service %s (defined by %s) conflicts with previously defined service defined by %s.
build-method-wrong-return-type=Method %s is named like a service builder method, \
but the return type (%s) is not acceptable (try an interface). \
The method has been ignored.
@@ -76,9 +75,9 @@
no-such-service=Service id '%s' is not defined by any module. Defined services: %s.
service-id-conflict=Service id '%s' has already been defined by %s and may not be redefined by %s. \
You should rename one of the service builder methods.
- no-constructor=Class %s (implementation of service '%s') does not contain any public constructors.
- bind-method-must-be-static=Method %s appears to be a service binder method, but is an instance method, not a static method.
- error-in-bind-method=Error invoking service binder method %s: %s
+no-constructor=Class %s (implementation of service '%s') does not contain any public constructors.
+bind-method-must-be-static=Method %s appears to be a service binder method, but is an instance method, not a static method.
+error-in-bind-method=Error invoking service binder method %s: %s
no-autobuild-constructor=Class %s does not contain a public constructor needed to autobuild.
autobuild-constructor-error=Error invoking constructor %s: %s
overlapping-service-proxy-providers=Setting a new service proxy provider when there's already an existing provider. This may indicate that you have multiple IoC Registries.
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplTest.java?rev=693636&r1=693635&r2=693636&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplTest.java Tue Sep 9 15:21:00 2008
@@ -19,7 +19,6 @@
import org.apache.tapestry5.ioc.def.DecoratorDef;
import org.apache.tapestry5.ioc.def.ModuleDef;
import org.apache.tapestry5.ioc.def.ServiceDef;
-import static org.apache.tapestry5.ioc.internal.IOCMessages.buildMethodConflict;
import org.apache.tapestry5.ioc.internal.services.ClassFactoryImpl;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
@@ -133,30 +132,23 @@
Logger logger = mockLogger();
- logger.warn(buildMethodConflict(conflictMethodString, expectedMethod));
-
replay();
// BigDecimal is arbitrary, any class would do.
- ModuleDef md = new DefaultModuleDefImpl(ServiceIdConflictMethodModule.class, logger, classFactory);
-
- Set<String> ids = md.getServiceIds();
-
- assertEquals(ids.size(), 1);
- assertTrue(ids.contains("Fred"));
-
- ServiceDef sd = md.getServiceDef("Fred");
-
- assertEquals(sd.getServiceId(), "Fred");
-
- assertEquals(sd.getServiceInterface(), FieService.class);
+ try
+ {
+ new DefaultModuleDefImpl(ServiceIdConflictMethodModule.class, logger, classFactory);
- // The methods are considered in ascending order, by name, then descending order, by
- // parameter count. So the grinder will latch onto the method that takes a parameter,
- // and consider the other method (with no parameters) the conflict.
+ unreachable();
+ }
+ catch (RuntimeException ex)
+ {
+ assertMessageContains(ex,
+ "Service Fred (defined by org.apache.tapestry5.ioc.internal.ServiceIdConflictMethodModule.buildFred()",
+ "conflicts with previously defined service defined by org.apache.tapestry5.ioc.internal.ServiceIdConflictMethodModule.buildFred(Object)");
+ }
- assertEquals(sd.toString(), expectedMethod.toString());
verify();
}