Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRastislav Wagner2016-03-10 06:35:45 -0500
committerFred Bricon2016-05-03 15:44:30 -0400
commit3bfcbe6461b2f5643d160c91b4c6176bc1e931c2 (patch)
tree8b50b7e5441a99efb073cc6531be3a7db4757d3f /org.eclipse.m2e.core
parente20752a8a92f8d5487a7f7a3427e44314b895fb9 (diff)
downloadm2e-core-3bfcbe6461b2f5643d160c91b4c6176bc1e931c2.tar.gz
m2e-core-3bfcbe6461b2f5643d160c91b4c6176bc1e931c2.tar.xz
m2e-core-3bfcbe6461b2f5643d160c91b4c6176bc1e931c2.zip
490083 Add support for changing maven pom properties
Change-Id: I8d634c2c611fef26532ad6d2b40de342ec692d80 Signed-off-by: Rastislav Wagner <rawagner@redhat.com>
Diffstat (limited to 'org.eclipse.m2e.core')
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ResolverConfigurationIO.java75
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java61
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/ResolverConfiguration.java11
3 files changed, 122 insertions, 25 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ResolverConfigurationIO.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ResolverConfigurationIO.java
index a50505a0..c07f2b38 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ResolverConfigurationIO.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ResolverConfigurationIO.java
@@ -11,6 +11,14 @@
package org.eclipse.m2e.core.internal.project;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
import org.osgi.service.prefs.BackingStoreException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,6 +60,14 @@ public class ResolverConfigurationIO {
*/
private static final String P_LIFECYCLE_MAPPING_ID = "lifecycleMappingId";
+ private static final String P_PROPERTIES = "properties";
+
+ private static final String PROPERTIES_KV_SEPARATOR = ">";
+
+ private static final String PROPERTIES_SEPARATOR = "|";
+
+ private static final String ENCODING = "UTF-8";
+
/**
* Current configuration version value. See {@link #P_VERSION}
*/
@@ -73,6 +89,12 @@ public class ResolverConfigurationIO {
projectNode.remove(P_LIFECYCLE_MAPPING_ID);
}
+ if(configuration.getProperties() != null && !configuration.getProperties().isEmpty()) {
+ projectNode.put(P_PROPERTIES, propertiesAsString(configuration.getProperties()));
+ } else {
+ projectNode.remove(P_PROPERTIES);
+ }
+
try {
projectNode.flush();
return true;
@@ -101,7 +123,60 @@ public class ResolverConfigurationIO {
configuration.setResolveWorkspaceProjects(projectNode.getBoolean(P_RESOLVE_WORKSPACE_PROJECTS, false));
configuration.setSelectedProfiles(projectNode.get(P_SELECTED_PROFILES, "")); //$NON-NLS-1$
configuration.setLifecycleMappingId(projectNode.get(P_LIFECYCLE_MAPPING_ID, (String) null));
+ configuration.setProperties(stringAsProperties(projectNode.get(P_PROPERTIES, null)));
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));
+ return propAsString;
+ }
+
+ private static Properties stringAsProperties(String properties) {
+ Properties p = new Properties();
+ if(properties != null) {
+ String[] entries = properties.split("\\" + PROPERTIES_SEPARATOR);
+ Stream.of(entries).forEach(e -> convert(e, p));
+ }
+ return p;
+ }
+
+ private static void convert(String e, Properties p) {
+ String[] kv = e.split(PROPERTIES_KV_SEPARATOR);
+ String key = kv[0];
+ String value = null;
+ if(kv.length == 2) {
+ value = kv[1];
+ }
+ p.put(urlDecode(key), urlDecode(value));
+ }
+
+ private static String encodeEntry(Entry<Object, Object> e) {
+ String key = e.getKey().toString();
+ String value = e.getValue() == null ? "" : e.getValue().toString();
+ return urlEncode(key) + PROPERTIES_KV_SEPARATOR + urlEncode(value);
+ }
+
+ private static String urlEncode(String string) {
+ if(string == null) {
+ return "";
+ }
+ try {
+ return URLEncoder.encode(string, ENCODING);
+ } catch(UnsupportedEncodingException notGonnaHappen) {
+ }
+ return string;
+ }
+
+ private static String urlDecode(String string) {
+ if(string == null) {
+ return "";
+ }
+ try {
+ return URLDecoder.decode(string, ENCODING);
+ } catch(UnsupportedEncodingException notGonnaHappen) {
+ }
+ return string;
+ }
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
index a9ade0d9..b2d09bda 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
@@ -25,6 +25,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
@@ -389,8 +390,8 @@ public class ProjectRegistryManager {
context.forcePomFiles(newState.getVersionedDependents(mavenParentCapability, true));
// refresh projects that import dependencyManagement from this one
- MavenCapability mavenArtifactImportCapability = MavenCapability.createMavenArtifactImport(oldFacade
- .getArtifactKey());
+ MavenCapability mavenArtifactImportCapability = MavenCapability
+ .createMavenArtifactImport(oldFacade.getArtifactKey());
context.forcePomFiles(newState.getVersionedDependents(mavenArtifactImportCapability, true));
}
@@ -401,8 +402,8 @@ public class ProjectRegistryManager {
MavenCapability mavenParentCapability = MavenCapability.createMavenParent(oldFacade.getArtifactKey());
context.forcePomFiles(newState.getDependents(mavenParentCapability, true));
- MavenCapability mavenArtifactImportCapability = MavenCapability.createMavenArtifactImport(oldFacade
- .getArtifactKey());
+ MavenCapability mavenArtifactImportCapability = MavenCapability
+ .createMavenArtifactImport(oldFacade.getArtifactKey());
context.forcePomFiles(newState.getVersionedDependents(mavenArtifactImportCapability, true));
}
}
@@ -415,8 +416,8 @@ public class ProjectRegistryManager {
context.forcePomFiles(newState.getVersionedDependents(mavenParentCapability, true));
// refresh projects that import dependencyManagement from this one
- MavenCapability mavenArtifactImportCapability = MavenCapability.createMavenArtifactImport(newFacade
- .getArtifactKey());
+ MavenCapability mavenArtifactImportCapability = MavenCapability
+ .createMavenArtifactImport(newFacade.getArtifactKey());
context.forcePomFiles(newState.getVersionedDependents(mavenArtifactImportCapability, true));
Set<Capability> capabilities = new LinkedHashSet<Capability>();
@@ -571,8 +572,8 @@ public class ProjectRegistryManager {
}
}
for(Capability capability : changedCapabilities) {
- context.forcePomFiles(versionedCapabilitiesOnly ? newState.getVersionedDependents(capability, true) : newState
- .getDependents(capability, true));
+ context.forcePomFiles(versionedCapabilitiesOnly ? newState.getVersionedDependents(capability, true)
+ : newState.getDependents(capability, true));
}
Set<RequiredCapability> oldRequirements = newState.setRequirements(pom, requirements);
@@ -590,9 +591,8 @@ public class ProjectRegistryManager {
private void setupLifecycleMapping(MutableProjectRegistry newState, IProgressMonitor monitor,
MavenProjectFacade newFacade) throws CoreException {
- LifecycleMappingResult mappingResult = LifecycleMappingFactory.calculateLifecycleMapping(
- getMavenProject(newFacade), newFacade.getMojoExecutions(), newFacade.getResolverConfiguration()
- .getLifecycleMappingId(), monitor);
+ LifecycleMappingResult mappingResult = LifecycleMappingFactory.calculateLifecycleMapping(getMavenProject(newFacade),
+ newFacade.getMojoExecutions(), newFacade.getResolverConfiguration().getLifecycleMappingId(), monitor);
newFacade.setLifecycleMappingId(mappingResult.getLifecycleMappingId());
Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mojoExecutionMapping = mappingResult
@@ -693,8 +693,8 @@ public class ProjectRegistryManager {
final MutableProjectRegistry state, final IProgressMonitor monitor) throws CoreException {
markerManager.deleteMarkers(pom, IMavenConstants.MARKER_POM_LOADING_ID);
- final ResolverConfiguration resolverConfiguration = ResolverConfigurationIO.readResolverConfiguration(pom
- .getProject());
+ final ResolverConfiguration resolverConfiguration = ResolverConfigurationIO
+ .readResolverConfiguration(pom.getProject());
return execute(state, pom, resolverConfiguration, new ICallable<MavenProjectFacade>() {
public MavenProjectFacade call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
@@ -722,8 +722,8 @@ public class ProjectRegistryManager {
}, monitor);
}
- /*package*/Map<String, List<MojoExecution>> calculateExecutionPlans(IFile pom, MavenProject mavenProject,
- IProgressMonitor monitor) {
+ /*package*/Map<String, List<MojoExecution>> calculateExecutionPlans(IFile pom, MavenProject mavenProject,
+ IProgressMonitor monitor) {
Map<String, List<MojoExecution>> executionPlans = new LinkedHashMap<String, List<MojoExecution>>();
executionPlans.put(LIFECYCLE_CLEAN, calculateExecutionPlan(pom, mavenProject, LIFECYCLE_CLEAN, monitor));
executionPlans.put(LIFECYCLE_DEFAULT, calculateExecutionPlan(pom, mavenProject, LIFECYCLE_DEFAULT, monitor));
@@ -731,8 +731,8 @@ public class ProjectRegistryManager {
return executionPlans;
}
- private List<MojoExecution> calculateExecutionPlan(IFile pom, final MavenProject mavenProject,
- final String lifecycle, final IProgressMonitor monitor) {
+ private List<MojoExecution> calculateExecutionPlan(IFile pom, final MavenProject mavenProject, final String lifecycle,
+ final IProgressMonitor monitor) {
List<MojoExecution> mojoExecutions = null;
try {
MavenExecutionPlan executionPlan = maven.calculateExecutionPlan(mavenProject, Arrays.asList(lifecycle), false,
@@ -809,7 +809,8 @@ public class ProjectRegistryManager {
try {
return execute(state, pomFile, resolverConfiguration, new ICallable<MavenExecutionResult>() {
- public MavenExecutionResult call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
+ public MavenExecutionResult call(IMavenExecutionContext context, IProgressMonitor monitor)
+ throws CoreException {
ProjectBuildingRequest configuration = context.newProjectBuildingRequest();
configuration.setResolveDependencies(true);
return getMaven().readMavenProject(pomFile.getLocation().toFile(), configuration);
@@ -859,13 +860,22 @@ public class ProjectRegistryManager {
return request;
}
- /*package*/MavenExecutionRequest configureExecutionRequest(MavenExecutionRequest request, IProjectRegistry state,
- IFile pom, ResolverConfiguration resolverConfiguration) throws CoreException {
+ /*package*/MavenExecutionRequest configureExecutionRequest(MavenExecutionRequest request, IProjectRegistry state,
+ IFile pom, ResolverConfiguration resolverConfiguration) throws CoreException {
request.setPom(pom.getLocation().toFile());
request.addActiveProfiles(resolverConfiguration.getActiveProfileList());
request.addInactiveProfiles(resolverConfiguration.getInactiveProfileList());
+ Properties p = request.getUserProperties();
+ Properties addProperties = resolverConfiguration.getProperties();
+ if(addProperties != null) {
+ if(p == null) {
+ p = new Properties();
+ }
+ p.putAll(addProperties);
+ }
+
// eclipse workspace repository implements both workspace dependency resolution
// and inter-module dependency resolution for multi-module projects.
@@ -888,7 +898,8 @@ public class ProjectRegistryManager {
EclipseWorkspaceArtifactRepository workspaceReader = getWorkspaceReader(projectRegistry, null,
resolverConfiguration);
- DelegatingLocalArtifactRepository localRepo = new DelegatingLocalArtifactRepository(getMaven().getLocalRepository());
+ DelegatingLocalArtifactRepository localRepo = new DelegatingLocalArtifactRepository(
+ getMaven().getLocalRepository());
localRepo.setIdeWorkspace(workspaceReader);
return localRepo;
@@ -929,8 +940,8 @@ public class ProjectRegistryManager {
return maven;
}
- /*package*/MojoExecution setupMojoExecution(MavenProjectFacade projectFacade, MojoExecution mojoExecution,
- IProgressMonitor monitor) throws CoreException {
+ /*package*/MojoExecution setupMojoExecution(MavenProjectFacade projectFacade, MojoExecution mojoExecution,
+ IProgressMonitor monitor) throws CoreException {
MavenProject mavenProject = null;
if(MavenExecutionContext.getThreadContext() == null) {
// the intent of this code is to provide backwards compatibility for clients that request setup MojoExecution
@@ -963,8 +974,8 @@ public class ProjectRegistryManager {
return context;
}
- public MavenExecutionContext createExecutionContext(final IFile pom, final ResolverConfiguration resolverConfiguration)
- throws CoreException {
+ public MavenExecutionContext createExecutionContext(final IFile pom,
+ final ResolverConfiguration resolverConfiguration) throws CoreException {
return createExecutionContext(projectRegistry, pom, resolverConfiguration);
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/ResolverConfiguration.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/ResolverConfiguration.java
index 9c4c5fa2..41a176f0 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/ResolverConfiguration.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/ResolverConfiguration.java
@@ -14,6 +14,7 @@ package org.eclipse.m2e.core.project;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
+import java.util.Properties;
/**
@@ -31,6 +32,16 @@ public class ResolverConfiguration implements Serializable {
private String lifecycleMappingId;
+ private Properties properties;
+
+ public Properties getProperties() {
+ return this.properties;
+ }
+
+ public void setProperties(Properties properties) {
+ this.properties = properties;
+ }
+
public boolean shouldResolveWorkspaceProjects() {
return this.resolveWorkspaceProjects;
}

Back to the top