Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
Support JRebel (#26) and allow printing server logs to console (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
johndevs committed Mar 16, 2013
1 parent b524563 commit 7edad4d
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 26 deletions.
27 changes: 25 additions & 2 deletions src/main/groovy/fi/jasoft/plugin/TaskListener.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fi.jasoft.plugin;
package fi.jasoft.plugin

import groovy.xml.MarkupBuilder;
import org.gradle.api.execution.TaskExecutionListener
import org.gradle.api.Task
import org.gradle.api.tasks.TaskState
Expand Down Expand Up @@ -52,10 +53,14 @@ public class TaskListener implements TaskExecutionListener{
if(task.getName() == 'jar'){
configureAddonMetadata(task)
}

if (task.getName() == 'war'){
configureJRebel(task)
}
}

public void afterExecute(Task task, TaskState state){

}

private void configureEclipsePlugin(Task task){
Expand Down Expand Up @@ -125,4 +130,22 @@ public class TaskListener implements TaskExecutionListener{
'Implementation-Vendor': project.vaadin.addon.author,
)
}

private void configureJRebel(Task task){
def project = task.getProject()
def rebelFile = project.sourceSets.main.output.classesDir.absolutePath + '/rebel.xml'
def srcWebApp = project.webAppDir.absolutePath
def writer = new FileWriter(rebelFile)

new MarkupBuilder(writer).application() {
classpath{
dir( name:project.sourceSets.main.output.classesDir.absolutePath )
}
web{
link(target:'/'){
dir(name:srcWebApp)
}
}
}
}
}
10 changes: 9 additions & 1 deletion src/main/groovy/fi/jasoft/plugin/VaadinPluginExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class VaadinPluginExtension{
boolean manageDependencies = true
int serverPort = 8080
String[] jvmArgs = null

// GWT Compiler and DevMode
GWT gwt = new GWT()
class GWT{
Expand Down Expand Up @@ -55,6 +55,7 @@ class VaadinPluginExtension{
VaadinPluginConfiguration plugin = new VaadinPluginConfiguration()
class VaadinPluginConfiguration {
boolean terminateOnEnter = true
boolean logToConsole = false
}

// Metadata
Expand All @@ -64,4 +65,11 @@ class VaadinPluginExtension{
String license = ''
String title = ''
}

// Jrebel
JRebel jrebel = new JRebel()
class JRebel {
boolean enabled = false
String location
}
}
67 changes: 52 additions & 15 deletions src/main/groovy/fi/jasoft/plugin/tasks/DevModeTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,59 @@ class DevModeTask extends DefaultTask {
project.sourceSets.main.runtimeClasspath +
project.sourceSets.main.compileClasspath


File logDir = new File('build/jetty/')
logDir.mkdirs()

appServerProcess = ['java',
"-Xrunjdwp:transport=dt_socket,address=${project.vaadin.debugPort},server=y,suspend=n",
'-Xdebug',
'-cp', cp.getAsPath(),
'org.mortbay.jetty.runner.Runner',
'--port', project.vaadin.serverPort,
'--out', logDir.canonicalPath + '/jetty8-devmode.log',
'--log', logDir.canonicalPath + '/jetty8-devmode.log',
webAppDir.canonicalPath
].execute()

println "Application running on http://0.0.0.0:${project.vaadin.serverPort} (debugger on ${project.vaadin.debugPort})"
logDir.mkdirs()

def appServerProcess = ['java']

// Debug
appServerProcess.add('-Xdebug')
appServerProcess.add("-Xrunjdwp:transport=dt_socket,address=${project.vaadin.debugPort},server=y,suspend=n")

// Jrebel
if(project.vaadin.jrebel.enabled){
if(project.vaadin.jrebel.location != null && new File(project.vaadin.jrebel.location).exists()){
appServerProcess.add('-noverify')
appServerProcess.add("-javaagent:${project.vaadin.jrebel.location}")
} else {
println "Could not find jrebel.jar, aborting run."
return;
}
}

// JVM options
appServerProcess.add('-cp')
appServerProcess.add(cp.getAsPath())

if(project.vaadin.jvmArgs != null){
appServerProcess.addAll(project.vaadin.jvmArgs)
}

// Program args
appServerProcess.add('org.mortbay.jetty.runner.Runner')

appServerProcess.add('--port')
appServerProcess.add(project.vaadin.serverPort)

appServerProcess.add(webAppDir.canonicalPath)

print "Application running on http://0.0.0.0:${project.vaadin.serverPort} "

if(project.vaadin.jrebel.enabled){
println "(debugger on ${project.vaadin.debugPort}, JRebel active)"
} else {
println "(debugger on ${project.vaadin.debugPort})"
}

// Execute server
appServerProcess = appServerProcess.execute()

if(project.vaadin.plugin.logToConsole){
appServerProcess.consumeProcessOutput(System.out, System.out)
} else {
File log = new File(logDir.canonicalPath + '/jetty8-devMode.log')
appServerProcess.consumeProcessOutputStream(new FileOutputStream(log))
}
}

protected void terminateApplicationServer(){
Expand Down
41 changes: 33 additions & 8 deletions src/main/groovy/fi/jasoft/plugin/tasks/RunTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,19 @@ public class RunTask extends DefaultTask {
def appServerProcess = ['java']

// Debug
appServerProcess.add("-Xrunjdwp:transport=dt_socket,address=${project.vaadin.debugPort},server=y,suspend=n")
appServerProcess.add('-Xdebug')
appServerProcess.add("-Xrunjdwp:transport=dt_socket,address=${project.vaadin.debugPort},server=y,suspend=n")

// Jrebel
if(project.vaadin.jrebel.enabled){
if(project.vaadin.jrebel.location != null && new File(project.vaadin.jrebel.location).exists()){
appServerProcess.add('-noverify')
appServerProcess.add("-javaagent:${project.vaadin.jrebel.location}")
} else {
println "Could not find jrebel.jar, aborting run."
return;
}
}

// JVM options
appServerProcess.add('-cp')
Expand All @@ -61,20 +72,33 @@ public class RunTask extends DefaultTask {
appServerProcess.add('--port')
appServerProcess.add(project.vaadin.serverPort)

appServerProcess.add('--out')
appServerProcess.add(logDir.canonicalPath + '/jetty8-vaadinRun.log')
appServerProcess.add(webAppDir.canonicalPath)

appServerProcess.add('--log')
appServerProcess.add(logDir.canonicalPath + '/jetty8-vaadinRun.log')
print "Application running on http://0.0.0.0:${project.vaadin.serverPort} "

appServerProcess.add(webAppDir.canonicalPath)
if(project.vaadin.jrebel.enabled){
println "(debugger on ${project.vaadin.debugPort}, JRebel active)"
} else {
println "(debugger on ${project.vaadin.debugPort})"
}

if(project.vaadin.plugin.terminateOnEnter){
println "Press [Enter] to stop server...";
}

// Excecute server
appServerProcess = appServerProcess.execute()

println "Application running on http://0.0.0.0:${project.vaadin.serverPort} (debugger on ${project.vaadin.debugPort})"
if(project.vaadin.plugin.logToConsole){
appServerProcess.consumeProcessOutput(System.out, System.out)
} else {
File log = new File(logDir.canonicalPath + '/jetty8-vaadinRun.log')
appServerProcess.consumeProcessOutputStream(new FileOutputStream(log))
}

if(project.vaadin.plugin.terminateOnEnter){
Util.readLine("\nPress [Enter] to stop server...")
// Wait for enter
Util.readLine("")

// Terminate server
appServerProcess.in.close()
Expand All @@ -84,6 +108,7 @@ public class RunTask extends DefaultTask {
appServerProcess = null;

} else {
// Block
appServerProcess.waitFor()
}
}
Expand Down

0 comments on commit 7edad4d

Please sign in to comment.