From ff469f4cc44486056eee29267fadcea5a354de99 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Sat, 18 Oct 2014 13:23:43 +0400 Subject: [PATCH] Repair m2e configurer in Windows --- .../eclipse/m2e/TeaVMProjectConfigurator.java | 39 +++++++++---------- .../PreferencesBasedTeaVMProjectSettings.java | 7 +++- .../org/teavm/eclipse/TeaVMEclipsePlugin.java | 13 ++++++- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java b/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java index 49d9c9df2..cfb3076c5 100644 --- a/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java @@ -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 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) { diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/PreferencesBasedTeaVMProjectSettings.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/PreferencesBasedTeaVMProjectSettings.java index b9537bdab..eba86cd1f 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/PreferencesBasedTeaVMProjectSettings.java +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/PreferencesBasedTeaVMProjectSettings.java @@ -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(); } diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMEclipsePlugin.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMEclipsePlugin.java index 6a7ca4852..9e2074a6a 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMEclipsePlugin.java +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMEclipsePlugin.java @@ -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);