Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial cut of forked compilation, currently only for sources not tes…
…t sources. Deactivated by default
- Loading branch information
1 parent
274c6b7
commit d9d9a1d
Showing
8 changed files
with
239 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...trap/src/main/groovy/org/codehaus/groovy/grails/cli/fork/ForkedGrailsProcessConfig.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,65 @@ | |||
/* | |||
* Copyright 2012 SpringSource | |||
* | |||
* 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.codehaus.groovy.grails.cli.fork | |||
|
|||
import groovy.transform.CompileStatic | |||
|
|||
/** | |||
* Configuration for a forked process | |||
* | |||
* @author Graeme Rocher | |||
* @since 2.3 | |||
*/ | |||
@CompileStatic | |||
class ForkedGrailsProcessConfig { | |||
|
|||
ForkedGrailsProcessConfig(config) { | |||
if (config instanceof Map<String, Object>) { | |||
this.forked = true | |||
def map = (Map<String, Object>)config | |||
|
|||
if (map.maxMemory) { | |||
maxMemory = map.maxMemory.toString().toInteger() | |||
} | |||
if (map.minMemory) { | |||
minMemory = map.minMemory.toString().toInteger() | |||
} | |||
if (map.maxPerm) { | |||
maxPerm = map.maxPerm.toString().toInteger() | |||
} | |||
if (map.debug) { | |||
debug = true | |||
} | |||
|
|||
} | |||
else if (config) { | |||
this.forked = true | |||
} | |||
} | |||
|
|||
ForkedGrailsProcessConfig() { | |||
} | |||
|
|||
Integer maxMemory = 512 | |||
Integer minMemory = 64 | |||
boolean debug = false | |||
Integer maxPerm = 256 | |||
boolean forked = false | |||
|
|||
Map asMap() { | |||
[maxMemory:maxMemory, minMemory:minMemory, debug:debug, maxPerm:maxPerm] | |||
} | |||
} |
72 changes: 72 additions & 0 deletions
72
...c/main/groovy/org/codehaus/groovy/grails/cli/fork/ForkedGrailsProjectClassExecutor.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,72 @@ | |||
/* | |||
* Copyright 2012 SpringSource | |||
* | |||
* 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.codehaus.groovy.grails.cli.fork | |||
|
|||
import grails.util.BuildSettings | |||
import groovy.transform.CompileStatic | |||
|
|||
/** | |||
* Base class that deals with the setup logic needed in order to run a Grails build system component (GrailsProjectCompiler, GrailsProjectLoader, GrailsProjectRunner etc.) in a forked process | |||
* | |||
* @author Graeme Rocher | |||
* @since 2.3 | |||
*/ | |||
@CompileStatic | |||
abstract class ForkedGrailsProjectClassExecutor extends ForkedGrailsProcess{ | |||
ExecutionContext executionContext | |||
|
|||
ForkedGrailsProjectClassExecutor(BuildSettings buildSettings) { | |||
executionContext = new ExecutionContext() | |||
executionContext.initialize(buildSettings) | |||
} | |||
|
|||
|
|||
protected ForkedGrailsProjectClassExecutor() { | |||
executionContext = readExecutionContext() | |||
if (executionContext == null) { | |||
throw new IllegalStateException("Forked process created without first creating execution context and calling fork()") | |||
} | |||
} | |||
|
|||
|
|||
protected final void run() { | |||
ExecutionContext ec = executionContext | |||
BuildSettings buildSettings = initializeBuildSettings(ec) | |||
URLClassLoader classLoader = initializeClassLoader(buildSettings) | |||
initializeLogging(ec.grailsHome,classLoader) | |||
Thread.currentThread().setContextClassLoader(classLoader) | |||
|
|||
final projectComponentClass = classLoader.loadClass(getProjectClassType()) | |||
final projectClassInstance = createInstance(projectComponentClass, buildSettings) | |||
|
|||
runInstance(projectClassInstance) | |||
} | |||
|
|||
protected Object createInstance(Class projectComponentClass, BuildSettings buildSettings) { | |||
projectComponentClass.newInstance(buildSettings) | |||
} | |||
|
|||
protected abstract String getProjectClassType() | |||
|
|||
abstract void runInstance(def instance) | |||
|
|||
@Override | |||
ExecutionContext createExecutionContext() { | |||
return executionContext | |||
} | |||
|
|||
|
|||
} |
66 changes: 66 additions & 0 deletions
66
...p/src/main/groovy/org/codehaus/groovy/grails/cli/fork/compile/ForkedGrailsCompiler.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,66 @@ | |||
/* | |||
* Copyright 2012 SpringSource | |||
* | |||
* 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.codehaus.groovy.grails.cli.fork.compile | |||
|
|||
import grails.build.logging.GrailsConsole | |||
import grails.util.BuildSettings | |||
import org.codehaus.groovy.grails.cli.fork.ForkedGrailsProjectClassExecutor | |||
import org.codehaus.groovy.grails.plugins.GrailsPluginUtils | |||
|
|||
/** | |||
* Forked implementation of Grails project compiler | |||
* | |||
* @author Graeme Rocher | |||
* @since 2.3 | |||
*/ | |||
class ForkedGrailsCompiler extends ForkedGrailsProjectClassExecutor{ | |||
|
|||
ForkedGrailsCompiler(BuildSettings buildSettings) { | |||
super(buildSettings) | |||
this.reloading = false | |||
} | |||
|
|||
protected ForkedGrailsCompiler() { | |||
} | |||
|
|||
static void main(String[] args) { | |||
try { | |||
new ForkedGrailsCompiler().run() | |||
System.exit(0) | |||
} catch (Throwable e) { | |||
GrailsConsole.getInstance().error("Error running forked compilation: " + e.getMessage(), e) | |||
System.exit(1) | |||
} | |||
|
|||
} | |||
|
|||
@Override | |||
protected String getProjectClassType() { | |||
return "org.codehaus.groovy.grails.compiler.GrailsProjectCompiler" | |||
} | |||
|
|||
@Override | |||
protected Object createInstance(Class projectComponentClass, BuildSettings buildSettings) { | |||
projectComponentClass.newInstance(GrailsPluginUtils.getPluginBuildSettings()) | |||
} | |||
|
|||
@Override | |||
void runInstance(instance) { | |||
((GroovyObject)instance).invokeMethod("configureClasspath", null) | |||
((GroovyObject)instance).invokeMethod("compileAll", null) | |||
} | |||
} | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters