Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #423 from tgodzik/add-mirror
Browse files Browse the repository at this point in the history
Add mirror env variable when set by the user
  • Loading branch information
tgodzik authored Feb 25, 2022
2 parents 04112b5 + ce3e31d commit a195d81
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/checkServerVersion.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { WorkspaceConfiguration } from "./interfaces/WorkspaceConfiguration";
import { ConfigurationTarget } from "./interfaces/ConfigurationTarget";
import * as semver from "semver";
import { ConfigurationTarget } from "./interfaces/ConfigurationTarget";
import { UserConfiguration } from "./interfaces/UserConfiguration";
import { WorkspaceConfiguration } from "./interfaces/WorkspaceConfiguration";

interface OnOutdatedParams {
message: string;
Expand All @@ -16,7 +17,7 @@ interface UpdateConfigParams {
configurationTarget: ConfigurationTarget;
}

const configSection = "serverVersion";
const configSection = UserConfiguration.ServerVersion;

interface CheckServerVersionParams {
config: WorkspaceConfiguration;
Expand Down
10 changes: 6 additions & 4 deletions src/detectLaunchConfigurationChanges.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UserConfiguration } from "./interfaces/UserConfiguration";
import { Workspace } from "./interfaces/Workspace";

interface PromptRestartParams {
Expand All @@ -13,10 +14,11 @@ export function detectLaunchConfigurationChanges(
): void {
workspace.onDidChangeConfiguration((e) => {
const promptRestartKeys = [
"serverVersion",
"serverProperties",
"javaHome",
"customRepositories",
UserConfiguration.ServerVersion,
UserConfiguration.ServerProperties,
UserConfiguration.JavaHome,
UserConfiguration.CustomRepositories,
UserConfiguration.CoursierMirror,
...additionalRestartKeys,
];
const shouldPromptRestart = promptRestartKeys.some((key) =>
Expand Down
5 changes: 5 additions & 0 deletions src/getJavaConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface JavaConfig {
javaOptions: string[];
javaPath: string;
coursierPath: string;
coursierMirrorFilePath: string | undefined;
extraEnv: {
[k: string]: string | undefined;
};
Expand All @@ -14,27 +15,31 @@ interface GetJavaConfigOptions {
workspaceRoot: string | undefined;
javaHome: string;
extensionPath: string;
coursierMirrorFilePath: string | undefined;
customRepositories: string[] | undefined;
}

export function getJavaConfig({
workspaceRoot,
javaHome,
extensionPath,
coursierMirrorFilePath,
customRepositories = [],
}: GetJavaConfigOptions): JavaConfig {
const javaOptions = getJavaOptions(workspaceRoot);
const javaPath = path.join(javaHome, "bin", "java");
const coursierPath = path.join(extensionPath, "./coursier");
const extraEnv = {
COURSIER_REPOSITORIES: customRepositories.join("|"),
COURSIER_MIRRORS: coursierMirrorFilePath,
JAVA_HOME: javaHome,
};

return {
javaOptions,
javaPath,
coursierPath,
coursierMirrorFilePath,
extraEnv,
};
}
2 changes: 1 addition & 1 deletion src/interfaces/ClientCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* These are all of the client commands that Metals supports. Note that not support
* may vary based on the `InitializationSettings` the client sets.
*
* - https://scalameta.org/metals/docs/editors/new-editor.html#metals-client-commands
* - https://scalameta.org/metals/docs/integrations/new-editor#metals-client-commands
*/
export const ClientCommands = {
/**
Expand Down
28 changes: 28 additions & 0 deletions src/interfaces/UserConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* These are some of the common user configuration options used in Metals and needed for the editors.
*
* - https://scalameta.org/metals/docs/integrations/new-editor#metals-user-configuration
*/
export enum UserConfiguration {
/**
* Metals server version
*/
ServerVersion = "serverVersion",
/**
* Metals server Java properties
*/
ServerProperties = "serverProperties",
/**
* Directory containing the Java binary.
*/
JavaHome = "javaHome",
/**
* Additional repositories that can be used to download dependencies.
* https://get-coursier.io/docs/other-repositories
*/
CustomRepositories = "customRepositories",
/**
* Repository to use instead of maven central for example `https://jcenter.bintray.com`
*/
CoursierMirror = "coursierMirror",
}

0 comments on commit a195d81

Please sign in to comment.