[
https://issues.apache.org/jira/browse/TWILL-182?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15429856#comment-15429856
]
ASF GitHub Bot commented on TWILL-182:
--------------------------------------
Github user serranom commented on a diff in the pull request:
https://github.com/apache/twill/pull/1#discussion_r75601503
--- Diff:
twill-core/src/test/java/org/apache/twill/internal/utils/ApplicationBundlerTest.java
---
@@ -68,6 +71,56 @@ public void testFindDependencies() throws IOException,
ClassNotFoundException {
Assert.assertNotSame(classLoader, clz.getClassLoader());
}
+ @Test
+ public void testSameJar() throws IOException, ClassNotFoundException {
+ File dir1 = tmpDir.newFolder();
+ File dir2 = tmpDir.newFolder();
+ File j1 = new File(dir1, "samename.jar");
+ File j2 = new File(dir2, "samename.jar");
+
+ createJar(Class1.class, j1);
+ createJar(Class2.class, j2);
+
+ ClassLoader currentClassLoader =
Thread.currentThread().getContextClassLoader();
+ Location location;
+
+ try {
+ URL[] urls = new URL[] { j1.toURI().toURL(), j2.toURI().toURL() };
+ Thread.currentThread().setContextClassLoader(new
URLClassLoader(urls, null));
+
+ // create bundle
+ location = new
LocalLocationFactory(tmpDir.newFolder()).create("test.jar");
+ ApplicationBundler bundler = new
ApplicationBundler(ImmutableList.<String> of());
+ bundler.createBundle(location, Class1.class, Class2.class);
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(currentClassLoader);
+ }
+
+ File targetDir = tmpDir.newFolder();
+ unjar(new File(location.toURI()), targetDir);
+
+ // should be able to load both classes
+ ClassLoader classLoader = createClassLoader(targetDir);
+ Class<?> c1 = classLoader.loadClass(Class1.class.getName());
+ Class<?> c2 = classLoader.loadClass(Class2.class.getName());
+
+ // make sure we are loading them from the correct class loader (not
defaulting back to some classloader
+ // from the test
+ Assert.assertSame(classLoader, c1.getClassLoader());
+ Assert.assertSame(classLoader, c2.getClassLoader());
+ }
+
+ private void createJar(Class<?> clazz, File jarFile) throws IOException {
+ try (JarOutputStream jos = new JarOutputStream(new
FileOutputStream(jarFile))) {
+ String pathname = clazz.getName().replace(".", "/") + ".class";
+ JarEntry entry = new JarEntry(pathname);
+ jos.putNextEntry(entry);
+ IOUtils.copy(clazz.getClassLoader().getResourceAsStream(pathname),
jos);
--- End diff --
I will switch to guava. And fix the resource stream.
> ApplicationBundler will overwrite dependencies with identical names
> -------------------------------------------------------------------
>
> Key: TWILL-182
> URL: https://issues.apache.org/jira/browse/TWILL-182
> Project: Apache Twill
> Issue Type: Bug
> Components: core
> Affects Versions: 0.7.0-incubating
> Reporter: Martin Serrano
> Fix For: 0.8.0
>
>
> If two jars obtained from *different* classpath locations have the same name
> but different contents, one will overwrite the other. The dependency code
> correctly finds the jars (uses the full path in the HashSet which accumulates
> the deps) but when the bundle is created the jars are written to {{/lib}}
> under their name. This results in one overwriting the other.
> While this is not a likely occurrence, it occurs for us in our development
> environment because our published jar names are built up from their project
> hierarchy. For example the model project for our sdk is in {{.../sdk/model}}
> and will be on the classpath as {{.../sdk/model.jar}} and published as
> {{sdk-model.jar}}.
> In practice however this could occur with any jar name and would be more
> likely over time.
> The {{ApplicationBundler}} could detect this and re-write the name with some
> part of the path or suffix to ensure the name is unique.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)