Saturday, January 12, 2013

JPA and Maven and multiple persistence units

I needed to convert an existing Netbeans build to use Maven in order to stabilize the code and support Test Driven Development.

Generally this was a fairly simple process: just move all the source files and resources to the right folders in a new Maven project, and add the dependencies.

Everything was going swimmingly until I ran my first tests and got this really lovely set of errors that didn’t really tell me what was going on:

javax.annotation.processing.FilerException: Attempt to recreate a file for type com.omnistools.GaclAcl_

Now at this point I normally just do a few Google searches and find out how somebody else has solved this problem, but I really wasn’t having any luck at all finding an answer.

I did run across a couple of posts that mentioned seeing this error when using multiple persistence units in the persistence.xml.

Now my project does have a persistence unit for testing outside GlassFish (my chosen EJB container), so my first thought was to move that PU to the “right” place for my tests. So I copied the persistence.xml from src/main/resources/META-INF to the src/test/resources/META-INF and changed them so there was only one PU in each.

Well, that seemed to work for a minute, no more exception on the compile step. But now I had a new problem: I was getting an error that the PU couldn’t be found:

Tests in error:
testinsertTrackingCustomerUnFixed(com.omnistools.service.util.CompanyCustomerTrackingTest): No Persistence provider for EntityManager named ProjectTest-ejbPU
testinsertTrackingWithoutCustomerUnFixed(com.omnistools.service.util.CompanyCustomerTrackingTest): No Persistence provider for EntityManager named ProjectTest-ejbPU
testinsertTrackingCustomerFixed(com.omnistools.service.util.CompanyCustomerTrackingTest): No Persistence provider for EntityManager named ProjectTest-ejbPU
testinsertTrackingWithoutCustomerFixed(com.omnistools.service.util.CompanyCustomerTrackingTest): No Persistence provider for EntityManager named ProjectTest-ejbPU

So doing a bit of digging, it appears that the persistence.xml only gets copied once and only from the src/main/resources/META-INF folder.

I must have tried a thousand different permutations and combinations until I realized that I could have an ugly workaround that is not ideal.

The issue is that if both have the “exclude-unlisted-classes” set to true, the javac compiler tries to recreate the annotation classes during the compiler:compile and of course fails on the second PU because the classes have already been created.

So to get this to work, I set the “exclude-unlisted-classes” to false for one of the PU’s, which gets me the generated meta classes, and the tests fail (because the PU doesn’t include the required entities).

I then flip the flag back to true, and run the build again. Since the classes have already been compiled, the compile:compile doesn’t run, and the tests can succeed.

And then finally, I run across a bug report on the NetBeans site: http://netbeans.org/bugzilla/show_bug.cgi?id=183779. Now this bug talked about setting some compiler flags (in particular -proc:none which tells the compiler not to generate meta classes).

Workaround was proc:none to the javac compiler args as described here: http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html

        <plugin>            <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-compiler-plugin</artifactId>            <version>2.3.2</version>            <configuration>                <source>1.7</source>                <target>1.7</target>                <compilerArguments>                    <endorseddirs>${endorsed.dir}</endorseddirs>                    <proc:none/>                    <Xlint/>                    <Xlint:-path/>                    <verbose />                </compilerArguments>                <showDeprecation>true</showDeprecation>            </configuration>        </plugin>

Now my Maven build works like a charm. Both persistence units are defined in my persistence.xml, and both have the “exclude-unlisted-classes” set to false, and not only do my tests work, but the deployment is now successful as well.

Thursday, December 6, 2012

Java 7 and Mac OS X

After getting my new Mac Mini pretty well set up with my development tools, I started playing with Amazon AWS. When trying to connect to one of my instances using their built in tool, Firefox bailed and I was presented with a prompt asking me if I wanted to install Java:

To open “Firefox,” you need a Java SE 6 runtime. Would you like to install one now?

Now this message looked very official, and I’d seen it before when starting up something on a new Mac that required Java, but since I’d already installed the latest JDK I was thoroughly confused. I thought, “OK, maybe you didn’t install Java after all”

So I popped open a terminal and

mini:~ robweaver$ java -version
java version “1.7.0_09″
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode.

OK, so that’s not it – so I changed browsers and tried the browser check at http://javatester.org again, only to get the same results …

Ouch – so I dug around a bit, and couldn’t find anything about how to fix it. And in fact the little bit I did find only confirmed that the browser plugin was active and the right version.

So finally I decided to punt and just let it install – Clicking the button to to let it start ran a package that looked like it was installing something, and when it was done another trip to javatester.org showed that somehow the plugin had been fixed and was now giving me the right version of Java in all my browsers.

Java Version tester

The only thing I can guess is that there was something that had to be set up on first use, but it did give me a start when being asked to install Java SE 6. Fortunately, whatever it did, it didn’t muck with my JVM and I’ll just have to hope that it didn’t break anything elsewhere.

 

Wednesday, December 5, 2012

Adding Missing PHP library on Mac OS X Mountain Lion (10.8)

I’m doing some work on a project that is using PHP, and have been working on setting up some continuous integration build scripts to make sure that we have a shot at catching errors before they make their way to production.

Recently some unit tests were added for the “forgot password” code, which uses the mcrypt libraries which are not installed by default on Mac OSX, so I was seeing this error:

Call to undefined function mcrypt_get_iv_size()

So some quick Google searches, and I found a couple of blogs with “how to” install the library (links at the end of this post), and proceeded to get this done.

First step was to download the mcrypt from SourceForge at http://sourceforge.net/project/showfiles.php?group_id=87941

Once I had the file, I opened a command prompt and ran:

tar xvfz libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/

Next I ran configure, setting the appropriate flags for my envirionment (note – I didn’t do this for the other configures, probably would have been a good idea):

MACOSX_DEPLOYMENT_TARGET=10.8 CFLAGS=’-O3 -fno-common -arch i386 -arch x86_64′ LDFLAGS=’-O3 -arch i386 -arch x86_64′ CXXFLAGS=’-O3 -fno-common -arch i386 -arch x86_64′ ./configure –disable-dependency-tracking

This sets up the make file, so you can run the next two commands:

make -j6

sudo make install

Next to make the PHP library, I needed the PHP source files, so I went out and grabbed PHP 5.3.15 (since that’s the version I have when I run php -version) by going to http://us3.php.net/get/php-5.3.15.tar.bz2/from/a/mirror. Note that you can simply change the version number in that URL to get the version you need.

Once I had that I did the following:

tar xvfz php-5.3.15.tar.bz2
cd php-5.3.15/ext/mcrypt
/usr/bin/phpize

This of course gave me an error about autoconf not being installed:

Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.

From there I installed autoconf by doing the following:

curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar xvfz autoconf-latest.tar.gz
cd autoconf-2.69/
./configure
make
sudo make install

Then back to the php mcrypt folder and reran the phpize step to and finish building:

/usr/bin/phpize
./configure
make
sudo make install

Finally an edit to the php.ini file which was simply to add the extension:

extension=”/usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so”

And of course a quick restart of Apache and the extension shows up and I can run my unit tests successfully.

Related posts:

http://www.coolestguyplanettech.com/how-to-install-mcrypt-for-php-on-mac-osx-lion-10-7-development-server/

http://michaelgracie.com/2011/07/21/plugging-mcrypt-into-php-on-mac-os-x-lion-10-7/

Wednesday, November 28, 2012

Installing Doxygen on Mac OS X

Just a quick note – I was guided toward doxygen, which is a tool that does source code documentation. It has a DMG installer, that includes an executable to run doxygen with a wizard.

But since my purpose was to run doxygen in an Ant build script, I needed to install the command line version.

I simply looked inside the application, and was able to see that the executable was in /Applications/Doxygen.app/Contents/Resources/

Adding a symbolic link to /usr/local/bin (which is in my PATH) did the trick:

sudo ln -s /Applications/Doxygen.app/Contents/Resources/doxygen /usr/local/bin

Sunday, November 11, 2012

Governance Change (A Fable)

Once upon a time, there was a kingdom of people who were busy managing projects named Pee-Em-Eye Ess-Eff-BeeA Sea. They were busy doing this work, and they found themselves wondering if there was a better way than just telling people what to do, and then scurrying off to the next project.

A small group of people in the kingdom thought that there was a better way to manage the kingdom of Pee-Em-Eye Ess-Eff-BeeA Sea. They believed they could apply some of their project management skills to help all the people in the kingdom to be more successful and happy.

So they started holding meetings with as many people as they could and asked people to become members of the community. They elected a president, and a board. Since each board member was interested in helping out in different areas, each one chose a different title (like CFO and VP of Professional Development, etc.). Since they all knew that they were trying to make life better for Pee-Em-Eye, they worked very well in these roles, and their work flourished.

At some point, they realized that they should probably apply some democratic best practices, so they wrote some bylaws that included both how things were working now, and things intended to sustain the kingdom (like how long a board member could serve, and how they would be elected, etc.)

The kingdom and the board flourished, and new boards were elected from the other volunteers in the organization. The organization grew, and life was good.

After a long while, a curious thing happened. Partly because none of the original council were still around, and partly because the world had changed, they were having trouble keeping momentum from year to year. And, in fact it was becoming harder to find people who could lead the work needing to be done while still thinking of the long term good of the kingdom. And the council was so busy with keeping things running that they were losing touch with their members. The members in turn were losing confidence in the kingdom, becoming less involved and in fact starting to wonder why they were even members at all.

Fortunately for the kingdom, around this time one of the members of the kingdom met Paulie C. Governance. Paulie, it seems, had a solution to the issues of the day: transparency, accountability and community involvement. There was a system, he told them that would focus them on the real goals of the organization (Paulie called this the “global ends statement”). Paulie also told them that the goals would align better with the needs of the members (Paulie called them “owners”), and would open communications between the citizens and the board. (Paulie called this increase in transparency and communication “ownership linkage”), and that system was called Policy Governance®.

After some interesting “Who’s on First?” conversation during which the board learned that the system wasn’t “Paulie C. Governance” and in fact hadn’t been named for Paulie, but rather was  an integrated set of concepts and principles that describes the job of any governing board. This system was similar to the PMBOK in that it was a system based on theory gained by study and synthesis of a number of other concepts including servant leadership.

So Paulie’s idea was to change the way the board operated. They would be responsible for guiding the kingdom, and responsible to the member/owners and accountable to them. All they had to do was to delegate the responsibility for the day to day work to someone who was accountable to the board, who in turn would be accountable to the member/owners.

So the council worked with Paulie to interpret the goals of the member/owners that they would need in order to focus on delivering the true needs of the member/owners (Paulie called these the “ends”). Once they had done that, they worked with the member/owners and with Paulie’s guidance decided upon the boundaries that were acceptable in accomplishing those ends (Paulie called these “limitations”).

They chose a new CEO to lead the day to day work of the organization guided by both the ends and limitations.

Paulie next told them:

In order for this system to work, the CEO needs the freedom to choose the means by which they accomplish the ends. So you need to judge their performance not by personal bias or unwritten ideas, but by the standard that they have used any reasonable interpretation in those means.

Any reasonable interpretation means just that. It doesn’t mean the interpretation of the most prominent board member, the interpretation the board had in mind but didn’t say, or even the interpretation now favored by the entire board. The council is obligated not only to be fair in this judgment, but to protect the CEO from individual board members who wish to judge based on their interpretation of the board’s policy.

Once the board adopted Policy Governance®, the moral of the story became clear. The board was able to clearly summarize the goals of the kingdom as:

PMI-SFBAC members, people who live and work in Northern California, and virtual beneficiaries experience a continually improving standard of living, stability, a sense of community, self-esteem and self- actualization. These Ends will be achieved in a sustainable manner that represents value for the resources invested.

Because there was now this clear vision, CEO no longer focused on random ideas of each board member, but was able to make intelligent decisions and ensure that all the work the volunteers were doing was driving toward that vision. And because the vision was clearer, what was being asked of the volunteers was clearer, and they were happier. And the board no longer had to spend long hours thinking about which programs to cut or how much to spend on each one, since the policies allowed the CEO to do this.

The CEO was able to mobilize more volunteers and more easily help guide them. There was the freedom to innovate, and clear boundaries to avoid misstep, and a confidence building since it was clear that there was no need to satisfy individual board members’ pet projects, but instead be responsible to using means that satisfied the “any reasonable interpretation” test for the entire board.

And the framework also helped the board in their job. Their calendar was now completely driven by monitoring the policies, and linking back to the membership. A schedule for monitoring the policies was included in the policies, so they knew exactly when they would be looking at which issue, and when to expect evidence of compliance from the CEO and when they would monitor their own compliance with the policies.

Because this system called Policy Goverance® helped them be clearer on what they needed to do, things that they had long thought impossible were happening: Board meetings were more organized and regular, they could spend more time working with the membership to improve the policies, the organization was able to be more innovative and focused.

So the journey began, and I’d like to say they “lived happily ever after”, but then came the trial of Paulie C. Governance … But that’s a story for another day ….

The End

Wednesday, October 31, 2012

Who is Policy Governance®

The court room quieted as Paulie C. Governance took the stand. He was sworn in on a stack of PMBOK‘s and the prosecutor was ready to begin.

The following was taken from the transcript and witness accounts:

Prosecutor: Please state your name and occupation for the court

Paulie: Paulie C. Governance, trusted advisor to the board.

Prosecutor: And you are a proposing a change to the way the board operates are you not ?

Paulie: Yes, Policy Governance®.

Prosecutor: Thank you, we have your name, I was asking you about the change you are proposing.

Paulie: Yes, that is Policy Governance® .. with a capital P and a capital G.

Prosecutor: Yes, yes, and a capital C. I was asking what, not who.

Paulie: No capital C, bu there is a registered trademark, like the PMP®

Prosecutor: You don’t capitalize the C?  That IS unusual. Why would Paulie C. Governance have a registered trademark?

Paulie: Well Policy Governance® is the child of John and Mirriam Carver, and they wanted the protection of the registered trademark.

Prosecutor: Your parents gave you a registered trademark ? I think we’re way off topic here. Please tell us: what is the name of the the system you are proposing.

Paulie: Policy Governance®

Prosecutor: So the system has your name ? Are you expecting to run the board yourself.

Paulie: No, the board will use an integrated set of concepts and principles that describes the job of any governing board.

Prosecutor: Now we’re getting somewhere: what is that system called ?

Paulie: Policy Governance@

Prosecutor (clearly frustrated): Now let me get this straight: your name is Paulie C. Governance, right?

Paulie: Yes

Prosecutor: And Mirriam Carver gave birth to Paulie C. Governance ?

Paulie: No, she only added to the theory, it was John Carver’s idea.

Prosecutor (grinning): It usually is the man’s idea. Let’s try something else: you are proposing the board use an integrated set of concepts and principles that describes the job of any governing board.

Paulie: Yes

Prosecutor: and that system is called Paulie C. Governance, but it’s not named after you?

Paulie: Yes

Prosecutor: then what is your name?

Paulie (now frustrated): Paulie C. Governance is my name, and the system is Policy Governance® which is an integrated set of concepts and principles that describes the job of any governing board.

At this point, the prosecutor tried to strangle Paulie, so court had to adjourn until a new prosecutor could be found …

Monday, October 1, 2012

Using Firebug and jQuerify to Filter a Page

I love Firebug, and I’m getting so I understand jQuery pretty well.

I often drop into the console and type in jQuery commands to figure out how to get things to happen on a page. For example, I was looking at a really long page of search results from Taleo that lists out all of my submissions for jobs at CACI. The problem is, that it shows the fully active submissions with the inactive ones, so it’s not very useful for figuring out what I need to follow up on.

So it occurred to me that if I could just write a couple lines of jQuery to look for the items that include “Active” in them, I could reduce this list in a way that would be meaningful for me.

So the first thing I did was go look at the page HTML to figure out whether there was something on the page I could use to separate out each row on the search page.

 

 

 

I fired up Firebug by right clicking on one of the items and choosing “Inspect in Firebug”.

 

 

 

 

 

 

 

 

 

 

This starts up Firebug (if it isn’t already showing) and took me to the part of the HTML that I was looking for:

 

 

 

 

 

 

So now I knew I needed to look for something that had a class of “iconcontentpanel” that contained the text “Active”.  I decided to outline it with a green dashed line, so my jQuery looked like:

$(".iconcontentpanel:contains('Active')").css('border','3px dotted green');

So I flipped over to the Console in Firebug and tried running that:

 

 

 

 

 

But that gave me an error since there is no jQuery on the original page. But there’s this nifty little thing in the console that says “jQuerify”, and clicking that injects jQuery into the page:

 

 

 

 

 

 

So now that jQuery is available, running the script again gives me what I was looking for:

 

 

 

 

 

 

 

And of course I can add even more jQuery to strip out unwanted parts of the page, change format, etc, leaving me something that is more  actionable: