This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 207463
Collapse All | Expand All

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

Return to bug 207463