fix: Store the schema version of the BSP project after import (#1395)
Signed-off-by: Sheng Chen <sheche@microsoft.com>
This commit is contained in:
Родитель
f5858024eb
Коммит
51f21620df
|
@ -10,6 +10,9 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.core.internal.resources.Project;
|
||||
import org.eclipse.core.internal.resources.ProjectDescription;
|
||||
import org.eclipse.core.internal.resources.VariableDescription;
|
||||
import org.eclipse.core.resources.ICommand;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
|
@ -46,6 +49,9 @@ public class GradleBuildServerProjectImporter extends AbstractProjectImporter {
|
|||
|
||||
private static final String BSP_VERSION = "2.1.0-M4";
|
||||
|
||||
private static final String SCHEMA_VERSION_KEY = "bspSchemaVersion";
|
||||
private static final String SCHEMA_VERSION = "0.1.0";
|
||||
|
||||
public static final String BUILD_GRADLE_DESCRIPTOR = "build.gradle";
|
||||
public static final String BUILD_GRADLE_KTS_DESCRIPTOR = "build.gradle.kts";
|
||||
public static final String SETTINGS_GRADLE_DESCRIPTOR = "settings.gradle";
|
||||
|
@ -187,6 +193,10 @@ public class GradleBuildServerProjectImporter extends AbstractProjectImporter {
|
|||
String projectName = findFreeProjectName(directory.getName());
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
IProjectDescription projectDescription = workspace.newProjectDescription(projectName);
|
||||
if (projectDescription instanceof ProjectDescription description) {
|
||||
VariableDescription variableDescription = new VariableDescription(SCHEMA_VERSION_KEY, SCHEMA_VERSION);
|
||||
description.setVariableDescription(SCHEMA_VERSION_KEY, variableDescription);
|
||||
}
|
||||
projectDescription.setLocation(Path.fromOSString(directory.getPath()));
|
||||
projectDescription.setNatureIds(new String[]{ GradleBuildServerProjectNature.NATURE_ID });
|
||||
ICommand buildSpec = Utils.getBuildServerBuildSpec(projectDescription);
|
||||
|
@ -208,6 +218,17 @@ public class GradleBuildServerProjectImporter extends AbstractProjectImporter {
|
|||
Utils.getBuildServerBuildSpec(projectDescription),
|
||||
problemReporter
|
||||
}, monitor);
|
||||
|
||||
// Here we don't use the public API: {@code project.setDescription()} to update the project,
|
||||
// because that API will ignore the variable descriptions.
|
||||
if (project instanceof Project internalProject) {
|
||||
ProjectDescription description = internalProject.internalGetDescription();
|
||||
VariableDescription variableDescription = new VariableDescription(SCHEMA_VERSION_KEY, SCHEMA_VERSION);
|
||||
boolean changed = description.setVariableDescription(SCHEMA_VERSION_KEY, variableDescription);
|
||||
if (changed) {
|
||||
internalProject.writeDescription(IResource.NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String findFreeProjectName(String baseName) {
|
||||
|
|
|
@ -65,7 +65,7 @@ public class ImporterPlugin extends Plugin {
|
|||
|
||||
public static DigestStore getDigestStore() {
|
||||
return instance.digestStore;
|
||||
}
|
||||
}
|
||||
|
||||
public static BuildServer getBuildServerConnection(IPath rootPath) throws CoreException {
|
||||
Pair<BuildServer, BuildClient> pair = instance.buildServers.get(rootPath);
|
||||
|
|
|
@ -124,28 +124,13 @@ public class Utils {
|
|||
* @throws CoreException
|
||||
*/
|
||||
public static void addBuildSpec(IProject project, String[] buildNames, IProgressMonitor monitor) throws CoreException {
|
||||
SubMonitor progress = SubMonitor.convert(monitor, 1);
|
||||
// get the description
|
||||
IProjectDescription description = project.getDescription();
|
||||
List<ICommand> currentBuildSpecs = Arrays.asList(description.getBuildSpec());
|
||||
List<ICommand> newSpecs = new LinkedList<>();
|
||||
newSpecs.addAll(currentBuildSpecs);
|
||||
for (String buildName : buildNames) {
|
||||
if (currentBuildSpecs.stream().anyMatch(spec -> Objects.equals(spec.getBuilderName(), buildName))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ICommand[] commands = Arrays.stream(buildNames).map(buildName -> {
|
||||
ICommand buildSpec = description.newCommand();
|
||||
buildSpec.setBuilderName(buildName);
|
||||
newSpecs.add(0, buildSpec);
|
||||
}
|
||||
|
||||
if (newSpecs.size() == currentBuildSpecs.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
description.setBuildSpec(newSpecs.toArray(new ICommand[newSpecs.size()]));
|
||||
project.setDescription(description, IResource.AVOID_NATURE_CONFIG, progress.newChild(1));
|
||||
return buildSpec;
|
||||
}).toArray(ICommand[]::new);
|
||||
addBuildSpec(project, commands, monitor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче