UnsupportedClassVersionError in Closure

Today while Getting Started with the Closure Compiler Application I ran into the following trouble:

jj5@mercy:~/Desktop/compiler-latest$ java -jar compiler.jar --help

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/google/javascript/jscomp/CommandLineRunner : Unsupported major.minor version 51.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: com.google.javascript.jscomp.CommandLineRunner. Program will exit.

To fix the problem I installed jdk-7:

root@mercy:/home/jj5# apt-get install openjdk-7-dbg openjdk-7-demo openjdk-7-doc openjdk-7-jdk openjdk-7-jre

Processing archives

I’m de-duplicating my archives. I processed 3.6 million files and then crashed:

Symlinks: 30,836
Directories: 513,860
Files: 3,665,000
Hardlinks: 2,241,681
Duplicates: 55,309

Time to start again. Duplicates that have already been processed will show up as unduplicated files on this next iteration… my script is here.

And now we’re finished:

Symlinks: 31,926
Directories: 2,071,219
Files: 11,682,777
Hardlinks: 8,034,685
Duplicates: 669,452
Rate: 3555.44 files/second

PHPUnit Skeleton Generator

Today I installed PHPUnit Skeleton Generator like this:

 $ vim ~/.composer/composer.json

Added:

 "minimum-stability": "dev"

 $ composer global require 'phpunit/phpunit-skeleton-generator=*'

But… then it turned out that the interface was broken when invoking from NetBeans, so over here:

$ pear channel-discover components.ez.no
$ pear install phpunit/PHPUnit_SkeletonGenerator

Then I created a phpunit-skelgen.php file in my project and added:

#!/usr/bin/php
<?php

require_once '/usr/share/php/SebastianBergmann/PHPUnit/SkeletonGenerator/autoload.php';
require_once '/usr/share/php/SebastianBergmann/PHPUnit/SkeletonGenerator/Command.php';

SebastianBergmann\PHPUnit\SkeletonGenerator\Command::main();

Simple! :)

Eclipse and XDebug NIGHTMARE

Welcome to my nightmare.

To see listeners:

 # netstat -anp | grep LISTEN | less
 # nmap localhost

To use IPv4 instead of IPv6 in Eclipse, edit:

/home/jj5/.eclipse/org.eclipse.platform_3.8_155965261/configuration/config.ini

And add:

 # https://lists.debian.org/debian-java/2010/03/msg00073.html
 java.net.preferIPv4Stack=true

More to come…

PDO Persistent Connection in PHP left broken if connected to dropped database

So you use PDO and specify PDO::ATTR_PERSISTENT => true. Then you drop your database. Then you open a new persistent connection and bang! Not working. The trick is to not use persistent connections to databases that may be dropped. And probably an ‘apache2ctl graceful’ after you drop a database being used by Apache…

Debugging PHPUnit tests in Eclipse PDT with XDebug on Debian GNU/Linux

Wow, this was complicated!

Make sure PHP, Xdebug, etc. are installed:

 # apt-get install php php5-xdebug php5-curl php5-mysql php5-gd

Install Eclipse:

 # apt-get install eclipse

To install PHP Developer Tools in Eclipse: Open Eclipse, click Help -> Install New Software…

Work with: http://download.eclipse.org/tools/pdt/updates/release

Select PHP Development Tools / PHP Development Tools (PDT) and install.

Create a new PHP project in Eclipse.

Download PHPUnit into your project folder, e.g.:

 $ cd ~/workspace/new-project
 $ wget https://phar.phpunit.de/phpunit.phar
 $ chmod +x phpunit.phar
 $ cp phpunit.phar /usr/local/bin/phpunit

In your Eclipse PHP project right-click on your project and select “Include Path” -> “Configure Include Path”.

Click “Libraries” -> “Add External PHARs” then add “phpunit.phar” (in your project’s workspace).

In Eclipse click “Run” -> “Debug Configurations”. Click “PHP CLI Application” and then “New”. Enter the PHP Script name as “PHPUnit” with Project default PHP: PHP CLI (Xdebug 5.4.4 CLI). Set the PHP file as “/project-name/phpunit.phar”.

Edit your php.ini file, e.g.:

 # vim /etc/php5/cli/php.ini

And make sure to specify an xdebug configuration (append to end of file is OK):

[xdebug]
zend_extension=/usr/lib/php5/20100525/xdebug.so
xdebug.remote_enable=On
;xdebug.remote_host="localhost"
xdebug.remote_host=localhost
;xdebug.remote_port=9999
;xdebug.remote_port=9000
xdebug.remote_port=9999
xdebug.remote_handler="dbgp"
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/var/tmp"

xdebug.default_enable = on

xdebug.remote_autostart=on
xdebug.remote_mode = "req"
xdebug.remote_connect_back = on
xdebug.remove_log = /tmp/xdebug.log

Make sure you have a phpunit.xml file next to phpunit.phar in your workspace, e.g.:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
  backupStaticAttributes="false"
  syntaxCheck="false">
  <testsuites>
    <testsuite name="Tests">
       <directory suffix="Test.php">test</directory>
    </testsuite>
  </testsuites>
</phpunit>

Make sure there is one test in your test directory, e.g. /project-name/test/MyTest.php

<?php
class MyTest extends PHPUnit_Framework_TestCase {

  public function setUp() {
    //require_once( __DIR__ . '/../src/example.php' );
  }

  public function testExample() {
    $this->assertSame( '1', '1' );
  }
}

Double-click in the sidebar next to $this->assertSame to put a breakpoint there.

Then in Eclipse on the toolbar at the top is a little ‘bug’ icon, click ‘down’ next to that and debug ‘PHPUnit’.

Your unit tests should run in PHPUnit and break into the PHP debugger in Eclipse.

Did that work for you? Let me know!