Created
November 19, 2012 19:10
-
-
Save lancelet/4112955 to your computer and use it in GitHub Desktop.
Does drip pick up classpath changes?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #----- | |
| # Test to see if drip picks up classpath changes. | |
| # | |
| # NB: For safety, create a new directory in which to execute this script! | |
| # | |
| # The drip utility (https://github.com/flatland/drip) is a way to launch a JVM | |
| # quickly. It works by keeping "a fresh JVM spun up in reserve with the | |
| # correct classpath and other JVM options". | |
| # | |
| # The purpose of this script is to determine whether drip keeps track of a | |
| # classpath change (perhaps by hashing). This is done by creating an | |
| # executable JAR file with a Class-Path option that references a second JAR | |
| # file. The second JAR file is then changed after drip is first executed. | |
| # | |
| # If drip is correctly detecting changes to the classpath, the output should | |
| # be: | |
| # Thump, thump! | |
| # Bang, bang! | |
| # If it is NOT correctly detecting classpath changes, the output should be: | |
| # Thump, thump! | |
| # Thump, thump! | |
| # | |
| # NOTE: drip currently fails the test (20 Nov 2012) | |
| #----- | |
| # Command to execute the JVM. For comparison with straight java, use | |
| # JVMCMD="java" | |
| JVMCMD="drip" | |
| # Clean up anything from previous runs, and stop drip | |
| rm -rf Greeble.jar Widget.jar src | |
| mkdir -p ./src/org/greeble | |
| mkdir -p ./src/org/widget | |
| if [ -n "`drip ps`" ] | |
| then | |
| drip kill | |
| fi | |
| # Stage 1: Create a Greeble.jar file to go on the classpath | |
| cat > ./src/org/greeble/Thumper.java <<DELIM | |
| package org.greeble; | |
| public class Thumper { | |
| public static void thump() { | |
| System.out.println("Thump, thump!"); | |
| } | |
| } | |
| DELIM | |
| javac ./src/org/greeble/Thumper.java | |
| jar cf ./Greeble.jar -C ./src org/greeble/Thumper.class | |
| # Stage 2: Create a Widget.jar executable file which has Greeble.jar in its | |
| # MANIFEST classpath | |
| cat > ./src/org/widget/Main.java <<DELIM | |
| package org.widget; | |
| import org.greeble.Thumper; | |
| public class Main { | |
| public static void main(String[] args) { | |
| Thumper.thump(); | |
| } | |
| } | |
| DELIM | |
| cat > ./src/org/widget/manifest.txt <<DELIM | |
| Main-Class: org.widget.Main | |
| Class-Path: Greeble.jar | |
| DELIM | |
| javac -cp Greeble.jar ./src/org/widget/Main.java | |
| jar cmf ./src/org/widget/manifest.txt ./Widget.jar -C ./src org/widget/Main.class | |
| # Stage 3: Execute the Widget.jar | |
| $JVMCMD -jar Widget.jar | |
| # Stage 4: Modify the Greeble.jar | |
| cat > ./src/org/greeble/Thumper.java <<DELIM | |
| package org.greeble; | |
| public class Thumper { | |
| public static void thump() { | |
| System.out.println("Bang, bang!"); | |
| } | |
| } | |
| DELIM | |
| javac ./src/org/greeble/Thumper.java | |
| jar cf ./Greeble.jar -C ./src org/greeble/Thumper.class | |
| # Stage 4: Re-execute Widget.jar to see if the changes were detected | |
| $JVMCMD -jar Widget.jar | |
| # Stop drip | |
| if [ -n "`drip ps`" ] | |
| then | |
| drip kill | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment