src/JavaAntProjectResource.st
branchjk_new_structure
changeset 869 314c2f46efb0
child 877 f5a5b93e1c78
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/JavaAntProjectResource.st	Mon Jul 18 17:12:03 2011 +0000
@@ -0,0 +1,124 @@
+"{ Package: 'stx:libjava' }"
+
+TestResource subclass:#JavaAntProjectResource
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Languages-Java-Tests'
+!
+
+JavaAntProjectResource class instanceVariableNames:'built'
+
+"
+ The following class instance variables are inherited by this class:
+
+	TestResource - current
+	TestAsserter - 
+	Object - 
+"
+!
+
+
+!JavaAntProjectResource class methodsFor:'accessing'!
+
+antBuildDotXml
+
+    ^self antProjectDir / 'build.xml'
+
+    "Created: / 18-07-2011 / 15:21:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+built
+    ^ built == true
+
+    "Modified: / 18-07-2011 / 14:48:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+built:aBoolean
+    built := aBoolean.
+!
+
+classpath
+
+    ^ Array with: (self antProjectDir / 'bin')
+
+    "Created: / 18-07-2011 / 15:02:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaAntProjectResource class methodsFor:'accessing - ant project'!
+
+antProjectDir
+    "raise an error: must be redefined in concrete subclass(es)"
+
+    ^ self subclassResponsibility
+! !
+
+!JavaAntProjectResource class methodsFor:'running'!
+
+build
+    "
+        JavaTestsResource build: true.
+        JavaTestsResource build: false.
+    "
+    
+    built == true 
+        ifFalse:
+            [ "Check for ant"
+            self assert:(OperatingSystem canExecuteCommand:'ant')
+                description:'Cannot execute ant'.
+            self assert:self antBuildDotXml exists
+                description:'No build.xml in ' , self antProjectDir asString.
+             "Launch ant"
+            Transcript
+                show:'Running ant in ';
+                showCR:self antProjectDir asString.
+            OperatingSystem 
+                executeCommand:'ant -f build.xml'
+                inputFrom:nil
+                outputTo:Stdout
+                errorTo:Stderr
+                inDirectory:self antProjectDir
+                onError:
+                    [:status | 
+                    Transcript showCR:'ANT FAILED!!!!!!'.
+                    self error:'ant failed'.
+                    ^ self ].
+            Transcript showCR:'Ant finished'.
+            built := true. ].
+    ^ built.
+
+    "Modified: / 16-03-2011 / 15:20:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-06-2011 / 18:03:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified (format): / 18-07-2011 / 15:05:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaAntProjectResource methodsFor:'running'!
+
+setUp
+    self class build.
+    self class classpath do:[:each | Java addToClassPath:each ].
+
+    "
+        JavaTestsResource basicNew setUp
+        Java classPath
+    "
+
+    "Modified: / 07-05-2011 / 18:19:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 18-07-2011 / 15:04:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaAntProjectResource methodsFor:'testing'!
+
+isAvailable
+
+    ^self class antProjectDir exists and:
+        [self class antBuildDotXml exists]
+
+    "Created: / 18-07-2011 / 15:07:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaAntProjectResource class methodsFor:'documentation'!
+
+version_SVN
+    ^ '$Id$'
+! !