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();
}
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");
}
});
}
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;
}
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);
}
}
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;
}
Aggregations