1. Trang chủ
  2. » Công Nghệ Thông Tin

NetBeans the Definitive User Guide phần 3 pot

64 402 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 64
Dung lượng 8,72 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

For each node, simply right-click and select Addfrom the context menu, and a list of valid tags should appear.Configuring the Ant Module... If a source object uses Ant Script Compilation

Trang 1

Figure 6.8 Ant Help page

Trang 2

You can add other elements to your build script from the Explorer For each node, simply right-click and select Addfrom the context menu, and a list of valid tags should appear.

Configuring the Ant Module

Trang 3

The Ant module is configurable via property sheets in the Options window, with global settings accessible atBuilding->Ant Settings Table 6.7 explains the properties for the Ant settings node.

The module also creates two compilation services and an execution service—Ant Script Compilation, Indirect Ant

Compilation, and Ant Script Execution All compilation services implement Build, Clean, and Compile actions The

Ant compilation services have properties that can be configured to define the actions by executing targets in an Antbuild script For example, in the Options window see Building->Compiler Types->Ant Script Compilation Notice the

Build Target(s) property Its default setting is clean, all The targets are executed from left to right If a source object

uses Ant Script Compilation, then selecting the Build action from the object's context menu results in executing the

clean target, followed by the all target in the Ant build script See Table 6.8.

The Indirect Ant Compilation compiler service is useful when you wish to call an Ant script while compiling anotherfile For example, it could be used to call the compile target in an Ant script when compiling a Java file The IndirectAnt Compilation has the very same properties as the Ant Compiler with the addition of a property to specify the Antscript that defines the necessary targets to invoke

The Ant Executor found in the Options window at Debugging and Executing->Execution Types->Ant Script Executiondefines targets to run when an Ant script is executed The default target of the Ant script is executed if no target is de-fined here

Executing and Compiling With Ant Scripts

By default, double-clicking an Ant build script should run the default target of that script To run a specific target, youcan right-click on the target's node and select Execute from the context menu The output from the Ant script shouldappear in the Output tab There is usually no need to define compilation for Ant script as you can simply execute thecompile target declared in the script However, if you set the Compiler property to the Ant compiler service then youcould select Build or Compile from the Build menu and the respective targets will be executed

Why Use Ant?

NetBeans already has compilation and execution services for all the object types that are supported for development.Why not just use the services that are provided? The short answer is, if you're happy without Ant, then don't use Ant Ifyou only build and execute single classes or small projects, then you probably don't need the flexibility that a build toollike Ant offers But if you're involved in a large project, especially a project that has needs complex and unique actions

to be performed many times during the course of development, then look to Ant for a powerful, easy to use, easy toconfigure tool

For example, this book was developed by several authors working remotely with Linux, Solaris and Windows ers with shared access to a CVS repository for storing the drafts of chapters, source examples, and related material Thetext was written in DocBook XML, which the authors and editors needed to validate and transform into HTML or PDFfrequently We created an Ant build script to perform the tasks As the project progressed and the variety of tasks ex-panded, the build script grew to accomodate the needs A simple CVS update automatically brought the enhanced buildscript into each author's environment Without CVS and Ant, there would have been many more emails and phone callsasking how to do common tasks With these tools, we have been able to keep our focus on the project goals

Trang 4

comput-Chapter 7 Customizing the environment

Table of Contents

The Setup Wizard 109

General NetBeans Settings 109

ModuleInstallation 112

UpdateCenter 112

The ToolsOptions Dialog 113

ConfiguringToolbars 114

ConfiguringMenus 116

ConfiguringEditors 117

Object Type Associations 117

EditorSettings 118

Command line options 126

Modules 128

InstallingModules 128

Enabling and Disabling Modules 131

The NetBeans IDE offers a highly customizeable environment through wizards and serializable options In this chapter you will learn how to customize your IDE environment We will look at the following areas of customization:

• The Setup Wizard

• Toolbars

• Menus

• Editors

• Modules

The Setup Wizard

The Setup Wizards allows you to quickly configure your IDE with some general settings required for everyday use It

is especially useful after an initial install of the IDE and is usually launched the first time you run NetBeans To use the Setup Wizard any time after the initial launch select Tools->Setup Wizard from the menu bar

General NetBeans Settings

Figure 7.1 The first pane of the Setup Wizard

Trang 5

The first pane of the Setup Wizard, shown in Figure 7.1, allows you to configure a proxy server, a window mode, and

an HTML browser

The proxy server settings will be used for all the network and Internet needs of the IDE such as acquiring informationfor AutoUpdate from a remote Update Center Your network administrator should be able to supply you with the serverand port information of your proxy server You will generally only need these settings if you are using the IDE behind

a firewall

The window mode setting is used to determine the type of windowing interface NetBeans should use There are ally two types of interfaces: SDI, or Single Document Interface , and MDI, or Multiple Document Interface Ignoringthe word "Document", the main difference between the two interfaces is that in SDI mode, the IDE has no main win-dow, and each workspace has its own window, whereas in MDI mode, all the windows are managed by a single win-dow known as the Main Frame Your choice of a window mode depends on your taste They both have their advan-tages In SDI mode the proliferation of windows for every document and workspace can be quite messy and annoying.The one benifit is that screen size per window can be maximized In MDI mode there is one window and everythingelse is a child of that window This makes window management very easy and agreeable with the programmer who al-ready has twelve other applications opened The one caveat is that since MDI child windows share space with a parentwindow, they cannot be maximized to take advantage of the entire screen area This can be especially annoying with aneditor window displaying Java source It's often convenient to minimize scrolling by showing as much text as possible.Microsoft Windows users may favor MDI mode because many Windows applications are MDI, including the DevStu-dio IDE

gener-The differences of the two modes do not necessarily form a fork in the road, and neither of the two can be considered

"the road less traveled" This is because the IDE lets you have the best of both worlds In NetBeans, windows can be

Trang 6

docked into one another Windows - also referred to as frames - can also be made into separate windows, regardless ofthe mode you chose This is an advanced level of customization for the NetBeans IDE, but remains simple to accom-plish For example, if you chose MDI mode from the Setup Wizard, but would like your editor to be displayed as a sep-arate window so that you could take advantage of more screen real estate, simply open a Java file; once the editor isopened select Window->Frame Resides ->As Separate Window from the menu bar You should now see the editor in aseparate window Conversely, if you preferred to dock the editor window, back Window->Frame Resides->As SeparateWindow into the main frame, you would select Window->Frame Resides->In IDE Desktop You can also chose tocombine multiple windows via docking For example, to add the filesystem explorer to the left side of an editor win-dow set the focus to the filesystem explorer, select Window+->Dock View Into->Source Editor-> Left Figure 7.2shows an editor window with a filesystem explorer docked on the left.

Figure 7.2 An editor window with a filesystem explorer docked on the left

The Web Browser selection is used for all the IDE's browsing needs such as Javadoc searching and JSP previewing.NetBeans comes with the ICE Browser embedded This will usually be sufficient for all your needs and provides thetightest integration with the IDE, however it lacks the feature rich capabilities of some commercial browsers and in thatcase you may wish to select an external browser for default HTML browsing If you choose an external browser, youwill have to configure it later by selecting Tools->Options and then expand the web browsers node

Trang 7

Module Installation

Figure 7.3 The second pane of the Setup Wizard

The second pane of the Setup Wizard (see Figure 7.3) allows you to configure which modules will be used by the IDE

at runtime The modules are shown in a table along with their enabled status (true\false), version number, and tion Upon startup, the IDE will attempt to load each of the enabled modules This process becomes slower with thenumber and complexity of the installed modules Memory usage is also a consideration since all modules are issuedtheir own classloader and run simultaneously in memory For these reasons it may not be desirable to enable every pos-sible module To disable a module, simply select "false" under the enabled column of that module's entry

descrip-Update Center

Figure 7.4 The third pane of the Setup Wizard

Trang 8

The third pane of the Setup Wizard, shown in Figure 7.4, allows you to configure the Update Center connection for theIDE's Auto Update tool The Auto Update tool connects to an Update Center to acquire modules and core componentsfor installation You can configure Auto Update to be automatically invoked on a recurring schedule, or you can manu-ally invoke it any time by selecting Tools->Update Center from the menu bar.

The ToolsOptions Dialog

Most NetBeans global or project level settings can be managed in the dialog invoked when you pull down Tools->tions dialog The components in this dialog represent the vast array of configurable settings in the IDE Thecomponents are organized in the left pane of this dialog in a tree of nodes Each node represents a specific configura-tion component while the folders represent categories by which the components are grouped by

Op-When you select a component its properties will appear in the left pane in a table that is known as the property sheet.Property sheets consist of two cells A property name cell and a property value cell Typically the property value cell is

to the right of the property name cell You can change a component's settings by changing the data in its property valuecell

Some property value cells allow you to enter plain text Others, such as true/false properties will have a combo box ofvalid entries Some value cells may require data that is not easily entered as text and will prompt you to use a specialproperty editor When the option to use a property editor is available, an ellipsis ( ) will appear in the rightmost end ofthe cell when you click on it Clicking on this ellipsis will launch the property editor for that cell Cell's that requireColor values frequently provide property editors that allow you to choose colors from a pallete

Some settings you change you may wish to change globally Other settings changes you may wish to apply only to theproject you have open Fortunately, NetBeans provides a means to specify the scope of a Tools Options setting

Trang 9

In the figure below, we have circled a very small and important button!

This button which bears two left angle brackets, or "arrows" (<<) as its emblem is called the Show Levels button Ifyou click it, a new panel "unfolds" into the options listing and you are offered three choices for the level of settings per-sistence which can be applied on a per-setting basis, as shown in the figure below

The three choices for settings persistence are as follows:

Default means "keep the default settings shipped with NetBeans and don't allow the user to apply any changes." Of

course, if you change your mind, you can always remove this persistence and allow yourself to change the givensetting It's just a safety net

Project means settings changes are applied to the current project only Any other project will retain the settings it

was left with until they are changed while that project is open

User means all changes apply to all projects for that user.

You can click the Show Levels button again to fold back this settings persistence panel so that it's out of your way

In the NetBeans IDE, each toolbar button is tied to an Action You may think of an action as a task For example Cut,Paste, and Copy are all actions Most of the IDE's actions are pre-packaged, while others are provided by third partymodules To begin configuring toolbars select Tools->Options and then go to IDE Configuration->Look andFeel->Toolbars Figure 7.5 shows the toolbar options

Trang 10

Figure 7.5 Toolbar options

These options allow you to edit and delete existing toolbars, or create your own You can add new buttons to an ing toolbar by copying and pasting actions For example, to add a new button to the Build toolbar for compiling youwould perform the following steps:

exist-1 Expand the Build toolbarnode

2 Expand Actions->Build, right click on the Compile node, and select Copy from the context menu

3 Right-click on the Build toolbar node and select Paste->Copy from the context menu

You can also rearrange the ordering of toolbar buttons To change the button order on a particular toolbar, right-click

on its node and select "Change Order" from the context menu You will be presented with the dialog box shown in ure 7.6 Use the "Move Up" and "Move Down" buttons to reorder each toolbar button's position The toolbar button atthe top of the list will appear first from the left on the toolbar

Fig-Figure 7.6 Changing the toolbar button order

Trang 11

Configuring Menus

The IDE also allows you to edit and create menus in the same way you edit and create toolbars To begin editing andcreating menus open the options dialog box (Tools-> Options) and go to IDE Configuration->Look and Feel->MenuBar You should see a list of nodes similar to the ones seen in Figure 7.7 that represent your current menu bar By ex-panding each menu, you will see a list of menu items An item can be either an Action or a separator Menus can alsocontain submenus

To add a submenu to a menu, right-click on the menu node and select New->Menu New->Menu from the contextmenu The new menu is immediately viewable under the menu you created it To add a menu item would require stepssimilar to the aforementioned toolbar button steps After copying an action, right-click on the destination menu nodeand select Paste->Copy from the context menu The reordering of menu items within menus is done exactly the sameway toolbar buttons are reordered (right-click a menu node and select "Change Order " from the context menu) Youcan also delete and rename menu items and menus in much the same way you would any node in the IDE There is also

an easy way for mapping shortcuts to menus When supplying a name for the menu, type an ampersand (&) in front ofthe letter you wish to map For example, &File will be mapped to the shortcut Alt+F

Figure 7.7 Creating and editing menus

Trang 12

Configuring Editors

Of all the components in the IDE, the editor will most likely be the one involved in your day-to-day programming use.Therefore it makes sense that is one of the most configurable of all the components in the IDE Although it may seemthat you are always working with one editor, there are in fact different editors for different types of files A file type isidentified by its extension The mapping of editor to file type is a one-to-many relationship Although the content theyhandle may be different, editors share a common set of configurable attributes Some editors may choose to disablesome of these attributes because of the irrelevance to the particular implementation - for example the "Auto PopupCode Completion" feature is disabled in the Plain editor Editors for some object types may have multiple views; insuch cases special menu items are provided for switching between views For example, there is a specialized editor formodifying Properties files That editor has two views: one provides a table for editing properties and values, and theother provides a plain text view Selecting Open from the context menu for a Properties file results in the default view,which is the table view To access the alternate plain text view, select Edit from the context menu

Object Type Associations

As previously mentioned, editors are mapped to file and MIME types In the IDE, a file is basically a type of object.The IDE uses Object Types to identify files based on their extensions Object Types do not always map to files Someare used internally as objects by modules You can map several file extensions to a single Object Type, thereby associ-

Trang 13

ating the files with those extensions to a particular file type in the IDE For example, adding java as an extension to theJava Source Object Type would make all files ending in.java recognized as Java file types in the IDE The realpower of Object Types comes in when you associate Actions with an Object Type Actions are objects in the IDE thatare mapped to menu items and used to carry out a specific task on a target object "Compile" is one example of an IDEAction The Compile Action can be used on Java Object types to invoke a configured Compiler Service with a Java file

as its target Nothing stops you from adding the Compile Action to an Image Object Type If for example you had aspecial Compiler Service that converted GIF to JPEG it would be useful to be able to right click on a.giffile, selectCompile from the menu and have your file converted Configuring Object Types makes all this possible Usually Ob-ject Types come with preconfigured Actions and extensions You would only need to change these to add custom be-havior

Table 7.1 shows some common Object Types and their descriptions

Usually the only property of an Object Type you would configure would be the extensions This is useful if you wouldlike to add a new extension so that it is recognized by the IDE For example, if you want the IDE to recognized fileswith the jad extensions as Java Source files simply go to the Java Source Objects node, and in the property sheet click

on the pane to edit the "Extensions and Mime Types" Click on the ellipsis that appears and you should see a dialog boxlike the one shown in Figure 7.8 Enter jad (NB You enter extensions without the dot prefix) in the input box and thenclick add Close the dialog box Any files in your mounted filesystems that has a jad extension should now appear withthe icon denoted for Java source files When you double click the file, you should see the source code in the Java edi-tor

Editor Settings

At the heart of Editor configuration is the Editor Settings The Editor Settings node can be found in the Options Dialogunder Editing->Editor Settings When you expand this node you will see all the various editors in the IDE Usually aneditor's name will give you a good idea of the types of files it supports Most of the editors have the same configurationparameters, however you will be able to configure them separately and maintain your changes

Global Key Bindings (Shortcut Keys)

Key bindings are the mapping of keys to predefined IDE actions For example, the mapping of the Control key and the'C' key combination is to the Copy action Many combinations can be mapped to a single action Each mapping isknown as a binding, since the sequence of key strokes is bound to the particular action Global Key Bindings are inher-ited by all the editors Each editor also has its own specific bindings that can override global key bindings or providetheir own mapping Global key bindings are configured by selecting the Editor Settings node and clicking on the KeyBindings cell in the property sheet, and then clicking on the ellipsis ( ) that appears You should see a dialog box simi-lar to the one shown in Figure 7.8 The predefined actions are shown in the List box and can be sorted by Name or Ac-tion (the internal action name) To add a new binding, first select an action from the list and then click on the Add button In the dialog box that appears, enter the key sequence that will cause the IDE to invoke the action For metakeys such as Control and Alt, you will need to hold on the key while typing So for binding the beep action to the Con-trol key and 'B' key combination, you would hold on the Control key while typing 'B' in this dialog box After clicking

OK to close the dialog box the new key binding should appear in the Keybindings list box

Figure 7.8 Global key bindings

Trang 14

You can modify an editor's local key bindings by selecting that editor from the list of nodes under Editor Settings, andediting its Key Binding property This behaves exactly like the global options, except these local options override anyexisting global key bindings for the specific editor the binding is associated with.

Fonts and Colors

Each editor has its own properties for fonts and colors Color is divided into foreground and background and is ually configured for each syntax element of an editor For example in the Java Editor, "Java Keyword" is a syntax ele-ment and it has its own foreground and background color properties So for a keyword such as "if" the foreground andbackground color properties selected would be shown whenever it is typed There is a default syntax element whoseproperties the other syntax elements can inherit or override This allows you to set a consistent background color for in-stance, and only chose different foreground colors for various elements Fonts are also chosen independently for eachsyntax element and may be inherited from the default To modify fonts or colors for a particular editor, select that edi-tor from the nodes under Editor Settings, click the Colors and Fonts cell in the property sheet and then click on the el-

Trang 15

individ-lipsis that appears You should see a dialog box that looks like Figure 7.9 Syntax elements are listed in the list box tothe right Click on an element to modify its font and color properties The Default element should be at the top of thelist To change the background from the white default to a light yellow (the color of a sticky pad for instance), selectthe default syntax element and click on the button in the "Background Color" box and then click on the ellipsis that ap-pears You should see a dialog box like the one shown in Figure 7.10 This is the color picker dialog box Each tabshows a pallete from which you can chose colors from Use the first pallette to select the light shade of yellow As analternative, instead of clicking on the ellipsis and using the color picker, you could type in the RGB color code in theedit box The RGB color code for this shade of yellow is 255,255,204.

Figure 7.9 The fonts and colors editor

Trang 16

Figure 7.10 The color picker

Trang 17

Your default background color should now be set; however, some of the syntax elements may not choose to inherit thisproperty You will need to go through the elements and click the Inherit check box in the Background Color Thiscauses the Background Color chosen for the default syntax element to be applied to the current syntax element.

Choosing a font is just as easy as choosing colors To modify the font for single line comments in the Java Editor,changing it from plain italics to bold italics, click on the button in the Font box and then click on the ellipsis that ap-pears You should see a dialog box similar to the one shown in Figure 7.11 In the first list you select the Font name.The second list allows you to configure the syle of the font For this example you would select Bold Italic from that list.The third list allows you to select the font size Once you're done configuring the font settings, click OK to close the di-alog box The settings in this example should only affect single line comments (comments that begin with "//") Nowevery time you type a single line comment it will appear as a font with a bold-italic style

Trang 18

Figure 7.11 The font picker

Macros

In chapter three you learned about macros in templates which were used for string expansion In this section you willlearn about a different macro used to execute a task on a particular editor You can refer to these as editor macros Edi-tor macros can be recorded, saved, and executed An editor macro can only be executed in the editor that it wasrecorded and saved in Finally an editor macro is mapped to a shortcut key so that it can be easily invoked through con-venient keystrokes

Recording and Saving Macros

Let's say you were using a logging class that would emit messages to a log file when the log method was called withthe classname and log message as parameters The static method signature is:

Logger.logMessage(this.getClass(),"message");

Instead of having to type that every time you wish to log a message, an editor macro can be created to type the entire

Trang 19

method signature and then position the caret between the quotation marks so that a message can be typed.

To begin recording your macro open a Java source file This macro will be available for all source files opened with theJava editor Start the macro recorder by typing Ctrl+J and then S (Hold Ctrl key, type J, release Crtl Key, type S) Youshould see the message "Recording" appear in the editor's status bar (the message goes away once you begin typing).Every keystroke beyond this point is recorded as part of the macro Type the following code snippet:

Logger.logMessage(this.getClass(),"");

When finished typing use the back arrow key to move the caret between the two quotation marks Type Ctrl+J and then

E to end the macro recorder A dialog box like the one shown in Figure 7.12 should appear Type in a canonical namefor the macro in the Name edit box and then click the Add button Another dialog should pop up prompting you toenter a key binding for this macro Type in a key sequence that you find convenient, for example Alt+Shift+0 (do nottype in the plus signs and remember to keep holding meta keys such as Alt while you type) Click Ok and your newmacro should be saved

Figure 7.12 Recording a macro

Note

When recording macros the IDE ignores mouse movements Therefore avoid using the mouse while recording.You can use shortcut keys, however This allows you to build complex actions, made up of several shortcutkey sequences, and then assign the complex action to a single shortcut key sequence

Trang 20

Editing and Executing Macros

After a macro is saved, it becomes one of the properties of the editor in which it was recorded The macro we wrote inthe previous section will be available to any source file opened with the Java editor To modify the macro we can edit itthrough the macro property found in the property sheet for the particular editor Click on the Macros cell to edit theproperty and click on the ellipsis You should see a dialog box similar to that shown in Figure 7.13 Select the macroyou wish to edit from the table and click on the Edit button to change the name or macro expansion

Figure 7.13 Editing macros

Trang 21

To execute the macro, type the keyboard shortcut anywhere in the editor For this example we used Ctrl+Alt+0, so ing that will execute the macro and we should see the code with our caret positioned between the quotation marks.

typ-Indentation Engines

The IDE uses the concept of an indentation engine to format code in the Source Editor Setting the width of tab spaces,adding a leading asterisk to comment lines, and placing spaces before parentheses are some examples of its usage Youcan create two types of engines, a Java Indentation Engine or a Simple Indentation Engine The Java Indentation En-gine has more options and is specific to formatting Java source code Simple Indentation only allows you to configurethe number of spaces for tab Table 7.2 shows the properties of the Java Indentation Engine You can associate an en-gine with any of the editors by selecting the editor from the list of nodes under Editor Settings, click on the IndentationEngine cell in the property editor and then click on the ellipsis You should see a dialog similar to the one shown inFigure 7.14 allowing you to select an Indentation Engine and configure it Many editors can use the same engine.Changing the engine's settings will affect all the editors that reference it

Figure 7.14 Indentation Engine

Command line options

Trang 22

The IDE can be run from the command line with arguments At the command line type runide.exe -help

(runide.shon UNIX systems) and you will see a dialog box like the one shown in Figure 7.15 with the commandline options These options are shown and described in Table 7.3

Figure 7.15 IDE command line options

Instead of typing the arguments at the command line each time you run the IDE, you can save your settings to a file that

is read into the IDE as command line parameters Your arguments need to be in theide.cfgfile found in thebinrectory of your installation For example, if you wanted to specifyxerces.jarahead of the IDE's classpath and setthe maximum heap size to 256MB youride.cfgfile will consist of a single line that looked like:

di cp:pc:\xerces\lib\xerces.jar -J-Xmx256m

Trang 23

Modules are what make the NetBeans IDE extensible The IDE consists of a thin layer known as the core on top ofwhich are modules that provide most of the features you use In the second part of this book you will learn how to cre-ate modules and build the IDE sources with minimal modules This section gives you an introduction to modules andshows you how to install, uninstall and configure them in the IDE

Installing Modules

The IDE allows you to install modules from NetBeans Update Centers (available through the web) or manually loaded NBM files Both of these methods are accomplished using the Auto Update Tool To use Auto Update selectTools-> UpdateCenter You will see a dialog box like the one shown in Figure 7.16

down-Figure 7.16 The Auto Update Center - Pane 1

Trang 24

If you are installing modules from the web, select the Update Centers you wish to connect to from the list provided andclick next If you are behind a firewall you will need to click on the Proxy Configuration button and supply the proxyserver and port.

Installing From The Web

If you chose to install from the web and clicked the next button you should see the next pane of the wizard as shown inFigure 7.17 If you do not see this pane there may be something wrong with your Internet connection, or the UpdateCenters you chose were invalid or experiencing network problems Another cause for problems could be your proxysettings Check your settings, or consult with a systems administrator if you're using your company network, and try toconnect again

Figure 7.17 Installing modules from the web

The modules are listed under each Update Center you selected in the first pane When you select a module the dialogdisplays the module's version info compared to what you currently have installed The text box gives a description ofthe module and what it does A web page giving more information about the module can be viewed by clicking on theMore button To select a module to be installed, select the module's node in left list box then click on the arrow point-

Trang 25

ing to the right, or to the "Include To Install" list box You can select multiple modules by holding the Ctrl key whileselecting and use the same arrow to chose those modules for installation The other arrow button pointing to the rightallows you to select all the modules for installation Click the next button and you might see a license agreement If youchose many modules you might have to click "Accept" on each of the license agreement dialogs that pop up After ac-cepting the license agreement the IDE will attempt to download the modules and check for any digital signatures.When the downloading is complete, you will be able to click Next and should see a dialog box like the one in Figure7.18.

Figure 7.18 Completing Installation of modules for the web

This is the final pane You should see a list of modules that were downloaded If the module is digitally signed and has

a valid certificate it will appear with the word Trusted under it You can select a module and click the View Certificatebutton to view its digital signature certificate The checkbox to the left of a module indicates whether you want thismodule installed when you click the Finish button Checking it means you would like it installed The IDE must berestarted for a module to be utilized You can choose to have the IDE restart immediately (don't worry, your files will

be automatically saved first), or install immediately and restart later at your own convenience Once you click the ish button, the module will be installed

Trang 26

Fin-Installing Manually Downloaded NBM Files

If you chose to install manually then you should see a dialog box like the one shown in Figure 7.19 after clicking Next

on the first pane This pane allows you to add.nbmfiles You can use the Browse button to find.nbmfiles on yourlocal system or on the network Once you click the Next button, the wizard will be the same as the previously explainedweb module installation

Figure 7.19 Installing modules manually

Enabling and Disabling Modules

By default, when a module is installed, it is enabled To improve performance and startup time you might want to runwith a minimum set of modules In this case you need to disable the modules you won't be using To disable a module,select Tools->Options under IDE Configurations->System->Modules find the module category for your module Usu-ally third party modules will create their own module category You can chose to disable an entire module by selectingthe category and chosing false for the enabled property in the property sheet Under the category's node are the specificmodule features These can be disabled as well by chosing false in the enabled property of the feature By disabling the

Trang 27

category, all module features are instantly removed from the IDE until the category is enabled by chosing true for theenabled property.

Trang 28

Chapter 8 Using Source Control (CVS)

Table of Contents

What is CVS? 133The How, When and Why of CVS in NetBeans 135

When to use CVS 135Where to get a client 135How does NetBeans interact with CVS? 135Using Generic VCS 136Using Command-Line CVS Support versus Built-in CVS 136What parts of my project does CVS within NetBeans save? 137Does NetBeans automatically add new files and packages I create to the repository? 137How do I manipulate my NetBeans project directly with CVS outside of NetBeans? 137Mounting CVS sources 138Exploring Versioned Sources 138Performing common CVS operations within the IDE 139

Checkout/Get 140Checkin/Commit 141Add and Import 141Log 142Diff 143Update 144UnexpectedResults 144

Spurious [Local] Designation 144When Adding directories 145When Adding binary files 145Uncommon CVS operations within the IDE 145

Branching, Merging and Tagging 146NetBeans CVS and the Secure Shell (SSH) 146Mounting and Customizing a Generic Versioning System 146One Final Tip 149

What is CVS?

CVS is a TLA (three-letter acronym) for Concurrent Versions System It's a system used by multiple developers toshare a centralized source code repository from which they can all check out files, make changes to those files, and thencheck the modified files back in Other developers may also concurrently work on the same files, with merges of over-lapping changes being handled by CVS at check-in time

Perhaps you have already dealt on the job with revision control Revision control is the software development process

of checking code incrementally into some sort of automated repository Doing this allows programmers to retrieve notonly the latest revision but also previous revisions when they wish to revert, that is, drop back to a previous revision,perhaps to recover some lost code Also, automated revisioning systems allow development projects to branch code sothat a current or past release can be maintained and have bugs fixed while the main line of the code continues toprogress towards the next release This avoids having the less-tested technology under development in the main line (or

in another branch) injected into the stable release

Terminological note

Trang 29

The terms Version control and versioning are used interchangeably with the term revision control.

History of Revision Control

The basic model of revision control in which a single developer may work at any one given time was long ago givenformal definition by computer scientists

[http://www.zdnet.com/devhead/stories/articles/0,4413,2431468,00.html], Marc Rochkind developed the Source CodeControl System, or SCCS at Bell Labs back in 1972 The Revision Control System, or RCS, came later in the early1980s thanks to Walter F Tichy RCS is a part of the BSD UNIX distributions and is also distributed by the Free Soft-ware Foundation

Conceptually (and often in implementation) CVS is a shell around and extension of RCS RCS deals with storing sions of single files under the effective control of a single developer Whereas RCS deals with files, CVS deals withsource modules (not to be confused with NetBeans modules discussed elsewhere in this book) Source modules are col-lections of files In CVS, a module consists of all the source files in a given directory and its sub-directories Modulescan also be aliases for a number of directory hierarchies to be checked out at one time

revi-Under CVS, source modules consisting of any depth of directories and files can be checked out by any number of velopers concurrently Whenever the modules are checked back in, CVS helps the developers, usually by managing au-tomatically the merge of variants caused by concurrent revision; and less frequently, by pointing out differences whichcannot be reconciled automatically These differences must be reconciled manually by the developer who checks in thelatest revision, which caused the conflicts

de-The relationship between RCS and CVS is summarized in Figure 8.1

Figure 8.1 Summary of how CVS extends RCS

scope of management individual files resident in a single

di-rectory

contents of a CVS root directory andits entire subdirectory hierarchyrepository location local subdirectory named RCS centralized shared repository with

TCP/IP server support

If you want to study CVS itself, which is a good idea if you have read this far without ever having used CVS, you may

read The CVS Info Manual [http://www.cvshome.org/docs/manual/].

NetBeans supports CVS in two ways:

1 Executing an external CVS application against an existing archive via host operating system commands

2 Performing CVS operations on an existing archive via NetBeans' own Java-coded module for CVS support.The name CVS is applied to more than one implementation of the CVS idea, notably the classic CVS[http://www.cvshome.org/] associated with the Free Software Foundation GNU Project [http://www.gnu.org] Thereare also other version control applications in the world of software development In addition to supporting CVS, Net-Beans allows you to use pretty much any other versioning system in place of either command-line or built-in CVS

Trang 30

CVS or VCS?

NetBeans allows you to use "real CVS" (either NetBeans' own built-in implementation or a command line sion of CVS), or any "generic" version control system (VCS) You configure the two types of systems sepa-rately But once configured, versioning operations except mounting a filesystem fall usually under the menuselection CVS and do not distinguish between CVS/VCS In other words, in the context of everyday opera-tions on a mounted versioned filesystem, it's all just called "CVS" However, some VCS profiles, for instance,the ClearCase template, create a menu selection which identifies the specific VCS system

ver-NetBeans allows you to use any reasonable generic version control system, with specific support for the most popularsystems, as we will see below But since

1 CVS specifically is so well supported in NetBeans, and

2 If you are in a position to use a different versioning system, you probably know a good deal about such matters ready,

al-our exposition here of versioning under NetBeans will mostly be expressed in terms of CVS, while still informing you

of that which is necessary for successful use of any generic version control system

The How, When and Why of CVS in NetBeans

If you're a lone developer, you might wonder why and when you would want to use CVS Isn't it just one more cratic obstruction to your workflow?

bureau-When to use CVS

You use CVS always Always! It is important for you as a developer to make sure you keep all your projects and evenyour little test programs in a source repository The trouble it takes you to set up CVS (usually about five minutes) ismore than amply repaid the first time you need to retrieve important code from an archived revision CVS also allowsyou to collate the entire body of your work in what is effectively a neatly indexed source code database

Where to get a client

CVS is available in both source code and binary form for any platform on which NetBeans will run Offerings rangefrom full CVS including the server to client-only implementations of varying degrees of completeness and GUI sup-port See the Appendix Where to Get CVS for links to sites offering CVS downloads

Before you rush off to download CVS

For use with NetBeans, you generally don't need a CVS client NetBeans' CVS support module implements aCVS client in Java and is usually sufficient for your needs However, if you plan on dealing with a sharedsource repository against which other members of your team are executing command-line CVS operations,you probably will also want to have at your disposal a CVS client for use from the command line

How does NetBeans interact with CVS?

Trang 31

Depending on how you set up your project, NetBeans performs CVS operations in any of three ways:

1 Command-line CVS formulates CVS-specific command lines and passes these command lines to the operatingsystem shell

2 Built-in CVS uses a NetBeans module consisting of Java classes which mimic classic CVS operations

3 Generic VCS formulates command lines based upon a user-supplied template and passes these command lines tothe operating system shell

In the cases above where command templates are used, the templates are parameterized, that is, the NetBeans logicconcerned with CVS operations performs substitutions on special variables This is so the template does not need tocontain, for instance, the name of every file the user might wish to check in When an operation is requested as a result

of the user interacting with the Explorer, NetBeans substitutes the values of variables such as ${ROOTDIR} based on

the current project

Using Generic VCS

Using a generic versioning control system (VCS) as an alternative to using CVS means that you can use pretty muchany versioning system you please Essentially, all that is required is that the versioning system provide a method ofcommand-line invocation NetBeans Generic VCS Support allows you to create a template of command-line stringssubject to variable substitution which NetBeans can then invoke with appropriate instantiations of the variables in order

to execute the high-level operations which you have requested via the NetBeans Explorer menu options for versioncontrol

Don't worry too much about writing a template for your favorite versioning system First of all, it's easy, and more portantly, most popular version control systems have already been tried with NetBeans and templates already exist fordealing with them Many of these templates are shipped with NetBeans Still others may be found athttp://vcsgeneric.netbeans.org/profiles/index.html [http://vcsgeneric.netbeans.org/profiles/index.html] which you maydownload and install into NetBeans Generic VCS support

im-Using Command-Line CVS Support versus Built-in CVS

As mentioned above, NetBeans possesses two means of accessing CVS repositories:

1 an installable module which implements most of a CVS client in Java;

2 a facility for issuing CVS commands via the operating system shell to an external CVS client implementation.Generally, CVS operations in NetBeans default to mounting via built-in CVS This is as it should be, since the built-inCVS client is quite reliable and there's no reason that chasing down problems in versioning operations under NetBeansshould be muddied by having to audit the behavior of your external CVS client There are, however, a couple of rea-sons you might end up using command-line support via an external client for your CVS operations:

1 You wish to customize your CVS operations to a greater degree than practical via the built-in CVS client

2 Some feature in your external command-line CVS client isn't implemented in built-in CVS

In any event, the NetBeans development team seems to be deprecating specific command-line support for CVS as

Trang 32

op-posed to treating command-line CVS as just one more instance of the support for Generic VCS We'll be showing youhow to use the specific command-line support for CVS in NetBeans, but probably Generic VCS and a CVS template isthe future of command-line CVS in NetBeans.

What parts of my project does CVS within NetBeans save?

NetBeans Explorer presents a view of a project and its components This view contains both more information than isavailable in a directory listing (such as methods and fields of classes) and less information (the Explorer doesn't showthe form files NetBeans uses to describe visual components) CVS itself deals with files and directories, and under-stands none of the abstractions employed by the NetBeans Explorer to present its object-centric view of the project tothe user

When you use the NetBeans Explorer to create a new Java package, a directory is created in the filesystem When youlikewise create a new class, a.javafile is added and later a.class file results from compiling the.javafile.When you create a class from a Swing-based template, a.formfile is created, which is an XML file describing thecomposition of the visual component which the user is creating NetBeans Explorer displays the composition of theclass in great detail, but doesn't specifically reveal that there are often three files behind the Explorer's rendition — the

.javafile, the.classfile and the.formfile

So when NetBeans prepares a CVS operation in the explorer, NetBeans makes its own assumptions about what is to besaved Adding a Java package to CVS means, to NetBeans, adding the directory, its.javafiles and its.formfiles.Additionally, if there are any files of a type that NetBeans either recognizes as significant, such as.xmland.html

files, these files are added, along with any files of types NetBeans doesn't recognize, such as foo, xyz, or

.chocolate_malted_milk NetBeans CVS support does not check in class files You don't want these in your repository; you compile them while you are working on checked out source Nor does NetBeans CVS support check in

.nbattrs files They're simply not terribly important and are regenerated when missing, if and when they are needed.

Does NetBeans automatically add new files and packages I create to the itory?

repos-NetBeans does not automatically add new files and packages you create to the repository at the time you create them.

Read on in this chapter to see how you add new files and packages to the repository

How do I manipulate my NetBeans project directly with CVS outside of Beans?

Net-If you go to perform CVS operations on a source tree which is mounted in NetBeans, either at the command line or viasome GUI tool other than NetBeans, it is best to close NetBeans while you are doing so

To operate on your project outside of NetBeans CVS support:

1 Make sure that theCVSROOTenvironment variable is set to point to the repository where your project is kept, andoptionally, that the type of repository and server name (in the case of external or password servers) is provided intheCVSROOTenvironment variable

• In the case of an external or password server, make sure you are logged in or otherwise prepared for cation

Ngày đăng: 12/08/2014, 21:20

TỪ KHÓA LIÊN QUAN