Apr 032012
 

UNIX에서 vi의 syntax 기능을 사용했던 개발자라면 syntax highlight 기능을 잘 알것입니다.

최근에 블로그에서도 웹기반의 소스를 아래와 같이 이쁘게 나오게 합니다.
(아래는 WP-Syntax라는 GeSHi 기반의 WordPress 플러그인입니다.)

<html>
 <head>
  <title>title</title>
 </head>

이것을 가능하게 하는 것이 GeSHi 라는 PHP 기반의 오픈소스가 있습니다.

http://qbnz.com/highlighter/

저도 제 블로그 사이트에 아래 링크로 샘플 사이트를 연결해 두었습니다.

http://blog.sukmoonlee.com/geshi/contrib/example.php

소스를 받아서 샘플 파일을 보시면 PHP 개발자라면 금방 사용할수 있으므로 참고하시면 좋습니다.

Apr 032012
 

SVN을 사용하면 hook script를 이용해서 다양한 기능을 할수 있다.
특히 commit을 하고 나면 해당 내용을 같은 팀원들이 공유를 하고, 서로 코드를 리뷰를 해주면 더욱 좋다.

SVN에 기본적으로 포함되어 있는 post-commit 스크립트와 mailer.py를 사용하면 보내면 text/plain 형태로 전달이 되기 때문에 가독성이 떨어진다. 이것을 text/html로 보내면서 문법까지 쉽게 확인하면 좋을것 같다는 생각을 가지고 소스를 약간 수정했다.

일단 아래와 같이 post-commit.tmpl 파일을 복사해서 아래와 같이 만든다.

$ diff post-commit.tmpl post-commit
50c50
&lt; mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf
---
&gt; /home/svn/mailer.py commit "$REPOS" $REV /home/svn/mailer.conf

그리고 svn을 설치된 경로에 가보면 아래와 같이 mailer.py와 mailer.conf 파일이 있다.
(리눅스 CentOS 6의 경우에는 아래의 경로에 있다.)

[smlee@nams2 mailer]$ rpm -ql subversion |grep mailer
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer
<strong>/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/mailer.conf.example /usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/mailer.py</strong>
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer-init.sh
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer-t1.output
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer-t1.sh
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer-tweak.py
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer.conf

해당 파일은 적당한 디렉토리(/home/svn) 에 복사해서 만들면 된다.
대부분 mailer.conf를 자신이 사용하는 메일서버(구글서버로 설정하면 편리합니다.)와 수신자와 발신자를 설정하면 된다.(대부분 commit을 한 author를 중심으로 설정하면 된다.)

여기서 제가 추가적으로 수정한 부분은 다음과 같습니다. 기존에 OS에서 가지고 있는 diff를 사용을 하면 text형태로만 제공이 됩니다.

144c144,145
&lt; diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s --- &gt; #diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s
&gt; diff = /home/svn/diff.sh %(label_from)s %(label_to)s %(from)s %(to)s

syntax highlight를 사용하기 위해서 GeSHi 프로그램을 사용하기 위해서 간단한 shell을 하나 만들어서 php 프로그램을 실행하도록 했습니다.

# cat diff.sh
#!/bin/sh
 
TMP="$4.diff"
 
/usr/bin/diff -u -L '$1' -L '$2' $3 $4 &gt; $TMP
php /home/bin/svn_geshi.php $TMP "$1" "$2"
rm -f $TMP

보는 것과 같이 기존의 diff 결과를 파일로 저장하고, 저장된 파일을 geshi에 들어있는 샘플 파일을 이용해서 출력을 하면 된다.
이렇게 하면 mailer.py 에서 해당 결과를 읽어서 메일로 전달하게 되는 구조이다.

다만 기존의 mailer.py는 text/plain 형태의 메일을 보내는 것을 text/html로 변경하고, 출력되는 문구에 HTML이 가능하도록 수정하면 된다. 나는 geshi에 있는 샘플 파일의 HTML 형식을 사용했다.

소스는 지금도 수정중이고, mailer.conf 파일의 활용법을 계속 연습중이라서 나중에 공개하도록 하겠다.

 

 

Apr 032012
 

SVN서버를 사용할때 오래된 OS(redhat 7.3)에는 설치하기가 힘듭니다. OS가 maintaince 기간이 만료되었기 때문에 rpm 구하기가 힘듭니다.

yum 도 사용하기 힘들기 때문에 소스를 컴파일해서 설치해서 사용해야 합니다.

설치를 하다 보면 APR(Apache Portable Runtime) 패키지가 없어서 아래와 같이 컴파일 에러가 납니다.

[root@guide1 subversion-1.7.4]# ./configure
configure: Configuring Subversion 1.7.4
configure: creating config.nice
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C preprocessor... gcc -E
checking for a sed that does not truncate output... /bin/sed
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking whether ln -s works... yes
checking for a BSD-compatible install... /usr/bin/install -c
configure: Apache Portable Runtime (APR) library configuration
checking for APR... no
configure: WARNING: APR not found
The Apache Portable Runtime (APR) library cannot be found.
Please install APR on this system and supply the appropriate
--with-apr option to 'configure'

or

get it with SVN and put it in a subdirectory of this source:

svn co \
http://svn.apache.org/repos/asf/apr/apr/branches/1.3.x \
apr

Run that right here in the top level of the Subversion tree.
Afterwards, run apr/buildconf in that subdirectory and
then run configure again here.

Whichever of the above you do, you probably need to do
something similar for apr-util, either providing both
--with-apr and --with-apr-util to 'configure', or
getting both from SVN with:

svn co \
http://svn.apache.org/repos/asf/apr/apr-util/branches/1.3.x \
apr-util

configure: error: no suitable apr found
[root@guide1 subversion-1.7.4]#

이런 문제를 해결하기 위해서는 최신 버전이 아닌 1.3.x 버전을 사용하면 해결이 가능합니다.

아래의 경로에서 다운로드 가능합니다.

http://archive.apache.org/dist/subversion/subversion-1.3.2.tar.gz

[root@guide1 root]# cat /etc/redhat-release
Red Hat Linux release 7.3 (Valhalla)
[root@guide1 root]# svn --version
svn, version 1.3.2 (r19776)
compiled Apr 3 2012, 15:09:18

Copyright (C) 2000-2006 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_dav : Module for accessing a repository via WebDAV (DeltaV) protocol.
- handles 'http' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
- handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
- handles 'file' scheme

참고사이트 : http://svn.haxx.se/users/archive-2006-06/0713.shtml

Apr 032012
 

리눅스에서 Eclipse와 OpenJDK 1.6 으로 개발한 Executive jar 실행 파일을 Sparc Solaris 10에 들어 있는 Sun의 JDK 1.5 환경에서 실행을 하면 아래와 같은 에러가 발생합니다.

bash-3.00# java -jar StatAgent.jar
Exception in thread “main” java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

당연히 될꺼라고 생각했지만, 컴파일 환경과 실행환경이 중요하더군요.

그래서 Eclipse에서 아래와 같이 설정이 가능합니다.
이렇게 하니깐 JDK 1.6 과 JDK 1.5 환경에서 모두 잘 작동합니다.

Plugin from the creators of Brindes :: More at Plulz Wordpress Plugins