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 229192
Collapse All | Expand All

(-)a/maven/src/org/netbeans/modules/maven/configurations/M2Configuration.java (-5 / +108 lines)
Lines 45-63 Link Here
45
import java.io.FileNotFoundException;
45
import java.io.FileNotFoundException;
46
import java.io.IOException;
46
import java.io.IOException;
47
import java.io.InputStream;
47
import java.io.InputStream;
48
import java.io.InputStreamReader;
48
import java.io.Reader;
49
import java.io.Reader;
50
import java.io.StringWriter;
49
import java.util.ArrayList;
51
import java.util.ArrayList;
50
import java.util.Collections;
52
import java.util.Collections;
51
import java.util.HashMap;
53
import java.util.HashMap;
52
import java.util.List;
54
import java.util.List;
53
import java.util.Map;
55
import java.util.Map;
54
import java.util.concurrent.atomic.AtomicBoolean;
56
import java.util.concurrent.atomic.AtomicBoolean;
57
import java.util.logging.Level;
58
import java.util.logging.Logger;
55
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
59
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
56
import org.netbeans.api.annotations.common.NonNull;
60
import org.netbeans.api.annotations.common.NonNull;
61
import org.netbeans.api.project.Project;
57
import org.netbeans.modules.maven.api.MavenConfiguration;
62
import org.netbeans.modules.maven.api.MavenConfiguration;
58
import static org.netbeans.modules.maven.configurations.Bundle.*;
63
import static org.netbeans.modules.maven.configurations.Bundle.*;
59
import org.netbeans.modules.maven.execute.model.ActionToGoalMapping;
64
import org.netbeans.modules.maven.execute.model.ActionToGoalMapping;
60
import org.netbeans.modules.maven.execute.model.NetbeansActionMapping;
65
import org.netbeans.modules.maven.execute.model.NetbeansActionMapping;
66
import org.netbeans.modules.maven.execute.model.NetbeansActionProfile;
67
import org.netbeans.modules.maven.execute.model.NetbeansActionReader;
68
import org.netbeans.modules.maven.execute.model.io.xpp3.NetbeansBuildActionXpp3Writer;
61
import org.netbeans.modules.maven.spi.actions.AbstractMavenActionsProvider;
69
import org.netbeans.modules.maven.spi.actions.AbstractMavenActionsProvider;
62
import org.openide.filesystems.FileChangeAdapter;
70
import org.openide.filesystems.FileChangeAdapter;
63
import org.openide.filesystems.FileChangeListener;
71
import org.openide.filesystems.FileChangeListener;
Lines 65-70 Link Here
65
import org.openide.filesystems.FileObject;
73
import org.openide.filesystems.FileObject;
66
import org.openide.filesystems.FileRenameEvent;
74
import org.openide.filesystems.FileRenameEvent;
67
import org.openide.filesystems.FileUtil;
75
import org.openide.filesystems.FileUtil;
76
import org.openide.util.Exceptions;
68
import org.openide.util.NbBundle.Messages;
77
import org.openide.util.NbBundle.Messages;
69
78
70
/**
79
/**
Lines 72-77 Link Here
72
 * @author mkleint
81
 * @author mkleint
73
 */
82
 */
74
public class M2Configuration extends AbstractMavenActionsProvider implements MavenConfiguration, Comparable<M2Configuration> {
83
public class M2Configuration extends AbstractMavenActionsProvider implements MavenConfiguration, Comparable<M2Configuration> {
84
    private static final Logger LOG = Logger.getLogger(M2Configuration.class.getName());
75
85
76
    public static final String DEFAULT = "%%DEFAULT%%"; //NOI18N
86
    public static final String DEFAULT = "%%DEFAULT%%"; //NOI18N
77
    
87
    
Lines 157-171 Link Here
157
    }
167
    }
158
168
159
    public @Override InputStream getActionDefinitionStream() {
169
    public @Override InputStream getActionDefinitionStream() {
160
170
        return getActionDefinitionStream(id);
171
    }
172
    final InputStream getActionDefinitionStream(String forId) {
161
        checkListener();
173
        checkListener();
162
        FileObject fo = projectDirectory.getFileObject(getFileNameExt(id));
174
        FileObject fo = projectDirectory.getFileObject(getFileNameExt(forId));
163
        resetCache.set(false);
175
        resetCache.set(false);
164
        if (fo != null) {
176
        if (fo != null) {
165
            try {
177
            try {
166
                return fo.getInputStream();
178
                return fo.getInputStream();
167
            } catch (FileNotFoundException ex) {
179
            } catch (FileNotFoundException ex) {
168
                ex.printStackTrace();
180
                LOG.log(Level.WARNING, "Cannot read " + fo, ex); // NOI18N
169
            }
181
            }
170
        }
182
        }
171
       return null;
183
       return null;
Lines 235-243 Link Here
235
            }
247
            }
236
            return toRet.toArray(new NetbeansActionMapping[toRet.size()]);
248
            return toRet.toArray(new NetbeansActionMapping[toRet.size()]);
237
        } catch (XmlPullParserException ex) {
249
        } catch (XmlPullParserException ex) {
238
            ex.printStackTrace();
250
            LOG.log(Level.WARNING, null, ex);
239
        } catch (IOException ex) {
251
        } catch (IOException ex) {
240
            ex.printStackTrace();
252
            LOG.log(Level.WARNING, null, ex);
241
        }
253
        }
242
        return fallbackActions;
254
        return fallbackActions;
243
    }
255
    }
Lines 247-250 Link Here
247
        return resetCache.get();
259
        return resetCache.get();
248
    }
260
    }
249
261
262
    @Override
263
    public ActionToGoalMapping getRawMappings() {
264
        if (originalMappings == null || reloadStream()) {
265
            Reader rdr = null;
266
            InputStream in = getActionDefinitionStream();
267
            try {
268
                if (in == null) {
269
                    in = getActionDefinitionStream(DEFAULT);
270
                    if (in != null) {
271
                        rdr = new InputStreamReader(in);
272
                        ActionToGoalMapping def = reader.read(rdr);
273
                        for (NetbeansActionProfile p : def.getProfiles()) {
274
                            if (id.equals(p.getId())) {
275
                                ActionToGoalMapping m = new ActionToGoalMapping();
276
                                m.setActions(m.getActions());
277
                                m.setModelEncoding(m.getModelEncoding());
278
                                originalMappings = m;
279
                                break;
280
                            }
281
                        }
282
283
                    } else {
284
                        originalMappings = new ActionToGoalMapping();
285
                    }
286
                } else {
287
                    rdr = new InputStreamReader(in);
288
                    originalMappings = reader.read(rdr);
289
                }
290
            } catch (IOException ex) {
291
                LOG.log(Level.INFO, "Loading raw mappings", ex);
292
            } catch (XmlPullParserException ex) {
293
                LOG.log(Level.INFO, "Loading raw mappings", ex);
294
            } finally {
295
                if (rdr != null) {
296
                    try {
297
                        rdr.close();
298
                    } catch (IOException ex) {
299
                    }
300
                }
301
            }
302
            if (originalMappings == null) {
303
                originalMappings = new ActionToGoalMapping();
304
            }
305
        }
306
        return originalMappings;
307
    }
308
309
    public NetbeansActionMapping getProfileMappingForAction(String action, Project project, Map<String,String> replaceMap) {
310
        return new NetbeansActionReader() {
311
            @Override
312
            protected String getRawMappingsAsString() {
313
                NetbeansBuildActionXpp3Writer writer = new NetbeansBuildActionXpp3Writer();
314
                StringWriter str = new StringWriter();
315
                try {
316
                    InputStream in = getActionDefinitionStream(DEFAULT);
317
                    InputStreamReader rdr = new InputStreamReader(in);
318
                    ActionToGoalMapping map = reader.read(rdr);
319
                    writer.write(str, map);
320
                } catch (IOException ex) {
321
                    LOG.log(Level.WARNING, "Loading raw mappings", ex);
322
                } catch (XmlPullParserException ex) {
323
                    LOG.log(Level.WARNING, "Loading raw mappings", ex);
324
                }
325
                return str.toString();
326
            }
327
328
            @Override
329
            protected Reader performDynamicSubstitutions(Map<String, String> replaceMap, String in) throws IOException {
330
                return M2Configuration.this.performDynamicSubstitutions(replaceMap, in);
331
            }
332
        }.getMappingForAction(reader, null, action, project, id, replaceMap);
333
    }
334
335
    public NetbeansActionMapping findMappingFor(Map<String, String> replaceMap, Project project, String actionName) {
336
        NetbeansActionMapping action = getProfileMappingForAction(actionName, project, replaceMap);
337
        if (action != null) {
338
            return action;
339
        }
340
        return new NetbeansActionReader() {
341
            @Override
342
            protected String getRawMappingsAsString() {
343
                return M2Configuration.this.getRawMappingsAsString();
344
            }
345
346
            @Override
347
            protected Reader performDynamicSubstitutions(Map<String, String> replaceMap, String in) throws IOException {
348
                return M2Configuration.this.performDynamicSubstitutions(replaceMap, in);
349
            }
350
        }.getMappingForAction(reader, LOG, actionName, project, null, replaceMap);
351
    }
352
250
}
353
}
(-)a/maven/src/org/netbeans/modules/maven/execute/ActionToGoalUtils.java (+3 lines)
Lines 210-215 Link Here
210
        NetbeansActionMapping na = null;
210
        NetbeansActionMapping na = null;
211
        if (configuration != null) {
211
        if (configuration != null) {
212
            na = configuration.getMappingForAction(action, project);
212
            na = configuration.getMappingForAction(action, project);
213
            if (na == null) {
214
                na = configuration.getProfileMappingForAction(action, project, Collections.<String,String>emptyMap());
215
            }
213
        }
216
        }
214
        if (na == null) {
217
        if (na == null) {
215
            na = getDefaultMapping(action, project);
218
            na = getDefaultMapping(action, project);
(-)a/maven/src/org/netbeans/modules/maven/execute/model/ActionToGoalMapping.java (+21 lines)
Lines 75-80 Link Here
75
     * Field actions.
75
     * Field actions.
76
     */
76
     */
77
    private java.util.List<NetbeansActionMapping> actions;
77
    private java.util.List<NetbeansActionMapping> actions;
78
    private java.util.List<NetbeansActionProfile> profiles;
78
79
79
80
80
      //-----------/
81
      //-----------/
Lines 180-183 Link Here
180
    {
181
    {
181
        return modelEncoding;
182
        return modelEncoding;
182
    }
183
    }
184
    
185
    public void addProfile(NetbeansActionProfile p) {
186
        getProfiles().add(p);
187
    }
188
189
    public java.util.List<NetbeansActionProfile> getProfiles() {
190
        if (this.profiles == null) {
191
            this.profiles = new java.util.ArrayList<NetbeansActionProfile>();
192
        }
193
        return this.profiles;
194
    } 
195
196
    public void removeProfile(NetbeansActionProfile p) {
197
        getActions().remove( p );
198
    }
199
200
    public void setProfiles(java.util.List<NetbeansActionProfile> p) {
201
        this.profiles  = p;
202
    }
203
    
183
}
204
}
(-)a/maven/src/org/netbeans/modules/maven/execute/model/NetbeansActionProfile.java (+120 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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     public String getId() {
37
        return id;
38
    }
39
40
    public void setId(String id) {
41
        this.id = id;
42
    }
43
option by the copyright holder.
44
 *
45
 * Contributor(s):
46
 *
47
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
48
 */
49
package org.netbeans.modules.maven.execute.model;
50
51
/**
52
 *
53
 * @author Jaroslav Tulach <jtulach@netbeans.org>
54
 */
55
public final class NetbeansActionProfile {
56
    /**
57
     * Field actions.
58
     */
59
    private java.util.List<NetbeansActionMapping> actions;
60
    private String id;
61
62
63
      //-----------/
64
     //- Methods -/
65
    //-----------/
66
67
    public String getId() {
68
        return id;
69
    }
70
71
    public void setId(String id) {
72
        this.id = id;
73
    }
74
75
    /**
76
     * Method addAction.
77
     * 
78
     * @param netbeansActionMapping
79
     */
80
    public void addAction(NetbeansActionMapping netbeansActionMapping)
81
    {
82
        getActions().add( netbeansActionMapping );
83
    } //-- void addAction(NetbeansActionMapping) 
84
85
    /**
86
     * Method getActions.
87
     * 
88
     * @return java.util.List
89
     */
90
    public java.util.List<NetbeansActionMapping> getActions()
91
    {
92
        if ( this.actions == null )
93
        {
94
            this.actions = new java.util.ArrayList<NetbeansActionMapping>();
95
        }
96
        
97
        return this.actions;
98
    } //-- java.util.List getActions() 
99
100
    /**
101
     * Method removeAction.
102
     * 
103
     * @param netbeansActionMapping
104
     */
105
    public void removeAction(NetbeansActionMapping netbeansActionMapping)
106
    {
107
        getActions().remove( netbeansActionMapping );
108
    } //-- void removeAction(NetbeansActionMapping) 
109
110
    /**
111
     * Set the actions field.
112
     * 
113
     * @param actions
114
     */
115
    public void setActions(java.util.List<NetbeansActionMapping> actions)
116
    {
117
        this.actions = actions;
118
    } //-- void setActions(java.util.List) 
119
    
120
}
(-)a/maven/src/org/netbeans/modules/maven/execute/model/NetbeansActionReader.java (+111 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.maven.execute.model;
43
44
import java.io.IOException;
45
import java.io.Reader;
46
import java.util.Collections;
47
import java.util.Iterator;
48
import java.util.List;
49
import java.util.Map;
50
import java.util.logging.Level;
51
import java.util.logging.Logger;
52
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
53
import org.netbeans.api.project.Project;
54
import org.netbeans.modules.maven.api.NbMavenProject;
55
import org.netbeans.modules.maven.execute.model.io.xpp3.NetbeansBuildActionXpp3Reader;
56
57
/**
58
 *
59
 * @author Jaroslav Tulach <jtulach@netbeans.org>
60
 */
61
public abstract class NetbeansActionReader {
62
    protected abstract String getRawMappingsAsString();
63
    protected abstract Reader performDynamicSubstitutions(Map<String,String> replaceMap, String in) throws IOException;
64
    
65
    
66
    public final NetbeansActionMapping getMappingForAction(
67
        NetbeansBuildActionXpp3Reader reader, Logger LOG,
68
        String actionName, Project project, String profile,
69
        Map<String, String> map
70
    ) {
71
        NetbeansActionMapping action = null;
72
        try {
73
            // just a converter for the To-Object reader..
74
            Reader read = performDynamicSubstitutions(map, getRawMappingsAsString());
75
            // basically doing a copy here..
76
            ActionToGoalMapping mapping = reader.read(read);
77
            List<NetbeansActionMapping> actions;
78
            if (profile == null) {
79
                actions = mapping.getActions();
80
            } else {
81
                actions = Collections.emptyList();
82
                for (NetbeansActionProfile p : mapping.getProfiles()) {
83
                    if (profile.equals(p.getId())) {
84
                        actions = p.getActions();
85
                        break;
86
                    }
87
                }
88
            }
89
            Iterator<NetbeansActionMapping> it = actions.iterator();
90
            NbMavenProject mp = project.getLookup().lookup(NbMavenProject.class);
91
            String prjPack = mp.getPackagingType();
92
            while (it.hasNext()) {
93
                NetbeansActionMapping elem = it.next();
94
                if (actionName.equals(elem.getActionName())
95
                        && (elem.getPackagings().isEmpty()
96
                        || elem.getPackagings().contains(prjPack.trim())
97
                        || elem.getPackagings().contains("*"))) {//NOI18N
98
                    action = elem;
99
                    break;
100
                }
101
            }
102
        } catch (XmlPullParserException ex) {
103
            LOG.log(Level.INFO, "Parsing action mapping", ex);
104
        } catch (IOException ex) {
105
            LOG.log(Level.INFO, "Parsing action mapping", ex);
106
        }
107
        return action;
108
109
    }
110
    
111
}
(-)a/maven/src/org/netbeans/modules/maven/execute/model/io/xpp3/NetbeansBuildActionXpp3Reader.java (+22 lines)
Lines 57-62 Link Here
57
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
57
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
58
import org.netbeans.modules.maven.execute.model.ActionToGoalMapping;
58
import org.netbeans.modules.maven.execute.model.ActionToGoalMapping;
59
import org.netbeans.modules.maven.execute.model.NetbeansActionMapping;
59
import org.netbeans.modules.maven.execute.model.NetbeansActionMapping;
60
import org.netbeans.modules.maven.execute.model.NetbeansActionProfile;
60
61
61
/**
62
/**
62
 * Class NetbeansBuildActionXpp3Reader.
63
 * Class NetbeansBuildActionXpp3Reader.
Lines 264-269 Link Here
264
                        actionToGoalMapping.setActions( actions );
265
                        actionToGoalMapping.setActions( actions );
265
                    }
266
                    }
266
                    actions.add( parseNetbeansActionMapping( "action", parser, strict ) );
267
                    actions.add( parseNetbeansActionMapping( "action", parser, strict ) );
268
                } else if ( parser.getName().equals( "profiles" ) ) {
269
                    while ( parser.nextTag() == XmlPullParser.START_TAG ) {
270
                        if (parser.getName().equals("profile")) {
271
                            actionToGoalMapping.getProfiles().add(parseProfile(parser, strict));
272
                        }
273
                    }
267
                }
274
                }
268
                else if ( !foundRoot && strict )
275
                else if ( !foundRoot && strict )
269
                {
276
                {
Lines 274-279 Link Here
274
        }
281
        }
275
        return actionToGoalMapping;
282
        return actionToGoalMapping;
276
    } //-- ActionToGoalMapping parseActionToGoalMapping(String, XmlPullParser, boolean) 
283
    } //-- ActionToGoalMapping parseActionToGoalMapping(String, XmlPullParser, boolean) 
284
    
285
    private NetbeansActionProfile parseProfile(XmlPullParser parser, boolean strict) throws IOException, XmlPullParserException {
286
        NetbeansActionProfile p = new NetbeansActionProfile();
287
        while ( parser.nextTag() == XmlPullParser.START_TAG ) {
288
            if (parser.getName().equals("id")) {
289
                p.setId(parser.nextText());
290
            } else if (parser.getName().equals("actions")) {
291
                while (parser.nextTag() == XmlPullParser.START_TAG && parser.getName().equals("action")) {
292
                    NetbeansActionMapping r = parseNetbeansActionMapping("actions", parser, strict);
293
                    p.addAction(r);
294
                }
295
            }
296
        }
297
        return p;
298
    }
277
299
278
    /**
300
    /**
279
     * Method parseNetbeansActionMapping.
301
     * Method parseNetbeansActionMapping.
(-)a/maven/src/org/netbeans/modules/maven/execute/model/io/xpp3/NetbeansBuildActionXpp3Writer.java (+19 lines)
Lines 54-59 Link Here
54
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
54
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
55
import org.netbeans.modules.maven.execute.model.ActionToGoalMapping;
55
import org.netbeans.modules.maven.execute.model.ActionToGoalMapping;
56
import org.netbeans.modules.maven.execute.model.NetbeansActionMapping;
56
import org.netbeans.modules.maven.execute.model.NetbeansActionMapping;
57
import org.netbeans.modules.maven.execute.model.NetbeansActionProfile;
57
58
58
/**
59
/**
59
 * Class NetbeansBuildActionXpp3Writer.
60
 * Class NetbeansBuildActionXpp3Writer.
Lines 123-128 Link Here
123
                    writeNetbeansActionMapping( o, "action", serializer );
124
                    writeNetbeansActionMapping( o, "action", serializer );
124
                }
125
                }
125
            }
126
            }
127
            if (!actionToGoalMapping.getProfiles().isEmpty()) {
128
                serializer.startTag(NAMESPACE, "profiles");
129
                for (NetbeansActionProfile p : actionToGoalMapping.getProfiles()) {
130
                    writeNetbeansActionProfile(p, "profile", serializer);
131
                }
132
                serializer.endTag(NAMESPACE, "profiles");
133
            }
126
            serializer.endTag( NAMESPACE, tagName );
134
            serializer.endTag( NAMESPACE, tagName );
127
        }
135
        }
128
    } //-- void writeActionToGoalMapping(ActionToGoalMapping, String, XmlSerializer) 
136
    } //-- void writeActionToGoalMapping(ActionToGoalMapping, String, XmlSerializer) 
Lines 210-214 Link Here
210
        }
218
        }
211
    } //-- void writeNetbeansActionMapping(NetbeansActionMapping, String, XmlSerializer) 
219
    } //-- void writeNetbeansActionMapping(NetbeansActionMapping, String, XmlSerializer) 
212
220
221
    private void writeNetbeansActionProfile(NetbeansActionProfile p, String tagName, XmlSerializer serializer)
222
    throws java.io.IOException {
223
        serializer.startTag( NAMESPACE, tagName);
224
        serializer.startTag( NAMESPACE, "id" ).text( p.getId()).endTag( NAMESPACE, "id");
225
        serializer.startTag( NAMESPACE, "actions");
226
        for (NetbeansActionMapping m : p.getActions()) {
227
            writeNetbeansActionMapping(m, "action", serializer);
228
        }
229
        serializer.endTag( NAMESPACE, "actions");
230
        serializer.endTag( NAMESPACE, tagName );
231
    } 
213
232
214
}
233
}
(-)a/maven/src/org/netbeans/modules/maven/spi/actions/AbstractMavenActionsProvider.java (-39 / +36 lines)
Lines 63-72 Link Here
63
import org.netbeans.modules.maven.api.NbMavenProject;
63
import org.netbeans.modules.maven.api.NbMavenProject;
64
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
64
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
65
import org.netbeans.api.project.Project;
65
import org.netbeans.api.project.Project;
66
import org.netbeans.modules.maven.configurations.M2Configuration;
66
import org.netbeans.modules.maven.execute.DefaultReplaceTokenProvider;
67
import org.netbeans.modules.maven.execute.DefaultReplaceTokenProvider;
67
import org.netbeans.modules.maven.execute.ModelRunConfig;
68
import org.netbeans.modules.maven.execute.ModelRunConfig;
68
import org.netbeans.modules.maven.execute.model.ActionToGoalMapping;
69
import org.netbeans.modules.maven.execute.model.ActionToGoalMapping;
69
import org.netbeans.modules.maven.execute.model.NetbeansActionMapping;
70
import org.netbeans.modules.maven.execute.model.NetbeansActionMapping;
71
import org.netbeans.modules.maven.execute.model.NetbeansActionReader;
70
import org.netbeans.modules.maven.execute.model.io.xpp3.NetbeansBuildActionXpp3Reader;
72
import org.netbeans.modules.maven.execute.model.io.xpp3.NetbeansBuildActionXpp3Reader;
71
import org.netbeans.modules.maven.execute.model.io.xpp3.NetbeansBuildActionXpp3Writer;
73
import org.netbeans.modules.maven.execute.model.io.xpp3.NetbeansBuildActionXpp3Writer;
72
import org.netbeans.spi.project.SingleMethod;
74
import org.netbeans.spi.project.SingleMethod;
Lines 231-262 Link Here
231
     */
233
     */
232
    @Override
234
    @Override
233
    public NetbeansActionMapping getMappingForAction(String actionName, Project project) {
235
    public NetbeansActionMapping getMappingForAction(String actionName, Project project) {
234
        NetbeansActionMapping action = null;
236
        return new NetbeansActionReader() {
235
        try {
237
            @Override
236
            // just a converter for the To-Object reader..
238
            protected String getRawMappingsAsString() {
237
            Reader read = performDynamicSubstitutions(Collections.<String, String>emptyMap(), getRawMappingsAsString());
239
                return AbstractMavenActionsProvider.this.getRawMappingsAsString();
238
            // basically doing a copy here..
239
            ActionToGoalMapping mapping = reader.read(read);
240
            Iterator<NetbeansActionMapping> it = mapping.getActions().iterator();
241
            NbMavenProject mp = project.getLookup().lookup(NbMavenProject.class);
242
            String prjPack = mp.getPackagingType();
243
            while (it.hasNext()) {
244
                NetbeansActionMapping elem = it.next();
245
                if (actionName.equals(elem.getActionName()) &&
246
                        (elem.getPackagings().isEmpty() ||
247
                         elem.getPackagings().contains(prjPack.trim()) ||
248
                         elem.getPackagings().contains("*"))) {//NOI18N
249
                    action = elem;
250
                    break;
251
                }
252
            }
240
            }
253
        } catch (XmlPullParserException ex) {
254
            LOG.log(Level.INFO, "Parsing action mapping", ex);
255
        } catch (IOException ex) {
256
            LOG.log(Level.INFO, "Parsing action mapping", ex);
257
        }
258
        return action;
259
241
242
            @Override
243
            protected Reader performDynamicSubstitutions(Map<String, String> replaceMap, String in) throws IOException {
244
                return AbstractMavenActionsProvider.this.performDynamicSubstitutions(replaceMap, in);
245
            }
246
        }.getMappingForAction(reader, LOG, actionName, project, null, Collections.<String, String>emptyMap());
260
    }
247
    }
261
248
262
    /**
249
    /**
Lines 267-287 Link Here
267
254
268
    private RunConfig mapGoalsToAction(Project project, String actionName, Map<String, String> replaceMap, FileObject selectedFile, Lookup lookup) {
255
    private RunConfig mapGoalsToAction(Project project, String actionName, Map<String, String> replaceMap, FileObject selectedFile, Lookup lookup) {
269
        try {
256
        try {
270
            // TODO need some caching really badly here..
257
            NetbeansActionMapping action;
271
            Reader read = performDynamicSubstitutions(replaceMap, getRawMappingsAsString());
258
            if (this instanceof M2Configuration) {
272
            ActionToGoalMapping mapping = reader.read(read);
259
                action = ((M2Configuration)this).findMappingFor(replaceMap, project, actionName);
273
            Iterator<NetbeansActionMapping> it = mapping.getActions().iterator();
260
            } else {
274
            NetbeansActionMapping action = null;
261
                action = findMapAction(replaceMap, project, actionName);
275
            NbMavenProject mp = project.getLookup().lookup(NbMavenProject.class);
276
            String prjPack = mp.getPackagingType();
277
            while (it.hasNext()) {
278
                NetbeansActionMapping elem = it.next();
279
                if (actionName.equals(elem.getActionName()) &&
280
                        (elem.getPackagings().contains(prjPack.trim()) ||
281
                        elem.getPackagings().contains("*") || elem.getPackagings().isEmpty())) {//NOI18N
282
                    action = elem;
283
                    break;
284
                }
285
            }
262
            }
286
            if (action != null) {
263
            if (action != null) {
287
                ModelRunConfig mrc = new ModelRunConfig(project, action, actionName, selectedFile, lookup);
264
                ModelRunConfig mrc = new ModelRunConfig(project, action, actionName, selectedFile, lookup);
Lines 299-304 Link Here
299
        return null;
276
        return null;
300
    }
277
    }
301
278
279
    private NetbeansActionMapping findMapAction(Map<String, String> replaceMap, Project project, String actionName) throws XmlPullParserException, IOException {
280
        // TODO need some caching really badly here..
281
        Reader read = performDynamicSubstitutions(replaceMap, getRawMappingsAsString());
282
        ActionToGoalMapping mapping = reader.read(read);
283
        Iterator<NetbeansActionMapping> it = mapping.getActions().iterator();
284
        NetbeansActionMapping action = null;
285
        NbMavenProject mp = project.getLookup().lookup(NbMavenProject.class);
286
        String prjPack = mp.getPackagingType();
287
        while (it.hasNext()) {
288
            NetbeansActionMapping elem = it.next();
289
            if (actionName.equals(elem.getActionName()) &&
290
                    (elem.getPackagings().contains(prjPack.trim()) ||
291
                    elem.getPackagings().contains("*") || elem.getPackagings().isEmpty())) {//NOI18N
292
                action = elem;
293
                break;
294
            }
295
        }
296
        return action;
297
    }
298
302
    /**
299
    /**
303
     * takes the input stream and a map, and for each occurence of ${<mapKey>}, replaces it with map entry value..
300
     * takes the input stream and a map, and for each occurence of ${<mapKey>}, replaces it with map entry value..
304
     * @param replaceMap
301
     * @param replaceMap
(-)a/maven/test/unit/src/org/netbeans/modules/maven/api/customizer/ModelHandle2Test.java (+33 lines)
Lines 42-47 Link Here
42
import org.netbeans.api.project.Project;
42
import org.netbeans.api.project.Project;
43
import org.netbeans.api.project.ProjectManager;
43
import org.netbeans.api.project.ProjectManager;
44
import org.netbeans.junit.NbTestCase;
44
import org.netbeans.junit.NbTestCase;
45
import org.netbeans.modules.maven.api.execute.RunConfig;
45
import org.netbeans.modules.maven.configurations.M2ConfigProvider;
46
import org.netbeans.modules.maven.configurations.M2ConfigProvider;
46
import org.netbeans.modules.maven.configurations.M2Configuration;
47
import org.netbeans.modules.maven.configurations.M2Configuration;
47
import org.netbeans.modules.maven.execute.model.NetbeansActionMapping;
48
import org.netbeans.modules.maven.execute.model.NetbeansActionMapping;
Lines 85-89 Link Here
85
        assertEquals("jetty", cp.getActiveConfiguration().getId());
86
        assertEquals("jetty", cp.getActiveConfiguration().getId());
86
        assertFalse(nbactionsJetty.asText().contains("someprop"));
87
        assertFalse(nbactionsJetty.asText().contains("someprop"));
87
    }
88
    }
89
    
90
    public void testModifyActiveConfigInOneFile() throws Exception { // #200772
91
        TestFileUtils.writeFile(d, "pom.xml", "<project><modelVersion>4.0.0</modelVersion><groupId>g</groupId><artifactId>a</artifactId><version>0</version><profiles><profile><id>jetty</id></profile></profiles></project>");
92
        TestFileUtils.writeFile(d, "nbactions.xml", "<actions><action><actionName>run</actionName><goals><goal>package</goal></goals></action>" +
93
            "<profiles><profile><id>jetty</id><actions><action><displayName>Jetty</displayName>"
94
                + "<actionName>run</actionName><goals><goal>jetty:run</goal></goals>"
95
                + "<properties><someprop>v</someprop></properties></action>"
96
                + "</actions></profile></profiles>"
97
                + "</actions>");
98
        Project project = ProjectManager.getDefault().findProject(d);
99
        M2ConfigProvider cp = project.getLookup().lookup(M2ConfigProvider.class);
100
        M2Configuration conf = null;
101
        for (M2Configuration c : cp.getConfigurations()) {
102
            if (c.getId().equals("jetty")) {
103
                cp.setActiveConfiguration(c);
104
                conf = c;
105
                break;
106
            }
107
        }
108
        assertNotNull("Configuration found", conf);
109
        assertEquals("jetty", cp.getActiveConfiguration().getId());
110
        NetbeansActionMapping mapp = ModelHandle2.getMapping("run", project, cp.getActiveConfiguration());
111
        assertNotNull(mapp);
112
        assertEquals("Jetty", mapp.getDisplayName());
113
        Map<String,String> props = mapp.getProperties();
114
        assertNotNull(props);
115
        assertEquals("{someprop=v}", props.toString());
116
        
117
        RunConfig run = conf.createConfigForDefaultAction("run", project, project.getLookup());
118
        assertEquals("One goal", 1, run.getGoals().size());
119
        assertEquals("jetty:run", run.getGoals().get(0));
120
    }
88
121
89
}
122
}

Return to bug 229192