You are viewing a plain text version of this content. The canonical link for it is here.
Posted to s4-commits@incubator.apache.org by mm...@apache.org on 2013/06/01 11:33:05 UTC

[15/50] [abbrv] git commit: S4-66 Check that appClass extends App

S4-66 Check that appClass extends App

Patch by Aimee Cheng


Project: http://git-wip-us.apache.org/repos/asf/incubator-s4/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s4/commit/dd1da04c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s4/tree/dd1da04c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s4/diff/dd1da04c

Branch: refs/heads/master
Commit: dd1da04c7f52eb0181c5af804a3defe7b4a7400d
Parents: 60a75a0
Author: Daniel Gómez Ferro <df...@apache.org>
Authored: Thu Mar 7 17:24:21 2013 +0100
Committer: Daniel Gómez Ferro <df...@apache.org>
Committed: Thu Mar 7 18:19:56 2013 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/s4/tools/Deploy.java  |    2 +-
 .../src/main/resources/templates/build.gradle      |   46 +++++++-------
 2 files changed, 24 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/dd1da04c/subprojects/s4-tools/src/main/java/org/apache/s4/tools/Deploy.java
----------------------------------------------------------------------
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 9f9310c..1070e1c 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
@@ -79,7 +79,7 @@ public class Deploy extends S4ArgsBase {
                     // it and won't use an S4R
                     logger.info("No S4R path specified, nor build file specified: this assumes the app is in the classpath");
                 } else {
-                    logger.error("You must specify an S4R file, a build file to create an S4R from, or an appClass that will be in the classpath");
+                    logger.error("You must specify an S4R file or an appClass that will be in the classpath");
                     System.exit(1);
                 }
 

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/dd1da04c/subprojects/s4-tools/src/main/resources/templates/build.gradle
----------------------------------------------------------------------
diff --git a/subprojects/s4-tools/src/main/resources/templates/build.gradle b/subprojects/s4-tools/src/main/resources/templates/build.gradle
index 3a59f05..2651642 100644
--- a/subprojects/s4-tools/src/main/resources/templates/build.gradle
+++ b/subprojects/s4-tools/src/main/resources/templates/build.gradle
@@ -58,8 +58,8 @@ project.ext["libraries"] = [
 
             // you always need the s4 libraries for building your app
            s4_base:            'org.apache.s4:s4-base:'+ s4Version,
-           s4_comm:            'org.apache.s4:s4-comm:'+s4Version,
-           s4_core:            'org.apache.s4:s4-core:'+s4Version
+           s4_comm:            'org.apache.s4:s4-comm:'+ s4Version,
+           s4_core:            'org.apache.s4:s4-core:'+ s4Version
        ]
 
 
@@ -122,6 +122,7 @@ s4r << {
    appDependencies.each { File file -> println 'Adding to s4 archive: ' + file.name }
    configurations.archives.allArtifacts.files.each { println 'Adding to s4 archive: ' + it.name }
 
+   checkAppClass()
 }
 
 task cp << {
@@ -136,27 +137,26 @@ task installS4R (type: Copy) {
    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.)
-*/
-def getAppClassname(file) {
-   def classname = "UNKNOWN"
-   def lines= file.readLines()
-   def packageName = ""
-   for(line in lines) {
-
-       def pn = line =~ /.*package\s+([\w\.]+)\s*;.*/
-       if(pn) {
-           packageName = pn[0][1] + "."
-       }
-       def an = line =~ /.*public\s+class\s+(\w+)\s+extends.+App.*\{/
-
-       if (an) {
-           classname = packageName + an[0][1]
-           println "Found app class name: " + classname
-           break
-       }
+/*Check whether the defined appClass exists and extends App*/
+void checkAppClass() {
 
+   def loader = this.getClass().getClassLoader()
+
+   def jardir = new File( project.libsDir.path,'lib' )
+   def jars = jardir.listFiles().findAll { it.name.endsWith('.jar') }
+   jars.each {
+      loader.addURL(it.toURI().toURL())
    }
-   classname
+
+   def appJar = project.libsDir.path+"/app/"+"$project.name"+".jar"
+   loader.addURL(new URL("file://"+appJar))
+
+   def instance = Class.forName(appClassName, true, this.getClass().getClassLoader()).newInstance()
+
+   if (!(instance.getClass().getSuperclass().getName() == 'org.apache.s4.core.App') ){
+      println "App class " + appClassName + " does not extend org.apache.s4.core.App!"
+      System.exit(1)
+   }
+
 }
+