org.gradle.api.UncheckedIOException Java Examples

The following examples show how to use org.gradle.api.UncheckedIOException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultIvyDependencyPublisher.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void publish(List<ModuleVersionPublisher> publishResolvers,
                    IvyModulePublishMetaData publishMetaData) {
    try {
        // Make a copy of the publication and filter missing artifacts
        DefaultIvyModulePublishMetaData publication = new DefaultIvyModulePublishMetaData(publishMetaData.getId());
        for (IvyModuleArtifactPublishMetaData artifact: publishMetaData.getArtifacts()) {
            addPublishedArtifact(artifact, publication);
        }
        for (ModuleVersionPublisher publisher : publishResolvers) {
            logger.info("Publishing to {}", publisher);
            publisher.publish(publication);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #2
Source File: CommandLineJavaCompilerArgumentsGenerator.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Iterable<String> shortenArgs(List<String> args) {
    File file = tempFileProvider.createTemporaryFile("compile-args", null, "java-compiler");
    // for command file format, see http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html#commandlineargfile
    // use platform character and line encoding
    try {
        PrintWriter writer = new PrintWriter(new FileWriter(file));
        try {
            ArgWriter argWriter = ArgWriter.unixStyle(writer);
            for (String arg : args) {
                argWriter.args(arg);
            }
        } finally {
            writer.close();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return Collections.singleton("@" + file.getPath());
}
 
Example #3
Source File: ClasspathVersionSource.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Properties create() {
    URL resource = classLoader.getResource(resourceName);
    if (resource == null) {
        throw new RuntimeException(
                "Unable to find the released versions information.\n"
                        + "The resource '" + resourceName + "' was not found.\n"
                        + "Most likely, you haven't run the 'prepareVersionsInfo' task.\n"
                        + "If you have trouble running tests from your IDE, please run gradlew idea|eclipse first."
        );
    }

    try {
        Properties properties = new Properties();
        InputStream stream = resource.openStream();
        try {
            properties.load(stream);
        } finally {
            stream.close();
        }
        return properties;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #4
Source File: AbstractReportTask.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@TaskAction
public void generate() {
    try {
        ReportRenderer renderer = getRenderer();
        File outputFile = getOutputFile();
        if (outputFile != null) {
            renderer.setOutputFile(outputFile);
        } else {
            renderer.setOutput(getServices().get(StyledTextOutputFactory.class).create(getClass()));
        }
        Set<Project> projects = new TreeSet<Project>(getProjects());
        for (Project project : projects) {
            renderer.startProject(project);
            generate(project);
            renderer.completeProject(project);
        }
        renderer.complete();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #5
Source File: BrowserEvaluate.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@TaskAction
void doEvaluate() {
    HttpFileServer fileServer = new SimpleHttpFileServerFactory().start(getContent(), 0);

    try {
        Writer resultWriter = new FileWriter(getResult());
        getEvaluator().evaluate(fileServer.getResourceUrl(getResource()), resultWriter);
        resultWriter.close();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        fileServer.stop();
    }

    setDidWork(true);
}
 
Example #6
Source File: IoActions.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void execute(Action<? super BufferedWriter> action) {
    try {
        File parentFile = file.getParentFile();
        if (parentFile != null) {
            if (!parentFile.mkdirs() && !parentFile.isDirectory()) {
                throw new IOException(String.format("Unable to create directory '%s'", parentFile));
            }
        }
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding));
        try {
            action.execute(writer);
        } finally {
            writer.close();
        }
    } catch (Exception e) {
        throw new UncheckedIOException(String.format("Could not write to file '%s'.", file), e);
    }
}
 
Example #7
Source File: RhinoWorkerUtils.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Scriptable parse(File source, String encoding, Action<Context> contextConfig) {
    Context context = Context.enter();
    if (contextConfig != null) {
        contextConfig.execute(context);
    }

    Scriptable scope = context.initStandardObjects();
    try {
        Reader reader = new InputStreamReader(new FileInputStream(source), encoding);
        try {
            context.evaluateReader(scope, reader, source.getName(), 0, null);
        } finally {
            reader.close();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        Context.exit();
    }

    return scope;
}
 
Example #8
Source File: BrowserEvaluate.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@TaskAction
void doEvaluate() {
    HttpFileServer fileServer = new SimpleHttpFileServerFactory().start(getContent(), 0);

    try {
        Writer resultWriter = new FileWriter(getResult());
        getEvaluator().evaluate(fileServer.getResourceUrl(getResource()), resultWriter);
        resultWriter.close();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        fileServer.stop();
    }

    setDidWork(true);
}
 
Example #9
Source File: RhinoWorkerUtils.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Scriptable parse(File source, String encoding, Action<Context> contextConfig) {
    Context context = Context.enter();
    if (contextConfig != null) {
        contextConfig.execute(context);
    }

    Scriptable scope = context.initStandardObjects();
    try {
        Reader reader = new InputStreamReader(new FileInputStream(source), encoding);
        try {
            context.evaluateReader(scope, reader, source.getName(), 0, null);
        } finally {
            reader.close();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        Context.exit();
    }

    return scope;
}
 
Example #10
Source File: PreferencesAssistant.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Saves the settings of the file chooser; and by settings I mean the 'last visited directory'.
 *
 * @param saveCurrentDirectoryVsSelectedFilesParent this should be true if you're selecting only directories, false if you're selecting only files. I don't know what if you allow both.
 */
public static void saveSettings(SettingsNode settingsNode, JFileChooser fileChooser, String id, Class fileChooserClass, boolean saveCurrentDirectoryVsSelectedFilesParent) {
    SettingsNode childNode = settingsNode.addChildIfNotPresent(getPrefix(fileChooserClass, id));

    String save;
    try {
        if (saveCurrentDirectoryVsSelectedFilesParent) {
            save = fileChooser.getCurrentDirectory().getCanonicalPath();
        } else {
            save = fileChooser.getSelectedFile().getCanonicalPath();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    if (save != null) {
        childNode.setValueOfChild(DIRECTORY_NAME, save);
    }
}
 
Example #11
Source File: IoActions.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void execute(Action<? super BufferedWriter> action) {
    try {
        File parentFile = file.getParentFile();
        if (parentFile != null) {
            if (!parentFile.mkdirs() && !parentFile.isDirectory()) {
                throw new IOException(String.format("Unable to create directory '%s'", parentFile));
            }
        }
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding));
        try {
            action.execute(writer);
        } finally {
            writer.close();
        }
    } catch (Exception e) {
        throw new UncheckedIOException(String.format("Could not write to file '%s'.", file), e);
    }
}
 
Example #12
Source File: OptionsFileArgsTransformer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected void transformArgs(List<String> input, List<String> output, File tempDir) {
    GFileUtils.mkdirs(tempDir);
    File optionsFile = new File(tempDir, "options.txt");
    try {
        PrintWriter writer = new PrintWriter(optionsFile);
        try {
            ArgWriter argWriter = argWriterFactory.transform(writer);
            argWriter.args(input);
        } finally {
            IOUtils.closeQuietly(writer);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(String.format("Could not write compiler options file '%s'.", optionsFile.getAbsolutePath()), e);
    }

    output.add(String.format("@%s", optionsFile.getAbsolutePath()));
}
 
Example #13
Source File: ClasspathVersionSource.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Properties create() {
    URL resource = classLoader.getResource(resourceName);
    if (resource == null) {
        throw new RuntimeException(
                "Unable to find the released versions information.\n"
                        + "The resource '" + resourceName + "' was not found.\n"
                        + "Most likely, you haven't ran the 'prepareVersionsInfo' task.\n"
                        + "If you have trouble running tests from your IDE, please run gradlew idea|eclipse first."
        );
    }

    try {
        Properties properties = new Properties();
        InputStream stream = resource.openStream();
        try {
            properties.load(stream);
        } finally {
            stream.close();
        }
        return properties;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #14
Source File: CommandLineJavaCompilerArgumentsGenerator.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Iterable<String> shortenArgs(File tempDir, List<String> args) {
    File file = new File(tempDir, "java-compiler-args.txt");
    // for command file format, see http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html#commandlineargfile
    // use platform character and line encoding
    try {
        PrintWriter writer = new PrintWriter(new FileWriter(file));
        try {
            ArgWriter argWriter = ArgWriter.unixStyle(writer);
            for (String arg : args) {
                argWriter.args(arg);
            }
        } finally {
            writer.close();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return Collections.singleton("@" + file.getPath());
}
 
Example #15
Source File: LayoutToPropertiesConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void maybeConfigureFrom(File propertiesFile, Map<String, String> result) {
    if (!propertiesFile.isFile()) {
        return;
    }

    Properties properties = new Properties();
    try {
        FileInputStream inputStream = new FileInputStream(propertiesFile);
        try {
            properties.load(inputStream);
        } finally {
            inputStream.close();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }

    for (Object key : properties.keySet()) {
        if (GradleProperties.ALL.contains(key.toString())) {
            result.put(key.toString(), properties.get(key).toString());
        }
    }
}
 
Example #16
Source File: RegexBackedCSourceParser.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void parseFile(File file, DefaultSourceDetails sourceDetails) {
    try {
        BufferedReader bf = new BufferedReader(new PreprocessingReader(new BufferedReader(new FileReader(file))));

        try {
            String line;
            while ((line = bf.readLine()) != null) {
                Matcher m = includePattern.matcher(line.trim());

                if (m.matches()) {
                    boolean isImport = "import".equals(m.group(1));
                    String value = m.group(2);
                    if (isImport) {
                        sourceDetails.getImports().add(value);
                    } else {
                        sourceDetails.getIncludes().add(value);
                    }
                }
            }
        } finally {
            IOUtils.closeQuietly(bf);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #17
Source File: DefaultIvyDependencyPublisher.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void publish(List<ModuleVersionPublisher> publishResolvers,
                    ModuleVersionPublishMetaData publishMetaData) {
    try {
        // Make a copy of the publication and filter missing artifacts
        DefaultModuleVersionPublishMetaData publication = new DefaultModuleVersionPublishMetaData(publishMetaData.getId());
        for (ModuleVersionArtifactPublishMetaData artifact: publishMetaData.getArtifacts()) {
            addPublishedArtifact(artifact, publication);
        }
        for (ModuleVersionPublisher publisher : publishResolvers) {
            logger.info("Publishing to {}", publisher);
            publisher.publish(publication);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #18
Source File: PreferencesAssistant.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Saves the settings of the file chooser; and by settings I mean the 'last visited directory'.
 *
 * @param saveCurrentDirectoryVsSelectedFilesParent this should be true true if you're selecting only directories, false if you're selecting only files. I don't know what if you allow both.
 */
public static void saveSettings(SettingsNode settingsNode, JFileChooser fileChooser, String id, Class fileChooserClass, boolean saveCurrentDirectoryVsSelectedFilesParent) {
    SettingsNode childNode = settingsNode.addChildIfNotPresent(getPrefix(fileChooserClass, id));

    String save;
    try {
        if (saveCurrentDirectoryVsSelectedFilesParent) {
            save = fileChooser.getCurrentDirectory().getCanonicalPath();
        } else {
            save = fileChooser.getSelectedFile().getCanonicalPath();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    if (save != null) {
        childNode.setValueOfChild(DIRECTORY_NAME, save);
    }
}
 
Example #19
Source File: EffectiveClassPath.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static List<File> findAvailableClasspathFiles(ClassLoader classLoader) {
    List<URL> rawClasspath = ClasspathUtil.getClasspath(classLoader);
    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);
            }
        }
    }

    // The file names passed to -cp are canonicalised by the JVM when it creates the system classloader, and so the file names are
    // lost if they happen to refer to links, for example, into the Gradle artifact cache. Try to reconstitute the file names
    // 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;
}
 
Example #20
Source File: TestResultSerializer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void write(Collection<TestClassResult> results) {
    try {
        OutputStream outputStream = new FileOutputStream(resultsFile);
        try {
            if (!results.isEmpty()) { // only write if we have results, otherwise truncate
                FlushableEncoder encoder = new KryoBackedEncoder(outputStream);
                encoder.writeSmallInt(RESULT_VERSION);
                write(results, encoder);
                encoder.flush();
            }
        } finally {
            outputStream.close();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #21
Source File: EffectiveClassPath.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static List<File> findAvailableClasspathFiles(ClassLoader classLoader) {
    List<URL> rawClasspath = ClasspathUtil.getClasspath(classLoader);
    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);
            }
        }
    }

    // The file names passed to -cp are canonicalised by the JVM when it creates the system classloader, and so the file names are
    // lost if they happen to refer to links, for example, into the Gradle artifact cache. Try to reconstitute the file names
    // 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;
}
 
Example #22
Source File: BuildSrcUpdateFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public DefaultClassPath create() {
    File markerFile = new File(cache.getBaseDir(), "built.bin");
    final boolean rebuild = !markerFile.exists();

    BuildSrcBuildListenerFactory.Listener listener = listenerFactory.create(rebuild);
    gradleLauncher.addListener(listener);
    gradleLauncher.run().rethrowFailure();

    Collection<File> classpath = listener.getRuntimeClasspath();
    LOGGER.debug("Gradle source classpath is: {}", classpath);
    LOGGER.info("================================================" + " Finished building buildSrc");
    try {
        markerFile.createNewFile();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return new DefaultClassPath(classpath);
}
 
Example #23
Source File: ApplicationClassesInSystemClassLoaderWorkerFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void prepareJavaCommand(JavaExecSpec execSpec) {
    execSpec.setMain("jarjar." + GradleWorkerMain.class.getName());
    execSpec.classpath(classPathRegistry.getClassPath("WORKER_MAIN").getAsFiles());
    Object requestedSecurityManager = execSpec.getSystemProperties().get("java.security.manager");
    if (requestedSecurityManager != null) {
        execSpec.systemProperty("org.gradle.security.manager", requestedSecurityManager);
    }
    execSpec.systemProperty("java.security.manager", "jarjar." + BootstrapSecurityManager.class.getName());
    try {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        DataOutputStream outstr = new DataOutputStream(new EncodedStream.EncodedOutput(bytes));
        LOGGER.debug("Writing an application classpath to child process' standard input.");
        outstr.writeInt(processBuilder.getApplicationClasspath().size());
        for (File file : processBuilder.getApplicationClasspath()) {
            outstr.writeUTF(file.getAbsolutePath());
        }
        outstr.close();
        final InputStream originalStdin = execSpec.getStandardInput();
        InputStream input = ByteStreams.join(ByteStreams.newInputStreamSupplier(bytes.toByteArray()), new InputSupplier<InputStream>() {
            public InputStream getInput() throws IOException {
                return originalStdin;
            }
        }).getInput();
        execSpec.setStandardInput(input);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #24
Source File: StreamBackedStandardOutputListener.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onOutput(CharSequence output) {
    try {
        appendable.append(output);
        flushable.flush();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #25
Source File: FileBackedBlockStore.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void open(Runnable runnable, Factory factory) {
    this.factory = factory;
    try {
        cacheFile.getParentFile().mkdirs();
        file = new RandomAccessFile(cacheFile, "rw");
        nextBlock = file.length();
        if (file.length() == 0) {
            runnable.run();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #26
Source File: HashUtil.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static HashValue createHash(File file, String algorithm) {
    try {
        return createHash(new FileInputStream(file), algorithm);
    } catch (FileNotFoundException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #27
Source File: BTreePersistentIndexedCache.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void reset() {
    close();
    try {
        open();
    } catch (Exception e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #28
Source File: FileBackedBlockStore.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void close() {
    try {
        file.close();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #29
Source File: GUtil.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static Properties loadProperties(InputStream inputStream) {
    Properties properties = new Properties();
    try {
        properties.load(inputStream);
        inputStream.close();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return properties;
}
 
Example #30
Source File: BTreePersistentIndexedCache.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void verify() {
    try {
        doVerify();
    } catch (Exception e) {
        throw new UncheckedIOException(String.format("Some problems were found when checking the integrity of %s.",
                this), e);
    }
}