--- maven.apisupport/src/org/netbeans/modules/maven/apisupport/InstallerPanel.java +++ maven.apisupport/src/org/netbeans/modules/maven/apisupport/InstallerPanel.java @@ -56,10 +56,11 @@ import org.netbeans.modules.maven.api.ModelUtils; import org.netbeans.modules.maven.api.NbMavenProject; import org.netbeans.modules.maven.api.PluginPropertyUtils; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.api.customizer.support.CheckBoxUpdater; import org.netbeans.modules.maven.api.customizer.support.TextComponentUpdater; import static org.netbeans.modules.maven.apisupport.Bundle.*; +import org.netbeans.modules.maven.model.ModelOperation; import org.netbeans.modules.maven.model.pom.Build; import org.netbeans.modules.maven.model.pom.Configuration; import org.netbeans.modules.maven.model.pom.POMExtensibilityElement; @@ -80,12 +81,14 @@ private static final String PROP_SOLARIS = "installerOsSolaris"; private static final String PROP_WINDOWS = "installerOsWindows"; + private static final String GOAL = "build-installers"; + private final ProjectCustomizer.Category category; private final Project project; - private final ModelHandle handle; + private final ModelHandle2 handle; @SuppressWarnings("ResultOfObjectAllocationIgnored") - private InstallerPanel(ProjectCustomizer.Category category, Project project, ModelHandle handle) { + private InstallerPanel(ProjectCustomizer.Category category, Project project, ModelHandle2 handle) { this.category = category; this.project = project; this.handle = handle; @@ -247,8 +250,7 @@ private javax.swing.JCheckBox windowsCheckBox; // End of variables declaration//GEN-END:variables - private Configuration config() { - POMModel pomModel = handle.getPOMModel(); + private static Configuration config(POMModel pomModel) { Build build = pomModel.getProject().getBuild(); if (build == null) { build = pomModel.getFactory().createBuild(); @@ -270,32 +272,28 @@ return config; } - private class BooleanPropUpdater extends CheckBoxUpdater { + private class BooleanPropUpdater extends CheckBoxUpdater implements ModelOperation { private final String property; private final boolean dflt; + private Boolean modifiedValue; + private final String pomValue; BooleanPropUpdater(String property, boolean dflt, JCheckBox comp) { super(comp); this.property = property; this.dflt = dflt; + pomValue = PluginPropertyUtils.getPluginProperty(project, MavenNbModuleImpl.GROUPID_MOJO, MavenNbModuleImpl.NBM_PLUGIN, property, GOAL); } @org.netbeans.api.annotations.common.SuppressWarnings("NP_BOOLEAN_RETURN_NULL") @Override public Boolean getValue() { - Configuration config = config(); - if (config != null) { - String val = config.getSimpleParameter(property); - if (val != null) { - return Boolean.valueOf(val); + if (modifiedValue != null) { + return modifiedValue; } + + return pomValue != null ? Boolean.valueOf(pomValue) : null; } - /* XXX suppress for consistency with StringPropUpdater: - String v = PluginPropertyUtils.getPluginProperty(project, MavenNbModuleImpl.GROUPID_MOJO, MavenNbModuleImpl.NBM_PLUGIN, property, GOAL); - return v != null ? Boolean.valueOf(v) : null; - */ - return null; - } @Override public boolean getDefaultValue() { return dflt; @@ -305,41 +303,50 @@ if (Utilities.compareObjects(value, getValue())) { return; } - Configuration config = config(); - POMExtensibilityElement e = ModelUtils.getOrCreateChild(config, property, config.getModel()); - if (value != null) { - e.setElementText(Boolean.toString(value)); + + modifiedValue = value; + handle.removePOMModification(this); + if (pomValue != null && pomValue.equals(modifiedValue)) { + //ignore now, we already have what we want in the project. } else { + handle.addPOMModification(this); + } + } + + @Override + public void performOperation(POMModel model) { + Configuration config = config(model); + if (modifiedValue != null) { + config.setSimpleParameter(property, modifiedValue != null ? Boolean.toString(modifiedValue) : Boolean.toString(getDefaultValue())); + } else { + //TODO for this case config(model) method which creates the configuration element is wrong.. + POMExtensibilityElement e = ModelUtils.getOrCreateChild(config, property, config.getModel()); config.removeExtensibilityElement(e); } - handle.markAsModified(handle.getPOMModel()); } } - private class StringPropUpdater extends TextComponentUpdater { + private class StringPropUpdater extends TextComponentUpdater implements ModelOperation{ private final String property; + private String modifiedValue; + private String pomValue; + StringPropUpdater(String property, JTextComponent comp, JLabel label) { super(comp, label); this.property = property; + pomValue = PluginPropertyUtils.getPluginProperty(project, MavenNbModuleImpl.GROUPID_MOJO, MavenNbModuleImpl.NBM_PLUGIN, property, GOAL); } @Override public String getValue() { - Configuration config = config(); - if (config != null) { - String val = config.getSimpleParameter(property); - if (val != null) { - return val; + if (modifiedValue != null) { + return modifiedValue; } + + return pomValue != null ? pomValue : ""; } - /* Cannot do this or we would fall back to last-saved value, which would be wrong; how to load inherited config? - String v = PluginPropertyUtils.getPluginProperty(project, MavenNbModuleImpl.GROUPID_MOJO, MavenNbModuleImpl.NBM_PLUGIN, property, GOAL); - return v != null ? v : ""; - */ - return null; - } @Override public String getDefaultValue() { return ""; @@ -349,14 +356,28 @@ if (Utilities.compareObjects(value, getValue())) { return; } - Configuration config = config(); + if (value == null) { + value = getDefaultValue(); + } + modifiedValue = value; + handle.removePOMModification(this); + if (pomValue != null && pomValue.equals(modifiedValue)) { + //we already have what we want in the pom.. skip + } else { + handle.addPOMModification(this); + } + } + + @Override + public void performOperation(POMModel model) { + Configuration config = config(model); POMExtensibilityElement e = ModelUtils.getOrCreateChild(config, property, config.getModel()); - if (value == null || value.isEmpty()) { + if (modifiedValue == null || modifiedValue.isEmpty()) { + //TODO for this case config(model) method which creates the configuration element is wrong.. config.removeExtensibilityElement(e); } else { - e.setElementText(value); + e.setElementText(modifiedValue); } - handle.markAsModified(handle.getPOMModel()); } } @@ -378,7 +399,7 @@ } @Override public JComponent createComponent(ProjectCustomizer.Category category, Lookup context) { - return new InstallerPanel(category, context.lookup(Project.class), context.lookup(ModelHandle.class)); + return new InstallerPanel(category, context.lookup(Project.class), context.lookup(ModelHandle2.class)); } } --- maven.apisupport/src/org/netbeans/modules/maven/apisupport/PackagesPanelProvider.java +++ maven.apisupport/src/org/netbeans/modules/maven/apisupport/PackagesPanelProvider.java @@ -45,11 +45,11 @@ import javax.swing.JComponent; import org.netbeans.api.project.Project; import org.netbeans.modules.maven.api.NbMavenProject; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; +import static org.netbeans.modules.maven.apisupport.Bundle.*; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; import org.openide.util.Lookup; -import static org.netbeans.modules.maven.apisupport.Bundle.*; import org.openide.util.NbBundle.Messages; /** @@ -67,7 +67,7 @@ NbMavenProject watcher = project.getLookup().lookup(NbMavenProject.class); if (NbMavenProject.TYPE_NBM.equalsIgnoreCase(watcher.getPackagingType())) { return ProjectCustomizer.Category.create( - ModelHandle.PANEL_COMPILE, + ModelHandle2.PANEL_COMPILE, TIT_Packages(), null); } @@ -76,7 +76,7 @@ @Override public JComponent createComponent(Category category, Lookup context) { - ModelHandle handle = context.lookup(ModelHandle.class); + ModelHandle2 handle = context.lookup(ModelHandle2.class); Project prj = context.lookup(Project.class); return new PublicPackagesPanel(handle, prj); } --- maven.apisupport/src/org/netbeans/modules/maven/apisupport/PublicPackagesPanel.java +++ maven.apisupport/src/org/netbeans/modules/maven/apisupport/PublicPackagesPanel.java @@ -55,9 +55,10 @@ import org.netbeans.modules.maven.api.FileUtilities; import org.netbeans.modules.maven.api.ModelUtils; import org.netbeans.modules.maven.api.PluginPropertyUtils; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.api.customizer.support.SelectedItemsTable; import org.netbeans.modules.maven.api.customizer.support.SelectedItemsTable.SelectedItemsTableModel; +import org.netbeans.modules.maven.model.ModelOperation; import org.netbeans.modules.maven.model.pom.Build; import org.netbeans.modules.maven.model.pom.Configuration; import org.netbeans.modules.maven.model.pom.POMExtensibilityElement; @@ -79,11 +80,12 @@ private static final String PUBLIC_PACKAGES = "publicPackages"; private final SelectedItemsTableModel tableModel; - private final ModelHandle handle; + private final ModelHandle2 handle; private final Project project; + private ModelOperation operation; /** Creates new form PublicPackagesPanel */ - public PublicPackagesPanel(ModelHandle handle, Project prj) { + public PublicPackagesPanel(ModelHandle2 handle, Project prj) { this.handle = handle; this.project = prj; tableModel = new SelectedItemsTableModel(this); @@ -174,8 +176,15 @@ } @Override - public void write(SortedMap selItems) { - POMModel pomModel = handle.getPOMModel(); + public void write(SortedMap items) { + if (operation != null) { + handle.removePOMModification(operation); + } + final SortedMap selItems = new TreeMap(items); + operation = new ModelOperation() { + + @Override + public void performOperation(POMModel pomModel) { Build build = pomModel.getProject().getBuild(); boolean selEmpty = true; for (Boolean selected : selItems.values()) { @@ -220,7 +229,6 @@ if (selEmpty) { if (packages != null) { config.removeExtensibilityElement(packages); - handle.markAsModified(pomModel); } return; } @@ -239,8 +247,10 @@ packages.addExtensibilityElement(publicP); } - handle.markAsModified(pomModel); } + }; + handle.addPOMModification(operation); + } /** * Transforms public packages in form of "selected items" map into --- maven.checkstyle/src/org/netbeans/modules/maven/format/checkstyle/CheckstyleCustomizerPanel.java +++ maven.checkstyle/src/org/netbeans/modules/maven/format/checkstyle/CheckstyleCustomizerPanel.java @@ -44,7 +44,7 @@ package org.netbeans.modules.maven.format.checkstyle; import javax.swing.JComponent; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.openide.util.Lookup; import org.openide.util.NbBundle; @@ -66,7 +66,7 @@ @Override public JComponent createComponent(ProjectCustomizer.Category cat, Lookup look) { - ModelHandle handle = look.lookup(ModelHandle.class); + ModelHandle2 handle = look.lookup(ModelHandle2.class); return new CheckstylePanel(handle, cat); } --- maven.checkstyle/src/org/netbeans/modules/maven/format/checkstyle/CheckstylePanel.java +++ maven.checkstyle/src/org/netbeans/modules/maven/format/checkstyle/CheckstylePanel.java @@ -50,8 +50,9 @@ import java.net.MalformedURLException; import java.net.URL; import org.netbeans.modules.maven.api.Constants; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.api.customizer.support.CheckBoxUpdater; +import org.netbeans.modules.maven.model.ModelOperation; import org.netbeans.modules.maven.model.pom.Configuration; import org.netbeans.modules.maven.model.pom.POMModel; import org.netbeans.modules.maven.model.pom.Properties; @@ -73,24 +74,42 @@ * @author mkleint */ public class CheckstylePanel extends javax.swing.JPanel { - private final ModelHandle handle; + private final ModelHandle2 handle; private final ProjectCustomizer.Category category; private boolean generated = false; private final CheckBoxUpdater checkboxUpdater; - CheckstylePanel(ModelHandle hndl, ProjectCustomizer.Category cat) { + CheckstylePanel(ModelHandle2 hndl, ProjectCustomizer.Category cat) { initComponents(); this.handle = hndl; category = cat; checkboxUpdater = new CheckBoxUpdater(cbEnable) { + + private String modifiedValue; + + private ModelOperation operation = new ModelOperation() { @Override + public void performOperation(POMModel model) { + Properties modprops = model.getProject().getProperties(); + if (modprops == null) { + modprops = model.getFactory().createProperties(); + model.getProject().setProperties(modprops); + } + modprops.setProperty(Constants.HINT_COMPILE_ON_SAVE, modifiedValue); //NOI18N + } + + }; + + @Override public Boolean getValue() { - String val = null; + String val = modifiedValue; + if (val == null) { Properties props = handle.getPOMModel().getProject().getProperties(); if (props != null) { val = props.getProperty(Constants.HINT_CHECKSTYLE_FORMATTING); } + } if (val == null) { val = handle.getRawAuxiliaryProperty(Constants.HINT_CHECKSTYLE_FORMATTING, true); } @@ -108,18 +127,16 @@ @Override public void setValue(Boolean value) { + handle.removePOMModification(operation); + modifiedValue = null; + String val = value != null ? value.toString() : null; boolean hasConfig = handle.getRawAuxiliaryProperty(Constants.HINT_CHECKSTYLE_FORMATTING, true) != null; //TODO also try to take the value in pom vs inherited pom value into account. if (handle.getProject().getProperties().containsKey(Constants.HINT_CHECKSTYLE_FORMATTING)) { - Properties modprops = handle.getPOMModel().getProject().getProperties(); - if (modprops == null) { - modprops = handle.getPOMModel().getFactory().createProperties(); - handle.getPOMModel().getProject().setProperties(modprops); - } - modprops.setProperty(Constants.HINT_CHECKSTYLE_FORMATTING, val); //NOI18N - handle.markAsModified(handle.getPOMModel()); + modifiedValue = val; + handle.addPOMModification(operation); if (hasConfig) { // in this case clean up the auxiliary config handle.setRawAuxiliaryProperty(Constants.HINT_CHECKSTYLE_FORMATTING, null, true); @@ -228,7 +245,10 @@ private void btnMissingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMissingActionPerformed generated = true; //generate now - POMModel mdl = handle.getPOMModel(); + handle.addPOMModification(new ModelOperation() { + + @Override + public void performOperation(POMModel mdl) { Reporting rep = mdl.getProject().getReporting(); if (rep == null) { rep = mdl.getFactory().createReporting(); @@ -244,7 +264,8 @@ plg.setConfiguration(conf); rep.addReportPlugin(plg); } - handle.markAsModified(handle.getPOMModel()); + } + }); //hide the button, we're done lblMissing.setVisible(false); --- maven.j2ee/src/org/netbeans/modules/maven/j2ee/ExecutionChecker.java +++ maven.j2ee/src/org/netbeans/modules/maven/j2ee/ExecutionChecker.java @@ -41,7 +41,6 @@ */ package org.netbeans.modules.maven.j2ee; -import org.netbeans.modules.maven.j2ee.utils.LoggingUtils; import java.io.File; import java.io.IOException; import java.net.URL; @@ -58,16 +57,17 @@ import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo; import org.netbeans.modules.maven.api.NbMavenProject; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.api.execute.ExecutionContext; import org.netbeans.modules.maven.api.execute.ExecutionResultChecker; import org.netbeans.modules.maven.api.execute.PrerequisitesChecker; import org.netbeans.modules.maven.api.execute.RunConfig; import org.netbeans.modules.maven.api.execute.RunUtils; import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; -import org.netbeans.modules.maven.spi.debug.MavenDebugger; import org.netbeans.modules.maven.j2ee.customizer.CustomizerRunWeb; +import org.netbeans.modules.maven.j2ee.utils.LoggingUtils; import org.netbeans.modules.maven.j2ee.utils.MavenProjectSupport; +import org.netbeans.modules.maven.spi.debug.MavenDebugger; import org.netbeans.spi.project.AuxiliaryProperties; import org.netbeans.spi.project.ProjectConfiguration; import org.netbeans.spi.project.ProjectConfigurationProvider; @@ -303,10 +303,10 @@ private static void removeNetbeansDeployFromActionMappings(Project project, String actionName) { try { ProjectConfiguration cfg = project.getLookup().lookup(ProjectConfigurationProvider.class).getActiveConfiguration(); - NetbeansActionMapping mapp = ModelHandle.getMapping(actionName, project, cfg); + NetbeansActionMapping mapp = ModelHandle2.getMapping(actionName, project, cfg); if (mapp != null) { mapp.getProperties().remove(MavenJavaEEConstants.ACTION_PROPERTY_DEPLOY); - ModelHandle.putMapping(mapp, project, cfg); + ModelHandle2.putMapping(mapp, project, cfg); } } catch (IOException ex) { Exceptions.printStackTrace(ex); --- maven.j2ee/src/org/netbeans/modules/maven/j2ee/Wrapper.java +++ maven.j2ee/src/org/netbeans/modules/maven/j2ee/Wrapper.java @@ -48,9 +48,10 @@ import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; import org.netbeans.modules.j2ee.deployment.devmodules.api.InstanceRemovedException; import org.netbeans.modules.j2ee.deployment.devmodules.api.ServerInstance; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.api.customizer.support.ComboBoxUpdater; import org.netbeans.modules.maven.j2ee.utils.MavenProjectSupport; +import org.netbeans.modules.maven.model.ModelOperation; import org.netbeans.modules.maven.model.pom.POMModel; import org.netbeans.modules.maven.model.pom.Properties; @@ -93,7 +94,7 @@ if (ExecutionChecker.DEV_NULL.equals(serverInstanceId)) { if (sessionServerInstanceId != null) { ServerInstance si = Deployment.getDefault().getServerInstance(sessionServerInstanceId); - String dn = sessionServerInstanceId; + String dn; try { dn = si.getDisplayName(); } catch (InstanceRemovedException ex) { @@ -136,20 +137,47 @@ } - public static ComboBoxUpdater createComboBoxUpdater(final ModelHandle handle, final JComboBox combo, JLabel label) { + public static ComboBoxUpdater createComboBoxUpdater(final ModelHandle2 handle, final JComboBox combo, JLabel label) { return new ComboBoxUpdater(combo, label) { + + private Wrapper modified; + private ModelOperation operation = new ModelOperation() { + @Override + public void performOperation(POMModel model) { + String sID = modified.getServerID(); + String iID = modified.getServerInstanceID(); + + if (ExecutionChecker.DEV_NULL.equals(iID)) { + Properties props = model.getProject().getProperties(); + if (props != null) { + props.setProperty(MavenJavaEEConstants.HINT_DEPLOY_J2EE_SERVER, null); + } + } else { + Properties props = model.getProject().getProperties(); + if (props == null) { + props = model.getFactory().createProperties(); + model.getProject().setProperties(props); + } + props.setProperty(MavenJavaEEConstants.HINT_DEPLOY_J2EE_SERVER, sID); + } + } + }; + + @Override public Wrapper getDefaultValue() { return null; } @Override public Wrapper getValue() { - Wrapper wr = null; + Wrapper wr = modified; + if (wr == null) { String id = handle.getRawAuxiliaryProperty(MavenJavaEEConstants.HINT_DEPLOY_J2EE_SERVER_ID, false); if (id != null) { wr = findWrapperByInstance(id, combo); } + } if (wr == null) { POMModel model = handle.getPOMModel(); Properties props = model.getProject().getProperties(); @@ -172,26 +200,16 @@ if (wr == null) { return; } + modified = wr; + handle.removePOMModification(operation); + handle.addPOMModification(operation); String sID = wr.getServerID(); String iID = wr.getServerInstanceID(); //remove old deprecated data. handle.setRawAuxiliaryProperty(MavenJavaEEConstants.HINT_DEPLOY_J2EE_SERVER_OLD, null, true); - POMModel model = handle.getPOMModel(); if (ExecutionChecker.DEV_NULL.equals(iID)) { - Properties props = model.getProject().getProperties(); - if (props != null) { - props.setProperty(MavenJavaEEConstants.HINT_DEPLOY_J2EE_SERVER, null); - handle.markAsModified(handle.getPOMModel()); - } handle.setRawAuxiliaryProperty(MavenJavaEEConstants.HINT_DEPLOY_J2EE_SERVER_ID, null, false); } else { - Properties props = model.getProject().getProperties(); - if (props == null) { - props = model.getFactory().createProperties(); - model.getProject().setProperties(props); - } - props.setProperty(MavenJavaEEConstants.HINT_DEPLOY_J2EE_SERVER, sID); - handle.markAsModified(handle.getPOMModel()); handle.setRawAuxiliaryProperty(MavenJavaEEConstants.HINT_DEPLOY_J2EE_SERVER_ID, iID, false); } } --- maven.j2ee/src/org/netbeans/modules/maven/j2ee/customizer/BaseRunCustomizer.java +++ maven.j2ee/src/org/netbeans/modules/maven/j2ee/customizer/BaseRunCustomizer.java @@ -56,7 +56,7 @@ import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; import org.netbeans.modules.maven.api.Constants; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.api.customizer.support.CheckBoxUpdater; import org.netbeans.modules.maven.api.customizer.support.ComboBoxUpdater; import org.netbeans.modules.maven.j2ee.ExecutionChecker; @@ -72,16 +72,17 @@ public abstract class BaseRunCustomizer extends JPanel implements ApplyChangesCustomizer { protected Project project; - protected ModelHandle handle; + protected ModelHandle2 handle; protected CheckBoxUpdater deployOnSaveUpdater; protected ComboBoxUpdater serverModelUpdater; - public BaseRunCustomizer(ModelHandle handle, Project project) { + public BaseRunCustomizer(ModelHandle2 handle, Project project) { this.handle = handle; this.project = project; } + //mkleint: this method should only be run from within the ApplyChangesCustomizer.applyChanges() method protected void changeServer(JComboBox selectedServerComboBox) { SessionContent sc = project.getLookup().lookup(SessionContent.class); if (serverModelUpdater.getValue() != null) { --- maven.j2ee/src/org/netbeans/modules/maven/j2ee/customizer/CustomizerRunEar.java +++ maven.j2ee/src/org/netbeans/modules/maven/j2ee/customizer/CustomizerRunEar.java @@ -43,11 +43,11 @@ package org.netbeans.modules.maven.j2ee.customizer; import java.io.IOException; -import org.netbeans.modules.maven.api.customizer.ModelHandle; -import static org.netbeans.modules.maven.j2ee.customizer.CustomizerRunWeb.PROP_SHOW_IN_BROWSER; import org.netbeans.api.project.Project; import org.netbeans.modules.j2ee.api.ejbjar.Ear; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; +import static org.netbeans.modules.maven.j2ee.customizer.CustomizerRunWeb.PROP_SHOW_IN_BROWSER; import org.netbeans.modules.maven.j2ee.utils.LoggingUtils; import org.openide.util.Exceptions; @@ -57,7 +57,7 @@ private Ear module; - public CustomizerRunEar(ModelHandle handle, Project project) { + public CustomizerRunEar(ModelHandle2 handle, Project project) { super(handle, project); initComponents(); --- maven.j2ee/src/org/netbeans/modules/maven/j2ee/customizer/CustomizerRunEjb.java +++ maven.j2ee/src/org/netbeans/modules/maven/j2ee/customizer/CustomizerRunEjb.java @@ -42,10 +42,10 @@ package org.netbeans.modules.maven.j2ee.customizer; -import org.netbeans.modules.maven.api.customizer.ModelHandle; import org.netbeans.api.project.Project; import org.netbeans.modules.j2ee.api.ejbjar.EjbJar; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.j2ee.utils.LoggingUtils; @@ -54,7 +54,7 @@ private EjbJar module; - public CustomizerRunEjb(ModelHandle handle, Project project) { + public CustomizerRunEjb(ModelHandle2 handle, Project project) { super(handle, project); initComponents(); --- maven.j2ee/src/org/netbeans/modules/maven/j2ee/customizer/CustomizerRunWeb.java +++ maven.j2ee/src/org/netbeans/modules/maven/j2ee/customizer/CustomizerRunWeb.java @@ -46,28 +46,30 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; -import javax.swing.JList; import java.util.Iterator; import java.util.List; import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultListCellRenderer; +import javax.swing.JList; import javax.swing.SwingUtilities; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.netbeans.api.j2ee.core.Profile; -import org.netbeans.modules.maven.api.customizer.ModelHandle; import org.netbeans.api.project.Project; import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; import org.netbeans.modules.maven.api.ModelUtils; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; import org.netbeans.modules.maven.j2ee.ExecutionChecker; -import org.netbeans.modules.maven.j2ee.utils.LoggingUtils; import static org.netbeans.modules.maven.j2ee.ExecutionChecker.CLIENTURLPART; import org.netbeans.modules.maven.j2ee.MavenJavaEEConstants; import org.netbeans.modules.maven.j2ee.Wrapper; +import org.netbeans.modules.maven.j2ee.utils.LoggingUtils; import org.netbeans.modules.maven.j2ee.web.WebModuleImpl; import org.netbeans.modules.maven.j2ee.web.WebModuleProviderImpl; +import org.netbeans.modules.maven.model.ModelOperation; import org.netbeans.modules.maven.model.pom.Dependency; +import org.netbeans.modules.maven.model.pom.POMModel; import org.netbeans.modules.maven.model.pom.Properties; import org.netbeans.modules.web.api.webmodule.WebModule; import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent; @@ -98,7 +100,7 @@ private String oldContextPath; - public CustomizerRunWeb(final ModelHandle handle, Project project) { + public CustomizerRunWeb(final ModelHandle2 handle, Project project) { super(handle, project); initComponents(); module = WebModule.getWebModule(project.getProjectDirectory()); @@ -135,18 +137,20 @@ comProfile.setSelectedItem(Profile.JAVA_EE_6_WEB); } comProfile.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - Profile p = (Profile) comProfile.getSelectedItem(); - org.netbeans.modules.maven.model.pom.Project root = handle.getPOMModel().getProject(); - if (p.equals(Profile.JAVA_EE_6_FULL)) { + private Profile modified; + private ModelOperation operation = new ModelOperation() { + + @Override + public void performOperation(POMModel model) { + org.netbeans.modules.maven.model.pom.Project root = model.getProject(); + if (Profile.JAVA_EE_6_FULL.equals(modified)) { Properties props = root.getProperties(); if (props == null) { - props = handle.getPOMModel().getFactory().createProperties(); + props = model.getFactory().createProperties(); root.setProperties(props); } - replaceDependency("javaee-web-api", "javaee-api"); - props.setProperty(MavenJavaEEConstants.HINT_J2EE_VERSION, p.toPropertiesString()); - handle.markAsModified(handle.getPOMModel()); + props.setProperty(MavenJavaEEConstants.HINT_J2EE_VERSION, modified.toPropertiesString()); + replaceDependency(model, "javaee-web-api", "javaee-api"); } else { Properties props = root.getProperties(); if (props != null && props.getProperty(MavenJavaEEConstants.HINT_J2EE_VERSION) != null) { @@ -154,12 +158,20 @@ if (props.getProperties().size() == 0) { ((AbstractDocumentComponent)root).removeChild("properties", props); } - replaceDependency("javaee-api", "javaee-web-api"); - handle.markAsModified(handle.getPOMModel()); + replaceDependency(model, "javaee-api", "javaee-web-api"); } } } + }; + @Override + public void actionPerformed(ActionEvent e) { + Profile p = (Profile) comProfile.getSelectedItem(); + modified = p; + handle.removePOMModification(operation); + handle.addPOMModification(operation); + } + }); } else { lblProfile.setVisible(false); @@ -190,9 +202,9 @@ } if (actionMappings == null || actionMappings.isEmpty()) { - run = ModelHandle.getDefaultMapping(ActionProvider.COMMAND_RUN, project); - debug = ModelHandle.getDefaultMapping(ActionProvider.COMMAND_DEBUG, project); - profile = ModelHandle.getDefaultMapping("profile", project); // NOI18N + run = ModelHandle2.getDefaultMapping(ActionProvider.COMMAND_RUN, project); + debug = ModelHandle2.getDefaultMapping(ActionProvider.COMMAND_DEBUG, project); + profile = ModelHandle2.getDefaultMapping("profile", project); // NOI18N } isRunCompatible = checkMapping(run); @@ -213,14 +225,17 @@ oldUrl = ""; //NOI18N } txtRelativeUrl.getDocument().addDocumentListener(new DocumentListener() { + @Override public void insertUpdate(DocumentEvent arg0) { applyRelUrl(); } + @Override public void removeUpdate(DocumentEvent arg0) { applyRelUrl(); } + @Override public void changedUpdate(DocumentEvent arg0) { applyRelUrl(); } @@ -420,17 +435,17 @@ if (!newUrl.equals(oldUrl)) { if (isRunCompatible) { run.addProperty(CLIENTURLPART, newUrl); - ModelHandle.setUserActionMapping(run, handle.getActionMappings()); + ModelHandle2.setUserActionMapping(run, handle.getActionMappings()); handle.markAsModified(handle.getActionMappings()); } if (isDebugCompatible) { debug.addProperty(CLIENTURLPART, newUrl); - ModelHandle.setUserActionMapping(debug, handle.getActionMappings()); + ModelHandle2.setUserActionMapping(debug, handle.getActionMappings()); handle.markAsModified(handle.getActionMappings()); } if (isProfileCompatible) { profile.addProperty(CLIENTURLPART, newUrl); - ModelHandle.setUserActionMapping(profile, handle.getActionMappings()); + ModelHandle2.setUserActionMapping(profile, handle.getActionMappings()); handle.markAsModified(handle.getActionMappings()); } } @@ -487,13 +502,17 @@ - private void replaceDependency(String oldArt, String newArt) { - Dependency d = ModelUtils.checkModelDependency(handle.getPOMModel(), "javax", oldArt, false); + private void replaceDependency(POMModel model, String oldArt, String newArt) { + Dependency d = ModelUtils.checkModelDependency(model, "javax", oldArt, false); if (d != null) { d.setArtifactId(newArt); } } + /* + * + * TODO - mkleint: this method has little relevant with the customizers, candidate for moving. + */ public static boolean isDeployOnSave(Project project) { //try to apply the hint if it exists. AuxiliaryProperties prop = project.getLookup().lookup(AuxiliaryProperties.class); --- maven.j2ee/src/org/netbeans/modules/maven/j2ee/customizer/MavenCompositePanelProvider.java +++ maven.j2ee/src/org/netbeans/modules/maven/j2ee/customizer/MavenCompositePanelProvider.java @@ -46,7 +46,7 @@ import javax.swing.JComponent; import org.netbeans.api.project.Project; import org.netbeans.modules.maven.api.NbMavenProject; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; import org.openide.util.Lookup; @@ -105,7 +105,7 @@ @Override public JComponent createComponent(Category category, Lookup context) { String name = category.getName(); - ModelHandle handle = context.lookup(ModelHandle.class); + ModelHandle2 handle = context.lookup(ModelHandle2.class); Project project = context.lookup(Project.class); category.setOkButtonListener(listenerAWT); --- maven.osgi/src/org/netbeans/modules/maven/osgi/customizer/FelixExportPersister.java +++ maven.osgi/src/org/netbeans/modules/maven/osgi/customizer/FelixExportPersister.java @@ -50,7 +50,8 @@ import org.netbeans.api.project.Project; import org.netbeans.modules.maven.api.ModelUtils; import org.netbeans.modules.maven.api.PluginPropertyUtils; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; +import org.netbeans.modules.maven.model.ModelOperation; import org.netbeans.modules.maven.model.pom.Build; import org.netbeans.modules.maven.model.pom.Configuration; import org.netbeans.modules.maven.model.pom.POMExtensibilityElement; @@ -65,10 +66,11 @@ */ public class FelixExportPersister implements SelectedItemsTablePersister { - private final ModelHandle handle; + private final ModelHandle2 handle; private final Project project; + private ModelOperation operation; - public FelixExportPersister (Project project, ModelHandle handle) { + public FelixExportPersister (Project project, ModelHandle2 handle) { this.project = project; this.handle = handle; } @@ -101,9 +103,15 @@ @Override public void write(SortedMap selItems) { - Map exportIns = InstructionsConverter.computeExportInstructions(selItems, project); - final POMModel pomModel = handle.getPOMModel(); + if (operation != null) { + handle.removePOMModification(operation); + } + final Map exportIns = InstructionsConverter.computeExportInstructions(selItems, project); + operation = new ModelOperation() { + + @Override + public void performOperation(POMModel pomModel) { Build build = pomModel.getProject().getBuild(); Plugin felixPlugin = null; if (build != null) { @@ -147,8 +155,10 @@ exportEl.setElementText(exportIns.get(InstructionsConverter.EXPORT_PACKAGE)); privateEl.setElementText(exportIns.get(InstructionsConverter.PRIVATE_PACKAGE)); - handle.markAsModified(pomModel); } + }; + handle.addPOMModification(operation); + } } --- maven.osgi/src/org/netbeans/modules/maven/osgi/customizer/PackagesPanel.java +++ maven.osgi/src/org/netbeans/modules/maven/osgi/customizer/PackagesPanel.java @@ -49,7 +49,7 @@ package org.netbeans.modules.maven.osgi.customizer; import org.netbeans.api.project.Project; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.api.customizer.support.SelectedItemsTable; import org.netbeans.modules.maven.api.customizer.support.SelectedItemsTable.SelectedItemsTableModel; @@ -62,7 +62,7 @@ private final SelectedItemsTableModel tableModel; /** Creates new form PackagesPanel */ - public PackagesPanel(ModelHandle handle, Project prj) { + public PackagesPanel(ModelHandle2 handle, Project prj) { FelixExportPersister exportPersist = new FelixExportPersister(prj, handle); tableModel = new SelectedItemsTableModel(exportPersist); --- maven.osgi/src/org/netbeans/modules/maven/osgi/customizer/PackagesPanelProvider.java +++ maven.osgi/src/org/netbeans/modules/maven/osgi/customizer/PackagesPanelProvider.java @@ -45,7 +45,7 @@ import javax.swing.JComponent; import org.netbeans.api.project.Project; import org.netbeans.modules.maven.api.NbMavenProject; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; import org.openide.util.Lookup; @@ -63,7 +63,7 @@ NbMavenProject watcher = project.getLookup().lookup(NbMavenProject.class); if (NbMavenProject.TYPE_OSGI.equalsIgnoreCase(watcher.getPackagingType())) { return ProjectCustomizer.Category.create( - ModelHandle.PANEL_COMPILE, + ModelHandle2.PANEL_COMPILE, org.openide.util.NbBundle.getMessage(PackagesPanelProvider.class, "TIT_Packages"), null); } @@ -72,7 +72,7 @@ @Override public JComponent createComponent(Category category, Lookup context) { - ModelHandle handle = context.lookup(ModelHandle.class); + ModelHandle2 handle = context.lookup(ModelHandle2.class); Project prj = context.lookup(Project.class); final PackagesPanel panel = new PackagesPanel(handle, prj); return panel; --- maven/src/org/netbeans/modules/maven/ActionProviderImpl.java +++ maven/src/org/netbeans/modules/maven/ActionProviderImpl.java @@ -64,7 +64,7 @@ import org.netbeans.modules.maven.api.Constants; import org.netbeans.modules.maven.api.NbMavenProject; import org.netbeans.modules.maven.api.PluginPropertyUtils; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.api.execute.RunConfig; import org.netbeans.modules.maven.api.execute.RunUtils; import org.netbeans.modules.maven.configurations.M2ConfigProvider; @@ -362,7 +362,7 @@ mapping.setActionName(tit); mapping.setDisplayName(pnl.isRememberedAs()); //TODO shall we write to configuration based files or not? - ModelHandle.putMapping(mapping, proj, conf.getDefaultConfig()); + ModelHandle2.putMapping(mapping, proj, conf.getDefaultConfig()); } catch (Exception ex) { ex.printStackTrace(); } --- maven/src/org/netbeans/modules/maven/MavenProjectPropsImpl.java +++ maven/src/org/netbeans/modules/maven/MavenProjectPropsImpl.java @@ -76,9 +76,6 @@ private static final Logger LOG = Logger.getLogger(MavenProjectPropsImpl.class.getName()); - private boolean transaction = false; - private TreeMap transPropsShared; - private TreeMap transPropsPrivate; private final AuxiliaryConfiguration aux; private boolean sharedChanged; private final NbMavenProjectImpl nbprji; @@ -97,21 +94,12 @@ } public synchronized String get(String key, boolean shared, boolean usePom) { - if (transaction) { - if (shared && transPropsShared.containsKey(key)) { - return transPropsShared.get(key); - } - if (!shared && transPropsPrivate.containsKey(key)) { - return transPropsPrivate.get(key); - } - } else { TreeMap props = readProperties(getAuxConf(), shared); //TODO optimize String ret = props.get(key); if (ret != null) { return ret; } - } if (shared && usePom) { String val = nbprji.getOriginalMavenProject().getProperties().getProperty(key); if (val != null) { @@ -125,16 +113,8 @@ if (shared) { //TODO put props to project.. shall we actually do it here? } - if (transaction) { - if (shared) { - sharedChanged |= !Utilities.compareObjects(value, transPropsShared.put(key, value)); - } else { - transPropsPrivate.put(key, value); - } - } else { writeAuxiliaryData(getAuxConf(), key, value, shared); } - } public synchronized Iterable listKeys(boolean shared) { TreeMap props = readProperties(getAuxConf(), shared); @@ -174,7 +154,7 @@ } } - private void writeAuxiliaryData(AuxiliaryConfiguration conf, TreeMap props, boolean shared) { + public static void writeAuxiliaryData(AuxiliaryConfiguration conf, TreeMap props, boolean shared) { Element el = getOrCreateRootElement(conf, shared); Element enEl; for (String key : props.keySet()) { @@ -204,7 +184,7 @@ } } - private Element getOrCreateRootElement(AuxiliaryConfiguration conf, boolean shared) { + private static Element getOrCreateRootElement(AuxiliaryConfiguration conf, boolean shared) { Element el = conf.getConfigurationFragment(ROOT, NAMESPACE, shared); if (el == null) { el = XMLUtil.createDocument(ROOT, NAMESPACE, null, null).getDocumentElement(); @@ -242,33 +222,7 @@ return readProperties(getAuxConf(), shared); } - public synchronized void startTransaction() { - transaction = true; - transPropsShared = getRawProperties(true); - transPropsPrivate = getRawProperties(false); - sharedChanged = false; - } - public synchronized void commitTransaction() { - transaction = false; - if (transPropsShared == null) { - LOG.warning("Committing a transaction that was canceled."); - return; - } - if (sharedChanged) { - writeAuxiliaryData(getAuxConf(), transPropsShared, true); - } - writeAuxiliaryData(getAuxConf(), transPropsPrivate, false); - transPropsPrivate = null; - transPropsShared = null; - } - - public synchronized void cancelTransaction() { - transaction = false; - transPropsPrivate = null; - transPropsShared = null; - } - static class Merger implements LookupMerger { private MavenProjectPropsImpl primary; --- maven/src/org/netbeans/modules/maven/api/customizer/ModelHandle.java +++ maven/src/org/netbeans/modules/maven/api/customizer/ModelHandle.java @@ -43,24 +43,18 @@ package org.netbeans.modules.maven.api.customizer; import java.io.IOException; -import java.io.StringReader; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.netbeans.api.annotations.common.CheckForNull; -import org.netbeans.modules.maven.configurations.M2Configuration; -import org.netbeans.modules.maven.customizer.CustomizerProviderImpl; -import org.netbeans.modules.maven.execute.ActionToGoalUtils; import org.netbeans.api.project.Project; import org.netbeans.modules.maven.MavenProjectPropsImpl; +import org.netbeans.modules.maven.configurations.M2Configuration; +import org.netbeans.modules.maven.customizer.CustomizerProviderImpl; import org.netbeans.modules.maven.execute.model.ActionToGoalMapping; import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; -import org.netbeans.modules.maven.execute.model.io.xpp3.NetbeansBuildActionXpp3Reader; import org.netbeans.modules.maven.model.pom.POMModel; import org.netbeans.spi.project.ProjectConfiguration; import org.openide.util.NbBundle; @@ -95,6 +89,7 @@ } + static class AccessorImpl extends CustomizerProviderImpl.ModelAccessor { public @Override ModelHandle createHandle(POMModel model, @@ -202,28 +197,14 @@ * @param mapp */ public static void setUserActionMapping(NetbeansActionMapping action, ActionToGoalMapping mapp) { - action.setPackagings(null); - List lst = mapp.getActions() != null ? mapp.getActions() : new ArrayList(); - Iterator it = lst.iterator(); - while (it.hasNext()) { - NetbeansActionMapping act = it.next(); - if (act.getActionName().equals(action.getActionName())) { - int index = lst.indexOf(act); - it.remove(); - lst.add(index, action); - return; + ModelHandle2.setUserActionMapping(action, mapp); } - } - //if not found, add to the end. - lst.add(action); - } - /** * @since 2.19 */ public static @CheckForNull NetbeansActionMapping getDefaultMapping(String action, Project project) { - return ActionToGoalUtils.getDefaultMapping(action, project); + return ModelHandle2.getDefaultMapping(action, project); } /** @@ -235,7 +216,7 @@ * @since 2.19 */ public static @CheckForNull NetbeansActionMapping getMapping(String action, Project project, ProjectConfiguration config) { - return ActionToGoalUtils.getActiveMapping(action, project, (M2Configuration) config); + return ModelHandle2.getMapping(action, project, config); } /** @@ -247,27 +228,8 @@ * @since 2.19 */ public static void putMapping(NetbeansActionMapping mapp, Project project, ProjectConfiguration config) throws IOException { - M2Configuration cfg = (M2Configuration) config; - ActionToGoalMapping mapping; - try { - mapping = new NetbeansBuildActionXpp3Reader().read(new StringReader(cfg.getRawMappingsAsString())); - } catch (XmlPullParserException x) { - throw new IOException(x); + ModelHandle2.putMapping(mapp, project, config); } - NetbeansActionMapping existing = null; - for (NetbeansActionMapping m : mapping.getActions()) { - if (m.getActionName().equals(mapp.getActionName())) { - existing = m; - break; - } - } - if (existing != null) { - mapping.getActions().set(mapping.getActions().indexOf(existing), mapp); - } else { - mapping.addAction(mapp); - } - CustomizerProviderImpl.writeNbActionsModel(project, mapping, M2Configuration.getFileNameExt(cfg.getId())); - } public List getConfigurations() { return configurations; @@ -350,78 +312,6 @@ * a javabean wrapper for configurations within the project customizer * */ - public static class Configuration { - private String id; - private boolean profileBased = false; - private boolean defaul = false; - - private List activatedProfiles; - private boolean shared = false; - - Configuration() {} - - public String getFileNameExt() { - return M2Configuration.getFileNameExt(id); + public static class Configuration extends ModelHandle2.Configuration { } - - public boolean isDefault() { - return defaul; } - - public void setDefault(boolean def) { - this.defaul = def; - } - - public List getActivatedProfiles() { - return activatedProfiles; - } - - public void setActivatedProfiles(List activatedProfiles) { - this.activatedProfiles = activatedProfiles; - } - - public String getDisplayName() { - if (isDefault()) { - return NbBundle.getMessage(ModelHandle.class, "DefaultConfig"); - } - if (isProfileBased()) { - return NbBundle.getMessage(ModelHandle.class, "ProfileConfig", id); - } - if (getActivatedProfiles() != null && getActivatedProfiles().size() > 0) { - return NbBundle.getMessage(ModelHandle.class, "CustomConfig1", id, Arrays.toString(getActivatedProfiles().toArray())); - } - return NbBundle.getMessage(ModelHandle.class, "CustomConfig2", id); - } - - public String getId() { - return id; - } - - public void setShared(boolean shared) { - this.shared = shared; - } - - public boolean isShared() { - return shared; - } - - void setId(String id) { - this.id = id; - } - - public boolean isProfileBased() { - return profileBased; - } - - void setProfileBased(boolean profileBased) { - this.profileBased = profileBased; - } - - @Override - public String toString() { - return getDisplayName(); - } - - - } -} --- maven/src/org/netbeans/modules/maven/api/customizer/ModelHandle2.java +++ maven/src/org/netbeans/modules/maven/api/customizer/ModelHandle2.java @@ -0,0 +1,463 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.api.customizer; + +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.netbeans.api.annotations.common.CheckForNull; +import org.netbeans.api.project.Project; +import org.netbeans.modules.maven.MavenProjectPropsImpl; +import org.netbeans.modules.maven.configurations.M2Configuration; +import org.netbeans.modules.maven.customizer.CustomizerProviderImpl; +import org.netbeans.modules.maven.execute.ActionToGoalUtils; +import org.netbeans.modules.maven.execute.model.ActionToGoalMapping; +import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; +import org.netbeans.modules.maven.execute.model.io.xpp3.NetbeansBuildActionXpp3Reader; +import org.netbeans.modules.maven.model.ModelOperation; +import org.netbeans.modules.maven.model.pom.POMModel; +import org.netbeans.spi.project.ProjectConfiguration; +import org.openide.util.NbBundle; + +/** + * + * @author mkleint + */ +public class ModelHandle2 { + + public static final String PANEL_RUN = ModelHandle.PANEL_RUN; + public static final String PANEL_BASIC = ModelHandle.PANEL_BASIC; + public static final String PANEL_CONFIGURATION = ModelHandle.PANEL_CONFIGURATION; + public static final String PANEL_MAPPING = ModelHandle.PANEL_MAPPING; + public static final String PANEL_LIBRARIES = ModelHandle.PANEL_LIBRARIES; + public static final String PANEL_SOURCES = ModelHandle.PANEL_SOURCES; + public static final String PANEL_COMPILE = ModelHandle.PANEL_COMPILE; + + + private final MavenProjectPropsImpl auxiliaryProps; + private final MavenProject project; + private final POMModel model; + private final List> pomOperations = new ArrayList>(); + private final Map mappings; + private List configurations; + private boolean modConfig = false; + private Configuration active; + TreeMap transPropsShared = new TreeMap(); + TreeMap transPropsPrivate = new TreeMap(); + Set modifiedMappings = new HashSet(); + + + static { + ModelHandle2.AccessorImpl impl = new ModelHandle2.AccessorImpl(); + impl.assign(); + } + + static class AccessorImpl extends CustomizerProviderImpl.ModelAccessor2 { + + public @Override ModelHandle2 createHandle( + POMModel model, + MavenProject proj, + Map mapp, + List configs, + Configuration active, + MavenProjectPropsImpl auxProps) { + return new ModelHandle2(model, proj, mapp, configs, active, auxProps); + } + + public void assign() { + if (CustomizerProviderImpl.ACCESSOR2 == null) { + CustomizerProviderImpl.ACCESSOR2 = this; + } + } + + @Override + public TreeMap getModifiedAuxProps(ModelHandle2 handle, boolean shared) { + return handle.getModifiedAuxProps(shared); + } + + @Override + public boolean isConfigurationModified(ModelHandle2 handle) { + return handle.modConfig; + } + + @Override + public boolean isModified(ModelHandle2 handle, ActionToGoalMapping mapp) { + return handle.modifiedMappings.contains(mapp); + } + + + } + + private ModelHandle2(POMModel model, MavenProject proj, Map mapp, List configs, Configuration active, MavenProjectPropsImpl auxProps) { + project = proj; + this.mappings = mapp; + configurations = configs; + this.active = active; + auxiliaryProps = auxProps; + this.model = model; + + } + + /** + * pom.xml model, READ-ONLY + * @return + */ + public POMModel getPOMModel() { + return model; + } + + /** + * the non changed (not-to-be-changed) instance of the complete project. + * NOT TO BE CHANGED. + * @return + */ + public MavenProject getProject() { + return project; + } + + + /** + * get the value of Auxiliary property defined in the project, + * however take only the content in nb-configurations.xml file into account, never + * consider values from pom.xml here. + * @param propertyName + * @param shared + * @return + */ + public String getRawAuxiliaryProperty(String propertyName, boolean shared) { + if (shared && transPropsShared.containsKey(propertyName)) { + return transPropsShared.get(propertyName); + } + if (!shared && transPropsPrivate.containsKey(propertyName)) { + return transPropsPrivate.get(propertyName); + } + return auxiliaryProps.get(propertyName, shared, false); + } + + /** + * set the value of Auxiliary property, will be written to nb-configurations.xml file + * @param propertyName + * @param shared + * @param value + */ + public void setRawAuxiliaryProperty(String propertyName, String value, boolean shared) { + if (shared) { + transPropsShared.put(propertyName, value); + } else { + transPropsPrivate.put(propertyName, value); + } + } + + private TreeMap getModifiedAuxProps(boolean shared) { + if (shared) return transPropsShared; + else return transPropsPrivate; + } + + + /** + * action mapping model + * @return + */ + public ActionToGoalMapping getActionMappings() { + return mappings.get(M2Configuration.DEFAULT); + } + + /** + * action mapping model + * @param config + * @return + */ + public ActionToGoalMapping getActionMappings(Configuration config) { + ActionToGoalMapping mapp = mappings.get(config.getId()); + if (mapp == null) { + mapp = new ActionToGoalMapping(); + markAsModified(mapp); + mappings.put(config.getId(), mapp); + } + return mapp; + } + + /** + * always after modifying the models, mark them as modified. + * without the marking, the particular file will not be saved. + */ + + public void markAsModified(ActionToGoalMapping mapp) { + modifiedMappings.add(mapp); + } + + /** + * always after modifying the models, mark them as modified. + * without the marking, the particular file will not be saved. + */ + public void markConfigurationsAsModified() { + modConfig = true; + } + + + public List getConfigurations() { + return configurations; + } + + public void addConfiguration(Configuration config) { + assert config != null; + configurations.add(config); + modConfig = true; + } + + public void removeConfiguration(Configuration config) { + assert config != null; + configurations.remove(config); + if (active == config) { + active = configurations.size() > 0 ? configurations.get(0) : null; + } + modConfig = true; + } + + public Configuration getActiveConfiguration() { + return active; + } + public void setActiveConfiguration(Configuration conf) { + assert conf != null; + assert configurations.contains(conf); + active = conf; + } + + + public void addPOMModification(ModelOperation operation) { + if (!pomOperations.contains(operation)) { + pomOperations.add(operation); + } + } + + public void removePOMModification(ModelOperation operation) { + pomOperations.remove(operation); + } + + public List> getPOMOperations() { + return new ArrayList>(pomOperations); + } + + public static Configuration createProfileConfiguration(String id) { + return ModelHandle.createProfileConfiguration(id); + } + + public static Configuration createDefaultConfiguration() { + return ModelHandle.createDefaultConfiguration(); + } + + public static Configuration createCustomConfiguration(String id) { + return ModelHandle.createCustomConfiguration(id); + } + + /** + * inserts the action definition in the right place based on matching action name. + * replaces old defintion or appends at the end. + * + * @param action + * @param mapp + */ + public static void setUserActionMapping(NetbeansActionMapping action, ActionToGoalMapping mapp) { + action.setPackagings(null); + List lst = mapp.getActions() != null ? mapp.getActions() : new ArrayList(); + Iterator it = lst.iterator(); + while (it.hasNext()) { + NetbeansActionMapping act = it.next(); + if (act.getActionName().equals(action.getActionName())) { + int index = lst.indexOf(act); + it.remove(); + lst.add(index, action); + return; + } + + } + //if not found, add to the end. + lst.add(action); + } + + /** + * @since 2.19 + */ + public static @CheckForNull NetbeansActionMapping getDefaultMapping(String action, Project project) { + return ActionToGoalUtils.getDefaultMapping(action, project); + } + + /** + * Load a particular action mapping. + * @param action an action name + * @param project a Maven project + * @param config a configuration of that project + * @return an action mapping model, or null + * @since 2.19 + */ + public static @CheckForNull NetbeansActionMapping getMapping(String action, Project project, ProjectConfiguration config) { + return ActionToGoalUtils.getActiveMapping(action, project, (M2Configuration) config); + } + + /** + * Store a particular action mapping. + * @param mapp an action mapping model + * @param project a Maven project + * @param config a configuration of that project + * @throws IOException in case of trouble + * @since 2.19 + */ + public static void putMapping(NetbeansActionMapping mapp, Project project, ProjectConfiguration config) throws IOException { + M2Configuration cfg = (M2Configuration) config; + ActionToGoalMapping mapping; + try { + mapping = new NetbeansBuildActionXpp3Reader().read(new StringReader(cfg.getRawMappingsAsString())); + } catch (XmlPullParserException x) { + throw new IOException(x); + } + NetbeansActionMapping existing = null; + for (NetbeansActionMapping m : mapping.getActions()) { + if (m.getActionName().equals(mapp.getActionName())) { + existing = m; + break; + } + } + if (existing != null) { + mapping.getActions().set(mapping.getActions().indexOf(existing), mapp); + } else { + mapping.addAction(mapp); + } + CustomizerProviderImpl.writeNbActionsModel(project, mapping, M2Configuration.getFileNameExt(cfg.getId())); + } + + + public static interface CustomizerOperation { + + void perform(T model); + + } + +/** + * a javabean wrapper for configurations within the project customizer + * + */ + public static class Configuration { + private String id; + private boolean profileBased = false; + private boolean defaul = false; + + private List activatedProfiles; + private boolean shared = false; + + Configuration() {} + + public String getFileNameExt() { + return M2Configuration.getFileNameExt(id); + } + + public boolean isDefault() { + return defaul; + } + + public void setDefault(boolean def) { + this.defaul = def; + } + + public List getActivatedProfiles() { + return activatedProfiles; + } + + public void setActivatedProfiles(List activatedProfiles) { + this.activatedProfiles = activatedProfiles; + } + + public String getDisplayName() { + if (isDefault()) { + return NbBundle.getMessage(ModelHandle.class, "DefaultConfig"); + } + if (isProfileBased()) { + return NbBundle.getMessage(ModelHandle.class, "ProfileConfig", id); + } + if (getActivatedProfiles() != null && getActivatedProfiles().size() > 0) { + return NbBundle.getMessage(ModelHandle.class, "CustomConfig1", id, Arrays.toString(getActivatedProfiles().toArray())); + } + return NbBundle.getMessage(ModelHandle.class, "CustomConfig2", id); + } + + public String getId() { + return id; + } + + public void setShared(boolean shared) { + this.shared = shared; + } + + public boolean isShared() { + return shared; + } + + void setId(String id) { + this.id = id; + } + + public boolean isProfileBased() { + return profileBased; + } + + void setProfileBased(boolean profileBased) { + this.profileBased = profileBased; + } + + @Override + public String toString() { + return getDisplayName(); + } + + + } + + +} --- maven/src/org/netbeans/modules/maven/api/customizer/support/ReflectionTextComponentUpdater.java +++ maven/src/org/netbeans/modules/maven/api/customizer/support/ReflectionTextComponentUpdater.java @@ -47,34 +47,60 @@ import javax.swing.JLabel; import javax.swing.text.JTextComponent; import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; +import org.netbeans.modules.maven.model.ModelOperation; import org.netbeans.modules.maven.model.pom.POMComponent; +import org.netbeans.modules.maven.model.pom.POMModel; /** * * @author mkleint */ -public class ReflectionTextComponentUpdater extends TextComponentUpdater { - private Object model; - private Object defaults; - private Method modelgetter; +public final class ReflectionTextComponentUpdater extends TextComponentUpdater { + private final Object model; + private final Object defaults; + private final Method modelgetter; private Method defgetter; private Method modelsetter; private ModelHandle handle; + private ModelHandle2 handle2; + private String initialValue2; + private Operation operation; /** Creates a new instance of ReflectionTextComponentUpdater */ public ReflectionTextComponentUpdater(String getter, String setter, Object model, Object defaults, JTextComponent field, JLabel label, ModelHandle handle) throws NoSuchMethodException { + this(getter, setter, model, defaults, field, label); + this.handle = handle; + + } + + public ReflectionTextComponentUpdater(String getter, Object model, Object defaults, JTextComponent field, JLabel label, ModelHandle2 handle, Operation operation) + throws NoSuchMethodException { + this(getter, null, model, defaults, field, label); + assert handle != null; + assert operation != null; + this.handle2 = handle; + initialValue2 = getValue(); + this.operation = operation; + } + + + private ReflectionTextComponentUpdater(String getter, String setter, Object model, Object defaults, JTextComponent field, JLabel label) + throws NoSuchMethodException { super(field, label); this.model = model; this.defaults = defaults; modelgetter = model.getClass().getMethod(getter, new Class[0]); + if (setter != null) { modelsetter = model.getClass().getMethod(setter, new Class[] {String.class}); + } if (defaults != null) { defgetter = defaults.getClass().getMethod(getter, new Class[0]); } - this.handle = handle; - } + + @Override public String getValue() { try { return (String)modelgetter.invoke(model, new Object[0]); @@ -88,6 +114,7 @@ return null; } + @Override public String getDefaultValue() { if (defgetter == null) { return null; @@ -104,14 +131,26 @@ return null; } + @Override public void setValue(String value) { try { + if (handle != null) { modelsetter.invoke(model, new Object[] { value }); if (model instanceof POMComponent) { handle.markAsModified(((POMComponent)model).getModel()); } else { handle.markAsModified(model); } + } + if (handle2 != null) { + if (value == null || value.equals(initialValue2)) { + handle2.removePOMModification(operation); + } else { + operation.setNewValue(value); + //TODO ideally only add if not added before.. + handle2.addPOMModification(operation); + } + } } catch (IllegalArgumentException ex) { ex.printStackTrace(); } catch (InvocationTargetException ex) { @@ -121,4 +160,21 @@ } } + + public static abstract class Operation implements ModelOperation { + + + private String newValue; + + public final void setNewValue(String value) { + newValue = value; } + + public final String getNewValue() { + return newValue; + } + + + } + +} --- maven/src/org/netbeans/modules/maven/configurations/ConfigurationsPanel.form +++ maven/src/org/netbeans/modules/maven/configurations/ConfigurationsPanel.form @@ -1,4 +1,4 @@ - +
--- maven/src/org/netbeans/modules/maven/configurations/ConfigurationsPanel.java +++ maven/src/org/netbeans/modules/maven/configurations/ConfigurationsPanel.java @@ -52,7 +52,7 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import org.netbeans.modules.maven.NbMavenProjectImpl; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.util.NbBundle; @@ -64,14 +64,14 @@ @SuppressWarnings("serial") public class ConfigurationsPanel extends javax.swing.JPanel { private NbMavenProjectImpl project; - private ModelHandle handle; - List lastNonProfileList = new ArrayList(); + private ModelHandle2 handle; + List lastNonProfileList = new ArrayList(); /** Creates new form ConfigurationsPanel */ private ConfigurationsPanel() { initComponents(); } - ConfigurationsPanel(ModelHandle handle, NbMavenProjectImpl project) { + ConfigurationsPanel(ModelHandle2 handle, NbMavenProjectImpl project) { this(); this.handle = handle; this.project = project; @@ -87,7 +87,7 @@ @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component supers = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - ModelHandle.Configuration conf = (ModelHandle.Configuration)value; + ModelHandle2.Configuration conf = (ModelHandle2.Configuration)value; if (conf == ConfigurationsPanel.this.handle.getActiveConfiguration()) { supers.setFont(supers.getFont().deriveFont(Font.BOLD)); } @@ -96,6 +96,7 @@ }); lstConfigurations.addListSelectionListener(new ListSelectionListener() { + @Override public void valueChanged(ListSelectionEvent e) { checkButtonEnablement(); } @@ -105,7 +106,7 @@ } private void checkButtonEnablement() { - ModelHandle.Configuration conf = (ModelHandle.Configuration) lstConfigurations.getSelectedValue(); + ModelHandle2.Configuration conf = (ModelHandle2.Configuration) lstConfigurations.getSelectedValue(); if (conf == null || conf.isProfileBased() || conf.isDefault()) { btnEdit.setEnabled(false); btnRemove.setEnabled(false); @@ -119,7 +120,7 @@ // boolean isProfile = false; DefaultListModel model = new DefaultListModel(); if (handle.getConfigurations() != null) { - for (ModelHandle.Configuration hndl : handle.getConfigurations()) { + for (ModelHandle2.Configuration hndl : handle.getConfigurations()) { model.addElement(hndl); // if (hndl.isProfileBased()) { // isProfile = true; @@ -240,18 +241,18 @@ pnl.attachDescriptor(dd); Object ret = DialogDisplayer.getDefault().notify(dd); if (ret == DialogDescriptor.OK_OPTION) { - ModelHandle.Configuration conf = ModelHandle.createCustomConfiguration(pnl.getConfigurationId()); + ModelHandle2.Configuration conf = ModelHandle2.createCustomConfiguration(pnl.getConfigurationId()); conf.setShared(pnl.isShared()); conf.setActivatedProfiles(pnl.getProfiles()); handle.addConfiguration(conf); - handle.markAsModified(handle.getConfigurations()); + handle.markConfigurationsAsModified(); createListModel(); lstConfigurations.setSelectedValue(conf, true); } }//GEN-LAST:event_btnAddActionPerformed private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed - ModelHandle.Configuration conf = (ModelHandle.Configuration) lstConfigurations.getSelectedValue(); + ModelHandle2.Configuration conf = (ModelHandle2.Configuration) lstConfigurations.getSelectedValue(); if (conf != null) { NewConfigurationPanel pnl = new NewConfigurationPanel(); pnl.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ConfigurationsPanel.class, "ACSD_Edit_Config")); @@ -263,7 +264,7 @@ if (ret == DialogDescriptor.OK_OPTION) { conf.setShared(pnl.isShared()); conf.setActivatedProfiles(pnl.getProfiles()); - handle.markAsModified(handle.getConfigurations()); + handle.markConfigurationsAsModified(); createListModel(); lstConfigurations.setSelectedValue(conf, true); } @@ -271,7 +272,7 @@ }//GEN-LAST:event_btnEditActionPerformed private void btnRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveActionPerformed - ModelHandle.Configuration conf = (ModelHandle.Configuration) lstConfigurations.getSelectedValue(); + ModelHandle2.Configuration conf = (ModelHandle2.Configuration) lstConfigurations.getSelectedValue(); if (conf != null) { handle.removeConfiguration(conf); createListModel(); @@ -279,7 +280,7 @@ }//GEN-LAST:event_btnRemoveActionPerformed private void btnActivateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActivateActionPerformed - ModelHandle.Configuration conf = (ModelHandle.Configuration) lstConfigurations.getSelectedValue(); + ModelHandle2.Configuration conf = (ModelHandle2.Configuration) lstConfigurations.getSelectedValue(); if (conf != null) { handle.setActiveConfiguration(conf); } --- maven/src/org/netbeans/modules/maven/configurations/ConfigurationsPanelProvider.java +++ maven/src/org/netbeans/modules/maven/configurations/ConfigurationsPanelProvider.java @@ -44,7 +44,7 @@ import javax.swing.JComponent; import org.netbeans.modules.maven.NbMavenProjectImpl; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.openide.util.Lookup; import org.openide.util.NbBundle; @@ -56,15 +56,17 @@ @ProjectCustomizer.CompositeCategoryProvider.Registration(projectType="org-netbeans-modules-maven", position=212) public class ConfigurationsPanelProvider implements ProjectCustomizer.CompositeCategoryProvider { + @Override public ProjectCustomizer.Category createCategory(Lookup context) { return ProjectCustomizer.Category.create( - ModelHandle.PANEL_CONFIGURATION, + ModelHandle2.PANEL_CONFIGURATION, NbBundle.getMessage(ConfigurationsPanelProvider.class, "TIT_Configurations"), null); } + @Override public JComponent createComponent(ProjectCustomizer.Category category, Lookup context) { - ModelHandle handle = context.lookup(ModelHandle.class); + ModelHandle2 handle = context.lookup(ModelHandle2.class); NbMavenProjectImpl project = context.lookup(NbMavenProjectImpl.class); return new ConfigurationsPanel(handle, project); } --- maven/src/org/netbeans/modules/maven/configurations/M2ConfigProvider.java +++ maven/src/org/netbeans/modules/maven/configurations/M2ConfigProvider.java @@ -42,7 +42,6 @@ package org.netbeans.modules.maven.configurations; -import org.codehaus.plexus.util.StringUtils; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -55,10 +54,11 @@ import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; +import org.codehaus.plexus.util.StringUtils; import org.netbeans.modules.maven.NbMavenProjectImpl; import org.netbeans.modules.maven.api.NbMavenProject; import org.netbeans.modules.maven.api.ProjectProfileHandler; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.customizer.CustomizerProviderImpl; import org.netbeans.spi.project.ActionProvider; import org.netbeans.spi.project.AuxiliaryConfiguration; @@ -232,7 +232,7 @@ public @Override void customize() { CustomizerProviderImpl prv = project.getLookup().lookup(CustomizerProviderImpl.class); - prv.showCustomizer(ModelHandle.PANEL_CONFIGURATION); + prv.showCustomizer(ModelHandle2.PANEL_CONFIGURATION); } public @Override boolean configurationsAffectAction(String action) { --- maven/src/org/netbeans/modules/maven/customizer/ActionMappings.java +++ maven/src/org/netbeans/modules/maven/customizer/ActionMappings.java @@ -42,10 +42,7 @@ package org.netbeans.modules.maven.customizer; -import org.codehaus.plexus.util.StringUtils; -import javax.swing.text.BadLocationException; import java.awt.Component; -import javax.swing.JList; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -69,6 +66,7 @@ import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JLabel; +import javax.swing.JList; import javax.swing.JMenu; import javax.swing.JPopupMenu; import javax.swing.JTextArea; @@ -78,22 +76,24 @@ import javax.swing.UIManager; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import javax.swing.text.BadLocationException; +import org.codehaus.plexus.util.StringUtils; import org.netbeans.api.annotations.common.NullAllowed; -import org.netbeans.modules.maven.spi.grammar.GoalsProvider; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.ActionProviderImpl; import org.netbeans.modules.maven.NbMavenProjectImpl; +import org.netbeans.modules.maven.TestChecker; import org.netbeans.modules.maven.TextValueCompleter; import org.netbeans.modules.maven.api.Constants; +import org.netbeans.modules.maven.api.NbMavenProject; import org.netbeans.modules.maven.api.ProjectProfileHandler; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.embedder.EmbedderFactory; import org.netbeans.modules.maven.execute.ActionToGoalUtils; -import org.netbeans.modules.maven.ActionProviderImpl; -import org.netbeans.modules.maven.TestChecker; -import org.netbeans.modules.maven.api.NbMavenProject; import org.netbeans.modules.maven.execute.DefaultReplaceTokenProvider; import org.netbeans.modules.maven.execute.model.ActionToGoalMapping; import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; import org.netbeans.modules.maven.options.DontShowAgainSettings; +import org.netbeans.modules.maven.spi.grammar.GoalsProvider; import org.netbeans.spi.project.ActionProvider; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; @@ -112,7 +112,7 @@ private static final RequestProcessor RP = new RequestProcessor(ActionMappings.class); private NbMavenProjectImpl project; - private ModelHandle handle; + private ModelHandle2 handle; private HashMap titles = new HashMap(); private final GoalsListener goalsListener; @@ -175,7 +175,7 @@ } /** Creates new form ActionMappings */ - public ActionMappings(ModelHandle hand, NbMavenProjectImpl proj) { + public ActionMappings(ModelHandle2 hand, NbMavenProjectImpl proj) { this(); project = proj; handle = hand; @@ -729,7 +729,7 @@ private ActionToGoalMapping getActionMappings() { assert handle != null || actionmappings != null; if (handle != null) { - return handle.getActionMappings((ModelHandle.Configuration) comConfiguration.getSelectedItem()); + return handle.getActionMappings((ModelHandle2.Configuration) comConfiguration.getSelectedItem()); } return actionmappings; } @@ -964,7 +964,7 @@ lblConfiguration.setVisible(true); comConfiguration.setVisible(true); DefaultComboBoxModel comModel = new DefaultComboBoxModel(); - for (ModelHandle.Configuration conf : handle.getConfigurations()) { + for (ModelHandle2.Configuration conf : handle.getConfigurations()) { comModel.addElement(conf); } comConfiguration.setModel(comModel); --- maven/src/org/netbeans/modules/maven/customizer/ActionMappingsPanelProvider.java +++ maven/src/org/netbeans/modules/maven/customizer/ActionMappingsPanelProvider.java @@ -41,9 +41,9 @@ */ package org.netbeans.modules.maven.customizer; -import org.netbeans.modules.maven.api.customizer.ModelHandle; import javax.swing.JComponent; import org.netbeans.modules.maven.NbMavenProjectImpl; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; import org.openide.util.Lookup; @@ -56,15 +56,17 @@ @ProjectCustomizer.CompositeCategoryProvider.Registration(projectType="org-netbeans-modules-maven", position=400) public class ActionMappingsPanelProvider implements ProjectCustomizer.CompositeCategoryProvider { + @Override public Category createCategory(Lookup context) { return ProjectCustomizer.Category.create( - ModelHandle.PANEL_MAPPING, + ModelHandle2.PANEL_MAPPING, NbBundle.getMessage(ActionMappingsPanelProvider.class, "TIT_Action_Mappings"), null); } + @Override public JComponent createComponent(Category category, Lookup context) { - ModelHandle handle = context.lookup(ModelHandle.class); + ModelHandle2 handle = context.lookup(ModelHandle2.class); NbMavenProjectImpl project = context.lookup(NbMavenProjectImpl.class); return new ActionMappings(handle, project); } --- maven/src/org/netbeans/modules/maven/customizer/BasicInfoPanel.java +++ maven/src/org/netbeans/modules/maven/customizer/BasicInfoPanel.java @@ -43,15 +43,16 @@ package org.netbeans.modules.maven.customizer; import java.io.CharConversionException; -import javax.swing.event.DocumentEvent; -import org.netbeans.modules.maven.api.customizer.support.TextComponentUpdater; -import org.netbeans.modules.maven.api.customizer.support.ReflectionTextComponentUpdater; -import org.netbeans.modules.maven.api.customizer.ModelHandle; import java.util.ArrayList; import java.util.List; import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.apache.maven.project.MavenProject; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; +import org.netbeans.modules.maven.api.customizer.support.ReflectionTextComponentUpdater; +import org.netbeans.modules.maven.api.customizer.support.TextComponentUpdater; +import org.netbeans.modules.maven.model.pom.POMModel; import org.netbeans.modules.maven.model.pom.Project; import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; import org.openide.util.NbBundle; @@ -62,12 +63,12 @@ * @author mkleint */ public class BasicInfoPanel extends javax.swing.JPanel implements DocumentListener { - private final ModelHandle handle; + private final ModelHandle2 handle; private List listeners; private final Category category; /** Creates new form BasicInfoPanel */ - public BasicInfoPanel(ModelHandle handle, Category category) { + public BasicInfoPanel(ModelHandle2 handle, Category category) { initComponents(); this.handle = handle; this.category = category; @@ -79,12 +80,42 @@ MavenProject project = handle.getProject().getParent(); listeners = new ArrayList(); try { - listeners.add(new ReflectionTextComponentUpdater("getGroupId", "setGroupId", mdl, project, txtGroupId, lblGroupId, handle)); //NOI18N - listeners.add(new ReflectionTextComponentUpdater("getArtifactId", "setArtifactId", mdl, project, txtArtifactId, lblArtifactId, handle)); //NOI18N - listeners.add(new ReflectionTextComponentUpdater("getVersion", "setVersion", mdl, project, txtVersion, lblVersion, handle)); //NOI18N - listeners.add(new ReflectionTextComponentUpdater("getName", "setName", mdl, project, txtName, lblName, handle)); //NOI18N - listeners.add(new ReflectionTextComponentUpdater("getPackaging", "setPackaging", mdl, project, txtPackaging, lblPackaging, handle)); //NOI18N - listeners.add(new ReflectionTextComponentUpdater("getDescription", "setDescription", mdl, project, taDescription, lblDescription, handle)); //NOI18N + listeners.add(new ReflectionTextComponentUpdater("getGroupId", mdl, project, txtGroupId, lblGroupId, handle, new ReflectionTextComponentUpdater.Operation() { + @Override + public void performOperation(POMModel model) { + model.getProject().setGroupId(getNewValue()); + } + })); //NOI18N + listeners.add(new ReflectionTextComponentUpdater("getArtifactId", mdl, project, txtArtifactId, lblArtifactId, handle, new ReflectionTextComponentUpdater.Operation() { + @Override + public void performOperation(POMModel model) { + model.getProject().setArtifactId(getNewValue()); + } + })); //NOI18N + listeners.add(new ReflectionTextComponentUpdater("getVersion", mdl, project, txtVersion, lblVersion, handle, new ReflectionTextComponentUpdater.Operation() { + @Override + public void performOperation(POMModel model) { + model.getProject().setVersion(getNewValue()); + } + })); //NOI18N + listeners.add(new ReflectionTextComponentUpdater("getName", mdl, project, txtName, lblName, handle, new ReflectionTextComponentUpdater.Operation() { + @Override + public void performOperation(POMModel model) { + model.getProject().setName(getNewValue()); + } + })); //NOI18N + listeners.add(new ReflectionTextComponentUpdater("getPackaging", mdl, project, txtPackaging, lblPackaging, handle, new ReflectionTextComponentUpdater.Operation() { + @Override + public void performOperation(POMModel model) { + model.getProject().setPackaging(getNewValue()); + } + })); //NOI18N + listeners.add(new ReflectionTextComponentUpdater("getDescription", mdl, project, taDescription, lblDescription, handle, new ReflectionTextComponentUpdater.Operation() { + @Override + public void performOperation(POMModel model) { + model.getProject().setDescription(getNewValue()); + } + })); //NOI18N } catch (NoSuchMethodException ex) { ex.printStackTrace(); } @@ -206,14 +237,17 @@ private javax.swing.JTextField txtVersion; // End of variables declaration//GEN-END:variables + @Override public void insertUpdate(DocumentEvent arg0) { checkCoords(); } + @Override public void removeUpdate(DocumentEvent arg0) { checkCoords(); } + @Override public void changedUpdate(DocumentEvent arg0) { checkCoords(); } --- maven/src/org/netbeans/modules/maven/customizer/BasicPanelProvider.java +++ maven/src/org/netbeans/modules/maven/customizer/BasicPanelProvider.java @@ -41,8 +41,8 @@ */ package org.netbeans.modules.maven.customizer; -import org.netbeans.modules.maven.api.customizer.ModelHandle; import javax.swing.JComponent; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; import org.openide.util.Lookup; @@ -55,15 +55,17 @@ @ProjectCustomizer.CompositeCategoryProvider.Registration(projectType="org-netbeans-modules-maven", position=100) public class BasicPanelProvider implements ProjectCustomizer.CompositeCategoryProvider { + @Override public Category createCategory(Lookup context) { return ProjectCustomizer.Category.create( - ModelHandle.PANEL_BASIC, + ModelHandle2.PANEL_BASIC, NbBundle.getMessage(BasicPanelProvider.class, "TIT_Basic"), null); } + @Override public JComponent createComponent(Category category, Lookup context) { - ModelHandle handle = context.lookup(ModelHandle.class); + ModelHandle2 handle = context.lookup(ModelHandle2.class); return new BasicInfoPanel(handle, category); } --- maven/src/org/netbeans/modules/maven/customizer/Bundle.properties +++ maven/src/org/netbeans/modules/maven/customizer/Bundle.properties @@ -112,7 +112,6 @@ LBL_AddAction=Enter action name LBL_Actions=Ac&tions: ActionMappings.lblConfiguration.text=Confi&guration: -TIT_Project_Properties=Project Properties - {0} ActionMappings.btnAddProps.text=A&dd > ActionMappings.debugMaven=Debug Maven build ActionMappings.envVar=New Environment Variable @@ -173,5 +172,4 @@ TIT_PLUGIN_EXPRESSION=Add Plugin Expression Property HINT_ApplicationCoS=Classes compiled with the Compile on Save feature in the IDE are not identical to classes compiled with JDK's javac.
When building your binaries for redistribution, please make sure to always perform a clean build.. -ERR_MissingPOM=Project's pom.xml file contains invalid xml content. Please fix the file before proceeding. RunJarPanel.lblConfiguration.text=&Configuration: --- maven/src/org/netbeans/modules/maven/customizer/CompilePanel.java +++ maven/src/org/netbeans/modules/maven/customizer/CompilePanel.java @@ -46,6 +46,8 @@ import java.awt.Component; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.util.HashMap; +import java.util.Map; import javax.swing.AbstractListModel; import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; @@ -59,10 +61,12 @@ import org.netbeans.api.project.Project; import org.netbeans.modules.maven.api.Constants; import org.netbeans.modules.maven.api.PluginPropertyUtils; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; +import org.netbeans.modules.maven.api.customizer.ModelHandle2.CustomizerOperation; import org.netbeans.modules.maven.api.customizer.support.CheckBoxUpdater; import org.netbeans.modules.maven.api.customizer.support.ComboBoxUpdater; import org.netbeans.modules.maven.classpath.BootClassPathImpl; +import org.netbeans.modules.maven.model.ModelOperation; import org.netbeans.modules.maven.model.pom.Build; import org.netbeans.modules.maven.model.pom.Configuration; import org.netbeans.modules.maven.model.pom.POMModel; @@ -102,17 +106,14 @@ private static final int COS_TESTS = 2; private static final int COS_NONE = 3; - private ComboBoxUpdater listener; - private final ModelHandle handle; + private final ModelHandle2 handle; private final Project project; - private CheckBoxUpdater debugUpdater; - private CheckBoxUpdater deprecateUpdater; private static boolean warningShown = false; private Color origComPlatformFore; /** Creates new form CompilePanel */ - public CompilePanel(ModelHandle handle, Project prj) { + public CompilePanel(ModelHandle2 handle, Project prj) { initComponents(); this.handle = handle; project = prj; @@ -145,18 +146,36 @@ } private void initValues() { - listener = new ComboBoxUpdater(comCompileOnSave, lblCompileOnSave) { + new ComboBoxUpdater(comCompileOnSave, lblCompileOnSave) { + private String modifiedValue; + private ModelOperation operation = new ModelOperation() { + + @Override + public void performOperation(POMModel model) { + Properties modprops = model.getProject().getProperties(); + if (modprops == null) { + modprops = model.getFactory().createProperties(); + model.getProject().setProperties(modprops); + } + modprops.setProperty(Constants.HINT_COMPILE_ON_SAVE, modifiedValue); //NOI18N + } + }; + + @Override public String getDefaultValue() { return LABELS[COS_TESTS]; } + @Override public String getValue() { - String val = null; + String val = modifiedValue; + if (val == null) { Properties props = handle.getPOMModel().getProject().getProperties(); if (props != null) { val = props.getProperty(Constants.HINT_COMPILE_ON_SAVE); } + } if (val == null) { val = handle.getRawAuxiliaryProperty(Constants.HINT_COMPILE_ON_SAVE, true); } @@ -166,7 +185,10 @@ return LABELS[COS_TESTS]; } + @Override public void setValue(String label) { + handle.removePOMModification(operation); + modifiedValue = null; String value = labelToValue(label); if (value != null && value.equals(VALUES[COS_TESTS])) { //just reset the value, no need to persist default. @@ -187,23 +209,19 @@ boolean hasConfig = handle.getRawAuxiliaryProperty(Constants.HINT_COMPILE_ON_SAVE, true) != null; if (handle.getProject().getProperties().containsKey(Constants.HINT_COMPILE_ON_SAVE)) { - Properties modprops = handle.getPOMModel().getProject().getProperties(); - if (modprops == null) { - modprops = handle.getPOMModel().getFactory().createProperties(); - handle.getPOMModel().getProject().setProperties(modprops); - } - modprops.setProperty(Constants.HINT_COMPILE_ON_SAVE, value == null ? null : value); //NOI18N - handle.markAsModified(handle.getPOMModel()); + modifiedValue = value; + handle.addPOMModification(operation); if (hasConfig) { // in this case clean up the auxiliary config handle.setRawAuxiliaryProperty(Constants.HINT_COMPILE_ON_SAVE, null, true); } - return; + } else { + handle.setRawAuxiliaryProperty(Constants.HINT_COMPILE_ON_SAVE, value, true); } - handle.setRawAuxiliaryProperty(Constants.HINT_COMPILE_ON_SAVE, value == null ? null : value, true); } }; - debugUpdater = new CheckBoxUpdater(cbDebug) { + new CheckBoxUpdater(cbDebug) { + @Override public Boolean getValue() { String val = getCompilerParam(handle,PARAM_DEBUG); if (val != null) { @@ -212,24 +230,27 @@ return null; } + @Override public void setValue(Boolean value) { String text; if (value == null) { //TODO we should attempt to remove the configuration // from pom if this parameter is the only one defined. - text = "true";//NOI18N + text = "" + getDefaultValue(); } else { text = value.toString(); } - checkCompilerParam(handle, PARAM_DEBUG, text); + modifyCompilerParamOperation(handle, PARAM_DEBUG, text); } + @Override public boolean getDefaultValue() { return true; } }; - deprecateUpdater = new CheckBoxUpdater(cbDeprecate) { + new CheckBoxUpdater(cbDeprecate) { + @Override public Boolean getValue() { String val = getCompilerParam(handle,PARAM_DEPRECATION); if (val != null) { @@ -238,18 +259,20 @@ return null; } + @Override public void setValue(Boolean value) { String text; if (value == null) { //TODO we should attempt to remove the configuration // from pom if this parameter is the only one defined. - text = "false";//NOI18N + text = "" + getDefaultValue(); } else { text = value.toString(); } - checkCompilerParam(handle, PARAM_DEPRECATION, text); + modifyCompilerParamOperation(handle, PARAM_DEPRECATION, text); } + @Override public boolean getDefaultValue() { return false; } @@ -257,14 +280,30 @@ // java platform updater new ComboBoxUpdater(comJavaPlatform, lblJavaPlatform) { + private String modifiedValue; + private ModelOperation operation = new ModelOperation() { + @Override + public void performOperation(POMModel model) { + Properties modprops = model.getProject().getProperties(); + if (modprops == null) { + modprops = model.getFactory().createProperties(); + model.getProject().setProperties(modprops); + } + modprops.setProperty(Constants.HINT_JDK_PLATFORM, modifiedValue); //NOI18N + } + }; + + @Override public JavaPlatform getValue() { - String val = null; + String val = modifiedValue; + if (val == null) { Properties props = handle.getPOMModel().getProject().getProperties(); if (props != null) { val = props.getProperty(Constants.HINT_JDK_PLATFORM); } + } if (val == null) { val = handle.getRawAuxiliaryProperty(Constants.HINT_JDK_PLATFORM, true); } @@ -282,6 +321,8 @@ @Override public void setValue(JavaPlatform value) { + handle.removePOMModification(operation); + modifiedValue = null; JavaPlatform platf = value == null ? JavaPlatformManager.getDefault().getDefaultPlatform() : value; String platformId = platf.getProperties().get("platform.ant.name"); //NOI18N if (JavaPlatformManager.getDefault().getDefaultPlatform().equals(platf)) { @@ -292,21 +333,16 @@ //TODO also try to take the value in pom vs inherited pom value into account. if (handle.getProject().getProperties().containsKey(Constants.HINT_JDK_PLATFORM)) { - Properties modprops = handle.getPOMModel().getProject().getProperties(); - if (modprops == null) { - modprops = handle.getPOMModel().getFactory().createProperties(); - handle.getPOMModel().getProject().setProperties(modprops); - } - modprops.setProperty(Constants.HINT_JDK_PLATFORM, platformId); //NOI18N - handle.markAsModified(handle.getPOMModel()); + modifiedValue = platformId; + handle.addPOMModification(operation); if (hasConfig) { // in this case clean up the auxiliary config handle.setRawAuxiliaryProperty(Constants.HINT_JDK_PLATFORM, null, true); } - return; - } + } else { handle.setRawAuxiliaryProperty(Constants.HINT_JDK_PLATFORM, platformId, true); } + } }; } @@ -425,20 +461,49 @@ private static final String CONFIGURATION_EL = "configuration";//NOI18N + private final Map operations = new HashMap(); + /** * update the debug param of project to given value. * * @param handle handle which models are to be updated * @param sourceLevel the sourcelevel to set */ - public static void checkCompilerParam(ModelHandle handle, String param, String value) { + private void modifyCompilerParamOperation(ModelHandle2 handle, String param, String value) { String debug = PluginPropertyUtils.getPluginProperty(handle.getProject(), Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, param, "compile"); //NOI18N if (debug != null && debug.contains(value)) { + ModelOperation removed = operations.remove(param); + if (removed != null) { + handle.removePOMModification(removed); + } return; } - POMModel model = handle.getPOMModel(); + ModelOperation removed = operations.remove(param); + if (removed != null) { + handle.removePOMModification(removed); + } + CompilerParamOperation added = new CompilerParamOperation(param, value); + operations.put(param, added); + handle.addPOMModification(added); + } + + private class CompilerParamOperation implements ModelOperation { + private final String value; + private final String param; + + public CompilerParamOperation(String param, String value) { + this.param = param; + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public void performOperation(POMModel model) { Plugin old = null; Plugin plugin; Build bld = model.getProject().getBuild(); @@ -463,23 +528,15 @@ plugin.setConfiguration(config); } config.setSimpleParameter(param, value); - handle.markAsModified(handle.getPOMModel()); } - public static String getCompilerParam(ModelHandle handle, String param) { - Build bld = handle.getPOMModel().getProject().getBuild(); - if (bld != null) { - Plugin plugin = bld.findPluginById(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER); - if (plugin != null) { - Configuration config = plugin.getConfiguration(); - if (config != null) { - String val = config.getSimpleParameter(param); - if (val != null) { - return val; } + + String getCompilerParam(ModelHandle2 handle, String param) { + CompilerParamOperation oper = operations.get(param); + if (oper != null) { + return oper.getValue(); } - } - } String value = PluginPropertyUtils.getPluginProperty(handle.getProject(), Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, param, @@ -502,23 +559,28 @@ sel = jpm.getDefaultPlatform(); } + @Override public int getSize() { return data.length; } + @Override public Object getElementAt(int index) { return data[index]; } + @Override public void setSelectedItem(Object anItem) { sel = anItem; fireContentsChanged(this, 0, data.length); } + @Override public Object getSelectedItem() { return sel; } + @Override public void propertyChange(PropertyChangeEvent evt) { JavaPlatformManager jpm = JavaPlatformManager.getDefault(); data = jpm.getInstalledPlatforms(); @@ -533,6 +595,7 @@ setOpaque(true); } + @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { --- maven/src/org/netbeans/modules/maven/customizer/CompilePanelProvider.java +++ maven/src/org/netbeans/modules/maven/customizer/CompilePanelProvider.java @@ -41,9 +41,9 @@ */ package org.netbeans.modules.maven.customizer; -import org.netbeans.modules.maven.api.customizer.ModelHandle; import javax.swing.JComponent; import org.netbeans.api.project.Project; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; import org.openide.util.Lookup; @@ -55,18 +55,19 @@ @ProjectCustomizer.CompositeCategoryProvider.Registration(projectType="org-netbeans-modules-maven", category="Build", position=100) public class CompilePanelProvider implements ProjectCustomizer.CompositeCategoryProvider { + @Override public Category createCategory(Lookup context) { return ProjectCustomizer.Category.create( - ModelHandle.PANEL_COMPILE, + ModelHandle2.PANEL_COMPILE, org.openide.util.NbBundle.getMessage(CompilePanelProvider.class, "TIT_Compile"), null); } + @Override public JComponent createComponent(Category category, Lookup context) { - ModelHandle handle = context.lookup(ModelHandle.class); + ModelHandle2 handle = context.lookup(ModelHandle2.class); Project prj = context.lookup(Project.class); - final CompilePanel panel = new CompilePanel(handle, prj); - return panel; + return new CompilePanel(handle, prj); } } --- maven/src/org/netbeans/modules/maven/customizer/CustomizerProviderImpl.java +++ maven/src/org/netbeans/modules/maven/customizer/CustomizerProviderImpl.java @@ -45,14 +45,13 @@ import java.awt.Dialog; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.io.*; import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractAction; @@ -73,6 +72,7 @@ import org.netbeans.modules.maven.NbMavenProjectImpl; import org.netbeans.modules.maven.api.NbMavenProject; import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.api.problem.ProblemReport; import org.netbeans.modules.maven.configurations.M2ConfigProvider; import org.netbeans.modules.maven.configurations.M2Configuration; @@ -86,6 +86,7 @@ import org.netbeans.modules.maven.problems.ProblemReporterImpl; import org.netbeans.modules.xml.xam.Model.State; import org.netbeans.modules.xml.xam.ModelSource; +import org.netbeans.spi.project.AuxiliaryConfiguration; import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.ui.CustomizerProvider; import org.netbeans.spi.project.ui.support.ProjectCustomizer; @@ -103,10 +104,12 @@ import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.lookup.Lookups; +import static org.netbeans.modules.maven.customizer.Bundle.*; +import org.openide.util.NbBundle.Messages; /** * maven implementation of CustomizerProvider, handles the general workflow, - *for panel creation depegates to M2CustomizerPanelProvider instances. + *for panel creation delegates to M2CustomizerPanelProvider instances. * @author Milos Kleint */ @ProjectServiceProvider(service={CustomizerProvider.class, CustomizerProviderImpl.class}, projectType="org-netbeans-modules-maven") @@ -114,6 +117,7 @@ private final Project project; private ModelHandle handle; + private ModelHandle2 handle2; private static final String BROKEN_NBACTIONS = "BROKENNBACTIONS"; //NOI18N @@ -131,34 +135,34 @@ showCustomizer( preselectedCategory, null ); } + @Messages({ + "TIT_Project_Properties=Project Properties - {0}", + "ERR_MissingPOM=Project's pom.xml file contains invalid xml content. Please fix the file before proceeding."}) public void showCustomizer( String preselectedCategory, String preselectedSubCategory ) { try { - init(); + POMModel mdl = init(); //#171958 start - try { - handle.getPOMModel().sync(); - } catch (IOException ex) { - Logger.getLogger(CustomizerProviderImpl.class.getName()).log(Level.INFO, "Error while syncing the editor document with model for pom.xml file", ex); //NOI18N - } - if (!handle.getPOMModel().getState().equals(State.VALID)) { - NotifyDescriptor nd = new NotifyDescriptor.Message(NbBundle.getMessage(CustomizerProviderImpl.class, "ERR_MissingPOM"), NotifyDescriptor.ERROR_MESSAGE); + if (!mdl.getState().equals(State.VALID)) { + NotifyDescriptor nd = new NotifyDescriptor.Message(ERR_MissingPOM(), NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notify(nd); return; } //#171958 end - handle.getPOMModel().startTransaction(); - project.getLookup().lookup(MavenProjectPropsImpl.class).startTransaction(); +// handle.getPOMModel().startTransaction(); +// project.getLookup().lookup(MavenProjectPropsImpl.class).startTransaction(); OptionListener listener = new OptionListener(); - Lookup context = Lookups.fixed(new Object[] { project, handle}); + Lookup context = Lookups.fixed(new Object[] { project, handle, handle2}); Dialog dialog = ProjectCustomizer.createCustomizerDialog("Projects/org-netbeans-modules-maven/Customizer", //NOI18N context, - preselectedCategory, listener, listener, new HelpCtx("maven_settings")); - dialog.addWindowListener( listener ); - listener.setDialog(dialog); - dialog.setTitle( MessageFormat.format( - org.openide.util.NbBundle.getMessage(CustomizerProviderImpl.class, "TIT_Project_Properties"), - new Object[] { ProjectUtils.getInformation(project).getDisplayName() } ) ); + preselectedCategory, + new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + //noop + } + }, listener, new HelpCtx("maven_settings")); + dialog.setTitle( TIT_Project_Properties(ProjectUtils.getInformation(project).getDisplayName())); dialog.setModal(true); dialog.setVisible(true); } catch (FileNotFoundException ex) { @@ -174,13 +178,14 @@ } } - private void init() throws XmlPullParserException, IOException { + private POMModel init() throws XmlPullParserException, IOException { FileObject pom = FileUtil.toFileObject(project.getLookup().lookup(NbMavenProjectImpl.class).getPOMFile()); if (pom == null || !pom.isValid()) { throw new FileNotFoundException("No pom file exists."); //NOI18N } ModelSource source = Utilities.createModelSource(pom); - POMModel model = POMModelFactory.getDefault().getModel(source); + POMModel model = POMModelFactory.getDefault().createFreshModel(source); + Map mapps = new HashMap(); NetbeansBuildActionXpp3Reader reader = new NetbeansBuildActionXpp3Reader(); List configs = new ArrayList(); @@ -230,9 +235,14 @@ handle = ACCESSOR.createHandle(model, project.getLookup().lookup(NbMavenProject.class).getMavenProject(), mapps, configs, active, project.getLookup().lookup(MavenProjectPropsImpl.class)); + handle2 = ACCESSOR2.createHandle(model, + project.getLookup().lookup(NbMavenProject.class).getMavenProject(), mapps, new ArrayList(configs), active, + project.getLookup().lookup(MavenProjectPropsImpl.class)); + return model; } public static ModelAccessor ACCESSOR = null; + public static ModelAccessor2 ACCESSOR2 = null; static { // invokes static initializer of ModelHandle.class @@ -243,7 +253,13 @@ } catch (Exception ex) { ex.printStackTrace(); } + c = ModelHandle2.class; + try { + Class.forName(c.getName(), true, c.getClassLoader()); + } catch (Exception ex) { + ex.printStackTrace(); } + } public static abstract class ModelAccessor { @@ -252,96 +268,59 @@ List configs, ModelHandle.Configuration active, MavenProjectPropsImpl auxProps); } - /** Listens to the actions on the Customizer's option buttons */ - private class OptionListener extends WindowAdapter implements ActionListener { - private Dialog dialog; - private boolean weAreSaving = false; - OptionListener() { + public static abstract class ModelAccessor2 { + + public abstract ModelHandle2 createHandle(POMModel model, MavenProject proj, Map mapp, + List configs, ModelHandle2.Configuration active, MavenProjectPropsImpl auxProps); + + public abstract TreeMap getModifiedAuxProps(ModelHandle2 handle, boolean shared); + + public abstract boolean isConfigurationModified(ModelHandle2 handle); + + public abstract boolean isModified(ModelHandle2 handle, ActionToGoalMapping mapp); + } - void setDialog(Dialog dlg) { - dialog = dlg; + /** Listens to the actions on the Customizer's option buttons + ONLY STORE listener now. + */ + private class OptionListener implements ActionListener { + + OptionListener() { } + // Listening to OK button ---------------------------------------------- @Override public void actionPerformed( ActionEvent e ) { - if (SwingUtilities.isEventDispatchThread()) { // OK option listener - if ( dialog != null ) { - dialog.setVisible(false); - dialog.dispose(); - dialog = null; - weAreSaving = true; + final FileObject pom = FileUtil.toFileObject(project.getLookup().lookup(NbMavenProjectImpl.class).getPOMFile()); + if (pom == null || !pom.isValid()) { + return; //TODO } - } else { // store listener - //we need to finish transactions in the same thread we initiated them, doh.. - // but #189854: this cannot be while holding project mutex - // and #192051: must happen before the other stuff - SwingUtilities.invokeLater(new Runnable() { - public @Override void run() { - if (handle.getPOMModel().isIntransaction()) { - if (handle.isModified(handle.getPOMModel())) { - handle.getPOMModel().endTransaction(); - } else { - handle.getPOMModel().rollbackTransaction(); - } - } + try { - project.getProjectDirectory().getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { - @Override - public void run() throws IOException { - project.getLookup().lookup(MavenProjectPropsImpl.class).commitTransaction(); - writeAll(handle, project.getLookup().lookup(NbMavenProjectImpl.class)); - } - }); + writeAll(handle2, project.getLookup().lookup(NbMavenProjectImpl.class)); } catch (IOException ex) { Exceptions.printStackTrace(ex); //TODO error reporting on wrong model save } } - }); } - } - // Listening to window events ------------------------------------------ - - @Override - public void windowClosed( WindowEvent e) { - if (!weAreSaving) { - //TODO where to put elsewhere? - project.getLookup().lookup(MavenProjectPropsImpl.class).cancelTransaction(); - if (handle.getPOMModel().isIntransaction()) { - handle.getPOMModel().rollbackTransaction(); - } - assert !handle.getPOMModel().isIntransaction(); - } - } - - @Override - public void windowClosing(WindowEvent e) { - if ( dialog != null ) { - dialog.setVisible(false); - dialog.dispose(); - dialog = null; - } - } - - } - static interface SubCategoryProvider { public void showSubCategory(String name); } - public static void writeAll(ModelHandle handle, NbMavenProjectImpl project) throws IOException { + static void writeAll(ModelHandle2 handle, NbMavenProjectImpl project) throws IOException { //save configs before pom, to save reloads in case both pom and configs were changed. boolean performConfigsInvokedReload = false; M2ConfigProvider prv = project.getLookup().lookup(M2ConfigProvider.class); - if (handle.isModified(handle.getConfigurations())) { + if (ACCESSOR2.isConfigurationModified(handle)) { List shared = new ArrayList(); List nonshared = new ArrayList(); - for (ModelHandle.Configuration mdlConf : handle.getConfigurations()) { + for (ModelHandle2.Configuration mdlConf : handle.getConfigurations()) { if (!mdlConf.isDefault() && !mdlConf.isProfileBased()) { M2Configuration c = new M2Configuration(mdlConf.getId(), project); c.setActivatedProfiles(mdlConf.getActivatedProfiles()); @@ -355,9 +334,18 @@ prv.setConfigurations(shared, nonshared, true); performConfigsInvokedReload = true; } + final FileObject pom = FileUtil.toFileObject(project.getLookup().lookup(NbMavenProjectImpl.class).getPOMFile()); + Utilities.performPOMModelOperations(pom, handle.getPOMOperations()); - Utilities.saveChanges(handle.getPOMModel()); - if (handle.isModified(handle.getActionMappings())) { + AuxiliaryConfiguration aux = project.getLookup().lookup(AuxiliaryConfiguration.class); + if (!ACCESSOR2.getModifiedAuxProps(handle, true).isEmpty()) { + MavenProjectPropsImpl.writeAuxiliaryData(aux, ACCESSOR2.getModifiedAuxProps(handle, true), true); + } + if (!ACCESSOR2.getModifiedAuxProps(handle, false).isEmpty()) { + MavenProjectPropsImpl.writeAuxiliaryData(aux, ACCESSOR2.getModifiedAuxProps(handle, false), false); + } + + if (ACCESSOR2.isModified(handle, handle.getActionMappings())) { writeNbActionsModel(project, handle.getActionMappings(), M2Configuration.getFileNameExt(M2Configuration.DEFAULT)); } @@ -369,12 +357,12 @@ } } //save action mappings for configurations.. - for (ModelHandle.Configuration c : handle.getConfigurations()) { - if (handle.isModified(handle.getActionMappings(c))) { + for (ModelHandle2.Configuration c : handle.getConfigurations()) { + if (ACCESSOR2.isModified(handle,handle.getActionMappings(c))) { writeNbActionsModel(project, handle.getActionMappings(c), M2Configuration.getFileNameExt(c.getId())); } } - if (performConfigsInvokedReload) { + if (performConfigsInvokedReload && handle.getPOMOperations().isEmpty()) { //#only do the reload if no change to po file was done. can be actually figured now with operations //#174637 NbMavenProject.fireMavenProjectReload(project); } --- maven/src/org/netbeans/modules/maven/customizer/RunJarPanel.java +++ maven/src/org/netbeans/modules/maven/customizer/RunJarPanel.java @@ -44,9 +44,6 @@ import java.awt.Component; import java.awt.Dialog; -import javax.swing.JList; -import javax.swing.event.DocumentEvent; -import org.netbeans.modules.maven.api.customizer.ModelHandle; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -61,16 +58,19 @@ import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JLabel; +import javax.swing.JList; import javax.swing.JTextField; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import org.netbeans.modules.maven.classpath.MavenSourcesImpl; -import org.netbeans.modules.maven.NbMavenProjectImpl; import org.netbeans.api.java.project.JavaProjectConstants; import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; +import org.netbeans.modules.maven.NbMavenProjectImpl; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; +import org.netbeans.modules.maven.classpath.MavenSourcesImpl; import org.netbeans.modules.maven.execute.model.ActionToGoalMapping; import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; import org.netbeans.spi.project.ActionProvider; @@ -101,7 +101,7 @@ private static final String PROFILE_CMD = "profile"; // NOI18N - private ModelHandle handle; + private ModelHandle2 handle; private NbMavenProjectImpl project; private NetbeansActionMapping run; private NetbeansActionMapping debug; @@ -114,7 +114,7 @@ private DocumentListener docListener; private ActionListener comboListener; - public RunJarPanel(ModelHandle handle, NbMavenProjectImpl project) { + public RunJarPanel(ModelHandle2 handle, NbMavenProjectImpl project) { initComponents(); this.handle = handle; this.project = project; @@ -152,19 +152,23 @@ btnMainClass.addActionListener(new MainClassListener(roots.toArray(new FileObject[roots.size()]), txtMainClass)); docListener = new DocumentListener() { + @Override public void insertUpdate(DocumentEvent arg0) { applyChanges(); } + @Override public void removeUpdate(DocumentEvent arg0) { applyChanges(); } + @Override public void changedUpdate(DocumentEvent arg0) { applyChanges(); } }; comboListener = new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { removeListeners(); initValues(); @@ -193,7 +197,7 @@ run = null; debug = null; profile = null; - ActionToGoalMapping mapp = handle.getActionMappings((ModelHandle.Configuration) comConfiguration.getSelectedItem()); + ActionToGoalMapping mapp = handle.getActionMappings((ModelHandle2.Configuration) comConfiguration.getSelectedItem()); @SuppressWarnings("unchecked") List lst = mapp.getActions(); for (NetbeansActionMapping m : lst) { @@ -208,13 +212,13 @@ } } if (run == null) { - run = ModelHandle.getDefaultMapping(ActionProvider.COMMAND_RUN, project); + run = ModelHandle2.getDefaultMapping(ActionProvider.COMMAND_RUN, project); } if (debug == null) { - debug = ModelHandle.getDefaultMapping(ActionProvider.COMMAND_DEBUG, project); + debug = ModelHandle2.getDefaultMapping(ActionProvider.COMMAND_DEBUG, project); } if (profile == null) { - profile = ModelHandle.getDefaultMapping(PROFILE_CMD, project); + profile = ModelHandle2.getDefaultMapping(PROFILE_CMD, project); } isCurrentRun = checkNewMapping(run); isCurrentDebug = checkNewMapping(debug); @@ -421,7 +425,7 @@ String newParams = txtArguments.getText().trim(); String newVMParams = txtVMOptions.getText().trim(); String newWorkDir = txtWorkDir.getText().trim(); - ActionToGoalMapping a2gm = handle.getActionMappings((ModelHandle.Configuration) comConfiguration.getSelectedItem()); + ActionToGoalMapping a2gm = handle.getActionMappings((ModelHandle2.Configuration) comConfiguration.getSelectedItem()); if (isCurrentRun || isCurrentDebug || isCurrentProfile) { String newAllParams = newVMParams + " -classpath %classpath "; //NOI18N if (newMainClass.trim().length() > 0) { @@ -442,7 +446,7 @@ changed = true; } if (changed) { - ModelHandle.setUserActionMapping(run, a2gm); + ModelHandle2.setUserActionMapping(run, a2gm); handle.markAsModified(a2gm); } } @@ -457,7 +461,7 @@ changed = true; } if (changed) { - ModelHandle.setUserActionMapping(debug, a2gm); + ModelHandle2.setUserActionMapping(debug, a2gm); handle.markAsModified(a2gm); } } @@ -473,7 +477,7 @@ } profile.addProperty(RUN_EXEC, DEFAULT_PROFILER_EXEC); if (changed) { - ModelHandle.setUserActionMapping(profile, a2gm); + ModelHandle2.setUserActionMapping(profile, a2gm); handle.markAsModified(a2gm); } } @@ -580,7 +584,7 @@ lblConfiguration.setVisible(true); comConfiguration.setVisible(true); DefaultComboBoxModel comModel = new DefaultComboBoxModel(); - for (ModelHandle.Configuration conf : handle.getConfigurations()) { + for (ModelHandle2.Configuration conf : handle.getConfigurations()) { comModel.addElement(conf); } comConfiguration.setModel(comModel); @@ -607,6 +611,7 @@ /** Handles button events */ + @Override public void actionPerformed( ActionEvent e ) { // only chooseMainClassButton can be performed @@ -617,6 +622,7 @@ DialogDescriptor.CANCEL_OPTION }; panel.addChangeListener (new ChangeListener () { + @Override public void stateChanged(ChangeEvent e) { if (e.getSource () instanceof MouseEvent && MouseUtils.isDoubleClick (((MouseEvent)e.getSource ()))) { // click button and finish the dialog with selected class --- maven/src/org/netbeans/modules/maven/customizer/RunJarPanelProvider.java +++ maven/src/org/netbeans/modules/maven/customizer/RunJarPanelProvider.java @@ -41,10 +41,10 @@ */ package org.netbeans.modules.maven.customizer; -import org.netbeans.modules.maven.api.customizer.ModelHandle; import javax.swing.JComponent; import org.netbeans.modules.maven.NbMavenProjectImpl; import org.netbeans.modules.maven.api.NbMavenProject; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; import org.openide.util.Lookup; @@ -56,21 +56,23 @@ @ProjectCustomizer.CompositeCategoryProvider.Registration(projectType="org-netbeans-modules-maven", position=300) public class RunJarPanelProvider implements ProjectCustomizer.CompositeCategoryProvider { + @Override public Category createCategory(Lookup context) { NbMavenProjectImpl project = context.lookup(NbMavenProjectImpl.class); NbMavenProject watcher = project.getLookup().lookup(NbMavenProject.class); if (NbMavenProject.TYPE_JAR.equalsIgnoreCase(watcher.getPackagingType())) { return ProjectCustomizer.Category.create( - ModelHandle.PANEL_RUN, + ModelHandle2.PANEL_RUN, org.openide.util.NbBundle.getMessage(RunJarPanelProvider.class, "TIT_Run"), null); } return null; } + @Override public JComponent createComponent(Category category, Lookup context) { - ModelHandle handle = context.lookup(ModelHandle.class); + ModelHandle2 handle = context.lookup(ModelHandle2.class); NbMavenProjectImpl project = context.lookup(NbMavenProjectImpl.class); final RunJarPanel panel = new RunJarPanel(handle, project); return panel; --- maven/src/org/netbeans/modules/maven/customizer/SourcesPanel.java +++ maven/src/org/netbeans/modules/maven/customizer/SourcesPanel.java @@ -50,12 +50,13 @@ import java.util.logging.Logger; import javax.swing.DefaultComboBoxModel; import javax.swing.JPanel; +import org.netbeans.api.java.queries.SourceLevelQuery; import org.netbeans.modules.maven.NbMavenProjectImpl; import org.netbeans.modules.maven.api.Constants; -import org.netbeans.modules.maven.api.PluginPropertyUtils; -import org.netbeans.modules.maven.api.customizer.ModelHandle; -import org.netbeans.api.java.queries.SourceLevelQuery; import org.netbeans.modules.maven.api.ModelUtils; +import org.netbeans.modules.maven.api.PluginPropertyUtils; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; +import org.netbeans.modules.maven.model.ModelOperation; import org.netbeans.modules.maven.model.pom.Build; import org.netbeans.modules.maven.model.pom.Configuration; import org.netbeans.modules.maven.model.pom.POMComponentFactory; @@ -75,12 +76,98 @@ public class SourcesPanel extends JPanel { + private String oldEncoding; private String encoding; + private final String sourceEncoding; private String defaultEncoding; private String sourceLevel; - private ModelHandle handle; + private ModelHandle2 handle; - public SourcesPanel( ModelHandle handle, NbMavenProjectImpl project ) { + private ModelOperation sourceLevelOperation = new ModelOperation() { + + @Override + public void performOperation(POMModel model) { + ModelUtils.setSourceLevel(model, sourceLevel); + } + }; + + private ModelOperation encodingOperation = new ModelOperation() { + + @Override + public void performOperation(POMModel model) { + //new approach, assume all plugins conform to the new setting. + POMComponentFactory fact = model.getFactory(); + Properties props = model.getProject().getProperties(); + if (props == null) { + props = fact.createProperties(); + model.getProject().setProperties(props); + } + props.setProperty(Constants.ENCODING_PROP, encoding); + boolean createPlugins = sourceEncoding == null; + + //check if compiler/resources plugins are configured and update them to ${project.source.encoding expression + Build bld = model.getProject().getBuild(); + if (bld == null) { + if (createPlugins) { + bld = fact.createBuild(); + model.getProject().setBuild(bld); + } else { + return; + } + } + + Plugin plugin = bld.findPluginById(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER); + Plugin plugin2 = bld.findPluginById(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_RESOURCES); + + String compilesource = PluginPropertyUtils.getPluginProperty(handle.getProject(), + Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, + Constants.ENCODING_PARAM, null); + String resourcesource = PluginPropertyUtils.getPluginProperty(handle.getProject(), + Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_RESOURCES, + Constants.ENCODING_PARAM, null); + + boolean updateCompiler = createPlugins || compilesource != null; /** configured in parent somehow */ + if (plugin == null && updateCompiler) { + plugin = fact.createPlugin(); + plugin.setGroupId(Constants.GROUP_APACHE_PLUGINS); + plugin.setArtifactId(Constants.PLUGIN_COMPILER); + plugin.setVersion(MavenVersionSettings.getDefault().getVersion(MavenVersionSettings.VERSION_COMPILER)); + bld.addPlugin(plugin); + } + if (plugin != null) { + Configuration conf = plugin.getConfiguration(); + if (conf == null && updateCompiler) { + conf = fact.createConfiguration(); + plugin.setConfiguration(conf); + } + if (conf != null && updateCompiler) { + conf.setSimpleParameter(Constants.ENCODING_PARAM, "${" + Constants.ENCODING_PROP + "}"); + } + } + + boolean updateResources = createPlugins || resourcesource != null; /** configured in parent somehow */ + if (plugin2 == null && updateResources) { + plugin2 = fact.createPlugin(); + plugin2.setGroupId(Constants.GROUP_APACHE_PLUGINS); + plugin2.setArtifactId(Constants.PLUGIN_RESOURCES); + plugin2.setVersion(MavenVersionSettings.getDefault().getVersion(MavenVersionSettings.VERSION_RESOURCES)); + bld.addPlugin(plugin2); + } + if (plugin2 != null) { + Configuration conf = plugin2.getConfiguration(); + if (conf == null && updateResources) { + conf = fact.createConfiguration(); + plugin2.setConfiguration(conf); + } + if (conf != null && updateResources) { + conf.setSimpleParameter(Constants.ENCODING_PARAM, "${" + Constants.ENCODING_PROP + "}"); + } + } + + } + }; + + public SourcesPanel( ModelHandle2 handle, NbMavenProjectImpl project ) { initComponents(); this.handle = handle; FileObject projectFolder = project.getProjectDirectory(); @@ -100,11 +187,11 @@ enc = PluginPropertyUtils.getPluginProperty(project, Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, Constants.ENCODING_PARAM, null); } - encoding = enc; + oldEncoding = enc; if (enc != null) { try { Charset chs = Charset.forName(enc); - encoding = chs.name(); + oldEncoding = chs.name(); } catch (Exception e) { Logger.getLogger(this.getClass().getName()).info("IllegalCharsetName: " + enc); //NOI18N } @@ -113,12 +200,13 @@ // for times before the http://docs.codehaus.org/display/MAVENUSER/POM+Element+for+Source+File+Encoding // proposal. this proposal defines the default value as ISO-8859-1 - if (encoding == null) { - encoding = Charset.defaultCharset().toString(); - } defaultEncoding = Charset.defaultCharset().toString(); + if (oldEncoding == null) { + oldEncoding = defaultEncoding; + } + sourceEncoding = handle.getProject().getProperties().getProperty(Constants.ENCODING_PROP); - comEncoding.setModel(ProjectCustomizer.encodingModel(encoding)); + comEncoding.setModel(ProjectCustomizer.encodingModel(oldEncoding)); comEncoding.setRenderer(ProjectCustomizer.encodingRenderer()); comSourceLevel.addActionListener(new ActionListener() { @@ -134,21 +222,20 @@ handleEncodingChange(); } }); - txtSrc.setText(project.getOriginalMavenProject().getBuild().getSourceDirectory()); - txtTestSrc.setText(project.getOriginalMavenProject().getBuild().getTestSourceDirectory()); + txtSrc.setText(handle.getProject().getBuild().getSourceDirectory()); + txtTestSrc.setText(handle.getProject().getBuild().getTestSourceDirectory()); } private void handleSourceLevelChange() { sourceLevel = (String)comSourceLevel.getSelectedItem(); + handle.removePOMModification(sourceLevelOperation); String source = PluginPropertyUtils.getPluginProperty(handle.getProject(), Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, Constants.SOURCE_PARAM, "compile"); //NOI18N if (source != null && source./*XXX not equals?*/contains(sourceLevel)) { return; } - POMModel mdl = handle.getPOMModel(); - ModelUtils.setSourceLevel(mdl, sourceLevel); - handle.markAsModified(mdl); + handle.addPOMModification(sourceLevelOperation); } @@ -159,9 +246,13 @@ if (enc != null) { encName = enc.name(); } else { - encName = encoding; + encName = oldEncoding; } - checkEncoding(handle, encName); + encoding = encName; + handle.removePOMModification(encodingOperation); + if (!encoding.equals(sourceEncoding)) { + handle.addPOMModification(encodingOperation); + } if (defaultEncoding.equals(encName)) { lblEncoding.setFont(lblEncoding.getFont().deriveFont(Font.PLAIN)); } else { // XXX use ComboBoxUpdater for the standard technique @@ -169,83 +260,6 @@ } } - private static void checkEncoding(ModelHandle handle, String enc) { - String source = handle.getProject().getProperties().getProperty(Constants.ENCODING_PROP); - if (enc.equals(source)) { - return; - } - //new approach, assume all plugins conform to the new setting. - POMModel model = handle.getPOMModel(); - handle.markAsModified(model); - POMComponentFactory fact = model.getFactory(); - Properties props = model.getProject().getProperties(); - if (props == null) { - props = fact.createProperties(); - model.getProject().setProperties(props); - } - props.setProperty(Constants.ENCODING_PROP, enc); - boolean createPlugins = source == null; - - //check if compiler/resources plugins are configured and update them to ${project.source.encoding expression - Build bld = model.getProject().getBuild(); - if (bld == null) { - if (createPlugins) { - bld = fact.createBuild(); - model.getProject().setBuild(bld); - } else { - return; - } - } - - Plugin plugin = bld.findPluginById(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER); - Plugin plugin2 = bld.findPluginById(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_RESOURCES); - - String compilesource = PluginPropertyUtils.getPluginProperty(handle.getProject(), - Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, - Constants.ENCODING_PARAM, null); - String resourcesource = PluginPropertyUtils.getPluginProperty(handle.getProject(), - Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_RESOURCES, - Constants.ENCODING_PARAM, null); - - boolean updateCompiler = createPlugins || compilesource != null; /** configured in parent somehow */ - if (plugin == null && updateCompiler) { - plugin = fact.createPlugin(); - plugin.setGroupId(Constants.GROUP_APACHE_PLUGINS); - plugin.setArtifactId(Constants.PLUGIN_COMPILER); - plugin.setVersion(MavenVersionSettings.getDefault().getVersion(MavenVersionSettings.VERSION_COMPILER)); - bld.addPlugin(plugin); - } - if (plugin != null) { - Configuration conf = plugin.getConfiguration(); - if (conf == null && updateCompiler) { - conf = fact.createConfiguration(); - plugin.setConfiguration(conf); - } - if (conf != null && updateCompiler) { - conf.setSimpleParameter(Constants.ENCODING_PARAM, "${" + Constants.ENCODING_PROP + "}"); - } - } - - boolean updateResources = createPlugins || resourcesource != null; /** configured in parent somehow */ - if (plugin2 == null && updateResources) { - plugin2 = fact.createPlugin(); - plugin2.setGroupId(Constants.GROUP_APACHE_PLUGINS); - plugin2.setArtifactId(Constants.PLUGIN_RESOURCES); - plugin2.setVersion(MavenVersionSettings.getDefault().getVersion(MavenVersionSettings.VERSION_RESOURCES)); - bld.addPlugin(plugin2); - } - if (plugin2 != null) { - Configuration conf = plugin2.getConfiguration(); - if (conf == null && updateResources) { - conf = fact.createConfiguration(); - plugin2.setConfiguration(conf); - } - if (conf != null && updateResources) { - conf.setSimpleParameter(Constants.ENCODING_PARAM, "${" + Constants.ENCODING_PROP + "}"); - } - } - } - /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is --- maven/src/org/netbeans/modules/maven/customizer/SourcesPanelProvider.java +++ maven/src/org/netbeans/modules/maven/customizer/SourcesPanelProvider.java @@ -43,10 +43,10 @@ package org.netbeans.modules.maven.customizer; import java.util.Collections; -import org.netbeans.modules.maven.api.customizer.ModelHandle; import javax.swing.JComponent; import org.netbeans.modules.editor.indent.project.api.Customizers; import org.netbeans.modules.maven.NbMavenProjectImpl; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; import org.openide.util.Lookup; @@ -60,15 +60,17 @@ @ProjectCustomizer.CompositeCategoryProvider.Registration(projectType="org-netbeans-modules-maven", position=200) public class SourcesPanelProvider implements ProjectCustomizer.CompositeCategoryProvider { + @Override public Category createCategory(Lookup context) { return ProjectCustomizer.Category.create( - ModelHandle.PANEL_SOURCES, + ModelHandle2.PANEL_SOURCES, NbBundle.getMessage(SourcesPanelProvider.class, "TIT_Sources"), null); } + @Override public JComponent createComponent(Category category, Lookup context) { - ModelHandle handle = context.lookup(ModelHandle.class); + ModelHandle2 handle = context.lookup(ModelHandle2.class); NbMavenProjectImpl project = context.lookup(NbMavenProjectImpl.class); return new SourcesPanel(handle, project); } --- maven/src/org/netbeans/modules/maven/queries/RepositoryMavenCPProvider.java +++ maven/src/org/netbeans/modules/maven/queries/RepositoryMavenCPProvider.java @@ -0,0 +1,213 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.queries; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.MavenArtifactRepository; +import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.model.building.ModelBuildingRequest; +import org.apache.maven.project.DefaultProjectBuildingRequest; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.project.ProjectBuildingResult; +import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.java.platform.JavaPlatformManager; +import org.netbeans.modules.maven.embedder.EmbedderFactory; +import org.netbeans.modules.maven.embedder.MavenEmbedder; +import org.netbeans.modules.maven.indexer.api.RepositoryInfo; +import org.netbeans.modules.maven.indexer.api.RepositoryPreferences; +import org.netbeans.spi.java.classpath.ClassPathFactory; +import org.netbeans.spi.java.classpath.ClassPathImplementation; +import org.netbeans.spi.java.classpath.ClassPathProvider; +import org.netbeans.spi.java.classpath.PathResourceImplementation; +import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author mkleint + */ +@ServiceProvider (service=ClassPathProvider.class, position=11) +public class RepositoryMavenCPProvider implements ClassPathProvider { + private static final Logger LOG = Logger.getLogger(RepositoryMavenCPProvider.class.getName()); + + @Override + public ClassPath findClassPath(FileObject file, String type) { + FileObject archive = FileUtil.getArchiveFile(file); + if (archive != null && archive.getNameExt().endsWith("-sources.jar")) { //first simple check + File sourceFile = FileUtil.toFile(archive); + if (sourceFile != null) { +// String name = jarFile.getName(); + File parent = sourceFile.getParentFile(); + if (parent != null) { + File parentParent = parent.getParentFile(); + if (parentParent != null) { + // each repository artifact should have this structure + String artifact = parentParent.getName(); + String version = parent.getName(); + //TODO is there a need for generified extension lookup or is just .jar files ok? + //TODO can the .jar extension be hardwired? on CP.. + File bin = new File(parent, artifact + "-" + version + ".jar"); //NOI18N + File pom = new File(parent, artifact + "-" + version + ".pom"); //NOI18N + + FileObject localRepoRoot = FileUtil.toFileObject(new File(EmbedderFactory.getProjectEmbedder().getLocalRepository().getBasedir())); + if (FileUtil.isParentOf(localRepoRoot, archive)) { + String groupId = FileUtil.getRelativePath(localRepoRoot, FileUtil.toFileObject(parentParent.getParentFile())); + if (groupId != null && !groupId.equals("")) { + groupId = groupId.replace("/", "."); + if (ClassPath.SOURCE.equals(type)) { + return ClassPathFactory.createClassPath(createSourceCPI(sourceFile)); + } + if (ClassPath.BOOT.equals(type)) { + return ClassPathFactory.createClassPath(createBootCPI()); + } + if (ClassPath.COMPILE.equals(type)) { + MavenProject mp = loadMavenProject(pom, groupId, artifact, version); + return ClassPathFactory.createClassPath(createCompileCPI(mp, bin)); + } + if (ClassPath.EXECUTE.equals(type)) { + MavenProject mp = loadMavenProject(pom, groupId, artifact, version); + return ClassPathFactory.createClassPath(createExecuteCPI(mp, bin)); + } + } else { + //some sort of weird groupId? + } + } + + } + } + } + + + } + return null; + } + + private MavenProject loadMavenProject(File pom, String groupId, String artifactId, String version) { + MavenEmbedder embedder = EmbedderFactory.getOnlineEmbedder(); + Artifact projectArtifact = embedder.createArtifact(groupId, artifactId, version, "jar"); + try { + DefaultProjectBuildingRequest dpbr = new DefaultProjectBuildingRequest(); + dpbr.setLocalRepository(embedder.getLocalRepository()); + dpbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); + dpbr.setSystemProperties(embedder.getSystemProperties()); + + dpbr.setProcessPlugins(false); + dpbr.setResolveDependencies(true); + ArrayList remoteRepos = new ArrayList(); + for (RepositoryInfo info : RepositoryPreferences.getInstance().getRepositoryInfos()) { + if (!info.isLocal()) { + remoteRepos.add(new MavenArtifactRepository(info.getId(), info.getRepositoryUrl(), new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy())); + } + } + dpbr.setRemoteRepositories(remoteRepos); + + ProjectBuildingResult res = embedder.buildProject(projectArtifact, dpbr); + if (res.getProject() != null) { + return res.getProject(); + } else { + LOG.log(Level.INFO, "No project model from repository for {0}: {1}", new Object[] {projectArtifact, res.getProblems()}); + } + } catch (ProjectBuildingException ex) { + LOG.log(Level.FINER, "Failed to load project model from repository for {0}: {1}", new Object[] {projectArtifact, ex}); + } catch (Exception exception) { + LOG.log(Level.FINER, "Failed to load project model from repository for " + projectArtifact, exception); + } + return null; + } + + + + private ClassPathImplementation createCompileCPI(MavenProject project, File binary) { + List items = new ArrayList(); + if (binary.exists()) { + items.add(ClassPathSupport.createResource(FileUtil.urlForArchiveOrDir(binary))); + } + if (project != null) { + for (Artifact s : project.getCompileArtifacts()) { + if (s.getFile() == null) continue; + File f = FileUtil.normalizeFile(s.getFile()); + items.add(ClassPathSupport.createResource(FileUtil.urlForArchiveOrDir(f))); + } + } + return ClassPathSupport.createClassPathImplementation(items); + } + + private ClassPathImplementation createExecuteCPI(MavenProject project, File binary) { + List items = new ArrayList(); + if (binary.exists()) { + items.add(ClassPathSupport.createResource(FileUtil.urlForArchiveOrDir(binary))); + } + if (project != null) { + for (Artifact s : project.getRuntimeArtifacts()) { + if (s.getFile() == null) continue; + File f = FileUtil.normalizeFile(s.getFile()); + items.add(ClassPathSupport.createResource(FileUtil.urlForArchiveOrDir(f))); + } + } + return ClassPathSupport.createClassPathImplementation(items); + } + + private ClassPathImplementation createSourceCPI(File sourceFile) { + return ClassPathSupport.createClassPathImplementation(Collections.singletonList(ClassPathSupport.createResource(FileUtil.urlForArchiveOrDir(sourceFile)))); + } + + private ClassPathImplementation createBootCPI() { + List result = new ArrayList (); + for (ClassPath.Entry entry : JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries().entries()) { + result.add(ClassPathSupport.createResource(entry.getURL())); + } + return ClassPathSupport.createClassPathImplementation(result); + } + + +} --- maven/src/org/netbeans/modules/maven/runjar/RunJarPrereqChecker.java +++ maven/src/org/netbeans/modules/maven/runjar/RunJarPrereqChecker.java @@ -56,7 +56,7 @@ import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; import org.netbeans.modules.maven.api.NbMavenProject; -import org.netbeans.modules.maven.api.customizer.ModelHandle; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.api.execute.ActiveJ2SEPlatformProvider; import org.netbeans.modules.maven.api.execute.PrerequisitesChecker; import org.netbeans.modules.maven.api.execute.RunConfig; @@ -184,9 +184,9 @@ static void writeMapping(String actionName, Project project, String clazz) { try { M2ConfigProvider usr = project.getLookup().lookup(M2ConfigProvider.class); - NetbeansActionMapping mapp = ModelHandle.getMapping(actionName, project, usr.getDefaultConfig()); + NetbeansActionMapping mapp = ModelHandle2.getMapping(actionName, project, usr.getDefaultConfig()); if (mapp == null) { - mapp = ModelHandle.getDefaultMapping(actionName, project); + mapp = ModelHandle2.getDefaultMapping(actionName, project); } // XXX should this rather run on _all_ actions that reference ${packageClassName}? for (Map.Entry e : mapp.getProperties().entrySet()) { @@ -197,7 +197,7 @@ } } //TODO we should definitely write to the mappings of active configuration here.. - ModelHandle.putMapping(mapp, project, usr.getDefaultConfig()); + ModelHandle2.putMapping(mapp, project, usr.getDefaultConfig()); } catch (Exception e) { Exceptions.attachMessage(e, "Cannot persist action configuration."); Exceptions.printStackTrace(e); --- projectuiapi/src/org/netbeans/modules/project/uiapi/CustomizerDialog.java +++ projectuiapi/src/org/netbeans/modules/project/uiapi/CustomizerDialog.java @@ -73,6 +73,7 @@ import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; +import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; import org.openide.util.HelpCtx; import org.openide.util.Lookup; @@ -291,10 +292,15 @@ // Call storeListeners out of AWT EQ RequestProcessor.getDefault().post(new Runnable() { + @Override public void run() { try { ProjectManager.mutex().writeAccess(new Mutex.Action() { + @Override public Object run() { + FileUtil.runAtomicAction(new Runnable() { + @Override + public void run() { handle.start(); if (storeListener != null) { storeListener.actionPerformed(e); @@ -302,11 +308,14 @@ storePerformed(e, categories); // #97998 related saveModifiedProject(); + } + }); return null; } }); } finally { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { dialog.setVisible(false); dialog.dispose();