Skip to content

Commit 4568238

Browse files
committed
Use preferences in property tester
The Maven property tester can hang the IDE as it query the project registry what might be a lengthy task. To determine if a project has workspace resolution we can simply go directly to the preferences.
1 parent aa33441 commit 4568238

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenPropertyTester.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
import org.eclipse.core.resources.IFolder;
1919
import org.eclipse.core.resources.IProject;
2020
import org.eclipse.core.resources.IResource;
21+
import org.eclipse.core.runtime.Adapters;
2122
import org.eclipse.core.runtime.CoreException;
22-
import org.eclipse.core.runtime.IAdaptable;
2323
import org.eclipse.core.runtime.IPath;
2424
import org.eclipse.core.runtime.NullProgressMonitor;
2525
import org.eclipse.ui.IFileEditorInput;
2626

2727
import org.eclipse.m2e.core.MavenPlugin;
2828
import org.eclipse.m2e.core.embedder.ArtifactKey;
2929
import org.eclipse.m2e.core.internal.IMavenConstants;
30+
import org.eclipse.m2e.core.internal.project.ResolverConfigurationIO;
3031
import org.eclipse.m2e.core.project.IMavenProjectFacade;
3132
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
32-
import org.eclipse.m2e.core.project.IProjectConfiguration;
3333
import org.eclipse.m2e.core.project.MavenProjectUtils;
3434

3535

@@ -60,19 +60,11 @@ public class MavenPropertyTester extends PropertyTester {
6060
@Override
6161
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
6262
if(WORKSPACE_RESULUTION_ENABLE.equals(property)) {
63-
boolean enableWorkspaceResolution = true;
64-
IAdaptable adaptable = (IAdaptable) receiver;
65-
66-
IProject projectAdapter = adaptable.getAdapter(IProject.class);
63+
IProject projectAdapter = Adapters.adapt(receiver, IProject.class);
6764
if(projectAdapter != null) {
68-
IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
69-
IMavenProjectFacade projectFacade = projectManager.create(projectAdapter, new NullProgressMonitor());
70-
if(projectFacade != null) {
71-
IProjectConfiguration configuration = projectFacade.getConfiguration();
72-
return !configuration.isResolveWorkspaceProjects();
73-
}
65+
return !ResolverConfigurationIO.isResolveWorkspaceProjects(projectAdapter);
7466
}
75-
return enableWorkspaceResolution;
67+
return true;
7668
}
7769

7870
if(HAS_ARTIFACT_KEY.equals(property)) {

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ResolverConfigurationIO.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public class ResolverConfigurationIO {
5656
*/
5757
private static final String P_RESOLVE_WORKSPACE_PROJECTS = "resolveWorkspaceProjects"; //$NON-NLS-1$
5858

59+
private static final boolean P_RESOLVE_WORKSPACE_PROJECTS_DEFAULT = false;
60+
5961
private static final String P_AUTO_UPDATE_CONFIGURATION = MavenPreferenceConstants.P_AUTO_UPDATE_CONFIGURATION;
6062

6163
/**
@@ -117,7 +119,8 @@ public static IProjectConfiguration readResolverConfiguration(IProject project)
117119
return new ResolverConfiguration(project);
118120
}
119121
ResolverConfiguration configuration = new ResolverConfiguration();
120-
configuration.setResolveWorkspaceProjects(projectNode.getBoolean(P_RESOLVE_WORKSPACE_PROJECTS, false));
122+
configuration.setResolveWorkspaceProjects(
123+
projectNode.getBoolean(P_RESOLVE_WORKSPACE_PROJECTS, P_RESOLVE_WORKSPACE_PROJECTS_DEFAULT));
121124
configuration.setSelectedProfiles(projectNode.get(P_SELECTED_PROFILES, "")); //$NON-NLS-1$
122125
configuration.setLifecycleMappingId(projectNode.get(P_LIFECYCLE_MAPPING_ID, (String) null));
123126
configuration.setProperties(stringAsProperties(projectNode.get(P_PROPERTIES, null)));
@@ -139,6 +142,14 @@ public static void setAutomaticallyUpdateConfiguration(IProject project, boolean
139142
}
140143
}
141144

145+
public static boolean isResolveWorkspaceProjects(IProject project) {
146+
IEclipsePreferences preferences = getMavenProjectPreferences(project);
147+
if(preferences == null) {
148+
return P_RESOLVE_WORKSPACE_PROJECTS_DEFAULT;
149+
}
150+
return preferences.getBoolean(P_RESOLVE_WORKSPACE_PROJECTS, P_RESOLVE_WORKSPACE_PROJECTS_DEFAULT);
151+
}
152+
142153
private static IEclipsePreferences getMavenProjectPreferences(IProject project) {
143154
return new ProjectScope(project).getNode(IMavenConstants.PLUGIN_ID);
144155
}

0 commit comments

Comments
 (0)