Skip to content

Commit

Permalink
Preliminary support for InvokeDynamic builds
Browse files Browse the repository at this point in the history
   - activate indy support using -Pindy=true
   - indy jars are produced with the "indy" classifier
   - OSGI support is disabled if indy is activated
   - distribution is still unaware of indy
 Misc
    - ensure that all output build directories are named "target" (some were "target", some where "build")
  • Loading branch information
melix committed May 24, 2012
1 parent 6eaa05e commit 1dd2f13
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 54 deletions.
79 changes: 68 additions & 11 deletions build.gradle
@@ -1,12 +1,18 @@
apply plugin: 'groovy'
apply plugin: 'codenarc'
apply plugin: 'checkstyle'
apply from: "$projectDir/gradle/indy.gradle"

// TODO use antlr plugin
//apply plugin: 'antlr'

allprojects { p ->
apply plugin: 'java'

buildDir = 'target'
sourceCompatibility = 1.5
targetCompatibility = 1.5

group = 'org.codehaus.groovy'
version = groovyVersion
// tasks.withType(Checkstyle).all { t -> t.ignoreFailures = true }
Expand All @@ -18,10 +24,6 @@ allprojects { p ->
compile.transitive = true
testCompile.transitive = true
}
// TODO why doesn't this work?
// test {
// excludes = ['**/*TestCase.class', '**/*$*.class']
// }

// todo: when we get rid of the Ant build, it will be much cleaner to use
// the conventional "resources" directory for classpath resources
Expand All @@ -46,11 +48,52 @@ allprojects { p ->
from sourceSets.main.allSource
}

apply plugin: 'java'
apply plugin: 'checkstyle'
apply plugin: 'groovy'
apply plugin: 'codenarc'
apply from: "${project(':').projectDir}/gradle/groovydoc.gradle"
apply from: "${project(':').projectDir}/gradle/indy.gradle"

if (useIndy()) {
def indyGroovy = {
options.useAnt = true
// todo: when Gradle includes support for "indy" option, replace this
// with groovyOptions.indy = true
groovyOptions.metaClass.optionMap = {
['indy':true,
memoryMaximumSize:'384m',
fork:true,
includeJavaRuntime:false,
verbose:false,
encoding:'UTF-8',
failonerror:true,
stacktrace:false,
listfiles:false]
}
groovyOptions.useAnt = true
sourceCompatibility = 1.7
targetCompatibility = 1.7
groovyClasspath = files(
project(':').compileJava.destinationDir,
project(':').compileJava.classpath,
{ project(':subprojects:groovy-docgenerator').compileJava.destinationDir },
{ project(':subprojects:groovy-groovydoc').compileJava.destinationDir },
{ project(':subprojects:groovy-ant').compileJava.destinationDir },
{ project(':subprojects:groovy-templates').compileJava.destinationDir },
)
}
// add tasks to compile the invokedynamic version

compileGroovy indyGroovy.clone()
compileTestGroovy indyGroovy.clone()

compileJava.sourceCompatibility = 1.7
compileJava.targetCompatibility = 1.7
jar {
classifier = 'indy'
}
}

}

// don't fail build on CodeNarc tasks
Expand All @@ -63,11 +106,6 @@ tasks.withType(Checkstyle).all { checkstyleTask ->
checkstyleTask.configFile = file("./config/checkstyle/checkstyle.xml")
}

sourceCompatibility = 1.5
targetCompatibility = 1.5

buildDir = 'target'

repositories {
// todo Some repos are needed only for some configs. Declare them just for the configuration once Gradle allows this.
// mavenCentral() // default, tools
Expand Down Expand Up @@ -207,6 +245,11 @@ sourceSets {
"$projectDir/subprojects/groovy-xml/src/main",
"$projectDir/subprojects/groovy-jmx/src/main",
]
if (!useIndy()) {
exclude '**/indy/*'
exclude '**/v7/*'
exclude '**/vm7/*'
}
}
}
main {
Expand All @@ -221,6 +264,11 @@ sourceSets {
}.visit {details ->
exclude "groovy/ui/$details.path"
}
if (!useIndy()) {
exclude '**/indy/*'
exclude '**/v7/*'
exclude '**/vm7/*'
}
}
groovy {
srcDirs = [
Expand Down Expand Up @@ -341,6 +389,11 @@ compileJava {
}

compileGroovy {
doFirst {
if (useIndy()) {
logger.info('Building with InvokeDynamic support activated')
}
}
groovyOptions.fork(memoryMaximumSize: groovycMain_mx)
}

Expand Down Expand Up @@ -379,4 +432,8 @@ task wrapper(type: Wrapper) {
}

// Define a GroovyDoc task which depends on the generated groovydoc tool
apply from: "$projectDir/gradle/groovydoc.gradle"
apply from: "$projectDir/gradle/groovydoc.gradle"

class MyGroovyOptions extends org.gradle.api.tasks.compile.GroovyCompileOptions {
boolean indy = true
}
17 changes: 17 additions & 0 deletions buildSrc/build.gradle
@@ -0,0 +1,17 @@
/*
* Copyright 2008-2012 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.
*/

buildDir = 'target'
68 changes: 40 additions & 28 deletions gradle/assemble.gradle
@@ -1,7 +1,9 @@
import org.apache.tools.ant.filters.ReplaceTokens
import java.text.SimpleDateFormat

apply plugin: 'osgi'
if (!rootProject.useIndy()) {
apply plugin: 'osgi'
}

group = 'org.codehaus.groovy'
archivesBaseName = 'groovy'
Expand Down Expand Up @@ -45,19 +47,23 @@ task copy(type: Copy) {
with licenseSpec
}

def commonOsgiManifest = {
// We exclude the Bnd-LastModified attribute as it always triggers a rebuild without being really needed.
from(allManifest) {
eachEntry {details ->
if (details.key == 'Bnd-LastModified') {
details.exclude()
def commonOsgiManifest

if (!rootProject.useIndy()) {
commonOsgiManifest = {
// We exclude the Bnd-LastModified attribute as it always triggers a rebuild without being really needed.
from(allManifest) {
eachEntry {details ->
if (details.key == 'Bnd-LastModified') {
details.exclude()
}
}
}
version = groovyBundleVersion
instruction '-nouses', 'true'
instruction 'Export-Package', "*;version=${version}"
classpath = sourceSets.main.runtimeClasspath
}
version = groovyBundleVersion
instruction '-nouses', 'true'
instruction 'Export-Package', "*;version=${version}"
classpath = sourceSets.main.runtimeClasspath
}

jar {
Expand All @@ -76,12 +82,14 @@ jar {
}
}
}
manifest = osgiManifest {
symbolicName = 'groovy'
instruction 'Import-Package', "antlr", "org.objectweb.asm", "*;resolution:=optional"
classesDir = sourceSets.main.output.classesDir
if (!rootProject.useIndy()) {
manifest = osgiManifest {
symbolicName = 'groovy'
instruction 'Import-Package', "antlr", "org.objectweb.asm", "*;resolution:=optional"
classesDir = sourceSets.main.output.classesDir
}
manifest commonOsgiManifest
}
manifest commonOsgiManifest
exclude '**/package-info.class', 'compiler', 'META-INF/groovy-release-info.properties'
}

Expand Down Expand Up @@ -125,6 +133,9 @@ def mergeModuleDescriptors() {
task jarAll(type: Jar, dependsOn: { modules()*.jar }) {
ext.metaInfDir = "$buildDir/tmp/groovy-all-metainf"
appendix = 'all'
if (rootProject.useIndy()) {
classifier = 'indy'
}
doLast {
manifest.writeTo("$metaInfDir/MANIFEST.MF")
copy {
Expand Down Expand Up @@ -156,16 +167,15 @@ task jarAll(type: Jar, dependsOn: { modules()*.jar }) {
}
}
}
// We exclude the Bnd-LastModified attribute as it always triggers a rebuild without being really needed.
manifest = osgiManifest {
symbolicName = 'groovy-all'
instruction 'Import-Package', "*;resolution:=optional"
classesDir = jar.archivePath
if (!rootProject.useIndy()) {
// We exclude the Bnd-LastModified attribute as it always triggers a rebuild without being really needed.
manifest = osgiManifest {
symbolicName = 'groovy-all'
instruction 'Import-Package', "*;resolution:=optional"
classesDir = jar.archivePath
}
manifest commonOsgiManifest
}
manifest commonOsgiManifest

// TODO: scan the various org.codehaus.groovy.runtime.ExtensionModule extension module descriptors
// and replace them with a single descriptor find which will be bundled into the groovy-all jar
}

task sourceAllJar(type: Jar, dependsOn: { modules()*.sourceJar }) {
Expand All @@ -174,18 +184,18 @@ task sourceAllJar(type: Jar, dependsOn: { modules()*.sourceJar }) {
with it.rootSpec
}
appendix = 'all'
classifier = 'sources'
classifier = rootProject.useIndy()?'indy-sources':'sources'
//with sourceJar.rootSpec
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
classifier = rootProject.useIndy()?'indy-javadoc':'javadoc'
from javadoc.destinationDir
}

task javadocAllJar(type: Jar, dependsOn: javadocJar) {
appendix = 'all'
classifier = 'javadoc'
classifier = rootProject.useIndy()?'indy-javadoc':'javadoc'
with javadocJar.rootSpec
}

Expand Down Expand Up @@ -258,3 +268,5 @@ task distSrc(type: Zip, dependsOn: [javadoc, groovydoc, docGDK]) {
'cobertura.ser', 'junitvmwatcher*.properties'
}
}

//task
31 changes: 31 additions & 0 deletions gradle/indy.gradle
@@ -0,0 +1,31 @@
/*
* Copyright 2008-2012 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.
*/

// This file contains support tools for the Gradle build
// with regards to invoke dynamic support (indy)

project(':').ext.useIndy = {
boolean indy = false

// first, check if a system property activates indy support
indy |= System.hasProperty('indy') && Boolean.valueOf(System.getProperty('indy'))

// ultimately, check if the main project has an extension property setting indy to true
// which is the case if the build is started with -Pindy=true or during install/dist tasks
indy |= project(':').hasProperty('indy') && (Boolean.valueOf(project(':').indy))

indy
}
8 changes: 3 additions & 5 deletions src/main/org/codehaus/groovy/tools/FileSystemCompiler.java
Expand Up @@ -17,6 +17,7 @@
package org.codehaus.groovy.tools;

import groovy.lang.GroovyResourceLoader;
import groovy.util.FileLog;
import org.apache.commons.cli.*;
import org.codehaus.groovy.control.CompilationUnit;
import org.codehaus.groovy.control.CompilerConfiguration;
Expand All @@ -25,10 +26,7 @@

import groovy.lang.GroovySystem;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
Expand Down Expand Up @@ -160,7 +158,7 @@ public static void commandLineCompile(String[] args, boolean lookupUnnamedFiles)
* @param args command line arguments
*/
public static void main(String[] args) {
commandLineCompileWithErrorHandling(args,true);
commandLineCompileWithErrorHandling(args, true);
}

/**
Expand Down
Expand Up @@ -17,6 +17,7 @@

import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyResourceLoader;
import groovy.util.FileLog;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;
Expand Down Expand Up @@ -1146,6 +1147,7 @@ private void loadRegisteredScriptExtensions() {
* @param useIndy the indy flag
*/
public void setIndy(boolean useIndy){
FileLog.log(useIndy, "/tmp/context.txt");
this.useIndy = useIndy;
}

Expand Down
Expand Up @@ -18,7 +18,7 @@
<project name="Test Groovyc Task" default="test1">

<property name="srcPath" value="."/>
<property name="destPath" value="${user.dir}/build/classes/test"/>
<property name="destPath" value="${user.dir}/target/classes/test"/>

<property name="javaVersion" value="5"/>

Expand Down
Expand Up @@ -17,6 +17,6 @@ package org.codehaus.groovy.ant

class GroovycTest1 {
static void main ( String[] args ) {
( new File ( 'build/classes/test/org/codehaus/groovy/ant/GroovycTest1_Result.txt' ) ).write ( 'OK.' )
( new File ( 'target/classes/test/org/codehaus/groovy/ant/GroovycTest1_Result.txt' ) ).write ( 'OK.' )
}
}
Expand Up @@ -21,7 +21,7 @@

class GroovycTest2 {
static void main(String[] args) throws IOException {
File f = new File("build/classes/test/org/codehaus/groovy/ant/GroovycTest2_Result.txt");
File f = new File("target/classes/test/org/codehaus/groovy/ant/GroovycTest2_Result.txt");
FileOutputStream fout = new FileOutputStream(f);
try {
fout.write("OK.".getBytes());
Expand Down

0 comments on commit 1dd2f13

Please sign in to comment.