# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /Users/mkleint/src/core-main # 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/manifest.mf --- maven/manifest.mf Base (BASE) +++ maven/manifest.mf Locally Modified (Based On LOCAL) @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.maven/2 -OpenIDE-Module-Specification-Version: 2.72 +OpenIDE-Module-Specification-Version: 2.73 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/maven/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/maven/layer.xml AutoUpdate-Show-In-Client: false Index: maven/nbproject/project.xml --- maven/nbproject/project.xml Base (BASE) +++ maven/nbproject/project.xml Locally Modified (Based On LOCAL) @@ -223,7 +223,7 @@ 1 - 1.23 + 1.53 Index: maven/src/org/netbeans/modules/maven/api/customizer/ModelHandle2.java --- maven/src/org/netbeans/modules/maven/api/customizer/ModelHandle2.java Base (BASE) +++ maven/src/org/netbeans/modules/maven/api/customizer/ModelHandle2.java Locally Modified (Based On LOCAL) @@ -81,6 +81,7 @@ public static final String PANEL_LIBRARIES = "LIBRARIES"; //NOI18N public static final String PANEL_SOURCES = "SOURCES"; //NOI18N public static final String PANEL_COMPILE = "COMPILE"; //NOI18N + public static final String PANEL_HEADERS = "LICENSE_HEADERS"; //NOI18N private final MavenProjectPropsImpl auxiliaryProps; Index: maven/src/org/netbeans/modules/maven/customizer/LicenseHeaderPanelProvider.java --- maven/src/org/netbeans/modules/maven/customizer/LicenseHeaderPanelProvider.java Base (BasicPanelProvider.java) +++ maven/src/org/netbeans/modules/maven/customizer/LicenseHeaderPanelProvider.java Locally Copied @@ -39,30 +39,45 @@ * * Portions Copyrighted 2008 Sun Microsystems, Inc. */ - package org.netbeans.modules.maven.customizer; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; import javax.swing.JComponent; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.netbeans.api.project.Project; +import org.netbeans.modules.maven.api.Constants; +import org.netbeans.modules.maven.api.FileUtilities; +import org.netbeans.modules.maven.api.PluginPropertyUtils; import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; import org.openide.util.Lookup; import static org.netbeans.modules.maven.customizer.Bundle.*; +import org.netbeans.modules.maven.model.ModelOperation; +import org.netbeans.modules.maven.model.pom.POMModel; +import org.netbeans.spi.project.AuxiliaryProperties; +import org.netbeans.spi.project.support.ant.ui.CustomizerUtilities; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; import org.openide.util.NbBundle.Messages; /** * * @author Milos Kleint */ -@ProjectCustomizer.CompositeCategoryProvider.Registration(projectType="org-netbeans-modules-maven", position=100) -public class BasicPanelProvider implements ProjectCustomizer.CompositeCategoryProvider { +@ProjectCustomizer.CompositeCategoryProvider.Registration(projectType = "org-netbeans-modules-maven", position = 620) +public class LicenseHeaderPanelProvider implements ProjectCustomizer.CompositeCategoryProvider { @Override - @Messages("TIT_Basic=General") + @Messages("TIT_Headers=License Headers") public Category createCategory(Lookup context) { return ProjectCustomizer.Category.create( - ModelHandle2.PANEL_BASIC, - TIT_Basic(), + ModelHandle2.PANEL_HEADERS, + TIT_Headers(), null); } @@ -70,7 +85,102 @@ public JComponent createComponent(Category category, Lookup context) { ModelHandle2 handle = context.lookup(ModelHandle2.class); Project prj = context.lookup(Project.class); - return new BasicInfoPanel(handle, category, prj); + return CustomizerUtilities.createLicenseHeaderCustomizerPanel(category, new Impl(handle, prj, prj.getLookup().lookup(AuxiliaryProperties.class))); } + private final class Impl implements CustomizerUtilities.LicensePanelContentHandler { + + final ModelHandle2 handle; + final AuxiliaryProperties props; + private final Project project; + private final ModelOperation operation; + private String licenseContent; + private String licensePath; + + public Impl(final ModelHandle2 handle, Project prj, AuxiliaryProperties props) { + this.handle = handle; + this.props = props; + this.project = prj; + operation = new ModelOperation() { + @Override + public void performOperation(POMModel model) { + if (licenseContent == null) { + return; } + try { + String eval = PluginPropertyUtils.createEvaluator(project).evaluate(licensePath).toString(); + + File file = FileUtilities.resolveFilePath(handle.getProject().getBasedir(), eval); + FileObject fo; + if (!file.exists()) { + fo = FileUtil.createData(file); + } else { + fo = FileUtil.toFileObject(file); + } + OutputStream out = fo.getOutputStream(); + try { + FileUtil.copy(new ByteArrayInputStream(licenseContent.getBytes()), out); + } finally { + out.close(); + } + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } catch (ExpressionEvaluationException ex) { + Exceptions.printStackTrace(ex); + } + } + }; + licensePath = getProjectLicenseLocation(); + } + + @Override + public String getProjectLicenseLocation() { + return props.get(Constants.HINT_LICENSE_PATH, true); + } + + @Override + public String getGlobalLicenseName() { + return props.get(Constants.HINT_LICENSE, true); + } + + @Override + public FileObject resolveProjectLocation(String path) { + try { + String eval = PluginPropertyUtils.createEvaluator(project).evaluate(path).toString(); + return FileUtil.toFileObject(FileUtilities.resolveFilePath(handle.getProject().getBasedir(), eval)); + } catch (ExpressionEvaluationException ex) { + Exceptions.printStackTrace(ex); + } + return null; + } + + @Override + public void setProjectLicenseLocation(String newLocation) { + licensePath = newLocation; + handle.setRawAuxiliaryProperty(Constants.HINT_LICENSE_PATH, newLocation, true); + } + + @Override + public void setGlobalLicenseName(String newName) { + handle.setRawAuxiliaryProperty(Constants.HINT_LICENSE, newName, true); + } + + @Override + public String getDefaultProjectLicenseLocation() { + return "${project.basedir}/licenseheader.txt"; + } + + @Override + public void setProjectLicenseContent(String text) { + //TODO a fake model operation that is only meant to provide us with way to save + // the license file at the end of the customizer. + if (text == null) { + handle.removePOMModification(operation); + licenseContent = null; + } else { + handle.addPOMModification(operation); + licenseContent = text; + } + } + } +}