--- java.j2seproject/nbproject/project.properties +++ java.j2seproject/nbproject/project.properties @@ -42,7 +42,7 @@ javac.compilerargs=-Xlint -Xlint:-serial javac.source=1.6 -spec.version.base=1.58.0 +spec.version.base=1.59.0 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml --- java.j2seproject/nbproject/project.xml +++ java.j2seproject/nbproject/project.xml @@ -185,7 +185,7 @@ 1 - 1.33 + 1.53 --- java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SECompositePanelProvider.java +++ java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SECompositePanelProvider.java @@ -47,10 +47,14 @@ import java.util.ResourceBundle; import javax.swing.JComponent; import javax.swing.JPanel; +import javax.swing.text.BadLocationException; import org.netbeans.api.project.Project; import org.netbeans.modules.java.j2seproject.J2SEProject; import org.netbeans.modules.java.j2seproject.J2SEProjectUtil; +import org.netbeans.spi.project.support.ant.ui.CustomizerUtilities; import org.netbeans.spi.project.ui.support.ProjectCustomizer; +import org.openide.filesystems.FileObject; +import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.NbBundle; @@ -68,6 +72,7 @@ private static final String JAVADOC = "Javadoc"; public static final String RUN = "Run"; private static final String APPLICATION = "Application"; + private static final String LICENSE = "License"; private String name; @@ -75,6 +80,7 @@ this.name = name; } + @Override public ProjectCustomizer.Category createCategory(Lookup context) { ResourceBundle bundle = NbBundle.getBundle( CustomizerProviderImpl.class ); ProjectCustomizer.Category toReturn = null; @@ -103,6 +109,11 @@ JAVADOC, bundle.getString( "LBL_Config_Javadoc" ), // NOI18N null); + } else if (LICENSE.equals(name)) { + toReturn = ProjectCustomizer.Category.create( + LICENSE, + "License Headers", // NOI18N + null); } else if (RUN.equals(name)) { boolean fxOverride = false; final Project project = context.lookup(Project.class); @@ -123,9 +134,10 @@ return toReturn; } - public JComponent createComponent(ProjectCustomizer.Category category, Lookup context) { + @Override + public JComponent createComponent(ProjectCustomizer.Category category, final Lookup context) { String nm = category.getName(); - J2SEProjectProperties uiProps = context.lookup(J2SEProjectProperties.class); + final J2SEProjectProperties uiProps = context.lookup(J2SEProjectProperties.class); if (SOURCES.equals(nm)) { return new CustomizerSources(uiProps); } else if (LIBRARIES.equals(nm)) { @@ -142,7 +154,77 @@ return new CustomizerRun(uiProps); } else if (APPLICATION.equals(nm)) { return new CustomizerApplication(uiProps); + } else if (LICENSE.equals(nm)) { + CustomizerUtilities.LicensePanelContentHandler handler = + new CustomizerUtilities.LicensePanelContentHandler() { + @Override + public String getProjectLicenseLocation() { + try { + String path = uiProps.LICENSE_PATH_DOC.getText(0, uiProps.LICENSE_PATH_DOC.getLength()); + if (path != null && path.trim().isEmpty()) { + path = null; } + return path; + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + return null; + } + + @Override + public String getGlobalLicenseName() { + try { + String name = uiProps.LICENSE_NAME_DOC.getText(0, uiProps.LICENSE_NAME_DOC.getLength()); + if (name != null && name.trim().isEmpty()) { + name = null; + } + return name; + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + return null; + } + + @Override + public FileObject resolveProjectLocation(String path) { + final J2SEProject project = context.lookup(J2SEProject.class); + String evaluated = uiProps.getEvaluator().evaluate(path); + return project.getAntProjectHelper().resolveFileObject(evaluated); + } + + @Override + public void setProjectLicenseLocation(String newLocation) { + try { + uiProps.LICENSE_PATH_DOC.remove(0, uiProps.LICENSE_PATH_DOC.getLength()); + uiProps.LICENSE_PATH_DOC.insertString(0, newLocation, null); + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + } + + @Override + public void setGlobalLicenseName(String newName) { + try { + uiProps.LICENSE_NAME_DOC.remove(0, uiProps.LICENSE_NAME_DOC.getLength()); + uiProps.LICENSE_NAME_DOC.insertString(0, newName, null); + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + } + + @Override + public String getDefaultProjectLicenseLocation() { + return "./nbproject/licenseheader.txt"; + } + + @Override + public void setProjectLicenseContent(String text) { + uiProps.CHANGED_LICENSE_PATH_CONTENT = text; + } + }; + + return CustomizerUtilities.createLicenseHeaderCustomizerPanel(category, handler); + } return new JPanel(); } @@ -207,4 +289,13 @@ public static J2SECompositePanelProvider createApplication() { return new J2SECompositePanelProvider(APPLICATION); } + + @ProjectCustomizer.CompositeCategoryProvider.Registration( + projectType="org-netbeans-modules-java-j2seproject", + position=600 + ) + public static J2SECompositePanelProvider createLicense() { + return new J2SECompositePanelProvider(LICENSE); } + +} --- java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java +++ java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java @@ -45,8 +45,11 @@ package org.netbeans.modules.java.j2seproject.ui.customizer; import java.awt.event.ActionListener; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; +import java.io.OutputStream; +import java.io.StringReader; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; @@ -176,6 +179,9 @@ public static final String APPLICATION_HOMEPAGE ="application.homepage"; // NOI18N public static final String APPLICATION_SPLASH ="application.splash"; // NOI18N + public static final String LICENSE_NAME = "project.license"; + public static final String LICENSE_PATH = "project.licensePath"; + // Properties stored in the PRIVATE.PROPERTIES public static final String JAVADOC_PREVIEW="javadoc.preview"; // NOI18N // Main build.xml location @@ -254,6 +260,11 @@ Document APPLICATION_HOMEPAGE_DOC; Document APPLICATION_SPLASH_DOC; + //customizer license headers + Document LICENSE_PATH_DOC; + Document LICENSE_NAME_DOC; + String CHANGED_LICENSE_PATH_CONTENT; + // CustomizerRunTest // Private fields ---------------------------------------------------------- @@ -292,6 +303,12 @@ init(); // Load known properties } + + public PropertyEvaluator getEvaluator() { + return evaluator; + } + + /** Initializes the visual models */ private void init() { @@ -428,6 +445,20 @@ APPLICATION_HOMEPAGE_DOC = projectGroup.createStringDocument(evaluator, APPLICATION_HOMEPAGE); APPLICATION_SPLASH_DOC = projectGroup.createStringDocument(evaluator, APPLICATION_SPLASH); + LICENSE_NAME_DOC = projectGroup.createStringDocument(evaluator, LICENSE_NAME); + LICENSE_PATH_DOC = projectGroup.createStringDocument(evaluator, LICENSE_PATH); + //oh well we want unresolved value, force it. + String p = projectProperties.get(LICENSE_PATH); + try { + //we want to show the unresolved value.. + LICENSE_PATH_DOC.remove(0, LICENSE_PATH_DOC.getLength()); + LICENSE_PATH_DOC.insertString(0, p, null); + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + + CHANGED_LICENSE_PATH_CONTENT = null; + if(!isFXProject()) { // CustomizerRun RUN_CONFIGS = readRunConfigs(); @@ -439,6 +470,27 @@ public void save() { try { saveLibrariesLocation(); + if (CHANGED_LICENSE_PATH_CONTENT != null) { + try { + String path = LICENSE_PATH_DOC.getText(0, LICENSE_PATH_DOC.getLength()); + String evaluated = getEvaluator().evaluate(path); + File file = project.getAntProjectHelper().resolveFile(evaluated); + FileObject fo; + if (!file.exists()) { + fo = FileUtil.createData(file); + } else { + fo = FileUtil.toFileObject(file); + } + OutputStream out = fo.getOutputStream(); + try { + FileUtil.copy(new ByteArrayInputStream(CHANGED_LICENSE_PATH_CONTENT.getBytes()), out); + } finally { + out.close(); + } + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + } // Store properties ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { public Void run() throws IOException {