# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: D:\hg\core-konik # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: maven.util/arch.xml --- maven.util/arch.xml Base (BASE) +++ maven.util/arch.xml Locally New @@ -0,0 +1,1115 @@ + + +]> + + + + &api-questions; + + + + +

The purpose of this module is to provide an easy way to read and set Maven + plugin parameters in POM.xml project file without having implementation + dependencies on several Maven modules. +

+

+

+
+ + + + + +

+ All public API methods will be covered by unit tests. +

+
+ + + + + +

+ 2 man days. +

+
+ + + + + +

+ The main use case is implementing a panel to be added to Maven project properties + window to adjust properties of a Maven plugin used in that project. +

+
+import org.netbeans.modules.maven.util.MavenCategoryProvider;
+
+@MavenCategoryProvider.Registration(artifactId = "my-special-artifactd", groupId = "my.special.maven.groupid")
+public class ProjectCustomizerImpl extends MavenCategoryProvider {
+
+
+    @Override
+    public ProjectCustomizer.Category createCategory( Lookup lkp ) {
+      //will be called only when the Maven project contains plugin with my.special.maven.groupid and my-special-artifactd
+    }
+
+    @Override
+    public JComponent createComponent( ProjectCustomizer.Category ctgr, Lookup lkp ) {
+      return new MyCustomizerPanel( ctgr, getPluginParameters() );
+    }
+}
+
+class MyCustomizerPanel extends JPanel {
+
+    MyCustomizerPanel( ProjectCustomizer.Category category, final MavenPluginParameters pluginParameters ) {
+
+        Object initialValue = pluginParameters.getParameter( "myParamName", "myplugin.myproperty.name" );
+
+        category.setOkButtonListener(new ActionListener() {
+            @Override
+            public void actionPerformed( ActionEvent e ) {
+                pluginParameters.setParameter( "myParamName", "some value" );
+            }
+        } );
+    }
+}
+
+  
+
+ + + + + +

+ Read and set Maven project properties. +

+
+ + + + + + + + + + + + +

+ This module does not deprecate nor replace any existing APIs. +

+
+ + + + + +

+ Does not apply. +

+
+ + + + + +

+ Does not apply. +

+
+ + + + + +

+ Future versions of this module should be backwards compatible. +

+
+ + + + + +

+ Same as the rest of the IDE. +

+
+ + + + + +

+ JDK required. +

+
+ + + + + + + + + + + + +

+ No extra dependencies. +

+
+ + + + + +

+ All platforms the IDE supports. +

+
+ + + + + +

+ No special dependencies. +

+
+ + + + + +

+ Only JAR. +

+
+ + + + + +

+ Yes. +

+
+ + + + + +

+ There are public packages in this module. + +

+
+ + + + + +

+ No special installation requirements. +

+
+ + + + + +

+ No ant tasks. +

+
+ + + + + +

+ No custom class loaders. +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ All API methods are thread safe. +

+
+ + + + + +

+ No clipboard interaction. +

+
+ + + + + +

+ No dnd. +

+
+ + + + + +

+ No direct disk access. +

+
+ + + + + +

+ Uses Lookup passed into project customizer to find Maven model handle. +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No UI components. +

+
+ + + + + +

+ No menus. +

+
+ + + + + +

+ No long running tasks. +

+
+ + + + + +

+ Does not apply. +

+
+ + + + + +

+ No plugged in code. +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ +
Index: maven.util/build.xml --- maven.util/build.xml Base (BASE) +++ maven.util/build.xml Locally New @@ -0,0 +1,5 @@ + + + Builds, tests, and runs the project org.netbeans.modules.maven.util + + Index: maven.util/manifest.mf --- maven.util/manifest.mf Base (BASE) +++ maven.util/manifest.mf Locally New @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +OpenIDE-Module: org.netbeans.modules.maven.util/1 +OpenIDE-Module-Implementation-Version: 1 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/maven/util/Bundle.properties + Index: maven.util/nbproject/project.properties --- maven.util/nbproject/project.properties Base (BASE) +++ maven.util/nbproject/project.properties Locally New @@ -0,0 +1,4 @@ +javac.source=1.6 +javac.compilerargs=-Xlint -Xlint:-serial +javadoc.arch=${basedir}/arch.xml +spec.version.base=1.0 Index: maven.util/nbproject/project.xml --- maven.util/nbproject/project.xml Base (BASE) +++ maven.util/nbproject/project.xml Locally New @@ -0,0 +1,89 @@ + + + org.netbeans.modules.apisupport.project + + + org.netbeans.modules.maven.util + + + org.netbeans.modules.maven + + + + 2 + + + + org.netbeans.modules.maven.embedder + + + + 2 + + + + org.netbeans.modules.maven.model + + + + 1 + + + + org.netbeans.modules.projectapi + + + + 1 + 1.54 + + + + org.netbeans.modules.projectuiapi + + + + 1 + 1.72 + + + + org.netbeans.modules.xml.xam + + + + 1 + 1.25.0.1 + + + + org.openide.filesystems + + + + 8.8 + + + + org.openide.util + + + + 8.33 + + + + org.openide.util.lookup + + + + 8.22 + + + + + org.netbeans.modules.maven.util + + + + Index: maven.util/src/org/netbeans/modules/maven/util/Bundle.properties --- maven.util/src/org/netbeans/modules/maven/util/Bundle.properties Base (BASE) +++ maven.util/src/org/netbeans/modules/maven/util/Bundle.properties Locally New @@ -0,0 +1 @@ +OpenIDE-Module-Name=Maven Utilities Index: maven.util/src/org/netbeans/modules/maven/util/impl/MavenCategoryProviderAnnotationProcessor.java --- maven.util/src/org/netbeans/modules/maven/util/impl/MavenCategoryProviderAnnotationProcessor.java Base (BASE) +++ maven.util/src/org/netbeans/modules/maven/util/impl/MavenCategoryProviderAnnotationProcessor.java Locally New @@ -0,0 +1,188 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 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 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.maven.util.impl; + +import java.lang.annotation.Annotation; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import static javax.lang.model.element.ElementKind.CLASS; +import static javax.lang.model.element.ElementKind.METHOD; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; +import org.netbeans.modules.maven.util.MavenCategoryProvider; +import org.netbeans.modules.maven.util.MavenCategoryProvider.Registration; +import org.openide.filesystems.annotations.LayerBuilder.File; +import org.openide.filesystems.annotations.LayerGeneratingProcessor; +import org.openide.filesystems.annotations.LayerGenerationException; +import org.openide.util.lookup.ServiceProvider; + +@ServiceProvider(service = Processor.class) +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class MavenCategoryProviderAnnotationProcessor extends LayerGeneratingProcessor { + + public @Override Set getSupportedAnnotationTypes() { + return new HashSet(Arrays.asList( + Registration.class.getCanonicalName() + )); + } + + @Override + protected boolean handleProcess(Set annotations, RoundEnvironment roundEnv) throws LayerGenerationException { + if (roundEnv.processingOver()) { + return false; + } + for (Element e : roundEnv.getElementsAnnotatedWith(Registration.class)) { + Registration r = e.getAnnotation(Registration.class); + if (r == null) { + continue; + } + handle(e, r); + } + return true; + } + + private void handle(Element e, Registration r) throws LayerGenerationException { + String path = "Projects/org-netbeans-modules-maven/Customizer"; //NOI18N + if (r.category().length() > 0) { + path += "/" + r.category(); + } + boolean addsFolder = r.categoryLabel().length() > 0; + if (addsFolder) { + handleFolder(path, e, r); + } + File f = layer(e).instanceFile(path, null, MavenCategoryProvider.class, r, null); + f.methodvalue("instanceCreate", "org.netbeans.modules.maven.util.ProxyCategoryProvider", "create"); //NOI18N + f.position(addsFolder ? 0 : r.position()); + if( r.groupId().isEmpty() ) + throw new LayerGenerationException("Must specify groupId", e, processingEnv, r); //NOI18N + f.stringvalue( "groupId", r.groupId()); + if( r.artifactId().isEmpty() ) + throw new LayerGenerationException("Must specify artifactId", e, processingEnv, r); //NOI18N + f.stringvalue( "artifactId", r.artifactId()); //NOI18N + + String[] clazzOrMethod = instantiableClassOrMethod(e, r, null); + String clazz = clazzOrMethod[0]; + String method = clazzOrMethod[1]; + if( null == method ) { + f.newvalue("categoryProvider", clazz); //NOI18N + } else { + f.methodvalue( "categoryProvider", clazz, method); //NOI18N + } + f.write(); + } + + private void handleFolder(String path, Element e, Registration r) throws LayerGenerationException { + if (r.category().length() == 0) { + throw new LayerGenerationException("Must specify category", e, processingEnv, r); //NOI18N + } + layer(e).folder(path).bundlevalue("displayName", r.categoryLabel(), r, "categoryLabel").position(r.position()).write(); //NOI18N + } + + + + private String[] instantiableClassOrMethod(Element originatingElement, Annotation annotation, String annotationMethod) throws IllegalArgumentException, LayerGenerationException { + Class type = MavenCategoryProvider.class; + if (originatingElement == null) { + throw new IllegalArgumentException("Only applicable to builders with exactly one associated element"); + } + TypeMirror typeMirror = type != null ? + processingEnv.getTypeUtils().getDeclaredType( + processingEnv.getElementUtils().getTypeElement(type.getName().replace('$', '.'))) : + null; + switch (originatingElement.getKind()) { + case CLASS: { + String clazz = processingEnv.getElementUtils().getBinaryName((TypeElement) originatingElement).toString(); + if (originatingElement.getModifiers().contains(Modifier.ABSTRACT)) { + throw new LayerGenerationException(clazz + " must not be abstract", originatingElement, processingEnv, annotation, annotationMethod); + } + { + boolean hasDefaultCtor = false; + for (ExecutableElement constructor : ElementFilter.constructorsIn(originatingElement.getEnclosedElements())) { + if (constructor.getParameters().isEmpty()) { + hasDefaultCtor = true; + break; + } + } + if (!hasDefaultCtor) { + throw new LayerGenerationException(clazz + " must have a no-argument constructor", originatingElement, processingEnv, annotation, annotationMethod); + } + } + if (typeMirror != null && !processingEnv.getTypeUtils().isAssignable(originatingElement.asType(), typeMirror)) { + throw new LayerGenerationException(clazz + " is not assignable to " + typeMirror, originatingElement, processingEnv, annotation, annotationMethod); + } + if (!originatingElement.getModifiers().contains(Modifier.PUBLIC)) { + throw new LayerGenerationException(clazz + " is not public", originatingElement, processingEnv, annotation, annotationMethod); + } + if (((TypeElement) originatingElement).getNestingKind().isNested() && !originatingElement.getModifiers().contains(Modifier.STATIC)) { + throw new LayerGenerationException(clazz + " is nested but not static", originatingElement, processingEnv, annotation, annotationMethod); + } + return new String[] {clazz, null}; + } + case METHOD: { + String clazz = processingEnv.getElementUtils().getBinaryName((TypeElement) originatingElement.getEnclosingElement()).toString(); + String method = originatingElement.getSimpleName().toString(); + if (!originatingElement.getModifiers().contains(Modifier.STATIC)) { + throw new LayerGenerationException(clazz + "." + method + " must be static", originatingElement, processingEnv, annotation, annotationMethod); + } + if (!((ExecutableElement) originatingElement).getParameters().isEmpty()) { + throw new LayerGenerationException(clazz + "." + method + " must not take arguments", originatingElement, processingEnv, annotation, annotationMethod); + } + if (typeMirror != null && !processingEnv.getTypeUtils().isAssignable(((ExecutableElement) originatingElement).getReturnType(), typeMirror)) { + throw new LayerGenerationException(clazz + "." + method + " is not assignable to " + typeMirror, originatingElement, processingEnv, annotation, annotationMethod); + } + return new String[] {clazz, method}; + } + default: + throw new LayerGenerationException("Annotated element is not loadable as an instance", originatingElement, processingEnv, annotation, annotationMethod); + } + } +} Index: maven.util/src/org/netbeans/modules/maven/util/MavenCategoryProvider.java --- maven.util/src/org/netbeans/modules/maven/util/MavenCategoryProvider.java Base (BASE) +++ maven.util/src/org/netbeans/modules/maven/util/MavenCategoryProvider.java Locally New @@ -0,0 +1,125 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 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 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.util; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.netbeans.spi.project.ui.support.ProjectCustomizer; + +/** + * Allows to register project customizer panels for Maven projects that have + * specific Maven plugins in their POM. + * + * @author S. Aubrecht + */ +public abstract class MavenCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider { + + private MavenPluginParameters pluginParameters; + + final void setPluginParameters( MavenPluginParameters params ) { + this.pluginParameters = params; + } + + /** + * Access utility methods to get/set Maven plugin parameters. + * @return Plugin parameters or null when not registered properly (without annotations). + */ + public final MavenPluginParameters getPluginParameters(){ + return pluginParameters; + } + + /** + * Used to register customizer panels for Maven projects that have specific + * plugin in their POM. + * There are three ways this annotation can be used: + *
    + *
  1. Register a "leaf" panel with no children. + * {@link #category} can be omitted for a top-level panel; + * if specified, the panel is placed in the named subcategory. + * {@link #categoryLabel} should not be specified. + * The annotation must be placed on a class or factory method implementing {@link CompositeCategoryProvider}. + *
  2. Register a category folder with no panel. + * {@link #category} must be specified; the last path component is the + * folder being defined, and any previous components are parent folders. + * {@link #categoryLabel} must be specified. + * The annotation must be placed on some package declaration (in {@code package-info.java}). + *
  3. Register a category folder also with its own panel (i.e. {@code Self}). + * {@link #category} and {@link #categoryLabel} must be specified as for #2, + * but the annotation must be on a provider implementation as for #1. + *
+ * To represent hierarchies of panels, the {@link #category} of a #1 can + * match the {@link #category} of a #2 or #3, and the {@link #category} of a #2 or #3 + * preceding the last {@code /} can match the {@link #category} of another #2 or #3. + *

Multiple registrations may be made in one place using {@link Registrations}. + */ + @Target({ElementType.TYPE, ElementType.METHOD}) + @Retention(RetentionPolicy.SOURCE) + public @interface Registration { + + /** + * Maven plugin group id that the project customizer applies to. + */ + String groupId(); + + /** + * Maven artifact id that the project customizer applies to. + */ + String artifactId(); + + /** + * Category folder (perhaps multiple components separated by {@code /}) + * in which to place this panel or which is the name of this panel folder. + */ + String category() default ""; + /** + * Display name when defining a category folder. + * Can use {@code pkg.of.Bundle#key_name} syntax. + */ + String categoryLabel() default ""; + /** + * Position of this panel or subfolder within its folder. + */ + int position() default Integer.MAX_VALUE; + } +} Index: maven.util/src/org/netbeans/modules/maven/util/MavenPluginParameters.java --- maven.util/src/org/netbeans/modules/maven/util/MavenPluginParameters.java Base (BASE) +++ maven.util/src/org/netbeans/modules/maven/util/MavenPluginParameters.java Locally New @@ -0,0 +1,166 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 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 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.util; + +import org.apache.maven.project.MavenProject; +import org.netbeans.modules.maven.api.NbMavenProject; +import org.netbeans.modules.maven.api.PluginPropertyUtils; +import org.netbeans.modules.maven.api.customizer.ModelHandle2; +import org.netbeans.modules.maven.model.ModelOperation; +import org.netbeans.modules.maven.model.pom.Build; +import org.netbeans.modules.maven.model.pom.Configuration; +import org.netbeans.modules.maven.model.pom.POMComponentFactory; +import org.netbeans.modules.maven.model.pom.POMModel; +import org.netbeans.modules.maven.model.pom.Plugin; +import org.openide.util.Lookup; + + +/** + * Convenience methods to retrieve and set plugin parameters in Maven POM. + * + * @author S. Aubrecht + */ +public final class MavenPluginParameters { + + private final Lookup lkp; + private final String groupId; + private final String artifactId; + + private MavenPluginParameters( Lookup lkp, String groupId, String artifactId ) { + this.lkp = lkp; + this.groupId = groupId; + this.artifactId = artifactId; + } + + /** + * Creates a new instance for the given group and artifact id. + * @param lkp + * @param groupId + * @param artifactId + * @return + */ + static MavenPluginParameters create( Lookup lkp, String groupId, String artifactId ) { + return new MavenPluginParameters( lkp, groupId, artifactId ); + } + + /** + * Retrieve Maven plugin version info. + * @return Version number for the given plugin or null. + */ + public String getPluginVersion() { + NbMavenProject nbMaven = lkp.lookup( NbMavenProject.class ); + + return PluginPropertyUtils.getPluginVersion( nbMaven.getMavenProject(), groupId, artifactId ); + } + + /** + * Retrieve Maven plugin configuration property. + * @param paramName Plugin parameter name. + * @param expressionProperty User property name. + * @return Parameter value or null if the parameter isn't defined. + */ + public String getParameter( String paramName, String expressionProperty ) { + NbMavenProject nbMaven = lkp.lookup( NbMavenProject.class ); + MavenProject prj = nbMaven.getMavenProject(); + return PluginPropertyUtils.getPluginProperty( prj, groupId, artifactId, paramName, null, expressionProperty ); + } + + /** + * Change/add property for the given Maven plugin. + * @param paramName Parameter name + * @param propertyValue Parameter value + */ + public void setParameter( String paramName, String propertyValue ) { + ModelHandle2 mh = lkp.lookup( ModelHandle2.class); + NbMavenProject nbMaven = lkp.lookup( NbMavenProject.class ); + mh.addPOMModification( new ParameterOperation( nbMaven, groupId, artifactId, paramName, propertyValue)); + } + + + private static class ParameterOperation implements ModelOperation { + + private final NbMavenProject nbMaven; + private final String groupId; + private final String artifactId; + private final String name; + private final String value; + + public ParameterOperation( NbMavenProject nbMaven, String groupId, String artifacId, String paramName, String paramValue ) { + this.nbMaven = nbMaven; + this.groupId = groupId; + this.artifactId = artifacId; + this.name = paramName; + this.value = paramValue; + } + + @Override + public void performOperation( POMModel model ) { + //new approach, assume all plugins conform to the new setting. + POMComponentFactory fact = model.getFactory(); + + //check if compiler/resources plugins are configured and update them to ${project.source.encoding expression + Build bld = model.getProject().getBuild(); + if( bld == null ) { + bld = fact.createBuild(); + model.getProject().setBuild( bld ); + return; + } + + Plugin plugin = bld.findPluginById( groupId, artifactId ); + if( plugin == null ) { + plugin = fact.createPlugin(); + plugin.setArtifactId( artifactId ); + plugin.setGroupId( groupId ); + plugin.setVersion( PluginPropertyUtils.getPluginVersion( nbMaven.getMavenProject(), groupId, artifactId ) ); + bld.addPlugin( plugin ); + } + Configuration conf = plugin.getConfiguration(); + if( conf == null ) { + conf = fact.createConfiguration(); + plugin.setConfiguration( conf ); + } + if( conf != null ) { + conf.setSimpleParameter( name, value ); + } + } + }; +} Index: maven.util/src/org/netbeans/modules/maven/util/ProxyCategoryProvider.java --- maven.util/src/org/netbeans/modules/maven/util/ProxyCategoryProvider.java Base (ProjectCustomizerImpl.java) +++ maven.util/src/org/netbeans/modules/maven/util/ProxyCategoryProvider.java Locally Copied @@ -39,46 +39,55 @@ * * Portions Copyrighted 2013 Sun Microsystems, Inc. */ -package org.netbeans.modules.deploy.ios.customizer; +package org.netbeans.modules.maven.util; +import java.util.HashMap; +import java.util.Map; import javax.swing.JComponent; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.netbeans.api.project.Project; import org.netbeans.modules.maven.api.NbMavenProject; import org.netbeans.modules.maven.api.PluginPropertyUtils; import org.openide.util.Lookup; -import org.openide.util.NbBundle; /** + * Category provider that delegates to a different category provider - if the Maven + * project POM contains the desired plugin. * * @author S. Aubrecht */ -@ProjectCustomizer.CompositeCategoryProvider.Registration( -projectType = "org-netbeans-modules-maven", position = 450) -public class ProjectCustomizerImpl implements ProjectCustomizer.CompositeCategoryProvider { +final class ProxyCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider { - private static final String CAT_IPHONE = "deploy-ios-iphone"; //NOI18N - private static final String CAT_IPAD = "deploy-ios-ipad"; //NOI18N - private static final String CAT_IOS = "deploy-ios"; //NOI18N + private final Map args; + private MavenCategoryProvider theProvider; + public ProxyCategoryProvider() { + this( new HashMap(0) ); + } + + private ProxyCategoryProvider( Map args ) { + this.args = args; + } + + static ProjectCustomizer.CompositeCategoryProvider create( Map args ) { + return new ProxyCategoryProvider( args ); + } + @Override public ProjectCustomizer.Category createCategory( Lookup lkp ) { if( isSupportedProject( lkp ) ) { - ProjectCustomizer.Category catIPhone = ProjectCustomizer.Category.create( CAT_IPHONE, NbBundle.getMessage(ProjectCustomizerImpl.class, "Cat_Iphone"), null, null ); - ProjectCustomizer.Category catIPad = ProjectCustomizer.Category.create( CAT_IPAD, NbBundle.getMessage(ProjectCustomizerImpl.class, "Cat_IPAD"), null, null ); - return ProjectCustomizer.Category.create( CAT_IOS, NbBundle.getMessage(ProjectCustomizerImpl.class, "Cat_IOS"), null, new ProjectCustomizer.Category[] { catIPhone, catIPad } ); + createProvider( lkp ); + if( null != theProvider ) { + return theProvider.createCategory( lkp ); } + } return null; } @Override public JComponent createComponent( ProjectCustomizer.Category ctgr, Lookup lkp ) { - if( CAT_IOS.equals( ctgr.getName() ) ) { - return new IOSMainCustomizer(ctgr, lkp); - } else if( CAT_IPHONE.equals( ctgr.getName() ) ) { - return new IPhoneCustomizer(ctgr, lkp); - } else if( CAT_IPAD.equals( ctgr.getName() ) ) { - return new IPadCustomizer(ctgr, lkp); + if( null != theProvider ) { + return theProvider.createComponent( ctgr, lkp ); } return null; } @@ -86,9 +95,27 @@ private boolean isSupportedProject( Lookup lkp ) { Project prj = lkp.lookup( Project.class ); NbMavenProject nbMaven = prj.getLookup().lookup( NbMavenProject.class ); + if( null == nbMaven ) + return false; + String groupId = getGroupId(); + String artifactId = getArtifactId(); + if( null == groupId || null == artifactId ) + return false; + return null != PluginPropertyUtils.getPluginVersion( nbMaven.getMavenProject(), groupId, artifactId ); + } - return null != PluginPropertyUtils.getPluginVersion( nbMaven.getMavenProject(), - AbstractCustomizerPanel.MAVEN_GROUP_ID, - AbstractCustomizerPanel.MAVEN_ARTIFACT_ID ); + private void createProvider( Lookup lkp ) { + if( null == theProvider ) { + theProvider = ( MavenCategoryProvider) args.get( "categoryProvider" ); + theProvider.setPluginParameters( MavenPluginParameters.create( lkp, getGroupId(), getArtifactId())); } } + + private String getGroupId() { + return (String) args.get( "groupId" ); //NOI18N + } + + private String getArtifactId() { + return (String) args.get( "artifactId" ); //NOI18N + } +}