Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Feature/add cacheSize config, fix tomcat log cache warning. #171

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ abstract class BaseTomcat8xPlusImpl extends BaseTomcat7xPlusImpl {
context.addServletContainerInitializer(jasperInitializer.newInstance(), null)
}


@Override
void addWebappResource(File resource) {
context.resources.createWebResourceSet(getResourceSetType('PRE'), '/WEB-INF/classes', resource.toURI().toURL(), '/')
Expand All @@ -31,4 +32,12 @@ abstract class BaseTomcat8xPlusImpl extends BaseTomcat7xPlusImpl {
Class resourceSetTypeClass = loadClass('org.apache.catalina.WebResourceRoot$ResourceSetType')
resourceSetTypeClass.enumConstants.find { it.name() == name }
}

void setResourcesCacheSize(int cacheSize) {
if (cacheSize > 0) {
context.resources.cacheMaxSize = cacheSize
} else if (cacheSize < 0) {
context.resources.cachingAllowed = false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class TomcatPlugin implements Plugin<Project> {
conventionMapping.map('ajpPort') { tomcatPluginExtension.ajpPort }
conventionMapping.map('ajpProtocol') { tomcatPluginExtension.ajpProtocol }
conventionMapping.map('users') { tomcatPluginExtension.users }
conventionMapping.map('cacheSize') { tomcatPluginExtension.cacheSize }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class TomcatPluginExtension {
String httpProtocol = DEFAULT_PROTOCOL_HANDLER
String httpsProtocol = DEFAULT_PROTOCOL_HANDLER
String ajpProtocol = DEFAULT_AJP_PROTOCOL_HANDLER
Integer cacheSize = 0
TomcatJasperConvention jasper = new TomcatJasperConvention()
List<TomcatUser> users = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.bmuschko.gradle.tomcat.internal.ssl.SSLKeyStoreImpl
import com.bmuschko.gradle.tomcat.internal.ssl.StoreType
import com.bmuschko.gradle.tomcat.internal.utils.ThreadContextClassLoader
import com.bmuschko.gradle.tomcat.internal.utils.TomcatThreadContextClassLoader
import org.codehaus.groovy.runtime.DefaultGroovyMethods
import org.gradle.api.GradleException
import org.gradle.api.InvalidUserDataException
import org.gradle.api.file.FileCollection
Expand Down Expand Up @@ -198,6 +199,14 @@ abstract class AbstractTomcatRun extends Tomcat {
@Input
String ajpProtocol = 'org.apache.coyote.ajp.AjpProtocol'

/**
* Add context resources cacheSize: 0 =unchange, lt 0 =disable caching, gt 0 =max size cache
*/
@Input
@Optional
Integer cacheSize = 0


/**
* The list of Tomcat users. Defaults to an empty list.
*/
Expand Down Expand Up @@ -308,6 +317,15 @@ abstract class AbstractTomcatRun extends Tomcat {
setWebApplicationContext()
server.createLoader(Thread.currentThread().contextClassLoader)

// FIX: large project cache warning in tomcat.
if (getCacheSize() != 0) { // only config cacheSize when cacheSize!=0
if(server.metaClass.respondsTo(server, "setResourcesCacheSize", getCacheSize())){
server.metaClass.invokeMethod(server,"setResourcesCacheSize", getCacheSize())
} else {
logger.warn("CacheSize setting only support tomcat 8+")
}
}

logger.info "Additional runtime resources classpath = ${getAdditionalRuntimeResources()}"

getAdditionalRuntimeResources().each { file ->
Expand Down