Search in sources :

Example 46 with UncheckedIOException

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

the class DefaultJvmVersionDetector method parseJavaVersionCommandOutput.

private JavaVersion parseJavaVersionCommandOutput(String javaExecutable, BufferedReader reader) {
    try {
        String versionStr = reader.readLine();
        while (versionStr != null) {
            Matcher matcher = Pattern.compile("(?:java|openjdk) version \"(.+?)\"( \\d{4}-\\d{2}-\\d{2}( LTS)?)?").matcher(versionStr);
            if (matcher.matches()) {
                return JavaVersion.toVersion(matcher.group(1));
            }
            versionStr = reader.readLine();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    throw new GradleException(String.format("Could not determine Java version using executable %s.", javaExecutable));
}
Also used : Matcher(java.util.regex.Matcher) GradleException(org.gradle.api.GradleException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 47 with UncheckedIOException

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

the class GenerateModuleMapFile method generateFile.

public static void generateFile(File moduleMapFile, String moduleName, List<String> publicHeaderDirs) {
    List<String> lines = Lists.newArrayList("module " + moduleName + " {");
    List<String> validHeaderDirs = filter(publicHeaderDirs, new Spec<String>() {

        @Override
        public boolean isSatisfiedBy(String path) {
            return new File(path).exists();
        }
    });
    lines.addAll(collect(validHeaderDirs, new Transformer<String, String>() {

        @Override
        public String transform(String path) {
            return "\tumbrella \"" + path + "\"";
        }
    }));
    lines.add("\texport *");
    lines.add("}");
    try {
        Files.createParentDirs(moduleMapFile);
        FileUtils.writeLines(moduleMapFile, lines);
    } catch (IOException e) {
        throw new UncheckedIOException("Could not generate a module map for " + moduleName, e);
    }
}
Also used : Transformer(org.gradle.api.Transformer) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File)

Example 48 with UncheckedIOException

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

the class GccMetadataProvider method determineVendor.

private String determineVendor(String error, VersionNumber versionNumber, File gccBinary) {
    BufferedReader reader = new BufferedReader(new StringReader(error));
    String majorMinorOnly = versionNumber.getMajor() + "." + versionNumber.getMinor();
    String line;
    try {
        while ((line = reader.readLine()) != null) {
            if (line.contains(majorMinorOnly) && line.contains(" version ") && line.contains(compilerType.getIdentifier()) && !line.contains(" default target ")) {
                return line;
            }
        }
    } catch (IOException e) {
        // Should not happen reading from a StringReader
        throw new UncheckedIOException(e);
    }
    throw new BrokenResultException(String.format("Could not determine %s metadata: could not find vendor in output of %s.", compilerType.getDescription(), gccBinary));
}
Also used : BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 49 with UncheckedIOException

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

the class GccMetadataProvider method determineSystemIncludes.

private ImmutableList<File> determineSystemIncludes(String error) {
    BufferedReader reader = new BufferedReader(new StringReader(error));
    String line;
    ImmutableList.Builder<File> builder = ImmutableList.builder();
    boolean systemIncludesStarted = false;
    try {
        while ((line = reader.readLine()) != null) {
            if (SYSTEM_INCLUDES_END.equals(line)) {
                break;
            }
            if (SYSTEM_INCLUDES_START.equals(line)) {
                systemIncludesStarted = true;
                continue;
            }
            if (systemIncludesStarted) {
                // Exclude frameworks for CLang - they need to be handled differently
                if (compilerType == CLANG && line.contains(FRAMEWORK_INCLUDE)) {
                    continue;
                }
                // Exclude framework directories for GCC - they are added as system search paths but they are actually not
                if (compilerType == GCC && line.endsWith("/Library/Frameworks")) {
                    continue;
                }
                builder.add(new File(line.trim()));
            }
        }
        return builder.build();
    } catch (IOException e) {
        // Should not happen reading from a StringReader
        throw new UncheckedIOException(e);
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File)

Example 50 with UncheckedIOException

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

the class GenerateModuleMetadata method run.

@TaskAction
void run() {
    File file = outputFile.get().getAsFile();
    PublicationInternal publication = (PublicationInternal) this.publication.get();
    List<PublicationInternal> publications = Cast.uncheckedCast(this.publications.get());
    try {
        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf8"));
        try {
            new ModuleMetadataFileGenerator(getBuildInvocationScopeId(), getProjectDependencyPublicationResolver()).generateTo(publication, publications, writer);
        } finally {
            writer.close();
        }
    } catch (IOException e) {
        throw new UncheckedIOException("Could not generate metadata file " + outputFile.get(), e);
    }
}
Also used : ModuleMetadataFileGenerator(org.gradle.api.publish.internal.ModuleMetadataFileGenerator) PublicationInternal(org.gradle.api.publish.internal.PublicationInternal) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

UncheckedIOException (org.gradle.api.UncheckedIOException)101 IOException (java.io.IOException)79 File (java.io.File)32 InputStream (java.io.InputStream)9 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 BufferedReader (java.io.BufferedReader)6 StringReader (java.io.StringReader)6 FileInputStream (java.io.FileInputStream)5 Matcher (java.util.regex.Matcher)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)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 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileReader (java.io.FileReader)3