Repair m2e configurer in Windows

This commit is contained in:
konsoletyper 2014-10-18 13:23:43 +04:00
parent 5bb3cbde65
commit ff469f4cc4
3 changed files with 35 additions and 24 deletions

View File

@ -1,5 +1,6 @@
package org.teavm.eclipse.m2e;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
@ -57,8 +58,11 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator {
}
monitor.beginTask("Configuring TeaVM builder", sz * 1000);
TeaVMProjectSettings settings = teaVMPlugin.getSettings(project);
settings.load();
try {
if (!hasNature) {
teaVMPlugin.addNature(new SubProgressMonitor(monitor, 1000), project);
}
settings.load();
Set<String> coveredProfiles = new HashSet<>();
for (MojoExecution execution : executions) {
if (monitor.isCanceled()) {
@ -82,9 +86,6 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator {
settings.deleteProfile(profile);
}
}
if (!hasNature) {
teaVMPlugin.addNature(new SubProgressMonitor(monitor, 1000), project);
}
settings.save();
} finally {
monitor.done();
@ -179,24 +180,20 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator {
}
private String absolutePathToWorkspacePath(String path) {
try {
IStringVariableManager varManager = VariablesPlugin.getDefault().getStringVariableManager();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IContainer[] containers = root.findContainersForLocationURI(new URI("file://" + path));
if (containers.length == 0) {
return null;
}
IContainer container = containers[0];
String suffix = "";
while (!(container instanceof IProject)) {
suffix = "/" + container.getName() + suffix;
container = container.getParent();
}
path = container.getFullPath().toString();
return varManager.generateVariableExpression("workspace_loc", path) + suffix;
} catch (URISyntaxException e) {
throw new RuntimeException(e);
IStringVariableManager varManager = VariablesPlugin.getDefault().getStringVariableManager();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IContainer[] containers = root.findContainersForLocationURI(new File(path).toURI());
if (containers.length == 0) {
return null;
}
IContainer container = containers[0];
String suffix = "";
while (!(container instanceof IProject)) {
suffix = "/" + container.getName() + suffix;
container = container.getParent();
}
path = container.getFullPath().toString();
return varManager.generateVariableExpression("workspace_loc", path) + suffix;
}
private TeaVMRuntimeMode getRuntimeMode(String name) {

View File

@ -53,8 +53,11 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
private String projectName;
public PreferencesBasedTeaVMProjectSettings(IProject project) {
ProjectScope scope = new ProjectScope(project);
globalPreferences = scope.getNode(TeaVMEclipsePlugin.ID);
this(project, new ProjectScope(project).getNode(TeaVMEclipsePlugin.ID));
}
public PreferencesBasedTeaVMProjectSettings(IProject project, IEclipsePreferences preferences) {
globalPreferences = preferences;
projectName = project.getName();
}

View File

@ -16,18 +16,21 @@
package org.teavm.eclipse;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.service.prefs.BackingStoreException;
/**
*
@ -90,6 +93,14 @@ public class TeaVMEclipsePlugin extends AbstractUIPlugin {
}
public void addNature(IProgressMonitor progressMonitor, IProject project) throws CoreException {
ProjectScope scope = new ProjectScope(project);
try {
IEclipsePreferences prefs = scope.getNode(TeaVMEclipsePlugin.ID);
prefs.flush();
settingsMap.put(project, new PreferencesBasedTeaVMProjectSettings(project, prefs));
} catch (BackingStoreException e) {
throw new RuntimeException("Error creating preferences", e);
}
IProjectDescription projectDescription = project.getDescription();
String[] natureIds = projectDescription.getNatureIds();
natureIds = Arrays.copyOf(natureIds, natureIds.length + 1);