Skip to content

Commit

Permalink
redesigning examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-bukhtoyarov committed Nov 6, 2015
1 parent 14fe0fc commit 0d657a7
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 118 deletions.

This file was deleted.

16 changes: 16 additions & 0 deletions examples/examples-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.github.spring-jar-helsing</groupId>
<artifactId>examples</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<packaging>jar</packaging>
<artifactId>examples-api</artifactId>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.springjarhelsing;

import java.util.concurrent.*;

public interface UninterpretableFutureGetter {

<T> T get(Future<T> future) throws ExecutionException, InterruptedException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<packaging>jar</packaging>
<artifactId>distribution</artifactId>
<artifactId>j2se-test</artifactId>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.springjarhelsing;

public class TestContext {

private UninterpretableFutureGetter guava09UninterpretableFutureGetter;
private UninterpretableFutureGetter guava17UninterpretableFutureGetter;

public void setGuava09UninterpretableFutureGetter(UninterpretableFutureGetter guava09UninterpretableFutureGetter) {
this.guava09UninterpretableFutureGetter = guava09UninterpretableFutureGetter;
}

public UninterpretableFutureGetter getGuava09UninterpretableFutureGetter() {
return guava09UninterpretableFutureGetter;
}

public void setGuava17UninterpretableFutureGetter(UninterpretableFutureGetter guava17UninterpretableFutureGetter) {
this.guava17UninterpretableFutureGetter = guava17UninterpretableFutureGetter;
}

public UninterpretableFutureGetter getGuava17UninterpretableFutureGetter() {
return guava17UninterpretableFutureGetter;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.*;

import static org.junit.Assert.assertEquals;

public class SpringJarHelsingTest {

Expand All @@ -25,8 +28,18 @@ public void shutdown() {

@Test
public void test() throws ExecutionException, InterruptedException {
testContext.getGuava09Tester().getProperties();
testContext.getGuava17Tester().getProperties();
Callable<Integer> task = new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return 42;
}
};
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Integer> future = executor.submit(task);

int result09 = testContext.getGuava09UninterpretableFutureGetter().get(future);
int result17 = testContext.getGuava17UninterpretableFutureGetter().get(future);
assertEquals(result09, result17);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">

<bean id="guava17Tester" class="com.github.springjarhelsing.Guava17Tester"/>
<bean id="guava17UninterpretableFutureGetter" class="com.github.springjarhelsing.Guava17UninterpretableFutureGetter"/>

<bean class="com.github.springjarhelsing.JarHelsingBeanFactoryPostProcessor">
<property name="resourceLocations">
<list>
<value type="java.lang.String">classpath:test-subcontext.xml</value>
<value>classpath:test-subcontext.xml</value>
</list>
</property>
<property name="overridenClasspathUrls">
<list>
<value type="java.lang.String">file:lib/guava-r09.jar</value>
<value>classpath:custom-libs/guava-r09.jar</value>
<value>classpath:custom-libs/with-guavar09-1.0.0.jar</value>
</list>
</property>
</bean>

<bean id="testContext" class="com.github.springjarhelsing.TestContext">
<property name="guava09Tester" ref="guava09Tester"/>
<property name="guava17Tester" ref="guava17Tester"/>
<property name="guava09UninterpretableFutureGetter" ref="guava09UninterpretableFutureGetter"/>
<property name="guava17UninterpretableFutureGetter" ref="guava17UninterpretableFutureGetter"/>
</bean>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">

<bean id="guava09Tester" class="com.github.springjarhelsing.Guava09Tester"/>
<bean id="guava09UninterpretableFutureGetter" class="com.github.springjarhelsing.Guava09UninterpretableFutureGetter"/>

</beans>
7 changes: 4 additions & 3 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
<name>Spring Jar Helsing usage example</name>

<modules>
<module>with-guavar09</module>
<module>with-guavar17</module>
<module>distribution</module>
<module>examples-api</module>
<module>with-guava-r09</module>
<module>with-guava-17</module>
<module>j2se-test</module>
</modules>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
</parent>

<packaging>jar</packaging>
<artifactId>with-guavar17</artifactId>
<artifactId>with-guava-17</artifactId>

<dependencies>
<dependency>
<groupId>com.github.spring-jar-helsing</groupId>
<artifactId>examples-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.springjarhelsing;

import com.google.common.util.concurrent.Uninterruptibles;
import java.util.concurrent.*;

public class Guava17UninterpretableFutureGetter implements UninterpretableFutureGetter {

@Override
public <T> T get(Future<T> future) throws ExecutionException, InterruptedException {
return Uninterruptibles.getUninterruptibly(future);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
</parent>

<packaging>jar</packaging>
<artifactId>with-guavar09</artifactId>
<artifactId>with-guava-r09</artifactId>

<dependencies>
<dependency>
<groupId>com.github.spring-jar-helsing</groupId>
<artifactId>examples-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.springjarhelsing;

import com.google.common.util.concurrent.Futures;
import java.util.concurrent.*;

public class Guava09UninterpretableFutureGetter implements UninterpretableFutureGetter {

@Override
public <T> T get(Future<T> future) throws ExecutionException, InterruptedException {
// this code can not be compiled with guava 17
return Futures.makeUninterruptible(future).get();
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableL
try {
ClassLoader parentClassLoader = getClass().getClassLoader();

this.jarHelsingClassLoader = buildJarHelsingClassloader(parentClassLoader, overridenClasspathUrls);
this.jarHelsingClassLoader = new JarHelsingClassLoader(overridenClasspathUrls, parentClassLoader);

setContextClassloader(jarHelsingClassLoader);

Expand All @@ -88,21 +88,6 @@ private static GenericXmlApplicationContext createSubcontext(Collection<String>
return subcontext;
}

private static JarHelsingClassLoader buildJarHelsingClassloader(ClassLoader parentClassLoader, Collection<String> classpath) throws BeansException {
URL[] classpathUrls = new URL[classpath.size()];
int i = 0;
for (String classpathElement : classpath) {
try {
classpathUrls[i] = new URL(classpathElement);
} catch (MalformedURLException e) {
String msg = "Fail to create url from [" + classpathElement + "]";
throw new BootstrapException(msg, e);
}
i++;
}
return new JarHelsingClassLoader(classpathUrls, parentClassLoader);
}

private ClassLoader getContextClassLoader() {
PrivilegedAction<ClassLoader> action = new PrivilegedAction<ClassLoader>() {
@Override
Expand Down

0 comments on commit 0d657a7

Please sign in to comment.