Search in sources :

Example 1 with PlatformHelper

use of org.curioswitch.gradle.helpers.platform.PlatformHelper in project curiostack by curioswitch.

the class UpdateIntelliJSdksTask method exec.

@TaskAction
public void exec() throws IOException {
    final Path intelliJConfigFolder;
    switch(new PlatformHelper().getOs()) {
        case LINUX:
            intelliJConfigFolder = Paths.get(System.getProperty("user.home"), ".config", "JetBrains");
            break;
        case MAC_OSX:
            intelliJConfigFolder = Paths.get(System.getProperty("user.home"), "Library", "Application Support", "JetBrains");
            break;
        case WINDOWS:
            intelliJConfigFolder = Paths.get(System.getProperty("user.home"), "AppData", "Roaming", "JetBrains");
            break;
        case UNKNOWN:
        default:
            throw new GradleException("Unsupported OS");
    }
    final List<Path> intelliJFolders;
    try (var files = Files.list(intelliJConfigFolder)) {
        intelliJFolders = files.filter(path -> Files.isDirectory(path) && (path.getFileName().toString().startsWith(".IntelliJIdea") || path.getFileName().toString().startsWith(".IdeaIC"))).sorted().collect(toImmutableList());
    }
    final Path intelliJFolder;
    if (!intelliJFolders.isEmpty()) {
        intelliJFolder = Iterables.getLast(intelliJFolders);
    } else {
        getProject().getLogger().info("No IntelliJ config folder found, writing to default location.");
        intelliJFolder = intelliJConfigFolder.resolve(LATEST_INTELLIJ_CONFIG_FOLDER);
    }
    getProject().getLogger().info("Updating IntelliJ folder {}, found folders {}", intelliJFolder, intelliJFolders);
    String majorVersion = ToolDependencies.getOpenJdkVersion(getProject());
    String javaVersion = Files.readString(getProject().getRootProject().file(".gradle/jdk-release-name.txt").toPath());
    var jdkTable = Files.createDirectories(intelliJFolder.resolve("config/options")).resolve("jdk.table.xml");
    updateConfig(jdkTable, "jdk-" + javaVersion, majorVersion, "curiostack/openjdk-intellij-table-snippet.template.xml", ImmutableMap.of("javaVersion", javaVersion, "javaModules", JAVA_MODULES, "majorVersion", majorVersion), getProject());
    // We optimistically update Go SDKs as well even if the build doesn't use Go. The worst that
    // could happen is a couple of red SDKs in the IntelliJ lists.
    updateGoSdk(intelliJFolder, getProject());
    updateGoPath(intelliJFolder, getProject());
}
Also used : Path(java.nio.file.Path) PlatformHelper(org.curioswitch.gradle.helpers.platform.PlatformHelper) Iterables(com.google.common.collect.Iterables) ImmutableMap(com.google.common.collect.ImmutableMap) Resources(com.google.common.io.Resources) Files(java.nio.file.Files) Project(org.gradle.api.Project) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PlatformHelper(org.curioswitch.gradle.helpers.platform.PlatformHelper) ToolDependencies(org.curioswitch.gradle.plugins.curiostack.ToolDependencies) Jinjava(com.hubspot.jinjava.Jinjava) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) TaskAction(org.gradle.api.tasks.TaskAction) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Paths(java.nio.file.Paths) GradleException(org.gradle.api.GradleException) Map(java.util.Map) DownloadedToolManager(org.curioswitch.gradle.tooldownloader.DownloadedToolManager) CommandUtil(org.curioswitch.gradle.plugins.shared.CommandUtil) DefaultTask(org.gradle.api.DefaultTask) VisibleForTesting(com.google.common.annotations.VisibleForTesting) OperatingSystem(org.curioswitch.gradle.helpers.platform.OperatingSystem) Path(java.nio.file.Path) GradleException(org.gradle.api.GradleException) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with PlatformHelper

use of org.curioswitch.gradle.helpers.platform.PlatformHelper in project curiostack by curioswitch.

the class FetchCodeCovCacheTask method exec.

@TaskAction
public void exec() {
    ExternalExecUtil.exec(getProject(), workerExecutor, exec -> {
        var toolManager = DownloadedToolManager.get(getProject());
        String gsutil = new PlatformHelper().getOs() == OperatingSystem.WINDOWS ? "gsutil.cmd" : "gsutil";
        exec.executable("bash");
        exec.args("-c", gsutil + " cp " + src.get() + " - | tar -xpz --skip-old-files");
        exec.setIgnoreExitValue(true);
        toolManager.addAllToPath(exec);
    });
}
Also used : PlatformHelper(org.curioswitch.gradle.helpers.platform.PlatformHelper) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with PlatformHelper

use of org.curioswitch.gradle.helpers.platform.PlatformHelper in project curiostack by curioswitch.

the class InstallCondaPackagesTask method exec.

@TaskAction
void exec() {
    Path toolDir = toolManager.getToolDir(name);
    getProject().exec(exec -> {
        OperatingSystem operatingSystem = new PlatformHelper().getOs();
        if (operatingSystem == OperatingSystem.WINDOWS) {
            exec.executable(toolDir.resolve("Scripts").resolve("conda.exe"));
        } else {
            exec.executable(toolDir.resolve("bin").resolve("conda"));
        }
        exec.args("install", "-y");
        exec.args(packages.get());
        toolManager.addAllToPath(exec);
    });
    getProject().delete(toolDir.resolve("pkgs"));
}
Also used : Path(java.nio.file.Path) OperatingSystem(org.curioswitch.gradle.helpers.platform.OperatingSystem) PlatformHelper(org.curioswitch.gradle.helpers.platform.PlatformHelper) TaskAction(org.gradle.api.tasks.TaskAction)

Example 4 with PlatformHelper

use of org.curioswitch.gradle.helpers.platform.PlatformHelper in project curiostack by curioswitch.

the class AwsSetupPlugin method apply.

@Override
public void apply(Project project) {
    checkState(project.getParent() == null, "AwsSetupPlugin must be applied to root project.");
    var toolDownloaderPlugin = project.getPlugins().apply(ToolDownloaderPlugin.class);
    var operatingSystem = new PlatformHelper().getOs();
    toolDownloaderPlugin.registerToolIfAbsent("awscli", tool -> {
        tool.getVersion().set(ToolDependencies.getAwsCliVersion(project));
        tool.getBaseUrl().set("https://awscli.amazonaws.com/");
        tool.getArtifactPattern().set("[artifact].[ext]");
        if (operatingSystem == OperatingSystem.LINUX) {
            tool.getArtifact().set("awscli-exe-linux-x86_64");
        } else {
            tool.getArtifact().set("AWSCLIV2");
        }
        var osExtensions = tool.getOsExtensions();
        osExtensions.getLinux().set("zip");
        osExtensions.getMac().set("pkg");
        osExtensions.getWindows().set("msi");
        if (operatingSystem == OperatingSystem.WINDOWS) {
            tool.getPathSubDirs().add("Amazon/AWSCLIV2");
        }
    });
    if (operatingSystem != OperatingSystem.LINUX) {
        var downloadTool = DownloadToolUtil.getDownloadTask(project, "awscli");
        downloadTool.configure(t -> {
            t.setArchiveExtractAction(archive -> {
                var toolDir = toolDownloaderPlugin.toolManager().getToolDir("awscli");
                if (operatingSystem == OperatingSystem.WINDOWS) {
                    project.exec(exec -> {
                        exec.executable("cmd");
                        exec.args("/c", "start /wait msiexec /a " + archive.getAbsolutePath() + " TARGETDIR=" + toolDir.toAbsolutePath().toString() + " /qn");
                    });
                }
            });
        });
    }
}
Also used : PlatformHelper(org.curioswitch.gradle.helpers.platform.PlatformHelper)

Example 5 with PlatformHelper

use of org.curioswitch.gradle.helpers.platform.PlatformHelper in project curiostack by curioswitch.

the class NodeTask method exec.

@TaskAction
public void exec() {
    ExternalExecUtil.exec(getProject(), workerExecutor, exec -> {
        var toolManager = DownloadedToolManager.get(getProject());
        String command = this.command.get();
        if (new PlatformHelper().getOs() == OperatingSystem.WINDOWS) {
            if (command.equals("node")) {
                command += ".exe";
            } else {
                command += ".cmd";
            }
        }
        Path binDir = toolManager.getBinDir("node");
        exec.executable(binDir.resolve(command));
        exec.args(args.get());
        toolManager.addAllToPath(exec, getProject().getRootProject().file("node_modules/.bin").toPath());
        execOverrides.forEach(o -> o.execute(exec));
        CondaExecUtil.condaExec(exec, getProject());
    });
}
Also used : PlatformHelper(org.curioswitch.gradle.helpers.platform.PlatformHelper) Path(java.nio.file.Path) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

PlatformHelper (org.curioswitch.gradle.helpers.platform.PlatformHelper)11 Path (java.nio.file.Path)6 OperatingSystem (org.curioswitch.gradle.helpers.platform.OperatingSystem)6 TaskAction (org.gradle.api.tasks.TaskAction)6 IOException (java.io.IOException)3 DownloadedToolManager (org.curioswitch.gradle.tooldownloader.DownloadedToolManager)3 Project (org.gradle.api.Project)3 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 File (java.io.File)2 UncheckedIOException (java.io.UncheckedIOException)2 Files (java.nio.file.Files)2 Paths (java.nio.file.Paths)2 List (java.util.List)2 ToolDependencies (org.curioswitch.gradle.plugins.curiostack.ToolDependencies)2 ToolDownloaderPlugin (org.curioswitch.gradle.tooldownloader.ToolDownloaderPlugin)2 DownloadToolUtil (org.curioswitch.gradle.tooldownloader.util.DownloadToolUtil)2 DefaultTask (org.gradle.api.DefaultTask)2 Plugin (org.gradle.api.Plugin)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1