2012-02-01 4 views
2

私がdev環境で動作していることを検出した場合、Karafの "dev:watch"コマンドを自動的に呼び出そうとしています。私はdev:watch *をetc/shell.init.scriptに直接追加することを検討しましたが、無条件で実行したくありません。だから、私はJavaプロパティ(単純なもの-Ddevelopment=trueのようなもの)をチェックし、org.apache.karaf.shell.dev.Watchそれ自身を呼び出す単純なサービスを作ることを検討しています。私はOSGiに(&(osgi.command.function=watch)(osgi.command.scope=dev))のFunctionインスタンスを求めることができると思うが、それを呼び出すためにmock CommandSessionを作成する必要がある。それはあまりにも複雑すぎるようです。より良いアプローチがありますか?Felix/Karafシェルコマンドをプログラム的に呼び出すにはどうすればよいですか?

答えて

0

質問よりしばらくお待ちしておりますが回答いたします。

CommandSessionクラスを使用する必要がありますが、それは簡単なことではありません。 This blog postが案内します。 Pax試験に関連していますが、どのような状況でも適用できます。リモートSSHクライアントを使用するか、リモートJXM管理コンソール(reference)を使用するなど、より多くの選択肢があります。

0

initスクリプトを使用して条件をテストし、その条件が満たされている場合はコマンドを実行して、コマンドセッションを自分で作成する必要はありません。

0

自体一つ回答明らかKaraf源:統合テストKaraf自体 に使用されるKarafTestSupportクラスで

を(https://git-wip-us.apache.org/repos/asf?p=karaf.git;a=blob;f=itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java;h=ebdea09ae8c6d926c8e4ac1fae6672f2c00a53dc;hb=HEAD参照)

関連方法が開始:

/** 
* Executes a shell command and returns output as a String. 
* Commands have a default timeout of 10 seconds. 
* 
* @param command The command to execute. 
* @param timeout The amount of time in millis to wait for the command to execute. 
* @param silent  Specifies if the command should be displayed in the screen. 
* @param principals The principals (e.g. RolePrincipal objects) to run the command under 
* @return 
*/ 
protected String executeCommand(final String command, final Long timeout, final Boolean silent, final Principal ... principals) { 
    waitForCommandService(command); 

    String response; 
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 
    final PrintStream printStream = new PrintStream(byteArrayOutputStream); 
    final SessionFactory sessionFactory = getOsgiService(SessionFactory.class); 
    final Session session = sessionFactory.create(System.in, printStream, System.err); 
    // 
    // 
    // 
    // Snip 
1

以来Apache Karaf 3.0.0ほとんどのコマンドは、OSGiサービスによってサポートされています。

たとえば、bundle:watchコマンドでサービス "org.apache.karaf.bundle.core.BundleWatcher"が使用されています。

このサービスをバインドするだけで、bundle:watch機能を非常に便利に呼び出すことができます。

関連する問題