This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 225895
Collapse All | Expand All

(-)a/o.n.bootstrap/arch.xml (+9 lines)
Lines 586-591 Link Here
586
                </api>
586
                </api>
587
            </li>
587
            </li>
588
            <li>
588
            <li>
589
                <api type="export" group="systemproperty" name="org.netbeans.CLIHandler.server" category="devel">
590
                    <p>
591
                        One can disable the CLI server (listening on commands
592
                        from subsequent invocations) by setting property
593
                        <code>org.netbeans.CLIHandler.server</code> to <code>false</code>.
594
                    </p>
595
                </api>
596
            </li>
597
            <li>
589
                <api type="export" group="systemproperty" name="org.netbeans.core.systemfilesystem.custom" category="friend">
598
                <api type="export" group="systemproperty" name="org.netbeans.core.systemfilesystem.custom" category="friend">
590
                    <p>
599
                    <p>
591
                        Contains class name of a class that can serve as provider of the writable layer of the
600
                        Contains class name of a class that can serve as provider of the writable layer of the
(-)a/o.n.bootstrap/src/org/netbeans/Bundle.properties (+2 lines)
Lines 55-60 Link Here
55
\n\
55
\n\
56
Click OK to continue in spite of previous error.
56
Click OK to continue in spite of previous error.
57
MSG_CannotWriteTitle=Warning
57
MSG_CannotWriteTitle=Warning
58
MSG_AlreadyRunning=The application is already running.
59
MSG_AlreadyRunningTitle=Warning
58
60
59
EXC_not_a_module={0} is not a valid NetBeans module.
61
EXC_not_a_module={0} is not a valid NetBeans module.
60
62
(-)a/o.n.bootstrap/src/org/netbeans/CLIHandler.java (-59 / +74 lines)
Lines 282-287 Link Here
282
    static final class Status {
282
    static final class Status {
283
        public static final int CANNOT_CONNECT = -255;
283
        public static final int CANNOT_CONNECT = -255;
284
        public static final int CANNOT_WRITE = -254;
284
        public static final int CANNOT_WRITE = -254;
285
        public static final int ALREADY_RUNNING = -253;
285
        
286
        
286
        private final File lockFile;
287
        private final File lockFile;
287
        private final int port;
288
        private final int port;
Lines 608-684 Link Here
608
                
609
                
609
                final RandomAccessFile os = raf;
610
                final RandomAccessFile os = raf;
610
                raf.seek(0L);
611
                raf.seek(0L);
611
                
612
612
                server = new Server(new FileAndLock(os, lock), arr, block, handlers, failOnUnknownOptions);
613
                int p;
613
                int p = server.getLocalPort();
614
                if ("false".equals(System.getProperty("org.netbeans.CLIHandler.server"))) { // NOI18N
615
                    server = null;
616
                    p = 0;
617
                } else {
618
                    server = new Server(new FileAndLock(os, lock), arr, block, handlers, failOnUnknownOptions);
619
                    p = server.getLocalPort();
620
                }
614
                os.writeInt(p);
621
                os.writeInt(p);
615
                os.getChannel().force(true);
622
                os.getChannel().force(true);
616
                
623
                
617
                enterState(20, block);
624
                enterState(20, block);
618
                
625
                
619
                Task parael = secureCLIPort.post(new Runnable() { // NOI18N
626
                Task parael;
620
                    @Override
627
                if (server != null) {
621
                    public void run() {
628
                    parael = secureCLIPort.post(new Runnable() { // NOI18N
622
                        SecureRandom random = null;
629
                        @Override
623
                        enterState(95, block);
630
                        public void run() {
624
                        try {
631
                            SecureRandom random = null;
625
                            random = SecureRandom.getInstance("SHA1PRNG"); // NOI18N
632
                            enterState(95, block);
626
                        } catch (NoSuchAlgorithmException e) {
627
                            // #36966: IBM JDK doesn't have it.
628
                            try {
633
                            try {
629
                                random = SecureRandom.getInstance("IBMSecureRandom"); // NOI18N
634
                                random = SecureRandom.getInstance("SHA1PRNG"); // NOI18N
630
                            } catch (NoSuchAlgorithmException e2) {
635
                            } catch (NoSuchAlgorithmException e) {
631
                                // OK, disable server...
636
                                // #36966: IBM JDK doesn't have it.
632
                                server.stopServer();
637
                                try {
638
                                    random = SecureRandom.getInstance("IBMSecureRandom"); // NOI18N
639
                                } catch (NoSuchAlgorithmException e2) {
640
                                    // OK, disable server...
641
                                    server.stopServer();
642
                                }
643
                            }
644
645
                            enterState(96, block);
646
647
                            if (random != null) {
648
                                random.nextBytes(arr);
649
                            }
650
651
                            enterState(97, block);
652
653
                            try {
654
                                os.write(arr);
655
                                os.getChannel().force(true);
656
657
                                enterState(27,block);
658
                                // if this turns to be slow due to lookup of getLocalHost
659
                                // address, it can be done asynchronously as nobody needs
660
                                // the address in the stream if the server is listening
661
                                byte[] host;
662
                                try {
663
                                    if (block != null && block.intValue() == 667) {
664
                                        // this is here to emulate #64004
665
                                        throw new UnknownHostException("dhcppc0"); // NOI18N
666
                                    }
667
                                    host = InetAddress.getLocalHost().getAddress();
668
                                } catch (UnknownHostException unknownHost) {
669
                                    if (!"dhcppc0".equals(unknownHost.getMessage())) { // NOI18N, see above
670
                                        // if we just cannot get the address, we can go on
671
                                        unknownHost.printStackTrace();
672
                                    }
673
                                    host = new byte[] {127, 0, 0, 1};
674
                                }
675
                                os.write(host);
676
                            } catch (IOException ex) {
677
                                ex.printStackTrace();
678
                            }
679
                            try {
680
                                os.getChannel().force(true);
681
                            } catch (IOException ex) {
682
                                // ignore
633
                            }
683
                            }
634
                        }
684
                        }
635
                        
685
                    });
636
                        enterState(96, block);
686
                } else {
637
                        
687
                    parael = Task.EMPTY;
638
                        if (random != null) {
688
                }
639
                            random.nextBytes(arr);
640
                        }
641
                        
642
                        enterState(97, block);
643
644
                        try {
645
                            os.write(arr);
646
                            os.getChannel().force(true);
647
648
                            enterState(27,block);
649
                            // if this turns to be slow due to lookup of getLocalHost
650
                            // address, it can be done asynchronously as nobody needs
651
                            // the address in the stream if the server is listening
652
                            byte[] host;
653
                            try {
654
                                if (block != null && block.intValue() == 667) {
655
                                    // this is here to emulate #64004
656
                                    throw new UnknownHostException("dhcppc0"); // NOI18N
657
                                }
658
                                host = InetAddress.getLocalHost().getAddress();
659
                            } catch (UnknownHostException unknownHost) {
660
                                if (!"dhcppc0".equals(unknownHost.getMessage())) { // NOI18N, see above
661
                                    // if we just cannot get the address, we can go on
662
                                    unknownHost.printStackTrace();
663
                                }
664
                                host = new byte[] {127, 0, 0, 1};
665
                            }
666
                            os.write(host);
667
                        } catch (IOException ex) {
668
                            ex.printStackTrace();
669
                        }
670
                        try {
671
                            os.getChannel().force(true);
672
                        } catch (IOException ex) {
673
                            // ignore
674
                        }
675
                    }
676
                });
677
                
689
                
678
                int execCode = processInitLevelCLI (args, handlers, failOnUnknownOptions);
690
                int execCode = processInitLevelCLI (args, handlers, failOnUnknownOptions);
679
                
691
                
680
                enterState(0, block);
692
                enterState(0, block);
681
                return new Status(lockFile, server.getLocalPort(), execCode, parael);
693
                return new Status(lockFile, p, execCode, parael);
682
            } catch (IOException ex) {
694
            } catch (IOException ex) {
683
                if (!"EXISTS".equals(ex.getMessage())) { // NOI18N
695
                if (!"EXISTS".equals(ex.getMessage())) { // NOI18N
684
                    ex.printStackTrace();
696
                    ex.printStackTrace();
Lines 695-700 Link Here
695
                    }
707
                    }
696
                    is = raf;
708
                    is = raf;
697
                    port = is.readInt();
709
                    port = is.readInt();
710
                    if (port == 0) {
711
                        return new Status(lockFile, 0, Status.ALREADY_RUNNING, Task.EMPTY);
712
                    }
698
                    enterState(22, block);
713
                    enterState(22, block);
699
                    key = new byte[KEY_LENGTH];
714
                    key = new byte[KEY_LENGTH];
700
                    is.readFully(key);
715
                    is.readFully(key);
(-)a/o.n.bootstrap/src/org/netbeans/MainImpl.java (+8 lines)
Lines 228-233 Link Here
228
                return result.getExitCode();
228
                return result.getExitCode();
229
            }
229
            }
230
        }
230
        }
231
        if (result.getExitCode () == CLIHandler.Status.ALREADY_RUNNING) {
232
            JOptionPane.showMessageDialog(null,
233
                MessageFormat.format(ResourceBundle.getBundle("org/netbeans/Bundle").getString("MSG_AlreadyRunning"), user),
234
                ResourceBundle.getBundle("org/netbeans/Bundle").getString("MSG_AlreadyRunningTitle"),
235
                JOptionPane.OK_OPTION
236
            );
237
            return result.getExitCode();
238
        }
231
239
232
        if (methodToCall != null) {
240
        if (methodToCall != null) {
233
            String className = System.getProperty("netbeans.mainclass", "org.netbeans.core.startup.Main"); // NOI18N
241
            String className = System.getProperty("netbeans.mainclass", "org.netbeans.core.startup.Main"); // NOI18N
(-)b7b62cba2b0b (+100 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans;
43
44
import java.io.File;
45
import org.netbeans.junit.NbTestCase;
46
47
/**
48
 *
49
 * @author Jaroslav Tulach <jtulach@netbeans.org>
50
 */
51
public class CLIHandlerNoServerTest extends NbTestCase {
52
53
    public CLIHandlerNoServerTest(String name) {
54
        super(name);
55
    }
56
57
    @Override
58
    protected int timeOut() {
59
        return 15000;
60
    }
61
62
    @Override
63
    protected void setUp() throws Exception {
64
        System.setProperty("org.netbeans.CLIHandler.server", "false");
65
        
66
        // setups a temporary file
67
        String p = getWorkDirPath();
68
        if (p == null) {
69
            p = System.getProperty("java.io.tmpdir");
70
        }
71
        String tmp = p;
72
        assertNotNull(tmp);
73
        System.getProperties().put("netbeans.user", tmp);
74
75
        File f = new File(tmp, "lock");
76
        if (f.exists()) {
77
            assertTrue("Clean up previous mess", f.delete());
78
            assertTrue(!f.exists());
79
        }
80
    }
81
    
82
83
    public void testCannotStartForTheSecondTime() {
84
        CLIHandler.Status res = CLIHandlerTest.cliInitialize(
85
            new String[0], 
86
            new CLIHandler[0], 
87
            CLIHandlerTest.nullInput, CLIHandlerTest.nullOutput, CLIHandlerTest.nullOutput
88
        );
89
90
        assertEquals("Started", 0, res.getExitCode());
91
        
92
        CLIHandler.Status snd = CLIHandlerTest.cliInitialize(
93
            new String[0], 
94
            new CLIHandler[0], 
95
            CLIHandlerTest.nullInput, CLIHandlerTest.nullOutput, CLIHandlerTest.nullOutput
96
        );
97
        
98
        assertEquals("Can't start for the second time", CLIHandler.Status.ALREADY_RUNNING, snd.getExitCode());
99
    }
100
}
(-)a/o.n.bootstrap/test/unit/src/org/netbeans/CLIHandlerTest.java (-7 / +7 lines)
Lines 58-65 Link Here
58
 */
58
 */
59
public class CLIHandlerTest extends NbTestCase {
59
public class CLIHandlerTest extends NbTestCase {
60
60
61
    private static ByteArrayInputStream nullInput = new ByteArrayInputStream(new byte[0]);
61
    final static ByteArrayInputStream nullInput = new ByteArrayInputStream(new byte[0]);
62
    private static ByteArrayOutputStream nullOutput = new ByteArrayOutputStream();
62
    final static ByteArrayOutputStream nullOutput = new ByteArrayOutputStream();
63
    
63
    
64
    private Logger LOG;
64
    private Logger LOG;
65
65
Lines 826-844 Link Here
826
    // Utility methods
826
    // Utility methods
827
    //
827
    //
828
    
828
    
829
    private static CLIHandler.Status cliInitialize(String[] args, CLIHandler handler, InputStream is, OutputStream os, OutputStream err, Integer lock) {
829
    static CLIHandler.Status cliInitialize(String[] args, CLIHandler handler, InputStream is, OutputStream os, OutputStream err, Integer lock) {
830
        return cliInitialize(args, handler, is, os, err, lock, System.getProperty ("user.dir"));
830
        return cliInitialize(args, handler, is, os, err, lock, System.getProperty ("user.dir"));
831
    }
831
    }
832
    private static CLIHandler.Status cliInitialize(String[] args, CLIHandler handler, InputStream is, OutputStream os, OutputStream err, Integer lock, String currentDir) {
832
    static CLIHandler.Status cliInitialize(String[] args, CLIHandler handler, InputStream is, OutputStream os, OutputStream err, Integer lock, String currentDir) {
833
        return cliInitialize(args, Collections.nCopies(1, handler), is, os, err, lock, currentDir);
833
        return cliInitialize(args, Collections.nCopies(1, handler), is, os, err, lock, currentDir);
834
    }
834
    }
835
    private static CLIHandler.Status cliInitialize(String[] args, CLIHandler[] arr, InputStream is, OutputStream os, OutputStream err) {
835
    static CLIHandler.Status cliInitialize(String[] args, CLIHandler[] arr, InputStream is, OutputStream os, OutputStream err) {
836
        return cliInitialize(args, Arrays.asList(arr), is, os, err, null);
836
        return cliInitialize(args, Arrays.asList(arr), is, os, err, null);
837
    }
837
    }
838
    private static CLIHandler.Status cliInitialize(String[] args, List<? extends CLIHandler> coll, InputStream is, OutputStream os, java.io.OutputStream err, Integer lock) {
838
    static CLIHandler.Status cliInitialize(String[] args, List<? extends CLIHandler> coll, InputStream is, OutputStream os, java.io.OutputStream err, Integer lock) {
839
        return cliInitialize (args, coll, is, os, err, lock, System.getProperty ("user.dir"));
839
        return cliInitialize (args, coll, is, os, err, lock, System.getProperty ("user.dir"));
840
    }
840
    }
841
    private static CLIHandler.Status cliInitialize(String[] args, List<? extends CLIHandler> coll, InputStream is, OutputStream os, java.io.OutputStream err, Integer lock, String currentDir) {
841
    static CLIHandler.Status cliInitialize(String[] args, List<? extends CLIHandler> coll, InputStream is, OutputStream os, java.io.OutputStream err, Integer lock, String currentDir) {
842
        return CLIHandler.initialize(new CLIHandler.Args(args, is, os, err, currentDir), lock, coll, false, true, null);
842
        return CLIHandler.initialize(new CLIHandler.Args(args, is, os, err, currentDir), lock, coll, false, true, null);
843
    }
843
    }
844
    
844
    

Return to bug 225895