Skip to content

Commit

Permalink
- Split apart runtime and plugin classpaths.
Browse files Browse the repository at this point in the history
- Added DependencyHandler.gradleApi() to allow a dependency on the Gradle API to be declared.
- Replaced static BootstrapUtil with ClassPathRegistry and ClassLoaderFactory.
- Use groovy-all.jar to get rid of potential conflicts on asm, commons-cli and antlr.
  • Loading branch information
adammurdoch committed Jan 8, 2010
1 parent c85a633 commit 1448478
Show file tree
Hide file tree
Showing 61 changed files with 860 additions and 253 deletions.
26 changes: 22 additions & 4 deletions build.gradle
Expand Up @@ -50,7 +50,7 @@ libraries = [
commons_io : 'commons-io:commons-io:1.4@jar',
commons_lang : 'commons-lang:commons-lang:2.4@jar',
dom4j : 'dom4j:dom4j:1.6.1@jar',
groovy : 'org.codehaus.groovy:groovy:1.7.0@jar',
groovy : 'org.codehaus.groovy:groovy-all:1.7.0@jar',
ivy : 'org.apache.ivy:ivy:2.1.0@jar',
jaxen : 'jaxen:jaxen:1.1@jar',
jopt_simple : 'net.sf.jopt-simple:jopt-simple:3.2@jar',
Expand All @@ -63,8 +63,8 @@ libraries = [
junit : 'junit:junit:4.7'
]

libraries.groovy_depends = [libraries.groovy, libraries.ant, libraries.ant_launcher, libraries.asm_all,
libraries.antlr, libraries.commons_cli, libraries.ant_junit, libraries.junit]
libraries.groovy_depends = [libraries.groovy, libraries.ant, libraries.ant_launcher, libraries.commons_cli,
libraries.ant_junit, libraries.junit]
libraries.jetty_depends = ["org.mortbay.jetty:jetty:6.1.22@jar", "org.mortbay.jetty:jetty-util:6.1.22@jar",
"javax.servlet:servlet-api:2.5@jar"]

Expand Down Expand Up @@ -137,15 +137,22 @@ configurations {
runtime {
visible = false
}
plugins {
visible = false
}
testRuntime {
extendsFrom runtime
extendsFrom plugins
}
}

dependencies {
groovyProjects().each {
runtimeProjects().each {
runtime project(path: it.path)
}
pluginProjects().each {
plugins project(path: it.path)
}
}

evaluationDependsOn(':docs')
Expand Down Expand Up @@ -176,6 +183,9 @@ binDistImage = copySpec {
}
into('lib') {
from configurations.runtime
into('plugins') {
from configurations.plugins - configurations.runtime
}
}
}

Expand Down Expand Up @@ -353,6 +363,14 @@ def groovyProjects() {
subprojects.findAll { project -> project.name != 'docs' }
}

def runtimeProjects() {
groovyProjects() - pluginProjects()
}

def pluginProjects() {
['plugins', 'codeQuality', 'jetty', 'wrapper'].collect { project(it) }
}

class Version {
String versionNumber
Date buildTime
Expand Down
2 changes: 1 addition & 1 deletion subprojects/gradle-core/core.gradle
Expand Up @@ -103,7 +103,7 @@ def writeVersionProperties(File destination) {

test {
xmsSize = '128m'
xmxSize = '1100m'
xmxSize = '512m'
maxPermSize = '128m'

// there must be a nicer way of doing this...
Expand Down
Expand Up @@ -18,59 +18,67 @@ package org.gradle.integtests
import org.junit.Test
import static org.hamcrest.Matchers.*
import org.gradle.util.TestFile
import org.junit.runner.RunWith

@RunWith(DistributionIntegrationTestRunner.class)
class BuildAggregationIntegrationTest {
// Injected by test runner
private GradleDistribution dist;
private GradleExecuter executer;

class BuildAggregationIntegrationTest extends AbstractIntegrationTest {
@Test
public void canExecuteAnotherBuildFromBuild() {
testFile('build.gradle') << '''
assertThat(gradle.parent, nullValue())
dist.testFile('build.gradle') << '''
assert gradle.parent == null
task build(type: GradleBuild) {
dir = 'other'
tasks = ['dostuff']
startParameter.searchUpwards = false
}
'''

testFile('other/build.gradle') << '''
assertThat(gradle.parent, notNullValue())
dist.testFile('other/build.gradle') << '''
assert gradle.parent != null
task dostuff << {
assertThat(gradle.parent, notNullValue())
assert gradle.parent != null
}
'''

inTestDirectory().withTasks('build').run()
executer.withTasks('build').run()
}

@Test
public void treatsBuildSrcProjectAsANestedBuild() {
testFile('build.gradle') << '''
assertThat(gradle.parent, nullValue())
dist.testFile('build.gradle') << '''
assert gradle.parent == null
task build
'''

testFile('buildSrc/build.gradle') << '''
dist.testFile('buildSrc/build.gradle') << '''
apply id: 'java'
assertThat(gradle.parent, notNullValue())
assert gradle.parent != null
classes << {
assertThat(gradle.parent, notNullValue())
assert gradle.parent != null
}
'''

inTestDirectory().withTasks('build').run()
executer.withTasks('build').run()
}

@Test
public void reportsNestedBuildFailure() {
TestFile other = testFile('other.gradle') << '''
TestFile other = dist.testFile('other.gradle') << '''
1/0
'''

testFile('build.gradle') << '''
dist.testFile('build.gradle') << '''
task build(type: GradleBuild) {
buildFile = 'other.gradle'
startParameter.searchUpwards = false
}
'''

ExecutionFailure failure = inTestDirectory().withTasks('build').runWithFailure()
ExecutionFailure failure = executer.withTasks('build').runWithFailure()
failure.assertHasFileName("Build file '${other}'")
failure.assertHasLineNumber(2)
failure.assertHasDescription('A problem occurred evaluating root project')
Expand All @@ -79,11 +87,9 @@ class BuildAggregationIntegrationTest extends AbstractIntegrationTest {

@Test
public void reportsBuildSrcFailure() {
testFile('buildSrc/src/main/java/Broken.java') << 'broken!'
ExecutionFailure failure = inTestDirectory().runWithFailure()
dist.testFile('buildSrc/src/main/java/Broken.java') << 'broken!'
ExecutionFailure failure = executer.runWithFailure()
failure.assertHasFileName('Default buildSrc build script')
failure.assertHasDescription('Execution failed for task \':compileJava\'')
}
}


Expand Up @@ -53,7 +53,7 @@ apply id: 'code-quality'
testFile('build.gradle') << '''
apply id: 'groovy'
apply id: 'code-quality'
dependencies { groovy files(org.gradle.util.BootstrapUtil.gradleClasspath) }
dependencies { groovy localGroovy() }
'''
writeCheckstyleConfig()

Expand Down Expand Up @@ -111,7 +111,7 @@ apply id: 'code-quality'
testFile('build.gradle') << '''
apply id: 'groovy'
apply id: 'code-quality'
dependencies { groovy files(org.gradle.util.BootstrapUtil.gradleClasspath) }
dependencies { groovy localGroovy() }
'''
writeCodeNarcConfigFile()

Expand Down Expand Up @@ -146,7 +146,7 @@ apply id: 'code-quality'
testFile('build.gradle') << '''
apply id: 'groovy'
apply id: 'code-quality'
dependencies { groovy files(org.gradle.util.BootstrapUtil.gradleClasspath) }
dependencies { groovy localGroovy() }
'''

writeCodeNarcConfigFile()
Expand Down
Expand Up @@ -86,8 +86,11 @@ class DistributionIntegrationTest {
contentsDir.file("lib/gradle-core-${version}.jar").assertIsFile()
contentsDir.file("lib/gradle-ui-${version}.jar").assertIsFile()
contentsDir.file("lib/gradle-launcher-${version}.jar").assertIsFile()
contentsDir.file("lib/gradle-jetty-${version}.jar").assertIsFile()
contentsDir.file("lib/gradle-wrapper-${version}.jar").assertIsFile()
contentsDir.file("lib/plugins/gradle-code-quality-${version}.jar").assertIsFile()
contentsDir.file("lib/plugins/gradle-plugins-${version}.jar").assertIsFile()
contentsDir.file("lib/plugins/gradle-jetty-${version}.jar").assertIsFile()
contentsDir.file("lib/plugins/gradle-wrapper-${version}.jar").assertIsFile()
contentsDir.file("lib/plugins/gradle-wrapper-tasks-${version}.jar").assertIsFile()

// Docs
contentsDir.file('getting-started.html').assertIsFile()
Expand Down
Expand Up @@ -106,6 +106,7 @@ Map executeInternal(String windowsCommandSnippet, String unixCommandSnippet, boo
builder.errorOutput(errStream);
builder.environment("GRADLE_HOME", "");
builder.environment("JAVA_HOME", System.getProperty("java.home"));
builder.environment("GRADLE_OPTS", "-ea");
builder.environment(environmentVars);
builder.execDirectory(getWorkingDir());

Expand Down Expand Up @@ -177,15 +178,15 @@ public ForkedExecutionFailure(Map result) {
}

public void assertHasLineNumber(int lineNumber) {
throw new UnsupportedOperationException();
assertThat(getError(), containsString(String.format(" line: %d", lineNumber)));
}

public void assertHasFileName(String filename) {
assertThat(getError(), containsLine(startsWith(filename)));
}

public void assertHasCause(String description) {
assertThatCause(equalTo(description));
assertThatCause(startsWith(description));
}

public void assertThatCause(final Matcher<String> matcher) {
Expand All @@ -203,7 +204,7 @@ public void describeTo(Description description) {
}

public void assertHasDescription(String context) {
assertThatDescription(equalTo(context));
assertThatDescription(startsWith(context));
}

public void assertThatDescription(Matcher<String> matcher) {
Expand Down
Expand Up @@ -38,7 +38,7 @@ assertNotNull(gradle)
assertSame(initscript.classLoader, getClass().classLoader.parent)
assertSame(initscript.classLoader, Thread.currentThread().contextClassLoader)
assertSame(scriptClassLoader, initscript.classLoader.parent)
assertSame(Gradle.class.classLoader, scriptClassLoader.parent)
assertSame(Gradle.class.classLoader, scriptClassLoader.parent.parent)
'''
testFile('build.gradle') << 'task doStuff'

Expand Down
Expand Up @@ -48,7 +48,7 @@ public void tryRemoteSenderAndReceiver() throws Throwable {
ListenerBroadcast<TestListenerInterface> broadcast = new ListenerBroadcast<TestListenerInterface>(TestListenerInterface.class);
broadcast.add(listenerMock);
RemoteExceptionListener exceptionListener = new RemoteExceptionListener();
RemoteReceiver receiver = new RemoteReceiver(broadcast, exceptionListener);
RemoteReceiver receiver = new RemoteReceiver(broadcast, exceptionListener, getClass().getClassLoader());

executeJava(RemoteProcess.class.getName(), receiver.getBoundPort());
if (exceptionListener.ex != null) {
Expand Down
Expand Up @@ -95,7 +95,7 @@ public interface DependencyHandler {
* Adds a dependency to the given configuration.
*
* @param configurationName The name of the configuration.
* @param dependencyNotation The dependency notation, in one of the notations decribed above.
* @param dependencyNotation The dependency notation, in one of the notations described above.
* @return The dependency.
*/
Dependency add(String configurationName, Object dependencyNotation);
Expand All @@ -104,9 +104,51 @@ public interface DependencyHandler {
* Adds a dependency to the given configuration, and configures the dependency using the given closure/
*
* @param configurationName The name of the configuration.
* @param dependencyNotation The dependency notation, in one of the notations decribed above.
* @param dependencyNotation The dependency notation, in one of the notations described above.
* @param configureClosure The closure to use to configure the dependency.
* @return The dependency.
*/
Dependency add(String configurationName, Object dependencyNotation, Closure configureClosure);

/**
* Creates a dependency on a client module.
*
* @param notation The module notation, in one of the notations described above.
* @return The dependency.
*/
Dependency module(Object notation);

/**
* Creates a dependency on a client module. The dependency is configured using the given closure before it is
* returned.
*
* @param notation The module notation, in one of the notations described above.
* @param configureClosure The closure to use to configure the dependency.
* @return The dependency.
*/
Dependency module(Object notation, Closure configureClosure);

/**
* Creates a dependency on a project.
*
* @param notation The project notation, in one of the notations described above.
* @return The dependency.
*/
Dependency project(Object notation);

/**
* Creates a dependency on a project. The dependency is configured using the given closure before it is returned.
*
* @param notation The project notation, in one of the notations described above.
* @param configureClosure The closure to use to configure the dependency.
* @return The dependency.
*/
Dependency project(Object notation, Closure configureClosure);

/**
* Creates a dependency on the API of the current version of Gradle.
*
* @return The dependency.
*/
Dependency gradleApi();
}
@@ -0,0 +1,26 @@
/*
* Copyright 2010 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.gradle.api.internal;

import java.io.File;
import java.net.URL;
import java.util.List;

public interface ClassPathRegistry {
URL[] getClassPathUrls(String name);

List<File> getClassPathFiles(String name);
}

0 comments on commit 1448478

Please sign in to comment.