Permalink
Browse files

moved code from Grails core

  • Loading branch information...
burtbeckwith committed Mar 17, 2013
1 parent d9c2d0d commit c230f3829f7d269b84d6875e4a58c2e5366933f8
View
@@ -1,21 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry kind="src" path="src/groovy"/>
+ <classpathentry kind="src" path="src/java"/>
<classpathentry kind="src" path="grails-app/conf"/>
+ <classpathentry kind="src" path="scripts"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
- <classpathentry kind="src" path=".link_to_grails_plugins/release-2.0.4/src/groovy">
+ <classpathentry kind="src" path=".link_to_grails_plugins/release-2.2.1/src/groovy">
<attributes>
- <attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
+ <attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
- <classpathentry kind="src" path=".link_to_grails_plugins/release-2.0.4/src/java">
+ <classpathentry kind="src" path=".link_to_grails_plugins/release-2.2.1/src/java">
<attributes>
- <attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
+ <attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
- <classpathentry kind="src" path=".link_to_grails_plugins/rest-client-builder-1.0.2/src/groovy">
+ <classpathentry kind="src" path=".link_to_grails_plugins/rest-client-builder-1.0.3/src/groovy">
<attributes>
- <attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
+ <attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.grails.ide.eclipse.core.CLASSPATH_CONTAINER"/>
@@ -1,4 +1,4 @@
-/* Copyright 2004-2012 SpringSource.
+/* Copyright 2004-2013 SpringSource.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,15 +13,14 @@
* limitations under the License.
*/
class TomcatGrailsPlugin {
- def version = "2.3.0.BUILD-SNAPSHOT"
+ def version = "7.0.37.BUILD-SNAPSHOT"
def grailsVersion = "2.3 > *"
def scopes = [excludes: 'war']
def author = "Graeme Rocher"
def authorEmail = "graeme.rocher@springsource.com"
def title = "Apache Tomcat plugin for Grails"
def description = 'Makes Tomcat 7.0 the default servlet container for Grails at development time.'
def documentation = "http://grails.org/plugin/tomcat"
-
def license = 'APACHE'
def organization = [name: 'SpringSource', url: 'http://www.springsource.org/']
def issueManagement = [system: 'JIRA', url: 'http://jira.grails.org/browse/GPTOMCAT']
View
@@ -1,3 +1 @@
app.grails.version=2.3.0.BUILD-SNAPSHOT
-app.name=tomcat
-
View
No changes.
@@ -1,17 +1,21 @@
-tomcatVersion = "7.0.37"
-
grails.project.work.dir = 'target'
grails.project.dependency.resolution = {
- inherits "global"
+ inherits "global", {
+ // TODO remove
+ excludes 'grails-plugin-tomcat', 'grails-tomcat'
+ }
log "warn"
repositories {
grailsCentral()
}
dependencies {
+
+ String tomcatVersion = "7.0.37"
+
runtime("org.apache.tomcat:tomcat-catalina-ant:$tomcatVersion") {
excludes 'tomcat-catalina', 'tomcat-coyote'
}
@@ -20,19 +24,18 @@ grails.project.dependency.resolution = {
runtime "org.apache.tomcat.embed:tomcat-embed-logging-log4j:$tomcatVersion"
runtime "org.apache.tomcat.embed:tomcat-embed-logging-juli:$tomcatVersion"
- // needed for JSP compilation
- runtime "org.eclipse.jdt.core.compiler:ecj:3.7.2"
-
+ // needed for JSP compilation
+ runtime "org.eclipse.jdt.core.compiler:ecj:3.7.2"
+
compile("org.grails:grails-plugin-tomcat:$grailsVersion") {
excludes group: "org.grails", name: "grails-core"
excludes group: "org.grails", name: "grails-bootstrap"
excludes group: "org.grails", name: "grails-web"
-
}
}
plugins {
- build(':release:2.2.0', ':rest-client-builder:1.0.2') {
+ build(':release:2.2.1', ':rest-client-builder:1.0.3') {
export = false
}
}
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * 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.
+ */
+package org.grails.plugins.tomcat
+
+import grails.util.Holders
+
+import static grails.build.logging.GrailsConsole.instance as CONSOLE
+import grails.util.Environment
+import grails.util.GrailsNameUtils
+
+import org.apache.catalina.Context
+import org.apache.catalina.Loader
+import org.apache.catalina.connector.Connector
+import org.apache.catalina.startup.Tomcat
+import org.apache.coyote.http11.Http11NioProtocol
+import org.apache.tomcat.util.scan.StandardJarScanner
+import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
+import org.grails.plugins.tomcat.fork.ForkedTomcatServer
+
+/**
+ * Serves the app, without packaging as a war and runs it in the same JVM.
+ */
+class InlineExplodedTomcatServer extends TomcatServer {
+
+ final Tomcat tomcat = new Tomcat()
+
+ Context context
+
+ InlineExplodedTomcatServer(String basedir, String webXml, String contextPath, ClassLoader classLoader) {
+
+ if (contextPath == '/') {
+ contextPath = ''
+ }
+
+ tomcat.setBaseDir(tomcatDir.absolutePath)
+ context = tomcat.addWebapp(contextPath, basedir)
+ boolean shouldScan = checkAndInitializingClasspathScanning()
+
+ def jarScanner = new StandardJarScanner()
+ jarScanner.setScanClassPath(shouldScan)
+ context.setJarScanner(jarScanner)
+
+ tomcat.enableNaming()
+
+ // we handle reloading manually
+ context.reloadable = false
+ context.setAltDDName(getWorkDirFile("resources/web.xml").absolutePath)
+
+ configureAliases(context)
+
+ def loader = createTomcatLoader(classLoader)
+ loader.container = context
+ context.loader = loader
+ initialize(tomcat)
+ }
+
+ protected void initialize(Tomcat tomcat) {
+ // do nothing, for subclasses to override
+ }
+
+ protected void configureAliases(Context context) {
+ def aliases = []
+ def pluginManager = Holders.getPluginManager()
+
+ if (pluginManager != null) {
+ for (plugin in pluginManager.userPlugins) {
+ def dir = pluginSettings.getPluginDirForName(GrailsNameUtils.getScriptName(plugin.name))
+ def webappDir = dir ? new File("${dir.file.absolutePath}/web-app") : null
+ if (webappDir?.exists()) {
+ aliases << "/plugins/${plugin.fileSystemName}=${webappDir.absolutePath}"
+ }
+ }
+ }
+
+ if (aliases) {
+ context.setAliases(aliases.join(','))
+ }
+ }
+
+ protected Loader createTomcatLoader(ClassLoader classLoader) {
+ new TomcatLoader(classLoader)
+ }
+
+ void doStart(String host, int httpPort, int httpsPort) {
+ preStart()
+
+ if (host != "localhost") {
+ tomcat.connector.setAttribute("address", host)
+ tomcat.connector.setAttribute("port", httpPort)
+ }
+
+ if (getConfigParam("nio")) {
+ CONSOLE.updateStatus "Enabling Tomcat NIO connector"
+ def connector = new Connector(Http11NioProtocol.name)
+ connector.port = httpPort
+ tomcat.service.addConnector(connector)
+ tomcat.connector = connector
+ }
+
+ tomcat.port = httpPort
+ tomcat.connector.URIEncoding = 'UTF-8'
+
+ if (httpsPort) {
+ def sslConnector = loadInstance('org.apache.catalina.connector.Connector')
+ sslConnector.scheme = "https"
+ sslConnector.secure = true
+ sslConnector.port = httpsPort
+ sslConnector.setProperty("SSLEnabled", "true")
+ sslConnector.setAttribute("keystoreFile", keystoreFile.absolutePath)
+ sslConnector.setAttribute("keystorePass", keyPassword)
+ sslConnector.URIEncoding = 'UTF-8'
+
+ if (host != "localhost") {
+ sslConnector.setAttribute("address", host)
+ }
+
+ if (truststoreFile.exists()) {
+ CONSOLE.addStatus "Using truststore $truststore"
+ sslConnector.setAttribute("truststoreFile", truststore)
+ sslConnector.setAttribute("truststorePass", trustPassword)
+ sslConnector.setAttribute("clientAuth", getConfigParam("clientAuth") ?: "want")
+ }
+
+ tomcat.service.addConnector(sslConnector)
+ }
+
+ if (Environment.isFork()) {
+ ForkedTomcatServer.startKillSwitch(tomcat, httpPort)
+ }
+ tomcat.start()
+
+ }
+
+ void stop() {
+ tomcat.stop()
+ tomcat.destroy()
+ GrailsPluginUtils.clearCaches()
+ }
+
+ private loadInstance(String name) {
+ tomcat.class.classLoader.loadClass(name).newInstance()
+ }
+
+ private preStart() {
+ eventListener?.triggerEvent("ConfigureTomcat", tomcat)
+ def jndiEntries = grailsConfig?.grails?.naming?.entries
+
+ if (!(jndiEntries instanceof Map)) {
+ return
+ }
+
+ System.setProperty("javax.sql.DataSource.Factory", "org.apache.commons.dbcp.BasicDataSourceFactory")
+
+ jndiEntries.each { name, resCfg ->
+ if (resCfg) {
+ if (!resCfg["type"]) {
+ throw new IllegalArgumentException("Must supply a resource type for JNDI configuration")
+ }
+ def res = loadInstance('org.apache.catalina.deploy.ContextResource')
+ res.name = name
+ res.type = resCfg.remove("type")
+ res.auth = resCfg.remove("auth")
+ res.description = resCfg.remove("description")
+ res.scope = resCfg.remove("scope")
+ // now it's only the custom properties left in the Map...
+ resCfg.each { key, value ->
+ res.setProperty(key, value)
+ }
+
+ context.namingResources.addResource res
+ }
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit c230f38

Please sign in to comment.