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/08/09 03:52:10 UTC
svn commit: r684170 - in /tapestry/tapestry5/trunk/tapestry-ioc/src:
main/java/org/apache/tapestry5/ioc/ test/fakejar/ test/fakejar/META-INF/
test/java/org/apache/tapestry5/ioc/
Author: hlship
Date: Fri Aug 8 18:52:10 2008
New Revision: 684170
URL: http://svn.apache.org/viewvc?rev=684170&view=rev
Log:
TAPESTRY-2536: Add explicit message on module loading failure
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/test/fakejar/
tapestry/tapestry5/trunk/tapestry-ioc/src/test/fakejar/META-INF/
tapestry/tapestry5/trunk/tapestry-ioc/src/test/fakejar/META-INF/MANIFEST.MF
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCUtilities.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/RegistryBuilder.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCUtilities.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCUtilities.java?rev=684170&r1=684169&r2=684170&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCUtilities.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCUtilities.java Fri Aug 8 18:52:10 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 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,7 @@
import static org.apache.tapestry5.ioc.IOCConstants.MODULE_BUILDER_MANIFEST_ENTRY_NAME;
import org.apache.tapestry5.ioc.annotations.SubModule;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import java.io.Closeable;
import java.io.IOException;
@@ -79,16 +80,18 @@
addModulesInList(builder, System.getProperty("tapestry.modules"));
}
- catch (Exception ex)
+ catch (IOException ex)
{
throw new RuntimeException(ex.getMessage(), ex);
}
}
- private static void addModulesInManifest(RegistryBuilder builder, URL url) throws IOException
+ private static void addModulesInManifest(RegistryBuilder builder, URL url)
{
InputStream in = null;
+ Throwable fail = null;
+
try
{
in = url.openStream();
@@ -103,10 +106,24 @@
addModulesInList(builder, list);
}
+ catch (RuntimeException ex)
+ {
+ fail = ex;
+ }
+ catch (IOException ex)
+ {
+ fail = ex;
+ }
finally
{
close(in);
}
+
+ if (fail != null)
+ throw new RuntimeException(String.format("Exception loading module(s) from manifest %s: %s",
+ url.toString(),
+ InternalUtils.toMessage(fail)), fail);
+
}
static void addModulesInList(RegistryBuilder builder, String list)
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/RegistryBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/RegistryBuilder.java?rev=684170&r1=684169&r2=684170&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/RegistryBuilder.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/RegistryBuilder.java Fri Aug 8 18:52:10 2008
@@ -22,6 +22,7 @@
import org.apache.tapestry5.ioc.internal.RegistryWrapper;
import org.apache.tapestry5.ioc.internal.services.ClassFactoryImpl;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.internal.util.OneShotLock;
import org.apache.tapestry5.ioc.services.ClassFactory;
import org.apache.tapestry5.ioc.services.TapestryIOCModule;
@@ -147,9 +148,10 @@
add(builderClass);
}
- catch (ClassNotFoundException ex)
+ catch (Exception ex)
{
- throw new IllegalArgumentException(ex);
+ throw new RuntimeException(String.format("Failure loading Tapestry IoC module class %s: %s",
+ classname, InternalUtils.toMessage(ex), ex));
}
return this;
Added: tapestry/tapestry5/trunk/tapestry-ioc/src/test/fakejar/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/fakejar/META-INF/MANIFEST.MF?rev=684170&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/fakejar/META-INF/MANIFEST.MF (added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/fakejar/META-INF/MANIFEST.MF Fri Aug 8 18:52:10 2008
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+Archiver-Version: Plexus Archiver
+Created-By: Apache Maven
+Built-By: Howard
+Build-Jdk: 1.5.0_13
+Tapestry-Module-Classes: does.not.exist.Module
+
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java?rev=684170&r1=684169&r2=684170&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java Fri Aug 8 18:52:10 2008
@@ -21,6 +21,9 @@
import org.testng.Assert;
import org.testng.annotations.Test;
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.sql.PreparedStatement;
import java.util.*;
@@ -858,6 +861,32 @@
}
r.shutdown();
+ }
+
+ @Test
+ public void invalid_class_in_manifest() throws Exception
+ {
+ File fakejar = new File("src/test/fakejar");
+
+ assertTrue(fakejar.exists() && fakejar.isDirectory(), "src/test/fakejar must be an existing directory");
+
+ URL url = fakejar.toURL();
+
+ URLClassLoader loader = new URLClassLoader(new URL[] {url}, Thread.currentThread().getContextClassLoader());
+
+ RegistryBuilder builder = new RegistryBuilder(loader);
+ try
+ {
+ IOCUtilities.addDefaultModules(builder);
+ unreachable();
+ }
+ catch (RuntimeException ex)
+ {
+ assertMessageContains(ex,
+ "Exception loading module(s) from manifest",
+ "Failure loading Tapestry IoC module class does.not.exist.Module"
+ );
+ }
}
}