Skip to content

Commit

Permalink
Add new IProjectConfiguration as replacement for ResolverConfiguration
Browse files Browse the repository at this point in the history
Currently ResolverConfiguration is used for many purpose especially for
grouping projects in resolve operations. The problem is that this class
itself is modifiable and thus can change without any notice and as it is
a public API class we can't easily change this or have alternative
implementations. Beside that the javadoc suggest that the naming is not
well chosen.

This adds a new interface IProjectConfiguration that also takes the new
concept of MultiModuleProjectDirectory into account
  • Loading branch information
laeubi committed Nov 10, 2022
1 parent a743960 commit bc760a8
Show file tree
Hide file tree
Showing 20 changed files with 181 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.eclipse.m2e.apt.preferences.AnnotationProcessingMode;
import org.eclipse.m2e.apt.preferences.IPreferencesManager;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.IProjectConfiguration;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
import org.eclipse.m2e.core.project.IProjectCreationListener;
import org.eclipse.m2e.core.project.ResolverConfiguration;
Expand Down Expand Up @@ -139,7 +140,7 @@ protected void updateProject(IProject project, String newPomName) throws Excepti
}

IProjectConfigurationManager configurationManager = MavenPlugin.getProjectConfigurationManager();
ResolverConfiguration configuration = new ResolverConfiguration();
IProjectConfiguration configuration = new ResolverConfiguration();
configurationManager.enableMavenNature(project, configuration, monitor);
configurationManager.updateProjectConfiguration(project, monitor);
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.m2e.binaryproject/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.m2e.binaryproject;singleton:=true
Bundle-Version: 2.0.1.qualifier
Bundle-Version: 2.1.0.qualifier
Bundle-Vendor: Eclipse.org - m2e
Bundle-Name: M2E Binary Project Core
Require-Bundle: org.eclipse.m2e.core;bundle-version="[2.0.0,3.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
import org.eclipse.m2e.core.project.IProjectConfiguration;
import org.eclipse.m2e.core.project.MavenProjectUtils;
import org.eclipse.m2e.core.project.ResolverConfiguration;


/**
Expand Down Expand Up @@ -69,8 +69,8 @@ public boolean test(Object receiver, String property, Object[] args, Object expe
IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
IMavenProjectFacade projectFacade = projectManager.create(projectAdapter, new NullProgressMonitor());
if(projectFacade != null) {
ResolverConfiguration configuration = projectFacade.getResolverConfiguration();
return !configuration.shouldResolveWorkspaceProjects();
IProjectConfiguration configuration = projectFacade.getResolverConfiguration();
return !configuration.isResolveWorkspaceProjects();
}
}
return enableWorkspaceResolution;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.project.IProjectConfiguration;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.eclipse.m2e.core.ui.internal.Messages;
Expand Down Expand Up @@ -107,9 +108,9 @@ protected void performDefaults() {
init(new ResolverConfiguration());
}

private void init(ResolverConfiguration configuration) {
private void init(IProjectConfiguration configuration) {

resolveWorspaceProjectsButton.setSelection(configuration.shouldResolveWorkspaceProjects());
resolveWorspaceProjectsButton.setSelection(configuration.isResolveWorkspaceProjects());
// includeModulesButton.setSelection(configuration.shouldIncludeModules());
selectedProfilesText.setText(configuration.getSelectedProfiles());
}
Expand All @@ -129,7 +130,7 @@ public boolean performOk() {
final ResolverConfiguration configuration = getResolverConfiguration();
if(configuration.getSelectedProfiles().equals(selectedProfilesText.getText()) &&
// configuration.shouldIncludeModules()==includeModulesButton.getSelection() &&
configuration.shouldResolveWorkspaceProjects() == resolveWorspaceProjectsButton.getSelection()) {
configuration.isResolveWorkspaceProjects() == resolveWorspaceProjectsButton.getSelection()) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.ui.forms.events.ExpansionEvent;
import org.eclipse.ui.forms.widgets.ExpandableComposite;

import org.eclipse.m2e.core.project.IProjectConfiguration;
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.eclipse.m2e.core.ui.internal.Messages;
Expand Down Expand Up @@ -117,14 +118,14 @@ public void expansionStateChanged(ExpansionEvent e) {
}

public void loadData() {
resolveWorkspaceProjects.setSelection(resolverConfiguration.shouldResolveWorkspaceProjects());
resolveWorkspaceProjects.setSelection(resolverConfiguration.isResolveWorkspaceProjects());
profiles.setText(resolverConfiguration.getSelectedProfiles());
if(template != null) {
template.setText(projectImportConfiguration.getProjectNameTemplate());
}
}

public ResolverConfiguration getResolverConfiguration() {
public IProjectConfiguration getResolverConfiguration() {
return this.resolverConfiguration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
import org.eclipse.m2e.core.internal.markers.IMavenMarkerManager;
import org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IProjectConfiguration;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.eclipse.m2e.core.project.configurator.AbstractBuildParticipant;
import org.eclipse.m2e.core.project.configurator.ILifecycleMapping;
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
Expand Down Expand Up @@ -74,7 +74,7 @@ public final T execute(final int kind, final Map<String, String> args, IProgress
return null;
}

ResolverConfiguration resolverConfiguration = configurationManager.getResolverConfiguration(project);
IProjectConfiguration resolverConfiguration = configurationManager.getResolverConfiguration(project);

if(resolverConfiguration == null) {
// TODO unit test me
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import org.eclipse.m2e.core.project.IMavenProjectChangedListener;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectImportResult;
import org.eclipse.m2e.core.project.IProjectConfiguration;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
import org.eclipse.m2e.core.project.IProjectCreationListener;
import org.eclipse.m2e.core.project.MavenProjectChangedEvent;
Expand Down Expand Up @@ -503,7 +504,7 @@ private void updateProjectConfiguration(ProjectConfigurationRequest request, IPr
}

@Override
public void enableMavenNature(IProject project, ResolverConfiguration configuration, IProgressMonitor monitor)
public void enableMavenNature(IProject project, IProjectConfiguration configuration, IProgressMonitor monitor)
throws CoreException {
monitor.subTask(Messages.ProjectConfigurationManager_task_enable_nature);
IMavenExecutionContext.getThreadContext().orElseGet(maven::createExecutionContext).execute(new AbstractRunnable() {
Expand All @@ -515,7 +516,7 @@ protected void run(IMavenExecutionContext context, IProgressMonitor monitor) thr
}, monitor);
}

void enableBasicMavenNature(IProject project, ResolverConfiguration configuration, IProgressMonitor monitor)
void enableBasicMavenNature(IProject project, IProjectConfiguration configuration, IProgressMonitor monitor)
throws CoreException {
ResolverConfigurationIO.saveResolverConfiguration(project, configuration);

Expand Down Expand Up @@ -838,7 +839,7 @@ IProject create(MavenProjectInfo projectInfo, ProjectImportConfiguration configu
listener.projectCreated(project);
}

ResolverConfiguration resolverConfiguration = configuration.getResolverConfiguration();
IProjectConfiguration resolverConfiguration = configuration.getResolverConfiguration();
enableBasicMavenNature(project, resolverConfiguration, monitor);

// create empty/marker persistent configuration
Expand Down Expand Up @@ -919,7 +920,7 @@ public ResolverConfiguration getResolverConfiguration(IProject project) {
}

@Override
public boolean setResolverConfiguration(IProject project, ResolverConfiguration configuration) {
public boolean setResolverConfiguration(IProject project, IProjectConfiguration configuration) {
return ResolverConfigurationIO.saveResolverConfiguration(project, configuration);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.stream.Collectors;
Expand All @@ -31,6 +32,7 @@
import org.eclipse.core.runtime.preferences.IScopeContext;

import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.project.IProjectConfiguration;
import org.eclipse.m2e.core.project.ResolverConfiguration;


Expand Down Expand Up @@ -75,13 +77,13 @@ public class ResolverConfigurationIO {
*/
private static final String VERSION = "1"; //$NON-NLS-1$

public static boolean saveResolverConfiguration(IProject project, ResolverConfiguration configuration) {
public static boolean saveResolverConfiguration(IProject project, IProjectConfiguration configuration) {
IScopeContext projectScope = new ProjectScope(project);
IEclipsePreferences projectNode = projectScope.getNode(IMavenConstants.PLUGIN_ID);
if(projectNode != null) {
projectNode.put(P_VERSION, VERSION);

projectNode.putBoolean(P_RESOLVE_WORKSPACE_PROJECTS, configuration.shouldResolveWorkspaceProjects());
projectNode.putBoolean(P_RESOLVE_WORKSPACE_PROJECTS, configuration.isResolveWorkspaceProjects());

projectNode.put(P_SELECTED_PROFILES, configuration.getSelectedProfiles());

Expand All @@ -91,8 +93,8 @@ public static boolean saveResolverConfiguration(IProject project, ResolverConfig
projectNode.remove(P_LIFECYCLE_MAPPING_ID);
}

if(configuration.getProperties() != null && !configuration.getProperties().isEmpty()) {
projectNode.put(P_PROPERTIES, propertiesAsString(configuration.getProperties()));
if(configuration.getConfigurationProperties() != null && !configuration.getConfigurationProperties().isEmpty()) {
projectNode.put(P_PROPERTIES, propertiesAsString(configuration.getConfigurationProperties()));
} else {
projectNode.remove(P_PROPERTIES);
}
Expand Down Expand Up @@ -129,9 +131,9 @@ public static ResolverConfiguration readResolverConfiguration(IProject project)
return configuration;
}

private static String propertiesAsString(Properties properties) {
Stream<Entry<Object, Object>> stream = properties.entrySet().stream();
String propAsString = stream.map(e -> encodeEntry(e)).collect(Collectors.joining(PROPERTIES_SEPARATOR));
private static String propertiesAsString(Map<?, ?> properties) {
String propAsString = properties.entrySet().stream().map(e -> encodeEntry(e))
.collect(Collectors.joining(PROPERTIES_SEPARATOR));
return propAsString;
}

Expand All @@ -154,7 +156,7 @@ private static void convert(String e, Properties p) {
p.put(urlDecode(key), urlDecode(value));
}

private static String encodeEntry(Entry<Object, Object> e) {
private static String encodeEntry(Entry<?, ?> e) {
String key = e.getKey().toString();
String value = e.getValue() == null ? "" : e.getValue().toString();
return urlEncode(key) + PROPERTIES_KV_SEPARATOR + urlEncode(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void resolveProjectDependencies(final IMavenProjectFacade facade, Set<Cap

markerManager.addMarkers(facade.getPom(), IMavenConstants.MARKER_DEPENDENCY_ID, mavenResult);

if(!facade.getResolverConfiguration().shouldResolveWorkspaceProjects()) {
if(!facade.getResolverConfiguration().isResolveWorkspaceProjects()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected File resolveAsEclipseProject(String groupId, String artifactId, String
return null;
}

if(context.resolverConfiguration.shouldResolveWorkspaceProjects()) {
if(context.resolverConfiguration.isResolveWorkspaceProjects()) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IPath file = pom.getLocation();
if(file == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.eclipse.m2e.core.internal.embedder.PlexusContainerManager;
import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IProjectConfiguration;
import org.eclipse.m2e.core.project.MavenProjectUtils;
import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
Expand Down Expand Up @@ -339,6 +340,11 @@ public ResolverConfiguration getResolverConfiguration() {
return resolverConfiguration;
}

@Override
public IProjectConfiguration getConfiguration() {
return resolverConfiguration;
}

/**
* @return true if maven project needs to be re-read from disk
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata;
import org.eclipse.m2e.core.project.IMavenProjectChangedListener;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IProjectConfiguration;
import org.eclipse.m2e.core.project.MavenProjectChangedEvent;
import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.eclipse.m2e.core.project.configurator.ILifecycleMapping;
Expand Down Expand Up @@ -497,7 +498,7 @@ private void refresh(MutableProjectRegistry newState, DependencyResolutionContex

if(newFacade != null) {
MavenProjectFacade facade = newFacade;
ResolverConfiguration resolverConfiguration = facade.getResolverConfiguration();
IProjectConfiguration resolverConfiguration = facade.getResolverConfiguration();
createExecutionContext(newState, pom, resolverConfiguration).execute(getMavenProject(newFacade),
(executionContext, pm) -> {
refreshPhase2(newState, context, originalCapabilities, originalRequirements, pom, facade, pm);
Expand Down Expand Up @@ -822,7 +823,7 @@ public MavenProjectFacade getMavenProject(String groupId, String artifactId, Str

private MavenProject readProjectWithDependencies(IMavenProjectFacade facade) {
IFile pomFile = facade.getPom();
ResolverConfiguration resolverConfiguration = facade.getResolverConfiguration();
IProjectConfiguration resolverConfiguration = facade.getResolverConfiguration();
Collection<MavenExecutionResult> results = readProjectsWithDependencies(pomFile, resolverConfiguration, null);
if(results.size() != 1) {
throw new IllegalStateException("Results should contain one entry.");
Expand Down Expand Up @@ -850,7 +851,7 @@ private static boolean hasError(MavenExecutionResult mavenExecutionResult) {
}

private Collection<MavenExecutionResult> readProjectsWithDependencies(IFile pomFile,
ResolverConfiguration resolverConfiguration, IProgressMonitor monitor) {
IProjectConfiguration resolverConfiguration, IProgressMonitor monitor) {
try {
IMavenPlexusContainer container = mapToContainer(pomFile);
Map<File, MavenExecutionResult> resultMap = Map.of();
Expand Down Expand Up @@ -885,33 +886,34 @@ public IMavenProjectFacade getProject(IProject project) {
static class Context {
final IProjectRegistry state;

final ResolverConfiguration resolverConfiguration;
final IProjectConfiguration resolverConfiguration;

final IFile pom;

Context(IProjectRegistry state, ResolverConfiguration resolverConfiguration, IFile pom) {
Context(IProjectRegistry state, IProjectConfiguration resolverConfiguration, IFile pom) {
this.state = state;
this.resolverConfiguration = resolverConfiguration;
this.pom = pom;
}
}

private MavenExecutionRequest configureExecutionRequest(MavenExecutionRequest request, IProjectRegistry state,
IFile pom, ResolverConfiguration resolverConfiguration) throws CoreException {
IFile pom, IProjectConfiguration resolverConfiguration) throws CoreException {
if(pom != null) {
request.setPom(ProjectRegistryManager.toJavaIoFile(pom));
}

request.addActiveProfiles(resolverConfiguration.getActiveProfileList());
request.addInactiveProfiles(resolverConfiguration.getInactiveProfileList());

Properties p = request.getUserProperties();
Properties addProperties = resolverConfiguration.getProperties();
Properties userProperties = request.getUserProperties();
Map<String, String> addProperties = resolverConfiguration.getConfigurationProperties();
if(addProperties != null) {
if(p == null) {
p = new Properties();
if(userProperties == null) {
userProperties = new Properties();
//FIXME should we not set them here?? request.setUserProperties(p);
}
p.putAll(addProperties);
userProperties.putAll(addProperties);
}

// eclipse workspace repository implements both workspace dependency resolution
Expand All @@ -928,7 +930,7 @@ private MavenExecutionRequest configureExecutionRequest(MavenExecutionRequest re
}

private static EclipseWorkspaceArtifactRepository getWorkspaceReader(IProjectRegistry state, IFile pom,
ResolverConfiguration resolverConfiguration) {
IProjectConfiguration resolverConfiguration) {
Context context = new Context(state, resolverConfiguration, pom);
return new EclipseWorkspaceArtifactRepository(context);
}
Expand Down Expand Up @@ -978,7 +980,7 @@ PlexusContainerManager getContainerManager() {
}

private IMavenExecutionContext createExecutionContext(IProjectRegistry state, IFile pom,
ResolverConfiguration resolverConfiguration) throws CoreException {
IProjectConfiguration resolverConfiguration) throws CoreException {

IMavenExecutionContext context;
try {
Expand All @@ -1003,7 +1005,7 @@ private IMavenExecutionContext createExecutionContext(IProjectRegistry state, IF
return context;
}

public IMavenExecutionContext createExecutionContext(IFile pom, ResolverConfiguration resolverConfiguration)
public IMavenExecutionContext createExecutionContext(IFile pom, IProjectConfiguration resolverConfiguration)
throws CoreException {
return createExecutionContext(projectRegistry, pom, resolverConfiguration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ public interface IMavenProjectFacade extends IMavenExecutableLocation {

Set<ArtifactRef> getMavenProjectArtifacts();

/**
* @return the configuration associated with this facade
*/
IProjectConfiguration getConfiguration();

/**
* @deprecated use {@link #getConfiguration()} instead
* @return
*/
@Deprecated(forRemoval = true)
ResolverConfiguration getResolverConfiguration();

/**
Expand Down
Loading

0 comments on commit bc760a8

Please sign in to comment.