I didn't show the summary output that Cobertura displays in Hudson. It looked like this:
You'll note (or I will do so for you) that there's a variety of packages here (in the cocoa case, these are just subdirectories of the current workspace).
Notwithstanding the anemic percentages of coverage overall, outside of the
What I want is accurate reporting for the code that I write.
When we setup the gcovr build step in Hudson, the command looked like this:
/usr/local/bin/gcovr -r . -x -b -e /Developer 1> html/coverage.xml 2>/dev/null
The -e /Developer command line argument instructs gcovr to exclude any files with names that match /Developer. The final config that I'm now working with is:
/usr/local/bin/gcovr -r . -x -b -e /Developer -e './UKKQueue/' -e './DebugUtils/' -e './Foundation/' -e './UnitTesting/' -e './Third Party Sources/' -e '.*/ShortcutRecorder.framework/' 1> html/coverage.xml 2>/dev/null
Which is obtuse at best, but works. The '.*/xxx/' is necessary because the fully qualified path is processed by gcovr. In my case it would be /Users/jschilli/.hudson/jobs/Tickets-MASTER/workspace/...
The results now look like this:
The absolute measure of coverage for each of the two remaining packages has not changed, but the information is now focused on the data that is most important to me.
With all of that said, the exclusions you choose to add are project specific. Hopefully this will help you hone the reporting to your liking.
]]>Continuous Integration (CI) has been around for a while now. Popularized in the java/ruby/[lang] communities, CI, when properly implemented promotes good code practices. CI alone won't guarantee great code, but it helps support good behavior and in fact rewards users routinely and reliably.
I've used Continuous Integration in many former lives - CI was essential on large geographically distributed teams - driving out incompatibilities in interface and implementation early and often.
My definition of a successful CI system and implementation are:
When I released my first iPhone app, I was building the project in Xcode, switching to Finder and/or Terminal.app, compressing, copying and generally screwing up at every possible step. Although I've seen the benefits of automation multiple times, I was so busy getting this app out that I couldn't see how I could take the time to write scripts. That airlock of paradox didn't last long. I wrote a few scripts and every aspect of my build/sign/archive workflow was automated - when I ran the script.
I repeated this exercise for my first Mac product - this time a hodge-podge of scripts to build the app, generate the help files, generate the sparkle appcast, release notes, upload, etc. I still use this script and it works great - when I run the script.
Although I've had great success with CI in the past, I wasn't convinced that my one workunit indie shop could or would benefit from implementing CI. There were a few things that helped turn me around on this:
When something changes, your CI should build the system to ensure that nothing has broken. If you're in the zone and a failure pops up - easy to fix. If you find an issue weeks later - well we've all been there.
CI is all about automating those rote tasks. It is important to emphasize both the automated aspects as well as the unattended aspects of CI. The only thing worse than no CI is CI that is broken and neglected. We'll come back to this point in a bit.
There are several compelling CI solutions in the market - CruiseControl, Hudson and scores of others in the opensource space. There are a spectrum of commercially available solutions as well including Bamboo. To my knowledge, there are no CI solutions that focus on the Cocoa space [just found BuildFactory - haven't checked it out]. The good news is that most of these systems can run external processes - the by-product is good news for cocoa devs.
Hudson seems to be the leading choice - it's really straight forward to get the basics working. From there, incremental tweaks should get you up and running.
I screwed up more than a few times getting my apps to build in Hudson. There are more than a few pages on the web that illustrate Cocoa/Hudson builds.
My suggestion is to ensure that you can take a fresh cut of your project from your SCM system, check it out to a new directory and build it clean.
I would encourage you to do this outside of your normal dev tree - it's surprising how easily a relative path will find its way into your xcode build settings.
Once you have a clean repeatable build - from your scm system - you should move on to getting hudson up and running.
Installing Hudson is well documented on the net. The Hudson site includes installation instructions that work well. There are several examples of cocoa specific sites - I started here.
Because I have multiple targets setup in my Xcode project, I selected 'This build is parameterized' and added some targets to choose from. Hudson will remember your last choice.
If you use Git, Christian Hedin's article covers that configuration as well. The critical thing is to use either SCM polling or a post-commit-hook to invoke the build. Hudson will allow you to setup a time based build e.g. build every thirty minutes. The issue with that is that it will execute the build whether there are changes or not. Polling or post- commit-hooks will ensure that builds are invoked when change occurs.
You will note that I've elected to only build my master branch - by default, Hudson will checkout and build each branch that it finds in your Git repo. While I see this as advantageous (forward dev on master, branches for production release and bug fix), my branches haven't gotten the Hudson CI/gcov/unit testing love that master has.
In the interest of walking before I run, I want my Hudson build to checkout my updated code, compile my code, execute unit tests and capture any reporting output for test coverage and unit test failures. It turns out that most of this is already performed when I build my UnitTests target in my Xcode projects.
Click on build now - you can check the console to see the steps that Hudson is taking.
If the stars are aligned, you should have a successful build. If not, you'll need to crawl through the console logs to determine where the failure occurred.
It is critical that you go back to your Xcode project/standalone build directory and correct mistakes there. Check in your changes and repeat. No one has to know how many times you repeat this cycle, but it's critical to meet the spirit and law of Rule #1!
Once the basic build is working you should add unit test reporting. If you have or are planning to run unit tests (Rule #2), download this ruby script, install it in /usr/local/bin or the directory of your choice and change your build step to look like this:
In the Post-build actions, configure Hudson to publish your test results.
Trigger a build and you'll now see a chart with the build results. As your test suite grows, you should see a trending graph with increased numbers of tests.
Unit tests execution is what we're after for Rule #2, but the number of tests as a key metric is easily misleading. I've seen a lot of cases where the same code is tested over and over again. Coverage is the key indicator!
Download and install gcovr and install it again in /usr/local/bin
Add the following as a new build step (after the xcodebuild step)
gcovr converts gcov data into a format parseable by Cobertura - a coverage analysis tool.
(See Tommy McLeod's blog post here for some additional details)
Assuming you have gcov correctly working for your project (the subject of an as yet unwritten post), executing the build will result in some nice graphs.
You can now navigate through the coverage reports and see your annotated source code including what's covered - and more importantly, what's not. (There's a one-line patch to gcovr detailed here that allows Cobertura/Hudson to navigate into your code)
[Edit 3/2/2010 - new example showing a real miss]
This example illustrates the value of visualizing test coverage - I had ~15 valid operations on a model class - I wrote this code from the spec - I erroneously interpreted running green on my unit tests meant all good. In fact, I had missed several cases - clearly identified here.
Make some changes in your project, commit them to your SCM system and monitor the build. Make a test fail, introduce a compiler error and monitor the results.
You want to be able to rely on your CI system to accurately report failures. If you have instability in the process, now is the time to grind through the issues.
You can install the Jabber notification plugin in Hudson, configure your jabber address (or that of a group chat if you're working with multiple people) and Hudson will now inform you of build successes and failures. You can also configure email.
The compelling aspect of the Jabber plugin is that Hudson has a jabber bot that you can use to get status, trigger builds and more.
What's left? There are a lot of different directions you can take Hudson now that the basics are in hand. I want to spend some more cycles getting better diagnostics when the build fails. Unit test failures are clearly reported. Compilation failures (forget to commit that new file to the build?) require spelunking through the console log. I also plan on moving my production builds to Hudson, but for now, getting that jabber notification that the build is clean is totally worth the time I've invested in setting this up.
]]>I spent several hours trying to isolate the differences between the two setups - same project, different rev of Xcode. I down leveled my Xcode install on the Mac Pro, same result - now things are weird.
I moved /Developer to /Developer.old - clean install. No Love!
What I observed on the failing machine was that the versioned data model was being created in the .xcdatamodeld directory, but was not being added to the Xcode project.pbxproj file. Very Frustrating.
I grabbed Activity Monitor to watch the open files for Xcode to see if I could determine what was going on.
I noticed that DefaultFolderX (DFX) had a scripting addition loaded into my Xcode process. I disabled DefaultFolderX and voila I was able to add my versioned data model file.
Were it that this is the end of the story. I sent a note off to Jon Gotow at St. Clair Software with my observations. Jon quickly replied and asked if I was by chance using a Logitech mouse. I am. He further suggested that I look to see if /Library/ScriptingAdditions/LCC Scroll Enhancer Loader.osax was being loaded.
I reenabled DFX and saw that indeed LCC Scroll enhancer was loaded, with errors. I did a quick sudo rm /Library/ScriptingAdditions/LCC Scroll Enhancer Loader.osax, restarted Xcode and everything is working well again.
Many thanks to Jon for his quick and professional response. Logitech - my bill has been remitted.
]]>Rather, its a note that I need to do so.
Daniel Kennett of kennetnet software has put together a few nice post mortems, most recently this one detailing the development of an iPhone companion app.
Whether you put together a presentation, a video or simply scratch some notes in your moleskine, the act of analyzing your performance on a product development or contract development effort is a good one.
I keep a page in VoodooPad for each development release and capture notes about what I could do better or differently the next time around.
iPhone Companion Apps: New Project to App Store in Two Months | Daniel Kennett: ""
]]>set :git_enable_submodules, 1
(tags: git capistrano github recipes configuration)
Froth is a Objective-C web application framework that brings the power and simplicity of Cocoa development to the web.
While froth web apps are technically deployable on many different platforms using Cocotron, currently our focus has been on the Amazon EC2 cloud.
(tags: objc amazon ec2 ami web programming)
Forwarding ssh keys
(tags: git ssh capistrano)
sudo a2enmod rewrite
(tags: apache ubutnu configuration)
]]>Braid Braid is a simple tool to help track git and svn vendor branches in a git repository.
The project homepage is at http://github.com/evilchelu/braid/wikis/home
(tags: git ruby tools utility)
HTTP Sniffer for OS X
]]>Wow!
(tags: coda css html productivity)
(tags: osx desktop management 10.6only)
]]>[alias] lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
PHGraph is a very simple cocoa framework to display scientific plots in the plane, for osX tiger and leopard (universal binary).
Why another framework ? Because the plotting frameworks I've been able to find here or there did not fulfill my expectations, including the ability to display quickly and efficiently plots with a large number of points.
]]>design web ux
]]>(tags: coda web design html css tools)
Tying instructions for the Beadhead Prince Nymph
(tags: fly patterns instruction illustrated diy)
]]>In this part of the series, we are going to add collapsible subviews.
There are several ways to support collapsible subviews. The first is supported directly by NSSplitView. As the user drags a divider to its minimum position, if subviews are collapsible, additional movement will result in the subview snapping shut.
We can support this behavior by adding the canCollapseSubview method.
- (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview;
{
NSView* rightView = [[splitView subviews] objectAtIndex:1];
NSLog(@"%@:%s returning %@",[self class], _cmd, ([subview isEqual:rightView])?@"YES":@"NO");
return ([subview isEqual:rightView]);
}
Dragging the divider to the right most edge of the window will result in the right subview snapping shut. The divider will still be show on the rightmost margin of the view. This collapsing behavior is our first bit of good news. When we collapse and uncollapse our right subviews, the layout is not munged as it was in part one when we effectively reduced the right subview width to zero. We'll use the observation later when we add programmatic collapsing.
We can hide the divider when the right subview is collapsed.
- (BOOL)splitView:(NSSplitView *)splitView shouldHideDividerAtIndex:(NSInteger)dividerIndex;
{
NSLog(@"%@:%s returning YES",[self class], _cmd);
return YES;
}
If you keep you're finger on the mouse while moving the divider, you can observe it collapse the right subview and then moving the divider back to the left - uncollapse it.
If you didn't keep your finger on the mouse, the right view collapsed and there is no way now to get the view back. Hovering over the right edge of the window won't do it. There aren't any buttons to press, nothing to double click.
Before we fix this issue, change shouldHideDividerAtIndex back to returning NO.
We'll add one more bit of goodness before we tackle programming collapsing.
NSSplitViewDelegate includes an optional method shouldCollapseSubview:forDoubleClickOnDividerAtIndex: - it does its name suggests. If we answer YES, double-clicking on the divider will collapse the right subview. Double-clicking on the divider while the right subview is collapsed will uncollapse the right subview.
Here's the implementation:
- (BOOL)splitView:(NSSplitView *)splitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex;
{
NSView* rightView = [[splitView subviews] objectAtIndex:1];
NSLog(@"%@:%s returning %@",[self class], _cmd, ([subview isEqual:rightView])?@"YES":@"NO");
return ([subview isEqual:rightView]);
}
Sweet!
Programmatic double-click will allow us to hook the action selector of a menu item, a toolbar button or other UI control to a method that will toggle the collapsed state of the collapsible subview.
First we'll add a toolbar to our window to have a convenient place to put the toggle button.
In MySplitViewController, we'll add the logic to toggle right subview.
-(IBAction)toggleRightView:(id)sender;
{
BOOL rightViewCollapsed = [[self mySplitView] isSubviewCollapsed:[[[self mySplitView] subviews] objectAtIndex: 1]];
NSLog(@"%@:%s toggleInspector isCollapsed: %@",[self class], _cmd, rightViewCollapsed?@"YES":@"NO");
if (rightViewCollapsed) {
[self uncollapseRightView];
} else {
[self collapseRightView];
}
}
-(void)collapseRightView
{
NSView *right = [[[self mySplitView] subviews] objectAtIndex:1];
NSView *left = [[[self mySplitView] subviews] objectAtIndex:0];
NSRect leftFrame = [left frame];
NSRect overallFrame = [[self mySplitView] frame]; //???
[right setHidden:YES];
[left setFrameSize:NSMakeSize(overallFrame.size.width,leftFrame.size.height)];
[[self mySplitView] display];
}
toggleRightView: is the public method that we'll connect UI elements to. It queries the NSSplitView to see if the right subview is collapsed. If not, it calls collapseRightView otherwise, we'll uncollapseRightView:. The key element here is to ensure that the 'collapsed' status of the right view is set correctly. My first several attempts to make this work involved setting the frame width of the right view to 0. NSSplitView did not answer YES to isSubviewCollapsed: under those circumstances. Remember the observation earlier that when we snapped the right view closed and reopened it the view had not been mangled by autoresize logic? That suggests that the view was never shrunk to zero width, but rather hidden. I confirmed this with a F-Script session.
uncollapseRightView: is equally straight forward --
-(void)uncollapseRightView
{
NSView *left = [[[self mySplitView] subviews] objectAtIndex:0];
NSView *right = [[[self mySplitView] subviews] objectAtIndex:1];
[right setHidden:NO];
CGFloat dividerThickness = [[self mySplitView] dividerThickness];
// get the different frames
NSRect leftFrame = [left frame];
NSRect rightFrame = [right frame];
// Adjust left frame size
leftFrame.size.width = (leftFrame.size.width-rightFrame.size.width-dividerThickness);
rightFrame.origin.x = leftFrame.size.width + dividerThickness;
[left setFrameSize:leftFrame.size];
[right setFrame:rightFrame];
[[self mySplitView] display];
}
The cool thing about all of this is that we're not saving frame rects or adding additional data structures to hold this state. I can assure you that my first several attempts to understand NSSplitView had loads of code to deal with view frames, collapse states, notifications to enable/disable view resizing etc. It is true, at least in this case, that if you're fighting the frameworks, there may be a more enlightened path awaiting discovery.
We can now go back and hide the divider when the right subview is collapsed. The app should now look like this.
We've accomplished quite a bit. I know, it's hard coded to collapse only the right subview and only handles a single split, but the concepts at work are illustrated plainly. The next few topics for future posts will include adding animated adjustments, controlling the effective drag area, customizing dividers and generalizing the solution.
The code for this segment can be downloaded here: Part-2
]]>(tags: fastspring indie mac biz)
]]>Pre-leopard behavior of NSSplitView gave rise to several of the third party frameworks. In 10.5 Apple cleaned up the implementation of NSSplitView and ostensibly provides everything one needs to use split views effectively.
My experiences (and occasional frustrations) with third party frameworks led me to dig in and try to understand what Apple offers, how it works and how (if) I could package that up in a reusable form for use in my own applications.
Everyone has there own pet list of requirements for a usable split view solution, but my list includes the following:
The excellent RBSplitView emerged in 2004 in the pre-leopard days. In addition to providing the runtime framework, RBSplitView includes an Interface Builder palette that supports IB modification of most of the desired behaviors, including divider selection, collapsible views, and min and max settings for view sizes.
RBSplitView also includes support for animating view adjustments such as collapse/uncollapse.
There are a long list of applications that use RBSplitView .
RBSplitView is, from my experiments, very solid code. Capabilities such as toggling splits works, preserving subview layouts.
The primary issue with RBSplitView is that the animation used is pre Core Animation. Running on my 8 core mac pro, this is not an issue, but it gets a bit jumpy on my MacBook Pro. Further, by implementing the animations in the framework, RBSplitView limits ones ability to leverage a consistent CA based animation scheme throughout the application.
Bottom line - in a 10.6 world, is RBSplitView still the best solution?
I have to say that I really want to like BWSplitView - Brandon Walkin's framework that provides a modern NSSplitView based solution. On the surface, it meets all of the requirements outlined above. It is supported by a rich IB palette with a slew of conveniences. Brandon's site includes some great screencasts illustrating the promise of BWSplitView.
That said, I struggled in real world usage of BWSplitView. Documented open issues around the splitter drag behavior created some showstopper issues for me.
In fact, it was my attempts to fix some of the BWSplitView issues that led me to explore how NSSplitView works.
The canonical example of splitter view behavior is perhaps Mail.app. Two splitters, a vertical split for the Mailboxes and main view. The main view is horizontally split into the messages list and the message viewer.
To understand what NSSplitView offers out of the box, let's build a sample app with a single splitter. If we can understand what is going on with a single split view, we can generalize that as we add additional split views.
In order to verify the subview resizing challenges, one of our subviews will have several standard cocoa controls with autoresizing turned on.
The app looks like this:
Dragging the divider all the way to the right and then back towards the middle quickly borks up the autoresizing behavior.
To end part 1 of this exploration, let's add minimum sizes for our split view.
We instantiate a new controller class, we'll call it MySplitViewController (as it stands now, its just a delegate but we'll be adding other functionality to it as we move along).
Instantiate an instance of this class in the XIB and hook the delegate outlet of the NSSplitView outlet to the new class.
There are a bunch of optional methods declared in the NSSplitViewDelegate - we'll implement only two. constrainMinCoordinate and constrainMaxCoordinate. The documentation is sparse on the functionality of these methods, but the header file for NSSplitView does a pretty good job of laying out the basics.
constrainMin... and constrainMax are called repeatedly while the divider is being dragged. In the example implementation, we'll answer proposedMinimum+200 for the constrainMinCoordinate call, which in our example will have the effect of limiting the left subview to 200 pixels. Judicious use of NSLog will show that the proposedMinimum will be 0 -- we're adding 200 and hence the minimum position of the divider will be 200 pixels. When you begin having splitviews with more than two subviews, the concept is the same, but you are now responsible for determining which subview is being referenced. In our example there is only one divider and its index will always be zero.
The constrainMaxCoordinate method works in a similar fashion. The splitview sends in a proposedMaximumPosition that is the width of splitview - in this case, the entire width of the window. We'll answer with that value - 100 resulting in a maximum divider position of the window width - 100 pixels.
@implementation MySplitViewController
/*
* Controls the minimum size of the left subview (or top subview in a horizonal NSSplitView)
*/
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex;
{
NSLog(@"%@:%s proposedMinimum: %f",[self class], _cmd, proposedMinimumPosition);
return proposedMinimumPosition + 200;
}
/*
* Controls the minimum size of the right subview (or lower subview in a horizonal NSSplitView)
*/
- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex;
{
NSLog(@"%@:%s proposedMaximum: %f",[self class], _cmd, proposedMaximumPosition);
return proposedMaximumPosition - 100;
}
After compiling and running, we can now see that both the left and right subview are indeed constrained. Although the 100 pixel extent of the right view does not prevent the view from looking terrible, it does prevent the autoresize funkiness of the first example.
We've only scratched the surface of NSSplitView. We limited the complexity of our NSSplitView example to the simplest possible case and illustrated some of the challenges in using NSSplitView. In the end, we were able to introduce a few delegate methods that exert additional control over the behavior of NSSplitView.
In the next article, we'll add support for collapsible subviews and then add programatic collapsing. Additional topics for future posts will cover adding animated adjustments, controlling the effective drag area, customizing dividers and generalizing the solution.
The code for this segment can be downloaded here: Part 1 Sample Projects
]]>(tags: opensource google text- processing)
]]>As you probably have guessed from the title of this post, I am not happy with this behavior, so I have written a class, CLAlert (MIT License) that displays alerts the way I think it should be done. I.e. a note icon for an informational alert, a caution icon for a warning alert and a stop icon for a critical alert as you can see on these screenshots.
(tags: cocoa nsalert mitlicense opensource)
When you want to localize your application, you can take several routes.
]]>What I really wanted was a version of Smalltalk that used the same object modal as Objective-C, like Pragmatic Smalltalk of Etoilé, or even MacRuby on Mac OS. Most of all, I wanted it to treat me like an adult: I don’t need a class browser, thank you, I’m more comfortable working with plain-old files. The persistent image construct in Smalltalk really makes me uncomfortable.
(tags: nstextcell cocoa badge customdrawing)
(tags: database etl conversion migration)
]]>