Merge pull request #48 from badsyntax/extension-conflict-2

Change task definition for better extension support
This commit is contained in:
Richard Willis 2019-11-14 18:10:35 +01:00 коммит произвёл GitHub
Родитель ece1b94bcd f52f62fa1b
Коммит 2097916814
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 27 добавлений и 31 удалений

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

@ -162,21 +162,17 @@
{
"type": "gradle",
"required": [
"task",
"buildFile"
"script",
"fileName"
],
"properties": {
"task": {
"script": {
"type": "string",
"description": "Gradle task name"
"description": "The task script name"
},
"buildFile": {
"fileName": {
"type": "string",
"description": "The build file that provides the task"
},
"subProjectBuildFile": {
"type": "string",
"description": "The subproject build file that provides the task"
"description": "The filename of the build file that provides the tasks"
}
}
}

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

@ -248,13 +248,13 @@ export class GradleTasksTreeDataProvider
buildFileTreeItem = new GradleBuildFileTreeItem(
workspaceTreeItem,
relativePath,
definition.buildFile
definition.fileName
);
workspaceTreeItem.addGradleBuildFileTreeItem(buildFileTreeItem);
buildFileTreeItems.set(fullPath, buildFileTreeItem);
}
if (showNestedSubProjects && definition.subProjectBuildFile) {
const [subProjectName] = task.definition.task.split(':');
if (showNestedSubProjects && definition.script.includes(':')) {
const [subProjectName] = definition.script.split(':');
let subProjectTreeItem = subProjectTreeItems.get(subProjectName);
if (!subProjectTreeItem) {
subProjectTreeItem = new SubProjectTreeItem(
@ -272,7 +272,7 @@ export class GradleTasksTreeDataProvider
subProjectBuildFileTreeItem = new GradleBuildFileTreeItem(
workspaceTreeItem,
relativePath,
path.basename(definition.subProjectBuildFile)
definition.fileName
);
subProjectTreeItem.addGradleBuildFileTreeItem(
subProjectBuildFileTreeItem

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

@ -17,9 +17,8 @@ export function enableTaskDetection() {
}
export interface GradleTaskDefinition extends vscode.TaskDefinition {
task: string;
buildFile: string;
subProjectBuildFile: string | undefined;
script: string;
fileName: string;
}
export class GradleTaskProvider implements vscode.TaskProvider {
@ -43,7 +42,7 @@ export class GradleTaskProvider implements vscode.TaskProvider {
public async resolveTask(
_task: vscode.Task
): Promise<vscode.Task | undefined> {
const gradleTask = (<any>_task.definition).task;
const gradleTask = (<any>_task.definition).script;
if (gradleTask) {
const { definition } = <any>_task;
let gradleBuildFileUri: vscode.Uri;
@ -68,7 +67,7 @@ export class GradleTaskProvider implements vscode.TaskProvider {
if (folder) {
return createTask(
definition,
definition.task,
definition.script,
_task.scope,
gradleBuildFileUri,
await getGradleWrapperCommandFromPath(folder.uri.fsPath)
@ -215,21 +214,19 @@ export async function createTask(
command: string
): Promise<vscode.Task> {
let definition: GradleTaskDefinition;
let fileName: string = path.basename(gradleBuildFileUri.fsPath);
if (typeof taskDefinitionOrTaskName === 'string') {
let subProjectBuildFile: string | undefined = undefined;
if (taskDefinitionOrTaskName.includes(':')) {
const [subProjectName] = taskDefinitionOrTaskName.split(':');
const subProjectPath = path.join(folder.uri.fsPath, subProjectName);
const folderUri = vscode.Uri.file(subProjectPath);
const buildFile = (await getBuildFilePaths(folderUri))[0];
subProjectBuildFile = buildFile.fsPath;
const uri = (await getBuildFilePaths(folderUri))[0];
fileName = path.basename(uri.fsPath);
}
definition = {
type: 'gradle',
task: taskDefinitionOrTaskName,
buildFile: path.basename(gradleBuildFileUri.fsPath),
subProjectBuildFile
script: taskDefinitionOrTaskName,
fileName
};
} else {
definition = taskDefinitionOrTaskName;
@ -259,7 +256,10 @@ export async function createTask(
if (relativeBuildGradle.length) {
definition.path = relativeBuildGradle;
}
const normalizedTaskName = getTaskName(definition.task, relativeBuildGradle);
const normalizedTaskName = getTaskName(
definition.script,
relativeBuildGradle
);
const cwd = path.dirname(gradleBuildFileUri.fsPath);
const task = new vscode.Task(
definition,
@ -274,7 +274,7 @@ export async function createTask(
showReuseMessage: false,
focus: true
};
return task;
return Object.freeze(task);
}
export async function hasGradleBuildFile(): Promise<boolean> {

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

@ -32,7 +32,7 @@ describe(fixtureName, () => {
);
assert.ok(groovyDefaultTask);
if (groovyDefaultTask) {
assert.equal(groovyDefaultTask.definition.buildFile, 'build.gradle');
assert.equal(groovyDefaultTask.definition.fileName, 'build.gradle');
}
});
@ -42,7 +42,7 @@ describe(fixtureName, () => {
);
assert.ok(kotlinTask);
if (kotlinTask) {
assert.equal(kotlinTask.definition.buildFile, 'build.gradle.kts');
assert.equal(kotlinTask.definition.fileName, 'build.gradle.kts');
}
});
@ -53,7 +53,7 @@ describe(fixtureName, () => {
assert.ok(groovyCustomTask);
if (groovyCustomTask) {
assert.equal(
groovyCustomTask.definition.buildFile,
groovyCustomTask.definition.fileName,
'my-custom-build.gradle'
);
}