Co-authored-by: mmsuo <mmsuo@travelsky.com>
This commit is contained in:
mannixsuo 2021-03-22 14:13:08 +08:00 коммит произвёл GitHub
Родитель 2ca0001682
Коммит 33c71d96fd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 45 добавлений и 10 удалений

Просмотреть файл

@ -192,6 +192,7 @@ Now right-click on an project item, and then click `Favorite ...`. The option `f
| `maven.terminal.customEnv` | Specifies an array of environment variable names and values. These environment variable values will be added to the terminal session before Maven is first executed. <br /> `environmentVariable`: Name of the environment variable to set. <br /> `value`: Value of the environment variable to set. | `[]` |
| `maven.terminal.favorites` | Specify pre-defined favorite commands to execute. <br /> `alias`: A short name for the command. <br /> `command`: Content of the favorite command. | `[]` |
| `maven.view` | Specifies the way of viewing Maven projects. Possible values: `flat`, `hierarchical`. | `flat` |
| `maven.settingsFile` | Specifies the absolute path of a maven configuration file| `~/.m2/settings.xml` |
## Data/Telemetry

Просмотреть файл

@ -429,6 +429,15 @@
{
"title": "Maven for Java",
"properties": {
"maven.settingsFile": {
"type": [
"string",
"null"
],
"default": "",
"description": "%configuration.maven.settingsFile%",
"scope": "machine"
},
"maven.excludedFolders": {
"type": "array",
"default": [

Просмотреть файл

@ -32,5 +32,6 @@
"configuration.maven.terminal.favorites": "Specify pre-defined favorite commands to execute.",
"configuration.maven.terminal.favorites.alias": "A short name for the command.",
"configuration.maven.terminal.favorites.command": "Content of the favorite command.",
"configuration.maven.terminal.favorites.debug": "Whether to execute in debug mode."
"configuration.maven.terminal.favorites.debug": "Whether to execute in debug mode.",
"configuration.maven.settingsFile":"Specifies the absolute path of your maven configuration file, the default value is ~/.m2/settings.xml"
}

Просмотреть файл

@ -31,5 +31,6 @@
"configuration.maven.terminal.favorites": "指定要执行的偏好命令。",
"configuration.maven.terminal.favorites.alias": "命令的简称。",
"configuration.maven.terminal.favorites.command": "命令的内容。",
"configuration.maven.terminal.favorites.debug": "是否以调试模式运行。"
"configuration.maven.terminal.favorites.debug": "是否以调试模式运行。",
"configuration.maven.settingsFile": "指定 maven 配置文件的绝对路径, 默认是 ~/.m2/settings.xml"
}

Просмотреть файл

@ -29,6 +29,10 @@ export namespace Settings {
workspace.getConfiguration().update("maven.executable.path", mvnPath, true);
}
export function getSettingsFilePath(): string | undefined {
return _getMavenSection<string>("settingsFile");
}
export namespace External {
export function javaHome(): string | undefined {
return workspace.getConfiguration("java").get<string>("home");

Просмотреть файл

@ -26,7 +26,7 @@ import { mavenOutputChannel } from "./mavenOutputChannel";
import { mavenTerminal } from "./mavenTerminal";
import { Settings } from "./Settings";
import { taskExecutor } from "./taskExecutor";
import { getAiKey, getExtensionId, getExtensionVersion, loadPackageInfo } from "./utils/contextUtils";
import { getAiKey, getExtensionId, getExtensionVersion, loadMavenSettingsFilePath, loadPackageInfo } from "./utils/contextUtils";
import { executeInTerminal } from "./utils/mavenUtils";
import { openFileIfExists, registerCommand } from "./utils/uiUtils";
import { Utils } from "./utils/Utils";
@ -158,6 +158,14 @@ function registerConfigChangeListener(context: vscode.ExtensionContext): void {
if (e.affectsConfiguration("maven.executable.preferMavenWrapper")) {
context.workspaceState.update("trustMavenWrapper", undefined);
}
// refresh MAVEN_LOCAL_REPOSITORY when change to a new settingsFile
if (e.affectsConfiguration("maven.settingsFile")) {
loadMavenSettingsFilePath().then(
//do nothing
).catch(
//do nothing
);
}
});
context.subscriptions.push(configChangeListener);
}
@ -203,7 +211,7 @@ async function refreshExplorerHandler(item?: ITreeItem): Promise<void> {
}
}
async function openPomHandler(node: MavenProject | {uri: string}): Promise<void> {
async function openPomHandler(node: MavenProject | { uri: string }): Promise<void> {
if (node instanceof MavenProject) {
if (node.pomPath) {
await openFileIfExists(node.pomPath);

Просмотреть файл

@ -272,4 +272,8 @@ export namespace Utils {
break;
}
}
export function settingsFilePath(): string | undefined {
return Settings.getSettingsFilePath();
}
}

Просмотреть файл

@ -28,19 +28,26 @@ export async function loadPackageInfo(context: ExtensionContext): Promise<void>
TEMP_FOLDER_PER_USER = path.join(os.tmpdir(), `${EXTENSION_NAME}-${os.userInfo().username}`);
// find Maven Local Repositry
await loadMavenSettingsFilePath();
if (!MAVEN_LOCAL_REPOSITORY) {
MAVEN_LOCAL_REPOSITORY = path.join(os.homedir(), ".m2", "repository");
}
}
export async function loadMavenSettingsFilePath(): Promise<void> {
// find Maven Local Repository
try {
const userSettingsPath: string = path.join(os.homedir(), ".m2", "settings.xml");
let userSettingsPath: string | undefined = Utils.settingsFilePath();
if (!userSettingsPath) {
userSettingsPath = path.join(os.homedir(), ".m2", "settings.xml");
}
const userSettings: {} | undefined = await Utils.parseXmlFile(userSettingsPath);
MAVEN_LOCAL_REPOSITORY = path.resolve(_.get(userSettings, "settings.localRepository[0]"));
mavenOutputChannel.appendLine(`local repository: ${MAVEN_LOCAL_REPOSITORY}`);
} catch (error) {
// ignore
}
if (!MAVEN_LOCAL_REPOSITORY) {
MAVEN_LOCAL_REPOSITORY = path.join(os.homedir(), ".m2", "repository");
}
}
export function getMavenLocalRepository(): string {