Kohei Nozaki's blog 

Installing and Configuring jEdit 5.2pre1 on OS X


Posted on Friday Jan 30, 2015 at 10:59PM in Technology


Recently I installed jEdit 5.2pre1 to OS X 10.9 and got stucked in some problems so leave some notes. I’m using Japanese environment and front end processor so some situation may vary for each environment such as about option keys.

Force jEdit.app to use Java7

UPDATE: now jEdit 5.2.0 is released and it runs fine with Java8, so this workaround is no longer needed.

UPDATE2: I have some problems on jEdit 5.2.0 on Java8 such as keyboard tester or tab moving (dragging) so I recommend OS X users to use jEdit with Java7 at the moment.

First, jEdit 5.2pre1 requires Java7, and currently it doesn’t work with Java8 on OS X. the problem seems fixed in trunk though. so we need to run jEdit with Java7, but the mechanism named appbundle which used in jEdit.app, enables standalone Java application to run as OS X application, it uses Java8 unexpectedly on my environment. the cause seems to that it uses JRE installed under /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home as default. you better to check the version of JRE as follows:

kyle-no-MacBook:~ kyle$ /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
kyle-no-MacBook:~ kyle$

So, I need to force jEdit.app to use Java7. my solution is following:

  1. Create a directory named Plugins inside jEdit.app/Contents

    $ pwd
    /Applications/jEdit.app/Contents
    $ mkdir Plugins
  2. Create a symbolic link to JRE as follows:

    $ cd Plugins/
    $ ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk jdk7
    $ tree
    .
    └── jdk7 -> /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk
    
    1 directory, 0 files
  3. Put following definition to Info.plist:

    <key>JVMRuntime</key>
    <string>jdk7</string>

Also replacing the stub at /Applications/jEdit.app/Contents/MacOS/jEdit with alternative one would be an another solution.

Prevent blurry rendering in Retina Macs

  1. Put following definition to Info.plist:

    <key>NSHighResolutionCapable</key>
    <true/>
  2. Run following command:

    /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f /Applications/jEdit.app

Make CMD+ENTER work as show Action Bar

There are 2 solutions:

  • Use Metal theme instead of OS X theme

  • Delete CMD+ENTER from primary shortcut of Action Bar, then set it to alternative shortcut instead

The issue is filed but left open. anyway it mentioned more about the workaround so check it: jEdit / Bugs / #3863 Mac OS X L&F: problems with Action Bar

UPDATE

I’ve confirmed that CMD+ENTER is working as Show Action Bar on my environment (OS X theme, jEdit 5.3.0, Oracle JRE8u71 and OS X 10.11.3), BufferTabs tab replacing with mouse dragging as well.

Make Option key work

In OS X, option key is reserved for special symbols but I’ve never used option keys for such purpose, just want to use other purpose like binding a function as keyboard shortcut. so following procedure is needed:

  1. Put https://github.com/kenfox/intellij-emacs/blob/master/Coding.keylayout into $HOME/Library/Keyboard Layouts

  2. Register Coding keyboard layout which just downloaded at OS X’s System Preferences - Keyboard. this discussion may helps.

  3. Put a BeanShell script contains a line Debug.ALT_KEY_PRESSED_DISABLED = false; to $HOME/Library/jEdit/startup/startup.bsh

  4. Select Coding keymap in the icon which is placed upper right on OS X’s menu bar

  5. Test if option key works as expected in Utilities - Troubleshooting - Keyboard tester.

Some key mnemonic such as ones available in Search and Replace dialog will work with the combination of Option + Control + [mnemonic]. it not works with Option + [mnemonic]. for example you can toggle Regular expressions with Option + Control + x.

Notes about Mac OS X Support plugin

I disabled all of 4 functions of Mac OS X Support v1.3, but it’s still necessary because it handles quit event triggered by Cmd+Q. when I unloaded it then Cmd+Q stop asking whether I’m sure to quit with unsaved files.

Shell script for launching from CLI

Put this into your PATH as jedit.

#!/bin/sh
open -a /Applications/jEdit.app $@

If the one above doesn’t work, Try following instead:

#!/bin/sh
app_bundle=/Applications/jEdit.app
settings_dir=${HOME}/Library/jEdit
port_file=${settings_dir}/server

# Make sure that jEdit is running
if [ ! -f ${port_file} ]; then
    open -a jEdit
    while [ ! -f ${port_file} ]
    do
        sleep 1
    done
fi

# Pass the list of files to the running instance
$JAVA_HOME/bin/java \
    -jar ${app_bundle}/Contents/Java/jedit.jar \
    -nosplash \
    -reuseview \
    -settings="${settings_dir}" \
    "$@"

# Bring to front
open -a jEdit


Testing build.xml itself with AntUnit


Posted on Wednesday Jan 28, 2015 at 03:27PM in Technology


In my prevous entry I used AntUnit as a custom task unit testing framework. this time I’d try it for testing build.xml file itself (no custom tasks). it enables with antcallback task which is part of ant-contrib.

Test target is following. simply loads a properties file, then set a property named result which will be asserted in the caller (test case).

<project name="mybuild" basedir=".">

    <target name="main">
        <loadproperties srcFile="mybuild.properties"/>
        <property name="result" value="Hello from mybuild | ${file.var}"/>
    </target>

</project>

Test case is fairly simple as follows. it imports the test target and invoke a target with antcallback, then acquire a property in the calling target. then assert whether the property is set as expected. additionally, it puts a parameter named basedir to enable loading of mybuild.properties which is placed in the same directory to mybuild.xml.

<project name="mybuildTest" xmlns:au="antlib:org.apache.ant.antunit" xmlns="antlib:org.apache.tools.ant">

    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

    <import file="${project.build.outputDirectory}/mybuild.xml"/>

    <target name="setUp">
        <echo>setup</echo>
    </target>

    <target name="test1">
        <antcallback target="mybuild.main" return="result">
            <!-- intended to enable loading mybuild.properties -->
            <param name="basedir" value="${project.build.outputDirectory}"/>
        </antcallback>

        <au:assertTrue>
            <equals arg1="Hello from mybuild | Hello from mybuild.properties" arg2="${result}"/>
        </au:assertTrue>
    </target>

    <target name="tearDown">
        <echo>tearDown</echo>
    </target>
</project>

Entire the project is available in my GitHub repository. you can test it on your environment easily with mvn clean test because Maven collects all of dependencies.

References:


Running AntUnit in Maven


Posted on Tuesday Jan 27, 2015 at 11:11PM in Technology


These days I’m writing a build.xml and some custom tasks which manipulates OS X’s tmutil (Time Machine utility) and vmrun (VMware utility). testing of custom tasks are bit annoying to me, so I’ve had some googling around and I found AntUnit which is unit test framework for custom Ant tasks. it enables us to test custom tasks in more realistic way than plain JUnit testing. it actually runs the custom tasks in test case which wrote as build.xml. it looks little similar to JUnit test case as follows:

<project xmlns:au="antlib:org.apache.ant.antunit" xmlns="antlib:org.apache.tools.ant">
    <taskdef name="mytask" classname="org.nailedtothex.antunitpractice.MyTask">
        <classpath>
            <pathelement location="${project.build.outputDirectory}"/>
        </classpath>
    </taskdef>

    <target name="setUp">
        <echo>setup</echo>
    </target>

    <target name="test1">
        <mytask property="prop"/>
        <au:assertTrue>
            <equals arg1="Hello from MyTask" arg2="${prop}"/>
        </au:assertTrue>
    </target>

    <target name="tearDown">
        <echo>tearDown</echo>
    </target>
</project>

Targets that beginning their name with test will be automatically executed. we can do assertion with some elements (e.g. au:assertTrue) that provided by AntUnit. target named setUp will be executed before executing every test cases. tearDown also the same as JUnit.

The function of a custom task which I wrote is very simple. it simply set the constant string Hello from MyTask to specified property (prop).

package org.nailedtothex.antunitpractice;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

public class MyTask extends Task {

    private String property;

    public String getProperty() {
        return property;
    }

    public void setProperty(String property) {
        this.property = property;
    }

    @Override
    public void execute() throws BuildException {
        getProject().setNewProperty(property, "Hello from MyTask");
    }
}

So, how to run the test? I used Maven’s maven-antrun-plugin. it doesn’t need annoying preparation such as standalone installation of Ant and AntUnit because it collects annoying dependencies automatically. we only need to run mvn clean test as follows:

kyle-no-MacBook:antunitpractice kyle$ mvn clean test
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building antunitpractice 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ antunitpractice ---
[INFO] Deleting /Users/kyle/src/antunitpractice/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ antunitpractice ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ antunitpractice ---
[INFO] Compiling 1 source file to /Users/kyle/src/antunitpractice/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ antunitpractice ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ antunitpractice ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ antunitpractice ---
[INFO]
[INFO] --- maven-antrun-plugin:1.8:run (default-cli) @ antunitpractice ---
[INFO] Executing tasks

main:
[au:antunit] Build File: /Users/kyle/src/antunitpractice/target/test-classes/myTaskTest.xml
[au:antunit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.018 sec
[au:antunit] Target: test1 took 0.016 sec
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.413s
[INFO] Finished at: Wed Jan 28 09:38:19 JST 2015
[INFO] Final Memory: 16M/212M
[INFO] ------------------------------------------------------------------------

I haven’t apply this method to actual projects yet but looks useful for some occasions.

More information can be found via the official site of AntUnit. the entire project using in this entry can be found in my GitHub repository.


Registering PostgreSQL JDBC driver & datasource on WildFly


Posted on Monday Jan 26, 2015 at 07:35AM in Technology


Registering JDBC driver as a module:

module add \
 --name=org.postgresql \
 --resources=/tmp/postgresql-9.3-1102.jdbc41.jar \
 --resource-delimiter=, \
 --dependencies=javax.api,javax.transaction.api

Registering JDBC driver which is referencing a module:

/subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql, \
 driver-module-name=org.postgresql, \
 driver-class-name=org.postgresql.Driver, \
 driver-datasource-class-name=org.postgresql.ds.PGSimpleDataSource, \
 driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)

Registering datasource

data-source add \
 --name=MyDS \
 --driver-name=postgresql \
 --jndi-name=java:jboss/jdbc/MyDS \
 --user-name=wildfly \
 --password=**** \
 --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker \
 --exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter \
 --connection-url=jdbc:postgresql://localhost:5432/wildfly

Registering XA datasource

xa-data-source add \
 --name=MyDS \
 --driver-name=postgresql \
 --jndi-name=java:jboss/jdbc/MyDS \
 --user-name=wildfly \
 --password=****\
 --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker \
 --exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter \
 --xa-datasource-properties={ \
  "ServerName" => "localhost", \
  "PortNumber" => "5432", \
  "DatabaseName" => "wildfly"}

Testing connection:

/subsystem=datasources/xa-data-source=MyDS:test-connection-in-pool

References


Backup of a database server on VMware Fusion


Posted on Sunday Jan 25, 2015 at 06:05PM in Technology


There are some opinion about AutoProtect enables backup of a virtual machine with Time Machine, but I decided that I will backup my virtual machine as a regular file after shutdown. because there are some opinion that sometimes snapshots bring corruption of databases. they said that there’s possibility of occurrence of unsaved state during taking snapshots and I don’t want to corrupt my database.

But I don’t know what is difference between database servers and daily use computer? is there no possibility of serious corruption of something in daily use computers? has potentially snapshots some wrong design? is it unnecessary to force quiescing for daily use computer? doesn’t it bring crucial problems like data corruption on databases?

Googling with vmware snapshot database consistency gave me many interesting articles or discussions.

As to the procedure about backup after shutdown, following URL would be good to read:

How to mount Time Capsule from command line: