Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2004-2023 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
*
* https://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.gsp.compiler
import java.util.concurrent.Callable
import java.util.concurrent.CompletionService
import java.util.concurrent.ExecutorCompletionService
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
import groovy.transform.CompileStatic
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.codehaus.groovy.control.CompilationUnit
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.Phases
import grails.config.ConfigMap
import org.grails.config.CodeGenConfig
import org.grails.gsp.GroovyPageMetaInfo
import org.grails.gsp.compiler.transform.GroovyPageInjectionOperation
import org.grails.taglib.encoder.OutputEncodingSettings
/**
* Used to compile GSP files into a specified target directory.
*
* @author Graeme Rocher
* @since 1.2
*/
@CompileStatic
class GroovyPageCompiler {
private static final Log LOG = LogFactory.getLog(GroovyPageCompiler)
private Map compileGSPRegistry = [:]
private final Object mutexObject = new Object()
File generatedGroovyPagesDirectory
File targetDir
CompilerConfiguration compilerConfig = new CompilerConfiguration()
GroovyPageInjectionOperation operation = new GroovyPageInjectionOperation()
GroovyClassLoader classLoader = new GroovyClassLoader(Thread.currentThread().contextClassLoader, compilerConfig)
List srcFiles = []
File viewsDir
String viewPrefix = '/'
String packagePrefix = 'default'
String encoding = 'UTF-8'
String expressionCodec = OutputEncodingSettings.getDefaultValue(OutputEncodingSettings.EXPRESSION_CODEC_NAME)
String[] configs = []
ConfigMap configMap
ExecutorService threadPool
void setCompilerConfig(CompilerConfiguration c) {
compilerConfig = c
classLoader = new GroovyClassLoader(Thread.currentThread().contextClassLoader, compilerConfig)
}
void setCleanCompilerConfig(CompilerConfiguration c) {
compilerConfig = c
classLoader = new GroovyClassLoader(System.classLoader, compilerConfig)
}
/**
* Compiles the given GSP pages and returns a Map of URI to classname mappings
*/
Map compile() {
if (srcFiles && targetDir && viewsDir) {
if (!generatedGroovyPagesDirectory) {
generatedGroovyPagesDirectory = new File(System.getProperty('java.io.tmpdir'), 'gspcompile')
generatedGroovyPagesDirectory.mkdirs()
}
if (configs) {
CodeGenConfig codeGenConfig = new CodeGenConfig()
codeGenConfig.classLoader = classLoader
configMap = codeGenConfig
for (path in configs) {
def f = new File(path)
if (f.exists()) {
if (f.name.endsWith('.yml')) {
codeGenConfig.loadYml(f)
}
else if (f.name.endsWith('.groovy')) {
codeGenConfig.loadGroovy(f)
}
}
}
}
compilerConfig.setTargetDirectory(targetDir)
compilerConfig.setSourceEncoding(encoding)
ExecutorService threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2)
CompletionService