Tuesday, July 10, 2007

RAD 7 - install Merant Version Manager 8.0.2.3 plugin

At my work place, we are using Merant Version Manager 8.0.2.3 (Build 662) with RAD7.

Merant Version Manager standalone app works ok, but the plugin installer doesn't know how to find a valid Eclipse install any more, due to the way RAD packages Eclipse.

Instead, create an "Extension Loction" within RAD from which it will install the plugin for us. An extension location must be a folder named "eclipse" containing a special marker file called ".eclipseextension".

  1. Go to the following Merant directory, C:\Program Files\Merant\vm\devint\eclipse3.0\eclipse\plugins and copy the file .eclipseextension to C:\Program Files\Merant\vm\devint\eclipse3.0\eclipse.
  2. In RAD 7 and select Help > Software Updates > Manage Configuration.
  3. Right click on the root node, Rational Application Developer and select Add > Extension Location.
  4. Enter C:\Program Files\Merant\vm\devint\eclipse3.0\eclipse.
  5. RAD will ask you to re-start. Let it do that and when RAD comes back you should have Merant on your menu.

If you get an SCC_E_INITIALIZEFAILED error when you open RAD (or the Merant menu item), go to my RAD 7 - Merant Version Manager: SCC_E_INITIALIZEFAILED blog post.

Monday, July 09, 2007

DB2 - Cryptic error messages begone!

Found this on the blog of my friend Lars. I haven't got enough fingers to count the number of times I needed something like this, so I am putting on my own blog as well. :)

A typical cryptic DB2 error message contains something like the following.

Assignment of a NULL value to a NOT NULL column "TBSPACEID=3, TABLEID=14, COLNO=1" is not allowed.

Here is some SQL you can run to determine which table and column such an error is referring to:

SELECT tabschema, tabname, colname
FROM syscat.columns
WHERE colno = XXXX
AND ( tabschema, tabname )
IN (SELECT tabschema, tabname
   FROM syscat.tables
   WHERE tbspaceid = yyyy
   AND tableid = ZZZZ )

Replace XXXX with the column number, YYYY with the table space id and ZZZZ with the table id.

Wednesday, July 04, 2007

RAD 7 - Merant Version Manager: SCC_E_INITIALIZEFAILED

I recently installed RAD7 on a freshly formatted machine. Merant Version Manager 8.0.2.3 was pre-installed on the machine (company image).

When I opened RAD I got some error dialogs.. When I tried to open Merant > Open from Merant Team Provider. I got them again:

Merant SCCJ dialog.
Incorrect SCC provider version installed.

Followed by SCCJ dialog.
Failed to load SCC provider.

Followed by Merant Team Interface dialog.
Failed to Initialize Merant Team Provider - Error Code:
SCC_E_INITIALIZEFAILED

In the workspace/.metadata/.log I find the following error.

!ENTRY com.merant.team.pvcs 4 4 2007-07-04 21:29:58.167
!MESSAGE Failed to Initialize Merant Team Provider - Error Code: SCC_E_INITIALIZEFAILED
!STACK 0
merant.interfaces.scc.SccException: Failed to Initialize SCC
       at merant.interfaces.scc.SccInstance.Initialize(Unknown Source)
       at com.merant.team.pvcs.scc.PvcsSccTeamProvider.GetFromScc(Unknown Source)
       at com.merant.team.pvcs.ui.scc.actions.GetFromSccAction.run(Unknown Source)
       at org.eclipse.ui.internal.PluginAction.runWithEvent(Unknown Source)
       at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(Unknown Source)
       at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(Unknown Source)
       at org.eclipse.jface.action.ActionContributionItem.access$2(Unknown Source)
       at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(Unknown Source)
       at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
       at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
       at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
       at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
       at org.eclipse.ui.internal.Workbench.runEventLoop(Unknown Source)
       at org.eclipse.ui.internal.Workbench.runUI(Unknown Source)
       at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Unknown Source)
       at org.eclipse.ui.PlatformUI.createAndRunWorkbench(Unknown Source)
       at org.eclipse.ui.internal.ide.IDEApplication.run(Unknown Source)
       at org.eclipse.core.internal.runtime.PlatformActivator$1.run(Unknown Source)
       at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(Unknown Source)
       at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(Unknown Source)
       at org.eclipse.core.runtime.adaptor.EclipseStarter.run(Unknown Source)
       at org.eclipse.core.runtime.adaptor.EclipseStarter.run(Unknown Source)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.eclipse.core.launcher.Main.invokeFramework(Unknown Source)
       at org.eclipse.core.launcher.Main.basicRun(Unknown Source)
       at org.eclipse.core.launcher.Main.run(Unknown Source)
       at org.eclipse.core.launcher.Main.main(Unknown Source)

The fix was supplied by Rob Noah on the Serena Message Boards. The fix is to un-register and re-register some *.dll and *.exe files

Save the following to two batch files within the devint\bin directory, which for me is C:\Program Files\Merant\vm\devint\bin.

Save this one as unReg_Devint.bat

REM save as unReg_Devint.bat
regsvr32 /u ActivityMonitor.dll
regsvr32 /u compcli.dll
regsvr32 /u COMSession.dll
regsvr32 /u DialogIntegration.dll
regsvr32 /u IFC_COM.dll
regsvr32 /u IFC_GUI.dll
regsvr32 /u IFC_SCC.dll
regsvr32 /u IFC_Services.dll
regsvr32 /u PvcsVmVCP.dll
regsvr32 /u SccSession.dll
pclioutproc.exe /unregserver
ActivityMonitorEXE.exe /unregister
pause;

Save this one as Reg_Devint.bat

REM save as Reg_Devint.bat
regsvr32 "C:\Program Files\Merant\vm\devint\bin\ActivityMonitor.dll"
regsvr32 "C:\Program Files\Merant\vm\devint\bin\compcli.dll"
regsvr32 "C:\Program Files\Merant\vm\devint\bin\COMSession.dll"
regsvr32 "C:\Program Files\Merant\vm\devint\bin\DialogIntegration.dll"
regsvr32 "C:\Program Files\Merant\vm\devint\bin\IFC_COM.dll"
regsvr32 "C:\Program Files\Merant\vm\devint\bin\IFC_GUI.dll"
regsvr32 "C:\Program Files\Merant\vm\devint\bin\IFC_SCC.dll"
regsvr32 "C:\Program Files\Merant\vm\devint\bin\IFC_Services.dll"
regsvr32 "C:\Program Files\Merant\vm\devint\bin\PvcsVmVCP.dll"
regsvr32 "C:\Program Files\Merant\vm\devint\bin\SccSession.dll"
"C:\Program Files\Merant\vm\devint\bin\pclioutproc.exe" /regserver
"C:\Program Files\Merant\vm\devint\bin\ActivityMonitorEXE.exe" /register
pause

Close all instances of RAD/Eclipse and Merant. Then run unReg_Devint.bat. Then Reg_Devint.bat. This fixed my problem.

Eclipse: project specific checkstyle configuration

Updates:
- 12th July, 2007 - use "Project Relative Configuration", don't use absolute paths.
- 21st March, 2008 - Modified JavadocMethod and RedundantThrows checks in checkstyleRules.xml (on box.net) as per this note.
- 24th May, 2009 - Modified linked checkstyleRules.xml (on box.net): a) sorted modules by name; b) added modifications I referred to in my first comment below.
- 28th February, 2010 - re-wrote post to use generated Checkstyle.xml and extra detail about customisation.
- 17th March, 2013 - Checkstyle Configuration now also in this pastebin: http://pastebin.com/hz77H62W

This is how I set up project specific Checkstyle configuration as files that you check in to source control so that every developer who works on the project will automatically use the same Checkstyle rules. This post assumes your team is using Eclipse (3 or greater) and has the Checkstyle plugin installed. Two files are involved: [projectRoot]/.checkstyle and checkstyle.xml. Eclipse projects with Checkstyle enabled will use a file called .checkstyle (in the project root dir) to record Eclipse specific checkstyle configuration settings and I always save the Checkstyle XML rules to [projectRoot]/tools/ide/checkstyle/checkstyle.xml..

Create a Checkstyle configuration for your project in the following way.

  1. Remove previous configurations and file sets.
    1. Select Project | Properties | Checkstyle | Main tab.
    2. If "Checkstyle active for this project" is not ticked, skip this step (Remove previous configurations...).
    3. Make sure "Use simple configuration" is not ticked.
    4. Un-tick "Enabled" and click Remove for any File Set entries in the top section (labeled "Advanced - configure file sets ...").
    5. Switch to the "Local Check Configurations" tab.
    6. Remove any "Check Configuration" entries you see there.
    7. Press "OK" to exit Project Properties.
  2. Generate the checkstyle XML rules file.
    1. In your project, make a directory like tools\ide\checkstyle or whatever makes sense to you.
    2. In Eclipse select Windows | Preferences | Checkstyle | select "Sun Checks (Eclipse" under "Global Check Configurations" | click Export | export to checkstyle.xml in the tools\ide\checkstyle directory (name and location can be anything, as long as it's in the project somewhere and has a name that makes sense).
  3. Set checkstyle.xml as your project local checkstyle configuration.
    1. Select Project | Properties | Checkstyle | Local Check Configurations.
    2. Press "New" and you should see the "Check Configuration Properties" dialog.
    3. Under "Type", select "Project Relative Configuration".
    4. Enter "Name" as "Local PROJECT X Checkstyle Configuration".
    5. Click "Browse" and navigate to your project's checkstyle xml file.
    6. Press "OK".
    7. Switch to the Main tab.
    8. If "Checkstyle active for this project" is not ticked, tick it.
    9. If "Use simple configuration" is not ticked, tick it. (See note on custom file sets below for more detail on this.
    10. In the drop down, select the "Local PROJECT X Checkstyle Configuration" you created earlier.
    11. Press "OK".
    12. Press "OK" (again).
    13. In the "Rebuild suggested" dialog, press "Yes".

Custom file sets. It is possible to use different Checkstyle rules (a different XML file) for different sets of Java files. For example, maybe you want to use more relaxed Checkstyle rules for your test cases (pesky Magic Numbers!). This is not hard to set up but it is harder to manage multiple Checkstyle Configurations than just one when things change. To use custom file sets, see below.

  1. Make a copy of checkstyle.xml for each file set you intend to use. Edit each XML as appropriate to apply the rules you want (see the note on customising checkstyle rules below.
  2. Create a Checkstyle Configuration for each file set (Project | Properties | Checkstyle | Local Check Configurations | New ...).
  3. Select Project | Properties | Checkstyle | Main.
  4. If "Checkstyle active for this project" is not ticked, tick it.
  5. If "Use simple configuration" is ticked, un-tick it.
  6. For each file set, press "Add" and fill out the "Checkstyle File Set Editor" dialog.
  7. Under "File Set Name" enter "PROJECT X Checkstyle File Set - [main, test, whatever]".
  8. Under "Check Configuration", select the Checkstyle Configuration you created earlier for this specific file set.
  9. Modify the regular expression patterns to define what files this Checkstyle Configuration should apply to. There is content assist to help building the regular expressions.

Personally, I have never had a real need for multiple Checkstyle configurations. I have just one configuration and use SuppressionCommentFilter to turn off Checkstyle in annoying chunks of test code (// CHECKSTYLE:OFF ... // CHECKSTYLE:ON.

Customising checkstyle rules. You can modify the rules in two ways: through Eclipse or by editing the XML file.

To edit them through Eclipse, select Project | Properties | Checkstyle | Local Check Configurations | click the one to edit | click Configure. On the left side you see categories of Checkstyle rules (Annotations, Javadoc Comments etc). Click on a category and you see over to the right side which individual rules for that category you are currently using. Tick or un-tick rules to use/ignore them. Click "Open" on any rule to modify the selected rule (there is a lot of room for customisation). Notice the icons on the left have a green tick if they are being used. Sometimes you don't see the item (ticked or not) on the right hand side. Click on it on the left had side and then click Add to use it (which also opens the customisation dialog which you have to accept). You see helpful notes against each item in the Description field, but sometimes it can be tricky working out which rule is the one you are after.

Whatever you do, don't select all on the left side and then click "Add". Eclipse makes you respond to every single customisation dialog for every single checkstyle rule, and I do believe there is an infinite number of them. I had to kill Eclipse and learn my lesson.

To edit them through the XML file, you need to... erm, edit the XML file. Refer to the Checkstyle Documentation for assistance. Each page has helpful (though at times sparse) examples.

As long as the plugin is installed, checkstyle will now work "out of the box" for any new developers.

Below is an example .checkstyle (xml) created for a project using the above process.

<?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="true">
    <local-check-config name="Local PROJECT X Checkstyle Configuration" location="tools/checkstyle/checkstyleRules.xml" type="project" description="">
        <additional-data name="protect-config-file" value="false"/>
    </local-check-config>
    <fileset name="all" enabled="true" check-config-name="Local PROJECT X Checkstyle Configuration" local="true">
        <file-match-pattern match-pattern="." include-pattern="true"/>
    </fileset>
</fileset-config>

You can also look at a sample Checkstyle xml file, checkstyleRules.xml (on box.net). Warning: this is valid under Checkstyle 4, but not 5 or later, where some schema changes were made - though most of the XML for individual rules should still be valid.

Eclipse: Shortcuts

I love my keyboard shortcuts and I actively seek out ways to use the mouse less. I find the keyboard to be more efficient than a mouse for so many tasks!

This article is about some of the very cool short-cuts that I use most, plus how you can make your own and export them for future use.

13/11/2007 12:31:46 PM Updated layout of this tutorial.

Index

  1. Open Files in the Workspace
  2. Views and Actions
  3. Navigate or Search within the Workspace
  4. Navigate between Editors, Views, Perspectives
  5. Show me the shortcuts
  6. Save your shortcuts

Open Files in the Workspace

Control+Shift+T to open up any type loaded by your projects. You can use * and ? as wild-cards here.

The same can be done for resources with Control+Shift+R. Resources is the superset of files i.e. you can find Java files through this shortcut too - by typing *.java for example.

Some perspectives don't have have this shortcut enabled. To enable it, go to Window > Customize Perspective > Commands tab. In the "Available command groups" pane, scroll down to "Resource Navigation" and check its box.

Index


Views and Actions

Alt+Q,Q brings up the "Show View" view, that allows you select any Eclipse view - and use * or ? to wild-card for their names.

This is the Alt+Shift+Q menu. By default It contains short-cuts to various views. Use the up/down keys to go through the options or press the final key in the key combinations listed.

This is the Alt+Shift+X menu. It contains short-cuts to various actions and works in the same way as the menu above.

Index


Navigate or Search within the Workspace

Press F3 while your cursor is on a variable, type or method reference and you will open up the declaration of the variable, type or method. If you use it to click on a reference to code held in an external Jar file, you might need to attach the source (if you have it) for this to work.

Perhaps the single most useful tool for jumping around a class or just examining what is in a class is the Quick Outline view, Control+O.

Type in the beginning of a method, again using ? and * wild cards, and the list shortens. This is the fastest way to move between methods in a large class. Control+O, type enough to narrow the methods down, arrow down and press enter. Much faster than the scrolling through a class or even scrolling through the outline view itself.

There are, of course, plenty of short-cuts I use that don't involve bringing up a pop-up of some sort.

Use Alt+Left and Alt+Right to navigate backward and forward respectively through your code "navigation" history. Control+Q visits the last edit location.

Control+Alt+G will do a file search on whatever token your cursor is within. Warning: by default, this will do a search through all files in your workspace so it might take a bit of time. Alternatively, select and copy that token, press Control+H (for the search dialog), select the tab for whatever search you want, fill it out, press enter and wait for those results. Most likely it will get your results faster, but requires a few more mouse and/or keyboard actions!

Control+Alt+H is one of my favourites: it will show the call hierarchy for whatever method your cursor happens to be within. This brings up the Call Hierarchy view and shows each chain of parseable method calls that reaches the current method: this is the caller hierarchy.

Flip it around by pressing a button in the Call Hierarchy view and you show the callee hierarchy - the methods called from the current method.

Unfortunately, this view won't help you identify methods called from within JSPs. This is the same for any other view that relies on being able to parse trees of Java elements.

Press F4 within a class to show the Hierarchy view, which shows an outline for the current class plus a tree of subclasses for the class. Again, you can flip it to show the tree of supertypes by pressing a button in the view.

Index


Navigate between Editors, Views, Perspectives

Control+F6 and Control+Shift+F6 to switch between all the editors you have open in a workspace. Personally I don't like having to use two hands for this, so I set Control+Tab and Control+Shift+Tab to this - see Show me the shortcuts!.

You can use a split screen function to display multiple editors at once. Do this by opening multiple files at once and clicking and dragging the tab of an editor to the left/right/tob/bottom of the editor view. You can switch between views in a particular partition using Control+E.

Press Control+Shift+E to bring up the "Switch to Editor" view. It has some nice functionality to let you manage editors you have open. But to be honest, if you need it, you are probably working on too many files at once!

Control+F7 and Control+Shift+F7 switches between views. I like this one enough that I changed it Control+~ and Control+Shift+~ - see Show me the shortcuts!

Control+F8 and Control+Shift+F8 switches between perspectives.

Index


Show me the shortcuts!

Sourceforge has a set of cheat sheets that tell you the default shortcuts for your version of Eclipse.

Check out your own shortcuts! Window > Preferences > General > Keys.

Go to the Modify tab to set your own shortcuts. I use this a lot.

In particular I set up the Shift+Alt+Q,X short cut to add all of the views that I switch between regularly. For example, to set a shortcut for the console, select the view as shown to the left. Put the cursor into the Key Sequence Name field, press Shift+Alt+Q, then C. Press Add to set the shortcut. Now, Shift+Alt+Q,C will open the Console View.

Index


Save your shortcuts

If you use multiple workspaces or use Eclipse on multiple machines and make lots of customizations to your shortcuts - or perspectives - you will know how hard it is to set up a workspace over and over. Thankfully, you can export all of these preferences and import them later. Go to File > Export > Preferences. Select "Export All" and fill out the destination path in the "To preference file" field. Click "Finish" to output a .epf file. Import these with File > Import > Preferences.

Index