ログ

実際に JVM の起動をおこなう前に、ログでも出力できるようにしてみます。

同じように Tomcat Plug-in を参考にして。

どうやら、Plugin クラスには getLog メソッドというものがあって、ILog インタフェースのオブジェクトがとれるらしいです。なので、WrpePlugin クラスに log メソッドをこんな風に作ってみました。

        public static void log(String msg) {
            ILog log = WrpePlugin.getDefault().getLog();
            Status status = new Status(IStatus.INFO,
                                       WrpePlugin.getDefault().getDescriptor().getUniqueIdentifier(),
                                       IStatus.INFO, msg, null);
            log.log(status);
        }
	
        public static void log(Throwable ex) {
            ILog log = WrpePlugin.getDefault().getLog();
            Status status = new Status(IStatus.ERROR,
                                       WrpePlugin.getDefault().getDescriptor().getUniqueIdentifier(),
                                       IStatus.ERROR, "", exception);
            log.log(status);
        }

そうしたらですね、いきなり getDescriptior メソッドと getUniqueIdentifier メソッドに訂正線が引かれちゃったんですよ。なんだかよく分からないのですが、これは Deprecated のしるしらしいのです。

こっちは他の人のコードを参考にして書いただけなのに、それが使えないなんて...

Plugin クラスの Javadoc を見ると、

public final IPluginDescriptor getDescriptor()

Deprecated. IPluginDescriptor was refactored in Eclipse 3.0. The getDescriptor() method may only be called by plug-ins which explicitly require the org.eclipse.core.runtime.compatibility plug-in. See the comments on IPluginDescriptor and its methods for details.

なのだそうなので、IPluginDescriptor インタフェースを見たわけです。そうしたら、IPluginDescriptor インタフェース自体が Deprecated なんですね。

IPluginDescriptor#getUniqueIdentifier メソッドは bundle.getSymbolicName メソッドを使えと書いてあります。bundle って何だ? IPluginDescriptor インタフェースの Javadoc の上の方を読んでいたら分かりましたが、それだったらこんな変数名みたいなものを使わずに Bundle#getSymbolicName と書いてくれればいいのに。

と、こんなところで怒っていてもしょうがないので、getSymbolicName を使って書きかえてみました。

        public static void log(String msg) {
            ILog log = WrpePlugin.getDefault().getLog();
            Status status = new Status(IStatus.INFO, 
                                   WrpePlugin.getDefault().getBundle().getSymbolicName(),
                                   IStatus.INFO, msg, null);
            log.log(status);
        }

いちおう WrpePlugin.getDefault().getBundle().getSymbolicName() の戻り値の文字列と、WrpePlugin.getDefault().getDescriptor().getUniqueIdentifier() の戻り値の文字列を比較して同じであることは確認してあります。

ちななみに出力された文字列は jp.gr.java_conf.skrb.lg3d.wrpe でした。