Search in sources :

Example 26 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class EffectiveClassPath method findAvailableClasspathFiles.

private static List<File> findAvailableClasspathFiles(ClassLoader classLoader) {
    List<URL> rawClasspath = ClasspathUtil.getClasspath(classLoader).getAsURLs();
    List<File> classpathFiles = new ArrayList<File>();
    for (URL url : rawClasspath) {
        if (url.getProtocol().equals("file")) {
            try {
                File classpathFile = new File(url.toURI());
                addClasspathFile(classpathFile, classpathFiles);
            } catch (URISyntaxException e) {
                throw new UncheckedIOException(e);
            }
        }
    }
    // from the system classpath
    if (classLoader == ClassLoader.getSystemClassLoader()) {
        for (String value : System.getProperty("java.class.path").split(File.pathSeparator)) {
            addClasspathFile(new File(value), classpathFiles);
        }
    }
    return classpathFiles;
}
Also used : ArrayList(java.util.ArrayList) UncheckedIOException(org.gradle.api.UncheckedIOException) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URL(java.net.URL)

Example 27 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class ManifestUtil method readManifestClasspathString.

private static String[] readManifestClasspathString(File classpathFile) {
    try {
        Manifest manifest = findManifest(classpathFile);
        if (manifest == null) {
            return EMPTY;
        }
        String classpathEntry = manifest.getMainAttributes().getValue("Class-Path");
        if (classpathEntry == null || classpathEntry.trim().length() == 0) {
            return EMPTY;
        }
        return classpathEntry.split(" ");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) Manifest(java.util.jar.Manifest)

Example 28 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class ManifestUtil method parseManifestClasspath.

public static List<URI> parseManifestClasspath(File jarFile) {
    List<URI> manifestClasspath = new ArrayList<URI>();
    for (String value : readManifestClasspathString(jarFile)) {
        try {
            URI uri = new URI(value);
            uri = jarFile.toURI().resolve(uri);
            manifestClasspath.add(uri);
        } catch (URISyntaxException e) {
            throw new UncheckedIOException(e);
        }
    }
    return manifestClasspath;
}
Also used : ArrayList(java.util.ArrayList) UncheckedIOException(org.gradle.api.UncheckedIOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 29 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class DefaultTemporaryFileProvider method createTemporaryFile.

public File createTemporaryFile(String prefix, @Nullable String suffix, String... path) {
    File dir = new File(baseDirFactory.create(), CollectionUtils.join("/", path));
    GFileUtils.mkdirs(dir);
    try {
        return File.createTempFile(prefix, suffix, dir);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File)

Example 30 with UncheckedIOException

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 URL) {
        try {
            notation = ((URL) notation).toURI();
        } catch (URISyntaxException e) {
            throw new UncheckedIOException(e);
        }
    }
    if (notation instanceof URI) {
        URI uri = (URI) notation;
        if (uri.getScheme().equals("file")) {
            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));
    }
}
Also used : Path(java.nio.file.Path) UncheckedIOException(org.gradle.api.UncheckedIOException) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI) URL(java.net.URL)

Aggregations

UncheckedIOException (org.gradle.api.UncheckedIOException)82 IOException (java.io.IOException)60 File (java.io.File)25 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)6 FileOutputStream (java.io.FileOutputStream)5 FileInputStream (java.io.FileInputStream)4 URI (java.net.URI)4 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 Manifest (java.util.jar.Manifest)4 ZipInputStream (java.util.zip.ZipInputStream)4 FileVisitDetails (org.gradle.api.file.FileVisitDetails)4 FileVisitor (org.gradle.api.file.FileVisitor)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileReader (java.io.FileReader)3 URISyntaxException (java.net.URISyntaxException)3 Matcher (java.util.regex.Matcher)3 ZipEntry (java.util.zip.ZipEntry)3