Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from gradle:master #15

Merged
merged 15 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ plugins {

tasks.withType<IntegrationTest>().configureEach {
// See AbstractKotlinIntegrationTest
"kotlinDslTestsExtraRepo".let {
systemProperty(it, System.getProperty(it))
"kotlinDslTestsExtraRepo".let { propName ->
System.getProperty(propName)?.let { systemProperty(propName, it) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.gradle.execution.ExecutionAccessChecker
import org.gradle.execution.ExecutionAccessListener
import org.gradle.internal.buildoption.InternalOptions
import org.gradle.internal.buildtree.BuildModelParameters
import org.gradle.internal.buildtree.BuildTreeModelControllerServices
import org.gradle.internal.cc.impl.initialization.ConfigurationCacheStartParameter
import org.gradle.internal.cc.impl.problems.BuildNameProvider
import org.gradle.internal.cc.impl.services.DefaultIsolatedProjectEvaluationListenerProvider
Expand All @@ -52,7 +53,7 @@ class ConfigurationCacheServices : AbstractGradleModuleServices() {

override fun registerBuildSessionServices(registration: ServiceRegistration) {
registration.run {
add(DefaultBuildTreeModelControllerServices::class.java)
add(BuildTreeModelControllerServices::class.java, DefaultBuildTreeModelControllerServices::class.java)
add(ConfigurationCacheRepository::class.java)
add(ConfigurationCacheEntryCollector::class.java)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,27 @@
import org.gradle.internal.FileUtils;
import org.gradle.internal.exceptions.DiagnosticsVisitor;
import org.gradle.internal.typeconversion.NotationParser;
import org.gradle.internal.typeconversion.NotationParserBuilder;
import org.gradle.internal.typeconversion.TransformingConverter;
import org.gradle.internal.typeconversion.UnsupportedNotationException;
import org.gradle.util.internal.DeferredUtil;

import javax.annotation.Nullable;
import java.io.File;
import java.net.URI;

public abstract class AbstractFileResolver implements FileResolver {
private final NotationParser<Object, Object> fileNotationParser;
private final NotationParser<Object, File> fileNotationParser;
private final NotationParser<Object, URI> uriOrFileNotationParser;

protected AbstractFileResolver() {
this.fileNotationParser = FileOrUriNotationConverter.parser();
this.fileNotationParser = FileNotationConverter.parser();
this.uriOrFileNotationParser = NotationParserBuilder
.toType(URI.class)
.typeDisplayName("a URI or File")
.noImplicitConverters()
.converter(new UriNotationConverter())
.converter(new TransformingConverter<>(new FileNotationConverter(), file -> resolveFile(file, PathValidation.NONE).toURI()))
.toComposite();
}

public FileResolver withBaseDir(Object path) {
Expand Down Expand Up @@ -71,42 +80,30 @@ public String resolveForDisplay(Object path) {

@Override
public File resolve(Object path, PathValidation validation) {
File file = doResolve(path);

file = FileUtils.normalize(file);

validate(file, validation);

return file;
File maybeRelativeFile = unpackAndParseNotation(path, fileNotationParser, "File");
return resolveFile(maybeRelativeFile, validation);
}

@Override
public URI resolveUri(Object path) {
return convertObjectToURI(path);
public URI resolveUri(Object uri) {
return unpackAndParseNotation(uri, uriOrFileNotationParser, "URI");
}

protected abstract File doResolve(Object path);

protected URI convertObjectToURI(Object path) {
Object object = DeferredUtil.unpack(path);
Object converted = fileNotationParser.parseNotation(object);
if (converted instanceof File) {
return resolve(converted).toURI();
private static <T> T unpackAndParseNotation(Object input, NotationParser<Object, T> parser, String hint) {
Object unpacked = DeferredUtil.unpack(input);
if (unpacked == null || "".equals(unpacked)) {
throw new IllegalArgumentException(String.format("Cannot convert '%s' to %s.", input, hint));
}
return (URI) converted;
return parser.parseNotation(unpacked);
}

@Nullable
protected File convertObjectToFile(Object path) {
Object object = DeferredUtil.unpack(path);
if (object == null) {
return null;
}
Object converted = fileNotationParser.parseNotation(object);
if (converted instanceof File) {
return (File) converted;
}
throw new InvalidUserDataException(String.format("Cannot convert URL '%s' to a file.", converted));
protected abstract File doResolve(File path);

private File resolveFile(File maybeRelativeFile, PathValidation validation) {
File file = doResolve(maybeRelativeFile);
file = FileUtils.normalize(file);
validate(file, validation);
return file;
}

protected void validate(File file, PathValidation validation) {
Expand Down Expand Up @@ -136,5 +133,4 @@ protected void validate(File file, PathValidation validation) {
break;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,66 @@

package org.gradle.api.internal.file;

import org.gradle.util.internal.GUtil;

import java.io.File;
import java.nio.file.Path;

public class BaseDirFileResolver extends AbstractBaseDirFileResolver {
public class BaseDirFileResolver extends AbstractFileResolver {
private final File baseDir;

/**
* Do not create instances of this type. Use {@link FileLookup} instead.
*/
public BaseDirFileResolver(File baseDir) {
assert baseDir.isAbsolute() : String.format("base dir '%s' is not an absolute file.", baseDir);
if (!GUtil.isTrue(baseDir)) {
throw new IllegalArgumentException(String.format("baseDir may not be null or empty string. basedir='%s'", baseDir));
}
if (!baseDir.isAbsolute()) {
throw new IllegalArgumentException(String.format("base dir '%s' is not an absolute file.", baseDir));
}
this.baseDir = baseDir;
}

@Override
protected File getBaseDir() {
return baseDir;
public String resolveAsRelativePath(Object path) {
Path baseDir = this.baseDir.toPath();
Path file = resolve(path).toPath();
if (file.equals(baseDir)) {
return ".";
} else {
return baseDir.relativize(file).toString();
}
}

@Override
public String resolveForDisplay(Object path) {
Path file = resolve(path).toPath();
Path baseDir = this.baseDir.toPath();
if (file.equals(baseDir)) {
return ".";
}
Path parent = baseDir.getParent();
if (parent == null) {
parent = baseDir;
}
if (file.startsWith(parent)) {
return baseDir.relativize(file).toString();
} else {
return file.toString();
}
}

@Override
protected File doResolve(File file) {
if (!file.isAbsolute()) {
return new File(baseDir, file.getPath());
}
return file;
}

@Override
public boolean canResolveRelativePath() {
return true;
}
}
Loading
Loading