Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2014-04-23 07:27:08 -0400
committerIgor Fedorenko2014-04-23 10:30:39 -0400
commit1ca0075f7feb451bc87c63d2b926955430a9056b (patch)
tree68b85e8d43eeb777dea3a2789246966136a93cd0
parent67fce5dbb00d72f2d951a4f61b0c73631b52f080 (diff)
downloadm2e-core-1ca0075f7feb451bc87c63d2b926955430a9056b.tar.gz
m2e-core-1ca0075f7feb451bc87c63d2b926955430a9056b.tar.xz
m2e-core-1ca0075f7feb451bc87c63d2b926955430a9056b.zip
433224 expose global settings.xml in m2e preferences
Change-Id: Id02badd679ca56f651ed374b49cf5c67881e6e55 Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java28
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties26
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenSettingsPreferencePage.java315
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java46
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java20
5 files changed, 239 insertions, 196 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 1f267db0..8e406bf1 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
@@ -521,13 +521,17 @@ public class Messages extends NLS {
public static String MavenRepositoryView_update_one;
- public static String MavenSettingsPreferencePage_btnBrowse;
+ public static String MavenSettingsPreferencePage_userSettingsBrowseButton_text;
public static String MavenSettingsPreferencePage_btnUpdate;
- public static String MavenSettingsPreferencePage_error_missing;
+ public static String MavenSettingsPreferencePage_error_globalSettingsMissing;
- public static String MavenSettingsPreferencePage_error_parse;
+ public static String MavenSettingsPreferencePage_error_userSettingsMissing;
+
+ public static String MavenSettingsPreferencePage_error_globalSettingsParse;
+
+ public static String MavenSettingsPreferencePage_error_userSettingsParse;
public static String MavenSettingsPreferencePage_job_indexing;
@@ -535,11 +539,17 @@ public class Messages extends NLS {
public static String MavenSettingsPreferencePage_lblLocal;
- public static String MavenSettingsPreferencePage_link_tooltip;
+ public static String MavenSettingsPreferencePage_userSettingslink_tooltip;
+
+ public static String MavenSettingsPreferencePage_userSettingslink1;
+
+ public static String MavenSettingsPreferencePage_userSettingslink2;
- public static String MavenSettingsPreferencePage_link1;
+ public static String MavenSettingsPreferencePage_globalSettingslink_tooltip;
- public static String MavenSettingsPreferencePage_link2;
+ public static String MavenSettingsPreferencePage_globalSettingslink1;
+
+ public static String MavenSettingsPreferencePage_globalSettingslink2;
public static String MavenSettingsPreferencePage_task_updating;
@@ -927,6 +937,12 @@ public class Messages extends NLS {
public static String MavenInstallationWizardPage_selectProjectTitle;
+ public static String MavenSettingsPreferencePage_text_1_text;
+
+ public static String MavenSettingsPreferencePage_txtBrowse_text;
+
+ public static String MavenSettingsPreferencePage_globalSettingsBrowseButton_text;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
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 62885bfa..25acf46e 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
@@ -1,5 +1,5 @@
#Eclipse modern messages class
-#Sat Apr 19 06:12:29 MSK 2014
+#Tue Apr 22 18:28:44 EDT 2014
AddDependencyAction_error_msg=Can't add dependency to {0}
AddDependencyAction_error_title=Add Dependency
AddDependencyAction_searchDialog_title=Add Dependency
@@ -168,8 +168,6 @@ MavenInstallFileArtifactWizardPage_title=Install file in local repository
MavenInstallFileWizard_error=Execution error
MavenInstallFileWizard_job=Installing artifact
MavenInstallFileWizard_title=Install artifact
-MavenInstallationWizard_titleAddInstallation=Edit Maven Runtime
-MavenInstallationWizard_titleNewInstallation=New Maven Runtime
MavenInstallationWizardPage_btnExternal_text_1=External
MavenInstallationWizardPage_btnWorkspace_text=Workspace
MavenInstallationWizardPage_lblInstallationType_text=Installation type\:
@@ -177,8 +175,10 @@ MavenInstallationWizardPage_messageDuplicateInstallationName=The Maven installat
MavenInstallationWizardPage_messageHomeDirectoryIsNotMavenInstll=Target is not a Maven Home
MavenInstallationWizardPage_messageSelectHomeDirectory=Enter the home directory of the Maven Installation
MavenInstallationWizardPage_messageSelectInstallatonName=Enter a name for the Maven Installation
-MavenInstallationWizardPage_selectProjectMessage=Select projects to add:
+MavenInstallationWizardPage_selectProjectMessage=Select projects to add\:
MavenInstallationWizardPage_selectProjectTitle=Project selection
+MavenInstallationWizard_titleAddInstallation=Edit Maven Runtime
+MavenInstallationWizard_titleNewInstallation=New Maven Runtime
MavenInstallationsPreferencePage_btnAdd=&Add...
MavenInstallationsPreferencePage_btnEdit=&Edit...
MavenInstallationsPreferencePage_btnRemove=&Remove
@@ -292,16 +292,22 @@ MavenRepositoryView_reload_msg=This will reload the settings.xml and rebuild the
MavenRepositoryView_reload_title=Reload settings.xml
MavenRepositoryView_update_more=Update Indexes
MavenRepositoryView_update_one=Update Index
-MavenSettingsPreferencePage_btnBrowse=&Browse...
+MavenSettingsPreferencePage_userSettingsBrowseButton_text=Browse...
MavenSettingsPreferencePage_btnUpdate=Update Settings
-MavenSettingsPreferencePage_error_missing=User settings file doesn't exist
-MavenSettingsPreferencePage_error_parse=Unable to parse user settings file; {0}
+MavenSettingsPreferencePage_error_globalSettingsMissing=Global settings file doesn't exist
+MavenSettingsPreferencePage_error_userSettingsMissing=User settings file doesn't exist
+MavenSettingsPreferencePage_error_globalSettingsParse=Unable to parse global settings file; {0}
+MavenSettingsPreferencePage_error_userSettingsParse=Unable to parse user settings file; {0}
+MavenSettingsPreferencePage_globalSettingsBrowseButton_text=Browse...
MavenSettingsPreferencePage_job_indexing=Indexing Local Repository...
MavenSettingsPreferencePage_job_updating=Updating Maven settings
MavenSettingsPreferencePage_lblLocal=Local Repository (From merged user and global settings)\:
-MavenSettingsPreferencePage_link1=User &Settings\:
-MavenSettingsPreferencePage_link2=User &Settings (<a href\="\#">open file</a>)\:
-MavenSettingsPreferencePage_link_tooltip=Open editor for user settings
+MavenSettingsPreferencePage_userSettingslink1=User &Settings\:
+MavenSettingsPreferencePage_userSettingslink2=User &Settings (<a href\="\#">open file</a>)\:
+MavenSettingsPreferencePage_userSettingslink_tooltip=Open editor for user settings
+MavenSettingsPreferencePage_globalSettingslink1=Global &Settings\:
+MavenSettingsPreferencePage_globalSettingslink2=Global &Settings (<a href\="\#">open file</a>)\:
+MavenSettingsPreferencePage_globalSettingslink_tooltip=Open editor for global settings
MavenSettingsPreferencePage_task_updating=Updating progress for {0}
MavenSettingsPreferencePage_title=Maven User Settings
MavenWarningsPreferencePage_groupidDupParent=Disable "{0}" warning
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenSettingsPreferencePage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenSettingsPreferencePage.java
index 0a171918..1f217627 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenSettingsPreferencePage.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenSettingsPreferencePage.java
@@ -65,8 +65,6 @@ import org.apache.maven.settings.building.SettingsProblem;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.IMaven;
import org.eclipse.m2e.core.embedder.IMavenConfiguration;
-import org.eclipse.m2e.core.embedder.MavenRuntime;
-import org.eclipse.m2e.core.embedder.MavenRuntimeManager;
import org.eclipse.m2e.core.internal.index.IndexManager;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.MavenUpdateRequest;
@@ -81,13 +79,11 @@ import org.eclipse.m2e.core.ui.internal.Messages;
public class MavenSettingsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
private static final Logger log = LoggerFactory.getLogger(MavenSettingsPreferencePage.class);
- final MavenRuntimeManager runtimeManager;
-
final IMavenConfiguration mavenConfiguration;
final IMaven maven;
- MavenRuntime defaultRuntime;
+ Text globalSettingsText;
Text userSettingsText;
@@ -95,12 +91,13 @@ public class MavenSettingsPreferencePage extends PreferencePage implements IWork
boolean dirty = false;
+ private Link globalSettingsLink;
+
private Link userSettingsLink;
public MavenSettingsPreferencePage() {
- setTitle(org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_title);
+ setTitle(Messages.MavenSettingsPreferencePage_title);
- this.runtimeManager = MavenPlugin.getMavenRuntimeManager();
this.mavenConfiguration = MavenPlugin.getMavenConfiguration();
this.maven = MavenPlugin.getMaven();
}
@@ -108,9 +105,6 @@ public class MavenSettingsPreferencePage extends PreferencePage implements IWork
public void init(IWorkbench workbench) {
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
- */
public void setVisible(boolean visible) {
super.setVisible(visible);
if(visible) {
@@ -118,27 +112,18 @@ public class MavenSettingsPreferencePage extends PreferencePage implements IWork
}
}
- protected void performDefaults() {
- userSettingsText.setText(MavenCli.DEFAULT_USER_SETTINGS_FILE.getAbsolutePath());
- setDirty(true);
- updateLocalRepository();
- super.performDefaults();
- }
-
protected void updateSettings(final boolean updateMavenDependencies) {
final String userSettings = getUserSettings();
+ final String globalSettings = getGlobalSettings();
- new Job(org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_job_updating) {
+ new Job(Messages.MavenSettingsPreferencePage_job_updating) {
protected IStatus run(IProgressMonitor monitor) {
try {
final File localRepositoryDir = new File(maven.getLocalRepository().getBasedir());
// this clears cached settings.xml instance
- if(userSettings.length() > 0) {
- mavenConfiguration.setUserSettingsFile(userSettings);
- } else {
- mavenConfiguration.setUserSettingsFile(null);
- }
+ mavenConfiguration.setGlobalSettingsFile(globalSettings);
+ mavenConfiguration.setUserSettingsFile(userSettings);
File newRepositoryDir = new File(maven.getLocalRepository().getBasedir());
if(!newRepositoryDir.equals(localRepositoryDir)) {
@@ -152,9 +137,9 @@ public class MavenSettingsPreferencePage extends PreferencePage implements IWork
MavenPlugin.getMaven().reloadSettings();
SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, projects.length);
for(int i = 0; i < projects.length; i++ ) {
- subMonitor.beginTask(NLS.bind(
- org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_task_updating, projects[i]
- .getProject().getName()), 1);
+ subMonitor
+ .beginTask(NLS.bind(Messages.MavenSettingsPreferencePage_task_updating, projects[i].getProject()
+ .getName()), 1);
allProjects.add(projects[i].getProject());
}
MavenPlugin.getMavenProjectRegistry().refresh(
@@ -171,57 +156,101 @@ public class MavenSettingsPreferencePage extends PreferencePage implements IWork
}.schedule();
}
- protected void performApply() {
- if(dirty) {
- updateSettings(false);
- }
+ @Override
+ protected void performDefaults() {
+ globalSettingsText.setText("");
+ userSettingsText.setText("");
+ checkSettings();
+ updateLocalRepository();
+ super.performDefaults();
}
+ @Override
public boolean performOk() {
- if(dirty) {
- updateSettings(false);
- }
+ updateSettings(false);
return true;
}
- public void setDirty(boolean dirty) {
- this.dirty = dirty;
- }
-
- public boolean isDirty() {
- return this.dirty;
- }
-
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
- GridLayout gridLayout = new GridLayout(4, false);
- gridLayout.marginBottom = 5;
- gridLayout.marginRight = 5;
- gridLayout.marginHeight = 0;
- gridLayout.marginWidth = 0;
- composite.setLayout(gridLayout);
-
- createUserSettings(composite);
+ composite.setLayout(new GridLayout(2, false));
+
+ globalSettingsLink = new Link(composite, SWT.NONE);
+ globalSettingsLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+ globalSettingsLink.setText(Messages.MavenSettingsPreferencePage_globalSettingslink2);
+ globalSettingsLink.setToolTipText(Messages.MavenSettingsPreferencePage_globalSettingslink_tooltip);
+ globalSettingsLink.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ String globalSettings = getGlobalSettings();
+ if(globalSettings.length() == 0) {
+ globalSettings = MavenCli.DEFAULT_GLOBAL_SETTINGS_FILE.getAbsolutePath();
+ }
+ openEditor(globalSettings);
+ }
+ });
+
+ globalSettingsText = new Text(composite, SWT.BORDER);
+ globalSettingsText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+
+ Button globalSettingsBrowseButton = new Button(composite, SWT.NONE);
+ globalSettingsBrowseButton.setText(Messages.MavenSettingsPreferencePage_globalSettingsBrowseButton_text);
+ globalSettingsBrowseButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ browseSettingsAction(globalSettingsText);
+ }
+ });
+
+ userSettingsLink = new Link(composite, SWT.NONE);
+ userSettingsLink.setText(Messages.MavenSettingsPreferencePage_userSettingslink2);
+ userSettingsLink.setToolTipText(Messages.MavenSettingsPreferencePage_userSettingslink_tooltip);
+ userSettingsLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+ userSettingsLink.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ String userSettings = getUserSettings();
+ if(userSettings.length() == 0) {
+ userSettings = MavenCli.DEFAULT_USER_SETTINGS_FILE.getAbsolutePath();
+ }
+ openEditor(userSettings);
+ }
+ });
+ userSettingsText = new Text(composite, SWT.BORDER);
+ userSettingsText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ userSettingsText.setMessage(MavenCli.DEFAULT_USER_SETTINGS_FILE.getAbsolutePath());
+
+ Button userSettingsBrowseButton = new Button(composite, SWT.NONE);
+ userSettingsBrowseButton.setLayoutData(new GridData(SWT.FILL, SWT.RIGHT, false, false, 1, 1));
+ userSettingsBrowseButton.setText(Messages.MavenSettingsPreferencePage_userSettingsBrowseButton_text);
+ userSettingsBrowseButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ browseSettingsAction(userSettingsText);
+ }
+ });
+
+ Button updateSettings = new Button(composite, SWT.NONE);
+ updateSettings.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
+ updateSettings.setText(Messages.MavenSettingsPreferencePage_btnUpdate);
+ updateSettings.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ updateSettings(true);
+ }
+ });
Label localRepositoryLabel = new Label(composite, SWT.NONE);
- GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
+ GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
gd.verticalIndent = 25;
localRepositoryLabel.setLayoutData(gd);
- localRepositoryLabel.setText(org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_lblLocal);
+ localRepositoryLabel.setText(Messages.MavenSettingsPreferencePage_lblLocal);
localRepositoryText = new Text(composite, SWT.READ_ONLY | SWT.BORDER);
- localRepositoryText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
+ localRepositoryText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
localRepositoryText.setData("name", "localRepositoryText"); //$NON-NLS-1$ //$NON-NLS-2$
localRepositoryText.setEditable(false);
Button reindexButton = new Button(composite, SWT.NONE);
reindexButton.setLayoutData(new GridData(SWT.FILL, SWT.RIGHT, false, false, 1, 1));
reindexButton.setText(Messages.preferencesReindexButton);
reindexButton.addSelectionListener(new SelectionAdapter() {
-
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
+ @Override
public void widgetSelected(SelectionEvent e) {
- new WorkspaceJob(org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_job_indexing) {
+ new WorkspaceJob(Messages.MavenSettingsPreferencePage_job_indexing) {
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
IndexManager indexManager = MavenPlugin.getIndexManager();
indexManager.getWorkspaceIndex().updateIndex(true, monitor);
@@ -230,101 +259,49 @@ public class MavenSettingsPreferencePage extends PreferencePage implements IWork
}.schedule();
}
});
- defaultRuntime = runtimeManager.getDefaultRuntime();
+ ModifyListener settingsModifyListener = new ModifyListener() {
+ public void modifyText(ModifyEvent modifyevent) {
+ updateLocalRepository();
+ checkSettings();
+ }
+ };
+ userSettingsText.addModifyListener(settingsModifyListener);
+ globalSettingsText.addModifyListener(settingsModifyListener);
+
+ String globalSettings = mavenConfiguration.getGlobalSettingsFile();
+ if(globalSettings != null) {
+ globalSettingsText.setText(globalSettings);
+ }
String userSettings = mavenConfiguration.getUserSettingsFile();
- if(userSettings == null || userSettings.length() == 0) {
- userSettingsText.setText(MavenCli.DEFAULT_USER_SETTINGS_FILE.getAbsolutePath());
- } else {
+ if(userSettings != null) {
userSettingsText.setText(userSettings);
}
-
checkSettings();
updateLocalRepository();
- userSettingsText.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent modifyevent) {
- updateLocalRepository();
- checkSettings();
- setDirty(true);
- }
- });
-
return composite;
}
- public void updateSettingsLink(boolean active) {
- String text = org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_link1;
+ private void updateUserSettingsLink(boolean active) {
+ String text = Messages.MavenSettingsPreferencePage_userSettingslink1;
if(active) {
- text = org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_link2;
+ text = Messages.MavenSettingsPreferencePage_userSettingslink2;
}
userSettingsLink.setText(text);
}
- /**
- * @param composite
- */
- private void createUserSettings(Composite composite) {
-
- userSettingsLink = new Link(composite, SWT.NONE);
- userSettingsLink.setData("name", "userSettingsLink"); //$NON-NLS-1$ //$NON-NLS-2$
- userSettingsLink.setText(org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_link2);
- userSettingsLink.setToolTipText(org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_link_tooltip);
- GridData gd_userSettingsLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
-
- gd_userSettingsLabel.verticalIndent = 15;
- userSettingsLink.setLayoutData(gd_userSettingsLabel);
- userSettingsLink.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- String userSettings = getUserSettings();
- if(userSettings.length() == 0) {
- userSettings = MavenCli.DEFAULT_USER_SETTINGS_FILE.getAbsolutePath();
- }
- openEditor(userSettings);
- }
- });
- userSettingsText = new Text(composite, SWT.BORDER);
- userSettingsText.setData("name", "userSettingsText"); //$NON-NLS-1$ //$NON-NLS-2$
- GridData gd_userSettingsText = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
- gd_userSettingsText.verticalIndent = 5;
- gd_userSettingsText.widthHint = 100;
- userSettingsText.setLayoutData(gd_userSettingsText);
-
- Button userSettingsBrowseButton = new Button(composite, SWT.NONE);
- GridData gd_userSettingsBrowseButton = new GridData(SWT.FILL, SWT.RIGHT, false, false, 1, 1);
-
- userSettingsBrowseButton.setLayoutData(gd_userSettingsBrowseButton);
- userSettingsBrowseButton.setText(org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_btnBrowse);
- userSettingsBrowseButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
- if(getUserSettings().length() > 0) {
- dialog.setFileName(getUserSettings());
- }
- String file = dialog.open();
- if(file != null) {
- file = file.trim();
- if(file.length() > 0) {
- userSettingsText.setText(file);
- updateLocalRepository();
- checkSettings();
- }
- }
- }
- });
-
- Button updateSettings = new Button(composite, SWT.NONE);
- updateSettings.setText(org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_btnUpdate);
- updateSettings.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- updateSettings(true);
- }
- });
+ private void updateGlobalSettingsLink(boolean active) {
+ String text = Messages.MavenSettingsPreferencePage_globalSettingslink1;
+ if(active) {
+ text = Messages.MavenSettingsPreferencePage_globalSettingslink2;
+ }
+ globalSettingsLink.setText(text);
}
protected void updateLocalRepository() {
+ final String globalSettings = getGlobalSettings();
final String userSettings = getUserSettings();
- String globalSettings = runtimeManager.getGlobalSettingsFile();
try {
Settings settings = maven.buildSettings(globalSettings, userSettings);
String localRepository = settings.getLocalRepository();
@@ -342,28 +319,39 @@ public class MavenSettingsPreferencePage extends PreferencePage implements IWork
protected void checkSettings() {
setErrorMessage(null);
setMessage(null);
- boolean fileExists = false;
+
+ // NB: enable/disable links regardless of validation errors
+
+ String globalSettings = getGlobalSettings();
+ updateGlobalSettingsLink(globalSettings != null && new File(globalSettings).canRead());
+
String userSettings = getUserSettings();
- if(userSettings != null && userSettings.length() > 0) {
- File userSettingsFile = new File(userSettings);
- if(!userSettingsFile.exists()) {
- setMessage(org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_error_missing,
- IMessageProvider.WARNING);
- userSettings = null;
-
- } else {
- fileExists = true;
- }
+ updateUserSettingsLink(userSettings != null && new File(userSettings).canRead());
+
+ if(globalSettings != null
+ && !checkSettings(globalSettings, Messages.MavenSettingsPreferencePage_error_globalSettingsMissing,
+ Messages.MavenSettingsPreferencePage_error_globalSettingsParse)) {
+ return;
+ }
- } else {
- userSettings = null;
+ if(userSettings != null
+ && !checkSettings(userSettings, Messages.MavenSettingsPreferencePage_error_userSettingsMissing,
+ Messages.MavenSettingsPreferencePage_error_userSettingsParse)) {
+ return;
}
- updateSettingsLink(fileExists);
- List<SettingsProblem> result = maven.validateSettings(userSettings);
+ }
+
+ private boolean checkSettings(String location, String errorMissing, String errorParse) {
+ if(!new File(location).canRead()) {
+ setMessage(errorMissing, IMessageProvider.WARNING);
+ return false;
+ }
+ List<SettingsProblem> result = maven.validateSettings(location);
if(result.size() > 0) {
- setMessage(NLS.bind(org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_error_parse, result
- .get(0).getMessage()), IMessageProvider.WARNING);
+ setMessage(NLS.bind(errorParse, result.get(0).getMessage()), IMessageProvider.WARNING);
+ return false;
}
+ return true;
}
void openEditor(final String fileName) {
@@ -389,6 +377,31 @@ public class MavenSettingsPreferencePage extends PreferencePage implements IWork
}
String getUserSettings() {
- return userSettingsText.getText().trim();
+ return getSettings(userSettingsText);
+ }
+
+ String getGlobalSettings() {
+ return getSettings(globalSettingsText);
+ }
+
+ private String getSettings(Text settings) {
+ String location = settings.getText().trim();
+ return location.length() > 0 ? location : null;
+ }
+
+ protected void browseSettingsAction(Text settings) {
+ FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
+ if(settings.getText().trim().length() > 0) {
+ dialog.setFileName(settings.getText());
+ }
+ String file = dialog.open();
+ if(file != null) {
+ file = file.trim();
+ if(file.length() > 0) {
+ settings.setText(file);
+ updateLocalRepository();
+ checkSettings();
+ }
+ }
}
}
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 a07321ae..31998624 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
@@ -72,8 +72,7 @@ public class MavenConfigurationImpl implements IMavenConfiguration, IPreferenceC
((IEclipsePreferences) preferencesLookup[0].parent()).removeNodeChangeListener(this);
preferencesLookup[0].removePreferenceChangeListener(this);
}
- //Don't use InstanceScope.INSTANCE to maintain compatibility with helios
- preferencesLookup[0] = new InstanceScope().getNode(IMavenConstants.PLUGIN_ID);
+ preferencesLookup[0] = InstanceScope.INSTANCE.getNode(IMavenConstants.PLUGIN_ID);
((IEclipsePreferences) preferencesLookup[0].parent()).addNodeChangeListener(this);
preferencesLookup[0].addPreferenceChangeListener(this);
@@ -81,8 +80,7 @@ public class MavenConfigurationImpl implements IMavenConfiguration, IPreferenceC
((IEclipsePreferences) preferencesLookup[1].parent()).removeNodeChangeListener(this);
preferencesLookup[1].removePreferenceChangeListener(this);
}
- //Don't use DefaultScope.INSTANCE to maintain compatibility with helios
- preferencesLookup[1] = new DefaultScope().getNode(IMavenConstants.PLUGIN_ID);
+ preferencesLookup[1] = DefaultScope.INSTANCE.getNode(IMavenConstants.PLUGIN_ID);
((IEclipsePreferences) preferencesLookup[1].parent()).addNodeChangeListener(this);
}
@@ -126,17 +124,39 @@ public class MavenConfigurationImpl implements IMavenConfiguration, IPreferenceC
}
public void setUserSettingsFile(String settingsFile) throws CoreException {
- preferencesLookup[0].put(MavenPreferenceConstants.P_USER_SETTINGS_FILE, nvl(settingsFile));
- preferenceStore.applyPreferences(preferencesLookup[0], new IPreferenceFilter[] {getPreferenceFilter()});
+ settingsFile = trim(settingsFile);
+ if(!eq(settingsFile, preferencesLookup[0].get(MavenPreferenceConstants.P_USER_SETTINGS_FILE, null))) {
+ if(settingsFile != null) {
+ preferencesLookup[0].put(MavenPreferenceConstants.P_USER_SETTINGS_FILE, settingsFile);
+ } else {
+ preferencesLookup[0].remove(MavenPreferenceConstants.P_USER_SETTINGS_FILE);
+ }
+ preferenceStore.applyPreferences(preferencesLookup[0], new IPreferenceFilter[] {getPreferenceFilter()});
+ }
}
public void setGlobalSettingsFile(String globalSettingsFile) throws CoreException {
- preferencesLookup[0].put(MavenPreferenceConstants.P_GLOBAL_SETTINGS_FILE, nvl(globalSettingsFile));
- preferenceStore.applyPreferences(preferencesLookup[0], new IPreferenceFilter[] {getPreferenceFilter()});
+ globalSettingsFile = trim(globalSettingsFile);
+ if(!eq(globalSettingsFile, preferencesLookup[0].get(MavenPreferenceConstants.P_GLOBAL_SETTINGS_FILE, null))) {
+ if(globalSettingsFile != null) {
+ preferencesLookup[0].put(MavenPreferenceConstants.P_GLOBAL_SETTINGS_FILE, globalSettingsFile);
+ } else {
+ preferencesLookup[0].remove(MavenPreferenceConstants.P_GLOBAL_SETTINGS_FILE);
+ }
+ preferenceStore.applyPreferences(preferencesLookup[0], new IPreferenceFilter[] {getPreferenceFilter()});
+ }
}
- private static String nvl(String s) {
- return s == null ? "" : s; //$NON-NLS-1$
+ private boolean eq(String a, String b) {
+ return a != null ? a.equals(b) : b == null;
+ }
+
+ private String trim(String str) {
+ if(str == null) {
+ return null;
+ }
+ str = str.trim();
+ return !str.isEmpty() ? str : null;
}
public boolean isUpdateProjectsOnStartup() {
@@ -211,7 +231,11 @@ public class MavenConfigurationImpl implements IMavenConfiguration, IPreferenceC
}
public void setWorkspaceLifecycleMappingMetadataFile(String location) throws CoreException {
- preferencesLookup[0].put(MavenPreferenceConstants.P_WORKSPACE_MAPPINGS_LOCATION, nvl(location));
+ if(location != null) {
+ preferencesLookup[0].put(MavenPreferenceConstants.P_WORKSPACE_MAPPINGS_LOCATION, location);
+ } else {
+ preferencesLookup[0].remove(MavenPreferenceConstants.P_WORKSPACE_MAPPINGS_LOCATION);
+ }
preferenceStore.applyPreferences(preferencesLookup[0], new IPreferenceFilter[] {getPreferenceFilter()});
}
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java
index ffd7decd..44cb40d3 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java
@@ -15,8 +15,6 @@ import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.apache.maven.cli.MavenCli;
-
import org.eclipse.m2e.core.internal.IMavenConstants;
@@ -27,19 +25,9 @@ import org.eclipse.m2e.core.internal.IMavenConstants;
*/
public class MavenPreferenceInitializer extends AbstractPreferenceInitializer {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
- */
+ @Override
public void initializeDefaultPreferences() {
- //Don't use DefaultScope.INSTANCE to maintain compatibility with helios
- IEclipsePreferences store = new DefaultScope().getNode(IMavenConstants.PLUGIN_ID);
-
- store.put(MavenPreferenceConstants.P_USER_SETTINGS_FILE, //
- MavenCli.DEFAULT_USER_SETTINGS_FILE.getAbsolutePath());
-
- store.put(MavenPreferenceConstants.P_GLOBAL_SETTINGS_FILE, ""); //$NON-NLS-1$
+ IEclipsePreferences store = DefaultScope.INSTANCE.getNode(IMavenConstants.PLUGIN_ID);
store.putBoolean(MavenPreferenceConstants.P_DEBUG_OUTPUT, false);
@@ -49,10 +37,6 @@ public class MavenPreferenceInitializer extends AbstractPreferenceInitializer {
store.putBoolean(MavenPreferenceConstants.P_DOWNLOAD_SOURCES, false);
store.putBoolean(MavenPreferenceConstants.P_DOWNLOAD_JAVADOC, false);
- // store.setDefault( MavenPreferenceConstants.P_GLOBAL_CHECKSUM_POLICY, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
- // store.setDefault( MavenPreferenceConstants.P_UPDATE_SNAPSHOTS, false);
- // store.setDefault( MavenPreferenceConstants.P_CHECK_LATEST_PLUGIN_VERSION, false);
-
store.put(MavenPreferenceConstants.P_OUTPUT_FOLDER, "target-eclipse"); //$NON-NLS-1$
store.put(MavenPreferenceConstants.P_RUNTIMES, ""); //$NON-NLS-1$

Back to the top