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 247404
Collapse All | Expand All

(-)a/api.intent/arch.xml (+1139 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE api-answers PUBLIC "-//NetBeans//DTD Arch Answers//EN" "../nbbuild/antsrc/org/netbeans/nbbuild/Arch.dtd" [
3
  <!ENTITY api-questions SYSTEM "../nbbuild/antsrc/org/netbeans/nbbuild/Arch-api-questions.xml">
4
]>
5
6
<api-answers
7
  question-version="1.29"
8
  author="jhavlin@netbeans.org"
9
>
10
11
  &api-questions;
12
13
    <!--
14
            <question id="arch-overall" when="init">
15
                Describe the overall architecture.
16
                <hint>
17
                What will be API for
18
                <a href="http://wiki.netbeans.org/API_Design#Separate_API_for_clients_from_support_API">
19
                    clients and what support API</a>?
20
                What parts will be pluggable?
21
                How will plug-ins be registered? Please use <code>&lt;api type="export"/&gt;</code>
22
                to describe your general APIs and specify their
23
                <a href="http://wiki.netbeans.org/API_Stability#Private">
24
                stability categories</a>.
25
                If possible please provide simple diagrams.
26
                </hint>
27
            </question>
28
    -->
29
    <answer id="arch-overall">
30
        <p>
31
            This module was originally created to provide a way to handle
32
            clicks on hyperlinks in the output window. Some more sophisticated
33
            objects for describing intended operations can be added into this
34
            module in the future.
35
        </p>
36
        <p>
37
            The URI-based actions are useful if the front-end and back-end of
38
            the application is separated, e.g. in network environment. The
39
            actions can be specified on back-end, but handled on front-end,
40
            without any unnecessary communication.
41
        </p>
42
43
        <api
44
            name="Intent"
45
            group="java"
46
            type="export"
47
            category="official"
48
            url="@org-netbeans-api-intent@/org/netbeans/api/intent/package-summary.html"
49
        >
50
            <p>
51
                API for invoking some intended operation, specified by
52
                a URI. For example, for displaying a web page in browser, or for
53
                opening a source file in editor.
54
            </p>
55
        </api>
56
        <api
57
            name="OpenUriSPI"
58
            group="java"
59
            type="export"
60
            category="official"
61
            url="@org-netbeans-api-intent@/org/netbeans/spi/intent/uri/package-summary.html"
62
        >
63
            <p>
64
                SPI for handlers that are able to invoke proper operation for
65
                some URI.
66
            </p>
67
        </api>
68
    </answer>
69
70
71
72
    <!--
73
            <question id="arch-quality" when="init">
74
                How will the <a href="http://www.netbeans.org/community/guidelines/q-evangelism.html">quality</a>
75
                of your code be tested and
76
                how are future regressions going to be prevented?
77
                <hint>
78
                What kind of testing do
79
                you want to use? How much functionality, in which areas,
80
                should be covered by the tests? How you find out that your
81
                project was successful?
82
                </hint>
83
            </question>
84
    -->
85
    <answer id="arch-quality">
86
        <p>
87
            The code is checked by unit tests.
88
        </p>
89
    </answer>
90
91
92
93
    <!--
94
            <question id="arch-time" when="init">
95
                What are the time estimates of the work?
96
                <hint>
97
                Please express your estimates of how long the design, implementation,
98
                stabilization are likely to last. How many people will be needed to
99
                implement this and what is the expected milestone by which the work should be
100
                ready?
101
                </hint>
102
            </question>
103
    -->
104
    <answer id="arch-time">
105
        <p>
106
            Done.
107
        </p>
108
    </answer>
109
110
111
112
    <!--
113
        <question id="arch-usecases" when="init">
114
            <hint>
115
                Content of this answer will be displayed as part of page at
116
                http://www.netbeans.org/download/dev/javadoc/usecases.html
117
                You can use tags &lt;usecase name="name&gt; regular html description &lt;/usecase&gt;
118
                and if you want to use an URL you can prefix if with @TOP@ to begin
119
                at the root of your javadoc
120
            </hint>
121
122
                Describe the main <a href="http://wiki.netbeans.org/API_Design#The_Importance_of_Being_Use_Case_Oriented">
123
                use cases</a> of the new API. Who will use it under
124
                what circumstances? What kind of code would typically need to be written
125
                to use the module?
126
            </question>
127
    -->
128
    <answer id="arch-usecases">
129
        <usecase id="openUri" name="Invoke proper operation for a URI">
130
            <pre>
131
    IntentManager.execute(Intent.forUri(new URI("scheme://path/")));
132
            </pre>
133
        </usecase>
134
135
        <usecase id="handleUri" name="Handle some URI clicked (or somehow invoked) in the application.">
136
            <pre>
137
   &nbsp;&#64;ServiceProvider(service = OpenUriHandler.class, position = 800)
138
    public class TestOpenUriHandler implements OpenUriHandler {
139
140
        public boolean open(URI uri) {
141
            if ("http".equals(uri.getScheme())) {
142
                // open default browser
143
                return true;
144
            } else {
145
                return false;
146
            }
147
        }
148
    }
149
            </pre>
150
        </usecase>
151
    </answer>
152
153
154
155
    <!--
156
            <question id="arch-what" when="init">
157
                What is this project good for?
158
                <hint>
159
                Please provide here a few lines describing the project,
160
                what problem it should solve, provide links to documentation,
161
                specifications, etc.
162
                </hint>
163
            </question>
164
    -->
165
    <answer id="arch-what">
166
        <p>
167
            This module provides a contract between API clients that can express
168
            some intention to invoke an operation (specified e.g. by a URI) and
169
            SPI providers that can handle the URI.
170
        </p>
171
        <p>
172
            This is useful in client-server environments, where the intention
173
            can be constructed on server-side, but handled on client-side. The
174
            objects that describe the intention should be easy to construct,
175
            transfer and interpret.
176
        </p>
177
    </answer>
178
179
180
181
    <!--
182
            <question id="arch-where" when="impl">
183
                Where one can find sources for your module?
184
                <hint>
185
                    Please provide link to the Hg web client at
186
                    http://hg.netbeans.org/
187
                    or just use tag defaultanswer generate='here'
188
                </hint>
189
            </question>
190
    -->
191
    <answer id="arch-where">
192
        <defaultanswer generate='here' />
193
    </answer>
194
195
196
197
    <!--
198
            <question id="compat-deprecation" when="init">
199
                How the introduction of your project influences functionality
200
                provided by previous version of the product?
201
                <hint>
202
                If you are planning to deprecate/remove/change any existing APIs,
203
                list them here accompanied with the reason explaining why you
204
                are doing so.
205
                </hint>
206
            </question>
207
    -->
208
    <answer id="compat-deprecation">
209
        <p>
210
            No deprecation needed.
211
        </p>
212
    </answer>
213
214
215
216
    <!--
217
            <question id="compat-i18n" when="impl">
218
                Is your module correctly internationalized?
219
                <hint>
220
                Correct internationalization means that it obeys instructions 
221
                at <a href="http://www.netbeans.org/download/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/i18n-branding.html">
222
                NetBeans I18N pages</a>.
223
                </hint>
224
            </question>
225
    -->
226
    <answer id="compat-i18n">
227
        <p>
228
            Yes.
229
        </p>
230
    </answer>
231
232
233
234
    <!--
235
            <question id="compat-standards" when="init">
236
                Does the module implement or define any standards? Is the
237
                implementation exact or does it deviate somehow?
238
            </question>
239
    -->
240
    <answer id="compat-standards">
241
        <p>
242
            No standards.
243
        </p>
244
    </answer>
245
246
247
248
<!--
249
        <question id="compat-version" when="impl">
250
            Can your module coexist with earlier and future
251
            versions of itself? Can you correctly read all old settings? Will future
252
            versions be able to read your current settings? Can you read
253
            or politely ignore settings stored by a future version?
254
255
                <hint>
256
                Very helpful for reading settings is to store version number
257
                there, so future versions can decide whether how to read/convert
258
                the settings and older versions can ignore the new ones.
259
                </hint>
260
            </question>
261
    -->
262
    <answer id="compat-version">
263
        <p>
264
            No settings are read or written.
265
        </p>
266
    </answer>
267
268
269
270
    <!--
271
            <question id="dep-jre" when="final">
272
                Which version of JRE do you need (1.2, 1.3, 1.4, etc.)?
273
                <hint>
274
                It is expected that if your module runs on 1.x that it will run
275
                on 1.x+1 if no, state that please. Also describe here cases where
276
                you run different code on different versions of JRE and why.
277
                </hint>
278
            </question>
279
    -->
280
    <answer id="dep-jre">
281
        <p>
282
            1.6
283
        </p>
284
    </answer>
285
286
287
288
    <!--
289
            <question id="dep-jrejdk" when="final">
290
                Do you require the JDK or is the JRE enough?
291
            </question>
292
    -->
293
    <answer id="dep-jrejdk">
294
        <p>
295
            JRE
296
        </p>
297
    </answer>
298
299
300
301
    <!--
302
            <question id="dep-nb" when="init">
303
                What other NetBeans projects and modules does this one depend on?
304
                <hint>
305
                Depending on other NetBeans projects influnces the ability of
306
                users of your work to customize their own branded version of
307
                NetBeans by enabling and disabling some modules. Too
308
                much dependencies restrict this kind of customization. If that
309
                is your case, then you may want to split your functionality into
310
                pieces of autoload, eager and regular modules which can be
311
                enabled independently. Usually the answer to this question
312
                is generated from your <code>project.xml</code> file, but
313
                if it is not guessed correctly, you can suppress it by
314
                specifying &lt;defaultanswer generate="none"/&gt; and
315
                write here your own. Please describe such projects as imported APIs using
316
                the <code>&lt;api name="identification" type="import or export" category="stable" url="where is the description" /&gt;</code>.
317
                By doing this information gets listed in the summary page of your
318
                javadoc.
319
                </hint>
320
            </question>
321
    -->
322
    <answer id="dep-nb">
323
        <defaultanswer generate='here' />
324
    </answer>
325
326
327
328
    <!--
329
        <question id="dep-non-nb" when="init">
330
            What other projects outside NetBeans does this one depend on?
331
332
                <hint>
333
                Depending on 3rd party libraries is always problematic,
334
                especially if they are not open source, as that complicates
335
                the licensing scheme of NetBeans. Please enumerate your
336
                external dependencies here, so it is correctly understood since
337
                the begining what are the legal implications of your project.
338
                Also please note that
339
                some non-NetBeans projects are packaged as NetBeans modules
340
                (see <a href="http://libs.netbeans.org/">libraries</a>) and
341
                it is preferred to use this approach when more modules may
342
                depend and share such third-party libraries.
343
                </hint>
344
            </question>
345
    -->
346
    <answer id="dep-non-nb">
347
        <p>
348
            No non-NB dependencies.
349
        </p>
350
    </answer>
351
352
353
354
    <!--
355
            <question id="dep-platform" when="init">
356
                On which platforms does your module run? Does it run in the same
357
                way on each?
358
                <hint>
359
                If you plan any dependency on OS or any usage of native code,
360
                please describe why you are doing so and describe how you envision
361
                to enforce the portability of your code.
362
                Please note that there is a support for <a href="http://www.netbeans.org/download/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#how-os-specific">OS conditionally
363
                enabled modules</a> which together with autoload/eager modules
364
                can allow you to enable to provide the best OS aware support
365
                on certain OSes while providing compatibility bridge on the not
366
                supported ones.
367
                Also please list the supported
368
                OSes/HW platforms and mentioned the lovest version of JDK required
369
                for your project to run on. Also state whether JRE is enough or
370
                you really need JDK.
371
                </hint>
372
            </question>
373
    -->
374
    <answer id="dep-platform">
375
        <p>
376
            Any platform.
377
        </p>
378
    </answer>
379
380
381
382
    <!--
383
            <question id="deploy-dependencies" when="final">
384
                What do other modules need to do to declare a dependency on this one,
385
                in addition to or instead of the normal module dependency declaration
386
                (e.g. tokens to require)?
387
                <hint>
388
                    Provide a sample of the actual lines you would add to a module manifest
389
                    to declare a dependency, for example OpenIDE-Module-Requires: some.token.
390
                    If other modules should not depend on this module, or should just use a
391
                    simple regular module dependency, you can just answer "nothing". If you
392
                    intentionally expose a semistable API to clients using implementation
393
                    dependencies, you should mention that here (but there is no need to give
394
                    an example of usage).
395
                </hint>
396
            </question>
397
    -->
398
    <answer id="deploy-dependencies">
399
        <p>
400
            Standard module dependency is sufficient.
401
        </p>
402
    </answer>
403
404
405
406
    <!--
407
        <question id="deploy-jar" when="impl">
408
            Do you deploy just module JAR file(s) or other files as well?
409
            <hint>
410
            Usually a module consist of one JAR file (perhaps with Class-Path
411
            extensions) and also a configuration file that enables it. If you
412
            have any other files, use
413
            &lt;api group="java.io.File" name="yourname" type="export" category="friend"&gt;...&lt;/api&gt;
414
            to define the location, name and stability of your files (of course
415
            changing "yourname" and "friend" to suit your needs).
416
417
                If it uses more than one JAR, describe where they are located, how
418
                they refer to each other.
419
                If it consist of module JAR(s) and other files, please describe
420
                what is their purpose, why other files are necessary. Please
421
                make sure that installation/uninstallation leaves the system
422
                in state as it was before installation.
423
                </hint>
424
            </question>
425
    -->
426
    <answer id="deploy-jar">
427
        <p>
428
            Just module JAR.
429
        </p>
430
    </answer>
431
432
433
434
    <!--
435
            <question id="deploy-nbm" when="impl">
436
                Can you deploy an NBM via the Update Center?
437
                <hint>
438
                If not why?
439
                </hint>
440
            </question>
441
    -->
442
    <answer id="deploy-nbm">
443
        <p>
444
            Yes.
445
        </p>
446
    </answer>
447
448
449
450
<!--
451
        <question id="deploy-packages" when="init">
452
            Are packages of your module made inaccessible by not declaring them
453
            public?
454
455
                <hint>
456
                By default NetBeans build harness treats all packages are private.
457
                If you export some of them - either as public or friend packages,
458
                you should have a reason. If the reason is described elsewhere
459
                in this document, you can ignore this question.
460
                </hint>
461
            </question>
462
    -->
463
    <answer id="deploy-packages">
464
        <p>
465
            Only API and SPI packages are public.
466
        </p>
467
    </answer>
468
469
470
471
    <!--
472
            <question id="deploy-shared" when="final">
473
                Do you need to be installed in the shared location only, or in the user directory only,
474
                or can your module be installed anywhere?
475
                <hint>
476
                Installation location shall not matter, if it does explain why.
477
                Consider also whether <code>InstalledFileLocator</code> can help.
478
                </hint>
479
            </question>
480
    -->
481
    <answer id="deploy-shared">
482
        <p>
483
            Installation location does not matter.
484
        </p>
485
    </answer>
486
487
488
489
    <!--
490
        <question id="exec-ant-tasks" when="impl">
491
            Do you define or register any ant tasks that other can use?
492
493
                <hint>
494
                If you provide an ant task that users can use, you need to be very
495
                careful about its syntax and behaviour, as it most likely forms an
496
                      API for end users and as there is a lot of end users, their reaction
497
                when such API gets broken can be pretty strong.
498
                </hint>
499
            </question>
500
    -->
501
    <answer id="exec-ant-tasks">
502
        <p>
503
            No.
504
        </p>
505
    </answer>
506
507
508
509
    <!--
510
            <question id="exec-classloader" when="impl">
511
                Does your code create its own class loader(s)?
512
                <hint>
513
                A bit unusual. Please explain why and what for.
514
                </hint>
515
            </question>
516
    -->
517
    <answer id="exec-classloader">
518
        <p>
519
            No.
520
        </p>
521
    </answer>
522
523
524
525
    <!--
526
        <question id="exec-component" when="impl">
527
            Is execution of your code influenced by any (string) property
528
            of any of your components?
529
530
                <hint>
531
                Often <code>JComponent.getClientProperty</code>, <code>Action.getValue</code>
532
                or <code>PropertyDescriptor.getValue</code>, etc. are used to influence
533
                a behavior of some code. This of course forms an interface that should
534
                be documented. Also if one depends on some interface that an object
535
                implements (<code>component instanceof Runnable</code>) that forms an
536
                API as well.
537
                </hint>
538
            </question>
539
    -->
540
    <answer id="exec-component">
541
        <p>
542
            No.
543
        </p>
544
    </answer>
545
546
547
548
    <!--
549
            <question id="exec-introspection" when="impl">
550
                Does your module use any kind of runtime type information (<code>instanceof</code>,
551
                work with <code>java.lang.Class</code>, etc.)?
552
                <hint>
553
                Check for cases when you have an object of type A and you also
554
                expect it to (possibly) be of type B and do some special action. That
555
                should be documented. The same applies on operations in meta-level
556
                (Class.isInstance(...), Class.isAssignableFrom(...), etc.).
557
                </hint>
558
            </question>
559
    -->
560
    <answer id="exec-introspection">
561
        <p>
562
            No.
563
        </p>
564
    </answer>
565
566
567
568
    <!--
569
            <question id="exec-privateaccess" when="final">
570
                Are you aware of any other parts of the system calling some of
571
                your methods by reflection?
572
                <hint>
573
                If so, describe the "contract" as an API. Likely private or friend one, but
574
                still API and consider rewrite of it.
575
                </hint>
576
            </question>
577
    -->
578
    <answer id="exec-privateaccess">
579
        <p>
580
            No.
581
        </p>
582
    </answer>
583
584
585
586
    <!--
587
            <question id="exec-process" when="impl">
588
                Do you execute an external process from your module? How do you ensure
589
                that the result is the same on different platforms? Do you parse output?
590
                Do you depend on result code?
591
                <hint>
592
                If you feed an input, parse the output please declare that as an API.
593
                </hint>
594
            </question>
595
    -->
596
    <answer id="exec-process">
597
        <p>
598
            No.
599
        </p>
600
    </answer>
601
602
603
604
    <!--
605
            <question id="exec-property" when="impl">
606
                Is execution of your code influenced by any environment or
607
                Java system (<code>System.getProperty</code>) property?
608
                On a similar note, is there something interesting that you
609
                pass to <code>java.util.logging.Logger</code>? Or do you observe
610
                what others log?
611
                <hint>
612
                If there is a property that can change the behavior of your
613
                code, somebody will likely use it. You should describe what it does
614
                and the <a href="http://wiki.netbeans.org/API_Stability">stability category</a>
615
                of this API. You may use
616
                <pre>
617
                    &lt;api type="export" group="property" name="id" category="private" url="http://..."&gt;
618
                        description of the property, where it is used, what it influence, etc.
619
                    &lt;/api&gt;
620
                </pre>
621
                </hint>
622
            </question>
623
    -->
624
    <answer id="exec-property">
625
        <p>
626
            No.
627
        </p>
628
    </answer>
629
630
631
632
    <!--
633
            <question id="exec-reflection" when="impl">
634
                Does your code use Java Reflection to execute other code?
635
                <hint>
636
                This usually indicates a missing or insufficient API in the other
637
                part of the system. If the other side is not aware of your dependency
638
                this contract can be easily broken.
639
                </hint>
640
            </question>
641
    -->
642
    <answer id="exec-reflection">
643
        <p>
644
            No.
645
        </p>
646
    </answer>
647
648
649
650
    <!--
651
            <question id="exec-threading" when="init">
652
                What threading models, if any, does your module adhere to? How the
653
                project behaves with respect to threading?
654
                <hint>
655
                    Is your API threadsafe? Can it be accessed from any threads or
656
                    just from some dedicated ones? Any special relation to AWT and
657
                    its Event Dispatch thread? Also
658
                    if your module calls foreign APIs which have a specific threading model,
659
                    indicate how you comply with the requirements for multithreaded access
660
                    (synchronization, mutexes, etc.) applicable to those APIs.
661
                    If your module defines any APIs, or has complex internal structures
662
                    that might be used from multiple threads, declare how you protect
663
                    data against concurrent access, race conditions, deadlocks, etc.,
664
                    and whether such rules are enforced by runtime warnings, errors, assertions, etc.
665
                    Examples: a class might be non-thread-safe (like Java Collections); might
666
                    be fully thread-safe (internal locking); might require access through a mutex
667
                    (and may or may not automatically acquire that mutex on behalf of a client method);
668
                    might be able to run only in the event queue; etc.
669
                    Also describe when any events are fired: synchronously, asynchronously, etc.
670
                    Ideas: <a href="http://core.netbeans.org/proposals/threading/index.html#recommendations">Threading Recommendations</a> (in progress)
671
                </hint>
672
            </question>
673
    -->
674
    <answer id="exec-threading">
675
        <p>
676
            The API is threadsafe. SPI implementations should ensure proper
677
            synchronization.
678
        </p>
679
    </answer>
680
681
682
683
    <!--
684
        <question id="format-clipboard" when="impl">
685
            Which data flavors (if any) does your code read from or insert to
686
            the clipboard (by access to clipboard on means calling methods on <code>java.awt.datatransfer.Transferable</code>?
687
688
                <hint>
689
                Often Node's deal with clipboard by usage of <code>Node.clipboardCopy, Node.clipboardCut and Node.pasteTypes</code>.
690
                Check your code for overriding these methods.
691
                </hint>
692
            </question>
693
    -->
694
    <answer id="format-clipboard">
695
        <p>
696
            No clipboard access.
697
        </p>
698
    </answer>
699
700
701
702
    <!--
703
            <question id="format-dnd" when="impl">
704
                Which protocols (if any) does your code understand during Drag &amp; Drop?
705
                <hint>
706
                Often Node's deal with clipboard by usage of <code>Node.drag, Node.getDropType</code>. 
707
                Check your code for overriding these methods. Btw. if they are not overridden, they
708
                by default delegate to <code>Node.clipboardCopy, Node.clipboardCut and Node.pasteTypes</code>.
709
                </hint>
710
            </question>
711
    -->
712
    <answer id="format-dnd">
713
        <p>
714
            No Drag &amp; Drop support.
715
        </p>
716
    </answer>
717
718
719
720
<!--
721
        <question id="format-types" when="impl">
722
            Which protocols and file formats (if any) does your module read or write on disk,
723
            or transmit or receive over the network? Do you generate an ant build script?
724
            Can it be edited and modified?
725
726
            <hint>
727
                <p>
728
                Files can be read and written by other programs, modules and users. If they influence
729
                your behaviour, make sure you either document the format or claim that it is a private
730
                api (using the &lt;api&gt; tag).
731
                </p>
732
                <p>
733
                If you generate an ant build file, this is very likely going to be seen by end users and
734
                they will be attempted to edit it. You should be ready for that and provide here a link
735
                to documentation that you have for such purposes and also describe how you are going to
736
                understand such files during next release, when you (very likely) slightly change the
737
                format.
738
                </p>
739
                </hint>
740
            </question>
741
    -->
742
    <answer id="format-types">
743
        <p>
744
            No files are read or written by this module.
745
        </p>
746
    </answer>
747
748
749
750
<!--
751
        <question id="lookup-lookup" when="init">
752
            Does your module use <code>org.openide.util.Lookup</code>
753
            or any similar technology to find any components to communicate with? Which ones?
754
755
                <hint>
756
                NetBeans is build around a generic registry of services called
757
                lookup. It is preferable to use it for registration and discovery
758
                if possible. See
759
                <a href="http://www.netbeans.org/download/dev/javadoc/org-openide-util/org/openide/util/lookup/doc-files/index.html">
760
                The Solution to Comunication Between Components
761
                </a>. If you do not plan to use lookup and insist usage
762
                of other solution, then please describe why it is not working for
763
                you.
764
                <br/>
765
                When filling the final version of your arch document, please
766
                describe the interfaces you are searching for, where
767
                are defined, whether you are searching for just one or more of them,
768
                if the order is important, etc. Also classify the stability of such
769
                API contract. Use &lt;api group=&amp;lookup&amp; /&gt; tag, so
770
                your information gets listed in the summary page of your javadoc.
771
                </hint>
772
            </question>
773
    -->
774
    <answer id="lookup-lookup">
775
        <p>
776
            The lookup is used to find registered <code>OpenUriHandler</code>s.
777
        </p>
778
    </answer>
779
780
781
782
    <!--
783
            <question id="lookup-register" when="final">
784
                Do you register anything into lookup for other code to find?
785
                <hint>
786
                Do you register using layer file or using a declarative annotation such as <code>@ServiceProvider</code>?
787
                Who is supposed to find your component?
788
                </hint>
789
            </question>
790
    -->
791
    <answer id="lookup-register">
792
        <p>
793
            No.
794
        </p>
795
    </answer>
796
797
798
799
    <!--
800
            <question id="lookup-remove" when="final">
801
                Do you remove entries of other modules from lookup?
802
                <hint>
803
                Why? Of course, that is possible, but it can be dangerous. Is the module
804
                your are masking resource from aware of what you are doing?
805
                </hint>
806
            </question>
807
    -->
808
    <answer id="lookup-remove">
809
        <p>
810
            No.
811
        </p>
812
    </answer>
813
814
815
816
    <!--
817
            <question id="perf-exit" when="final">
818
                Does your module run any code on exit?
819
            </question>
820
    -->
821
    <answer id="perf-exit">
822
        <p>
823
            No.
824
        </p>
825
    </answer>
826
827
828
829
    <!--
830
            <question id="perf-huge_dialogs" when="final">
831
                Does your module contain any dialogs or wizards with a large number of
832
                GUI controls such as combo boxes, lists, trees, or text areas?
833
            </question>
834
    -->
835
    <answer id="perf-huge_dialogs">
836
        <p>
837
            No.
838
        </p>
839
    </answer>
840
841
842
843
    <!--
844
            <question id="perf-limit" when="init">
845
                Are there any hard-coded or practical limits in the number or size of
846
                elements your code can handle?
847
                <hint>
848
                    Most of algorithms have increasing memory and speed complexity
849
                    with respect to size of data they operate on. What is the critical
850
                    part of your project that can be seen as a bottleneck with
851
                    respect to speed or required memory? What are the practical
852
                    sizes of data you tested your project with? What is your estimate
853
                    of potential size of data that would cause visible performance
854
                    problems? Is there some kind of check to detect such situation
855
                    and prevent "hard" crashes - for example the CloneableEditorSupport
856
                    checks for size of a file to be opened in editor
857
                    and if it is larger than 1Mb it shows a dialog giving the
858
                    user the right to decide - e.g. to cancel or commit suicide.
859
                </hint>
860
            </question>
861
    -->
862
    <answer id="perf-limit">
863
        <p>
864
            No.
865
        </p>
866
    </answer>
867
868
869
870
    <!--
871
            <question id="perf-mem" when="final">
872
                How much memory does your component consume? Estimate
873
                with a relation to the number of windows, etc.
874
            </question>
875
    -->
876
    <answer id="perf-mem">
877
        <p>
878
            Very little memory consumed.
879
        </p>
880
    </answer>
881
882
883
884
    <!--
885
            <question id="perf-menus" when="final">
886
                Does your module use dynamically updated context menus, or
887
                context-sensitive actions with complicated and slow enablement logic?
888
                <hint>
889
                    If you do a lot of tricks when adding actions to regular or context menus, you can significantly
890
                    slow down display of the menu, even when the user is not using your action. Pay attention to
891
                    actions you add to the main menu bar, and to context menus of foreign nodes or components. If
892
                    the action is conditionally enabled, or changes its display dynamically, you need to check the
893
                    impact on performance. In some cases it may be more appropriate to make a simple action that is
894
                    always enabled but does more detailed checks in a dialog if it is actually run.
895
                </hint>
896
            </question>
897
    -->
898
    <answer id="perf-menus">
899
        <p>
900
            No.
901
        </p>
902
    </answer>
903
904
905
906
    <!--
907
        <question id="perf-progress" when="final">
908
            Does your module execute any long-running tasks?
909
910
                <hint>Long running tasks should never block
911
                AWT thread as it badly hurts the UI
912
                <a href="http://performance.netbeans.org/responsiveness/issues.html">
913
                responsiveness</a>.
914
                Tasks like connecting over
915
                network, computing huge amount of data, compilation
916
                be done asynchronously (for example
917
                using <code>RequestProcessor</code>), definitively it should
918
                not block AWT thread.
919
                </hint>
920
            </question>
921
    -->
922
    <answer id="perf-progress">
923
        <p>
924
            No.
925
        </p>
926
    </answer>
927
928
929
930
    <!--
931
            <question id="perf-scale" when="init">
932
                Which external criteria influence the performance of your
933
                program (size of file in editor, number of files in menu,
934
                in source directory, etc.) and how well your code scales?
935
                <hint>
936
                Please include some estimates, there are other more detailed
937
                questions to answer in later phases of implementation.
938
                </hint>
939
            </question>
940
    -->
941
    <answer id="perf-scale">
942
        <p>
943
            Code in the module is very simple. Performance is incluenced mosly
944
            by SPI implementations, which should run quite quickly.
945
        </p>
946
    </answer>
947
948
949
950
    <!--
951
            <question id="perf-spi" when="init">
952
                How the performance of the plugged in code will be enforced?
953
                <hint>
954
                If you allow foreign code to be plugged into your own module, how
955
                do you enforce that it will behave correctly and quickly and will not
956
                negatively influence the performance of your own module?
957
                </hint>
958
            </question>
959
    -->
960
    <answer id="perf-spi">
961
        <p>
962
            No performance criteria are enforced. The plugged-in code is invoked
963
            by a dedicated executor.
964
        </p>
965
    </answer>
966
967
968
969
    <!--
970
            <question id="perf-startup" when="final">
971
                Does your module run any code on startup?
972
            </question>
973
    -->
974
    <answer id="perf-startup">
975
        <p>
976
            No.
977
        </p>
978
    </answer>
979
980
981
982
    <!--
983
            <question id="perf-wakeup" when="final">
984
                Does any piece of your code wake up periodically and do something
985
                even when the system is otherwise idle (no user interaction)?
986
            </question>
987
    -->
988
    <answer id="perf-wakeup">
989
        <p>
990
            No.
991
        </p>
992
    </answer>
993
994
995
996
    <!--
997
        <question id="resources-file" when="final">
998
            Does your module use <code>java.io.File</code> directly?
999
1000
                <hint>
1001
                NetBeans provide a logical wrapper over plain files called 
1002
                <code>org.openide.filesystems.FileObject</code> that
1003
                provides uniform access to such resources and is the preferred
1004
                way that should be used. But of course there can be situations when
1005
                this is not suitable.
1006
                </hint>
1007
            </question>
1008
    -->
1009
    <answer id="resources-file">
1010
        <p>
1011
            No.
1012
        </p>
1013
    </answer>
1014
1015
1016
1017
    <!--
1018
        <question id="resources-layer" when="final">
1019
            Does your module provide own layer? Does it create any files or
1020
            folders in it? What it is trying to communicate by that and with which
1021
            components?
1022
1023
                <hint>
1024
                NetBeans allows automatic and declarative installation of resources
1025
                by module layers. Module register files into appropriate places
1026
                and other components use that information to perform their task
1027
                (build menu, toolbar, window layout, list of templates, set of
1028
                options, etc.).
1029
                </hint>
1030
            </question>
1031
    -->
1032
    <answer id="resources-layer">
1033
        <p>
1034
            No.
1035
        </p>
1036
    </answer>
1037
1038
1039
1040
    <!--
1041
        <question id="resources-mask" when="final">
1042
            Does your module mask/hide/override any resources provided by other modules in
1043
            their layers?
1044
1045
                <hint>
1046
                If you mask a file provided by another module, you probably depend
1047
                on that and do not want the other module to (for example) change
1048
                the file's name. That module shall thus make that file available as an API
1049
                of some stability category.
1050
                </hint>
1051
            </question>
1052
    -->
1053
    <answer id="resources-mask">
1054
        <p>
1055
            No.
1056
        </p>
1057
    </answer>
1058
1059
1060
1061
    <!--
1062
            <question id="resources-preferences" when="final">
1063
                Does your module uses preferences via Preferences API? Does your module use NbPreferences or
1064
                or regular JDK Preferences ? Does it read, write or both ?
1065
                Does it share preferences with other modules ? If so, then why ?
1066
                <hint>
1067
                    You may use
1068
                        &lt;api type="export" group="preferences"
1069
                        name="preference node name" category="private"&gt;
1070
                        description of individual keys, where it is used, what it
1071
                        influences, whether the module reads/write it, etc.
1072
                        &lt;/api&gt;
1073
                    Due to XML ID restrictions, rather than /org/netbeans/modules/foo give the "name" as org.netbeans.modules.foo.
1074
                    Note that if you use NbPreferences this name will then be the same as the code name base of the module.
1075
                </hint>
1076
            </question>
1077
    -->
1078
    <answer id="resources-preferences">
1079
        <p>
1080
            No.
1081
        </p>
1082
    </answer>
1083
1084
1085
1086
    <!--
1087
        <question id="resources-read" when="final">
1088
            Does your module read any resources from layers? For what purpose?
1089
1090
                <hint>
1091
                As this is some kind of intermodule dependency, it is a kind of API.
1092
                Please describe it and classify according to
1093
                <a href="http://wiki.netbeans.org/API_Design#What_is_an_API.3F">
1094
                common stability categories</a>.
1095
                </hint>
1096
            </question>
1097
    -->
1098
    <answer id="resources-read">
1099
        <p>
1100
            No.
1101
        </p>
1102
    </answer>
1103
1104
1105
1106
    <!--
1107
            <question id="security-grant" when="final">
1108
                Does your code grant additional rights to some other code?
1109
                <hint>Avoid using a class loader that adds extra
1110
                permissions to loaded code unless really necessary.
1111
                Also note that your API implementation
1112
                can also expose unneeded permissions to enemy code by
1113
                calling AccessController.doPrivileged().</hint>
1114
            </question>
1115
    -->
1116
    <answer id="security-grant">
1117
        <p>
1118
            No.
1119
        </p>
1120
    </answer>
1121
1122
1123
1124
    <!--
1125
            <question id="security-policy" when="final">
1126
                Does your functionality require modifications to the standard policy file?
1127
                <hint>Your code might pass control to third-party code not
1128
                coming from trusted domains. This could be code downloaded over the
1129
                network or code coming from libraries that are not bundled
1130
                with NetBeans. Which permissions need to be granted to which domains?</hint>
1131
            </question>
1132
    -->
1133
    <answer id="security-policy">
1134
        <p>
1135
            No.
1136
        </p>
1137
    </answer>
1138
1139
</api-answers>
(-)a/api.intent/build.xml (+5 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project basedir="." default="netbeans" name="api.intent">
3
    <description>Builds, tests, and runs the project org.netbeans.api.intent</description>
4
    <import file="../nbbuild/templates/projectized.xml"/>
5
</project>
(-)a/api.intent/manifest.mf (+6 lines)
Line 0 Link Here
1
Manifest-Version: 1.0
2
AutoUpdate-Show-In-Client: true
3
OpenIDE-Module: org.netbeans.api.intent
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/intent/Bundle.properties
5
OpenIDE-Module-Specification-Version: 1.0
6
(-)a/api.intent/nbproject/project.properties (+4 lines)
Line 0 Link Here
1
is.autoload=true
2
javac.source=1.6
3
javac.compilerargs=-Xlint -Xlint:-serial
4
javadoc.arch=${basedir}/arch.xml
(-)a/api.intent/nbproject/project.xml (+53 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://www.netbeans.org/ns/project/1">
3
    <type>org.netbeans.modules.apisupport.project</type>
4
    <configuration>
5
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
6
            <code-name-base>org.netbeans.api.intent</code-name-base>
7
            <module-dependencies>
8
                <dependency>
9
                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
10
                    <build-prerequisite/>
11
                    <compile-dependency/>
12
                    <run-dependency>
13
                        <release-version>1</release-version>
14
                        <specification-version>1.25</specification-version>
15
                    </run-dependency>
16
                </dependency>
17
                <dependency>
18
                    <code-name-base>org.openide.util.base</code-name-base>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
21
                    <run-dependency>
22
                        <specification-version>9.1</specification-version>
23
                    </run-dependency>
24
                </dependency>
25
                <dependency>
26
                    <code-name-base>org.openide.util.lookup</code-name-base>
27
                    <build-prerequisite/>
28
                    <compile-dependency/>
29
                    <run-dependency>
30
                        <specification-version>8.26</specification-version>
31
                    </run-dependency>
32
                </dependency>
33
            </module-dependencies>
34
            <test-dependencies>
35
                <test-type>
36
                    <name>unit</name>
37
                    <test-dependency>
38
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
39
                        <compile-dependency/>
40
                    </test-dependency>
41
                    <test-dependency>
42
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
43
                        <compile-dependency/>
44
                    </test-dependency>
45
                </test-type>
46
            </test-dependencies>
47
            <public-packages>
48
                <package>org.netbeans.api.intent</package>
49
                <package>org.netbeans.spi.intent.uri</package>
50
            </public-packages>
51
        </data>
52
    </configuration>
53
</project>
(-)a/api.intent/src/org/netbeans/api/intent/Bundle.properties (+7 lines)
Line 0 Link Here
1
OpenIDE-Module-Display-Category=Infrastructure
2
OpenIDE-Module-Long-Description=\
3
    API for invoking intended operations (described by suitable type of object, e.g. \
4
    URI) by some of registered handlers.\n\
5
    SPI for handlers of possible intended operations.
6
OpenIDE-Module-Name=Intent API
7
OpenIDE-Module-Short-Description=Performing intended operations by suitable handlers
(-)a/api.intent/src/org/netbeans/api/intent/Intent.java (+80 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.intent;
43
44
import java.net.URI;
45
import org.netbeans.api.annotations.common.NonNull;
46
import org.netbeans.spi.intent.uri.OpenUriHandler;
47
import org.openide.util.Parameters;
48
49
/**
50
 * Class that describes an intended operation.
51
 *
52
 * @author jhavlin
53
 *
54
 * @param <R> Result type of the intended operation.
55
 * @see IntentManager
56
 */
57
public abstract class Intent<R> {
58
59
    abstract R invoke();
60
61
    Intent() {
62
    }
63
64
    /**
65
     * Create an intended operation described by a URI.
66
     * <p>
67
     * Result type of the operation will be a boolean value: true if the URI was
68
     * handled, false if no provider was able to handle it.
69
     * </p>
70
     *
71
     * @param uri URI describing the operation.
72
     * @return The new URI-based intended operation.
73
     *
74
     * @see OpenUriHandler
75
     */
76
    public static Intent<Boolean> forUri(@NonNull URI uri) {
77
        Parameters.notNull("uri", uri);                                 //NOI18N
78
        return new UriIntent(uri);
79
    }
80
}
(-)a/api.intent/src/org/netbeans/api/intent/IntentManager.java (+95 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.intent;
43
44
import java.util.concurrent.Callable;
45
import java.util.concurrent.Executor;
46
import java.util.concurrent.Future;
47
import org.openide.util.RequestProcessor;
48
49
/**
50
 * Manager for execution and submitting of {@link Intent}s.
51
 *
52
 * @author jhavlin
53
 * @see Executor
54
 */
55
public final class IntentManager {
56
57
    private static final RequestProcessor RP = new RequestProcessor(
58
            IntentManager.class);
59
60
    private IntentManager() {
61
    }
62
63
    /**
64
     * Execute an intent by an internal executor.
65
     *
66
     * @param intent The intent to execute.
67
     */
68
    public static void execute(final Intent<?> intent) {
69
        RP.execute(new Runnable() {
70
71
            @Override
72
            public void run() {
73
                intent.invoke();
74
            }
75
        });
76
    }
77
78
    /**
79
     * Submit an intent to an internal executor.
80
     *
81
     * @param <T> Result type of the intended operation.
82
     * @param intent The intent to submit.
83
     *
84
     * @return {@link Future} object of the submitted task.
85
     */
86
    public static <T> Future<? extends T> submit(final Intent<T> intent) {
87
        return RP.submit(new Callable<T>() {
88
89
            @Override
90
            public T call() throws Exception {
91
                return intent.invoke();
92
            }
93
        });
94
    }
95
}
(-)a/api.intent/src/org/netbeans/api/intent/UriIntent.java (+76 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.intent;
43
44
import java.net.URI;
45
import org.netbeans.spi.intent.uri.OpenUriHandler;
46
import org.openide.util.Lookup;
47
48
/**
49
 * Intent described by a URI object.
50
 *
51
 * <p>
52
 * This is a package-private implementation returned by
53
 * {@link Intent#forUri(java.net.URI)}.
54
 * </p>
55
 *
56
 * @author jhavlin
57
 */
58
class UriIntent extends Intent<Boolean> {
59
60
    private final URI uri;
61
62
    UriIntent(URI uri) {
63
        this.uri = uri;
64
    }
65
66
    @Override
67
    Boolean invoke() {
68
        for (OpenUriHandler handler : Lookup.getDefault().lookupAll(
69
                OpenUriHandler.class)) {
70
            if (handler.open(uri)) {
71
                return true;
72
            }
73
        }
74
        return false;
75
    }
76
}
(-)a/api.intent/src/org/netbeans/spi/intent/uri/OpenUriHandler.java (+80 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.intent.uri;
43
44
import java.net.URI;
45
import org.netbeans.api.annotations.common.NonNull;
46
import org.netbeans.api.intent.Intent;
47
import org.openide.util.lookup.ServiceProvider;
48
49
/**
50
 * SPI for handlers that can process URI hyperlinks that were clicked in the
51
 * application (or somehow invoked).
52
 *
53
 * <p>
54
 * This is a handler for for intents created by
55
 * {@link Intent#forUri(java.net.URI)}.
56
 * </p>
57
 *
58
 * @see Intent#forUri(java.net.URI)
59
 * @author jhavlin
60
 */
61
public interface OpenUriHandler {
62
63
    /**
64
     * Handle the passed URI, if it is supported by this handler.
65
     *
66
     * <p>
67
     * To register a handler, use {@link ServiceProvider} annotation. Ensure
68
     * that {@link ServiceProvider#position()} is set properly.
69
     * </p>
70
     *
71
     * @param uri The URI to open.
72
     *
73
     * @return True if the URI has been handled succesfully, false if this
74
     * handler doesn't support it and thus it should be passed to next available
75
     * handler.
76
     *
77
     * @see Intent#forUri(java.net.URI)
78
     */
79
    boolean open(@NonNull URI uri);
80
}
(-)a/api.intent/test/unit/src/org/netbeans/api/intent/UriIntentTest.java (+99 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.intent;
43
44
import java.net.URI;
45
import java.net.URISyntaxException;
46
import java.util.concurrent.ExecutionException;
47
import java.util.concurrent.Future;
48
import org.junit.Test;
49
import static org.junit.Assert.*;
50
import org.netbeans.junit.MockServices;
51
import org.netbeans.spi.intent.uri.OpenUriHandler;
52
53
/**
54
 *
55
 * @author jhavlin
56
 */
57
public class UriIntentTest {
58
59
    @Test
60
    public void testOpenUri() throws URISyntaxException, InterruptedException,
61
            ExecutionException {
62
63
        Future<? extends Boolean> f = IntentManager.submit(Intent.forUri(
64
                new URI("test://a/b/c/")));
65
        assertFalse(f.get());
66
67
        MockServices.setServices(TestOpenUriHandler.class);
68
        try {
69
            assertFalse(TestOpenUriHandler.HANDLED);
70
            Future<? extends Boolean> res2 = IntentManager.submit(Intent.forUri(
71
                    new URI("test://a/b/c/")));
72
            assertTrue(res2.get());
73
            assertTrue(TestOpenUriHandler.HANDLED);
74
75
            Future<? extends Boolean> res3 = IntentManager.submit(Intent.forUri(
76
                    new URI("other://x/y/z/")));
77
            assertFalse(res3.get());
78
        } finally {
79
            MockServices.setServices();
80
        }
81
    }
82
83
    @SuppressWarnings("PublicInnerClass")
84
    public static class TestOpenUriHandler implements OpenUriHandler {
85
86
        @SuppressWarnings("PackageVisibleField")
87
        static boolean HANDLED = false;
88
89
        @Override
90
        public boolean open(URI uri) {
91
            if ("test".equals(uri.getScheme())) {
92
                HANDLED = true;
93
                return true;
94
            } else {
95
                return false;
96
            }
97
        }
98
    }
99
}
(-)a/api.io/arch.xml (+1188 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE api-answers PUBLIC "-//NetBeans//DTD Arch Answers//EN" "../nbbuild/antsrc/org/netbeans/nbbuild/Arch.dtd" [
3
  <!ENTITY api-questions SYSTEM "../nbbuild/antsrc/org/netbeans/nbbuild/Arch-api-questions.xml">
4
]>
5
6
<api-answers
7
  question-version="1.29"
8
  author="jhavlin@netbeans.org"
9
>
10
<!-- This file was based on arch.xml file in module openide.io. -->
11
12
  &api-questions;
13
14
15
    <!--
16
            <question id="arch-overall" when="init">
17
                Describe the overall architecture.
18
                <hint>
19
                What will be API for
20
                <a href="http://wiki.netbeans.org/API_Design#Separate_API_for_clients_from_support_API">
21
                    clients and what support API</a>?
22
                What parts will be pluggable?
23
                How will plug-ins be registered? Please use <code>&lt;api type="export"/&gt;</code>
24
                to describe your general APIs and specify their
25
                <a href="http://wiki.netbeans.org/API_Stability#Private">
26
                stability categories</a>.
27
                If possible please provide simple diagrams.
28
                </hint>
29
            </question>
30
    -->
31
    <answer id="arch-overall">
32
        <api
33
            name="NbInputOutputAPI"
34
            group="java"
35
            type="export"
36
            category="official"
37
            url="@org-netbeans-api-io@/org/netbeans/api/io/package-summary.html"
38
        >
39
            <p>
40
                The module contains APIs for creating output panes (e.g. output tabs in Output Window in the IDE)
41
                and for writing data into them. It also supports some advanced techniques, e.g. color text,
42
                hyperlinks, code folding, scrolling to stored positions.
43
            </p>
44
        </api>
45
        <api
46
            name="NbInputOutputSPI"
47
            group="java"
48
            type="export"
49
            category="official"
50
            url="@org-netbeans-api-io@/org/netbeans/spi/io/package-summary.html"
51
        >
52
            <p>
53
                SPI for providing custom implementations of output window is also included in this module, in package
54
                <code>org.netbeans.spi.io</code>
55
            </p>
56
        </api>
57
    </answer>
58
59
60
61
    <!--
62
            <question id="arch-quality" when="init">
63
                How will the <a href="http://www.netbeans.org/community/guidelines/q-evangelism.html">quality</a>
64
                of your code be tested and
65
                how are future regressions going to be prevented?
66
                <hint>
67
                What kind of testing do
68
                you want to use? How much functionality, in which areas,
69
                should be covered by the tests? How you find out that your
70
                project was successful?
71
                </hint>
72
            </question>
73
    -->
74
    <answer id="arch-quality">
75
        <p>
76
            Unit test will be prepared for invocable code in API classes. But most of the
77
            code is just definition of API and SPI.
78
        </p>
79
    </answer>
80
81
82
83
    <!--
84
            <question id="arch-time" when="init">
85
                What are the time estimates of the work?
86
                <hint>
87
                Please express your estimates of how long the design, implementation,
88
                stabilization are likely to last. How many people will be needed to
89
                implement this and what is the expected milestone by which the work should be
90
                ready?
91
                </hint>
92
            </question>
93
    -->
94
    <answer id="arch-time">
95
        <p>
96
            The design, implementation, preparing unit tests and reviews will
97
            probably take several weeks.
98
        </p>
99
    </answer>
100
101
102
103
<!--
104
        <question id="arch-usecases" when="init">
105
            <hint>
106
                Content of this answer will be displayed as part of page at
107
                http://www.netbeans.org/download/dev/javadoc/usecases.html
108
                You can use tags &lt;usecase name="name&gt; regular html description &lt;/usecase&gt;
109
                and if you want to use an URL you can prefix if with @TOP@ to begin
110
                at the root of your javadoc
111
            </hint>
112
113
                Describe the main <a href="http://wiki.netbeans.org/API_Design#The_Importance_of_Being_Use_Case_Oriented">
114
                use cases</a> of the new API. Who will use it under
115
                what circumstances? What kind of code would typically need to be written
116
                to use the module?
117
            </question>
118
    -->
119
    <answer id="arch-usecases">
120
121
        <usecase id="print" name="Print a simple output to a new output tab">
122
            <p>
123
                The basic use-case is printing a simple text, e.g. text output of an application,
124
                into a dedicated pane in the UI, e.g. a tab in Output Window in the IDE.
125
            </p>
126
            <pre>
127
    InputOutput io = InputOutput.get("UseCase1", true);
128
    io.getOut().println("This is a simple output");
129
    io.getOut().close();
130
            </pre>
131
        </usecase>
132
133
        <usecase id="printUriHyperlink" name="Reuse existing tab and print a line containing a hyperlink for a URI">
134
            <p>
135
                Implementations can support hyperlinks. If the hyperlink is defined by a URI,
136
                it will be opened by the UI part of the application when the hyperlink is clicked
137
                in the output window. The following example will open a file and place the cursor
138
                at line and column specified by query part of the URI (after question mark).
139
            </p>
140
            <pre>
141
    InputOutput io = InputOutput.get("UseCase2", false);
142
    io.getOut().print("A line containing a ");
143
    io.getOut().print("hyperlink", Hyperlink.forURI(new URI("file://n:/test/Test.java?line=4&amp;col=2")));
144
    io.getOut().println(" for a URI.");
145
    io.getOut().close();
146
            </pre>
147
        </usecase>
148
149
        <usecase id="printOnClickHyperlink" name="Print a line with hyperlink for invocation of arbitrary code">
150
            <p>
151
                Hyperlinks can be also used to invoke some code when clicked.
152
            </p>
153
            <pre>
154
    InputOutput io = InputOutput.get("UseCase3", true);
155
    io.getOut().print("A line containing a ");
156
    io.getOut().print("hyperlink", Hyperlink.onClick(new Runnable() {
157
        public void run() {
158
            System.gc();
159
        }
160
    }));
161
    io.getOut().println(" for invocation of custom code.");
162
    io.getOut().close();
163
            </pre>
164
        </usecase>
165
166
        <usecase id="printColor" name="Print color text">
167
            <p>
168
                Print a color text. Users can select a predefined color for
169
                common cases (debug, warning, failure, success), or custom
170
                color specified as RGB value.
171
            </p>
172
            <pre>
173
    InputOutput io = InputOutput.get("UseCase4", true);
174
    io.getOut().println("Let's print some info", OutputColor.debug());
175
    io.getOut().println("or warning with appropriate color", OutputColor.warning());
176
    io.getOut().println("Maybe also text with custom reddish color", OutputColor.rgb(255, 16, 16));
177
    io.getOut().close();
178
            </pre>
179
        </usecase>
180
181
        <usecase id="printAndReset" name="Reset an InputOutput to clear all previosly printed text">
182
            <p>
183
                It is possible to reuse already created output pane and clear
184
                all the previously printed text if it is not needed any more.
185
            </p>
186
            <pre>
187
    InputOutput io = InputOutput.get("UseCase5", true);
188
    io.getOut().println("Let's print some text");
189
    io.getErr().println("and reset the pane immediately.");
190
    io.reset();
191
    io.getOut().println("The pane is now empty and we can reuse it simply");
192
    io.getOut().close();
193
            </pre>
194
        </usecase>
195
196
    </answer>
197
198
199
200
    <!--
201
            <question id="arch-what" when="init">
202
                What is this project good for?
203
                <hint>
204
                Please provide here a few lines describing the project, 
205
                what problem it should solve, provide links to documentation, 
206
                specifications, etc.
207
                </hint>
208
            </question>
209
    -->
210
    <answer id="arch-what">
211
        <p>
212
            The Input/Output API and SPI is a small module
213
            which contains <code>InputOutput</code> and related interfaces used in
214
            driving the Output Window.
215
        </p>
216
        <p>
217
            The normal implementation is <code>org.netbeans.core.output2</code>.
218
        </p>
219
    </answer>
220
221
222
223
    <!--
224
            <question id="arch-where" when="impl">
225
                Where one can find sources for your module?
226
                <hint>
227
                    Please provide link to the Hg web client at
228
                    http://hg.netbeans.org/
229
                    or just use tag defaultanswer generate='here'
230
                </hint>
231
            </question>
232
    -->
233
    <answer id="arch-where">
234
        <defaultanswer generate='here' />
235
    </answer>
236
237
238
239
    <!--
240
            <question id="compat-deprecation" when="init">
241
                How the introduction of your project influences functionality
242
                provided by previous version of the product?
243
                <hint>
244
                If you are planning to deprecate/remove/change any existing APIs,
245
                list them here accompanied with the reason explaining why you
246
                are doing so.
247
                </hint>
248
            </question>
249
    -->
250
    <answer id="compat-deprecation">
251
        <p>
252
            Backward compatibility of other modules is not broken.
253
        </p>
254
        <p>
255
            This module should replace original I/O API module
256
            <code>org.openide.io</code>, which has the same goals, but which is
257
            not UI independent, and which is difficult to extend.
258
        </p>
259
    </answer>
260
261
262
263
    <!--
264
            <question id="compat-i18n" when="impl">
265
                Is your module correctly internationalized?
266
                <hint>
267
                Correct internationalization means that it obeys instructions
268
                at <a href="http://www.netbeans.org/download/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/i18n-branding.html">
269
                NetBeans I18N pages</a>.
270
                </hint>
271
            </question>
272
    -->
273
    <answer id="compat-i18n">
274
        <p>
275
            Yes. There is not much to internationalize.
276
        </p>
277
    </answer>
278
279
280
281
    <!--
282
            <question id="compat-standards" when="init">
283
                Does the module implement or define any standards? Is the 
284
                implementation exact or does it deviate somehow?
285
            </question>
286
    -->
287
    <answer id="compat-standards">
288
        <p>
289
            The module defines an API.
290
        </p>
291
    </answer>
292
293
294
295
    <!--
296
        <question id="compat-version" when="impl">
297
            Can your module coexist with earlier and future
298
            versions of itself? Can you correctly read all old settings? Will future
299
            versions be able to read your current settings? Can you read
300
            or politely ignore settings stored by a future version?
301
302
                <hint>
303
                Very helpful for reading settings is to store version number
304
                there, so future versions can decide whether how to read/convert
305
                the settings and older versions can ignore the new ones.
306
                </hint>
307
            </question>
308
    -->
309
    <answer id="compat-version">
310
        <p>
311
            N/A. No settings are read or written by this module.
312
        </p>
313
    </answer>
314
315
316
317
    <!--
318
            <question id="dep-jre" when="final">
319
                Which version of JRE do you need (1.2, 1.3, 1.4, etc.)?
320
                <hint>
321
                It is expected that if your module runs on 1.x that it will run 
322
                on 1.x+1 if no, state that please. Also describe here cases where
323
                you run different code on different versions of JRE and why.
324
                </hint>
325
            </question>
326
    -->
327
    <answer id="dep-jre">
328
        1.7
329
    </answer>
330
331
332
333
    <!--
334
            <question id="dep-jrejdk" when="final">
335
                Do you require the JDK or is the JRE enough?
336
            </question>
337
    -->
338
    <answer id="dep-jrejdk">
339
        JRE
340
    </answer>
341
342
343
344
    <!--
345
            <question id="dep-nb" when="init">
346
                What other NetBeans projects and modules does this one depend on?
347
                <hint>
348
                Depending on other NetBeans projects influnces the ability of
349
                users of your work to customize their own branded version of
350
                NetBeans by enabling and disabling some modules. Too
351
                much dependencies restrict this kind of customization. If that
352
                is your case, then you may want to split your functionality into
353
                pieces of autoload, eager and regular modules which can be
354
                enabled independently. Usually the answer to this question
355
                is generated from your <code>project.xml</code> file, but
356
                if it is not guessed correctly, you can suppress it by
357
                specifying &lt;defaultanswer generate="none"/&gt; and
358
                write here your own. Please describe such projects as imported APIs using
359
                the <code>&lt;api name="identification" type="import or export" category="stable" url="where is the description" /&gt;</code>.
360
                By doing this information gets listed in the summary page of your
361
                javadoc.
362
                </hint>
363
            </question>
364
    -->
365
    <answer id="dep-nb">
366
        <defaultanswer generate='here' />
367
    </answer>
368
369
370
371
<!--
372
        <question id="dep-non-nb" when="init">
373
            What other projects outside NetBeans does this one depend on?
374
375
                <hint>
376
                Depending on 3rd party libraries is always problematic,
377
                especially if they are not open source, as that complicates
378
                the licensing scheme of NetBeans. Please enumerate your
379
                external dependencies here, so it is correctly understood since
380
                the begining what are the legal implications of your project.
381
                Also please note that
382
                some non-NetBeans projects are packaged as NetBeans modules
383
                (see <a href="http://libs.netbeans.org/">libraries</a>) and
384
                it is preferred to use this approach when more modules may
385
                depend and share such third-party libraries.
386
                </hint>
387
            </question>
388
    -->
389
    <answer id="dep-non-nb">
390
        None.
391
    </answer>
392
393
394
395
    <!--
396
            <question id="dep-platform" when="init">
397
                On which platforms does your module run? Does it run in the same
398
                way on each?
399
                <hint>
400
                If you plan any dependency on OS or any usage of native code,
401
                please describe why you are doing so and describe how you envision
402
                to enforce the portability of your code.
403
                Please note that there is a support for <a href="http://www.netbeans.org/download/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#how-os-specific">OS conditionally
404
                enabled modules</a> which together with autoload/eager modules
405
                can allow you to enable to provide the best OS aware support
406
                on certain OSes while providing compatibility bridge on the not
407
                supported ones.
408
                Also please list the supported
409
                OSes/HW platforms and mentioned the lovest version of JDK required
410
                for your project to run on. Also state whether JRE is enough or
411
                you really need JDK.
412
                </hint>
413
            </question>
414
    -->
415
    <answer id="dep-platform">
416
        Any.
417
    </answer>
418
419
420
421
    <!--
422
            <question id="deploy-dependencies" when="final">
423
                What do other modules need to do to declare a dependency on this one,
424
                in addition to or instead of the normal module dependency declaration
425
                (e.g. tokens to require)?
426
                <hint>
427
                    Provide a sample of the actual lines you would add to a module manifest
428
                    to declare a dependency, for example OpenIDE-Module-Requires: some.token.
429
                    If other modules should not depend on this module, or should just use a
430
                    simple regular module dependency, you can just answer "nothing". If you
431
                    intentionally expose a semistable API to clients using implementation
432
                    dependencies, you should mention that here (but there is no need to give
433
                    an example of usage).
434
                </hint>
435
            </question>
436
    -->
437
    <answer id="deploy-dependencies">
438
        <p>
439
            Normal module dependency is enough.
440
        </p>
441
        <p>
442
            Availability of some implementation of the SPI is guaranteed by
443
            "OpenIDE-Module-Needs: org.netbeans.spi.io.InputOutputProvider" in
444
            the manifest of this module.
445
        </p>
446
    </answer>
447
448
449
450
    <!--
451
        <question id="deploy-jar" when="impl">
452
            Do you deploy just module JAR file(s) or other files as well?
453
            <hint>
454
            Usually a module consist of one JAR file (perhaps with Class-Path
455
            extensions) and also a configuration file that enables it. If you
456
            have any other files, use
457
            &lt;api group="java.io.File" name="yourname" type="export" category="friend"&gt;...&lt;/api&gt;
458
            to define the location, name and stability of your files (of course
459
            changing "yourname" and "friend" to suit your needs).
460
461
                If it uses more than one JAR, describe where they are located, how
462
                they refer to each other.
463
                If it consist of module JAR(s) and other files, please describe
464
                what is their purpose, why other files are necessary. Please
465
                make sure that installation/uninstallation leaves the system
466
                in state as it was before installation.
467
                </hint>
468
            </question>
469
    -->
470
    <answer id="deploy-jar">
471
        <p>
472
            Just the module JAR.
473
        </p>
474
    </answer>
475
476
477
478
    <!--
479
            <question id="deploy-nbm" when="impl">
480
                Can you deploy an NBM via the Update Center?
481
                <hint>
482
                If not why?
483
                </hint>
484
            </question>
485
    -->
486
    <answer id="deploy-nbm">
487
        <p>
488
            Yes.
489
        </p>
490
    </answer>
491
492
493
494
    <!--
495
        <question id="deploy-packages" when="init">
496
            Are packages of your module made inaccessible by not declaring them
497
            public?
498
499
                <hint>
500
                By default NetBeans build harness treats all packages are private.
501
                If you export some of them - either as public or friend packages,
502
                you should have a reason. If the reason is described elsewhere
503
                in this document, you can ignore this question.
504
                </hint>
505
            </question>
506
    -->
507
    <answer id="deploy-packages">
508
        <p>
509
            No; only API classes are public.
510
        </p>
511
    </answer>
512
513
514
515
    <!--
516
            <question id="deploy-shared" when="final">
517
                Do you need to be installed in the shared location only, or in the user directory only,
518
                or can your module be installed anywhere?
519
                <hint>
520
                Installation location shall not matter, if it does explain why.
521
                Consider also whether <code>InstalledFileLocator</code> can help.
522
                </hint>
523
            </question>
524
    -->
525
    <answer id="deploy-shared">
526
        <p>
527
            Anywhere.
528
        </p>
529
    </answer>
530
531
532
533
    <!--
534
        <question id="exec-ant-tasks" when="impl">
535
            Do you define or register any ant tasks that other can use?
536
537
                <hint>
538
                If you provide an ant task that users can use, you need to be very
539
                careful about its syntax and behaviour, as it most likely forms an
540
                      API for end users and as there is a lot of end users, their reaction
541
                when such API gets broken can be pretty strong.
542
                </hint>
543
            </question>
544
    -->
545
    <answer id="exec-ant-tasks">
546
        <p>
547
            No.
548
        </p>
549
    </answer>
550
551
552
553
    <!--
554
            <question id="exec-classloader" when="impl">
555
                Does your code create its own class loader(s)?
556
                <hint>
557
                A bit unusual. Please explain why and what for.
558
                </hint>
559
            </question>
560
    -->
561
    <answer id="exec-classloader">
562
        <p>
563
            No.
564
        </p>
565
    </answer>
566
567
568
569
    <!--
570
        <question id="exec-component" when="impl">
571
            Is execution of your code influenced by any (string) property
572
            of any of your components?
573
574
                <hint>
575
                Often <code>JComponent.getClientProperty</code>, <code>Action.getValue</code>
576
                or <code>PropertyDescriptor.getValue</code>, etc. are used to influence
577
                a behavior of some code. This of course forms an interface that should
578
                be documented. Also if one depends on some interface that an object
579
                implements (<code>component instanceof Runnable</code>) that forms an
580
                API as well.
581
                </hint>
582
            </question>
583
    -->
584
    <answer id="exec-component">
585
        <p>
586
            No.
587
        </p>
588
    </answer>
589
590
591
592
    <!--
593
            <question id="exec-introspection" when="impl">
594
                Does your module use any kind of runtime type information (<code>instanceof</code>,
595
                work with <code>java.lang.Class</code>, etc.)?
596
                <hint>
597
                Check for cases when you have an object of type A and you also
598
                expect it to (possibly) be of type B and do some special action. That
599
                should be documented. The same applies on operations in meta-level
600
                (Class.isInstance(...), Class.isAssignableFrom(...), etc.).
601
                </hint>
602
            </question>
603
    -->
604
    <answer id="exec-introspection">
605
        <p>
606
            No.
607
        </p>
608
    </answer>
609
610
611
612
    <!--
613
            <question id="exec-privateaccess" when="final">
614
                Are you aware of any other parts of the system calling some of 
615
                your methods by reflection?
616
                <hint>
617
                If so, describe the "contract" as an API. Likely private or friend one, but
618
                still API and consider rewrite of it.
619
                </hint>
620
            </question>
621
    -->
622
    <answer id="exec-privateaccess">
623
        <p>
624
            No.
625
        </p>
626
    </answer>
627
628
629
630
    <!--
631
            <question id="exec-process" when="impl">
632
                Do you execute an external process from your module? How do you ensure
633
                that the result is the same on different platforms? Do you parse output?
634
                Do you depend on result code?
635
                <hint>
636
                If you feed an input, parse the output please declare that as an API.
637
                </hint>
638
            </question>
639
    -->
640
    <answer id="exec-process">
641
        <p>
642
            No.
643
        </p>
644
    </answer>
645
646
647
648
    <!--
649
            <question id="exec-property" when="impl">
650
                Is execution of your code influenced by any environment or
651
                Java system (<code>System.getProperty</code>) property?
652
                On a similar note, is there something interesting that you
653
                pass to <code>java.util.logging.Logger</code>? Or do you observe
654
                what others log?
655
                <hint>
656
                If there is a property that can change the behavior of your 
657
                code, somebody will likely use it. You should describe what it does 
658
                and the <a href="http://wiki.netbeans.org/API_Stability">stability category</a>
659
                of this API. You may use
660
                <pre>
661
                    &lt;api type="export" group="property" name="id" category="private" url="http://..."&gt;
662
                        description of the property, where it is used, what it influence, etc.
663
                    &lt;/api&gt;
664
                </pre>
665
                </hint>
666
            </question>
667
    -->
668
    <answer id="exec-property">
669
        <p>
670
            No.
671
        </p>
672
    </answer>
673
674
675
676
    <!--
677
            <question id="exec-reflection" when="impl">
678
                Does your code use Java Reflection to execute other code?
679
                <hint>
680
                This usually indicates a missing or insufficient API in the other
681
                part of the system. If the other side is not aware of your dependency
682
                this contract can be easily broken.
683
                </hint>
684
            </question>
685
    -->
686
    <answer id="exec-reflection">
687
        <p>
688
            No.
689
        </p>
690
    </answer>
691
692
693
694
    <!--
695
            <question id="exec-threading" when="init">
696
                What threading models, if any, does your module adhere to? How the
697
                project behaves with respect to threading?
698
                <hint>
699
                    Is your API threadsafe? Can it be accessed from any threads or
700
                    just from some dedicated ones? Any special relation to AWT and
701
                    its Event Dispatch thread? Also
702
                    if your module calls foreign APIs which have a specific threading model,
703
                    indicate how you comply with the requirements for multithreaded access
704
                    (synchronization, mutexes, etc.) applicable to those APIs.
705
                    If your module defines any APIs, or has complex internal structures
706
                    that might be used from multiple threads, declare how you protect
707
                    data against concurrent access, race conditions, deadlocks, etc.,
708
                    and whether such rules are enforced by runtime warnings, errors, assertions, etc.
709
                    Examples: a class might be non-thread-safe (like Java Collections); might
710
                    be fully thread-safe (internal locking); might require access through a mutex
711
                    (and may or may not automatically acquire that mutex on behalf of a client method);
712
                    might be able to run only in the event queue; etc.
713
                    Also describe when any events are fired: synchronously, asynchronously, etc.
714
                    Ideas: <a href="http://core.netbeans.org/proposals/threading/index.html#recommendations">Threading Recommendations</a> (in progress)
715
                </hint>
716
            </question>
717
    -->
718
    <answer id="exec-threading">
719
        <p>
720
            API classes are thread safe, they mostly represent immutable
721
            objects, or delegate to the SPI.
722
        </p>
723
        <p>
724
            Implementators of the SPI should ensure that their code is properly
725
            synchronized, as it can be called from any thread.
726
        </p>
727
    </answer>
728
729
730
731
<!--
732
        <question id="format-clipboard" when="impl">
733
            Which data flavors (if any) does your code read from or insert to
734
            the clipboard (by access to clipboard on means calling methods on <code>java.awt.datatransfer.Transferable</code>?
735
736
                <hint>
737
                Often Node's deal with clipboard by usage of <code>Node.clipboardCopy, Node.clipboardCut and Node.pasteTypes</code>.
738
                Check your code for overriding these methods.
739
                </hint>
740
            </question>
741
    -->
742
    <answer id="format-clipboard">
743
        <p>
744
            Plain Unicode text only.
745
        </p>
746
    </answer>
747
748
749
750
    <!--
751
            <question id="format-dnd" when="impl">
752
                Which protocols (if any) does your code understand during Drag &amp; Drop?
753
                <hint>
754
                Often Node's deal with clipboard by usage of <code>Node.drag, Node.getDropType</code>. 
755
                Check your code for overriding these methods. Btw. if they are not overridden, they
756
                by default delegate to <code>Node.clipboardCopy, Node.clipboardCut and Node.pasteTypes</code>.
757
                </hint>
758
            </question>
759
    -->
760
    <answer id="format-dnd">
761
        <p>
762
            N/A
763
        </p>
764
    </answer>
765
766
767
768
    <!--
769
        <question id="format-types" when="impl">
770
            Which protocols and file formats (if any) does your module read or write on disk,
771
            or transmit or receive over the network? Do you generate an ant build script?
772
            Can it be edited and modified?
773
774
            <hint>
775
                <p>
776
                Files can be read and written by other programs, modules and users. If they influence
777
                your behaviour, make sure you either document the format or claim that it is a private
778
                api (using the &lt;api&gt; tag).
779
                </p>
780
                <p>
781
                If you generate an ant build file, this is very likely going to be seen by end users and
782
                they will be attempted to edit it. You should be ready for that and provide here a link
783
                to documentation that you have for such purposes and also describe how you are going to
784
                understand such files during next release, when you (very likely) slightly change the 
785
                format.
786
                </p>
787
            </hint>
788
        </question>
789
    -->
790
    <answer id="format-types">
791
        <p>
792
            None.
793
        </p>
794
    </answer>
795
796
797
798
    <!--
799
        <question id="lookup-lookup" when="init">
800
            Does your module use <code>org.openide.util.Lookup</code>
801
            or any similar technology to find any components to communicate with? Which ones?
802
803
                <hint>
804
                NetBeans is build around a generic registry of services called
805
                lookup. It is preferable to use it for registration and discovery
806
                if possible. See
807
                <a href="http://www.netbeans.org/download/dev/javadoc/org-openide-util/org/openide/util/lookup/doc-files/index.html">
808
                The Solution to Comunication Between Components
809
                </a>. If you do not plan to use lookup and insist usage
810
                of other solution, then please describe why it is not working for
811
                you.
812
                <br/>
813
                When filling the final version of your arch document, please
814
                describe the interfaces you are searching for, where 
815
                are defined, whether you are searching for just one or more of them,
816
                if the order is important, etc. Also classify the stability of such
817
                API contract. Use &lt;api group=&amp;lookup&amp; /&gt; tag, so
818
                your information gets listed in the summary page of your javadoc.
819
                </hint>
820
            </question>
821
    -->
822
    <answer id="lookup-lookup">
823
        <p>
824
            <code>IOProvider.getDefault()</code> asks lookup for the first instance
825
            of <code>InputOutputProvider</code>. This is normally provided by
826
            <code>org.netbeans.core.output2</code>.
827
        </p>
828
    </answer>
829
830
831
832
    <!--
833
            <question id="lookup-register" when="final">
834
                Do you register anything into lookup for other code to find?
835
                <hint>
836
                Do you register using layer file or using a declarative annotation such as <code>@ServiceProvider</code>?
837
                Who is supposed to find your component?
838
                </hint>
839
            </question>
840
    -->
841
    <answer id="lookup-register">
842
        <p>
843
            No.
844
        </p>
845
    </answer>
846
847
848
849
    <!--
850
            <question id="lookup-remove" when="final">
851
                Do you remove entries of other modules from lookup?
852
                <hint>
853
                Why? Of course, that is possible, but it can be dangerous. Is the module
854
                your are masking resource from aware of what you are doing?
855
                </hint>
856
            </question>
857
    -->
858
    <answer id="lookup-remove">
859
        <p>
860
            No.
861
        </p>
862
    </answer>
863
864
865
866
    <!--
867
            <question id="perf-exit" when="final">
868
                Does your module run any code on exit?
869
            </question>
870
    -->
871
    <answer id="perf-exit">
872
        <p>
873
            No.
874
        </p>
875
    </answer>
876
877
878
879
    <!--
880
            <question id="perf-huge_dialogs" when="final">
881
                Does your module contain any dialogs or wizards with a large number of
882
                GUI controls such as combo boxes, lists, trees, or text areas?
883
            </question>
884
    -->
885
    <answer id="perf-huge_dialogs">
886
        <p>
887
            No.
888
        </p>
889
    </answer>
890
891
892
893
    <!--
894
            <question id="perf-limit" when="init">
895
                Are there any hard-coded or practical limits in the number or size of
896
                elements your code can handle?
897
                <hint>
898
                    Most of algorithms have increasing memory and speed complexity
899
                    with respect to size of data they operate on. What is the critical
900
                    part of your project that can be seen as a bottleneck with
901
                    respect to speed or required memory? What are the practical
902
                    sizes of data you tested your project with? What is your estimate
903
                    of potential size of data that would cause visible performance
904
                    problems? Is there some kind of check to detect such situation
905
                    and prevent "hard" crashes - for example the CloneableEditorSupport
906
                    checks for size of a file to be opened in editor
907
                    and if it is larger than 1Mb it shows a dialog giving the
908
                    user the right to decide - e.g. to cancel or commit suicide.
909
                </hint>
910
            </question>
911
    -->
912
    <answer id="perf-limit">
913
        <p>
914
            No.
915
        </p>
916
    </answer>
917
918
919
920
    <!--
921
            <question id="perf-mem" when="final">
922
                How much memory does your component consume? Estimate
923
                with a relation to the number of windows, etc.
924
            </question>
925
    -->
926
    <answer id="perf-mem">
927
        <p>
928
            N/A
929
        </p>
930
    </answer>
931
932
933
934
    <!--
935
            <question id="perf-menus" when="final">
936
                Does your module use dynamically updated context menus, or
937
                context-sensitive actions with complicated and slow enablement logic?
938
                <hint>
939
                    If you do a lot of tricks when adding actions to regular or context menus, you can significantly
940
                    slow down display of the menu, even when the user is not using your action. Pay attention to
941
                    actions you add to the main menu bar, and to context menus of foreign nodes or components. If
942
                    the action is conditionally enabled, or changes its display dynamically, you need to check the
943
                    impact on performance. In some cases it may be more appropriate to make a simple action that is
944
                    always enabled but does more detailed checks in a dialog if it is actually run.
945
                </hint>
946
            </question>
947
    -->
948
    <answer id="perf-menus">
949
        <p>
950
            No.
951
        </p>
952
    </answer>
953
954
955
956
    <!--
957
        <question id="perf-progress" when="final">
958
            Does your module execute any long-running tasks?
959
960
                <hint>Long running tasks should never block
961
                AWT thread as it badly hurts the UI
962
                <a href="http://performance.netbeans.org/responsiveness/issues.html">
963
                responsiveness</a>.
964
                Tasks like connecting over
965
                network, computing huge amount of data, compilation
966
                be done asynchronously (for example
967
                using <code>RequestProcessor</code>), definitively it should
968
                not block AWT thread.
969
                </hint>
970
            </question>
971
    -->
972
    <answer id="perf-progress">
973
        <p>
974
            No.
975
        </p>
976
    </answer>
977
978
979
980
    <!--
981
            <question id="perf-scale" when="init">
982
                Which external criteria influence the performance of your
983
                program (size of file in editor, number of files in menu,
984
                in source directory, etc.) and how well your code scales?
985
                <hint>
986
                Please include some estimates, there are other more detailed
987
                questions to answer in later phases of implementation.`
988
                </hint>
989
            </question>
990
    -->
991
    <answer id="perf-scale">
992
        <p>
993
            Scalability in GUI speed and memory consumption is probably limited
994
            only by the Output Window implementation.
995
        </p>
996
    </answer>
997
998
999
1000
    <!--
1001
            <question id="perf-spi" when="init">
1002
                How the performance of the plugged in code will be enforced?
1003
                <hint>
1004
                If you allow foreign code to be plugged into your own module, how
1005
                do you enforce that it will behave correctly and quickly and will not
1006
                negatively influence the performance of your own module?
1007
                </hint>
1008
            </question>
1009
    -->
1010
    <answer id="perf-spi">
1011
        <p>
1012
            No special behavior.
1013
        </p>
1014
    </answer>
1015
1016
1017
1018
    <!--
1019
            <question id="perf-startup" when="final">
1020
                Does your module run any code on startup?
1021
            </question>
1022
    -->
1023
    <answer id="perf-startup">
1024
        <p>
1025
            No.
1026
        </p>
1027
    </answer>
1028
1029
1030
1031
    <!--
1032
            <question id="perf-wakeup" when="final">
1033
                Does any piece of your code wake up periodically and do something
1034
                even when the system is otherwise idle (no user interaction)?
1035
            </question>
1036
    -->
1037
    <answer id="perf-wakeup">
1038
        <p>
1039
            No.
1040
        </p>
1041
    </answer>
1042
1043
1044
1045
    <!--
1046
        <question id="resources-file" when="final">
1047
            Does your module use <code>java.io.File</code> directly?
1048
1049
                <hint>
1050
                NetBeans provide a logical wrapper over plain files called
1051
                <code>org.openide.filesystems.FileObject</code> that
1052
                provides uniform access to such resources and is the preferred
1053
                way that should be used. But of course there can be situations when
1054
                this is not suitable.
1055
                </hint>
1056
            </question>
1057
    -->
1058
    <answer id="resources-file">
1059
        <p>
1060
            No, but the implementation may.
1061
        </p>
1062
    </answer>
1063
1064
1065
1066
    <!--
1067
        <question id="resources-layer" when="final">
1068
            Does your module provide own layer? Does it create any files or
1069
            folders in it? What it is trying to communicate by that and with which 
1070
            components?
1071
1072
                <hint>
1073
                NetBeans allows automatic and declarative installation of resources 
1074
                by module layers. Module register files into appropriate places
1075
                and other components use that information to perform their task
1076
                (build menu, toolbar, window layout, list of templates, set of
1077
                options, etc.).
1078
                </hint>
1079
            </question>
1080
    -->
1081
    <answer id="resources-layer">
1082
        <p>
1083
            No.
1084
        </p>
1085
    </answer>
1086
1087
1088
1089
    <!--
1090
        <question id="resources-mask" when="final">
1091
            Does your module mask/hide/override any resources provided by other modules in
1092
            their layers?
1093
1094
                <hint>
1095
                If you mask a file provided by another module, you probably depend
1096
                on that and do not want the other module to (for example) change
1097
                the file's name. That module shall thus make that file available as an API
1098
                of some stability category.
1099
                </hint>
1100
            </question>
1101
    -->
1102
    <answer id="resources-mask">
1103
        <p>
1104
            No.
1105
        </p>
1106
    </answer>
1107
1108
1109
1110
    <!--
1111
            <question id="resources-preferences" when="final">
1112
                Does your module uses preferences via Preferences API? Does your module use NbPreferences or
1113
                or regular JDK Preferences ? Does it read, write or both ?
1114
                Does it share preferences with other modules ? If so, then why ?
1115
                <hint>
1116
                    You may use
1117
                        &lt;api type="export" group="preferences"
1118
                        name="preference node name" category="private"&gt;
1119
                        description of individual keys, where it is used, what it
1120
                        influences, whether the module reads/write it, etc.
1121
                        &lt;/api&gt;
1122
                    Due to XML ID restrictions, rather than /org/netbeans/modules/foo give the "name" as org.netbeans.modules.foo.
1123
                    Note that if you use NbPreferences this name will then be the same as the code name base of the module.
1124
                </hint>
1125
            </question>
1126
    -->
1127
    <answer id="resources-preferences">
1128
        <p>
1129
            No.
1130
        </p>
1131
    </answer>
1132
1133
1134
1135
    <!--
1136
        <question id="resources-read" when="final">
1137
            Does your module read any resources from layers? For what purpose?
1138
1139
                <hint>
1140
                As this is some kind of intermodule dependency, it is a kind of API.
1141
                Please describe it and classify according to
1142
                <a href="http://wiki.netbeans.org/API_Design#What_is_an_API.3F">
1143
                common stability categories</a>.
1144
                </hint>
1145
            </question>
1146
    -->
1147
    <answer id="resources-read">
1148
        <p>
1149
            No.
1150
        </p>
1151
    </answer>
1152
1153
1154
1155
    <!--
1156
            <question id="security-grant" when="final">
1157
                Does your code grant additional rights to some other code?
1158
                <hint>Avoid using a class loader that adds extra
1159
                permissions to loaded code unless really necessary.
1160
                Also note that your API implementation
1161
                can also expose unneeded permissions to enemy code by
1162
                calling AccessController.doPrivileged().</hint>
1163
            </question>
1164
    -->
1165
    <answer id="security-grant">
1166
        <p>
1167
            No.
1168
        </p>
1169
    </answer>
1170
1171
1172
1173
    <!--
1174
            <question id="security-policy" when="final">
1175
                Does your functionality require modifications to the standard policy file?
1176
                <hint>Your code might pass control to third-party code not
1177
                coming from trusted domains. This could be code downloaded over the
1178
                network or code coming from libraries that are not bundled
1179
                with NetBeans. Which permissions need to be granted to which domains?</hint>
1180
            </question>
1181
    -->
1182
    <answer id="security-policy">
1183
        <p>
1184
            No.
1185
        </p>
1186
    </answer>
1187
1188
</api-answers>
(-)a/api.io/build.xml (+5 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project basedir="." default="netbeans" name="api.io">
3
    <description>Builds, tests, and runs the project org.netbeans.api.io</description>
4
    <import file="../nbbuild/templates/projectized.xml"/>
5
</project>
(-)a/api.io/manifest.mf (+6 lines)
Line 0 Link Here
1
Manifest-Version: 1.0
2
AutoUpdate-Show-In-Client: true
3
OpenIDE-Module: org.netbeans.api.io
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/io/Bundle.properties
5
OpenIDE-Module-Specification-Version: 1.0
6
OpenIDE-Module-Needs: org.netbeans.spi.io.InputOutputProvider
(-)a/api.io/nbproject/project.properties (+4 lines)
Line 0 Link Here
1
is.autoload=true
2
javac.source=1.6
3
javac.compilerargs=-Xlint -Xlint:-serial
4
javadoc.arch=${basedir}/arch.xml
(-)a/api.io/nbproject/project.xml (+54 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://www.netbeans.org/ns/project/1">
3
    <type>org.netbeans.modules.apisupport.project</type>
4
    <configuration>
5
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
6
            <code-name-base>org.netbeans.api.io</code-name-base>
7
            <module-dependencies>
8
                <dependency>
9
                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
10
                    <build-prerequisite/>
11
                    <compile-dependency/>
12
                    <run-dependency>
13
                        <release-version>1</release-version>
14
                        <specification-version>1.25</specification-version>
15
                    </run-dependency>
16
                </dependency>
17
                <dependency>
18
                    <code-name-base>org.openide.util.base</code-name-base>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
21
                    <run-dependency>
22
                        <specification-version>9.1</specification-version>
23
                    </run-dependency>
24
                </dependency>
25
                <dependency>
26
                    <code-name-base>org.openide.util.lookup</code-name-base>
27
                    <build-prerequisite/>
28
                    <compile-dependency/>
29
                    <run-dependency>
30
                        <specification-version>8.26</specification-version>
31
                    </run-dependency>
32
                </dependency>
33
            </module-dependencies>
34
            <test-dependencies>
35
                <test-type>
36
                    <name>unit</name>
37
                    <test-dependency>
38
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
39
                        <compile-dependency/>
40
                    </test-dependency>
41
                    <test-dependency>
42
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
43
                        <compile-dependency/>
44
                    </test-dependency>
45
                </test-type>
46
            </test-dependencies>
47
            <public-packages>
48
                <package>org.netbeans.api.io</package>
49
                <package>org.netbeans.spi.io</package>
50
                <package>org.netbeans.spi.io.support</package>
51
            </public-packages>
52
        </data>
53
    </configuration>
54
</project>
(-)a/api.io/src/org/netbeans/api/io/Bundle.properties (+6 lines)
Line 0 Link Here
1
OpenIDE-Module-Display-Category=Infrastructure
2
OpenIDE-Module-Long-Description=\
3
    API classes for creating output panes (e.g. tabs in output window) and for writing data into them.\n\
4
    SPI for custom implementations of output window.
5
OpenIDE-Module-Name=I/O API and SPI
6
OpenIDE-Module-Short-Description=APIs and SPIs related to displaying output.
(-)a/api.io/src/org/netbeans/api/io/Fold.java (+131 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import java.io.PrintWriter;
45
import org.netbeans.spi.io.InputOutputProvider;
46
47
/**
48
 * A fold (nested or standalone) in the output window.
49
 *
50
 * <p>
51
 * Methods of this class can be called in any thread.
52
 * </p>
53
 *
54
 * @author jhavlin
55
 */
56
public abstract class Fold {
57
58
    static final Fold UNSUPPORTED = new Fold() {
59
60
        @Override
61
        public void setExpanded(boolean expanded) {
62
        }
63
64
        @Override
65
        void endFold() {
66
        }
67
    };
68
69
    private Fold() {
70
    }
71
72
    static <IO, OW extends PrintWriter, P, F> Fold create(
73
            InputOutputProvider<IO, OW, P, F> provider, IO io, OW writer,
74
            F fold) {
75
        if (fold == null) {
76
            return UNSUPPORTED;
77
        } else {
78
            return new Impl<IO, OW, P, F>(provider, io, writer, fold);
79
        }
80
    }
81
82
    /**
83
     * Set fold expansion state.
84
     *
85
     * @param expanded True to expand the fold, false to collapse it.
86
     */
87
    public abstract void setExpanded(boolean expanded);
88
89
    abstract void endFold();
90
91
    /**
92
     * Expand the fold.
93
     */
94
    public final void expand() {
95
        setExpanded(true);
96
    }
97
98
    /**
99
     * Collapse the fold.
100
     */
101
    public final void collapse() {
102
        setExpanded(false);
103
    }
104
105
    private static class Impl<IO, OW extends PrintWriter, P, F> extends Fold {
106
107
        private final InputOutputProvider<IO, OW, P, F> provider;
108
        private final IO io;
109
        private final OW writer;
110
        private final F fold;
111
112
        public Impl(InputOutputProvider<IO, OW, P, F> provider, IO io,
113
                OW writer, F fold) {
114
115
            this.provider = provider;
116
            this.io = io;
117
            this.writer = writer;
118
            this.fold = fold;
119
        }
120
121
        @Override
122
        public void setExpanded(boolean expanded) {
123
            provider.setFoldExpanded(io, writer, fold, expanded);
124
        }
125
126
        @Override
127
        void endFold() {
128
            provider.endFold(io, writer, fold);
129
        }
130
    }
131
}
(-)a/api.io/src/org/netbeans/api/io/Hyperlink.java (+159 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import java.net.URI;
45
import org.netbeans.api.annotations.common.NonNull;
46
import org.netbeans.modules.io.HyperlinkAccessor;
47
import org.openide.util.Parameters;
48
49
/**
50
 * Hyperlink in output window. It can be specified by a URI to open (e.g. file +
51
 * row + col), or a {@link Runnable} to invoke when the hyperlink is clicked.
52
 *
53
 * @author jhavlin
54
 */
55
public abstract class Hyperlink {
56
57
    private final boolean important;
58
59
    private Hyperlink(boolean important) {
60
        this.important = important;
61
    }
62
63
    static {
64
        HyperlinkAccessor.setDefault(new HyperlinkAccessorImpl());
65
    }
66
67
    /**
68
     * @return True if the hyperlink has been marked as important, false if it
69
     * is a standard link.
70
     */
71
    boolean isImportant() {
72
        return important;
73
    }
74
75
    /**
76
     * Create a new hyperlink for specified URI.
77
     *
78
     * @param uri Hyperlink targed.
79
     *
80
     * @return The new hyperlink.
81
     */
82
    @NonNull
83
    public static Hyperlink from(@NonNull URI uri) {
84
        return Hyperlink.from(uri, false);
85
    }
86
87
    /**
88
     * Create a new hyperlink for specified {@link Runnable}, which will be
89
     * invoked when the line is clicked.
90
     *
91
     * @param runnable The runnable to run on click.
92
     * @return The new hyperlink.
93
     */
94
    @NonNull
95
    public static Hyperlink from(@NonNull Runnable runnable) {
96
        return from(runnable, false);
97
    }
98
99
    /**
100
     * Create a new hyperlink for specified URI.
101
     *
102
     * @param uri Hyperlink targed.
103
     * @param important True if the hyperlink should be handled as an important
104
     * one, false if it is a standard one.
105
     *
106
     * @return The new hyperlink.
107
     */
108
    @NonNull
109
    public static Hyperlink from(@NonNull URI uri, boolean important) {
110
        Parameters.notNull("uri", uri);
111
        return new UriHyperlink(uri, important);
112
    }
113
114
    /**
115
     * Create a new hyperlink for specified {@link Runnable}, which will be
116
     * invoked when the line is clicked.
117
     *
118
     * @param runnable The runnable to run on click.
119
     * @param important True if the hyperlink should be handled as an important
120
     * one, false if it is a standard one.
121
     * @return The new hyperlink.
122
     */
123
    @NonNull
124
    public static Hyperlink from(@NonNull Runnable runnable,
125
            boolean important) {
126
        Parameters.notNull("runnable", runnable);
127
        return new OnClickHyperlink(runnable, important);
128
    }
129
130
    @SuppressWarnings("PackageVisibleInnerClass")
131
    static class OnClickHyperlink extends Hyperlink {
132
133
        private final Runnable runnable;
134
135
        public OnClickHyperlink(Runnable runnable, boolean important) {
136
            super(important);
137
            this.runnable = runnable;
138
        }
139
140
        public Runnable getRunnable() {
141
            return runnable;
142
        }
143
    }
144
145
    @SuppressWarnings("PackageVisibleInnerClass")
146
    static class UriHyperlink extends Hyperlink {
147
148
        private final URI uri;
149
150
        public UriHyperlink(URI uri, boolean important) {
151
            super(important);
152
            this.uri = uri;
153
        }
154
155
        public URI getUri() {
156
            return uri;
157
        }
158
    }
159
}
(-)a/api.io/src/org/netbeans/api/io/HyperlinkAccessorImpl.java (+89 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import java.net.URI;
45
import org.netbeans.modules.io.HyperlinkAccessor;
46
import org.netbeans.spi.io.support.HyperlinkType;
47
48
/**
49
 * Implementation of accessor that enables retrieving information about
50
 * hyperlinks in SPI.
51
 *
52
 * @author jhavlin
53
 */
54
class HyperlinkAccessorImpl extends HyperlinkAccessor {
55
56
    @Override
57
    public HyperlinkType getType(Hyperlink hyperlink) {
58
        if (hyperlink instanceof Hyperlink.OnClickHyperlink) {
59
            return HyperlinkType.FROM_RUNNABLE;
60
        } else if (hyperlink instanceof Hyperlink.UriHyperlink) {
61
            return HyperlinkType.FROM_URI;
62
        } else {
63
            throw new IllegalArgumentException("Unknown hyperlink.");   //NOI18N
64
        }
65
    }
66
67
    @Override
68
    public boolean isImportant(Hyperlink hyperlink) {
69
        return hyperlink.isImportant();
70
    }
71
72
    @Override
73
    public Runnable getRunnable(Hyperlink hyperlink) {
74
        if (hyperlink instanceof Hyperlink.OnClickHyperlink) {
75
            return ((Hyperlink.OnClickHyperlink) hyperlink).getRunnable();
76
        } else {
77
            throw new IllegalArgumentException("Not an ON_CLICK link.");//NOI18N
78
        }
79
    }
80
81
    @Override
82
    public URI getURI(Hyperlink hyperlink) {
83
        if (hyperlink instanceof Hyperlink.UriHyperlink) {
84
            return ((Hyperlink.UriHyperlink) hyperlink).getUri();
85
        } else {
86
            throw new IllegalArgumentException("Not a FOR_URI link.");  //NOI18N
87
        }
88
    }
89
}
(-)a/api.io/src/org/netbeans/api/io/IOProvider.java (+296 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import java.io.InputStreamReader;
45
import java.io.PrintWriter;
46
import java.io.Reader;
47
import java.util.Collection;
48
import java.util.Set;
49
import org.netbeans.api.annotations.common.NonNull;
50
import org.netbeans.spi.io.InputOutputProvider;
51
import org.openide.util.Lookup;
52
import org.openide.util.Parameters;
53
54
/**
55
 * A factory for IO tabs shown in the output window. To create a new tab to
56
 * write to, call e.g.
57
 * <code>IOProvider.getDefault().getIO("MyTab", false)</code> (pass true if
58
 * there may be an existing tab with the same name and you want to write to a
59
 * new tab).
60
 *
61
 * <p>
62
 * Methods of this class can be called in any thread.
63
 * </p>
64
 *
65
 * @author Jesse Glick, Jaroslav Havlin
66
 */
67
public abstract class IOProvider {
68
69
    private IOProvider() {
70
    }
71
72
    /**
73
     * Get the default I/O provider.
74
     * <p>
75
     * Normally this is taken from {@link Lookup#getDefault} but if there is no
76
     * instance in lookup, a fallback instance is created which just uses the
77
     * standard system I/O streams. This is useful for unit tests and perhaps
78
     * for standalone usage of various libraries.
79
     * </p>
80
     *
81
     * @return The default instance (never null).
82
     */
83
    @NonNull
84
    public static IOProvider getDefault() {
85
        InputOutputProvider<?, ?, ?, ?> def
86
                = Lookup.getDefault().lookup(InputOutputProvider.class);
87
        if (def != null) {
88
            return wrapProvider(def);
89
        } else {
90
            return wrapProvider(new Trivial());
91
        }
92
    }
93
94
    private static <IO, OW extends PrintWriter, P, F> IOProvider wrapProvider(
95
            InputOutputProvider<IO, OW, P, F> provider) {
96
97
        return new Impl<IO, OW, P, F>(provider);
98
    }
99
100
    /**
101
     * Gets IOProvider of selected name or delegates to getDefault() if none was
102
     * found.
103
     *
104
     * @param id ID of provider.
105
     * @return The instance corresponding to provided name or default instance
106
     * if not found.
107
     */
108
    @NonNull
109
    public static IOProvider get(@NonNull String id) {
110
        Parameters.notNull("id", id);
111
112
        @SuppressWarnings("rawtypes")
113
        Collection<? extends InputOutputProvider> providers
114
                = Lookup.getDefault().lookupAll(InputOutputProvider.class);
115
116
        for (InputOutputProvider<?, ?, ?, ?> p : providers) {
117
            if (p.getId().equals(id)) {
118
                return wrapProvider(p);
119
            }
120
        }
121
        return getDefault();
122
    }
123
124
    /**
125
     * Gets identifier of this provider.
126
     *
127
     * @return Name of this provider.
128
     */
129
    @NonNull
130
    public abstract String getId();
131
132
    /**
133
     * Get a named instance of InputOutput, which represents an output tab in
134
     * the output window. Streams for reading/writing can be accessed via
135
     * getters on the returned instance.
136
     *
137
     * @param name A localised display name for the tab.
138
     * @param newIO If <tt>true</tt>, a new <code>InputOutput</code> is
139
     * returned, else an existing <code>InputOutput</code> of the same name may
140
     * be returned.
141
     * @return An <code>InputOutput</code> instance for accessing the new tab.
142
     * @see InputOutput
143
     */
144
    @NonNull
145
    public abstract InputOutput getIO(@NonNull String name, boolean newIO);
146
147
    /**
148
     * Get a named instance of InputOutput, which represents an output tab in
149
     * the output window. Streams for reading/writing can be accessed via
150
     * getters on the returned instance.
151
     *
152
     * @param name A localised display name for the tab.
153
     * @param newIO If <tt>true</tt>, a new <code>InputOutput</code> is
154
     * returned, else an existing <code>InputOutput</code> of the same name may
155
     * be returned.
156
     * @param lookup Lookup which may contain additional information for various
157
     * implementations of output window.
158
     * @return An <code>InputOutput</code> instance for accessing the new tab.
159
     * @see InputOutput
160
     */
161
    @NonNull
162
    public abstract InputOutput getIO(@NonNull String name, boolean newIO,
163
            @NonNull Lookup lookup);
164
165
    /**
166
     * Implementation of IOProvider that uses {@link InputOutputProvider} SPI
167
     * internally.
168
     *
169
     * @param <IO>
170
     * @param <OW>
171
     * @param <POS>
172
     */
173
    private static class Impl<IO, OW extends PrintWriter, P, F>
174
            extends IOProvider {
175
176
        private final InputOutputProvider<IO, OW, P, F> impl;
177
178
        public Impl(InputOutputProvider<IO, OW, P, F> impl) {
179
            this.impl = impl;
180
        }
181
182
        @Override
183
        public String getId() {
184
            return impl.getId();
185
        }
186
187
        @Override
188
        public InputOutput getIO(String name, boolean newIO) {
189
            return getIO(name, newIO, Lookup.EMPTY);
190
        }
191
192
        @Override
193
        public InputOutput getIO(String name, boolean newIO, Lookup lookup) {
194
            Parameters.notNull("name", name);
195
            Parameters.notNull("lookup", lookup);
196
            return InputOutput.create(impl, impl.getIO(name, newIO, lookup));
197
        }
198
    }
199
200
    /**
201
     * Trivial implementation of {@link IOProvider} that uses system input,
202
     * output and error streams.
203
     */
204
    private static class Trivial
205
            implements InputOutputProvider<Object, PrintWriter, Void, Void> {
206
207
        @Override
208
        public String getId() {
209
            return "Trivial";
210
        }
211
212
        @Override
213
        public Object getIO(String name, boolean newIO, Lookup lookup) {
214
            return this;
215
        }
216
217
        @Override
218
        public Reader getIn(Object io) {
219
            return new InputStreamReader(System.in);
220
        }
221
222
        @Override
223
        public PrintWriter getOut(Object io) {
224
            return new PrintWriter(System.out);
225
        }
226
227
        @Override
228
        public PrintWriter getErr(Object io) {
229
            return new PrintWriter(System.err);
230
        }
231
232
        @Override
233
        public void print(Object io, PrintWriter writer, String text,
234
                Hyperlink link, OutputColor color, boolean printLineEnd) {
235
            writer.print(text);
236
            if (printLineEnd) {
237
                writer.println();
238
            }
239
        }
240
241
        @Override
242
        public Lookup getIOLookup(Object io) {
243
            return Lookup.EMPTY;
244
        }
245
246
        @Override
247
        public void resetIO(Object io) {
248
        }
249
250
        @Override
251
        public void showIO(Object io,
252
                Set<ShowOperation> operations) {
253
        }
254
255
        @Override
256
        public void closeIO(Object io) {
257
        }
258
259
        @Override
260
        public boolean isIOClosed(Object io) {
261
            return false;
262
        }
263
264
        @Override
265
        public Void getCurrentPosition(Object io, PrintWriter writer) {
266
            return null;
267
        }
268
269
        @Override
270
        public void scrollTo(Object io, PrintWriter writer, Void position) {
271
        }
272
273
        @Override
274
        public Void startFold(Object io, PrintWriter writer, boolean expanded) {
275
            return null;
276
        }
277
278
        @Override
279
        public void endFold(Object io, PrintWriter writer, Void fold) {
280
        }
281
282
        @Override
283
        public void setFoldExpanded(Object io, PrintWriter writer, Void fold,
284
                boolean expanded) {
285
        }
286
287
        @Override
288
        public String getIODescription(Object io) {
289
            return null;
290
        }
291
292
        @Override
293
        public void setIODescription(Object io, String description) {
294
        }
295
    }
296
}
(-)a/api.io/src/org/netbeans/api/io/InputOutput.java (+314 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import java.io.PrintWriter;
45
import java.io.Reader;
46
import java.util.Collections;
47
import java.util.EnumSet;
48
import java.util.Map;
49
import java.util.Set;
50
import java.util.WeakHashMap;
51
import org.netbeans.api.annotations.common.CheckForNull;
52
import org.netbeans.api.annotations.common.NonNull;
53
import org.netbeans.api.annotations.common.NullAllowed;
54
import org.netbeans.spi.io.InputOutputProvider;
55
import org.openide.util.Lookup;
56
57
/**
58
 * An I/O connection to one tab on the Output Window. To acquire an instance to
59
 * write to, call, e.g.,
60
 * <code>IOProvider.getDefault().getInputOutput("someName", false)</code>. To
61
 * get actual streams to write to, call <code>getOut()</code> or <code>
62
 * getErr()</code> on the returned instance.
63
 * <p>
64
 * Generally it is preferable not to hold a reference to an instance of
65
 * {@link org.netbeans.api.io.InputOutput}, but rather to fetch it by name from
66
 * {@link org.netbeans.api.io.IOProvider} as needed.
67
 * </p>
68
 *
69
 * <p>
70
 * Methods of this class can be called in any thread.
71
 * </p>
72
 *
73
 * @see OutputWriter
74
 * @author Ian Formanek, Jaroslav Tulach, Petr Hamernik, Ales Novak, Jan
75
 * Jancura, Jaroslav Havlin
76
 */
77
public abstract class InputOutput implements Lookup.Provider {
78
79
    private static final Set<ShowOperation> DEFAULT_SHOW_OPERATIONS
80
            = EnumSet.of(ShowOperation.OPEN, ShowOperation.MAKE_VISIBLE);
81
82
    private InputOutput() {
83
    }
84
85
    /**
86
     * Get a named instance of InputOutput from the default {@link IOProvider},
87
     * which represents an output tab in the output window. Streams for
88
     * reading/writing can be accessed via getters on the returned instance.
89
     *
90
     * <p>
91
     * This is a shorthand for {@code IOProvider.getDefault().getIO(...)}.
92
     * </p>
93
     *
94
     * @param name A localised display name for the tab.
95
     * @param newIO If <tt>true</tt>, a new <code>InputOutput</code> is
96
     * returned, else an existing <code>InputOutput</code> of the same name may
97
     * be returned.
98
     * @return An <code>InputOutput</code> instance for accessing the new tab.
99
     * @see IOProvider
100
     */
101
    @NonNull
102
    public static InputOutput get(@NonNull String name, boolean newIO) {
103
        return IOProvider.getDefault().getIO(name, newIO);
104
    }
105
106
     /**
107
     * Get a named instance of InputOutput from the default {@link IOProvider},
108
     * which represents an output tab in the output window. Streams for
109
     * reading/writing can be accessed via getters on the returned instance.
110
     *
111
     * <p>
112
     * This is a shorthand for {@code IOProvider.getDefault().getIO(...)}.
113
     * </p>
114
     *
115
     * @param name A localised display name for the tab.
116
     * @param newIO If <tt>true</tt>, a new <code>InputOutput</code> is
117
     * returned, else an existing <code>InputOutput</code> of the same name may
118
     * be returned.
119
     * @param lookup Lookup which may contain additional information for various
120
     * implementations of output window.
121
     * @return An <code>InputOutput</code> instance for accessing the new tab.
122
     * @see IOProvider
123
     */
124
    @NonNull
125
    public static InputOutput get(@NonNull String name, boolean newIO,
126
            @NonNull Lookup lookup) {
127
        return IOProvider.getDefault().getIO(name, newIO, lookup);
128
    }
129
130
    /**
131
     * Get a reader to read from the tab.
132
     *
133
     * @return The reader.
134
     */
135
    @NonNull
136
    public abstract Reader getIn();
137
138
    /**
139
     * Acquire an output writer to write to the tab.
140
     *
141
     * @return The writer.
142
     */
143
    @NonNull
144
    public abstract OutputWriter getOut();
145
146
    /**
147
     * Get an output writer to write to the tab in error mode. This might show
148
     * up in a different color than the regular output, e.g., or appear in a
149
     * separate pane.
150
     *
151
     * @return The writer.
152
     */
153
    @NonNull
154
    public abstract OutputWriter getErr();
155
156
    /**
157
     * Clear the output pane.
158
     */
159
    public abstract void reset();
160
161
    /**
162
     * Get lookup which may contain extensions provided by implementation of
163
     * output window.
164
     *
165
     * @return The lookup.
166
     */
167
    @NonNull
168
    @Override
169
    public abstract Lookup getLookup();
170
171
    /**
172
     * Closes this tab. The effect of calling any method on an instance of
173
     * InputOutput after calling <code>close()</code> on it is
174
     * undefined.
175
     */
176
    public abstract void close();
177
178
    /**
179
     * Test whether this tab has been closed, either by a call to
180
     * {@link #close()} or by the user closing the tab in the UI.
181
     *
182
     * @return Value <code>true</code> if it is closed.
183
     */
184
    public abstract boolean isClosed();
185
186
    /**
187
     * Get description of this I/O instance.
188
     *
189
     * @return The description, or null if not set.
190
     */
191
    @CheckForNull
192
    public abstract String getDescription();
193
194
    /**
195
     * Set description of this I/O instance. It can be used e.g. as tooltip for
196
     * output tab in the GUI.
197
     *
198
     * @param description The description, can be null.
199
     */
200
    public abstract void setDescription(@NullAllowed String description);
201
202
    static <IO, OW extends PrintWriter, P, F> InputOutput create(
203
            InputOutputProvider<IO, OW, P, F> provider, IO io) {
204
205
        return new Impl<IO, OW, P, F>(provider, io);
206
    }
207
208
    /**
209
     * Show this I/O if possible (e.g. in tabbed pane).
210
     * <p>
211
     * Calling this method is the same as calling:
212
     * </p>
213
     * <pre>
214
     * show(EnumSet.of(ShowOperation.OPEN, ShowOperation.MAKE_VISIBLE));
215
     * </pre>
216
     *
217
     * @see #show(java.util.Set)
218
     */
219
    public final void show() {
220
        show(DEFAULT_SHOW_OPERATIONS);
221
    }
222
223
    /**
224
     * Show this I/O if possible (e.g. in tabbed pane).
225
     *
226
     * @param operations Set of operations that should be invoked to show the
227
     * output. If the set is empty or null, pane for this I/O will be only
228
     * selected, but its component will not be opened or made visible. So it
229
     * will stay closed or hidden if it is not opened or not visible.
230
     *
231
     * @see ShowOperation
232
     */
233
    public abstract void show(@NullAllowed Set<ShowOperation> operations);
234
235
    private static class Impl<IO, OW extends PrintWriter, P, F>
236
            extends InputOutput {
237
238
        private final Map<OW, OutputWriter> cache
239
                = Collections.synchronizedMap(
240
                        new WeakHashMap<OW, OutputWriter>());
241
242
        private final InputOutputProvider<IO, OW, P, F> provider;
243
        private final IO ioObject;
244
245
        public Impl(InputOutputProvider<IO, OW, P, F> provider, IO ioObject) {
246
247
            this.provider = provider;
248
            this.ioObject = ioObject;
249
        }
250
251
        @Override
252
        public Reader getIn() {
253
            return provider.getIn(ioObject);
254
        }
255
256
        @Override
257
        public OutputWriter getOut() {
258
            return createOrGetCachedWrapper(provider.getOut(ioObject));
259
        }
260
261
        @Override
262
        public OutputWriter getErr() {
263
            return createOrGetCachedWrapper(provider.getErr(ioObject));
264
        }
265
266
        @Override
267
        @NonNull
268
        public Lookup getLookup() {
269
            return provider.getIOLookup(ioObject);
270
        }
271
272
        @Override
273
        public void reset() {
274
            provider.resetIO(ioObject);
275
        }
276
277
        private OutputWriter createOrGetCachedWrapper(OW pw) {
278
            OutputWriter ow = cache.get(pw);
279
            if (ow == null) {
280
                ow = OutputWriter.create(provider, ioObject, pw);
281
                cache.put(pw, ow);
282
            }
283
            return ow;
284
        }
285
286
        @Override
287
        public void close() {
288
            provider.closeIO(ioObject);
289
        }
290
291
        @Override
292
        public boolean isClosed() {
293
            return provider.isIOClosed(ioObject);
294
        }
295
296
        @Override
297
        public String getDescription() {
298
            return provider.getIODescription(ioObject);
299
        }
300
301
        @Override
302
        public void setDescription(String description) {
303
            provider.setIODescription(ioObject, description);
304
        }
305
306
        @Override
307
        public void show(Set<ShowOperation> operations) {
308
            provider.showIO(ioObject,
309
                    operations != null
310
                            ? operations
311
                            : Collections.<ShowOperation>emptySet());
312
        }
313
    }
314
}
(-)a/api.io/src/org/netbeans/api/io/OutputColor.java (+198 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import org.netbeans.spi.io.support.OutputColorType;
45
import org.netbeans.api.annotations.common.NonNull;
46
import org.netbeans.modules.io.OutputColorAccessor;
47
48
/**
49
 * A color specified for part of text in output pane. It can be a predefined
50
 * color for some type of text (success, debug, warning, failure), or arbitrary
51
 * RGB color.
52
 * <p>
53
 * Although using wide range of custom RGB colors may be tempting, predefined
54
 * colors are recommended, as they can be configured to respect GUI theme in
55
 * use.
56
 * </p>
57
 *
58
 * @author jhavlin
59
 */
60
public abstract class OutputColor {
61
62
63
    private final OutputColorType type;
64
    private static final OutputColor CLR_WARNING = new TypeColor(OutputColorType.WARNING);
65
    private static final OutputColor CLR_FAILURE = new TypeColor(OutputColorType.FAILURE);
66
    private static final OutputColor CLR_DEBUG = new TypeColor(OutputColorType.DEBUG);
67
    private static final OutputColor CLR_SUCCESS = new TypeColor(OutputColorType.SUCCESS);
68
69
    static {
70
        OutputColorAccessor.setDefault(new OutputColorAccessorImpl());
71
    }
72
73
    private OutputColor(OutputColorType type) {
74
        this.type = type;
75
    }
76
77
    OutputColorType getType() {
78
        return type;
79
    }
80
81
    /**
82
     * Warning text color.
83
     *
84
     * @return Predefined color for text of type "warning".
85
     */
86
    @NonNull
87
    public static OutputColor warning() {
88
        return CLR_WARNING;
89
    }
90
91
    /**
92
     * Failure text color.
93
     *
94
     * @return Predefined color for text of type "failure".
95
     */
96
    @NonNull
97
    public static OutputColor failure() {
98
        return CLR_FAILURE;
99
    }
100
101
    /**
102
     * Debug text color.
103
     *
104
     * @return Predefined color for text of type "debug".
105
     */
106
    @NonNull
107
    public static OutputColor debug() {
108
        return CLR_DEBUG;
109
    }
110
111
    /**
112
     * Success text color.
113
     *
114
     * @return Predefined color for text of type "success".
115
     */
116
    @NonNull
117
    public static OutputColor success() {
118
        return CLR_SUCCESS;
119
    }
120
121
    /**
122
     * Arbitrary constant RGB color.
123
     *
124
     * <p>
125
     * Please note that it is recommended to use colors for predefined text
126
     * types, which can respect color theme used by the GUI.
127
     * </p>
128
     *
129
     * @param r The red component, in the range (0 - 255).
130
     * @param g The green component, in the range (0 - 255).
131
     * @param b The blue component, in the range (0 - 255).
132
     *
133
     * @return Color specified for a constant RGB value.
134
     * @throws IllegalArgumentException If some of color components is out of
135
     * range.
136
     */
137
    @NonNull
138
    public static OutputColor rgb(int r, int g, int b) {
139
        checkColorComponentRange("r", r);
140
        checkColorComponentRange("g", g);
141
        checkColorComponentRange("b", b);
142
        int value = ((r & 0xFF) << 16)
143
                | ((g & 0xFF) << 8)
144
                | ((b & 0xFF));
145
        return rgb(value);
146
    }
147
148
    /**
149
     * Arbitrary constant RGB color. Creates an opaque sRGB color with the
150
     * specified combined RGB value consisting of the red component in bits
151
     * 16-23, the green component in bits 8-15, and the blue component in bits
152
     * 0-7.
153
     *
154
     * <p>
155
     * Please note that it is recommended to use colors for predefined text
156
     * types, which can respect color theme used by the GUI.
157
     * </p>
158
     *
159
     * @param rgbValue The combined RGB components.
160
     *
161
     * @return Color specified for a constant RGB value.
162
     */
163
    @NonNull
164
    public static OutputColor rgb(int rgbValue) {
165
        return new RgbColor(rgbValue);
166
    }
167
168
    private static void checkColorComponentRange(String name,
169
            int colorComponent) {
170
171
        if (colorComponent < 0 || colorComponent > 255) {
172
            throw new IllegalArgumentException("Color component " + name//NOI18N
173
                    + " is out of range (0 - 255): " + colorComponent); //NOI18N
174
        }
175
    }
176
177
    private static class TypeColor extends OutputColor {
178
179
        public TypeColor(OutputColorType type) {
180
            super(type);
181
        }
182
    }
183
184
    @SuppressWarnings("PackageVisibleInnerClass")
185
    static class RgbColor extends OutputColor {
186
187
        private final int value;
188
189
        public RgbColor(int value) {
190
            super(OutputColorType.RGB);
191
            this.value = value;
192
        }
193
194
        public int getRGB() {
195
            return value;
196
        }
197
    }
198
}
(-)a/api.io/src/org/netbeans/api/io/OutputColorAccessorImpl.java (+68 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import org.netbeans.modules.io.OutputColorAccessor;
45
import org.netbeans.spi.io.support.OutputColorType;
46
47
/**
48
 * Implementation of accessor that enables retrieving information about output
49
 * colors in SPI.
50
 *
51
 * @author jhavlin
52
 */
53
class OutputColorAccessorImpl extends OutputColorAccessor{
54
55
    @Override
56
    public OutputColorType getType(OutputColor color) {
57
        return color.getType();
58
    }
59
60
    @Override
61
    public int getRgb(OutputColor color) {
62
        if (color instanceof OutputColor.RgbColor) {
63
            return ((OutputColor.RgbColor) color).getRGB();
64
        } else {
65
            throw new IllegalArgumentException("Not an RGB color.");    //NOI18N
66
        }
67
    }
68
}
(-)a/api.io/src/org/netbeans/api/io/OutputWriter.java (+366 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import java.io.IOException;
45
import java.io.PrintWriter;
46
import java.io.Writer;
47
import java.util.Collections;
48
import java.util.EnumSet;
49
import java.util.Locale;
50
import java.util.Set;
51
import org.netbeans.api.annotations.common.NullAllowed;
52
import org.netbeans.spi.io.InputOutputProvider;
53
54
/**
55
 * Extended {@link PrintWriter} for writing into output window or similar output
56
 * GUI component. It can support features like color printing, hyperlinks, or
57
 * folding.
58
 *
59
 * <p>
60
 * Methods of this class can be called in any thread.
61
 * </p>
62
 *
63
 * @author jhavlin
64
 */
65
public abstract class OutputWriter extends PrintWriter {
66
67
    private OutputWriter() {
68
        super(new DummyWriter());
69
    }
70
71
    /**
72
     * Get current position in the output stream.
73
     *
74
     * @return The position.
75
     */
76
    public abstract Position getCurrentPosition();
77
78
    /**
79
     * Start a new fold. If a fold already exists, a nested fold will be
80
     * created.
81
     *
82
     * @param expanded True if the fold should be expanded by default, false if
83
     * it should be collapsed.
84
     *
85
     * @return The fold handle.
86
     */
87
    public abstract Fold startFold(boolean expanded);
88
89
    /**
90
     * Finish a fold. If it contains some unfinished nested folds, they will be
91
     * finished as well.
92
     *
93
     * @param fold The fold to finish.
94
     */
95
    public abstract void endFold(Fold fold);
96
97
    public abstract void print(String s, Hyperlink link, OutputColor color);
98
99
    public abstract void print(String s, Hyperlink link);
100
101
    public abstract void print(String s, OutputColor color);
102
103
    public abstract void println(String s, Hyperlink link, OutputColor color);
104
105
    public abstract void println(String s, Hyperlink link);
106
107
    public abstract void println(String s, OutputColor color);
108
109
    static <IO, OW extends PrintWriter, P, F> OutputWriter create(
110
            InputOutputProvider<IO, OW, P, F> provider, IO io, OW writer) {
111
112
        return new Impl<IO, OW, P, F>(provider, io, writer);
113
    }
114
115
    private static class Impl<IO, OW extends PrintWriter, P, F>
116
            extends OutputWriter {
117
118
        private final InputOutputProvider<IO, OW, P, F> provider;
119
        private final IO io;
120
        private final OW writer;
121
122
        public Impl(InputOutputProvider<IO, OW, P, F> provider,
123
                IO io, OW writer) {
124
125
            this.provider = provider;
126
            this.io = io;
127
            this.writer = writer;
128
        }
129
130
        @Override
131
        public Position getCurrentPosition() {
132
            return Position.create(provider, io, writer,
133
                    provider.getCurrentPosition(io, writer));
134
        }
135
136
        @Override
137
        public void print(String s, Hyperlink link, OutputColor color) {
138
            provider.print(io, writer, s, link, color, false);
139
        }
140
141
        @Override
142
        public void print(String s, Hyperlink link) {
143
            provider.print(io, writer, s, link, null, false);
144
        }
145
146
        @Override
147
        public void print(String s, OutputColor color) {
148
            provider.print(io, writer, s, null, color, false);
149
        }
150
151
        @Override
152
        public void println(String s, Hyperlink link, OutputColor color) {
153
            provider.print(io, writer, s, link, color, true);
154
        }
155
156
        @Override
157
        public void println(String s, Hyperlink link) {
158
            provider.print(io, writer, s, link, null, true);
159
        }
160
161
        @Override
162
        public void println(String s, OutputColor color) {
163
            provider.print(io, writer, s, null, color, true);
164
        }
165
166
        @Override
167
        public void flush() {
168
            writer.flush();
169
        }
170
171
        @Override
172
        public void close() {
173
            writer.close();
174
        }
175
176
        @Override
177
        public boolean checkError() {
178
            return writer.checkError();
179
        }
180
181
        @Override
182
        public void write(int c) {
183
            writer.write(c);
184
        }
185
186
        @Override
187
        public void write(char[] buf, int off, int len) {
188
            writer.write(buf, off, len);
189
        }
190
191
        @Override
192
        public void write(char[] buf) {
193
            writer.write(buf);
194
        }
195
196
        @Override
197
        public void write(String s, int off, int len) {
198
            writer.write(s, off, len);
199
        }
200
201
        @Override
202
        public void write(String s) {
203
            writer.write(s);
204
        }
205
206
        @Override
207
        public void print(boolean b) {
208
            writer.print(b);
209
        }
210
211
        @Override
212
        public void print(char c) {
213
            writer.print(c);
214
        }
215
216
        @Override
217
        public void print(int i) {
218
            writer.print(i);
219
        }
220
221
        @Override
222
        public void print(long l) {
223
            writer.print(l);
224
        }
225
226
        @Override
227
        public void print(float f) {
228
            writer.print(f);
229
        }
230
231
        @Override
232
        public void print(double d) {
233
            writer.print(d);
234
        }
235
236
        @Override
237
        @SuppressWarnings("ImplicitArrayToString")
238
        public void print(char[] s) {
239
            writer.print(s);
240
        }
241
242
        @Override
243
        public void print(String s) {
244
            writer.print(s);
245
        }
246
247
        @Override
248
        public void print(Object obj) {
249
            writer.print(obj);
250
        }
251
252
        @Override
253
        public void println() {
254
            writer.println();
255
        }
256
257
        @Override
258
        public void println(boolean x) {
259
            writer.println(x);
260
        }
261
262
        @Override
263
        public void println(char x) {
264
            writer.println(x);
265
        }
266
267
        @Override
268
        public void println(int x) {
269
            writer.println(x);
270
        }
271
272
        @Override
273
        public void println(long x) {
274
            writer.println(x);
275
        }
276
277
        @Override
278
        public void println(float x) {
279
            writer.println(x);
280
        }
281
282
        @Override
283
        public void println(double x) {
284
            writer.println(x);
285
        }
286
287
        @Override
288
        @SuppressWarnings("ImplicitArrayToString")
289
        public void println(char[] x) {
290
            writer.println(x);
291
        }
292
293
        @Override
294
        public void println(String x) {
295
            writer.println(x);
296
        }
297
298
        @Override
299
        public void println(Object x) {
300
            writer.println(x);
301
        }
302
303
        @Override
304
        public PrintWriter printf(String format, Object... args) {
305
            return writer.printf(format, args);
306
        }
307
308
        @Override
309
        public PrintWriter printf(Locale l, String format, Object... args) {
310
            return writer.printf(l, format, args);
311
        }
312
313
        @Override
314
        public PrintWriter format(String format, Object... args) {
315
            return writer.format(format, args);
316
        }
317
318
        @Override
319
        public PrintWriter format(Locale l, String format, Object... args) {
320
            return writer.format(l, format, args);
321
        }
322
323
        @Override
324
        public PrintWriter append(CharSequence csq) {
325
            return writer.append(csq);
326
        }
327
328
        @Override
329
        public PrintWriter append(CharSequence csq, int start, int end) {
330
            return writer.append(csq, start, end);
331
        }
332
333
        @Override
334
        public PrintWriter append(char c) {
335
            return writer.append(c);
336
        }
337
338
        @Override
339
        public Fold startFold(boolean expanded) {
340
            F fold = provider.startFold(io, writer, expanded);
341
            return Fold.create(provider, io, writer, fold);
342
        }
343
344
        @Override
345
        public void endFold(Fold fold) {
346
            if (fold != Fold.UNSUPPORTED) {
347
                fold.endFold();
348
            }
349
        }
350
    }
351
352
    private static class DummyWriter extends Writer {
353
354
        @Override
355
        public void write(char[] cbuf, int off, int len) throws IOException {
356
        }
357
358
        @Override
359
        public void flush() throws IOException {
360
        }
361
362
        @Override
363
        public void close() throws IOException {
364
        }
365
    }
366
}
(-)a/api.io/src/org/netbeans/api/io/Position.java (+106 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import java.io.PrintWriter;
45
import org.netbeans.spi.io.InputOutputProvider;
46
47
/**
48
 *
49
 * Stored position in the output window.
50
 *
51
 * <p>
52
 * Methods of this class can be called in any thread.
53
 * </p>
54
 *
55
 * @author jhavlin
56
 */
57
public abstract class Position {
58
59
    static final Position UNSUPPORTED = new Position() {
60
61
        @Override
62
        public void scrollTo() {
63
        }
64
    };
65
66
    private Position() {
67
    }
68
69
    /**
70
     * Scroll to this position.
71
     */
72
    public abstract void scrollTo();
73
74
    static <IO, OW extends PrintWriter, P, F> Position create(
75
            InputOutputProvider<IO, OW, P, F> provider, IO io,
76
            OW writer, P position) {
77
78
        if (position == null) {
79
            return UNSUPPORTED;
80
        } else {
81
            return new Impl<IO, OW, P, F>(provider, io, writer, position);
82
        }
83
    }
84
85
    private static class Impl<IO, OW extends PrintWriter, P, F>
86
            extends Position {
87
88
        private final InputOutputProvider<IO, OW, P, F> provider;
89
        private final IO io;
90
        private final OW ow;
91
        private final P position;
92
93
        public Impl(InputOutputProvider<IO, OW, P, F> provider, IO io, OW ow,
94
                P position) {
95
            this.provider = provider;
96
            this.io = io;
97
            this.ow = ow;
98
            this.position = position;
99
        }
100
101
        @Override
102
        public void scrollTo() {
103
            provider.scrollTo(io, ow, position);
104
        }
105
    }
106
}
(-)a/api.io/src/org/netbeans/api/io/ShowOperation.java (+65 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
/**
45
 * Operations that should take part when showing a component. The actual
46
 * behavior depends on implementation (some features may be unsupported).
47
 *
48
 * @author jhavlin
49
 */
50
public enum ShowOperation {
51
    /**
52
     * Open the GUI component (Output Window) if it is closed.
53
     */
54
    OPEN,
55
    /**
56
     * Make the GUI component (Output Window) visible. E.g. show it if it is
57
     * minimized.
58
     */
59
    MAKE_VISIBLE,
60
    /**
61
     * Activate the GUI component (Output Window). E.g. highlight and possibly
62
     * focus it.
63
     */
64
    ACTIVATE
65
}
(-)a/api.io/src/org/netbeans/modules/io/HyperlinkAccessor.java (+89 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.io;
43
44
import java.net.URI;
45
import org.netbeans.api.io.Hyperlink;
46
import org.netbeans.spi.io.support.HyperlinkType;
47
48
/**
49
 *
50
 * @author jhavlin
51
 */
52
public abstract class HyperlinkAccessor {
53
54
    /**
55
     * The default implementation is set in static initializer of
56
     * {@link Hyperlink}.
57
     */
58
    private static HyperlinkAccessor DEFAULT;
59
60
    public static void setDefault(HyperlinkAccessor def) {
61
        HyperlinkAccessor.DEFAULT = def;
62
    }
63
64
    public static HyperlinkAccessor getDefault() {
65
        if (DEFAULT != null) {
66
            return DEFAULT;
67
        }
68
69
        // invokes static initializer of Item.class
70
        // that will assign value to the DEFAULT field above
71
        Class<Hyperlink> c = Hyperlink.class;
72
        try {
73
            Class.forName(c.getName(), true, c.getClassLoader());
74
        } catch (ClassNotFoundException ex) {
75
            assert false : ex;
76
        }
77
        assert DEFAULT != null :
78
                "The DEFAULT field must be initialized";                //NOI18N
79
        return DEFAULT;
80
    }
81
82
    public abstract HyperlinkType getType(Hyperlink hyperlink);
83
84
    public abstract boolean isImportant(Hyperlink hyperlink);
85
86
    public abstract Runnable getRunnable(Hyperlink hyperlink);
87
88
    public abstract URI getURI(Hyperlink hyperlink);
89
}
(-)a/api.io/src/org/netbeans/modules/io/OutputColorAccessor.java (+84 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.io;
43
44
import org.netbeans.api.io.OutputColor;
45
import org.netbeans.spi.io.support.OutputColorType;
46
47
/**
48
 *
49
 * @author jhavlin
50
 */
51
public abstract class OutputColorAccessor {
52
53
    /**
54
     * The default implementation is set in static initializer of
55
     * {@link OutputColor}.
56
     */
57
    private static OutputColorAccessor DEFAULT;
58
59
    public static void setDefault(OutputColorAccessor def) {
60
        OutputColorAccessor.DEFAULT = def;
61
    }
62
63
    public static OutputColorAccessor getDefault() {
64
        if (DEFAULT != null) {
65
            return DEFAULT;
66
        }
67
68
        // invokes static initializer of Item.class
69
        // that will assign value to the DEFAULT field above
70
        Class<OutputColor> c = OutputColor.class;
71
        try {
72
            Class.forName(c.getName(), true, c.getClassLoader());
73
        } catch (ClassNotFoundException ex) {
74
            assert false : ex;
75
        }
76
        assert DEFAULT != null :
77
                "The DEFAULT field must be initialized";                //NOI18N
78
        return DEFAULT;
79
    }
80
81
    public abstract OutputColorType getType(OutputColor color);
82
83
    public abstract int getRgb(OutputColor color);
84
}
(-)a/api.io/src/org/netbeans/spi/io/InputOutputProvider.java (+329 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.io;
43
44
import java.io.PrintWriter;
45
import java.io.Reader;
46
import java.util.Set;
47
import org.netbeans.api.annotations.common.CheckForNull;
48
import org.netbeans.api.annotations.common.NonNull;
49
import org.netbeans.api.annotations.common.NullAllowed;
50
import org.netbeans.api.io.Hyperlink;
51
import org.netbeans.api.io.InputOutput;
52
import org.netbeans.api.io.OutputColor;
53
import org.netbeans.api.io.ShowOperation;
54
import org.openide.util.Lookup;
55
import org.openide.util.lookup.ServiceProvider;
56
57
/**
58
 *
59
 * SPI for custom output window implementations.
60
 * <p>
61
 * Use {@link ServiceProvider} annotation for registration.
62
 * </p>
63
 *
64
 * <p>
65
 * Note: Methods of this interface can be called in any thread by the
66
 * infrastructure, so implementations should ensure proper synchronization.
67
 * </p>
68
 *
69
 * @author jhavlin
70
 *
71
 * @param <IO> Type of objects that will represent I/O instances (e.g. tabs in
72
 * output window).
73
 * @param <WRITER> Type of writers for standard and error streams.
74
 * @param <POS> Type of object that describes position of a character in the
75
 * output window. If the implementation does not support this type of
76
 * information, use {@link Void} here.
77
 * @param <FOLD> Type of object that describes a fold in output window. If the
78
 * implementation does not support this type of information, use {@link Void}
79
 * here.
80
 */
81
public interface InputOutputProvider<IO, WRITER extends PrintWriter, POS, FOLD> {
82
83
    /**
84
     * Get identifier of this provider.
85
     *
86
     * @return Name of this provider, never null.
87
     */
88
    @NonNull
89
    String getId();
90
91
    /**
92
     * Get or create an object that encapsulates state of a single I/O instance
93
     * (e.g. tab in output window).
94
     *
95
     * @param name Display name of the output pane.
96
     * @param newIO True to always create new I/O, false to return already
97
     * existing instance if available.
98
     * @param lookup Lookup with additional information.
99
     *
100
     * @return A single I/O instance, a newly created or already existing.
101
     * @see InputOutput
102
     */
103
    @NonNull
104
    IO getIO(@NonNull String name, boolean newIO, @NonNull Lookup lookup);
105
106
    /**
107
     * Get input of the passed I/O.
108
     *
109
     * @param io I/O instance.
110
     *
111
     * @return {@link Reader} Reader for the input entered in the output pane.
112
     */
113
    @NonNull
114
    Reader getIn(@NonNull IO io);
115
116
    /**
117
     * Get output stream of the passed I/O.
118
     *
119
     * @param io I/O instance.
120
     *
121
     * @return {@link PrintWriter} for the output stream.
122
     */
123
    @NonNull
124
    WRITER getOut(@NonNull IO io);
125
126
    /**
127
     * Get error stream of the passed I/O.
128
     *
129
     * @param io The I/O instance.
130
     *
131
     * @return {@link PrintWriter} for the error stream.
132
     */
133
    @NonNull
134
    WRITER getErr(@NonNull IO io);
135
136
    /**
137
     * Print enhanced text. It can represent a clickable hyperlink, and can be
138
     * assigned some color.
139
     *
140
     * <p>
141
     * If the implementation doesn't support this feature, this method should
142
     * call something like
143
     * {@code writer.print(text); if (printLineEnd) {writer.println();}}.
144
     * </p>
145
     *
146
     * @param io The I/O instance.
147
     * @param writer The Stream to write into.
148
     * @param text Text to print.
149
     * @param link Link which should be represented by the text, can be null for
150
     * standard text.
151
     * @param color Color of the text, can be null for the default color of the
152
     * stream.
153
     * @param printLineEnd True if new-line should be appended after printing
154
     * {code text}.
155
     */
156
    void print(@NonNull IO io, @NonNull WRITER writer, @NullAllowed String text,
157
            @NullAllowed Hyperlink link, @NullAllowed OutputColor color,
158
            boolean printLineEnd);
159
160
    /**
161
     * Get lookup of an I/O instance, which can contain various extensions and
162
     * additional info.
163
     *
164
     * @param io The I/O instance.
165
     *
166
     * @return The lookup, which can be empty, but never null.
167
     */
168
    @NonNull
169
    Lookup getIOLookup(@NonNull IO io);
170
171
    /**
172
     * Reset the I/O. Clear previously written data and prepare it for new data.
173
     * <p>
174
     * If the implementation doesn't support this feature, this method should do
175
     * nothing.
176
     * </p>
177
     *
178
     * @param io The I/O instance.
179
     */
180
    void resetIO(@NonNull IO io);
181
182
    /**
183
     * Show output pane for the passed I/O instance.
184
     * <p>
185
     * If the implementation doesn't support this feature, this method should do
186
     * nothing.
187
     * </p>
188
     *
189
     * @param io The I/O instance.
190
     * @param operations Operations that should be performed to show the output.
191
     * If the set is empty, the output pane (e.g. tab) can be selected, but no
192
     * GUI component should be shown or made visible if it is currently closed
193
     * or hidden.
194
     *
195
     * @see ShowOperation
196
     */
197
    void showIO(@NonNull IO io,
198
            Set<ShowOperation> operations);
199
200
    /**
201
     * Close the I/O, its output pane and release resources.
202
     *
203
     * @param io The I/O instance.
204
     *
205
     * @see #isIOClosed(java.lang.Object)
206
     */
207
    void closeIO(@NonNull IO io);
208
209
    /**
210
     * Check whether the I/O is closed.
211
     *
212
     * @param io The I/O instance.
213
     *
214
     * @return True if the I/O was closed, false otherwise.
215
     *
216
     * @see #closeIO(java.lang.Object)
217
     */
218
    boolean isIOClosed(@NonNull IO io);
219
220
    /**
221
     * Get current position.
222
     *
223
     * @param io The I/O instance.
224
     * @param writer Output or error writer. If the streams are merged, the
225
     * value can be ignored.
226
     *
227
     * @return The current position in the output pane. If this feature is not
228
     * supported, return null.
229
     */
230
    @CheckForNull
231
    POS getCurrentPosition(@NonNull IO io, @NonNull WRITER writer);
232
233
    /**
234
     * Scroll to a position.
235
     * <p>
236
     * If this feature is not supported
237
     * ({@link #getCurrentPosition(Object, PrintWriter)} returns null), this
238
     * method should do nothing, it will be never called.
239
     * </p>
240
     *
241
     * @param io The I/O instance.
242
     * @param writer Output or error writer. If the streams are merged, the
243
     * value can be ignored.
244
     * @param position The position to scroll to.
245
     *
246
     * @see #getCurrentPosition(java.lang.Object, java.io.PrintWriter)
247
     */
248
    void scrollTo(@NonNull IO io, @NonNull WRITER writer,
249
            @NonNull POS position);
250
251
    /**
252
     * Start fold at the current position. If a fold is already open, start a
253
     * new nested fold (but if a fold with the same start position already
254
     * exists, no nested fold will be created, and the same start position will
255
     * be returned).
256
     *
257
     * @param io The I/O instance.
258
     * @param writer Output or error writer. If the streams are merged, the
259
     * value can be ignored.
260
     * @param expanded True if the new fold should be expanded by default, false
261
     * if it should be collapsed.
262
     *
263
     * @return Object the fold. If the implementation doesn't support this
264
     * feature, return null.
265
     */
266
    @CheckForNull
267
    FOLD startFold(@NonNull IO io, @NonNull WRITER writer, boolean expanded);
268
269
    /**
270
     * Finish a fold specified by its start position. If some nested folds
271
     * exist, they will be finished as well if needed.
272
     *
273
     * <p>
274
     * If this feature is not supported
275
     * ({@link #startFold(Object, PrintWriter, boolean)} returns null), this
276
     * method should do nothing, it will be never called.
277
     * </p>
278
     *
279
     * @param io The I/O instance.
280
     * @param writer Output or error writer. If the streams are merged, the
281
     * value can be ignored.
282
     * @param fold The fold to finish.
283
     */
284
    void endFold(@NonNull IO io, @NonNull WRITER writer,
285
            @NonNull FOLD fold);
286
287
    /**
288
     * Expand or collapse a fold.
289
     *
290
     * <p>
291
     * If this feature is not supported
292
     * ({@link #startFold(Object, PrintWriter, boolean)} returns null), this
293
     * method should do nothing, it will be never called.
294
     * </p>
295
     *
296
     * @param io The I/O instance.
297
     * @param writer Output or error writer. If the streams are merged, the
298
     * value can be ignored.
299
     * @param fold The fold to finish.
300
     * @param expanded True to expand the fold, false to collapse the fold.
301
     */
302
    void setFoldExpanded(@NonNull IO io, @NonNull WRITER writer,
303
            FOLD fold, boolean expanded);
304
305
306
    /**
307
     * Get description of an I/O instance. It can be used e.g. as tooltip text
308
     * for the output tab.
309
     *
310
     * @param io The I/O instance.
311
     *
312
     * @return The description, or null if not set.
313
     */
314
    @CheckForNull String getIODescription(@NonNull IO io);
315
316
    /**
317
     * Set description of an I/O instance.
318
     *
319
     * <p>
320
     * If this feature is not supported, this method should do nothing.
321
     * </p>
322
     *
323
     * @param io The I/O instance.
324
     * @param description The description, can be null.
325
     *
326
     * @see #getIODescription(java.lang.Object)
327
     */
328
    void setIODescription(@NonNull IO io, @NullAllowed String description);
329
}
(-)a/api.io/src/org/netbeans/spi/io/support/HyperlinkType.java (+54 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.io.support;
43
44
/**
45
 * Type of the hyperlink.
46
 * <p>
47
 * Note: New items may be added in the future.
48
 * </p>
49
 *
50
 * @author jhavlin
51
 */
52
public enum HyperlinkType {
53
    FROM_RUNNABLE, FROM_URI
54
}
(-)a/api.io/src/org/netbeans/spi/io/support/Hyperlinks.java (+115 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.io.support;
43
44
import java.net.URI;
45
import org.netbeans.api.annotations.common.NonNull;
46
import org.netbeans.api.io.Hyperlink;
47
import org.netbeans.modules.io.HyperlinkAccessor;
48
49
/**
50
 * Helper class for accessing information from {@link Hyperlink} objects.
51
 *
52
 * @author jhavlin
53
 */
54
public final class Hyperlinks {
55
56
    private Hyperlinks() {
57
    }
58
59
    /**
60
     * Get hyperlink type.
61
     *
62
     * @param hyperlink The hyperlink to get type of.
63
     * @return The type of the hyperlink.
64
     */
65
    @NonNull
66
    public static HyperlinkType getType(@NonNull Hyperlink hyperlink) {
67
        return HyperlinkAccessor.getDefault().getType(hyperlink);
68
    }
69
70
    /**
71
     * Check whether a hyperlink is important.
72
     *
73
     * @param hyperlink The hyperlink to check.
74
     *
75
     * @return True if the hyperlink has been marked as important, false if it
76
     * is a standard link.
77
     */
78
    public static boolean isImportant(@NonNull Hyperlink hyperlink) {
79
        return HyperlinkAccessor.getDefault().isImportant(hyperlink);
80
    }
81
82
    /**
83
     * Get URI associated with a hyperlink of type
84
     * {@link HyperlinkType#FROM_URI}.
85
     *
86
     * @param hyperlink The hyperlink to get URI from.
87
     *
88
     * @return The URI.
89
     * @throws IllegalArgumentException if type of the hyperlink is not
90
     * {@link HyperlinkType#FROM_URI}.
91
     * @see #getType(org.netbeans.api.io.Hyperlink)
92
     * @see HyperlinkType
93
     */
94
    @NonNull
95
    public static URI getURI(@NonNull Hyperlink hyperlink) {
96
        return HyperlinkAccessor.getDefault().getURI(hyperlink);
97
    }
98
99
    /**
100
     * Get runnable associated with a hyperlink of type
101
     * {@link HyperlinkType#FROM_RUNNABLE}.
102
     *
103
     * @param hyperlink The hyperlink to get runnable from.
104
     *
105
     * @return A runnable.
106
     * @throws IllegalArgumentException if type of the hyperlink is not
107
     * {@link HyperlinkType#FROM_RUNNABLE}.
108
     * @see #getType(org.netbeans.api.io.Hyperlink)
109
     * @see HyperlinkType
110
     */
111
    @NonNull
112
    public static Runnable getRunnable(@NonNull Hyperlink hyperlink) {
113
        return HyperlinkAccessor.getDefault().getRunnable(hyperlink);
114
    }
115
}
(-)a/api.io/src/org/netbeans/spi/io/support/OutputColorType.java (+54 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.io.support;
43
44
/**
45
 * Type of the color - static (rgb) or dynamic.
46
 * <p>
47
 * Note: New items may be added in the future.
48
 * </p>
49
 *
50
 * @author jhavlin
51
 */
52
public enum OutputColorType {
53
    WARNING, FAILURE, DEBUG, SUCCESS, RGB
54
}
(-)a/api.io/src/org/netbeans/spi/io/support/OutputColors.java (+83 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.io.support;
43
44
import org.netbeans.api.annotations.common.NonNull;
45
import org.netbeans.api.io.OutputColor;
46
import org.netbeans.modules.io.OutputColorAccessor;
47
48
/**
49
 * Helper class for accessing information from {@link OutputColor} objects.
50
 *
51
 * @author jhavlin
52
 */
53
public final class OutputColors {
54
55
    private OutputColors() {
56
    }
57
58
    /**
59
     * Get type of a color.
60
     *
61
     * @param color The color to get type of.
62
     * @return Type of color.
63
     */
64
    @NonNull
65
    public static OutputColorType getType(@NonNull OutputColor color) {
66
        return OutputColorAccessor.getDefault().getType(color);
67
    }
68
69
    /**
70
     * Get RGB value for an {@link OutputColor} specified for a constant RGB
71
     * color (type {@link OutputColorType#RGB}).
72
     *
73
     * @param color The color to get RGB value for.
74
     *
75
     * @return RGB value of the color.
76
     * @throws IllegalArgumentException if the color is not of type
77
     * {@link OutputColorType#RGB}.
78
     */
79
    public static int getRGB(OutputColor color) {
80
        return OutputColorAccessor.getDefault().getRgb(color);
81
    }
82
83
}
(-)a/api.io/test/unit/src/org/netbeans/api/io/HyperlinkTest.java (+99 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import java.net.URI;
45
import java.net.URISyntaxException;
46
import static org.junit.Assert.*;
47
import org.junit.Test;
48
import org.netbeans.spi.io.support.HyperlinkType;
49
import org.netbeans.spi.io.support.Hyperlinks;
50
51
/**
52
 *
53
 * @author jhavlin
54
 */
55
public class HyperlinkTest {
56
57
    @Test
58
    public void testUriLink() throws URISyntaxException {
59
        Hyperlink h = Hyperlink.from(new URI("file://x"));
60
        assertTrue(Hyperlinks.getType(h) == HyperlinkType.FROM_URI);
61
        assertFalse(h.isImportant());
62
        assertNotNull(Hyperlinks.getURI(h));
63
        assertEquals("file://x", Hyperlinks.getURI(h).toString());
64
    }
65
66
    @Test
67
    public void testUriLinkImportant() throws URISyntaxException {
68
        Hyperlink h = Hyperlink.from(new URI("file://x"), true);
69
        assertTrue(h.isImportant());
70
    }
71
72
    @Test
73
    public void testOnClickLink() {
74
75
        final boolean[] invoked = new boolean[1];
76
        Hyperlink h = Hyperlink.from(new Runnable() {
77
78
            @Override
79
            public void run() {
80
                invoked[0] = true;
81
            }
82
        });
83
        assertTrue(Hyperlinks.getType(h) == HyperlinkType.FROM_RUNNABLE);
84
        assertFalse(h.isImportant());
85
        assertNotNull(Hyperlinks.getRunnable(h));
86
        Hyperlinks.getRunnable(h).run();
87
        assertTrue("The passed code should be invoked", invoked[0]);
88
    }
89
90
    @Test
91
    public void testOnClickLinkImportant() {
92
        Hyperlink h = Hyperlink.from(new Runnable() {
93
            @Override
94
            public void run() {
95
            }
96
        }, true);
97
        assertTrue(h.isImportant());
98
    }
99
}
(-)a/api.io/test/unit/src/org/netbeans/api/io/IOProviderTest.java (+283 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import java.io.PrintWriter;
45
import java.io.Reader;
46
import java.io.StringReader;
47
import java.io.StringWriter;
48
import java.net.URI;
49
import java.net.URISyntaxException;
50
import java.util.ArrayList;
51
import java.util.Set;
52
import org.junit.Test;
53
import static org.junit.Assert.*;
54
import org.netbeans.junit.MockServices;
55
import org.netbeans.spi.io.InputOutputProvider;
56
import org.openide.util.Lookup;
57
import org.openide.util.lookup.Lookups;
58
59
/**
60
 *
61
 * @author jhavlin
62
 */
63
public class IOProviderTest {
64
65
    public IOProviderTest() {
66
    }
67
68
    @Test
69
    public void useCase1() {
70
        InputOutput io = IOProvider.getDefault().getIO("UseCase1", true);
71
        io.getOut().println("This is a simple output");
72
        io.getOut().close();
73
    }
74
75
    @Test
76
    public void useCase2() throws URISyntaxException {
77
        InputOutput io = IOProvider.getDefault().getIO("UseCase2", false);
78
        io.getOut().print("A line containing a ");
79
        io.getOut().print("hyperlink", Hyperlink.from(new URI(
80
                "file://n:/test/Test.java?line=4&col=2")));
81
        io.getOut().println(" for a URI.");
82
        io.getOut().close();
83
    }
84
85
    @Test
86
    public void useCase3() {
87
        InputOutput io = IOProvider.getDefault().getIO("UseCase3", true);
88
        io.getOut().print("A line containing a ");
89
        io.getOut().print("hyperlink", Hyperlink.from(new Runnable() {
90
            @Override
91
            public void run() {
92
                System.gc();
93
            }
94
        }));
95
        io.getOut().println(" for invokation of custom code.");
96
        io.getOut().close();
97
    }
98
99
    @Test
100
    public void useCase4() {
101
        InputOutput io = IOProvider.getDefault().getIO("UseCase4", true);
102
        io.getOut().println("Let's print some info", OutputColor.debug());
103
        io.getOut().println("or warning with appropriate color",
104
                OutputColor.warning());
105
        io.getOut().println("Maybe also text with custom reddish color",
106
                OutputColor.rgb(255, 16, 16));
107
        io.getOut().close();
108
    }
109
110
    @Test
111
    public void useCase5() {
112
        InputOutput io = IOProvider.getDefault().getIO("UseCase5", true);
113
        io.getOut().println("Let's print some text");
114
        io.getErr().println("and reset the pane immediately.");
115
        io.reset();
116
        io.getOut().println("The pane is now empty and we can reuse it simply");
117
        io.getOut().close();
118
    }
119
120
    @Test
121
    public void testTrivialImplementationAlwaysAvailable() {
122
        assertEquals("Trivial", IOProvider.getDefault().getId());
123
        assertEquals("Trivial", IOProvider.get("Trivial").getId());
124
        assertEquals("Trivial", IOProvider.get("Another").getId());
125
    }
126
127
    @Test
128
    public void testGetFromLookup() {
129
        MockServices.setServices(MockInputOutputProvider.class);
130
        try {
131
            assertEquals("mock", IOProvider.getDefault().getId());
132
            assertEquals("mock", IOProvider.get("mock").getId());
133
            assertEquals("mock", IOProvider.get("wrong").getId());
134
        } finally {
135
            MockServices.setServices();
136
        }
137
    }
138
139
    @Test
140
    public void testAllMethodsAreDelegatedToSPI() {
141
        MockServices.setServices(MockInputOutputProvider.class);
142
        try {
143
            IOProvider.getDefault().getIO("test1", true);
144
            Lookup lkp = IOProvider.getDefault()
145
                    .getIO("test1", false, Lookup.EMPTY).getLookup();
146
            CalledMethodList list = lkp.lookup(CalledMethodList.class);
147
            assertEquals("getIO", list.get(0));
148
            assertEquals("getIO", list.get(1));
149
            assertEquals("getIOLookup", list.get(2));
150
            assertEquals(3, list.size());
151
        } finally {
152
            MockServices.setServices();
153
        }
154
    }
155
156
    @SuppressWarnings("PackageVisibleInnerClass")
157
    static class CalledMethodList extends ArrayList<String> {
158
    }
159
160
    @SuppressWarnings("PublicInnerClass")
161
    public static class MockInputOutputProvider implements
162
            InputOutputProvider<Object, PrintWriter, Object, Object> {
163
164
        private final CalledMethodList calledMethods = new CalledMethodList();
165
        private final StringWriter stringWriter = new StringWriter();
166
        private final Lookup lookup = Lookups.fixed(calledMethods, stringWriter);
167
168
        @Override
169
        public String getId() {
170
            return "mock";
171
        }
172
173
        @Override
174
        public Object getIO(String name, boolean newIO, Lookup lookup) {
175
            calledMethods.add("getIO");
176
            return new Object();
177
        }
178
179
        @Override
180
        public Reader getIn(Object io) {
181
            calledMethods.add("getIn");
182
            return new StringReader("");
183
        }
184
185
        @Override
186
        public PrintWriter getOut(Object io) {
187
            calledMethods.add("getOut");
188
            return new PrintWriter(stringWriter);
189
        }
190
191
        @Override
192
        public PrintWriter getErr(Object io) {
193
            calledMethods.add("getErr");
194
            return new PrintWriter(stringWriter);
195
        }
196
197
        @Override
198
        public void print(Object io, PrintWriter writer, String text,
199
                Hyperlink link, OutputColor color, boolean printLineEnd) {
200
            if (link != null || color != null) {
201
                stringWriter.append("<ext");
202
                stringWriter.append(color != null ? " color" : "");
203
                stringWriter.append(link != null ? " link" : "");
204
                stringWriter.append(">");
205
            }
206
            stringWriter.append(text);
207
            if (link != null || color != null) {
208
                stringWriter.append("</ext>");
209
            }
210
            calledMethods.add("print");
211
            if (printLineEnd) {
212
                stringWriter.append(System.getProperty("line.separator"));
213
            }
214
        }
215
216
        @Override
217
        public Lookup getIOLookup(Object io) {
218
            calledMethods.add("getIOLookup");
219
            return lookup;
220
        }
221
222
        @Override
223
        public void resetIO(Object io) {
224
            calledMethods.add("resetIO");
225
        }
226
227
        @Override
228
        public void showIO(Object io,
229
                Set<ShowOperation> operations) {
230
            calledMethods.add("showIO");
231
        }
232
233
        @Override
234
        public void closeIO(Object io) {
235
            calledMethods.add("closeIO");
236
        }
237
238
        @Override
239
        public boolean isIOClosed(Object io) {
240
            calledMethods.add("isIOClosed");
241
            return false;
242
        }
243
244
        @Override
245
        public Object getCurrentPosition(Object io, PrintWriter writer) {
246
            calledMethods.add("getCurrentPosition");
247
            return new Object();
248
        }
249
250
        @Override
251
        public void scrollTo(Object io, PrintWriter writer, Object position) {
252
            calledMethods.add("scrollTo");
253
        }
254
255
        @Override
256
        public Object startFold(Object io, PrintWriter writer, boolean expanded) {
257
            calledMethods.add("startFold");
258
            return new Object();
259
        }
260
261
        @Override
262
        public void endFold(Object io, PrintWriter writer, Object foldNumber) {
263
            calledMethods.add("endFold");
264
        }
265
266
        @Override
267
        public void setFoldExpanded(Object io, PrintWriter writer,
268
                Object foldNumber, boolean expanded) {
269
            calledMethods.add("setFoldExpanded");
270
        }
271
272
        @Override
273
        public String getIODescription(Object io) {
274
            calledMethods.add("getIODescription");
275
            return null;
276
        }
277
278
        @Override
279
        public void setIODescription(Object io, String description) {
280
            calledMethods.add("setIODescription");
281
        }
282
    }
283
}
(-)a/api.io/test/unit/src/org/netbeans/api/io/InputOutputTest.java (+91 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import org.junit.Test;
45
import static org.junit.Assert.*;
46
import org.netbeans.junit.MockServices;
47
import org.openide.util.Lookup;
48
49
/**
50
 *
51
 * @author jhavlin
52
 */
53
public class InputOutputTest {
54
55
    public InputOutputTest() {
56
    }
57
58
    @Test
59
    @SuppressWarnings("ValueOfIncrementOrDecrementUsed")
60
    public void testAllMethodsAreDelegatedToSPI() {
61
        MockServices.setServices(IOProviderTest.MockInputOutputProvider.class);
62
        try {
63
            InputOutput io = IOProvider.getDefault().getIO("test1", true);
64
            io.getIn();
65
            io.getOut();
66
            io.getErr();
67
            io.reset();
68
            io.isClosed();
69
            io.close();
70
            io.getDescription();
71
            io.setDescription(null);
72
            Lookup lkp = io.getLookup();
73
            IOProviderTest.CalledMethodList list
74
                    = lkp.lookup(IOProviderTest.CalledMethodList.class);
75
76
            int order = 0;
77
            assertEquals("getIO", list.get(order++));
78
            assertEquals("getIn", list.get(order++));
79
            assertEquals("getOut", list.get(order++));
80
            assertEquals("getErr", list.get(order++));
81
            assertEquals("resetIO", list.get(order++));
82
            assertEquals("isIOClosed", list.get(order++));
83
            assertEquals("closeIO", list.get(order++));
84
            assertEquals("getIODescription", list.get(order++));
85
            assertEquals("setIODescription", list.get(order++));
86
            assertEquals("getIOLookup", list.get(order++));
87
        } finally {
88
            MockServices.setServices();
89
        }
90
    }
91
}
(-)a/api.io/test/unit/src/org/netbeans/api/io/OutputColorTest.java (+91 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import org.netbeans.spi.io.support.OutputColorType;
45
import org.junit.Test;
46
import static org.junit.Assert.*;
47
import org.netbeans.spi.io.support.OutputColors;
48
49
/**
50
 *
51
 * @author jhavlin
52
 */
53
public class OutputColorTest {
54
55
    @Test
56
    public void testRgbColor() {
57
        OutputColor c = OutputColor.rgb(127, 255, 1);
58
        assertEquals(OutputColorType.RGB, OutputColors.getType(c));
59
        int value = OutputColors.getRGB(c);
60
        int r = value >> 16;
61
        int g = value >> 8 & 0xFF;
62
        int b = value & 0xFF;
63
        assertEquals(127, r);
64
        assertEquals(255, g);
65
        assertEquals(1, b);
66
    }
67
68
    @Test
69
    public void testWarningColor() {
70
        OutputColor c = OutputColor.warning();
71
        assertEquals(OutputColorType.WARNING, c.getType());
72
    }
73
74
    @Test
75
    public void testFailureColor() {
76
        OutputColor c = OutputColor.failure();
77
        assertEquals(OutputColorType.FAILURE, c.getType());
78
    }
79
80
    @Test
81
    public void testDebugColor() {
82
        OutputColor c = OutputColor.debug();
83
        assertEquals(OutputColorType.DEBUG, c.getType());
84
    }
85
86
    @Test
87
    public void testSuccessColor() {
88
        OutputColor c = OutputColor.success();
89
        assertEquals(OutputColorType.SUCCESS, c.getType());
90
    }
91
}
(-)a/api.io/test/unit/src/org/netbeans/api/io/OutputWriterTest.java (+129 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.io;
43
44
import java.io.StringWriter;
45
import java.net.URI;
46
import java.net.URISyntaxException;
47
import org.junit.Test;
48
import static org.junit.Assert.*;
49
import org.netbeans.junit.MockServices;
50
import org.openide.util.Lookup;
51
52
/**
53
 *
54
 * @author jhavlin
55
 */
56
public class OutputWriterTest {
57
58
    public OutputWriterTest() {
59
    }
60
61
    @Test
62
    @SuppressWarnings("ValueOfIncrementOrDecrementUsed")
63
    public void testAllMethodsAreDelegatedToSPI() throws URISyntaxException {
64
        MockServices.setServices(IOProviderTest.MockInputOutputProvider.class);
65
        try {
66
67
            InputOutput io = IOProvider.getDefault().getIO("test1", true);
68
            OutputWriter ow = io.getOut();
69
            Lookup lkp = io.getLookup();
70
71
            IOProviderTest.CalledMethodList list
72
                    = lkp.lookup(IOProviderTest.CalledMethodList.class);
73
74
            io.show();
75
            Position p = ow.getCurrentPosition();
76
            p.scrollTo();
77
            Fold f = ow.startFold(true);
78
            f.expand();
79
            f.collapse();
80
            ow.endFold(f);
81
82
            int order = 0;
83
            assertEquals("getIO", list.get(order++));
84
            assertEquals("getOut", list.get(order++));
85
            assertEquals("getIOLookup", list.get(order++));
86
            assertEquals("showIO", list.get(order++));
87
            assertEquals("getCurrentPosition", list.get(order++));
88
            assertEquals("scrollTo", list.get(order++));
89
            assertEquals("startFold", list.get(order++));
90
            assertEquals("setFoldExpanded", list.get(order++));
91
            assertEquals("setFoldExpanded", list.get(order++));
92
            assertEquals("endFold", list.get(order++));
93
94
            ow.print("Line");
95
            ow.print(" 1");
96
            ow.println();
97
98
            ow.print("Hyperlink ", Hyperlink.from(new URI("file://x")));
99
            ow.print(" ");
100
            ow.print("Color", OutputColor.debug());
101
            ow.print(" ");
102
            ow.print("Color link", Hyperlink.from(new URI("file://y")),
103
                    OutputColor.debug());
104
            ow.println();
105
106
            ow.println("Line with link", Hyperlink.from(new URI("file://z")));
107
            ow.println("Color line", OutputColor.debug());
108
            ow.println("Color line with link",
109
                    Hyperlink.from(new URI("file://a")), OutputColor.debug());
110
111
            StringWriter sw = lkp.lookup(StringWriter.class);
112
            sw.toString();
113
114
            String[] lines = sw.toString().split(
115
                    System.getProperty("line.separator"));
116
117
            assertEquals("Line 1", lines[0]);
118
            assertEquals("<ext link>Hyperlink </ext> <ext color>Color</ext> "
119
                    + "<ext color link>Color link</ext>", lines[1]);
120
            assertEquals("<ext link>Line with link</ext>", lines[2]);
121
            assertEquals("<ext color>Color line</ext>", lines[3]);
122
            assertEquals("<ext color link>Color line with link</ext>", lines[4]);
123
124
        } finally {
125
            MockServices.setServices();
126
        }
127
    }
128
129
}
(-)a/core.output2/manifest.mf (-1 / +1 lines)
Lines 2-8 Link Here
2
OpenIDE-Module: org.netbeans.core.output2/1
2
OpenIDE-Module: org.netbeans.core.output2/1
3
OpenIDE-Module-Layer: org/netbeans/core/output2/layer.xml
3
OpenIDE-Module-Layer: org/netbeans/core/output2/layer.xml
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/output2/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/output2/Bundle.properties
5
OpenIDE-Module-Provides: org.openide.windows.IOProvider
5
OpenIDE-Module-Provides: org.openide.windows.IOProvider org.netbeans.spi.io.InputOutputProvider
6
AutoUpdate-Essential-Module: true
6
AutoUpdate-Essential-Module: true
7
OpenIDE-Module-Specification-Version: 1.38
7
OpenIDE-Module-Specification-Version: 1.38
8
8
(-)a/core.output2/nbproject/project.xml (-1 / +9 lines)
Lines 50-55 Link Here
50
            <code-name-base>org.netbeans.core.output2</code-name-base>
50
            <code-name-base>org.netbeans.core.output2</code-name-base>
51
            <module-dependencies>
51
            <module-dependencies>
52
                <dependency>
52
                <dependency>
53
                    <code-name-base>org.netbeans.api.io</code-name-base>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
56
                    <run-dependency>
57
                        <specification-version>1.0</specification-version>
58
                    </run-dependency>
59
                </dependency>
60
                <dependency>
53
                    <code-name-base>org.netbeans.modules.options.api</code-name-base>
61
                    <code-name-base>org.netbeans.modules.options.api</code-name-base>
54
                    <build-prerequisite/>
62
                    <build-prerequisite/>
55
                    <compile-dependency/>
63
                    <compile-dependency/>
Lines 111-117 Link Here
111
                    <build-prerequisite/>
119
                    <build-prerequisite/>
112
                    <compile-dependency/>
120
                    <compile-dependency/>
113
                    <run-dependency>
121
                    <run-dependency>
114
                        <specification-version>1.40</specification-version>
122
                        <specification-version>1.47</specification-version>
115
                    </run-dependency>
123
                    </run-dependency>
116
                </dependency>
124
                </dependency>
117
                <dependency>
125
                <dependency>
(-)a/core.output2/src/org/netbeans/core/output2/NbIOProvider.java (-2 / +10 lines)
Lines 47-54 Link Here
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.util.WeakHashMap;
48
import java.util.WeakHashMap;
49
import javax.swing.Action;
49
import javax.swing.Action;
50
import org.netbeans.spi.io.InputOutputProvider;
50
import org.openide.util.Exceptions;
51
import org.openide.util.Exceptions;
51
import org.openide.util.NbBundle;
52
import org.openide.util.NbBundle;
53
import org.openide.util.lookup.ServiceProvider;
54
import org.openide.util.lookup.ServiceProviders;
55
import org.openide.windows.BridgingIOProvider;
52
import org.openide.windows.IOContainer;
56
import org.openide.windows.IOContainer;
53
import org.openide.windows.IOProvider;
57
import org.openide.windows.IOProvider;
54
import org.openide.windows.InputOutput;
58
import org.openide.windows.InputOutput;
Lines 58-65 Link Here
58
 * Supplies Output Window implementation through Lookup.
62
 * Supplies Output Window implementation through Lookup.
59
 * @author Jesse Glick, Tim Boudreau
63
 * @author Jesse Glick, Tim Boudreau
60
 */
64
 */
61
@org.openide.util.lookup.ServiceProvider(service=org.openide.windows.IOProvider.class, position=100)
65
@ServiceProviders({
62
public final class NbIOProvider extends IOProvider {
66
    @ServiceProvider(service=IOProvider.class, position=100),
67
    @ServiceProvider(service=InputOutputProvider.class, position=100)
68
})
69
public final class NbIOProvider extends BridgingIOProvider {
70
63
    private static final WeakHashMap<IOContainer, PairMap> containerPairMaps =
71
    private static final WeakHashMap<IOContainer, PairMap> containerPairMaps =
64
            new WeakHashMap<IOContainer, PairMap>();
72
            new WeakHashMap<IOContainer, PairMap>();
65
73
(-)a/nbbuild/build.properties (+2 lines)
Lines 100-105 Link Here
100
config.javadoc.stable=\
100
config.javadoc.stable=\
101
    api.annotations.common,\
101
    api.annotations.common,\
102
    api.html4j,\
102
    api.html4j,\
103
    api.intent,\
104
    api.io,\
103
    api.maven,\
105
    api.maven,\
104
    autoupdate.services,\
106
    autoupdate.services,\
105
    autoupdate.ui,\
107
    autoupdate.ui,\
(-)a/nbbuild/cluster.properties (+2 lines)
Lines 195-200 Link Here
195
nb.cluster.platform=\
195
nb.cluster.platform=\
196
        api.annotations.common,\
196
        api.annotations.common,\
197
        api.html4j,\
197
        api.html4j,\
198
        api.intent,\
199
        api.io,\
198
        api.progress,\
200
        api.progress,\
199
        api.progress.compat8,\
201
        api.progress.compat8,\
200
        api.progress.nb,\
202
        api.progress.nb,\
(-)a/nbbuild/javadoctools/links.xml (+2 lines)
Lines 234-236 Link Here
234
<link href="${javadoc.docs.org-netbeans-modules-project-ant-ui}" offline="true" packagelistloc="${netbeans.javadoc.dir}/org-netbeans-modules-project-ant-ui"/>
234
<link href="${javadoc.docs.org-netbeans-modules-project-ant-ui}" offline="true" packagelistloc="${netbeans.javadoc.dir}/org-netbeans-modules-project-ant-ui"/>
235
<link href="${javadoc.docs.org-netbeans-modules-java-project-ui}" offline="true" packagelistloc="${netbeans.javadoc.dir}/org-netbeans-modules-java-project-ui"/>
235
<link href="${javadoc.docs.org-netbeans-modules-java-project-ui}" offline="true" packagelistloc="${netbeans.javadoc.dir}/org-netbeans-modules-java-project-ui"/>
236
<link href="${javadoc.docs.org-netbeans-modules-xml-catalog-ui}" offline="true" packagelistloc="${netbeans.javadoc.dir}/org-netbeans-modules-xml-catalog-ui"/>
236
<link href="${javadoc.docs.org-netbeans-modules-xml-catalog-ui}" offline="true" packagelistloc="${netbeans.javadoc.dir}/org-netbeans-modules-xml-catalog-ui"/>
237
<link href="${javadoc.docs.org-netbeans-api-io}" offline="true" packagelistloc="${netbeans.javadoc.dir}\org-netbeans-api-io"/>
238
<link href="${javadoc.docs.org-netbeans-api-intent}" offline="true" packagelistloc="${netbeans.javadoc.dir}\org-netbeans-api-intent"/>
(-)a/nbbuild/javadoctools/properties.xml (+2 lines)
Lines 233-235 Link Here
233
<property name="javadoc.docs.org-netbeans-modules-project-ant-ui" value="${javadoc.web.root}/org-netbeans-modules-project-ant-ui"/>
233
<property name="javadoc.docs.org-netbeans-modules-project-ant-ui" value="${javadoc.web.root}/org-netbeans-modules-project-ant-ui"/>
234
<property name="javadoc.docs.org-netbeans-modules-java-project-ui" value="${javadoc.web.root}/org-netbeans-modules-java-project-ui"/>
234
<property name="javadoc.docs.org-netbeans-modules-java-project-ui" value="${javadoc.web.root}/org-netbeans-modules-java-project-ui"/>
235
<property name="javadoc.docs.org-netbeans-modules-xml-catalog-ui" value="${javadoc.web.root}/org-netbeans-modules-xml-catalog-ui"/>
235
<property name="javadoc.docs.org-netbeans-modules-xml-catalog-ui" value="${javadoc.web.root}/org-netbeans-modules-xml-catalog-ui"/>
236
<property name="javadoc.docs.org-netbeans-api-io" value="${javadoc.web.root}/org-netbeans-api-io"/>
237
<property name="javadoc.docs.org-netbeans-api-intent" value="${javadoc.web.root}/org-netbeans-api-intent"/>
(-)a/nbbuild/javadoctools/replaces.xml (+2 lines)
Lines 233-235 Link Here
233
<replacefilter token="@org-netbeans-modules-project-ant-ui@" value="${javadoc.docs.org-netbeans-modules-project-ant-ui}"/>
233
<replacefilter token="@org-netbeans-modules-project-ant-ui@" value="${javadoc.docs.org-netbeans-modules-project-ant-ui}"/>
234
<replacefilter token="@org-netbeans-modules-java-project-ui@" value="${javadoc.docs.org-netbeans-modules-java-project-ui}"/>
234
<replacefilter token="@org-netbeans-modules-java-project-ui@" value="${javadoc.docs.org-netbeans-modules-java-project-ui}"/>
235
<replacefilter token="@org-netbeans-modules-xml-catalog-ui@" value="${javadoc.docs.org-netbeans-modules-xml-catalog-ui}"/>
235
<replacefilter token="@org-netbeans-modules-xml-catalog-ui@" value="${javadoc.docs.org-netbeans-modules-xml-catalog-ui}"/>
236
<replacefilter token="@org-netbeans-api-io@" value="${javadoc.docs.org-netbeans-api-io}"/>
237
<replacefilter token="@org-netbeans-api-intent@" value="${javadoc.docs.org-netbeans-api-intent}"/>
(-)a/openide.io/apichanges.xml (+18 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
<changes>
109
<changes>
110
    <change id="BridgingIOProvider">
111
      <api name="io"/>
112
      <summary>Create a provider abstract class that implements new I/O SPI</summary>
113
      <version major="1" minor="47"/>
114
      <date day="22" month="10" year="2014"/>
115
      <author login="jhavlin"/>
116
      <compatibility addition="yes" binary="compatible" semantic="compatible" />
117
      <description>
118
          <p>
119
              As new API and SPI for output windows has been introduced, it is
120
              useful to have a convenient way for implementators of the original
121
              API to support the new API as well. The BridgingIOProvider class
122
              implements both SPIs, and its JavaDoc explains how to use it.
123
          </p>
124
      </description>
125
      <class package="org.openide.windows" name="BridgingIOProvider"/>
126
      <issue number="247404" />
127
    </change>
110
    <change id="enhancedFoldHandleApi">
128
    <change id="enhancedFoldHandleApi">
111
      <api name="io"/>
129
      <api name="io"/>
112
      <summary>Created new user-friendly methods for working with FoldHandle instances.</summary>
130
      <summary>Created new user-friendly methods for working with FoldHandle instances.</summary>
(-)a/openide.io/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.io
2
OpenIDE-Module: org.openide.io
3
OpenIDE-Module-Specification-Version: 1.46
3
OpenIDE-Module-Specification-Version: 1.47
4
OpenIDE-Module-Localizing-Bundle: org/openide/io/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/io/Bundle.properties
5
OpenIDE-Module-Recommends: org.openide.windows.IOProvider, org.openide.windows.IOContainer$Provider
5
OpenIDE-Module-Recommends: org.openide.windows.IOProvider, org.openide.windows.IOContainer$Provider
6
AutoUpdate-Essential-Module: true
6
AutoUpdate-Essential-Module: true
(-)a/openide.io/nbproject/org-openide-io.sig (-1 / +1 lines)
Lines 1-5 Link Here
1
#Signature file v4.1
1
#Signature file v4.1
2
#Version 1.45
2
#Version 1.44.1
3
3
4
CLSS public abstract interface java.io.Closeable
4
CLSS public abstract interface java.io.Closeable
5
intf java.lang.AutoCloseable
5
intf java.lang.AutoCloseable
(-)a/openide.io/nbproject/project.xml (-3 / +11 lines)
Lines 59-69 Link Here
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
62
                    <code-name-base>org.openide.util</code-name-base>
62
                    <code-name-base>org.netbeans.api.intent</code-name-base>
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <specification-version>9.0</specification-version>
66
                        <specification-version>1.0</specification-version>
67
                    </run-dependency>
68
                </dependency>
69
                <dependency>
70
                    <code-name-base>org.netbeans.api.io</code-name-base>
71
                    <build-prerequisite/>
72
                    <compile-dependency/>
73
                    <run-dependency>
74
                        <specification-version>1.0</specification-version>
67
                    </run-dependency>
75
                    </run-dependency>
68
                </dependency>
76
                </dependency>
69
                <dependency>
77
                <dependency>
Lines 71-77 Link Here
71
                    <build-prerequisite/>
79
                    <build-prerequisite/>
72
                    <compile-dependency/>
80
                    <compile-dependency/>
73
                    <run-dependency>
81
                    <run-dependency>
74
                        <specification-version>9.0</specification-version>
82
                        <specification-version>9.1</specification-version>
75
                    </run-dependency>
83
                    </run-dependency>
76
                </dependency>
84
                </dependency>
77
                <dependency>
85
                <dependency>
(-)a/openide.io/src/org/openide/windows/BridgingIOProvider.java (+388 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.openide.windows;
43
44
import java.awt.Color;
45
import java.io.IOException;
46
import java.io.Reader;
47
import java.util.ArrayDeque;
48
import java.util.Deque;
49
import java.util.EnumSet;
50
import java.util.Set;
51
import java.util.logging.Level;
52
import java.util.logging.Logger;
53
import javax.swing.Action;
54
import org.netbeans.api.intent.Intent;
55
import org.netbeans.api.intent.IntentManager;
56
import org.netbeans.api.io.Hyperlink;
57
import org.netbeans.api.io.OutputColor;
58
import org.netbeans.api.io.ShowOperation;
59
import org.netbeans.spi.io.support.Hyperlinks;
60
import org.netbeans.spi.io.InputOutputProvider;
61
import org.netbeans.spi.io.support.OutputColorType;
62
import org.netbeans.spi.io.support.OutputColors;
63
import org.openide.util.Lookup;
64
import org.openide.util.lookup.ServiceProvider;
65
import org.openide.util.lookup.ServiceProviders;
66
import org.openide.windows.IOColors.OutputType;
67
import org.openide.windows.IOPosition.Position;
68
69
/**
70
 * Abstract class for easy support of {@link InputOutputProvider}, the SPI for
71
 * the new I/O API.
72
 * <p>
73
 * This class is useful if you have a custom implementation of Output Window,
74
 * which uses SPI contained in this module ({@link IOProvider} and related
75
 * interfaces), and want to your implementation also accessible via the new I/O
76
 * API in module api.io.
77
 * </p>
78
 * <p>
79
 * To start supporting the new API:
80
 * </p>
81
 * <ol>
82
 * <li>Add dependency on module api.io (I/O API ans SPI,
83
 * org.netbeans.api.io)</li>
84
 * <li>Make your I/O provider extend {@link BridgingIOProvider} instead of
85
 * {@link IOProvider}</li>
86
 * <li>Add {@link ServiceProvider} annotation for {@link InputOutputProvider},
87
 *   {@link ServiceProviders} will be needed to allow multiple services:
88
 * <pre>
89
 *
90
 *  &#64;ServiceProviders({
91
 *    &#64;ServiceProvider(service=IOProvider.class, position=900),
92
 *    &#64;ServiceProvider(service=InputOutputProvider.class, position=900)
93
 *  })
94
 * public final class MyIOProvider extends BridgingIOProvider { ... }
95
 * </pre>
96
 * </li>
97
 * <li>If needed, override some of the method to improve performance.</li>
98
 * </ol>
99
 *
100
 * @author jhavlin
101
 */
102
public abstract class BridgingIOProvider extends IOProvider
103
        implements InputOutputProvider<InputOutput, OutputWriter, Position, FoldHandle> {
104
105
    private static final Logger LOG
106
            = Logger.getLogger(BridgingIOProvider.class.getName());
107
108
    private final Deque<FoldHandle> foldStack = new ArrayDeque<FoldHandle>();
109
110
    @Override
111
    public String getId() {
112
        return getName();
113
    }
114
115
    @Override
116
    public InputOutput getIO(String name, boolean newIO, Lookup lookup) {
117
        Action[] actions = lookup.lookup(Action[].class);
118
        IOContainer container = lookup.lookup(IOContainer.class);
119
        if (container == null && actions == null) {
120
            return getIO(name, newIO);
121
        } else if (newIO) {
122
            if (container != null && actions != null) {
123
                return getIO(name, actions, container);
124
            } else if (actions != null) {
125
                return getIO(name, actions);
126
            } else {
127
                return getIO(name, new Action[0], container);
128
            }
129
        } else {
130
            return getIO(name, newIO, actions == null ? new Action[0] : actions,
131
                    container);
132
        }
133
    }
134
135
    @Override
136
    public Reader getIn(InputOutput io) {
137
        return io.getIn();
138
    }
139
140
    @Override
141
    public OutputWriter getOut(InputOutput io) {
142
        return io.getOut();
143
    }
144
145
    @Override
146
    public OutputWriter getErr(InputOutput io) {
147
        return io.getErr();
148
    }
149
150
    @Override
151
    public void print(InputOutput io, OutputWriter writer, String text,
152
            Hyperlink link, OutputColor outputColor, boolean printLineEnd) {
153
154
        Color awtColor = outputColorToAwtColor(io, outputColor);
155
        OutputListener listener = hyperlinkToOutputListener(link);
156
        boolean listenerImportant = link != null && Hyperlinks.isImportant(link);
157
        try {
158
            if (printLineEnd && outputColor == null) {
159
                writer.println(text, listener, listenerImportant);
160
            } else if (printLineEnd && IOColorLines.isSupported(io)) {
161
                IOColorLines.println(io, text, listener, listenerImportant,
162
                        awtColor);
163
            } else if (IOColorPrint.isSupported(io)) {
164
                IOColorPrint.print(io, text, listener, listenerImportant,
165
                        awtColor);
166
                if (printLineEnd) {
167
                    writer.println();
168
                }
169
            } else if (printLineEnd) {
170
                writer.println(text);
171
            } else {
172
                writer.print(text);
173
            }
174
        } catch (IOException ex) {
175
            LOG.log(Level.FINE, "Cannot print color or hyperlink", ex); //NOI18N
176
        }
177
    }
178
179
    @Override
180
    public Lookup getIOLookup(InputOutput io) {
181
        if (io instanceof Lookup.Provider) {
182
            return ((Lookup.Provider) io).getLookup();
183
        } else {
184
            return Lookup.EMPTY;
185
        }
186
    }
187
188
    @Override
189
    public void resetIO(InputOutput io) {
190
        try {
191
            io.getOut().reset();
192
        } catch (IOException ex) {
193
            LOG.log(Level.FINE, "Cannot reset InputOutput.", ex);       //NOI18N
194
        }
195
    }
196
197
    @Override
198
    public void showIO(InputOutput io,
199
            Set<ShowOperation> operations) {
200
        if (operations.contains(ShowOperation.OPEN)
201
                && operations.contains(ShowOperation.MAKE_VISIBLE)
202
                && operations.size() == 2) {
203
            io.select();
204
        } else {
205
            IOSelect.select(io, showOperationsToIoSelect(operations));
206
        }
207
    }
208
209
    /**
210
     * Translate set of {@link ShowOperation}s to set of
211
     * {@link IOSelect.AdditionalOperation}s.
212
     */
213
    private Set<IOSelect.AdditionalOperation> showOperationsToIoSelect(
214
            Set<ShowOperation> operations) {
215
        Set<IOSelect.AdditionalOperation> res
216
                = EnumSet.noneOf(IOSelect.AdditionalOperation.class);
217
        for (ShowOperation so : operations) {
218
            switch (so) {
219
                case OPEN:
220
                    res.add(IOSelect.AdditionalOperation.OPEN);
221
                    break;
222
                case MAKE_VISIBLE:
223
                    res.add(IOSelect.AdditionalOperation.REQUEST_VISIBLE);
224
                    break;
225
                case ACTIVATE:
226
                    res.add(IOSelect.AdditionalOperation.REQUEST_ACTIVE);
227
                    break;
228
            }
229
        }
230
        return res;
231
    }
232
233
    @Override
234
    public void closeIO(InputOutput io) {
235
        io.closeInputOutput();
236
    }
237
238
    @Override
239
    public boolean isIOClosed(InputOutput io) {
240
        return io.isClosed();
241
    }
242
243
    @Override
244
    public Position getCurrentPosition(InputOutput io, OutputWriter writer) {
245
        if (IOPosition.isSupported(io)) {
246
            return IOPosition.currentPosition(io);
247
        } else {
248
            return null;
249
        }
250
    }
251
252
    @Override
253
    public void scrollTo(InputOutput io, OutputWriter writer, Position position) {
254
        position.scrollTo();
255
    }
256
257
    @Override
258
    public FoldHandle startFold(InputOutput io, OutputWriter writer,
259
            boolean expanded) {
260
261
        if (IOFolding.isSupported(io)) {
262
            synchronized (foldStack) {
263
                if (foldStack.isEmpty()) {
264
                    foldStack.addLast(IOFolding.startFold(io, expanded));
265
                } else {
266
                    foldStack.addLast(foldStack.getLast().startFold(expanded));
267
                }
268
                return foldStack.getLast();
269
            }
270
        } else {
271
            return null;
272
        }
273
    }
274
275
    @Override
276
    public void endFold(InputOutput io, OutputWriter writer, FoldHandle fold) {
277
        synchronized (foldStack) {
278
            while (!foldStack.isEmpty()) {
279
                if (foldStack.removeLast() == fold) {
280
                    break;
281
                }
282
            }
283
            fold.silentFinish();
284
        }
285
    }
286
287
    @Override
288
    public void setFoldExpanded(InputOutput io, OutputWriter writer,
289
            FoldHandle fold, boolean expanded) {
290
        fold.setExpanded(expanded);
291
    }
292
293
    @Override
294
    public String getIODescription(InputOutput io) {
295
        if (IOTab.isSupported(io)) {
296
            return IOTab.getToolTipText(io);
297
        } else {
298
            return null;
299
        }
300
    }
301
302
    @Override
303
    public void setIODescription(InputOutput io, String description) {
304
        if (IOTab.isSupported(io)) {
305
            IOTab.setToolTipText(io, description);
306
        }
307
    }
308
309
    /**
310
     * Convert a hyperlink to an output listener.
311
     *
312
     * @param link The hyperlink.
313
     * @return The wrapping output listener.
314
     */
315
    private static OutputListener hyperlinkToOutputListener(
316
            final Hyperlink link) {
317
318
        if (link == null) {
319
            return null;
320
        }
321
        switch (Hyperlinks.getType(link)) {
322
            case FROM_URI:
323
                return new OutputListenerAdapter() {
324
                    @Override
325
                    public void outputLineAction(OutputEvent ev) {
326
                        Hyperlinks.getRunnable(link).run();
327
                    }
328
                };
329
            case FROM_RUNNABLE:
330
                return new OutputListenerAdapter() {
331
                    @Override
332
                    public void outputLineAction(OutputEvent ev) {
333
                        IntentManager.execute(
334
                                Intent.forUri(Hyperlinks.getURI(link)));
335
                    }
336
                };
337
            default:
338
                return null;
339
        }
340
    }
341
342
    /**
343
     * Convert AWT-independent {@link OutputColor} to {@link java.awt.Color}.
344
     *
345
     * @return Appropriate color, or null if default color should be used.
346
     */
347
    private static Color outputColorToAwtColor(InputOutput io,
348
            OutputColor color) {
349
350
        if (color == null) {
351
            return null;
352
        }
353
        OutputColorType type = OutputColors.getType(color);
354
        if (type == OutputColorType.RGB) {
355
            return new Color(OutputColors.getRGB(color));
356
        } else if (IOColors.isSupported(io)) {
357
            switch (type) {
358
                case DEBUG:
359
                    return IOColors.getColor(io, OutputType.LOG_DEBUG);
360
                case FAILURE:
361
                    return IOColors.getColor(io, OutputType.LOG_FAILURE);
362
                case WARNING:
363
                    return IOColors.getColor(io, OutputType.LOG_WARNING);
364
                case SUCCESS:
365
                    return IOColors.getColor(io, OutputType.LOG_SUCCESS);
366
                default:
367
                    return null;
368
            }
369
        } else {
370
            return null;
371
        }
372
    }
373
374
    private static class OutputListenerAdapter implements OutputListener {
375
376
        @Override
377
        public void outputLineSelected(OutputEvent ev) {
378
        }
379
380
        @Override
381
        public void outputLineAction(OutputEvent ev) {
382
        }
383
384
        @Override
385
        public void outputLineCleared(OutputEvent ev) {
386
        }
387
    }
388
}
(-)a/utilities/nbproject/project.xml (+16 lines)
Lines 50-55 Link Here
50
            <code-name-base>org.netbeans.modules.utilities</code-name-base>
50
            <code-name-base>org.netbeans.modules.utilities</code-name-base>
51
            <module-dependencies>
51
            <module-dependencies>
52
                <dependency>
52
                <dependency>
53
                    <code-name-base>org.netbeans.api.intent</code-name-base>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
56
                    <run-dependency>
57
                        <specification-version>1.0</specification-version>
58
                    </run-dependency>
59
                </dependency>
60
                <dependency>
61
                    <code-name-base>org.netbeans.api.io</code-name-base>
62
                    <build-prerequisite/>
63
                    <compile-dependency/>
64
                    <run-dependency>
65
                        <specification-version>1.0</specification-version>
66
                    </run-dependency>
67
                </dependency>
68
                <dependency>
53
                    <code-name-base>org.netbeans.modules.queries</code-name-base>
69
                    <code-name-base>org.netbeans.modules.queries</code-name-base>
54
                    <build-prerequisite/>
70
                    <build-prerequisite/>
55
                    <compile-dependency/>
71
                    <compile-dependency/>
(-)a/utilities/src/org/netbeans/modules/openfile/OpenFileUriHandler.java (+103 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.openfile;
43
44
import java.net.MalformedURLException;
45
import java.net.URI;
46
import java.util.regex.Matcher;
47
import java.util.regex.Pattern;
48
import org.netbeans.spi.intent.uri.OpenUriHandler;
49
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.URLMapper;
51
import org.openide.util.lookup.ServiceProvider;
52
53
/**
54
 * Handler for file URIs clicked in the Output Windows.
55
 *
56
 * @author jhavlin
57
 */
58
@ServiceProvider(service = OpenUriHandler.class, position = 100)
59
public class OpenFileUriHandler implements OpenUriHandler {
60
61
    private static final Pattern LINE_NUM_PAT
62
            = Pattern.compile("line=(\\d+)");                           //NOI18N
63
64
    @Override
65
    public boolean open(URI uri) {
66
        if ("file".equals(uri.getScheme())) {                           //NOI18N
67
            int line = getLineNumber(uri);
68
            try {
69
                FileObject fo = URLMapper.findFileObject(uri.toURL());
70
                if (fo != null && fo.isData()) {
71
                    OpenFile.open(fo, line);
72
                    return true;
73
                } else {
74
                    return false;
75
                }
76
            } catch (MalformedURLException ex) {
77
                return false;
78
            }
79
        } else {
80
            return false;
81
        }
82
    }
83
84
    static int getLineNumber(URI uri) {
85
        String str = uri.getQuery();
86
        if (str == null) {
87
            return -1;
88
        }
89
        String[] params = str.split("&");                               //NOI18N
90
        for (String param : params) {
91
            Matcher m = LINE_NUM_PAT.matcher(param);
92
            if (m.matches()) {
93
                String lineStr = m.group(1);
94
                try {
95
                    return Integer.parseInt(lineStr);
96
                } catch (NumberFormatException ex) {
97
                    // keep trying
98
                }
99
            }
100
        }
101
        return -1;
102
    }
103
}
(-)a/utilities/test/unit/src/org/netbeans/modules/openfile/OpenFileUriHandlerTest.java (+65 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.openfile;
43
44
import java.net.URI;
45
import java.net.URISyntaxException;
46
import static junit.framework.Assert.assertEquals;
47
import org.junit.Test;
48
49
import static org.netbeans.modules.openfile.OpenFileUriHandler.getLineNumber;
50
51
/**
52
 *
53
 * @author jhavlin
54
 */
55
public class OpenFileUriHandlerTest {
56
57
    @Test
58
    public void testGetLineNumber() throws URISyntaxException {
59
        assertEquals(10, getLineNumber(new URI("file://x?line=10")));
60
        assertEquals(20, getLineNumber(new URI("file://x?a=b&line=20&r=1")));
61
        assertEquals(-1, getLineNumber(new URI("file://x?Xline=20")));
62
        assertEquals(-1, getLineNumber(new URI("file://x?line=a")));
63
        assertEquals(-1, getLineNumber(new URI("file://x")));
64
    }
65
}

Return to bug 247404