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

The following examples show how to use org.gradle.util.GFileUtils#canonicalise() . 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: 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 2
Source File: DefaultFileLockManager.java    From pushfish-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 locateSdkInPath() {
    File resourceCompiler = os.findInPath(RESOURCE_FILENAME);
    if (resourceCompiler == null) {
        LOGGER.debug("Could not find Windows resource compiler in system path.");
        return;
    }
    File sdkDir = GFileUtils.canonicalise(resourceCompiler.getParentFile().getParentFile());
    if (!isWindowsSdk(sdkDir)) {
        sdkDir = sdkDir.getParentFile();
        if (!isWindowsSdk(sdkDir)) {
            LOGGER.debug("Ignoring candidate Windows SDK for {} as it does not look like a Windows SDK installation.", resourceCompiler);
        }
    }
    LOGGER.debug("Found Windows SDK {} using system path", sdkDir);

    if (!foundSdks.containsKey(sdkDir)) {
        addSdk(sdkDir, "path", "Path-resolved Windows SDK");
    }
    pathSdk = foundSdks.get(sdkDir);
}
 
Example 4
Source File: DefaultWindowsSdkLocator.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void locateSdkInPath() {
    File resourceCompiler = os.findInPath(RESOURCE_FILENAME);
    if (resourceCompiler == null) {
        LOGGER.debug("Could not find Windows resource compiler in system path.");
        return;
    }
    File sdkDir = GFileUtils.canonicalise(resourceCompiler.getParentFile().getParentFile());
    if (!isWindowsSdk(sdkDir)) {
        sdkDir = sdkDir.getParentFile();
        if (!isWindowsSdk(sdkDir)) {
            LOGGER.debug("Ignoring candidate Windows SDK for {} as it does not look like a Windows SDK installation.", resourceCompiler);
        }
    }
    LOGGER.debug("Found Windows SDK {} using system path", sdkDir);

    if (!foundSdks.containsKey(sdkDir)) {
        addSdk(sdkDir, "path", "Path-resolved Windows SDK");
    }
    pathSdk = foundSdks.get(sdkDir);
}
 
Example 5
Source File: DefaultFileLockManager.java    From pushfish-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 6
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 7
Source File: DefaultWindowsSdkLocator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void locateSdkInPath() {
    File resourceCompiler = os.findInPath(RESOURCE_FILENAME);
    if (resourceCompiler == null) {
        LOGGER.debug("Could not find Windows resource compiler in system path.");
        return;
    }
    File sdkDir = GFileUtils.canonicalise(resourceCompiler.getParentFile().getParentFile());
    if (!isWindowsSdk(sdkDir)) {
        sdkDir = sdkDir.getParentFile();
        if (!isWindowsSdk(sdkDir)) {
            LOGGER.debug("Ignoring candidate Windows SDK for {} as it does not look like a Windows SDK installation.", resourceCompiler);
        }
    }
    LOGGER.debug("Found Windows SDK {} using system path", sdkDir);

    if (!foundSdks.containsKey(sdkDir)) {
        addSdk(sdkDir, "path", "Path-resolved Windows SDK");
    }
    pathSdk = foundSdks.get(sdkDir);
}
 
Example 8
Source File: StartParameter.java    From pushfish-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 9
Source File: DefaultVisualStudioLocator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private SearchResult locateUserSpecifiedInstall(File candidate) {
    File visualStudioDir = GFileUtils.canonicalise(candidate);
    File visualCppDir = new File(visualStudioDir, "VC");
    if (!isVisualStudio(visualStudioDir) || !isVisualCpp(visualCppDir)) {
        LOGGER.debug("Ignoring candidate Visual C++ install for {} as it does not look like a Visual C++ installation.", candidate);
        return new InstallNotFound(String.format("The specified installation directory '%s' does not appear to contain a Visual Studio installation.", candidate));
    }

    if (!foundInstalls.containsKey(visualStudioDir)) {
        VisualCppInstall visualCpp = buildVisualCppInstall("Visual C++ from user provided path", visualStudioDir, visualCppDir, VersionNumber.UNKNOWN);
        VisualStudioInstall visualStudio = new VisualStudioInstall(visualStudioDir, visualCpp);
        foundInstalls.put(visualStudioDir, visualStudio);
    }
    return new InstallFound(foundInstalls.get(visualStudioDir));
}
 
Example 10
Source File: DefaultVisualStudioLocator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void locateInstallsInRegistry(String baseKey) {
    List<String> visualCppVersions;
    try {
        visualCppVersions = windowsRegistry.getValueNames(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, baseKey + REGISTRY_ROOTPATH_VC);
    } catch (MissingRegistryEntryException e) {
        // No Visual Studio information available in the registry
        return;
    }

    for (String valueName : visualCppVersions) {
        if (!valueName.matches("\\d+\\.\\d+")) {
            // Ignore the other values
            continue;
        }
        File visualCppDir = new File(windowsRegistry.getStringValue(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, baseKey + REGISTRY_ROOTPATH_VC, valueName));
        visualCppDir = GFileUtils.canonicalise(visualCppDir);
        File visualStudioDir = visualCppDir.getParentFile();

        if (isVisualCpp(visualCppDir) && isVisualStudio(visualStudioDir)) {
            LOGGER.debug("Found Visual C++ {} at {}", valueName, visualCppDir);
            VersionNumber version = VersionNumber.parse(valueName);
            VisualCppInstall visualCpp = buildVisualCppInstall("Visual C++ " + valueName, visualStudioDir, visualCppDir, version);
            VisualStudioInstall visualStudio = new VisualStudioInstall(visualStudioDir, visualCpp);
            foundInstalls.put(visualStudioDir, visualStudio);
        } else {
            LOGGER.debug("Ignoring candidate Visual C++ directory {} as it does not look like a Visual C++ installation.", visualCppDir);
        }
    }
}
 
Example 11
Source File: StartParameter.java    From Pushjet-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 12
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 13
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 14
Source File: DefaultVisualStudioLocator.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void locateInstallsInRegistry(String baseKey) {
    List<String> visualCppVersions;
    try {
        visualCppVersions = windowsRegistry.getValueNames(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, baseKey + REGISTRY_ROOTPATH_VC);
    } catch (MissingRegistryEntryException e) {
        // No Visual Studio information available in the registry
        return;
    }

    for (String valueName : visualCppVersions) {
        if (!valueName.matches("\\d+\\.\\d+")) {
            // Ignore the other values
            continue;
        }
        File visualCppDir = new File(windowsRegistry.getStringValue(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, baseKey + REGISTRY_ROOTPATH_VC, valueName));
        visualCppDir = GFileUtils.canonicalise(visualCppDir);
        File visualStudioDir = visualCppDir.getParentFile();

        if (isVisualCpp(visualCppDir) && isVisualStudio(visualStudioDir)) {
            LOGGER.debug("Found Visual C++ {} at {}", valueName, visualCppDir);
            VersionNumber version = VersionNumber.parse(valueName);
            VisualCppInstall visualCpp = buildVisualCppInstall("Visual C++ " + valueName, visualStudioDir, visualCppDir, version);
            VisualStudioInstall visualStudio = new VisualStudioInstall(visualStudioDir, visualCpp);
            foundInstalls.put(visualStudioDir, visualStudio);
        } else {
            LOGGER.debug("Ignoring candidate Visual C++ directory {} as it does not look like a Visual C++ installation.", visualCppDir);
        }
    }
}
 
Example 15
Source File: EstablishBuildEnvironment.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void doBuild(DaemonCommandExecution execution, Build build) {
    Properties originalSystemProperties = new Properties();
    originalSystemProperties.putAll(System.getProperties());
    Map<String, String> originalEnv = new HashMap<String, String>(System.getenv());
    File originalProcessDir = GFileUtils.canonicalise(new File("."));

    for (Map.Entry<String, String> entry : build.getParameters().getSystemProperties().entrySet()) {
        if (SystemProperties.getStandardProperties().contains(entry.getKey())) {
            continue;
        }
        if (SystemProperties.getNonStandardImportantProperties().contains(entry.getKey())) {
            continue;
        }
        if (entry.getKey().startsWith("sun.")) {
            continue;
        }
        System.setProperty(entry.getKey(), entry.getValue());
    }

    LOGGER.debug("Configuring env variables: {}", build.getParameters().getEnvVariables());
    processEnvironment.maybeSetEnvironment(build.getParameters().getEnvVariables());
    processEnvironment.maybeSetProcessDir(build.getParameters().getCurrentDir());

    // Capture and restore this in case the build code calls Locale.setDefault()
    Locale locale = Locale.getDefault();

    try {
        execution.proceed();
    } finally {
        System.setProperties(originalSystemProperties);
        processEnvironment.maybeSetEnvironment(originalEnv);
        processEnvironment.maybeSetProcessDir(originalProcessDir);
        Locale.setDefault(locale);
    }
}
 
Example 16
Source File: DefaultWindowsSdkLocator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private SearchResult locateUserSpecifiedSdk(File candidate) {
    File sdkDir = GFileUtils.canonicalise(candidate);
    if (!isWindowsSdk(sdkDir)) {
        return new SdkNotFound(String.format("The specified installation directory '%s' does not appear to contain a Windows SDK installation.", candidate));
    }

    if (!foundSdks.containsKey(sdkDir)) {
        addSdk(sdkDir, VERSION_USER, NAME_USER);
    }
    return new SdkFound(foundSdks.get(sdkDir));
}
 
Example 17
Source File: DirectoryFileTree.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DirectoryFileTree(File dir, PatternSet patternSet) {
    this.patternSet = patternSet;
    this.dir = GFileUtils.canonicalise(dir);
}
 
Example 18
Source File: AvailableJavaHomes.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static File getJavaHome(String label) {
    String value = System.getenv().get(String.format("JDK_%s", label));
    return value == null ? null : GFileUtils.canonicalise(new File(value));
}
 
Example 19
Source File: DefaultProjectDescriptor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public File getBuildFile() {
    return GFileUtils.canonicalise(new File(dir, buildFileName));
}
 
Example 20
Source File: DirectoryFileTree.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DirectoryFileTree(File dir, PatternSet patternSet) {
    this.patternSet = patternSet;
    this.dir = GFileUtils.canonicalise(dir);
}