org.gradle.util.GFileUtils Java Examples

The following examples show how to use org.gradle.util.GFileUtils. 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: PathKeyFileStore.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected LocallyAvailableResource saveIntoFileStore(final File source, final File destination, final boolean isMove) {
    String verb = isMove ? "move" : "copy";

    if (!source.exists()) {
        throw new GradleException(String.format("Cannot %s '%s' into filestore @ '%s' as it does not exist", verb, source, destination));
    }

    String error = String.format("Failed to %s file '%s' into filestore at '%s' ", verb, source, destination);

    return doAdd(destination, error, new Action<File>() {
        public void execute(File file) {
            if (isMove) {
                GFileUtils.moveFile(source, destination);
            } else {
                GFileUtils.copyFile(source, destination);
            }
        }
    });
}
 
Example #2
Source File: DefaultFileLockManager.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public FileLock lock(File target, LockOptions options, String targetDisplayName, String operationDisplayName) {
    if (options.getMode() == LockMode.None) {
        throw new UnsupportedOperationException(String.format("No %s mode lock implementation available.", options));
    }
    File canonicalTarget = GFileUtils.canonicalise(target);
    if (!lockedFiles.add(canonicalTarget)) {
        throw new IllegalStateException(String.format("Cannot lock %s as it has already been locked by this process.", targetDisplayName));
    }
    try {
        int port = fileLockContentionHandler.reservePort();
        return new DefaultFileLock(canonicalTarget, options, targetDisplayName, operationDisplayName, port);
    } catch (Throwable t) {
        lockedFiles.remove(canonicalTarget);
        throw throwAsUncheckedException(t);
    }
}
 
Example #3
Source File: DefaultWindowsSdkLocator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void locateKitsInRegistry(String baseKey) {
    String[] versions = {
            VERSION_KIT_8,
            VERSION_KIT_81
    };
    String[] keys = {
            REGISTRY_KIT_8,
            REGISTRY_KIT_81
    };

    for (int i = 0; i != keys.length; ++i) {
        try {
            File kitDir = GFileUtils.canonicalise(new File(windowsRegistry.getStringValue(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, baseKey + REGISTRY_ROOTPATH_KIT, keys[i])));
            if (isWindowsSdk(kitDir)) {
                LOGGER.debug("Found Windows Kit {} at {}", versions[i], kitDir);
                addSdk(kitDir, versions[i], NAME_KIT + " " + versions[i]);
            } else {
                LOGGER.debug("Ignoring candidate Windows Kit directory {} as it does not look like a Windows Kit installation.", kitDir);
            }
        } catch (MissingRegistryEntryException e) {
            // Ignore the version if the string cannot be read
        }
    }
}
 
Example #4
Source File: DefaultWindowsSdkLocator.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void locateKitsInRegistry(String baseKey) {
    String[] versions = {
            VERSION_KIT_8,
            VERSION_KIT_81
    };
    String[] keys = {
            REGISTRY_KIT_8,
            REGISTRY_KIT_81
    };

    for (int i = 0; i != keys.length; ++i) {
        try {
            File kitDir = GFileUtils.canonicalise(new File(windowsRegistry.getStringValue(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, baseKey + REGISTRY_ROOTPATH_KIT, keys[i])));
            if (isWindowsSdk(kitDir)) {
                LOGGER.debug("Found Windows Kit {} at {}", versions[i], kitDir);
                addSdk(kitDir, versions[i], NAME_KIT + " " + versions[i]);
            } else {
                LOGGER.debug("Ignoring candidate Windows Kit directory {} as it does not look like a Windows Kit installation.", kitDir);
            }
        } catch (MissingRegistryEntryException e) {
            // Ignore the version if the string cannot be read
        }
    }
}
 
Example #5
Source File: PathKeyFileStore.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected LocallyAvailableResource saveIntoFileStore(final File source, final File destination, final boolean isMove) {
    String verb = isMove ? "move" : "copy";

    if (!source.exists()) {
        throw new GradleException(String.format("Cannot %s '%s' into filestore @ '%s' as it does not exist", verb, source, destination));
    }

    String error = String.format("Failed to %s file '%s' into filestore at '%s' ", verb, source, destination);

    return doAdd(destination, error, new Action<File>() {
        public void execute(File file) {
            if (isMove) {
                GFileUtils.moveFile(source, destination);
            } else {
                GFileUtils.copyFile(source, destination);
            }
        }
    });
}
 
Example #6
Source File: PathKeyFileStore.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected LocallyAvailableResource saveIntoFileStore(final File source, final File destination, final boolean isMove) {
    String verb = isMove ? "move" : "copy";

    if (!source.exists()) {
        throw new GradleException(String.format("Cannot %s '%s' into filestore @ '%s' as it does not exist", verb, source, destination));
    }

    String error = String.format("Failed to %s file '%s' into filestore at '%s' ", verb, source, destination);

    return doAdd(destination, error, new Action<File>() {
        public void execute(File file) {
            if (isMove) {
                GFileUtils.moveFile(source, destination);
            } else {
                GFileUtils.copyFile(source, destination);
            }
        }
    });
}
 
Example #7
Source File: GroovyCompile.java    From pushfish-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 #8
Source File: FileResourceConnector.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void upload(Factory<InputStream> source, Long contentLength, String destination) throws IOException {
    File target = getFile(destination);
    if (!target.canWrite()) {
        target.delete();
    } // if target is writable, the copy will overwrite it without requiring a delete
    GFileUtils.mkdirs(target.getParentFile());
    FileOutputStream fileOutputStream = new FileOutputStream(target);
    try {
        InputStream sourceInputStream = source.create();
        try {
            if (IOUtils.copy(sourceInputStream, fileOutputStream) == -1) {
                throw new IOException(String.format("File copy failed from %s to %s", source, target));
            }
        } finally {
            sourceInputStream.close();
        }
    } finally {
        fileOutputStream.close();
    }
}
 
Example #9
Source File: GradleBuildComparison.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private BuildComparisonResultRenderer<Writer> createResultRenderer(Charset encoding, final File reportDir, final Map<String, String> hostAttributes) {
    return new GradleBuildComparisonResultHtmlRenderer(
            comparisonResultRenderers,
            outcomeRenderers,
            encoding,
            sourceBuildExecuter,
            targetBuildExecuter,
            hostAttributes,
            new Transformer<String, File>() {
                public String transform(File original) {
                    return GFileUtils.relativePath(reportDir, original);
                }
            }
    );
}
 
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: DefaultTemporaryFileProvider.java    From pushfish-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 #12
Source File: DaemonDiagnostics.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String tailDaemonLog() {
    try {
        String tail = GFileUtils.tail(getDaemonLog(), TAIL_SIZE);
        return formatTail(tail);
    } catch (GFileUtils.TailReadingException e) {
        return "Unable to read from the daemon log file: " + getDaemonLog().getAbsolutePath() + ", because of: " + e.getCause();
    }
}
 
Example #13
Source File: StartParameter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Sets the build file to use to select the default project. Use null to disable selecting the default project using the build file.
 *
 * @param buildFile The build file. May be null.
 */
public void setBuildFile(File buildFile) {
    if (buildFile == null) {
        this.buildFile = null;
        setCurrentDir(null);
    } else {
        this.buildFile = GFileUtils.canonicalise(buildFile);
        setProjectDir(this.buildFile.getParentFile());
    }
}
 
Example #14
Source File: DefaultSourceIncludesResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void searchForDependency(Set<ResolvedInclude> dependencies, List<File> searchPath, String include) {
    for (File searchDir : searchPath) {
        File candidate = new File(searchDir, include);
        // TODO:DAZ This means that we'll never detect changed files if they are not on the defined include path
        if (candidate.isFile()) {
            dependencies.add(new ResolvedInclude(include, GFileUtils.canonicalise(candidate)));
            return;
        }
    }
}
 
Example #15
Source File: StartParameter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Sets the project directory to use to select the default project. Use null to use the default criteria for selecting the default project.
 *
 * @param projectDir The project directory. May be null.
 */
public void setProjectDir(File projectDir) {
    if (projectDir == null) {
        setCurrentDir(null);
        this.projectDir = null;
    } else {
        File canonicalFile = GFileUtils.canonicalise(projectDir);
        currentDir = canonicalFile;
        this.projectDir = canonicalFile;
    }
}
 
Example #16
Source File: TmpDirTemporaryFileProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public TmpDirTemporaryFileProvider() {
    super(new Factory<File>() {
        public File create() {
            return GFileUtils.canonicalise(new File(SystemProperties.getJavaIoTmpDir()));
        }
    });
}
 
Example #17
Source File: StartParameter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Sets the project directory to use to select the default project. Use null to use the default criteria for selecting the default project.
 *
 * @param projectDir The project directory. May be null.
 */
public void setProjectDir(File projectDir) {
    if (projectDir == null) {
        setCurrentDir(null);
        this.projectDir = null;
    } else {
        File canonicalFile = GFileUtils.canonicalise(projectDir);
        currentDir = canonicalFile;
        this.projectDir = canonicalFile;
    }
}
 
Example #18
Source File: GradleBuildComparison.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void writeReport(final BuildComparisonResult result, final File reportDir, FileStore<String> fileStore, final Map<String, String> hostAttributes) {
    if (reportDir.exists() && reportDir.list().length > 0) {
        GFileUtils.cleanDirectory(reportDir);
    }

    fileStore.moveFilestore(new File(reportDir, FILES_DIR_NAME));

    final Charset encoding = Charset.defaultCharset();
    IoActions.writeTextFile(new File(reportDir, HTML_REPORT_FILE_NAME), encoding.name(), new Action<BufferedWriter>() {
        public void execute(BufferedWriter writer) {
            createResultRenderer(encoding, reportDir, hostAttributes).render(result, writer);
        }
    });
}
 
Example #19
Source File: JarCache.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private FileInfo copyIntoCache(Factory<File> baseDirFactory, File source, long lastModified, long length, HashValue hashValue) {
    File baseDir = baseDirFactory.create();
    File cachedFile = new File(baseDir, hashValue.asCompactString() + '/' + source.getName());
    if (!cachedFile.isFile()) {
        // Has previously been added to the cache directory
        GFileUtils.copyFile(source, cachedFile);
    }
    FileInfo fileInfo = new FileInfo(lastModified, length, hashValue, cachedFile);
    cachedFiles.put(source, fileInfo);
    return fileInfo;
}
 
Example #20
Source File: DefaultPersistentDirectoryCache.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void initialize(FileLock fileLock) {
    for (File file : getBaseDir().listFiles()) {
        if (fileLock.isLockFile(file) || file.equals(propertiesFile)) {
            continue;
        }
        GFileUtils.forceDelete(file);
    }
    if (initAction != null) {
        initAction.execute(DefaultPersistentDirectoryCache.this);
    }
    GUtil.saveProperties(properties, propertiesFile);
    didRebuild = true;
}
 
Example #21
Source File: DefaultPersistentDirectoryCache.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void initialize(FileLock fileLock) {
    for (File file : getBaseDir().listFiles()) {
        if (fileLock.isLockFile(file) || file.equals(propertiesFile)) {
            continue;
        }
        GFileUtils.forceDelete(file);
    }
    if (initAction != null) {
        initAction.execute(DefaultPersistentDirectoryCache.this);
    }
    GUtil.saveProperties(properties, propertiesFile);
    didRebuild = true;
}
 
Example #22
Source File: GradleBuildComparison.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void writeReport(final BuildComparisonResult result, final File reportDir, FileStore<String> fileStore, final Map<String, String> hostAttributes) {
    if (reportDir.exists() && reportDir.list().length > 0) {
        GFileUtils.cleanDirectory(reportDir);
    }

    fileStore.moveFilestore(new File(reportDir, FILES_DIR_NAME));

    final Charset encoding = Charset.defaultCharset();
    IoActions.writeTextFile(new File(reportDir, HTML_REPORT_FILE_NAME), encoding.name(), new Action<BufferedWriter>() {
        public void execute(BufferedWriter writer) {
            createResultRenderer(encoding, reportDir, hostAttributes).render(result, writer);
        }
    });
}
 
Example #23
Source File: DefaultProjectDescriptor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultProjectDescriptor(DefaultProjectDescriptor parent, String name, File dir,
                                ProjectDescriptorRegistry projectDescriptorRegistry, FileResolver fileResolver) {
    this.parent = parent;
    this.name = name;
    this.fileResolver = fileResolver;
    this.dir = GFileUtils.canonicalise(dir);
    this.projectDescriptorRegistry = projectDescriptorRegistry;
    this.path = path(name);
    projectDescriptorRegistry.addProject(this);
    if (parent != null) {
        parent.getChildren().add(this);
    }
}
 
Example #24
Source File: VerifyingExternalResourceDownloader.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void get(ExternalResource resource, File destination) throws IOException {
    LOGGER.debug("Downloading {} to {}", resource.getName(), destination);
    if (destination.getParentFile() != null) {
        GFileUtils.mkdirs(destination.getParentFile());
    }

    try {
        resource.writeTo(destination);
    } finally {
        resource.close();
    }
}
 
Example #25
Source File: StartParameter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Sets the settings file to use for the build. Use null to use the default settings file.
 *
 * @param settingsFile The settings file to use. May be null.
 */
public void setSettingsFile(File settingsFile) {
    if (settingsFile == null) {
        this.settingsFile = null;
    } else {
        this.useEmptySettings = false;
        this.settingsFile = GFileUtils.canonicalise(settingsFile);
        currentDir = this.settingsFile.getParentFile();
    }
}
 
Example #26
Source File: ProjectBuilderImpl.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public File prepareProjectDir(File projectDir) {
    if (projectDir == null) {
        TemporaryFileProvider temporaryFileProvider = new TmpDirTemporaryFileProvider();
        projectDir = temporaryFileProvider.createTemporaryDirectory("gradle", "projectDir");
        // TODO deleteOnExit won't clean up non-empty directories (and it leaks memory for long-running processes).
        projectDir.deleteOnExit();
    } else {
        projectDir = GFileUtils.canonicalise(projectDir);
    }
    return projectDir;
}
 
Example #27
Source File: StartParameter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Sets the project directory to use to select the default project. Use null to use the default criteria for selecting the default project.
 *
 * @param projectDir The project directory. May be null.
 */
public void setProjectDir(File projectDir) {
    if (projectDir == null) {
        setCurrentDir(null);
        this.projectDir = null;
    } else {
        File canonicalFile = GFileUtils.canonicalise(projectDir);
        currentDir = canonicalFile;
        this.projectDir = canonicalFile;
    }
}
 
Example #28
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 #29
Source File: DefaultProjectDescriptor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultProjectDescriptor(DefaultProjectDescriptor parent, String name, File dir,
                                ProjectDescriptorRegistry projectDescriptorRegistry, FileResolver fileResolver) {
    this.parent = parent;
    this.name = name;
    this.fileResolver = fileResolver;
    this.dir = GFileUtils.canonicalise(dir);
    this.projectDescriptorRegistry = projectDescriptorRegistry;
    this.path = path(name);
    projectDescriptorRegistry.addProject(this);
    if (parent != null) {
        parent.getChildren().add(this);
    }
}
 
Example #30
Source File: TarFileTree.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public InputStream open() {
    if (read && file != null) {
        return GFileUtils.openInputStream(file);
    }
    if (read || tar.getCurrent() != entry) {
        throw new UnsupportedOperationException(String.format("The contents of %s has already been read.", this));
    }
    read = true;
    return tar;
}