Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

License added; dos2unix applied; bootstrap scripts improvement; batch…

…-war improvement
  • Loading branch information...
commit eec018b21925cc5c79bb0caf458e9e6cbd678b05 1 parent 9a72a19
Daniel Henrique Alves Lima authored
2  BatchLauncherGrailsPlugin.groovy
View
@@ -1,6 +1,6 @@
class BatchLauncherGrailsPlugin {
// the plugin version
- def version = "0.1"
+ def version = "0.2"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.3.3 > *"
// the other plugins this plugin depends on
202 LICENSE.txt
View
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
12 application.properties
View
@@ -1,6 +1,6 @@
-#Grails Metadata file
-#Fri Dec 03 10:37:29 BRST 2010
-app.grails.version=1.3.3
-app.name=batch-launcher
-plugins.hibernate=1.3.3
-plugins.tomcat=1.3.3
+#Grails Metadata file
+#Fri Dec 03 10:37:29 BRST 2010
+app.grails.version=1.3.3
+app.name=batch-launcher
+plugins.hibernate=1.3.3
+plugins.tomcat=1.3.3
4 plugin.xml
View
@@ -1,11 +1,11 @@
-<plugin name='batch-launcher' version='0.1' grailsVersion='1.3.3 &gt; *'>
+<plugin name='batch-launcher' version='0.2' grailsVersion='1.3.3 &gt; *'>
<author>Daniel Henrique Alves Lima</author>
<authorEmail>email_daniel_h@yahoo.com.br</authorEmail>
<title>Plugin to load and run batch (non-webapp) Grails application</title>
<description>\
Brief description of the plugin.
</description>
- <documentation>http://grails.org/plugin/batch-launcher</documentation>
+ <documentation>https://code.google.com/p/grails-batch-launcher-plugin</documentation>
<resources>
<resource>BuildConfig</resource>
<resource>Config</resource>
14 scripts/BatchFastRunApp.groovy
View
@@ -1,7 +1,7 @@
-includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchRun.groovy")
-
-target(default: "Runs a Grails batch application in fast launch/bootstrap mode") {
- binding.batch.pluginScannerEnabled = false
- binding.batch.useGroovyClassLoader = true
- _batchRunApp()
-}
+includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchRun.groovy")
+
+target(default: "Runs a Grails batch application in fast launch/bootstrap mode") {
+ binding.batch.pluginScannerEnabled = false
+ binding.batch.useGroovyClassLoader = true
+ _batchRunApp()
+}
10 scripts/BatchReloadApp.groovy
View
@@ -1,5 +1,5 @@
-includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchRun.groovy")
-
-target(default: "Reloads batch app") {
- _batchReloadApp()
-}
+includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchRun.groovy")
+
+target(default: "Reloads batch app") {
+ _batchReloadApp()
+}
12 scripts/BatchRunApp.groovy
View
@@ -1,6 +1,6 @@
-includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchRun.groovy")
-
-target(default: "Runs a Grails batch application") {
- depends(checkVersion, configureProxy, packageApp, parseArguments)
- _batchRunApp()
-}
+includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchRun.groovy")
+
+target(default: "Runs a Grails batch application") {
+ depends(checkVersion, configureProxy, packageApp, parseArguments)
+ _batchRunApp()
+}
10 scripts/BatchWar.groovy
View
@@ -1,5 +1,5 @@
-includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchWar.groovy")
-
-target(default: "Runs a Grails batch application") {
- _batchWar()
-}
+includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchWar.groovy")
+
+target(default: "Runs a Grails batch application") {
+ _batchWar()
+}
76 scripts/_BatchInit.groovy
View
@@ -1,39 +1,39 @@
-import org.codehaus.groovy.grails.plugins.logging.Log4jConfig
-import org.apache.log4j.LogManager
-
-if (binding.variables.containsKey("_grails_batch_init_package_called")) {
- return
-}
-
-_grails_batch_init_package_called = true
-binding.batch = [:]
-
-def props = binding.batch
-props.bootstrapClassName = "net.sf.grails.batch.Bootstrap"
-props.pluginScannerEnabled = true
-props.useGroovyClassLoader = false
-props.autoRecompile = "true".equals(System.getProperty("disable.auto.recompile", "true"))? true: false
-props.autoRecompileFrequency = 3
-props.args = null
-props.infiniteLoop = true
-props.autoReload = "true".equals(System.getProperty("batch.disable.auto.recompile", "true"))? true: false
-props.autoReloadFrequency = 3
-
-
-target(_batchStartLogging: "Bootstraps logging") {
- /*ant.echo("props " + props)
- ant.echo("props " + binding.batch)
- ant.echo("props " + batch)*/
-
- /*
- LogManager.resetConfiguration()
- if (config.log4j instanceof Closure) {
- profile("configuring log4j") {
- new Log4jConfig().configure(config.log4j)
- }
- }
- else {
- // setup default logging
- new Log4jConfig().configure()
- }*/
+import org.codehaus.groovy.grails.plugins.logging.Log4jConfig
+import org.apache.log4j.LogManager
+
+if (binding.variables.containsKey("_grails_batch_init_package_called")) {
+ return
+}
+
+_grails_batch_init_package_called = true
+binding.batch = [:]
+
+def props = binding.batch
+props.bootstrapClassName = "org.codehaus.groovy.grails.plugins.batch.Bootstrap"
+props.pluginScannerEnabled = true
+props.useGroovyClassLoader = false
+props.autoRecompile = "true".equals(System.getProperty("disable.auto.recompile", "true"))? true: false
+props.autoRecompileFrequency = 3
+props.args = null
+props.infiniteLoop = true
+props.autoReload = "true".equals(System.getProperty("batch.disable.auto.reload", "true"))? true: false
+props.autoReloadFrequency = 3
+props.bootstrapJarExploded = "true".equals(System.getProperty("batch.bootstrap.jar.exploded", "false"))? true: false
+
+target(_batchStartLogging: "Bootstrap logging") {
+ /*ant.echo("props " + props)
+ ant.echo("props " + binding.batch)
+ ant.echo("props " + batch)*/
+
+ /*
+ LogManager.resetConfiguration()
+ if (config.log4j instanceof Closure) {
+ profile("configuring log4j") {
+ new Log4jConfig().configure(config.log4j)
+ }
+ }
+ else {
+ // setup default logging
+ new Log4jConfig().configure()
+ }*/
}
48 scripts/_BatchInstallTemplates.groovy
View
@@ -1,25 +1,25 @@
-if (binding.variables.containsKey("_grails_batch_install_templates_called")) {
- return
-}
-
-_grails_batch_install_templates_called = true
-
-includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchInit.groovy")
-
-target(_batchInstallTemplates: "") {
- depends(_batchStartLogging)
- targetDir = "${basedir}/src/templates/batch"
- //ant.echo "targetDir " + targetDir
- //def overwrite = ant.getProperty("overwrite.templates")
- //ant.echo "overwrite1 ${overwrite}"
- //ant.setProperty("overwrite.templates", "true")
- //ant.mkdir(dir: targetDir)
- //overwrite = ant.getProperty("overwrite.templates")
- //ant.echo "overwrite2 ${overwrite}"
- ant.copy(todir: targetDir) {
- fileset(dir: "${batchLauncherPluginDir}/src/templates/batch") {
- include(name: "*.bat")
- include(name: "*.sh")
- }
- }
+if (binding.variables.containsKey("_grails_batch_install_templates_called")) {
+ return
+}
+
+_grails_batch_install_templates_called = true
+
+includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchInit.groovy")
+
+target(_batchInstallTemplates: "") {
+ depends(_batchStartLogging)
+ targetDir = "${basedir}/src/templates/batch"
+ //ant.echo "targetDir " + targetDir
+ //def overwrite = ant.getProperty("overwrite.templates")
+ //ant.echo "overwrite1 ${overwrite}"
+ //ant.setProperty("overwrite.templates", "true")
+ //ant.mkdir(dir: targetDir)
+ //overwrite = ant.getProperty("overwrite.templates")
+ //ant.echo "overwrite2 ${overwrite}"
+ ant.copy(todir: targetDir) {
+ fileset(dir: "${batchLauncherPluginDir}/src/templates/batch") {
+ include(name: "*.bat")
+ include(name: "*.sh")
+ }
+ }
}
646 scripts/_BatchRun.groovy
View
@@ -1,324 +1,324 @@
-import org.codehaus.groovy.grails.plugins.PluginManagerHolder
-
-//import net.sf.grails.batch.InternalSecurityManager
-//import net.sf.grails.batch.ExitTrappedException
-
-//import java.security.Permission
-
-import org.codehaus.groovy.tools.shell.util.NoExitSecurityManager
-
-if (binding.variables.containsKey("_grails_batch_run_package_called")) {
- return
-}
-
-_grails_batch_run_package_called = true
-
-includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchInit.groovy")
-includeTargets << grailsScript("_GrailsRun")
-
-def props = binding.batch
-
-def recompileThread = null
-def killThread = null
-def batchThread = null
-def batchReload = false
-
-def oldSecurityManager = null
-def newSecurityManager = null
-
-target(_batchRunApp: "") {
- depends(_batchStartLogging, _batchParseArguments)
-
- def autoRecompile = props.autoRecompile
- def autoRecompileFrequency = props.autoRecompileFrequency
- def autoReload = props.autoReload
- def autoReloadFrequency = props.autoReloadFrequency
- ant.echo("autoRecompile ${autoRecompile}")
- ant.echo("autoReload ${autoReload}")
-
- if (autoRecompile && (!recompileThread || !recompileThread.isAlive())) {
- def ant = new AntBuilder(ant.project) // To avoid concurrent access to AntBuilder
- def exec = {
- while (true) {
- _batchAutoRecompile()
- Thread.sleep(autoRecompileFrequency * 1000)
- }
- } as Runnable
-
- recompileThread = new Thread(exec, "RecompileThread-" + (Thread.activeCount() + 1)) {
- public void start() {
- setDaemon(true)
- super.start()
- }
- }
-
- recompileThread.start()
- }
-
- if (autoReload && (!killThread || !killThread.isAlive())) {
- def exec = {
- def ant = new AntBuilder(ant.project) // To avoid concurrent access to AntBuilder
- def baseDir = new File(".")
- long lastModified = baseDir.lastModified()
-
- while (true) {
- Thread.sleep(autoReloadFrequency * 1000)
- long lastModified2 = baseDir.lastModified()
- if (lastModified2 > lastModified) {
- lastModified = lastModified2
- _batchKill(props)
- batchReload = true
- }
- }
- } as Runnable
-
- killThread = new Thread(exec, "KillThread-" + (Thread.activeCount() + 1)) {
- public void start() {
- setDaemon(true)
- super.start()
- }
- }
-
- killThread.start()
- }
-
- while (true) {
- _preBatchRun(props)
- _batchRun(props)
- _postBatchRun(props)
- if (!props.infiniteLoop) {
- break;
- }
-
- if (props.autoReload) {
- ant.echo("App finished. Waiting for 'reload' command")
- while (!batchReload) {
- Thread.sleep(props.autoReloadFrequency)
- }
- }
- }
-}
-
-
-
-_batchRun = {
- myProps ->
-
- def exec = {
-
- ant.echo("Loading ${myProps.bootstrapClassName}")
- Class c = classLoader.loadClass(myProps.bootstrapClassName)
- c.main(myProps.args as String[])
-
- } as Runnable
-
-
- batchThread = new Thread(exec) {
- public void start() {
- setDaemon(true)
- super.start()
- }
- }
-
- if (myProps.autoReload && myProps.infiniteLoop && !newSecurityManager) {
- oldSecurityManager = System.getSecurityManager()
- if (oldSecurityManager) {
- newSecurityManager = new NoExitSecurityManager(oldSecurityManager)
- } else {
- newSecurityManager = new NoExitSecurityManager()
- }
- }
- if (newSecurityManager) {
- ant.echo("disabling System.exit()")
- System.setSecurityManager(newSecurityManager)
- }
-
- batchThread.setContextClassLoader(classLoader)
-
- batchReload = false
- batchThread.start()
- try {
- while (batchThread && batchThread.isAlive() && !batchThread.interrupted()) {
- batchThread.join(myProps.autoReload? myProps.autoReloadFrequency * 1000: 0)
- }
- } catch (Exception e) {
- def handled = false
- if (InterruptedException.class.instanceOf(e) || java.nio.channels.ClosedByInterruptException.class.instanceOf(e)) {
- if (batchThread.interrupted()) {
- handled = true
- e.printStackTrace()
- }
- }
-
- if (!handled) {
- throw e
- }
- }
-
- if (newSecurityManager) {
- ant.echo("enabling System.exit()")
- System.setSecurityManager(oldSecurityManager)
- }
-
- batchThread = null
-}
-
-
-
-_batchKill = {
- myProps ->
-
- if (batchThread) {
- ant.echo("unloading batch app")
- while (batchThread && batchThread.isAlive() && !batchThread.interrupted()) {
- batchThread.interrupt()
- Thread.yield()
- }
- ant.echo("batch app unloaded")
- }
-}
-
-_preBatchRun = {
- myProps ->
-
- def pluginScannerEnabled = myProps.pluginScannerEnabled
- def useGroovyClassLoader = myProps.useGroovyClassLoader
-
- def grailsReloadLocation = System.getProperty("grails.reload.location")
- if (!grailsReloadLocation) {
- grailsReloadLocation = new java.io.File("").absolutePath
- System.setProperty("grails.reload.location", grailsReloadLocation)
- }
-
- def sourceDirs = [new java.io.File("").toURI().toURL()]
- resolveResources("file:${basedir}/grails-app/*").each {sourceDirs << it.file.toURI().toURL()}
-
- def classesDirs = [
- classesDir,
- pluginClassesDir].collect { it.toURI().toURL() }
-
- classLoader = null
- if (useGroovyClassLoader) {
- classLoader = new GroovyClassLoader(rootLoader)
- sourceDirs.each {
- classLoader.addURL(it)
- }
- classesDirs.each {
- classLoader.addURL(it)
- }
- } else {
- classesDirs.add(0, sourceDirs[0])
- classLoader = new URLClassLoader(classesDirs as URL[], rootLoader)
- }
-
- Thread.currentThread().setContextClassLoader classLoader
- PluginManagerHolder.pluginManager = null
-
- loadPlugins()
- if (pluginScannerEnabled) {
- startPluginScanner()
- ant.echo("plugin scanner started")
- }
-}
-
-
-_postBatchRun = {
- myProps ->
-
- if (myProps.pluginScannerEnabled) {
- stopPluginScanner()
- ant.echo("plugin scanner stoped")
- }
-}
-
-
-target(_batchReloadApp: "") {
- def file = File.createTempFile("touch", "tmp", new File("."))
- file.deleteOnExit()
- file.delete()
-}
-
-
-target(_batchParseArguments: "Parse the arguments passed on the command line") {
- if (!props.args) {
- def argsSwitchFound = false
- props.args = []
-
- args?.tokenize().each {token ->
- def argsSwitch = token =~ "--?args"
- if (argsSwitch.matches()) {
- argsSwitchFound = true
- }
- else {
- if (argsSwitchFound) {
- props.args << token
- }
- }
- }
- }
-}
-
-
-target(_batchAutoRecompile: "") {
- depends(compilePlugins)
-
- def ant = new AntBuilder(ant.project)
- def classesDirPath = new File(grailsSettings.classesDir.path)
- ant.mkdir(dir:classesDirPath)
-
- profile("Compiling sources to location [$classesDirPath]") {
- try {
- String classpathId = "grails.compile.classpath"
- //def sourceDirs = new File("${basedir}/grails-app").listFiles({dir, name -> !name.equals("conf")} as FilenameFilter)
- //ant.echo("sourceDirs " + sourceDirs)
-
- /* To avoid continuous resources.groovy recompilation. */
- ant.groovyc(destdir:classesDirPath,
- classpathref:classpathId,
- encoding:"UTF-8",
- verbose: grailsSettings.verboseCompile,
- listfiles: grailsSettings.verboseCompile,
- excludes: "spring/resources.groovy",
- compilerPaths.curry(classpathId))
-
- ant.groovyc(destdir:classesDirPath,
- classpathref:classpathId,
- encoding:"UTF-8",
- verbose: grailsSettings.verboseCompile,
- listfiles: grailsSettings.verboseCompile,
- includes: "resources.groovy"
- ) {
- src(path: "${basedir}/grails-app/conf/spring")
- }
- }
- catch (Exception e) {
- e.printStackTrace()
- }
-
- classLoader.addURL(grailsSettings.classesDir.toURI().toURL())
- classLoader.addURL(grailsSettings.pluginClassesDir.toURI().toURL())
-
- // If this is a plugin project, the descriptor is not included
- // in the compiler's source path. So, we manually compile it now.
- if (isPluginProject) compilePluginDescriptor(findPluginDescriptor(grailsSettings.baseDir))
- }
-}
-
-
-static class InternalSecurityManager extends SecurityManager {
-
- InternalSecurityManager() {
- }
-
- /*@Override
- public void checkPermission(Permission permission) {
- //if ("exitVM".equals(permission.getName())) {
- //throw new ExitTrappedException();
- //System.out.println("ok security")
- //}
- }*/
-
-}
-
-static class ExitTrappedException extends SecurityException {
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder
+
+//import net.sf.grails.batch.InternalSecurityManager
+//import net.sf.grails.batch.ExitTrappedException
+
+//import java.security.Permission
+
+import org.codehaus.groovy.tools.shell.util.NoExitSecurityManager
+
+if (binding.variables.containsKey("_grails_batch_run_package_called")) {
+ return
+}
+
+_grails_batch_run_package_called = true
+
+includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchInit.groovy")
+includeTargets << grailsScript("_GrailsRun")
+
+def props = binding.batch
+
+def recompileThread = null
+def killThread = null
+def batchThread = null
+def batchReload = false
+
+def oldSecurityManager = null
+def newSecurityManager = null
+
+target(_batchRunApp: "") {
+ depends(_batchStartLogging, _batchParseArguments)
+
+ def autoRecompile = props.autoRecompile
+ def autoRecompileFrequency = props.autoRecompileFrequency
+ def autoReload = props.autoReload
+ def autoReloadFrequency = props.autoReloadFrequency
+ ant.echo("autoRecompile ${autoRecompile}")
+ ant.echo("autoReload ${autoReload}")
+
+ if (autoRecompile && (!recompileThread || !recompileThread.isAlive())) {
+ def ant = new AntBuilder(ant.project) // To avoid concurrent access to AntBuilder
+ def exec = {
+ while (true) {
+ _batchAutoRecompile()
+ Thread.sleep(autoRecompileFrequency * 1000)
+ }
+ } as Runnable
+
+ recompileThread = new Thread(exec, "RecompileThread-" + (Thread.activeCount() + 1)) {
+ public void start() {
+ setDaemon(true)
+ super.start()
+ }
+ }
+
+ recompileThread.start()
+ }
+
+ if (autoReload && (!killThread || !killThread.isAlive())) {
+ def exec = {
+ def ant = new AntBuilder(ant.project) // To avoid concurrent access to AntBuilder
+ def baseDir = new File(".")
+ long lastModified = baseDir.lastModified()
+
+ while (true) {
+ Thread.sleep(autoReloadFrequency * 1000)
+ long lastModified2 = baseDir.lastModified()
+ if (lastModified2 > lastModified) {
+ lastModified = lastModified2
+ _batchKill(props)
+ batchReload = true
+ }
+ }
+ } as Runnable
+
+ killThread = new Thread(exec, "KillThread-" + (Thread.activeCount() + 1)) {
+ public void start() {
+ setDaemon(true)
+ super.start()
+ }
+ }
+
+ killThread.start()
+ }
+
+ while (true) {
+ _preBatchRun(props)
+ _batchRun(props)
+ _postBatchRun(props)
+ if (!props.infiniteLoop) {
+ break;
+ }
+
+ if (props.autoReload) {
+ ant.echo("App finished. Waiting for 'reload' command")
+ while (!batchReload) {
+ Thread.sleep(props.autoReloadFrequency)
+ }
+ }
+ }
+}
+
+
+
+_batchRun = {
+ myProps ->
+
+ def exec = {
+
+ ant.echo("Loading ${myProps.bootstrapClassName}")
+ Class c = classLoader.loadClass(myProps.bootstrapClassName)
+ c.main(myProps.args as String[])
+
+ } as Runnable
+
+
+ batchThread = new Thread(exec) {
+ public void start() {
+ setDaemon(true)
+ super.start()
+ }
+ }
+
+ if (myProps.autoReload && myProps.infiniteLoop && !newSecurityManager) {
+ oldSecurityManager = System.getSecurityManager()
+ if (oldSecurityManager) {
+ newSecurityManager = new NoExitSecurityManager(oldSecurityManager)
+ } else {
+ newSecurityManager = new NoExitSecurityManager()
+ }
+ }
+ if (newSecurityManager) {
+ ant.echo("disabling System.exit()")
+ System.setSecurityManager(newSecurityManager)
+ }
+
+ batchThread.setContextClassLoader(classLoader)
+
+ batchReload = false
+ batchThread.start()
+ try {
+ while (batchThread && batchThread.isAlive() && !batchThread.interrupted()) {
+ batchThread.join(myProps.autoReload? myProps.autoReloadFrequency * 1000: 0)
+ }
+ } catch (Exception e) {
+ def handled = false
+ if (InterruptedException.class.instanceOf(e) || java.nio.channels.ClosedByInterruptException.class.instanceOf(e)) {
+ if (batchThread.interrupted()) {
+ handled = true
+ e.printStackTrace()
+ }
+ }
+
+ if (!handled) {
+ throw e
+ }
+ }
+
+ if (newSecurityManager) {
+ ant.echo("enabling System.exit()")
+ System.setSecurityManager(oldSecurityManager)
+ }
+
+ batchThread = null
+}
+
+
+
+_batchKill = {
+ myProps ->
+
+ if (batchThread) {
+ ant.echo("unloading batch app")
+ while (batchThread && batchThread.isAlive() && !batchThread.interrupted()) {
+ batchThread.interrupt()
+ Thread.yield()
+ }
+ ant.echo("batch app unloaded")
+ }
+}
+
+_preBatchRun = {
+ myProps ->
+
+ def pluginScannerEnabled = myProps.pluginScannerEnabled
+ def useGroovyClassLoader = myProps.useGroovyClassLoader
+
+ def grailsReloadLocation = System.getProperty("grails.reload.location")
+ if (!grailsReloadLocation) {
+ grailsReloadLocation = new java.io.File("").absolutePath
+ System.setProperty("grails.reload.location", grailsReloadLocation)
+ }
+
+ def sourceDirs = [new java.io.File("").toURI().toURL()]
+ resolveResources("file:${basedir}/grails-app/*").each {sourceDirs << it.file.toURI().toURL()}
+
+ def classesDirs = [
+ classesDir,
+ pluginClassesDir].collect { it.toURI().toURL() }
+
+ classLoader = null
+ if (useGroovyClassLoader) {
+ classLoader = new GroovyClassLoader(rootLoader)
+ sourceDirs.each {
+ classLoader.addURL(it)
+ }
+ classesDirs.each {
+ classLoader.addURL(it)
+ }
+ } else {
+ classesDirs.add(0, sourceDirs[0])
+ classLoader = new URLClassLoader(classesDirs as URL[], rootLoader)
+ }
+
+ Thread.currentThread().setContextClassLoader classLoader
+ PluginManagerHolder.pluginManager = null
+
+ loadPlugins()
+ if (pluginScannerEnabled) {
+ startPluginScanner()
+ ant.echo("plugin scanner started")
+ }
+}
+
+
+_postBatchRun = {
+ myProps ->
+
+ if (myProps.pluginScannerEnabled) {
+ stopPluginScanner()
+ ant.echo("plugin scanner stoped")
+ }
+}
+
+
+target(_batchReloadApp: "") {
+ def file = File.createTempFile("touch", "tmp", new File("."))
+ file.deleteOnExit()
+ file.delete()
+}
+
+
+target(_batchParseArguments: "Parse the arguments passed on the command line") {
+ if (!props.args) {
+ def argsSwitchFound = false
+ props.args = []
+
+ args?.tokenize().each {token ->
+ def argsSwitch = token =~ "--?args"
+ if (argsSwitch.matches()) {
+ argsSwitchFound = true
+ }
+ else {
+ if (argsSwitchFound) {
+ props.args << token
+ }
+ }
+ }
+ }
+}
+
+
+target(_batchAutoRecompile: "") {
+ depends(compilePlugins)
+
+ def ant = new AntBuilder(ant.project)
+ def classesDirPath = new File(grailsSettings.classesDir.path)
+ ant.mkdir(dir:classesDirPath)
+
+ profile("Compiling sources to location [$classesDirPath]") {
+ try {
+ String classpathId = "grails.compile.classpath"
+ //def sourceDirs = new File("${basedir}/grails-app").listFiles({dir, name -> !name.equals("conf")} as FilenameFilter)
+ //ant.echo("sourceDirs " + sourceDirs)
+
+ /* To avoid continuous resources.groovy recompilation. */
+ ant.groovyc(destdir:classesDirPath,
+ classpathref:classpathId,
+ encoding:"UTF-8",
+ verbose: grailsSettings.verboseCompile,
+ listfiles: grailsSettings.verboseCompile,
+ excludes: "spring/resources.groovy",
+ compilerPaths.curry(classpathId))
+
+ ant.groovyc(destdir:classesDirPath,
+ classpathref:classpathId,
+ encoding:"UTF-8",
+ verbose: grailsSettings.verboseCompile,
+ listfiles: grailsSettings.verboseCompile,
+ includes: "resources.groovy"
+ ) {
+ src(path: "${basedir}/grails-app/conf/spring")
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace()
+ }
+
+ classLoader.addURL(grailsSettings.classesDir.toURI().toURL())
+ classLoader.addURL(grailsSettings.pluginClassesDir.toURI().toURL())
+
+ // If this is a plugin project, the descriptor is not included
+ // in the compiler's source path. So, we manually compile it now.
+ if (isPluginProject) compilePluginDescriptor(findPluginDescriptor(grailsSettings.baseDir))
+ }
+}
+
+
+static class InternalSecurityManager extends SecurityManager {
+
+ InternalSecurityManager() {
+ }
+
+ /*@Override
+ public void checkPermission(Permission permission) {
+ //if ("exitVM".equals(permission.getName())) {
+ //throw new ExitTrappedException();
+ //System.out.println("ok security")
+ //}
+ }*/
+
+}
+
+static class ExitTrappedException extends SecurityException {
}
207 scripts/_BatchWar.groovy
View
@@ -1,94 +1,113 @@
-
-if (binding.variables.containsKey("_grails_batch_war_package_called")) {
- return
-}
-
-_grails_batch_war_package_called = true
-
-scriptEnv = "production"
-//ant.property(name:"grails.war.exploded", value: "true")
-
-includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchInit.groovy")
-includeTargets << grailsScript("_GrailsWar")
-
-def props = binding.batch
-
-target(_batchWar: "") {
- war()
-
- def warDir = new File(warName.replace(".war", "/war"))
- def batchDir = warDir.parentFile
- def appName = grailsAppName
- def appVersion = metadata.getApplicationVersion()
- //def appName = batchDir.name
- def templatesSourceDir = new File("${basedir}/src/templates/batch")
-
- ant.mkdir(dir: batchDir.absolutePath)
-
- def libDirName = "war/WEB-INF/lib"
- def classesDirName = "war/WEB-INF/classes"
-
- def bootstrapJarName = batchDir.name + ".jar"
-
- ant.unjar(src: warName, dest: warDir.absolutePath)
- ant.delete(file: warName)
-
- ant.copy(todir: warDir.absolutePath + "/WEB-INF/lib") {
- fileset(dir: "${grailsHome}/lib") {
- include(name: "org.springframework.test-*.jar")
- include(name: "servlet-api-*.jar")
- include(name: "jta-*.jar")
- }
- }
-
-
- StringBuilder manifestClasspath = new StringBuilder()
- manifestClasspath.append(". ${classesDirName} war")
-
- new File("WEB-INF/lib", warDir).listFiles().each {
- manifestClasspath.append(" ${libDirName}/" + it.name)
- }
-
- ant.jar(destfile: batchDir.absolutePath + "/" + bootstrapJarName, baseDir: warDir.absolutePath + "/WEB-INF/classes") {
- manifest {
- attribute(name: "Class-Path", value: manifestClasspath)
- attribute(name: "Main-Class", value: props.bootstrapClassName)
- }
- }
-
-
- if (templatesSourceDir.exists()) {
- def filterTokens = [appName: appName, appVersion: appVersion, bootstrapJarName: bootstrapJarName, bootstrapClassName: props.bootstrapClassName, libDirName: libDirName, classesDirName: classesDirName]
-
- ant.copy(todir: batchDir.absolutePath, filtering: true) {
- fileset(dir: templatesSourceDir.absolutePath) {
- include(name: "*")
- exclude(name: "batch-launcher*")
- }
- filterset {
- filterTokens.each {
- filter(token: it.key, value: it.value)
- }
- }
- }
-
- ant.copy(todir: batchDir.absolutePath, filtering: true) {
- fileset(dir: templatesSourceDir.absolutePath) {
- include(name: "batch-launcher*")
- }
- globmapper(from: "batch-launcher*", to: appName + "*")
- filterset {
- filterTokens.each {
- filter(token: it.key, value: it.value)
- }
- }
- }
- }
-
-
- ant.delete(dir: warDir.absolutePath + "/WEB-INF/classes") {
- include(name: "**/*")
- }
-
-
-}
+
+if (binding.variables.containsKey("_grails_batch_war_package_called")) {
+ return
+}
+
+_grails_batch_war_package_called = true
+
+scriptEnv = "production"
+//ant.property(name:"grails.war.exploded", value: "true")
+System.setProperty("grails.war.exploded", "true")
+
+includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchInit.groovy")
+includeTargets << grailsScript("_GrailsWar")
+
+def props = binding.batch
+
+target(_batchWar: "") {
+ war()
+
+ def warDir = new File(warName.replace(".war", "/war"))
+ def batchDir = warDir.parentFile
+ def appName = grailsAppName
+ def appVersion = metadata.getApplicationVersion()
+ //def appName = batchDir.name
+ def templatesSourceDir = new File("${basedir}/src/templates/batch")
+ if (!templatesSourceDir.exists()) {
+ templatesSourceDir = new File("${batchLauncherPluginDir}/src/templates/batch")
+ }
+
+ ant.mkdir(dir: batchDir.absolutePath)
+
+ def libDirName = "war/WEB-INF/lib"
+ def classesDirName = "war/WEB-INF/classes"
+
+ def bootstrapJarName = batchDir.name + ".jar"
+ def stagingDir = grailsSettings.projectWarExplodedDir
+
+ //ant.unjar(src: warName, dest: warDir.absolutePath)
+ //ant.delete(file: warName)
+
+ ant.copy(todir: warDir.absolutePath) {
+ fileset(dir: stagingDir) {
+ include(name: "**/*")
+ }
+ }
+
+ ant.copy(todir: warDir.absolutePath + "/WEB-INF/lib") {
+ fileset(dir: "${grailsHome}/lib") {
+ include(name: "org.springframework.test-*.jar")
+ include(name: "servlet-api-*.jar")
+ include(name: "jta-*.jar")
+ }
+ }
+
+
+ StringBuilder manifestClasspath = new StringBuilder()
+ StringBuilder windowsLibClasspath = new StringBuilder("")
+ StringBuilder linuxLibClasspath = new StringBuilder("")
+ manifestClasspath.append(". ${classesDirName} war")
+
+ new File("WEB-INF/lib", warDir).listFiles().each {
+ manifestClasspath.append(" ${libDirName}/" + it.name)
+ windowsLibClasspath.append("${libDirName}/" + it.name + ";")
+ linuxLibClasspath.append("${libDirName}/" + it.name + ":")
+ }
+
+ if (!props.bootstrapJarExploded) {
+ ant.jar(destfile: batchDir.absolutePath + "/" + bootstrapJarName, baseDir: warDir.absolutePath + "/WEB-INF/classes") {
+ manifest {
+ attribute(name: "Class-Path", value: manifestClasspath)
+ attribute(name: "Main-Class", value: props.bootstrapClassName)
+ }
+ }
+
+ ant.delete(dir: warDir.absolutePath + "/WEB-INF/classes") {
+ include(name: "**/*")
+ }
+
+ windowsLibClasspath.delete(0, windowsLibClasspath.length())
+ linuxLibClasspath.delete(0, linuxLibClasspath.length())
+ }
+
+
+ if (templatesSourceDir.exists()) {
+ def filterTokens = [appName: appName, appVersion: appVersion, bootstrapJarName: bootstrapJarName, bootstrapClassName: props.bootstrapClassName, libDirName: libDirName, classesDirName: classesDirName, windowsLibClasspath: windowsLibClasspath, linuxLibClasspath: linuxLibClasspath]
+
+ ant.copy(todir: batchDir.absolutePath, filtering: true) {
+ fileset(dir: templatesSourceDir.absolutePath) {
+ include(name: "*")
+ exclude(name: "batch-launcher*")
+ }
+ filterset {
+ filterTokens.each {
+ filter(token: it.key, value: it.value)
+ }
+ }
+ }
+
+ ant.copy(todir: batchDir.absolutePath, filtering: true) {
+ fileset(dir: templatesSourceDir.absolutePath) {
+ include(name: "batch-launcher*")
+ }
+ globmapper(from: "batch-launcher*", to: appName + "*")
+ filterset {
+ filterTokens.each {
+ filter(token: it.key, value: it.value)
+ }
+ }
+ }
+ }
+
+
+}
14 scripts/_Events.groovy
View
@@ -1,8 +1,8 @@
-includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchInstallTemplates.groovy")
-
-eventStatusUpdate = { msg ->
- if (msg && msg.startsWith("Templates installed successfully")) {
- println ">>>>>>>>>>>>> ${msg} ${ant}"
- _batchInstallTemplates()
- }
+includeTargets << new File("${batchLauncherPluginDir}/scripts/_BatchInstallTemplates.groovy")
+
+eventStatusUpdate = { msg ->
+ if (msg && msg.startsWith("Templates installed successfully")) {
+ println ">>>>>>>>>>>>> ${msg} ${ant}"
+ _batchInstallTemplates()
+ }
}
464 src/java/net/sf/grails/batch/Bootstrap.java → ...dehaus/groovy/grails/plugins/batch/Bootstrap.java
View
@@ -1,232 +1,232 @@
-package net.sf.grails.batch;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextListener;
-import javax.servlet.ServletContextEvent;
-
-import org.codehaus.groovy.grails.web.context.GrailsConfigUtils;
-import org.codehaus.groovy.grails.commons.GrailsApplication;
-
-import org.springframework.web.context.support.WebApplicationContextUtils;
-import org.springframework.web.context.WebApplicationContext;
-import org.springframework.mock.web.MockServletContext;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.access.BootstrapException;
-import org.springframework.web.context.support.XmlWebApplicationContext;
-
-import org.codehaus.groovy.grails.commons.GrailsBootstrapClass;
-import org.codehaus.groovy.grails.commons.GrailsClass;
-import org.codehaus.groovy.grails.commons.spring.GrailsApplicationContext;
-import org.codehaus.groovy.grails.commons.BootstrapArtefactHandler;
-import org.codehaus.groovy.grails.compiler.injection.GrailsAwareClassLoader;
-import org.codehaus.groovy.grails.web.util.Log4jConfigListener;
-import org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener;
-import org.codehaus.groovy.grails.plugins.PluginManagerHolder;
-import org.codehaus.groovy.grails.plugins.GrailsPluginManager;
-import org.codehaus.groovy.grails.plugins.DefaultGrailsPluginManager;
-
-
-import grails.util.GrailsUtil;
-import grails.util.Environment;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-//import org.apache.log4j.Logger;
-
-public class Bootstrap {
-
- public static final Log LOG = LogFactory.getLog(Bootstrap.class);
- // public static final Logger LOGGER = Logger.getLogger(Bootstrap.class);
-
- private ServletContext servletContext;
- private ServletContextListener [] servletContextListeners;
-
- private WebApplicationContext webContext;
-
- public void init(String [] args) {
- LOG.debug("init(): begin");
- // System.out.println("" + LOG);
- // System.out.println("" + LOG.isErrorEnabled());
- // System.out.println("" + LOG.isDebugEnabled());
- // System.out.println("" + LOGGER.getLevel());
- // LOG.error("BLA1"); LOG.debug("BLA1");
- // LOGGER.error("BLA1"); LOGGER.debug("BLA1");
- // System.out.println("+++++++++++++++++++ " + Thread.currentThread().getContextClassLoader());
- // System.out.println("+++++++++++++++++++ " + this.getClass().getClassLoader());
- // System.out.println("args " + java.util.Arrays.asList(args));
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("init(): this classLoader " + this.getClass().getClassLoader());
- LOG.debug("init(): thread classLoader " + Thread.currentThread().getContextClassLoader());
- }
-
- /*if (1 == 1) {
- throw new RuntimeException("bla__");
- }*/
-
- //Thread.currentThread().setContextClassLoader(new GrailsAwareClassLoader());
-
- // System.out.println("environment " + Environment.getCurrent());
- if (LOG.isDebugEnabled()) {
- LOG.debug("init(): env " + Environment.getCurrent());
- }
-
- String resourcePath = null;
- switch(Environment.getCurrent()) {
- case PRODUCTION:
- resourcePath = "war";
- break;
- default:
- //resourcePath = (new java.io.File("web-app")).getAbsolutePath();
- resourcePath = "web-app";
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("init(): resourcePath " + resourcePath);
- }
-
- // System.out.println("path " + resourcePath);
- servletContext = resourcePath != null? new MockServletContext(resourcePath): new MockServletContext();
- servletContext.setAttribute("args", args);
-
- /*try {
- // System.out.println("path " + servletContext.getResource("/"));
- // System.out.println("path " + servletContext.getResource(""));
- // System.out.println("path " + servletContext.getResource("."));
- } catch (java.net.MalformedURLException e) {
- throw new RuntimeException(e);
- }*/
-
- servletContextListeners = new ServletContextListener[] {
- new Log4jConfigListener(),
- new GrailsContextLoaderListener()
- };
-
- try
- {
- ServletContextEvent event = new ServletContextEvent(servletContext);
- for (ServletContextListener l : servletContextListeners) {
- l.contextInitialized(event);
- // System.out.println("" + l + " ok");
- // System.out.println("" + LOG);
- // System.out.println("" + LOG.isErrorEnabled());
- // System.out.println("" + LOG.isDebugEnabled());
- // System.out.println("" + LOGGER.getLevel());
- // LOG.error("BLA2");LOG.debug("BLA1");
- // LOGGER.error("BLA1"); LOGGER.debug("BLA1");
- }
- } catch (RuntimeException e) {
- LOG.error("init()", e);
- throw e;
- }
-
- // No fixed context defined for this servlet - create a local one.
- /*XmlWebApplicationContext parent = new XmlWebApplicationContext();
- parent.setServletContext(servletContext);
- //parent.setNamespace(getClass().getName() + ".CONTEXT.");
- parent.refresh();*/
- WebApplicationContext parent = WebApplicationContextUtils.getWebApplicationContext(servletContext);
-
- WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
- // construct the SpringConfig for the container managed application
- //Assert.notNull(parent, "Grails requires a parent ApplicationContext, is the /WEB-INF/applicationContext.xml file missing?");
- GrailsApplication application = parent.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
-
- //WebApplicationContext webContext;
- if (wac instanceof GrailsApplicationContext) {
- webContext = wac;
- }
- else {
- webContext = GrailsConfigUtils.configureWebApplicationContext(servletContext, parent);
- // System.out.println("configureWebApplicationContext ok");
-
- try {
- GrailsConfigUtils.executeGrailsBootstraps(application, webContext, servletContext);
- // System.out.println("executeGrailsBootstraps ok");
- }
- catch (Exception e) {
- LOG.debug("init()", e);
- GrailsUtil.deepSanitize(e);
- if (e instanceof BeansException) {
- throw (BeansException)e;
- }
-
- throw new BootstrapException("Error executing bootstraps", e);
- }
- }
-
- /*
- boolean x = true;
- try {
- while (x) {
- // System.out.println(Bootstrap.class.getName() + ": " + Thread.currentThread() + " " + new java.util.Date());
- Thread.sleep(10000);
- }
- } catch (Exception e) {
- }*/
-
- // System.out.println("+++++++++++++++++++ " + Thread.currentThread().getContextClassLoader());
- // System.out.println("+++++++++++++++++++ " + this.getClass().getClassLoader());
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("init(): thread classLoader " + Thread.currentThread().getContextClassLoader());
- }
-
-
- /*GrailsPluginManager pm = PluginManagerHolder.getPluginManager();
- if (pm instanceof DefaultGrailsPluginManager) {
- ((DefaultGrailsPluginManager) pm).startPluginChangeScanner();
- }*/
-
- /*if (1 == 1) {
- throw new Error("abc");
- }*/
- LOG.debug("init(): end");
- }
-
- public void destroy() {
- LOG.debug("destroy(): begin");
- /*GrailsPluginManager pm = PluginManagerHolder.getPluginManager();
- if (pm instanceof DefaultGrailsPluginManager) {
- ((DefaultGrailsPluginManager) pm).stopPluginChangeScanner();
- }*/
-
- GrailsApplication grailsApplication = webContext.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
-
- GrailsClass[] bootstraps = grailsApplication.getArtefacts(BootstrapArtefactHandler.TYPE);
- for (GrailsClass bootstrap : bootstraps) {
- ((GrailsBootstrapClass) bootstrap).callDestroy();
- }
-
-
- {
- ServletContextEvent event = new ServletContextEvent(servletContext);
- for (ServletContextListener l : servletContextListeners) {
- l.contextDestroyed(event);
- }
- }
-
- servletContext = null;
-
- LOG.debug("destroy(): end");
- }
-
-
- public static void main(String [] args) {
- // System.out.println(Bootstrap.class.getName()+ ".main() - begin " + new java.util.Date());
- if (LOG.isDebugEnabled()) {
- LOG.debug("main(): begin " + Bootstrap.class.getName()+ " - " + new java.util.Date());
- }
-
- Bootstrap r = new Bootstrap();
- r.init(args);
- r.destroy();
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("main(): end " + Bootstrap.class.getName()+ " - " + new java.util.Date());
- }
-
- // System.out.println(Bootstrap.class.getName()+ ".main() - end " + new java.util.Date());
- }
-}
+package org.codehaus.groovy.grails.plugins.batch;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextListener;
+import javax.servlet.ServletContextEvent;
+
+import org.codehaus.groovy.grails.web.context.GrailsConfigUtils;
+import org.codehaus.groovy.grails.commons.GrailsApplication;
+
+import org.springframework.web.context.support.WebApplicationContextUtils;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.mock.web.MockServletContext;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.access.BootstrapException;
+import org.springframework.web.context.support.XmlWebApplicationContext;
+
+import org.codehaus.groovy.grails.commons.GrailsBootstrapClass;
+import org.codehaus.groovy.grails.commons.GrailsClass;
+import org.codehaus.groovy.grails.commons.spring.GrailsApplicationContext;
+import org.codehaus.groovy.grails.commons.BootstrapArtefactHandler;
+import org.codehaus.groovy.grails.compiler.injection.GrailsAwareClassLoader;
+import org.codehaus.groovy.grails.web.util.Log4jConfigListener;
+import org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener;
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder;
+import org.codehaus.groovy.grails.plugins.GrailsPluginManager;
+import org.codehaus.groovy.grails.plugins.DefaultGrailsPluginManager;
+
+
+import grails.util.GrailsUtil;
+import grails.util.Environment;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+//import org.apache.log4j.Logger;
+
+public class Bootstrap {
+
+ public static final Log LOG = LogFactory.getLog(Bootstrap.class);
+ // public static final Logger LOGGER = Logger.getLogger(Bootstrap.class);
+
+ private ServletContext servletContext;
+ private ServletContextListener [] servletContextListeners;
+
+ private WebApplicationContext webContext;
+
+ public void init(String [] args) {
+ LOG.debug("init(): begin");
+ // System.out.println("" + LOG);
+ // System.out.println("" + LOG.isErrorEnabled());
+ // System.out.println("" + LOG.isDebugEnabled());
+ // System.out.println("" + LOGGER.getLevel());
+ // LOG.error("BLA1"); LOG.debug("BLA1");
+ // LOGGER.error("BLA1"); LOGGER.debug("BLA1");
+ // System.out.println("+++++++++++++++++++ " + Thread.currentThread().getContextClassLoader());
+ // System.out.println("+++++++++++++++++++ " + this.getClass().getClassLoader());
+ // System.out.println("args " + java.util.Arrays.asList(args));
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("init(): this classLoader " + this.getClass().getClassLoader());
+ LOG.debug("init(): thread classLoader " + Thread.currentThread().getContextClassLoader());
+ }
+
+ /*if (1 == 1) {
+ throw new RuntimeException("bla__");
+ }*/
+
+ //Thread.currentThread().setContextClassLoader(new GrailsAwareClassLoader());
+
+ // System.out.println("environment " + Environment.getCurrent());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("init(): env " + Environment.getCurrent());
+ }
+
+ String resourcePath = null;
+ switch(Environment.getCurrent()) {
+ case PRODUCTION:
+ resourcePath = "war";
+ break;
+ default:
+ //resourcePath = (new java.io.File("web-app")).getAbsolutePath();
+ resourcePath = "web-app";
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("init(): resourcePath " + resourcePath);
+ }
+
+ // System.out.println("path " + resourcePath);
+ servletContext = resourcePath != null? new MockServletContext(resourcePath): new MockServletContext();
+ servletContext.setAttribute("args", args);
+
+ /*try {
+ // System.out.println("path " + servletContext.getResource("/"));
+ // System.out.println("path " + servletContext.getResource(""));
+ // System.out.println("path " + servletContext.getResource("."));
+ } catch (java.net.MalformedURLException e) {
+ throw new RuntimeException(e);
+ }*/
+
+ servletContextListeners = new ServletContextListener[] {
+ new Log4jConfigListener(),
+ new GrailsContextLoaderListener()
+ };
+
+ try
+ {
+ ServletContextEvent event = new ServletContextEvent(servletContext);
+ for (ServletContextListener l : servletContextListeners) {
+ l.contextInitialized(event);
+ // System.out.println("" + l + " ok");
+ // System.out.println("" + LOG);
+ // System.out.println("" + LOG.isErrorEnabled());
+ // System.out.println("" + LOG.isDebugEnabled());
+ // System.out.println("" + LOGGER.getLevel());
+ // LOG.error("BLA2");LOG.debug("BLA1");
+ // LOGGER.error("BLA1"); LOGGER.debug("BLA1");
+ }
+ } catch (RuntimeException e) {
+ LOG.error("init()", e);
+ throw e;
+ }
+
+ // No fixed context defined for this servlet - create a local one.
+ /*XmlWebApplicationContext parent = new XmlWebApplicationContext();
+ parent.setServletContext(servletContext);
+ //parent.setNamespace(getClass().getName() + ".CONTEXT.");
+ parent.refresh();*/
+ WebApplicationContext parent = WebApplicationContextUtils.getWebApplicationContext(servletContext);
+
+ WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
+ // construct the SpringConfig for the container managed application
+ //Assert.notNull(parent, "Grails requires a parent ApplicationContext, is the /WEB-INF/applicationContext.xml file missing?");
+ GrailsApplication application = parent.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
+
+ //WebApplicationContext webContext;
+ if (wac instanceof GrailsApplicationContext) {
+ webContext = wac;
+ }
+ else {
+ webContext = GrailsConfigUtils.configureWebApplicationContext(servletContext, parent);
+ // System.out.println("configureWebApplicationContext ok");
+
+ try {
+ GrailsConfigUtils.executeGrailsBootstraps(application, webContext, servletContext);
+ // System.out.println("executeGrailsBootstraps ok");
+ }
+ catch (Exception e) {
+ LOG.debug("init()", e);
+ GrailsUtil.deepSanitize(e);
+ if (e instanceof BeansException) {
+ throw (BeansException)e;
+ }
+
+ throw new BootstrapException("Error executing bootstraps", e);
+ }
+ }
+
+ /*
+ boolean x = true;
+ try {
+ while (x) {
+ // System.out.println(Bootstrap.class.getName() + ": " + Thread.currentThread() + " " + new java.util.Date());
+ Thread.sleep(10000);
+ }
+ } catch (Exception e) {
+ }*/
+
+ // System.out.println("+++++++++++++++++++ " + Thread.currentThread().getContextClassLoader());
+ // System.out.println("+++++++++++++++++++ " + this.getClass().getClassLoader());
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("init(): thread classLoader " + Thread.currentThread().getContextClassLoader());
+ }
+
+
+ /*GrailsPluginManager pm = PluginManagerHolder.getPluginManager();
+ if (pm instanceof DefaultGrailsPluginManager) {
+ ((DefaultGrailsPluginManager) pm).startPluginChangeScanner();
+ }*/
+
+ /*if (1 == 1) {
+ throw new Error("abc");
+ }*/
+ LOG.debug("init(): end");
+ }
+
+ public void destroy() {
+ LOG.debug("destroy(): begin");
+ /*GrailsPluginManager pm = PluginManagerHolder.getPluginManager();
+ if (pm instanceof DefaultGrailsPluginManager) {
+ ((DefaultGrailsPluginManager) pm).stopPluginChangeScanner();
+ }*/
+
+ GrailsApplication grailsApplication = webContext.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
+
+ GrailsClass[] bootstraps = grailsApplication.getArtefacts(BootstrapArtefactHandler.TYPE);
+ for (GrailsClass bootstrap : bootstraps) {
+ ((GrailsBootstrapClass) bootstrap).callDestroy();
+ }
+
+
+ {
+ ServletContextEvent event = new ServletContextEvent(servletContext);
+ for (ServletContextListener l : servletContextListeners) {
+ l.contextDestroyed(event);
+ }
+ }
+
+ servletContext = null;
+
+ LOG.debug("destroy(): end");
+ }
+
+
+ public static void main(String [] args) {
+ // System.out.println(Bootstrap.class.getName()+ ".main() - begin " + new java.util.Date());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("main(): begin " + Bootstrap.class.getName()+ " - " + new java.util.Date());
+ }
+
+ Bootstrap r = new Bootstrap();
+ r.init(args);
+ r.destroy();
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("main(): end " + Bootstrap.class.getName()+ " - " + new java.util.Date());
+ }
+
+ // System.out.println(Bootstrap.class.getName()+ ".main() - end " + new java.util.Date());
+ }
+}
2  src/templates/batch/batch-launcher.bat
View
@@ -1 +1 @@
-java -cp .;@classesDirName@;@bootstrapJarName@ -jar @bootstrapJarName@
+java -cp .;@classesDirName@;@bootstrapJarName@;@windowsLibClasspath@ -jar @bootstrapJarName@ %*
2  src/templates/batch/batch-launcher.sh
View
@@ -1,2 +1,2 @@
#!/bin/sh
-java -cp .:@classesDirName@:@bootstrapJarName@ -jar @bootstrapJarName@
+java -cp .:@classesDirName@:@bootstrapJarName@:@linuxLibClasspath@ -jar @bootstrapJarName@ $*
Please sign in to comment.
Something went wrong with that request. Please try again.