Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2013-11-04 06:10:20 -0500
committerFred Bricon2014-05-03 19:14:09 -0400
commit39412a5c858939fd9a23c719f032d63ada8d74e7 (patch)
treee5954f4cb7653c4fd42eb3a7ab2f53662537961d
parentae0237523b4585d516d33f497c39e8f4d845f3a5 (diff)
downloadm2e-core-39412a5c858939fd9a23c719f032d63ada8d74e7.tar.gz
m2e-core-39412a5c858939fd9a23c719f032d63ada8d74e7.tar.xz
m2e-core-39412a5c858939fd9a23c719f032d63ada8d74e7.zip
418674 : Expose checksum check flag in preferences
Change-Id: If0e32c8be1af99f315d528111a9d9d0efbc4e4cd Signed-off-by: Fred Bricon <fbricon@gmail.com>
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java12
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties6
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenPreferencePage.java73
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java18
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java1
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java1
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java22
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java4
8 files changed, 121 insertions, 16 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
index e87b7284..11e4dcce 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
@@ -671,6 +671,18 @@ public class Messages extends NLS {
public static String preferencesDebugOutput;
+ public static String preferencesGlobalChecksumPolicy;
+
+ public static String preferencesGlobalChecksumPolicy_tooltip;
+
+ public static String preferencesGlobalChecksumPolicy_default;
+
+ public static String preferencesGlobalChecksumPolicy_ignore;
+
+ public static String preferencesGlobalChecksumPolicy_warn;
+
+ public static String preferencesGlobalChecksumPolicy_fail;
+
public static String preferencesDownloadSources;
public static String preferencesDownloadJavadoc;
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
index b239d75a..65da0c45 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
@@ -395,6 +395,12 @@ preferencesDownloadJavadoc=Download Artifact &JavaDoc
preferencesDownloadSources=Do&wnload Artifact Sources
preferencesGlobalUpdateNever=Do not automatically update dependencies from remote repositories
preferencesOffline=&Offline
+preferencesGlobalChecksumPolicy=Global Checksum Policy\:
+preferencesGlobalChecksumPolicy_tooltip=What to do when artifact checksums don't match
+preferencesGlobalChecksumPolicy_default=Default
+preferencesGlobalChecksumPolicy_ignore=Ignore
+preferencesGlobalChecksumPolicy_warn=Warn
+preferencesGlobalChecksumPolicy_fail=Fail
preferencesReindexButton=Re&index
projectSelectionDialogTitle=Select a Maven project
resolverConfigurationAdvanced=Ad&vanced
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenPreferencePage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenPreferencePage.java
index d8704424..5b5af0e9 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenPreferencePage.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenPreferencePage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc.
+ * Copyright (c) 2008-2014 Sonatype, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,31 +8,40 @@
* Contributors:
* Sonatype, Inc. - initial API and implementation
* Andrew Eisenberg - Work on Bug 350414
+ * Fred Bricon (Red Hat, Inc.) - Add global checksum policy prefs.
*******************************************************************************/
package org.eclipse.m2e.core.ui.internal.preferences;
+import java.util.ArrayList;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.eclipse.core.resources.IProject;
import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.ComboFieldEditor;
+import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+
+import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.internal.preferences.MavenPreferenceConstants;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator;
import org.eclipse.m2e.core.ui.internal.Messages;
+import org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob;
public class MavenPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
private static final Logger log = LoggerFactory.getLogger(MavenPreferencePage.class);
+ private String originalChecksumPolicy;
+
public MavenPreferencePage() {
super(GRID);
setPreferenceStore(M2EUIPluginActivator.getDefault().getPreferenceStore());
@@ -78,15 +87,53 @@ public class MavenPreferencePage extends FieldEditorPreferencePage implements IW
addField(new BooleanFieldEditor(MavenPreferenceConstants.P_HIDE_FOLDERS_OF_NESTED_PROJECTS, //
Messages.MavenPreferencePage_hide, getFieldEditorParent()));
- GridData comboCompositeGridData = new GridData();
- comboCompositeGridData.verticalIndent = 25;
- comboCompositeGridData.horizontalSpan = 3;
- comboCompositeGridData.grabExcessHorizontalSpace = true;
- comboCompositeGridData.horizontalAlignment = GridData.FILL;
+ String[][] checksumPolicies = new String[][] {
+ new String[] {Messages.preferencesGlobalChecksumPolicy_default, null},
+ new String[] {Messages.preferencesGlobalChecksumPolicy_ignore, ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE},
+ new String[] {Messages.preferencesGlobalChecksumPolicy_warn, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN},
+ new String[] {Messages.preferencesGlobalChecksumPolicy_fail, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL}};
+ originalChecksumPolicy = getPreferenceStore().getString(MavenPreferenceConstants.P_GLOBAL_CHECKSUM_POLICY);
- Composite comboComposite = new Composite(getFieldEditorParent(), SWT.NONE);
- comboComposite.setLayoutData(comboCompositeGridData);
- comboComposite.setLayout(new GridLayout(2, false));
+ FieldEditor checksumPolicy = new ComboFieldEditor(MavenPreferenceConstants.P_GLOBAL_CHECKSUM_POLICY,
+ Messages.preferencesGlobalChecksumPolicy, checksumPolicies, getFieldEditorParent());
+ checksumPolicy.getLabelControl(getFieldEditorParent()).setToolTipText(
+ Messages.preferencesGlobalChecksumPolicy_tooltip);
+ addField(checksumPolicy);
+
+ }
+
+ @Override
+ protected void performApply() {
+ super.performApply();
+ updateProjects();
+ }
+
+ @Override
+ public boolean performOk() {
+ boolean result = super.performOk();
+ if(result) {
+ updateProjects();
+ }
+ return result;
+ }
+ private void updateProjects() {
+ //Update projects if the checksum policy changed
+ String newChecksumPolicy = getPreferenceStore().getString(MavenPreferenceConstants.P_GLOBAL_CHECKSUM_POLICY);
+ boolean updateRequired = !originalChecksumPolicy.equals(newChecksumPolicy);
+ if(updateRequired) {
+ IMavenProjectFacade[] facades = MavenPlugin.getMavenProjectRegistry().getProjects();
+ if(facades != null && facades.length > 0) {
+ ArrayList<IProject> allProjects = new ArrayList<IProject>(facades.length);
+ for(IMavenProjectFacade facade : facades) {
+ allProjects.add(facade.getProject());
+ }
+ new UpdateMavenProjectJob(
+ allProjects.toArray(new IProject[allProjects.size()]), //
+ MavenPlugin.getMavenConfiguration().isOffline(), true /*forceUpdateDependencies*/,
+ false /*updateConfiguration*/, true /*rebuild*/, true /*refreshFromLocal*/).schedule();
+ }
+ }
+ originalChecksumPolicy = newChecksumPolicy;
}
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java
index bca5f987..78d42897 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java
@@ -14,6 +14,9 @@ package org.eclipse.m2e.core.embedder;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.apache.maven.execution.MavenExecutionRequest;
+
/**
* IMavenConfiguration
@@ -75,7 +78,20 @@ public interface IMavenConfiguration {
* Returns {@link IMarker} severity of "out-of-date" project problem
*
* @return One of <code>ignore</code>, <code>warning</code> or <code>error</code>.
- * @since 1.5.0
+ * @since 1.5
*/
public String getOutOfDateProjectSeverity();
+
+ /**
+ * Returns the global checksum policy applied on {@link MavenExecutionRequest}s.
+ *
+ * @return <code>fail</code>, <code>warn</code> or <code>ignore</code> to override repositories specific checksum
+ * policies or <code>null</code> to follow default behavior.
+ * @see {@link ArtifactRepositoryPolicy#CHECKSUM_POLICY_FAIL}
+ * @see {@link ArtifactRepositoryPolicy#CHECKSUM_POLICY_WARN}
+ * @see {@link ArtifactRepositoryPolicy#CHECKSUM_POLICY_IGNORE}
+ * @since 1.5
+ */
+ public String getGlobalChecksumPolicy();
+
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java
index 8b4f99ad..5ebbc5a7 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java
@@ -88,6 +88,7 @@ public class MavenExecutionContext implements IMavenExecutionContext {
if(request == null) {
request = maven.createExecutionRequest();
}
+
return request;
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
index 01aa6df4..30757f0b 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
@@ -250,6 +250,7 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener {
request.setCacheNotFound(true);
request.setCacheTransferError(true);
+ request.setGlobalChecksumPolicy(mavenConfiguration.getGlobalChecksumPolicy());
// the right way to disable snapshot update
// request.setUpdateSnapshots(false);
return request;
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java
index 226ba80a..650bc77d 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java
@@ -32,6 +32,8 @@ import org.eclipse.core.runtime.preferences.IPreferenceFilter;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+
import org.eclipse.m2e.core.embedder.IMavenConfiguration;
import org.eclipse.m2e.core.embedder.IMavenConfigurationChangeListener;
import org.eclipse.m2e.core.embedder.MavenConfigurationChangeEvent;
@@ -255,4 +257,24 @@ public class MavenConfigurationImpl implements IMavenConfiguration, IPreferenceC
}
preferenceStore.applyPreferences(preferencesLookup[0], new IPreferenceFilter[] {getPreferenceFilter()});
}
+
+ @Override
+ public String getGlobalChecksumPolicy() {
+ return preferenceStore.get(MavenPreferenceConstants.P_GLOBAL_CHECKSUM_POLICY, null, preferencesLookup);
+ }
+
+ /**
+ * For testing purposes only.
+ */
+ public void setGlobalChecksumPolicy(String checksumPolicy) {
+ if(checksumPolicy == null) {
+ preferencesLookup[0].remove(MavenPreferenceConstants.P_GLOBAL_CHECKSUM_POLICY);
+ } else if(ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL.equals(checksumPolicy) //will fail eclipse builds in case checksum fails
+ || ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN.equals(checksumPolicy) //XXX checksum warnings should be rendered as markers
+ || ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE.equals(checksumPolicy)) {//will simply be ignored
+ preferencesLookup[0].put(MavenPreferenceConstants.P_GLOBAL_CHECKSUM_POLICY, checksumPolicy);
+ } else {
+ throw new IllegalArgumentException(checksumPolicy + " is not a valid checksum policy");
+ }
+ }
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java
index 7751e951..64d063cc 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java
@@ -28,8 +28,8 @@ public interface MavenPreferenceConstants {
/** true or false */
// public static final String P_CHECK_LATEST_PLUGIN_VERSION = PREFIX+"checkLatestPluginVersion";
- /** String ??? */
- // public static final String P_GLOBAL_CHECKSUM_POLICY = PREFIX+"globalChecksumPolicy";
+ /** String */
+ public static final String P_GLOBAL_CHECKSUM_POLICY = PREFIX + "globalChecksumPolicy";
/** boolean */
public static final String P_OFFLINE = PREFIX + "offline"; //$NON-NLS-1$

Back to the top