use of org.gradle.api.file.FileSystemLocation in project gradle by gradle.
the class FileOrUriNotationConverter method convert.
public void convert(Object notation, NotationConvertResult<? super Object> result) throws TypeConversionException {
if (notation instanceof File) {
result.converted(notation);
return;
}
if (notation instanceof Path) {
result.converted(((Path) notation).toFile());
return;
}
if (notation instanceof FileSystemLocation) {
result.converted(((FileSystemLocation) notation).getAsFile());
return;
}
if (notation instanceof URL) {
try {
notation = ((URL) notation).toURI();
} catch (URISyntaxException e) {
throw new UncheckedIOException(e);
}
}
if (notation instanceof URI) {
URI uri = (URI) notation;
if ("file".equals(uri.getScheme()) && uri.getPath() != null) {
result.converted(new File(uri.getPath()));
} else {
result.converted(uri);
}
return;
}
if (notation instanceof CharSequence) {
String notationString = notation.toString();
if (notationString.startsWith("file:")) {
result.converted(new File(uriDecode(notationString.substring(5))));
return;
}
for (File file : File.listRoots()) {
String rootPath = file.getAbsolutePath();
String normalisedStr = notationString;
if (!fileSystem.isCaseSensitive()) {
rootPath = rootPath.toLowerCase();
normalisedStr = normalisedStr.toLowerCase();
}
if (normalisedStr.startsWith(rootPath) || normalisedStr.startsWith(rootPath.replace(File.separatorChar, '/'))) {
result.converted(new File(notationString));
return;
}
}
// Check if string starts with a URI scheme
if (URI_SCHEME.matcher(notationString).matches()) {
try {
result.converted(new URI(notationString));
return;
} catch (URISyntaxException e) {
throw new UncheckedIOException(e);
}
}
result.converted(new File(notationString));
}
}
use of org.gradle.api.file.FileSystemLocation in project gradle by gradle.
the class LazyPublishArtifact method getFile.
@Override
public File getFile() {
if (file == null) {
Object value = provider.get();
if (value instanceof FileSystemLocation) {
FileSystemLocation location = (FileSystemLocation) value;
file = location.getAsFile();
} else if (value instanceof File) {
file = (File) value;
} else {
throw new InvalidUserDataException(String.format("Cannot convert provided value (%s) to a file.", value));
}
}
return file;
}
Aggregations