Search in sources :

Example 1 with ScriptSource

use of org.gradle.groovy.scripts.ScriptSource in project gradle by gradle.

the class DefaultObjectConfigurationAction method applyScript.

private void applyScript(Object script) {
    URI scriptUri = resolver.resolveUri(script);
    ScriptSource scriptSource = new UriScriptSource("script", scriptUri);
    ClassLoaderScope classLoaderScopeChild = classLoaderScope.createChild("script-" + scriptUri.toString());
    ScriptHandler scriptHandler = scriptHandlerFactory.create(scriptSource, classLoaderScopeChild);
    ScriptPlugin configurer = configurerFactory.create(scriptSource, scriptHandler, classLoaderScopeChild, classLoaderScope, false);
    for (Object target : targets) {
        configurer.apply(target);
    }
}
Also used : UriScriptSource(org.gradle.groovy.scripts.UriScriptSource) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) ScriptPlugin(org.gradle.configuration.ScriptPlugin) URI(java.net.URI) ScriptSource(org.gradle.groovy.scripts.ScriptSource) UriScriptSource(org.gradle.groovy.scripts.UriScriptSource) ScriptHandler(org.gradle.api.initialization.dsl.ScriptHandler)

Example 2 with ScriptSource

use of org.gradle.groovy.scripts.ScriptSource in project gradle by gradle.

the class DefaultExceptionAnalyser method transform.

public Throwable transform(Throwable exception) {
    Throwable actualException = findDeepestRootException(exception);
    if (actualException instanceof LocationAwareException) {
        return actualException;
    }
    ScriptSource source = null;
    Integer lineNumber = null;
    // TODO: remove these special cases
    if (actualException instanceof ScriptCompilationException) {
        ScriptCompilationException scriptCompilationException = (ScriptCompilationException) actualException;
        source = scriptCompilationException.getScriptSource();
        lineNumber = scriptCompilationException.getLineNumber();
    }
    if (source == null) {
        for (Throwable currentException = actualException; currentException != null; currentException = currentException.getCause()) {
            for (StackTraceElement element : currentException.getStackTrace()) {
                if (element.getLineNumber() >= 0 && scripts.containsKey(element.getFileName())) {
                    source = scripts.get(element.getFileName());
                    lineNumber = element.getLineNumber();
                    break;
                }
            }
        }
    }
    return new LocationAwareException(actualException, source, lineNumber);
}
Also used : LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) ScriptCompilationException(org.gradle.groovy.scripts.ScriptCompilationException) ScriptSource(org.gradle.groovy.scripts.ScriptSource)

Example 3 with ScriptSource

use of org.gradle.groovy.scripts.ScriptSource in project gradle by gradle.

the class ScriptEvaluatingSettingsProcessor method applySettingsScript.

private void applySettingsScript(SettingsLocation settingsLocation, final SettingsInternal settings) {
    ScriptSource settingsScriptSource = settingsLocation.getSettingsScriptSource();
    ClassLoaderScope settingsClassLoaderScope = settings.getClassLoaderScope();
    ScriptHandler scriptHandler = scriptHandlerFactory.create(settingsScriptSource, settingsClassLoaderScope);
    ScriptPlugin configurer = configurerFactory.create(settingsScriptSource, scriptHandler, settingsClassLoaderScope, settings.getRootClassLoaderScope(), true);
    configurer.apply(settings);
}
Also used : ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) ScriptPlugin(org.gradle.configuration.ScriptPlugin) ScriptSource(org.gradle.groovy.scripts.ScriptSource) ScriptHandler(org.gradle.api.initialization.dsl.ScriptHandler)

Example 4 with ScriptSource

use of org.gradle.groovy.scripts.ScriptSource in project gradle by gradle.

the class ScriptUsageLocationReporter method reportStackTraceElement.

private void reportStackTraceElement(StackTraceElement stackTraceElement, StringBuilder target) {
    ScriptSource scriptSource = scripts.get(stackTraceElement.getFileName());
    target.append(StringUtils.capitalize(scriptSource.getDisplayName()));
    if (stackTraceElement.getLineNumber() > 0) {
        target.append(": line ");
        target.append(stackTraceElement.getLineNumber());
    }
}
Also used : ScriptSource(org.gradle.groovy.scripts.ScriptSource)

Example 5 with ScriptSource

use of org.gradle.groovy.scripts.ScriptSource in project gradle by gradle.

the class ProjectFactory method createProject.

public DefaultProject createProject(ProjectDescriptor projectDescriptor, ProjectInternal parent, GradleInternal gradle, ClassLoaderScope selfClassLoaderScope, ClassLoaderScope baseClassLoaderScope) {
    File buildFile = projectDescriptor.getBuildFile();
    ScriptSource source = UriScriptSource.file("build file", buildFile);
    DefaultProject project = instantiator.newInstance(DefaultProject.class, projectDescriptor.getName(), parent, projectDescriptor.getProjectDir(), source, gradle, gradle.getServiceRegistryFactory(), selfClassLoaderScope, baseClassLoaderScope);
    if (parent != null) {
        parent.addChildProject(project);
    }
    projectRegistry.addProject(project);
    return project;
}
Also used : File(java.io.File) ScriptSource(org.gradle.groovy.scripts.ScriptSource) UriScriptSource(org.gradle.groovy.scripts.UriScriptSource)

Aggregations

ScriptSource (org.gradle.groovy.scripts.ScriptSource)5 ScriptHandler (org.gradle.api.initialization.dsl.ScriptHandler)2 ClassLoaderScope (org.gradle.api.internal.initialization.ClassLoaderScope)2 ScriptPlugin (org.gradle.configuration.ScriptPlugin)2 UriScriptSource (org.gradle.groovy.scripts.UriScriptSource)2 File (java.io.File)1 URI (java.net.URI)1 ScriptCompilationException (org.gradle.groovy.scripts.ScriptCompilationException)1 LocationAwareException (org.gradle.internal.exceptions.LocationAwareException)1