use of org.gradle.api.UncheckedIOException 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.UncheckedIOException in project gradle by gradle.
the class FileToArchiveEntrySetTransformer method walk.
private ImmutableSet<ArchiveEntry> walk(InputStream archiveInputStream, ImmutableSet.Builder<ArchiveEntry> allEntries, ImmutableList<String> parentPaths) {
ImmutableSet.Builder<ArchiveEntry> entries = ImmutableSet.builder();
ZipInputStream zipStream = new ZipInputStream(archiveInputStream);
try {
ZipEntry entry = zipStream.getNextEntry();
while (entry != null) {
ArchiveEntry.Builder builder = new ArchiveEntry.Builder();
builder.setParentPaths(parentPaths);
builder.setPath(entry.getName());
builder.setCrc(entry.getCrc());
builder.setDirectory(entry.isDirectory());
builder.setSize(entry.getSize());
if (!builder.isDirectory() && (zipStream.available() == 1)) {
boolean zipEntry;
final BufferedInputStream bis = new BufferedInputStream(zipStream) {
@Override
public void close() throws IOException {
}
};
bis.mark(Integer.MAX_VALUE);
zipEntry = new ZipInputStream(bis).getNextEntry() != null;
bis.reset();
if (zipEntry) {
ImmutableList<String> nextParentPaths = ImmutableList.<String>builder().addAll(parentPaths).add(entry.getName()).build();
ImmutableSet<ArchiveEntry> subEntries = walk(bis, allEntries, nextParentPaths);
builder.setSubEntries(subEntries);
}
}
ArchiveEntry archiveEntry = builder.build();
entries.add(archiveEntry);
allEntries.add(archiveEntry);
zipStream.closeEntry();
entry = zipStream.getNextEntry();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
} finally {
IOUtils.closeQuietly(zipStream);
}
return entries.build();
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class Wrapper method writeProperties.
private void writeProperties(File propertiesFileDestination) {
Properties wrapperProperties = new Properties();
wrapperProperties.put(WrapperExecutor.DISTRIBUTION_URL_PROPERTY, getDistributionUrl());
if (distributionSha256Sum != null) {
wrapperProperties.put(WrapperExecutor.DISTRIBUTION_SHA_256_SUM, distributionSha256Sum);
}
wrapperProperties.put(WrapperExecutor.DISTRIBUTION_BASE_PROPERTY, distributionBase.toString());
wrapperProperties.put(WrapperExecutor.DISTRIBUTION_PATH_PROPERTY, distributionPath);
wrapperProperties.put(WrapperExecutor.ZIP_STORE_BASE_PROPERTY, archiveBase.toString());
wrapperProperties.put(WrapperExecutor.ZIP_STORE_PATH_PROPERTY, archivePath);
try {
PropertiesUtils.store(wrapperProperties, propertiesFileDestination);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class GUtil method loadProperties.
public static Properties loadProperties(URL url) {
try {
URLConnection uc = url.openConnection();
uc.setUseCaches(false);
return loadProperties(uc.getInputStream());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class RuntimeShadedJarCreator method processDirectory.
private void processDirectory(final ZipOutputStream outputStream, File file, final byte[] buffer, final HashSet<String> seenPaths, final Map<String, List<String>> services) {
final List<FileVisitDetails> fileVisitDetails = new ArrayList<FileVisitDetails>();
directoryFileTreeFactory.create(file).visit(new FileVisitor() {
@Override
public void visitDir(FileVisitDetails dirDetails) {
fileVisitDetails.add(dirDetails);
}
@Override
public void visitFile(FileVisitDetails fileDetails) {
fileVisitDetails.add(fileDetails);
}
});
// We need to sort here since the file order obtained from the filesystem
// can change between machines and we always want to have the same shaded jars.
Collections.sort(fileVisitDetails, new Comparator<FileVisitDetails>() {
@Override
public int compare(FileVisitDetails o1, FileVisitDetails o2) {
return o1.getPath().compareTo(o2.getPath());
}
});
for (FileVisitDetails details : fileVisitDetails) {
try {
if (details.isDirectory()) {
ZipEntry zipEntry = newZipEntryWithFixedTime(details.getPath() + "/");
processEntry(outputStream, null, zipEntry, buffer, seenPaths, services);
} else {
ZipEntry zipEntry = newZipEntryWithFixedTime(details.getPath());
InputStream inputStream = details.open();
try {
processEntry(outputStream, inputStream, zipEntry, buffer, seenPaths, services);
} finally {
inputStream.close();
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
Aggregations