# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: F:\Sources\Release55\core\startup # 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: src/org/netbeans/core/startup/Splash.java *** F:\Sources\Release55\core\startup\src\org\netbeans\core\startup\Splash.java Base (1.2.16.2) --- F:\Sources\Release55\core\startup\src\org\netbeans\core\startup\Splash.java Locally Modified (Based On 1.2.16.2) *************** *** 23,28 **** --- 23,30 ---- import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; + import java.awt.GridBagConstraints; + import java.awt.GridBagLayout; import java.awt.Image; import java.awt.Rectangle; import java.awt.RenderingHints; *************** *** 31,39 **** --- 33,48 ---- import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; + import java.io.BufferedReader; + import java.io.FileNotFoundException; + import java.io.IOException; + import java.io.InputStream; + import java.io.InputStreamReader; + import java.io.StringWriter; import java.lang.ref.Reference; import java.lang.ref.WeakReference; import java.net.URL; + import java.text.MessageFormat; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; *************** *** 43,56 **** --- 52,72 ---- import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JPanel; + import javax.swing.JScrollPane; import javax.swing.JTabbedPane; + import javax.swing.JTextArea; import javax.swing.KeyStroke; + import javax.swing.ScrollPaneConstants; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; + import javax.swing.border.EmptyBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openide.ErrorManager; + import org.openide.filesystems.FileObject; + import org.openide.filesystems.FileSystem; + import org.openide.filesystems.Repository; import org.openide.util.Utilities; import org.openide.util.NbBundle; *************** *** 182,187 **** --- 198,298 ---- } } + /** Utility method; loads license text from About/License folder on default + * file system and feeds it into resulting text area. + * + * @return Text area containing loaded license text or null if no license + * file was found or some kind of other I/O error happenned. + */ + /* package private for tests */ static JComponent getLicenseComp () { + FileSystem fs = Repository.getDefault().getDefaultFileSystem(); + FileObject licenseFolder = fs.findResource("About/Licenses"); + if (licenseFolder == null) { + return null; + } + + FileObject[] foArray = licenseFolder.getChildren(); + if (foArray.length <= 0) { + return null; + } + + String curLicense; + boolean isSomeLicense = false; + StringWriter sw = new StringWriter(); + for (int i = 0; i < foArray.length; i++) { + curLicense = loadLicenseText(foArray[i]); + if (curLicense != null) { + sw.write(curLicense); + isSomeLicense = true; + } + // new line between multiple licenses + if (i < foArray.length - 1) { + sw.append("\n"); //NOI18N + } + } + + if (!isSomeLicense) { + return null; + } + + JTextArea ta = new JTextArea(sw.toString(), 4, 0); + ta.setBorder(new EmptyBorder(5, 12, 0, 12)); + ta.setEditable(false); + ta.setOpaque(false); + ta.setWrapStyleWord(true); + + JScrollPane sp = new JScrollPane(ta); + sp.setBorder(null); + + return sp; + } + + /** Tries to load text stored in given file object. + * + * @param fo File object to retrieve text from + * @return String containing text from the file, or null if file can't be found + * or some kind of I/O error appeared. + */ + private static String loadLicenseText (FileObject fo) { + InputStream is = null; + try { + is = fo.getInputStream(); + } catch (FileNotFoundException ex) { + // warning if license file not found + String msg = MessageFormat.format( + NbBundle.getBundle(Splash.class).getString("EXC_LicenseFileNotFound"), + new Object[] { fo.getPath() } + ); + ErrorManager em = ErrorManager.getDefault(); + em.annotate(ex, msg); + em.notify(ErrorManager.WARNING, ex); + return null; + } + + BufferedReader in = new BufferedReader(new InputStreamReader(is)); + StringWriter result = new StringWriter(); + int curChar; + try { + // reading content of license file + while ((curChar = in.read()) != -1) { + result.write(curChar); + } + } catch (IOException ex) { + // don't return anything if any problem during read + String msg = MessageFormat.format( + NbBundle.getBundle(Splash.class).getString("EXC_LicenseReadBroken"), + new Object[] { fo.getPath() } + ); + ErrorManager em = ErrorManager.getDefault(); + em.annotate(ex, msg); + em.notify(ErrorManager.WARNING, ex); + return null; + } + + return result.toString(); + } + + /** * This class implements double-buffered splash screen component. */ *************** *** 460,469 **** --- 571,585 ---- return new Dimension(image.getWidth (null), image.getHeight (null)); } + public Dimension getMinimumSize() { + return getPreferredSize(); + } + public boolean isOpaque () { return true; } + } private static class AboutComponent extends SplashComponent { *************** *** 562,573 **** public SplashDialog (java.awt.Frame parent, javax.swing.JComponent infoPanel) { super (parent, true); - JPanel splashPanel = new JPanel(); JTabbedPane tabbedPane = new JTabbedPane(); setTitle (NbBundle.getMessage(Splash.class, "CTL_About_Title")); ! // add splash component ! splashPanel.add (splashComponent); ! tabbedPane.addTab(NbBundle.getMessage(Splash.class, "CTL_About_Title"), splashPanel); tabbedPane.addTab(NbBundle.getMessage(Splash.class, "CTL_About_Detail"), infoPanel); getContentPane().add(tabbedPane, BorderLayout.CENTER); --- 678,686 ---- public SplashDialog (java.awt.Frame parent, javax.swing.JComponent infoPanel) { super (parent, true); JTabbedPane tabbedPane = new JTabbedPane(); setTitle (NbBundle.getMessage(Splash.class, "CTL_About_Title")); ! tabbedPane.addTab(NbBundle.getMessage(Splash.class, "CTL_About_Title"), getSplashPanel()); tabbedPane.addTab(NbBundle.getMessage(Splash.class, "CTL_About_Detail"), infoPanel); getContentPane().add(tabbedPane, BorderLayout.CENTER); *************** *** 586,591 **** --- 699,728 ---- setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); } + /** Configures and returns content of first tab - splash panel, with + * possible license info if present. + * + * @return Component representing splash panel. + */ + private JComponent getSplashPanel () { + JPanel splashPanel = new JPanel(new GridBagLayout()); + splashPanel.add(splashComponent, new GridBagConstraints()); + + JComponent licenseComp = Splash.getLicenseComp(); + if (licenseComp != null) { + GridBagConstraints gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.weighty = 1.0; + splashPanel.add(licenseComp, gridBagConstraints); + } + + return splashPanel; + } + + /** * Prints the given progress message on the splash screen. * @param x specifies a string that is to be displayed Index: src/org/netbeans/core/startup/Bundle.properties *** F:\Sources\Release55\core\startup\src\org\netbeans\core\startup\Bundle.properties Base (1.7.2.1) --- F:\Sources\Release55\core\startup\src\org\netbeans\core\startup\Bundle.properties Locally Modified (Based On 1.7.2.1) *************** *** 179,181 **** --- 179,184 ---- This property cannot be changed while the IDE is running, so this attempt had no effect. # {0} - JAR file name TEXT_patch=Module patch or custom extension: {0} + + EXC_LicenseReadBroken=Error during reading of license file {0}. + EXC_LicenseFileNotFound=License file {0} can't be found. Index: test/unit/src/org/netbeans/core/startup/SplashTest.java *** F:\Sources\Release55\core\startup\test\unit\src\org\netbeans\core\startup\SplashTest.java No Base Revision --- F:\Sources\Release55\core\startup\test\unit\src\org\netbeans\core\startup\SplashTest.java Locally New *************** *** 1,0 **** --- 1,60 ---- + /* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.netbeans.core.startup; + + import java.beans.PropertyVetoException; + import java.io.IOException; + import java.net.URL; + import javax.swing.JComponent; + import javax.swing.JTextArea; + import javax.swing.text.Utilities; + import junit.framework.Assert; + import org.netbeans.junit.NbTestCase; + import org.openide.filesystems.Repository; + import org.openide.filesystems.XMLFileSystem; + import org.openide.util.Lookup; + import org.openide.util.lookup.Lookups; + import org.openide.util.lookup.ProxyLookup; + import org.xml.sax.SAXException; + + /** Simple test of correct loading of license files from About/Licenses folder. + * + * @author Dafe Simonek + */ + public class SplashTest extends NbTestCase { + + public SplashTest(String testName) {\ + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + public void testGetLicenseComp () throws Exception { + UnitTestUtils.prepareTest(new String [] { "/org/netbeans/core/startup/data/testGetLicenseCompLayer.xml" }); + + System.out.println("Testing loading and concatenating of multiple license files..."); + JTextArea comp = Splash.getLicenseComp(); + assertNotNull(comp); + + String text = comp.getText(); + assertTrue(text.indexOf("first license text") != -1); + assertTrue(text.indexOf("second license text") != -1); + } + + + } Index: test/unit/src/org/netbeans/core/startup/data/testGetLicenseCompLayer.xml *** F:\Sources\Release55\core\startup\test\unit\src\org\netbeans\core\startup\data\testGetLicenseCompLayer.xml No Base Revision --- F:\Sources\Release55\core\startup\test\unit\src\org\netbeans\core\startup\data\testGetLicenseCompLayer.xml Locally New *************** *** 1,0 **** --- 1,11 ---- + + + + + + + + + + + Index: test/unit/src/org/netbeans/core/startup/UnitTestUtils.java *** F:\Sources\Release55\core\startup\test\unit\src\org\netbeans\core\startup\UnitTestUtils.java No Base Revision --- F:\Sources\Release55\core\startup\test\unit\src\org\netbeans\core\startup\UnitTestUtils.java Locally New *************** *** 1,0 **** --- 1,106 ---- + /* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.netbeans.core.startup; + + import java.beans.PropertyVetoException; + import java.io.File; + import java.io.IOException; + import java.net.URL; + import javax.swing.text.Utilities; + import junit.framework.Assert; + import org.netbeans.junit.NbTestCase; + import org.openide.filesystems.FileObject; + import org.openide.filesystems.FileUtil; + import org.openide.filesystems.LocalFileSystem; + import org.openide.filesystems.Repository; + import org.openide.filesystems.XMLFileSystem; + import org.openide.util.Lookup; + import org.openide.util.lookup.Lookups; + import org.openide.util.lookup.ProxyLookup; + import org.xml.sax.SAXException; + + /** + * Allows tests to install own layers for testing. + * Copied from org.netbeans.api.project.TestUtil. + * + * @author Dafe Simonek + */ + public class UnitTestUtils extends ProxyLookup { + + public static UnitTestUtils DEFAULT_LOOKUP = null; + + /** Creates a new instance of UnitTestUtils */ + public UnitTestUtils() { + Assert.assertNull(DEFAULT_LOOKUP); + DEFAULT_LOOKUP = this; + } + + /** Makes global layer from given string resource info */ + public static void prepareTest(String[] stringLayers) + throws IOException, SAXException, PropertyVetoException { + prepareTest(stringLayers, null); + } + + public static void prepareTest (String[] stringLayers, Lookup lkp) + throws IOException, SAXException, PropertyVetoException { + URL[] layers = new URL[stringLayers.length]; + + for (int cntr = 0; cntr < layers.length; cntr++) { + layers[cntr] = Utilities.class.getResource(stringLayers[cntr]); + } + + XMLFileSystem system = new XMLFileSystem(); + system.setXmlUrls(layers); + + Repository repository = new Repository(system); + + if (lkp == null) { + DEFAULT_LOOKUP.setLookup(new Object[] { repository }, UnitTestUtils.class.getClassLoader()); + } else { + DEFAULT_LOOKUP.setLookup(new Object[] { repository }, lkp, UnitTestUtils.class.getClassLoader()); + } + } + + /** + * Set the global default lookup with some fixed instances including META-INF/services/*. + */ + private static void setLookup(Object[] instances, ClassLoader cl) { + DEFAULT_LOOKUP.setLookups(new Lookup[] { + Lookups.fixed(instances), + Lookups.metaInfServices(cl), + Lookups.singleton(cl), + }); + } + + private static void setLookup(Object[] instances, Lookup lkp, ClassLoader cl) { + DEFAULT_LOOKUP.setLookups(new Lookup[] { + lkp, + Lookups.fixed(instances), + Lookups.metaInfServices(cl), + Lookups.singleton(cl), + }); + } + + + static { + UnitTestUtils.class.getClassLoader().setDefaultAssertionStatus(true); + System.setProperty("org.openide.util.Lookup", UnitTestUtils.class.getName()); + Assert.assertEquals(UnitTestUtils.class, Lookup.getDefault().getClass()); + } + + public static void initLookup() { + //currently nothing. + } + + } Index: test/unit/src/org/netbeans/core/startup/data/license1.txt *** F:\Sources\Release55\core\startup\test\unit\src\org\netbeans\core\startup\data\license1.txt No Base Revision --- F:\Sources\Release55\core\startup\test\unit\src\org\netbeans\core\startup\data\license1.txt Locally New *************** *** 1,0 **** --- 1,1 ---- + first license text. Index: test/unit/src/org/netbeans/core/startup/data/license2.txt *** F:\Sources\Release55\core\startup\test\unit\src\org\netbeans\core\startup\data\license2.txt No Base Revision --- F:\Sources\Release55\core\startup\test\unit\src\org\netbeans\core\startup\data\license2.txt Locally New *************** *** 1,0 **** --- 1,1 ---- + second license text.