S4-73 remove appsDir concept
diff --git a/subprojects/s4-benchmarks/s4-benchmarks.gradle b/subprojects/s4-benchmarks/s4-benchmarks.gradle
index 76ce1a0..9f30b60 100644
--- a/subprojects/s4-benchmarks/s4-benchmarks.gradle
+++ b/subprojects/s4-benchmarks/s4-benchmarks.gradle
@@ -18,11 +18,8 @@
 
 
 
-project.ext["s4AppInstallDir"] = hasProperty('appsDir') ? "$appsDir" : "/tmp/appsDir"
-
 project.ext["s4Version"] = '0.5.0-incubating'
 description = 'Apache S4 App'
-//defaultTasks 'installS4R'
 project.ext["archivesBaseName"] = "$project.name"
 project.ext["distRootFolder"] = "$archivesBaseName-${-> version}"
 
diff --git a/subprojects/s4-core/src/test/java/org/apache/s4/deploy/TestAutomaticDeployment.java b/subprojects/s4-core/src/test/java/org/apache/s4/deploy/TestAutomaticDeployment.java
index 8b5329b..20f2285 100644
--- a/subprojects/s4-core/src/test/java/org/apache/s4/deploy/TestAutomaticDeployment.java
+++ b/subprojects/s4-core/src/test/java/org/apache/s4/deploy/TestAutomaticDeployment.java
@@ -62,18 +62,24 @@
     private Process forkedNode;
     private ZkClient zkClient;
     private S4RHttpServer s4rHttpServer;
-    public static File tmpAppsDir;
+    public static File s4rDir;
 
     @BeforeClass
     public static void createS4RFiles() throws Exception {
-        tmpAppsDir = Files.createTempDir();
 
         File gradlewFile = CoreTestUtils.findGradlewInRootDir();
 
+        s4rDir = new File(gradlewFile.getParentFile().getAbsolutePath()
+                + "/test-apps/simple-deployable-app-1/build/libs");
         CoreTestUtils.callGradleTask(new File(gradlewFile.getParentFile().getAbsolutePath()
-                + "/test-apps/simple-deployable-app-1/build.gradle"), "installS4R", new String[] { "appsDir="
-                + tmpAppsDir.getAbsolutePath() });
+                + "/test-apps/simple-deployable-app-1/build.gradle"), "clean", new String[] { "-buildFile="
+                + gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/simple-deployable-app-1/build.gradle" });
+        Assert.assertFalse(s4rDir.exists());
 
+        CoreTestUtils.callGradleTask(new File(gradlewFile.getParentFile().getAbsolutePath()
+                + "/test-apps/simple-deployable-app-1/build.gradle"), "s4r", new String[] { "-buildFile="
+                + gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/simple-deployable-app-1/build.gradle" });
+        Assert.assertTrue(new File(s4rDir, "simple-deployable-app-1-0.0.0-SNAPSHOT.s4r").exists());
     }
 
     @Test
@@ -83,13 +89,7 @@
 
         Assert.assertFalse(zkClient.exists(AppConstants.INITIALIZED_ZNODE_1));
 
-        File s4rToDeploy = File.createTempFile("testapp" + System.currentTimeMillis(), "s4r");
-
-        Assert.assertTrue(ByteStreams.copy(
-                Files.newInputStreamSupplier(new File(tmpAppsDir.getAbsolutePath()
-                        + "/simple-deployable-app-1-0.0.0-SNAPSHOT.s4r")), Files.newOutputStreamSupplier(s4rToDeploy)) > 0);
-
-        final String uri = s4rToDeploy.toURI().toString();
+        final String uri = new File(s4rDir, "simple-deployable-app-1-0.0.0-SNAPSHOT.s4r").toURI().toString();
 
         assertDeployment(uri, zkClient, true);
 
@@ -146,8 +146,8 @@
         File s4rToDeploy = new File(tmpDir, String.valueOf(System.currentTimeMillis()));
 
         Assert.assertTrue(ByteStreams.copy(
-                Files.newInputStreamSupplier(new File(tmpAppsDir.getAbsolutePath()
-                        + "/simple-deployable-app-1-0.0.0-SNAPSHOT.s4r")), Files.newOutputStreamSupplier(s4rToDeploy)) > 0);
+                Files.newInputStreamSupplier(new File(s4rDir, "/simple-deployable-app-1-0.0.0-SNAPSHOT.s4r")),
+                Files.newOutputStreamSupplier(s4rToDeploy)) > 0);
 
         // we start a
         s4rHttpServer = new S4RHttpServer(8080, tmpDir);
diff --git a/subprojects/s4-core/src/test/java/org/apache/s4/deploy/prodcon/TestProducerConsumer.java b/subprojects/s4-core/src/test/java/org/apache/s4/deploy/prodcon/TestProducerConsumer.java
index 31c6a34..90f4033 100644
--- a/subprojects/s4-core/src/test/java/org/apache/s4/deploy/prodcon/TestProducerConsumer.java
+++ b/subprojects/s4-core/src/test/java/org/apache/s4/deploy/prodcon/TestProducerConsumer.java
@@ -45,7 +45,6 @@
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import com.google.common.io.Files;
 import com.google.common.io.Resources;
 import com.sun.net.httpserver.HttpServer;
 
@@ -58,22 +57,37 @@
     private final static String PRODUCER_CLUSTER = "producerCluster";
     private final static String CONSUMER_CLUSTER = "consumerCluster";
     private HttpServer httpServer;
-    private static File tmpAppsDir;
+    private static File producerS4rDir;
+    private static File consumerS4rDir;
 
     @BeforeClass
     public static void createS4RFiles() throws Exception {
-        tmpAppsDir = Files.createTempDir();
-
-        Assert.assertTrue(tmpAppsDir.exists());
         File gradlewFile = CoreTestUtils.findGradlewInRootDir();
 
-        CoreTestUtils.callGradleTask(new File(gradlewFile.getParentFile().getAbsolutePath()
-                + "/test-apps/producer-app/build.gradle"), "installS4R",
-                new String[] { "appsDir=" + tmpAppsDir.getAbsolutePath() });
+        producerS4rDir = new File(gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/producer-app/build/libs");
+        consumerS4rDir = new File(gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/consumer-app/build/libs");
 
         CoreTestUtils.callGradleTask(new File(gradlewFile.getParentFile().getAbsolutePath()
-                + "/test-apps/consumer-app/build.gradle"), "installS4R",
-                new String[] { "appsDir=" + tmpAppsDir.getAbsolutePath() });
+                + "/test-apps/producer-app/build.gradle"), "clean", new String[] { "-buildFile="
+                + gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/producer-app/build.gradle" });
+        Assert.assertFalse(producerS4rDir.exists());
+
+        CoreTestUtils.callGradleTask(new File(gradlewFile.getParentFile().getAbsolutePath()
+                + "/test-apps/producer-app/build.gradle"), "s4r", new String[] { "-buildFile="
+                + gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/producer-app/build.gradle" });
+
+        Assert.assertTrue(new File(producerS4rDir, "producer-app-0.0.0-SNAPSHOT.s4r").exists());
+
+        CoreTestUtils.callGradleTask(new File(gradlewFile.getParentFile().getAbsolutePath()
+                + "/test-apps/consumer-app/build.gradle"), "clean", new String[] { "-buildFile="
+                + gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/consumer-app/build.gradle" });
+        Assert.assertFalse(consumerS4rDir.exists());
+
+        CoreTestUtils.callGradleTask(new File(gradlewFile.getParentFile().getAbsolutePath()
+                + "/test-apps/consumer-app/build.gradle"), "s4r", new String[] { "-buildFile="
+                + gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/consumer-app/build.gradle" });
+
+        Assert.assertTrue(new File(consumerS4rDir, "consumer-app-0.0.0-SNAPSHOT.s4r").exists());
     }
 
     @Before
@@ -106,10 +120,10 @@
     @Test
     public void testInitialDeploymentFromFileSystem() throws Exception {
 
-        File producerS4R = new File(tmpAppsDir, "producer-app-0.0.0-SNAPSHOT.s4r");
+        File producerS4R = new File(producerS4rDir, "producer-app-0.0.0-SNAPSHOT.s4r");
         String uriProducer = producerS4R.toURI().toString();
 
-        File consumerS4R = new File(tmpAppsDir, "consumer-app-0.0.0-SNAPSHOT.s4r");
+        File consumerS4R = new File(consumerS4rDir, "consumer-app-0.0.0-SNAPSHOT.s4r");
         String uriConsumer = consumerS4R.toURI().toString();
 
         initializeS4Node();
diff --git a/subprojects/s4-tools/src/main/java/org/apache/s4/tools/Deploy.java b/subprojects/s4-tools/src/main/java/org/apache/s4/tools/Deploy.java
index 76a1d43..cae6266 100644
--- a/subprojects/s4-tools/src/main/java/org/apache/s4/tools/Deploy.java
+++ b/subprojects/s4-tools/src/main/java/org/apache/s4/tools/Deploy.java
@@ -48,7 +48,6 @@
 
 public class Deploy extends S4ArgsBase {
 
-    private static File tmpAppsDir;
     static org.slf4j.Logger logger = LoggerFactory.getLogger(Deploy.class);
 
     /**
@@ -64,8 +63,6 @@
             ZkClient zkClient = new ZkClient(deployArgs.zkConnectionString, deployArgs.timeout);
             zkClient.setZkSerializer(new ZNRecordSerializer());
 
-            tmpAppsDir = Files.createTempDir();
-
             if (!Strings.isNullOrEmpty(deployArgs.s4rPath) && !Strings.isNullOrEmpty(deployArgs.generatedS4R)) {
                 logger.error("-s4r and -generatedS4R options are mutually exclusive");
                 System.exit(1);
@@ -89,22 +86,24 @@
                 List<String> params = new ArrayList<String>();
                 // prepare gradle -P parameters, including passed gradle opts
                 params.addAll(deployArgs.gradleOpts);
-                params.add("appClass=" + deployArgs.appClass);
-                params.add("appsDir=" + tmpAppsDir.getAbsolutePath());
-                params.add("appName=" + deployArgs.appName);
-                ExecGradle.exec(deployArgs.gradleBuildFile, "installS4R", params.toArray(new String[] {}));
-                File tmpS4R = new File(tmpAppsDir.getAbsolutePath() + "/" + deployArgs.appName + ".s4r");
+                params.add("-appClass=" + deployArgs.appClass);
+                // params.add("-appsDir=" + tmpAppsDir.getAbsolutePath());
+                params.add("-appName=" + deployArgs.appName);
+                params.add(deployArgs.appName);
+                ExecGradle.exec(deployArgs.gradleBuildFile, "s4r", params.toArray(new String[] {}));
+                File s4rFile = new File(deployArgs.gradleBuildFile.getParentFile(), "/build/libs/" + deployArgs.appName
+                        + ".s4r");
                 if (!Strings.isNullOrEmpty(deployArgs.generatedS4R)) {
                     logger.info("Copying generated S4R to [{}]", deployArgs.generatedS4R);
                     s4rURI = new URI(deployArgs.generatedS4R);
-                    if (!(ByteStreams.copy(Files.newInputStreamSupplier(tmpS4R),
+                    if (!(ByteStreams.copy(Files.newInputStreamSupplier(s4rFile),
                             Files.newOutputStreamSupplier(new File(s4rURI))) > 0)) {
-                        logger.error("Cannot copy generated s4r from {} to {}", tmpS4R.getAbsolutePath(),
+                        logger.error("Cannot copy generated s4r from {} to {}", s4rFile.getAbsolutePath(),
                                 s4rURI.toString());
                         System.exit(1);
                     }
                 } else {
-                    s4rURI = tmpS4R.toURI();
+                    s4rURI = s4rFile.toURI();
                 }
             } else {
                 if (!Strings.isNullOrEmpty(deployArgs.appClass)) {
diff --git a/subprojects/s4-tools/src/main/java/org/apache/s4/tools/Package.java b/subprojects/s4-tools/src/main/java/org/apache/s4/tools/Package.java
index fe8761a..0b315ba 100644
--- a/subprojects/s4-tools/src/main/java/org/apache/s4/tools/Package.java
+++ b/subprojects/s4-tools/src/main/java/org/apache/s4/tools/Package.java
@@ -40,7 +40,7 @@
             // prepare gradle -P parameters, including passed gradle opts
             params.add("appClass=" + packageArgs.appClass);
             params.add("appName=" + packageArgs.appName.get(0));
-            ExecGradle.exec(packageArgs.gradleBuildFile, "installS4R", params.toArray(new String[] {}));
+            ExecGradle.exec(packageArgs.gradleBuildFile, "s4r", params.toArray(new String[] {}));
 
             // Explicitly shutdown the JVM since Gradle leaves non-daemon threads running that delay the termination
             System.exit(0);
diff --git a/subprojects/s4-tools/src/main/resources/templates/build.gradle b/subprojects/s4-tools/src/main/resources/templates/build.gradle
index 6476309..1122fcc 100644
--- a/subprojects/s4-tools/src/main/resources/templates/build.gradle
+++ b/subprojects/s4-tools/src/main/resources/templates/build.gradle
@@ -17,11 +17,8 @@
  */
 
 
-project.ext["s4AppInstallDir"] = hasProperty('appsDir') ? "$appsDir" : "/tmp/appsDir"
-
 project.ext["s4Version"] = '0.5.0-incubating'
 description = 'Apache S4 App'
-//defaultTasks 'installS4R'
 project.ext["archivesBaseName"] = "$project.name"
 project.ext["distRootFolder"] = "$archivesBaseName-${-> version}"
 
@@ -162,13 +159,6 @@
     new File("classpath.txt").write(sourceSets.main.output.classesDir.path + File.pathSeparator + <s4_install_dir> + '/lib/*' + File.pathSeparator + <s4_install_dir> + '/subprojects/s4-tools/build/install/s4-tools/lib/*')
 }
 
-/* Install the S4 archive to the install directory. */
-task installS4R (type: Copy) {
-   dependsOn s4r
-   from s4r.archivePath
-   into s4AppInstallDir
-}
-
 /* Parse source file to get the app classname so we can use it in the manifest.
 * TODO: Use a real Java parser. (This is not skipping comments for example.)
 */
diff --git a/subprojects/s4-tools/src/test/java/org/apache/s4/tools/TestDeploy.java b/subprojects/s4-tools/src/test/java/org/apache/s4/tools/TestDeploy.java
index cff7359..7a3abe8 100644
--- a/subprojects/s4-tools/src/test/java/org/apache/s4/tools/TestDeploy.java
+++ b/subprojects/s4-tools/src/test/java/org/apache/s4/tools/TestDeploy.java
@@ -80,9 +80,8 @@
 
         File s4rToDeploy = new File(tmpDir, String.valueOf(System.currentTimeMillis()));
 
-        Assert.assertTrue(ByteStreams.copy(
-                Files.newInputStreamSupplier(new File(TestAutomaticDeployment.tmpAppsDir.getAbsolutePath()
-                        + "/simple-deployable-app-1-0.0.0-SNAPSHOT.s4r")), Files.newOutputStreamSupplier(s4rToDeploy)) > 0);
+        Assert.assertTrue(ByteStreams.copy(Files.newInputStreamSupplier(new File(TestAutomaticDeployment.s4rDir,
+                "simple-deployable-app-1-0.0.0-SNAPSHOT.s4r")), Files.newOutputStreamSupplier(s4rToDeploy)) > 0);
 
         s4rHttpServer = new S4RHttpServer(8080, tmpDir);
         s4rHttpServer.start();
diff --git a/test-apps/consumer-app/build.gradle b/test-apps/consumer-app/build.gradle
index bc53b3a..663e095 100644
--- a/test-apps/consumer-app/build.gradle
+++ b/test-apps/consumer-app/build.gradle
@@ -34,14 +34,8 @@
 *
 */
 
-/* Set the destination where we want to install the apps. */
-//s4AppInstallDir = "/tmp/s4Apps" // TODO: decide how to standarize dirs, use env var?
-
-project.ext["s4AppInstallDir"] = hasProperty('appsDir') ? "$appsDir" : "/tmp/appsDir"
-
 project.ext["s4Version"] = '0.5.0-SNAPSHOT'
 description = 'Apache S4 App'
-//defaultTasks 'installS4R'
 archivesBaseName = "$project.name"
 distRootFolder = "$archivesBaseName-${-> version}"
 
@@ -189,16 +183,6 @@
 
 }
 
-/* Install the S4 archive to the install directory. */
-task installS4R (type: Copy) {
-   dependsOn s4r
-   from s4r.archivePath
-   into s4AppInstallDir
-}
-
-
-
-
 /* Parse source file to get the app classname so we can use it in the manifest.
 * TODO: Use a real Java parser. (This is not skippong comments for example.)
 */
diff --git a/test-apps/custom-modules/build.gradle b/test-apps/custom-modules/build.gradle
index e93c141..b4eeaf2 100644
--- a/test-apps/custom-modules/build.gradle
+++ b/test-apps/custom-modules/build.gradle
@@ -34,14 +34,8 @@
 *
 */
 
-/* Set the destination where we want to install the apps. */
-//s4AppInstallDir = "/tmp/s4Apps" // TODO: decide how to standarize dirs, use env var?
-
-project.ext["s4AppInstallDir"] = hasProperty('appsDir') ? "$appsDir" : "/tmp/appsDir"
-
 project.ext["s4Version"] = '0.5.0-incubating'
 description = 'Apache S4 App'
-//defaultTasks 'installS4R'
 project.ext["archivesBaseName"] = "$project.name"
 project.ext["distRootFolder"] = "$archivesBaseName-${-> version}"
 
diff --git a/test-apps/producer-app/build.gradle b/test-apps/producer-app/build.gradle
index bc53b3a..7524cd1 100644
--- a/test-apps/producer-app/build.gradle
+++ b/test-apps/producer-app/build.gradle
@@ -34,14 +34,8 @@
 *
 */
 
-/* Set the destination where we want to install the apps. */
-//s4AppInstallDir = "/tmp/s4Apps" // TODO: decide how to standarize dirs, use env var?
-
-project.ext["s4AppInstallDir"] = hasProperty('appsDir') ? "$appsDir" : "/tmp/appsDir"
-
 project.ext["s4Version"] = '0.5.0-SNAPSHOT'
 description = 'Apache S4 App'
-//defaultTasks 'installS4R'
 archivesBaseName = "$project.name"
 distRootFolder = "$archivesBaseName-${-> version}"
 
@@ -189,15 +183,6 @@
 
 }
 
-/* Install the S4 archive to the install directory. */
-task installS4R (type: Copy) {
-   dependsOn s4r
-   from s4r.archivePath
-   into s4AppInstallDir
-}
-
-
-
 
 /* Parse source file to get the app classname so we can use it in the manifest.
 * TODO: Use a real Java parser. (This is not skippong comments for example.)
diff --git a/test-apps/simple-deployable-app-1/build.gradle b/test-apps/simple-deployable-app-1/build.gradle
index bc53b3a..7524cd1 100644
--- a/test-apps/simple-deployable-app-1/build.gradle
+++ b/test-apps/simple-deployable-app-1/build.gradle
@@ -34,14 +34,8 @@
 *
 */
 
-/* Set the destination where we want to install the apps. */
-//s4AppInstallDir = "/tmp/s4Apps" // TODO: decide how to standarize dirs, use env var?
-
-project.ext["s4AppInstallDir"] = hasProperty('appsDir') ? "$appsDir" : "/tmp/appsDir"
-
 project.ext["s4Version"] = '0.5.0-SNAPSHOT'
 description = 'Apache S4 App'
-//defaultTasks 'installS4R'
 archivesBaseName = "$project.name"
 distRootFolder = "$archivesBaseName-${-> version}"
 
@@ -189,15 +183,6 @@
 
 }
 
-/* Install the S4 archive to the install directory. */
-task installS4R (type: Copy) {
-   dependsOn s4r
-   from s4r.archivePath
-   into s4AppInstallDir
-}
-
-
-
 
 /* Parse source file to get the app classname so we can use it in the manifest.
 * TODO: Use a real Java parser. (This is not skippong comments for example.)
diff --git a/test-apps/twitter-adapter/build.gradle b/test-apps/twitter-adapter/build.gradle
index e7734d3..1eeeb69 100644
--- a/test-apps/twitter-adapter/build.gradle
+++ b/test-apps/twitter-adapter/build.gradle
@@ -34,14 +34,8 @@
 *
 */
 
-/* Set the destination where we want to install the apps. */
-//s4AppInstallDir = "/tmp/s4Apps" // TODO: decide how to standarize dirs, use env var?
-
-project.ext["s4AppInstallDir"] = hasProperty('appsDir') ? "$appsDir" : "/tmp/appsDir"
-
 project.ext["s4Version"] = '0.5.0-incubating'
 description = 'Apache S4 App'
-//defaultTasks 'installS4R'
 project.ext["archivesBaseName"] = "$project.name"
 project.ext["distRootFolder"] = "$archivesBaseName-${-> version}"
 
@@ -176,13 +170,6 @@
 
 }
 
-/* Install the S4 archive to the install directory. */
-task installS4R (type: Copy) {
-   dependsOn s4r
-   from s4r.archivePath
-   into s4AppInstallDir
-}
-
 /* Generates the gradlew scripts.
 http://www.gradle.org/1.0-milestone-3/docs/userguide/gradle_wrapper.html */
 task wrapper(type: Wrapper) { gradleVersion = '1.0' }
diff --git a/test-apps/twitter-counter/build.gradle b/test-apps/twitter-counter/build.gradle
index e88e8d8..89db544 100644
--- a/test-apps/twitter-counter/build.gradle
+++ b/test-apps/twitter-counter/build.gradle
@@ -34,14 +34,8 @@
 *
 */
 
-/* Set the destination where we want to install the apps. */
-//s4AppInstallDir = "/tmp/s4Apps" // TODO: decide how to standarize dirs, use env var?
-
-project.ext["s4AppInstallDir"] = hasProperty('appsDir') ? "$appsDir" : "/tmp/appsDir"
-
 project.ext["s4Version"] = '0.5.0-incubating'
 description = 'Apache S4 App'
-//defaultTasks 'installS4R'
 project.ext["archivesBaseName"] = "$project.name"
 project.ext["distRootFolder"] = "$archivesBaseName-${-> version}"
 
@@ -173,13 +167,6 @@
 
 }
 
-/* Install the S4 archive to the install directory. */
-task installS4R (type: Copy) {
-   dependsOn s4r
-   from s4r.archivePath
-   into s4AppInstallDir
-}
-
 /* Generates the gradlew scripts.
 http://www.gradle.org/1.0-milestone-3/docs/userguide/gradle_wrapper.html */
 task wrapper(type: Wrapper) { gradleVersion = '1.0' }