Search in sources :

Example 1 with TextResource

use of org.gradle.internal.resource.TextResource in project gradle by gradle.

the class DefaultScriptSourceHasher method hash.

@Override
public HashCode hash(ScriptSource scriptSource) {
    TextResource resource = scriptSource.getResource();
    File file = resource.getFile();
    if (file != null) {
        try {
            return fileHasher.hash(file);
        } catch (UncheckedIOException e) {
            if (e.getCause() instanceof FileNotFoundException) {
                throw new UncheckedIOException("Could not read " + scriptSource.getDisplayName() + " as it does not exist.", e.getCause());
            }
            throw e;
        }
    }
    Hasher hasher = contentHasherFactory.create();
    hasher.putString(resource.getText());
    return hasher.hash();
}
Also used : TextResource(org.gradle.internal.resource.TextResource) FileHasher(org.gradle.internal.hash.FileHasher) Hasher(org.gradle.internal.hash.Hasher) FileNotFoundException(java.io.FileNotFoundException) UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File)

Example 2 with TextResource

use of org.gradle.internal.resource.TextResource in project gradle by gradle.

the class InitScriptHandler method executeScripts.

public void executeScripts(final GradleInternal gradle) {
    final List<File> initScripts = gradle.getStartParameter().getAllInitScripts();
    if (initScripts.isEmpty()) {
        return;
    }
    buildOperationExecutor.run(new RunnableBuildOperation() {

        @Override
        public void run(BuildOperationContext context) {
            for (File script : initScripts) {
                TextResource resource = resourceLoader.loadFile("initialization script", script);
                processor.process(new TextResourceScriptSource(resource), gradle);
            }
        }

        @Override
        public BuildOperationDescriptor.Builder description() {
            return BuildOperationDescriptor.displayName("Run init scripts").progressDisplayName("Running init scripts");
        }
    });
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) TextResource(org.gradle.internal.resource.TextResource) TextResourceScriptSource(org.gradle.groovy.scripts.TextResourceScriptSource) File(java.io.File) RunnableBuildOperation(org.gradle.internal.operations.RunnableBuildOperation)

Example 3 with TextResource

use of org.gradle.internal.resource.TextResource in project gradle by gradle.

the class ProjectFactory method createProject.

@Override
public ProjectInternal createProject(GradleInternal gradle, ProjectDescriptor projectDescriptor, ProjectState owner, @Nullable ProjectInternal parent, ClassLoaderScope selfClassLoaderScope, ClassLoaderScope baseClassLoaderScope) {
    File buildFile = projectDescriptor.getBuildFile();
    TextResource resource = textFileResourceLoader.loadFile("build file", buildFile);
    ScriptSource source = new TextResourceScriptSource(resource);
    DefaultProject project = instantiator.newInstance(DefaultProject.class, projectDescriptor.getName(), parent, projectDescriptor.getProjectDir(), buildFile, source, gradle, owner, gradle.getServiceRegistryFactory(), selfClassLoaderScope, baseClassLoaderScope);
    project.beforeEvaluate(p -> {
        NameValidator.validate(project.getName(), "project name", DefaultProjectDescriptor.INVALID_NAME_IN_INCLUDE_HINT);
        gradle.getServices().get(DependenciesAccessors.class).createExtensions(project);
        gradle.getServices().get(DependencyResolutionManagementInternal.class).configureProject(project);
    });
    gradle.getProjectRegistry().addProject(project);
    return project;
}
Also used : TextResource(org.gradle.internal.resource.TextResource) TextResourceScriptSource(org.gradle.groovy.scripts.TextResourceScriptSource) DependenciesAccessors(org.gradle.initialization.DependenciesAccessors) File(java.io.File) TextResourceScriptSource(org.gradle.groovy.scripts.TextResourceScriptSource) ScriptSource(org.gradle.groovy.scripts.ScriptSource) DependencyResolutionManagementInternal(org.gradle.internal.management.DependencyResolutionManagementInternal)

Example 4 with TextResource

use of org.gradle.internal.resource.TextResource in project gradle by gradle.

the class DefaultObjectConfigurationAction method applyScript.

private void applyScript(Object script) {
    URI scriptUri = resolver.resolveUri(script);
    TextResource resource;
    if (script instanceof TextResource) {
        resource = (TextResource) script;
    } else {
        HttpRedirectVerifier redirectVerifier = createHttpRedirectVerifier(scriptUri);
        resource = textUriFileResourceLoaderFactory.create(redirectVerifier).loadUri("script", scriptUri);
    }
    ScriptSource scriptSource = new TextResourceScriptSource(resource);
    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 : TextResource(org.gradle.internal.resource.TextResource) HttpRedirectVerifier(org.gradle.internal.verifier.HttpRedirectVerifier) TextResourceScriptSource(org.gradle.groovy.scripts.TextResourceScriptSource) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) ScriptPlugin(org.gradle.configuration.ScriptPlugin) URI(java.net.URI) TextResourceScriptSource(org.gradle.groovy.scripts.TextResourceScriptSource) ScriptSource(org.gradle.groovy.scripts.ScriptSource) ScriptHandler(org.gradle.api.initialization.dsl.ScriptHandler)

Example 5 with TextResource

use of org.gradle.internal.resource.TextResource 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();
    TextResource resource = resourceLoader.loadFile("build file", buildFile);
    ScriptSource source = new TextResourceScriptSource(resource);
    NameValidator.validate(projectDescriptor.getName(), "project name", DefaultProjectDescriptor.INVALID_NAME_IN_INCLUDE_HINT);
    DefaultProject project = instantiator.newInstance(DefaultProject.class, projectDescriptor.getName(), parent, projectDescriptor.getProjectDir(), buildFile, source, gradle, gradle.getServiceRegistryFactory(), selfClassLoaderScope, baseClassLoaderScope);
    if (parent != null) {
        parent.addChildProject(project);
    }
    projectRegistry.addProject(project);
    return project;
}
Also used : TextResource(org.gradle.internal.resource.TextResource) TextResourceScriptSource(org.gradle.groovy.scripts.TextResourceScriptSource) File(java.io.File) ScriptSource(org.gradle.groovy.scripts.ScriptSource) TextResourceScriptSource(org.gradle.groovy.scripts.TextResourceScriptSource)

Aggregations

TextResource (org.gradle.internal.resource.TextResource)6 File (java.io.File)5 ScriptSource (org.gradle.groovy.scripts.ScriptSource)4 TextResourceScriptSource (org.gradle.groovy.scripts.TextResourceScriptSource)4 BuildOperationContext (org.gradle.internal.operations.BuildOperationContext)2 RunnableBuildOperation (org.gradle.internal.operations.RunnableBuildOperation)2 FileNotFoundException (java.io.FileNotFoundException)1 URI (java.net.URI)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 ScriptHandler (org.gradle.api.initialization.dsl.ScriptHandler)1 ClassLoaderScope (org.gradle.api.internal.initialization.ClassLoaderScope)1 ScriptPlugin (org.gradle.configuration.ScriptPlugin)1 DependenciesAccessors (org.gradle.initialization.DependenciesAccessors)1 FileHasher (org.gradle.internal.hash.FileHasher)1 Hasher (org.gradle.internal.hash.Hasher)1 DependencyResolutionManagementInternal (org.gradle.internal.management.DependencyResolutionManagementInternal)1 BuildOperationDescriptor (org.gradle.internal.operations.BuildOperationDescriptor)1 ResourceLocation (org.gradle.internal.resource.ResourceLocation)1 HttpRedirectVerifier (org.gradle.internal.verifier.HttpRedirectVerifier)1