diff --git a/maven/src/org/netbeans/modules/maven/configurations/M2Configuration.java b/maven/src/org/netbeans/modules/maven/configurations/M2Configuration.java --- a/maven/src/org/netbeans/modules/maven/configurations/M2Configuration.java +++ b/maven/src/org/netbeans/modules/maven/configurations/M2Configuration.java @@ -45,19 +45,27 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.Reader; +import java.io.StringWriter; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.Level; +import java.util.logging.Logger; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.project.Project; import org.netbeans.modules.maven.api.MavenConfiguration; import static org.netbeans.modules.maven.configurations.Bundle.*; import org.netbeans.modules.maven.execute.model.ActionToGoalMapping; import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; +import org.netbeans.modules.maven.execute.model.NetbeansActionProfile; +import org.netbeans.modules.maven.execute.model.NetbeansActionReader; +import org.netbeans.modules.maven.execute.model.io.xpp3.NetbeansBuildActionXpp3Writer; import org.netbeans.modules.maven.spi.actions.AbstractMavenActionsProvider; import org.openide.filesystems.FileChangeAdapter; import org.openide.filesystems.FileChangeListener; @@ -65,6 +73,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileRenameEvent; import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; import org.openide.util.NbBundle.Messages; /** @@ -72,6 +81,7 @@ * @author mkleint */ public class M2Configuration extends AbstractMavenActionsProvider implements MavenConfiguration, Comparable { + private static final Logger LOG = Logger.getLogger(M2Configuration.class.getName()); public static final String DEFAULT = "%%DEFAULT%%"; //NOI18N @@ -157,15 +167,17 @@ } public @Override InputStream getActionDefinitionStream() { - + return getActionDefinitionStream(id); + } + final InputStream getActionDefinitionStream(String forId) { checkListener(); - FileObject fo = projectDirectory.getFileObject(getFileNameExt(id)); + FileObject fo = projectDirectory.getFileObject(getFileNameExt(forId)); resetCache.set(false); if (fo != null) { try { return fo.getInputStream(); } catch (FileNotFoundException ex) { - ex.printStackTrace(); + LOG.log(Level.WARNING, "Cannot read " + fo, ex); // NOI18N } } return null; @@ -235,9 +247,9 @@ } return toRet.toArray(new NetbeansActionMapping[toRet.size()]); } catch (XmlPullParserException ex) { - ex.printStackTrace(); + LOG.log(Level.WARNING, null, ex); } catch (IOException ex) { - ex.printStackTrace(); + LOG.log(Level.WARNING, null, ex); } return fallbackActions; } @@ -247,4 +259,95 @@ return resetCache.get(); } + @Override + public ActionToGoalMapping getRawMappings() { + if (originalMappings == null || reloadStream()) { + Reader rdr = null; + InputStream in = getActionDefinitionStream(); + try { + if (in == null) { + in = getActionDefinitionStream(DEFAULT); + if (in != null) { + rdr = new InputStreamReader(in); + ActionToGoalMapping def = reader.read(rdr); + for (NetbeansActionProfile p : def.getProfiles()) { + if (id.equals(p.getId())) { + ActionToGoalMapping m = new ActionToGoalMapping(); + m.setActions(m.getActions()); + m.setModelEncoding(m.getModelEncoding()); + originalMappings = m; + break; + } + } + + } else { + originalMappings = new ActionToGoalMapping(); + } + } else { + rdr = new InputStreamReader(in); + originalMappings = reader.read(rdr); + } + } catch (IOException ex) { + LOG.log(Level.INFO, "Loading raw mappings", ex); + } catch (XmlPullParserException ex) { + LOG.log(Level.INFO, "Loading raw mappings", ex); + } finally { + if (rdr != null) { + try { + rdr.close(); + } catch (IOException ex) { + } + } + } + if (originalMappings == null) { + originalMappings = new ActionToGoalMapping(); + } + } + return originalMappings; + } + + public NetbeansActionMapping getProfileMappingForAction(String action, Project project, Map replaceMap) { + return new NetbeansActionReader() { + @Override + protected String getRawMappingsAsString() { + NetbeansBuildActionXpp3Writer writer = new NetbeansBuildActionXpp3Writer(); + StringWriter str = new StringWriter(); + try { + InputStream in = getActionDefinitionStream(DEFAULT); + InputStreamReader rdr = new InputStreamReader(in); + ActionToGoalMapping map = reader.read(rdr); + writer.write(str, map); + } catch (IOException ex) { + LOG.log(Level.WARNING, "Loading raw mappings", ex); + } catch (XmlPullParserException ex) { + LOG.log(Level.WARNING, "Loading raw mappings", ex); + } + return str.toString(); + } + + @Override + protected Reader performDynamicSubstitutions(Map replaceMap, String in) throws IOException { + return M2Configuration.this.performDynamicSubstitutions(replaceMap, in); + } + }.getMappingForAction(reader, null, action, project, id, replaceMap); + } + + public NetbeansActionMapping findMappingFor(Map replaceMap, Project project, String actionName) { + NetbeansActionMapping action = getProfileMappingForAction(actionName, project, replaceMap); + if (action != null) { + return action; + } + return new NetbeansActionReader() { + @Override + protected String getRawMappingsAsString() { + return M2Configuration.this.getRawMappingsAsString(); + } + + @Override + protected Reader performDynamicSubstitutions(Map replaceMap, String in) throws IOException { + return M2Configuration.this.performDynamicSubstitutions(replaceMap, in); + } + }.getMappingForAction(reader, LOG, actionName, project, null, replaceMap); + } + } diff --git a/maven/src/org/netbeans/modules/maven/execute/ActionToGoalUtils.java b/maven/src/org/netbeans/modules/maven/execute/ActionToGoalUtils.java --- a/maven/src/org/netbeans/modules/maven/execute/ActionToGoalUtils.java +++ b/maven/src/org/netbeans/modules/maven/execute/ActionToGoalUtils.java @@ -210,6 +210,9 @@ NetbeansActionMapping na = null; if (configuration != null) { na = configuration.getMappingForAction(action, project); + if (na == null) { + na = configuration.getProfileMappingForAction(action, project, Collections.emptyMap()); + } } if (na == null) { na = getDefaultMapping(action, project); diff --git a/maven/src/org/netbeans/modules/maven/execute/model/ActionToGoalMapping.java b/maven/src/org/netbeans/modules/maven/execute/model/ActionToGoalMapping.java --- a/maven/src/org/netbeans/modules/maven/execute/model/ActionToGoalMapping.java +++ b/maven/src/org/netbeans/modules/maven/execute/model/ActionToGoalMapping.java @@ -75,6 +75,7 @@ * Field actions. */ private java.util.List actions; + private java.util.List profiles; //-----------/ @@ -180,4 +181,24 @@ { return modelEncoding; } + + public void addProfile(NetbeansActionProfile p) { + getProfiles().add(p); + } + + public java.util.List getProfiles() { + if (this.profiles == null) { + this.profiles = new java.util.ArrayList(); + } + return this.profiles; + } + + public void removeProfile(NetbeansActionProfile p) { + getActions().remove( p ); + } + + public void setProfiles(java.util.List p) { + this.profiles = p; + } + } diff --git a/maven/src/org/netbeans/modules/maven/execute/model/NetbeansActionProfile.java b/maven/src/org/netbeans/modules/maven/execute/model/NetbeansActionProfile.java new file mode 100644 --- /dev/null +++ b/maven/src/org/netbeans/modules/maven/execute/model/NetbeansActionProfile.java @@ -0,0 +1,120 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2014 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.execute.model; + +/** + * + * @author Jaroslav Tulach + */ +public final class NetbeansActionProfile { + /** + * Field actions. + */ + private java.util.List actions; + private String id; + + + //-----------/ + //- Methods -/ + //-----------/ + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + /** + * Method addAction. + * + * @param netbeansActionMapping + */ + public void addAction(NetbeansActionMapping netbeansActionMapping) + { + getActions().add( netbeansActionMapping ); + } //-- void addAction(NetbeansActionMapping) + + /** + * Method getActions. + * + * @return java.util.List + */ + public java.util.List getActions() + { + if ( this.actions == null ) + { + this.actions = new java.util.ArrayList(); + } + + return this.actions; + } //-- java.util.List getActions() + + /** + * Method removeAction. + * + * @param netbeansActionMapping + */ + public void removeAction(NetbeansActionMapping netbeansActionMapping) + { + getActions().remove( netbeansActionMapping ); + } //-- void removeAction(NetbeansActionMapping) + + /** + * Set the actions field. + * + * @param actions + */ + public void setActions(java.util.List actions) + { + this.actions = actions; + } //-- void setActions(java.util.List) + +} diff --git a/maven/src/org/netbeans/modules/maven/execute/model/NetbeansActionReader.java b/maven/src/org/netbeans/modules/maven/execute/model/NetbeansActionReader.java new file mode 100644 --- /dev/null +++ b/maven/src/org/netbeans/modules/maven/execute/model/NetbeansActionReader.java @@ -0,0 +1,111 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2014 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.execute.model; + +import java.io.IOException; +import java.io.Reader; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.netbeans.api.project.Project; +import org.netbeans.modules.maven.api.NbMavenProject; +import org.netbeans.modules.maven.execute.model.io.xpp3.NetbeansBuildActionXpp3Reader; + +/** + * + * @author Jaroslav Tulach + */ +public abstract class NetbeansActionReader { + protected abstract String getRawMappingsAsString(); + protected abstract Reader performDynamicSubstitutions(Map replaceMap, String in) throws IOException; + + + public final NetbeansActionMapping getMappingForAction( + NetbeansBuildActionXpp3Reader reader, Logger LOG, + String actionName, Project project, String profile, + Map map + ) { + NetbeansActionMapping action = null; + try { + // just a converter for the To-Object reader.. + Reader read = performDynamicSubstitutions(map, getRawMappingsAsString()); + // basically doing a copy here.. + ActionToGoalMapping mapping = reader.read(read); + List actions; + if (profile == null) { + actions = mapping.getActions(); + } else { + actions = Collections.emptyList(); + for (NetbeansActionProfile p : mapping.getProfiles()) { + if (profile.equals(p.getId())) { + actions = p.getActions(); + break; + } + } + } + Iterator it = actions.iterator(); + NbMavenProject mp = project.getLookup().lookup(NbMavenProject.class); + String prjPack = mp.getPackagingType(); + while (it.hasNext()) { + NetbeansActionMapping elem = it.next(); + if (actionName.equals(elem.getActionName()) + && (elem.getPackagings().isEmpty() + || elem.getPackagings().contains(prjPack.trim()) + || elem.getPackagings().contains("*"))) {//NOI18N + action = elem; + break; + } + } + } catch (XmlPullParserException ex) { + LOG.log(Level.INFO, "Parsing action mapping", ex); + } catch (IOException ex) { + LOG.log(Level.INFO, "Parsing action mapping", ex); + } + return action; + + } + +} diff --git a/maven/src/org/netbeans/modules/maven/execute/model/io/xpp3/NetbeansBuildActionXpp3Reader.java b/maven/src/org/netbeans/modules/maven/execute/model/io/xpp3/NetbeansBuildActionXpp3Reader.java --- a/maven/src/org/netbeans/modules/maven/execute/model/io/xpp3/NetbeansBuildActionXpp3Reader.java +++ b/maven/src/org/netbeans/modules/maven/execute/model/io/xpp3/NetbeansBuildActionXpp3Reader.java @@ -57,6 +57,7 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.netbeans.modules.maven.execute.model.ActionToGoalMapping; import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; +import org.netbeans.modules.maven.execute.model.NetbeansActionProfile; /** * Class NetbeansBuildActionXpp3Reader. @@ -264,6 +265,12 @@ actionToGoalMapping.setActions( actions ); } actions.add( parseNetbeansActionMapping( "action", parser, strict ) ); + } else if ( parser.getName().equals( "profiles" ) ) { + while ( parser.nextTag() == XmlPullParser.START_TAG ) { + if (parser.getName().equals("profile")) { + actionToGoalMapping.getProfiles().add(parseProfile(parser, strict)); + } + } } else if ( !foundRoot && strict ) { @@ -274,6 +281,21 @@ } return actionToGoalMapping; } //-- ActionToGoalMapping parseActionToGoalMapping(String, XmlPullParser, boolean) + + private NetbeansActionProfile parseProfile(XmlPullParser parser, boolean strict) throws IOException, XmlPullParserException { + NetbeansActionProfile p = new NetbeansActionProfile(); + while ( parser.nextTag() == XmlPullParser.START_TAG ) { + if (parser.getName().equals("id")) { + p.setId(parser.nextText()); + } else if (parser.getName().equals("actions")) { + while (parser.nextTag() == XmlPullParser.START_TAG && parser.getName().equals("action")) { + NetbeansActionMapping r = parseNetbeansActionMapping("actions", parser, strict); + p.addAction(r); + } + } + } + return p; + } /** * Method parseNetbeansActionMapping. diff --git a/maven/src/org/netbeans/modules/maven/execute/model/io/xpp3/NetbeansBuildActionXpp3Writer.java b/maven/src/org/netbeans/modules/maven/execute/model/io/xpp3/NetbeansBuildActionXpp3Writer.java --- a/maven/src/org/netbeans/modules/maven/execute/model/io/xpp3/NetbeansBuildActionXpp3Writer.java +++ b/maven/src/org/netbeans/modules/maven/execute/model/io/xpp3/NetbeansBuildActionXpp3Writer.java @@ -54,6 +54,7 @@ import org.codehaus.plexus.util.xml.pull.XmlSerializer; import org.netbeans.modules.maven.execute.model.ActionToGoalMapping; import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; +import org.netbeans.modules.maven.execute.model.NetbeansActionProfile; /** * Class NetbeansBuildActionXpp3Writer. @@ -123,6 +124,13 @@ writeNetbeansActionMapping( o, "action", serializer ); } } + if (!actionToGoalMapping.getProfiles().isEmpty()) { + serializer.startTag(NAMESPACE, "profiles"); + for (NetbeansActionProfile p : actionToGoalMapping.getProfiles()) { + writeNetbeansActionProfile(p, "profile", serializer); + } + serializer.endTag(NAMESPACE, "profiles"); + } serializer.endTag( NAMESPACE, tagName ); } } //-- void writeActionToGoalMapping(ActionToGoalMapping, String, XmlSerializer) @@ -210,5 +218,16 @@ } } //-- void writeNetbeansActionMapping(NetbeansActionMapping, String, XmlSerializer) + private void writeNetbeansActionProfile(NetbeansActionProfile p, String tagName, XmlSerializer serializer) + throws java.io.IOException { + serializer.startTag( NAMESPACE, tagName); + serializer.startTag( NAMESPACE, "id" ).text( p.getId()).endTag( NAMESPACE, "id"); + serializer.startTag( NAMESPACE, "actions"); + for (NetbeansActionMapping m : p.getActions()) { + writeNetbeansActionMapping(m, "action", serializer); + } + serializer.endTag( NAMESPACE, "actions"); + serializer.endTag( NAMESPACE, tagName ); + } } diff --git a/maven/src/org/netbeans/modules/maven/spi/actions/AbstractMavenActionsProvider.java b/maven/src/org/netbeans/modules/maven/spi/actions/AbstractMavenActionsProvider.java --- a/maven/src/org/netbeans/modules/maven/spi/actions/AbstractMavenActionsProvider.java +++ b/maven/src/org/netbeans/modules/maven/spi/actions/AbstractMavenActionsProvider.java @@ -63,10 +63,12 @@ import org.netbeans.modules.maven.api.NbMavenProject; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.netbeans.api.project.Project; +import org.netbeans.modules.maven.configurations.M2Configuration; import org.netbeans.modules.maven.execute.DefaultReplaceTokenProvider; import org.netbeans.modules.maven.execute.ModelRunConfig; import org.netbeans.modules.maven.execute.model.ActionToGoalMapping; import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; +import org.netbeans.modules.maven.execute.model.NetbeansActionReader; import org.netbeans.modules.maven.execute.model.io.xpp3.NetbeansBuildActionXpp3Reader; import org.netbeans.modules.maven.execute.model.io.xpp3.NetbeansBuildActionXpp3Writer; import org.netbeans.spi.project.SingleMethod; @@ -231,32 +233,17 @@ */ @Override public NetbeansActionMapping getMappingForAction(String actionName, Project project) { - NetbeansActionMapping action = null; - try { - // just a converter for the To-Object reader.. - Reader read = performDynamicSubstitutions(Collections.emptyMap(), getRawMappingsAsString()); - // basically doing a copy here.. - ActionToGoalMapping mapping = reader.read(read); - Iterator it = mapping.getActions().iterator(); - NbMavenProject mp = project.getLookup().lookup(NbMavenProject.class); - String prjPack = mp.getPackagingType(); - while (it.hasNext()) { - NetbeansActionMapping elem = it.next(); - if (actionName.equals(elem.getActionName()) && - (elem.getPackagings().isEmpty() || - elem.getPackagings().contains(prjPack.trim()) || - elem.getPackagings().contains("*"))) {//NOI18N - action = elem; - break; - } + return new NetbeansActionReader() { + @Override + protected String getRawMappingsAsString() { + return AbstractMavenActionsProvider.this.getRawMappingsAsString(); } - } catch (XmlPullParserException ex) { - LOG.log(Level.INFO, "Parsing action mapping", ex); - } catch (IOException ex) { - LOG.log(Level.INFO, "Parsing action mapping", ex); - } - return action; + @Override + protected Reader performDynamicSubstitutions(Map replaceMap, String in) throws IOException { + return AbstractMavenActionsProvider.this.performDynamicSubstitutions(replaceMap, in); + } + }.getMappingForAction(reader, LOG, actionName, project, null, Collections.emptyMap()); } /** @@ -267,21 +254,11 @@ private RunConfig mapGoalsToAction(Project project, String actionName, Map replaceMap, FileObject selectedFile, Lookup lookup) { try { - // TODO need some caching really badly here.. - Reader read = performDynamicSubstitutions(replaceMap, getRawMappingsAsString()); - ActionToGoalMapping mapping = reader.read(read); - Iterator it = mapping.getActions().iterator(); - NetbeansActionMapping action = null; - NbMavenProject mp = project.getLookup().lookup(NbMavenProject.class); - String prjPack = mp.getPackagingType(); - while (it.hasNext()) { - NetbeansActionMapping elem = it.next(); - if (actionName.equals(elem.getActionName()) && - (elem.getPackagings().contains(prjPack.trim()) || - elem.getPackagings().contains("*") || elem.getPackagings().isEmpty())) {//NOI18N - action = elem; - break; - } + NetbeansActionMapping action; + if (this instanceof M2Configuration) { + action = ((M2Configuration)this).findMappingFor(replaceMap, project, actionName); + } else { + action = findMapAction(replaceMap, project, actionName); } if (action != null) { ModelRunConfig mrc = new ModelRunConfig(project, action, actionName, selectedFile, lookup); @@ -299,6 +276,26 @@ return null; } + private NetbeansActionMapping findMapAction(Map replaceMap, Project project, String actionName) throws XmlPullParserException, IOException { + // TODO need some caching really badly here.. + Reader read = performDynamicSubstitutions(replaceMap, getRawMappingsAsString()); + ActionToGoalMapping mapping = reader.read(read); + Iterator it = mapping.getActions().iterator(); + NetbeansActionMapping action = null; + NbMavenProject mp = project.getLookup().lookup(NbMavenProject.class); + String prjPack = mp.getPackagingType(); + while (it.hasNext()) { + NetbeansActionMapping elem = it.next(); + if (actionName.equals(elem.getActionName()) && + (elem.getPackagings().contains(prjPack.trim()) || + elem.getPackagings().contains("*") || elem.getPackagings().isEmpty())) {//NOI18N + action = elem; + break; + } + } + return action; + } + /** * takes the input stream and a map, and for each occurence of ${}, replaces it with map entry value.. * @param replaceMap diff --git a/maven/test/unit/src/org/netbeans/modules/maven/api/customizer/ModelHandle2Test.java b/maven/test/unit/src/org/netbeans/modules/maven/api/customizer/ModelHandle2Test.java --- a/maven/test/unit/src/org/netbeans/modules/maven/api/customizer/ModelHandle2Test.java +++ b/maven/test/unit/src/org/netbeans/modules/maven/api/customizer/ModelHandle2Test.java @@ -42,6 +42,7 @@ import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.maven.api.execute.RunConfig; import org.netbeans.modules.maven.configurations.M2ConfigProvider; import org.netbeans.modules.maven.configurations.M2Configuration; import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; @@ -85,5 +86,37 @@ assertEquals("jetty", cp.getActiveConfiguration().getId()); assertFalse(nbactionsJetty.asText().contains("someprop")); } + + public void testModifyActiveConfigInOneFile() throws Exception { // #200772 + TestFileUtils.writeFile(d, "pom.xml", "4.0.0ga0jetty"); + TestFileUtils.writeFile(d, "nbactions.xml", "runpackage" + + "jettyJetty" + + "runjetty:run" + + "v" + + "" + + ""); + Project project = ProjectManager.getDefault().findProject(d); + M2ConfigProvider cp = project.getLookup().lookup(M2ConfigProvider.class); + M2Configuration conf = null; + for (M2Configuration c : cp.getConfigurations()) { + if (c.getId().equals("jetty")) { + cp.setActiveConfiguration(c); + conf = c; + break; + } + } + assertNotNull("Configuration found", conf); + assertEquals("jetty", cp.getActiveConfiguration().getId()); + NetbeansActionMapping mapp = ModelHandle2.getMapping("run", project, cp.getActiveConfiguration()); + assertNotNull(mapp); + assertEquals("Jetty", mapp.getDisplayName()); + Map props = mapp.getProperties(); + assertNotNull(props); + assertEquals("{someprop=v}", props.toString()); + + RunConfig run = conf.createConfigForDefaultAction("run", project, project.getLookup()); + assertEquals("One goal", 1, run.getGoals().size()); + assertEquals("jetty:run", run.getGoals().get(0)); + } }