Skip to content

Commit

Permalink
Merge pull request #1498 from mliarakos/fix-coursier-properties
Browse files Browse the repository at this point in the history
use properties and environment when fetching metals
  • Loading branch information
tgodzik authored May 12, 2024
2 parents 12a8ba7 + 405492c commit 55a173d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
33 changes: 30 additions & 3 deletions packages/metals-languageclient/src/fetchMetals.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import * as semver from "semver";
import { ChildProcessPromise, spawn } from "promisify-child-process";
import { JavaConfig } from "./getJavaConfig";
import { OutputChannel } from "./interfaces/OutputChannel";

interface FetchMetalsOptions {
serverVersion: string;
serverProperties: string[];
javaConfig: JavaConfig;
outputChannel: OutputChannel;
}

/**
Expand All @@ -17,15 +20,30 @@ interface PackedChildPromise {

export async function fetchMetals({
serverVersion,
javaConfig: { coursier },
serverProperties,
javaConfig: { javaOptions, coursier, extraEnv },
outputChannel,
}: FetchMetalsOptions): Promise<PackedChildPromise> {
const serverDependency = calcServerDependency(serverVersion);

const fetchProperties = serverProperties.filter(
(p) => !p.startsWith("-agentlib")
);
if (fetchProperties.length != serverProperties.length) {
outputChannel.appendLine(
'Ignoring "-agentlib" option when fetching Metals with Coursier'
);
}

// Convert Java properties to the "-J" argument form used by Coursier
const javaArgs = javaOptions.concat(fetchProperties).map((p) => `-J${p}`);

const coursierArgs = [
...javaArgs,
"fetch",
"-p",
"--ttl",
// Use infinite ttl to avoid redunant "Checking..." logs when using SNAPSHOT
// Use infinite ttl to avoid redundant "Checking..." logs when using SNAPSHOT
// versions. Metals SNAPSHOT releases are effectively immutable since we
// never publish the same version twice.
"Inf",
Expand All @@ -39,7 +57,16 @@ export async function fetchMetals({
"-p",
];

return { promise: spawn(coursier, coursierArgs) };
const environment = {
env: {
...process.env,
...extraEnv,
},
};

return {
promise: spawn(coursier, coursierArgs, environment),
};
}

export function calcServerDependency(serverVersion: string): string {
Expand Down
2 changes: 2 additions & 0 deletions packages/metals-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ async function fetchAndLaunchMetals(

const fetchProcess = fetchMetals({
serverVersion,
serverProperties,
javaConfig,
outputChannel,
});

const title = `Downloading Metals v${serverVersion}`;
Expand Down

0 comments on commit 55a173d

Please sign in to comment.