Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2011-04-18 13:38:52 -0400
committerIgor Fedorenko2011-04-18 13:38:52 -0400
commitd86b6722b411779c7e503f63b70f5fe0ab5d9a33 (patch)
tree1b791b29022804edb39512a140574d081f8d67c9
parentd19635e05a89b09fdacb7bc7a9ae61f5735b88ac (diff)
downloadm2e-core-d86b6722b411779c7e503f63b70f5fe0ab5d9a33.tar.gz
m2e-core-d86b6722b411779c7e503f63b70f5fe0ab5d9a33.tar.xz
m2e-core-d86b6722b411779c7e503f63b70f5fe0ab5d9a33.zip
343180 - cache parsed user settings.xml
Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenSettingsPreferencePage.java3
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java54
2 files changed, 34 insertions, 23 deletions
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 3f566c0a..aa54ae1a 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
@@ -134,6 +134,8 @@ public class MavenSettingsPreferencePage extends PreferencePage implements IWork
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 {
@@ -313,7 +315,6 @@ public class MavenSettingsPreferencePage extends PreferencePage implements IWork
});
Button updateSettings = new Button(composite, SWT.NONE);
- GridData gd = new GridData(SWT.FILL, SWT.LEFT, false, false, 1, 1);
updateSettings.setText(org.eclipse.m2e.core.ui.internal.Messages.MavenSettingsPreferencePage_btnUpdate);
updateSettings.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
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 0001cd73..3458f2f8 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
@@ -164,7 +164,6 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener {
*/
public static final String MAVEN_CORE_REALM_ID = "plexus.core"; //$NON-NLS-1$
-
private DefaultPlexusContainer plexus;
private final IMavenConfiguration mavenConfiguration;
@@ -175,6 +174,11 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener {
private final ArrayList<ILocalRepositoryListener> localRepositoryListeners = new ArrayList<ILocalRepositoryListener>();
+ /**
+ * Cached parsed settings.xml instance
+ */
+ private Settings settings;
+
public MavenImpl(IMavenConfiguration mavenConfiguration) {
this.mavenConfiguration = mavenConfiguration;
mavenConfiguration.addConfigurationChangeListener(this);
@@ -354,28 +358,35 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener {
}
public Settings getSettings() throws CoreException {
+ return getSettings(false);
+ }
+
+ public synchronized Settings getSettings(boolean reload) throws CoreException {
// MUST NOT use createRequest!
- // TODO: Can't that delegate to buildSettings()?
- SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
- request.setSystemProperties(System.getProperties());
- if(mavenConfiguration.getGlobalSettingsFile() != null) {
- request.setGlobalSettingsFile(new File(mavenConfiguration.getGlobalSettingsFile()));
- }
- if(mavenConfiguration.getUserSettingsFile() != null) {
- request.setUserSettingsFile(new File(mavenConfiguration.getUserSettingsFile()));
- }
- try {
- return lookup(SettingsBuilder.class).build(request).getEffectiveSettings();
- } catch(SettingsBuildingException ex) {
- String msg = "Could not read settings.xml, assuming default values";
- log.error(msg, ex);
- /*
- * NOTE: This method provides input for various other core functions, just bailing out would make m2e highly
- * unusuable. Instead, we fail gracefully and just ignore the broken settings, using defaults.
- */
- return new Settings();
+ if (reload || settings==null) {
+ // TODO: Can't that delegate to buildSettings()?
+ SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
+ request.setSystemProperties(System.getProperties());
+ if(mavenConfiguration.getGlobalSettingsFile() != null) {
+ request.setGlobalSettingsFile(new File(mavenConfiguration.getGlobalSettingsFile()));
+ }
+ if(mavenConfiguration.getUserSettingsFile() != null) {
+ request.setUserSettingsFile(new File(mavenConfiguration.getUserSettingsFile()));
+ }
+ try {
+ settings = lookup(SettingsBuilder.class).build(request).getEffectiveSettings();
+ } catch(SettingsBuildingException ex) {
+ String msg = "Could not read settings.xml, assuming default values";
+ log.error(msg, ex);
+ /*
+ * NOTE: This method provides input for various other core functions, just bailing out would make m2e highly
+ * unusuable. Instead, we fail gracefully and just ignore the broken settings, using defaults.
+ */
+ settings = new Settings();
+ }
}
+ return settings;
}
public Settings buildSettings(String globalSettings, String userSettings) throws CoreException {
@@ -423,8 +434,7 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener {
}
public void reloadSettings() throws CoreException {
- // TODO do something more meaningful
- Settings settings = getSettings();
+ Settings settings = getSettings(true);
for(ISettingsChangeListener listener : settingsListeners) {
try {
listener.settingsChanged(settings);

Back to the top