Java Code Examples for org.gradle.util.GFileUtils#mkdirs()

The following examples show how to use org.gradle.util.GFileUtils#mkdirs() . 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: GroovyCompile.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private DefaultGroovyJavaJointCompileSpec createSpec() {
    DefaultGroovyJavaJointCompileSpec spec = new DefaultGroovyJavaJointCompileSpec();
    spec.setSource(getSource());
    spec.setDestinationDir(getDestinationDir());
    spec.setWorkingDir(getProject().getProjectDir());
    spec.setTempDir(getTemporaryDir());
    spec.setClasspath(getClasspath());
    spec.setSourceCompatibility(getSourceCompatibility());
    spec.setTargetCompatibility(getTargetCompatibility());
    spec.setGroovyClasspath(getGroovyClasspath());
    spec.setCompileOptions(compileOptions);
    spec.setGroovyCompileOptions(groovyCompileOptions);
    if (spec.getGroovyCompileOptions().getStubDir() == null) {
        File dir = new File(getTemporaryDir(), "groovy-java-stubs");
        GFileUtils.mkdirs(dir);
        spec.getGroovyCompileOptions().setStubDir(dir);
    }
    return spec;
}
 
Example 2
Source File: DefaultScriptCompilationHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void compileToDir(ScriptSource source, ClassLoader classLoader, File classesDir,
                         Transformer transformer, Class<? extends Script> scriptBaseClass) {
    Clock clock = new Clock();
    GFileUtils.deleteDirectory(classesDir);
    GFileUtils.mkdirs(classesDir);
    CompilerConfiguration configuration = createBaseCompilerConfiguration(scriptBaseClass);
    configuration.setTargetDirectory(classesDir);
    try {
        compileScript(source, classLoader, configuration, classesDir, transformer);
    } catch (GradleException e) {
        GFileUtils.deleteDirectory(classesDir);
        throw e;
    }

    logger.debug("Timing: Writing script to cache at {} took: {}", classesDir.getAbsolutePath(),
            clock.getTime());
}
 
Example 3
Source File: DefaultScriptCompilationHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void compileToDir(ScriptSource source, ClassLoader classLoader, File classesDir,
                         Transformer transformer, Class<? extends Script> scriptBaseClass, Verifier verifier) {
    Clock clock = new Clock();
    GFileUtils.deleteDirectory(classesDir);
    GFileUtils.mkdirs(classesDir);
    CompilerConfiguration configuration = createBaseCompilerConfiguration(scriptBaseClass);
    configuration.setTargetDirectory(classesDir);
    try {
        compileScript(source, classLoader, configuration, classesDir, transformer, verifier);
    } catch (GradleException e) {
        GFileUtils.deleteDirectory(classesDir);
        throw e;
    }

    logger.debug("Timing: Writing script to cache at {} took: {}", classesDir.getAbsolutePath(),
            clock.getTime());
}
 
Example 4
Source File: OptionsFileArgsTransformer.java    From Pushjet-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 5
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 6
Source File: GroovyCompile.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@TaskAction
protected void compile() {
    checkGroovyClasspathIsNonEmpty();
    DefaultGroovyJavaJointCompileSpec spec = new DefaultGroovyJavaJointCompileSpec();
    spec.setSource(getSource());
    spec.setDestinationDir(getDestinationDir());
    spec.setClasspath(getClasspath());
    spec.setSourceCompatibility(getSourceCompatibility());
    spec.setTargetCompatibility(getTargetCompatibility());
    spec.setGroovyClasspath(getGroovyClasspath());
    spec.setCompileOptions(compileOptions);
    spec.setGroovyCompileOptions(groovyCompileOptions);
    if (spec.getGroovyCompileOptions().getStubDir() == null) {
        File dir = tempFileProvider.newTemporaryFile("groovy-java-stubs");
        GFileUtils.mkdirs(dir);
        spec.getGroovyCompileOptions().setStubDir(dir);
    }
    WorkResult result = compiler.execute(spec);
    setDidWork(result.getDidWork());
}
 
Example 7
Source File: InMemoryCacheFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public PersistentCache open(File cacheDir, String displayName, CacheUsage usage, CacheValidator cacheValidator, Map<String, ?> properties, LockOptions lockOptions, Action<? super PersistentCache> initializer) {
    GFileUtils.mkdirs(cacheDir);
    InMemoryCache cache = new InMemoryCache(cacheDir);
    if (initializer != null) {
        initializer.execute(cache);
    }
    return cache;
}
 
Example 8
Source File: DefaultTemporaryFileProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public File createTemporaryDirectory(@Nullable String prefix, @Nullable String suffix, @Nullable String... path) {
    File dir = new File(baseDirFactory.create(), CollectionUtils.join("/", path));
    GFileUtils.mkdirs(dir);
    try {
        // TODO: This is not a great paradigm for creating a temporary directory.
        // See http://guava-libraries.googlecode.com/svn/tags/release08/javadoc/com/google/common/io/Files.html#createTempDir%28%29 for an alternative.
        File tmpDir = File.createTempFile("gradle", "projectDir", dir);
        tmpDir.delete();
        tmpDir.mkdir();
        return tmpDir;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 9
Source File: DefaultCacheAwareExternalResourceAccessor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private LocallyAvailableExternalResource copyToCache(final URI source, final ResourceFileStore fileStore, final ExternalResource resource) {
    if (resource == null) {
        return null;
    }

    final File destination = temporaryFileProvider.createTemporaryFile("gradle_download", "bin");
    try {
        try {
            try {
                LOGGER.debug("Downloading {} to {}", resource.getName(), destination);
                if (destination.getParentFile() != null) {
                    GFileUtils.mkdirs(destination.getParentFile());
                }
                resource.writeTo(destination);
            } finally {
                resource.close();
            }
        } catch (IOException e) {
            throw new ResourceException(String.format("Failed to download resource '%s'.", resource.getName()), e);
        }
        return cacheLockingManager.useCache(String.format("Store %s", resource.getName()), new Factory<LocallyAvailableExternalResource>() {
            public LocallyAvailableExternalResource create() {
                LocallyAvailableResource cachedResource = fileStore.moveIntoCache(destination);
                File fileInFileStore = cachedResource.getFile();
                ExternalResourceMetaData metaData = resource.getMetaData();
                cachedExternalResourceIndex.store(source.toString(), fileInFileStore, metaData);
                return new DefaultLocallyAvailableExternalResource(source, cachedResource, metaData);
            }
        });
    } finally {
        destination.delete();
    }
}
 
Example 10
Source File: AbstractFileTreeElement.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean copyTo(File target) {
    validateTimeStamps();
    try {
        if (isDirectory()) {
            GFileUtils.mkdirs(target);
        } else {
            GFileUtils.mkdirs(target.getParentFile());
            copyFile(target);
        }
        chmod.chmod(target, getMode());
        return true;
    } catch (Exception e) {
        throw new GradleException(String.format("Could not copy %s to '%s'.", getDisplayName(), target), e);
    }
}
 
Example 11
Source File: DefaultPersistentDirectoryStore.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultPersistentDirectoryStore open() {
    GFileUtils.mkdirs(dir);
    cacheAccess = createCacheAccess();
    try {
        cacheAccess.open(lockOptions);
    } catch (Throwable e) {
        throw new CacheOpenException(String.format("Could not open %s.", this), e);
    }

    return this;
}
 
Example 12
Source File: DefaultTemporaryFileProvider.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public File createTemporaryDirectory(@Nullable String prefix, @Nullable String suffix, @Nullable String... path) {
    File dir = new File(baseDirFactory.create(), CollectionUtils.join("/", path));
    GFileUtils.mkdirs(dir);
    try {
        // TODO: This is not a great paradigm for creating a temporary directory.
        // See http://guava-libraries.googlecode.com/svn/tags/release08/javadoc/com/google/common/io/Files.html#createTempDir%28%29 for an alternative.
        File tmpDir = File.createTempFile("gradle", "projectDir", dir);
        tmpDir.delete();
        tmpDir.mkdir();
        return tmpDir;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 13
Source File: DefaultFileOperations.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public File mkdir(Object path) {
    File dir = fileResolver.resolve(path);
    if (dir.isFile()) {
        throw new InvalidUserDataException(String.format("Can't create directory. The path=%s points to an existing file.", path));
    }
    GFileUtils.mkdirs(dir);
    return dir;
}
 
Example 14
Source File: InMemoryCacheFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public PersistentCache open(File cacheDir, String displayName, CacheValidator cacheValidator, Map<String, ?> properties, LockOptions lockOptions, Action<? super PersistentCache> initializer) {
    GFileUtils.mkdirs(cacheDir);
    InMemoryCache cache = new InMemoryCache(cacheDir);
    if (initializer != null) {
        initializer.execute(cache);
    }
    return cache;
}
 
Example 15
Source File: DefaultPersistentDirectoryStore.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultPersistentDirectoryStore open() {
    GFileUtils.mkdirs(dir);
    cacheAccess = createCacheAccess();
    try {
        cacheAccess.open(lockOptions);
    } catch (Throwable e) {
        throw new CacheOpenException(String.format("Could not open %s.", this), e);
    }

    return this;
}
 
Example 16
Source File: AntlrTask.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@TaskAction
public void generate() {
    // Determine the grammar files and the proper ordering amongst them
    XRef xref = new MetadataExtracter().extractMetadata(getSource());
    List<GenerationPlan> generationPlans = new GenerationPlanBuilder(outputDirectory).buildGenerationPlans(xref);

    for (GenerationPlan generationPlan : generationPlans) {
        if (!generationPlan.isOutOfDate()) {
            LOGGER.info("grammar [" + generationPlan.getId() + "] was up-to-date; skipping");
            continue;
        }

        LOGGER.info("performing grammar generation [" + generationPlan.getId() + "]");

        //noinspection ResultOfMethodCallIgnored
        GFileUtils.mkdirs(generationPlan.getGenerationDirectory());

        ANTLR antlr = new ANTLR();
        antlr.setProject(getAnt().getAntProject());
        Path antlrTaskClasspath = antlr.createClasspath();
        for (File dep : getAntlrClasspath()) {
            antlrTaskClasspath.createPathElement().setLocation(dep);
        }
        antlr.setTrace(trace);
        antlr.setTraceLexer(traceLexer);
        antlr.setTraceParser(traceParser);
        antlr.setTraceTreeWalker(traceTreeWalker);
        antlr.setOutputdirectory(generationPlan.getGenerationDirectory());
        antlr.setTarget(generationPlan.getSource());

        antlr.execute();
    }
}
 
Example 17
Source File: DefaultCacheAwareExternalResourceAccessor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private LocallyAvailableExternalResource copyToCache(final URI source, final ResourceFileStore fileStore, final ExternalResource resource) {
    if (resource == null) {
        return null;
    }

    final File destination = temporaryFileProvider.createTemporaryFile("gradle_download", "bin");
    try {
        try {
            try {
                LOGGER.debug("Downloading {} to {}", resource.getName(), destination);
                if (destination.getParentFile() != null) {
                    GFileUtils.mkdirs(destination.getParentFile());
                }
                resource.writeTo(destination);
            } finally {
                resource.close();
            }
        } catch (IOException e) {
            throw new ResourceException(String.format("Failed to download resource '%s'.", resource.getName()), e);
        }
        return cacheLockingManager.useCache(String.format("Store %s", resource.getName()), new Factory<LocallyAvailableExternalResource>() {
            public LocallyAvailableExternalResource create() {
                LocallyAvailableResource cachedResource = fileStore.moveIntoCache(destination);
                File fileInFileStore = cachedResource.getFile();
                ExternalResourceMetaData metaData = resource.getMetaData();
                cachedExternalResourceIndex.store(source.toString(), fileInFileStore, metaData);
                return new DefaultLocallyAvailableExternalResource(source, cachedResource, metaData);
            }
        });
    } finally {
        destination.delete();
    }
}
 
Example 18
Source File: DefaultTemporaryFileProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
    }
}
 
Example 19
Source File: AbstractFileTreeElement.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean copyTo(File target) {
    validateTimeStamps();
    try {
        if (isDirectory()) {
            GFileUtils.mkdirs(target);
        } else {
            GFileUtils.mkdirs(target.getParentFile());
            copyFile(target);
        }
        chmod.chmod(target, getMode());
        return true;
    } catch (Exception e) {
        throw new GradleException(String.format("Could not copy %s to '%s'.", getDisplayName(), target), e);
    }
}
 
Example 20
Source File: AntlrTask.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@TaskAction
public void generate() {
    // Determine the grammar files and the proper ordering amongst them
    XRef xref = new MetadataExtracter().extractMetadata(getSource());
    List<GenerationPlan> generationPlans = new GenerationPlanBuilder(outputDirectory).buildGenerationPlans(xref);

    for (GenerationPlan generationPlan : generationPlans) {
        if (!generationPlan.isOutOfDate()) {
            LOGGER.info("grammar [" + generationPlan.getId() + "] was up-to-date; skipping");
            continue;
        }

        LOGGER.info("performing grammar generation [" + generationPlan.getId() + "]");

        //noinspection ResultOfMethodCallIgnored
        GFileUtils.mkdirs(generationPlan.getGenerationDirectory());

        ANTLR antlr = new ANTLR();
        antlr.setProject(getAnt().getAntProject());
        Path antlrTaskClasspath = antlr.createClasspath();
        for (File dep : getAntlrClasspath()) {
            antlrTaskClasspath.createPathElement().setLocation(dep);
        }
        antlr.setTrace(trace);
        antlr.setTraceLexer(traceLexer);
        antlr.setTraceParser(traceParser);
        antlr.setTraceTreeWalker(traceTreeWalker);
        antlr.setOutputdirectory(generationPlan.getGenerationDirectory());
        antlr.setTarget(generationPlan.getSource());

        antlr.execute();
    }
}