2017-04-25 13 views
0

Eclipse/OSGIソースバンドルからソースコードにアクセスするにはどうすればよいですか?EclipseソースバンドルからのJavaファイルへのアクセス

ソースフィーチャーパッケージを使用してソースバンドルを作成するには、Maven/Tychoを使用します。これは、サードパーティの開発のためのソースを添付するのに適しています。それらは「Javaソース添付ファイル」の「外部ロケーション」としてJAR上で参照されます。

しかし、プログラムでソースバンドルに到達するにはどうすればよいですか?ソースバンドルは通常のバンドルとしてアクセスできません。つまり、Platform.getBundle('com.myplugin.source')です。ソースファイルはマスターバンドルからアクセスできません。つまり、 'com.myplugin'プラグインマニフェストヘッダーにも参照はありません。私が使用すべきEclipse OSGIサービスはありますか?どんな助けもありがとう。

答えて

0

私が望んでいた解決策ではありませんでしたが、回避策としてソースバンドルのJARファイルに直接行くことができます。私はこれがOomphのような将来の証拠であるかどうかわからないので、より良い解決策があることを願っています。

String bloc = Platform.getBundle(bundlename).getLocation(); 
String location = bloc.replace(bundlename, bundlename+".source"); 
String path = new URL(location.replace("reference:", "")).getPath(); 

// Depending on installation type it may to prefix with Eclipse's installation path 
if(!new File(path).exists()) 
    path=Platform.getInstallLocation().getURL().getFile()+path; 

File srcbundle = new File(path); 
if(!srcbundle.exists()){ 
    Logger.IDE.severe("Source bundle '"+path+"' not found!"); 
    // When in runtime workbench we will get the source files from the bundle 
    for (URL url : Collections.list(bundle.findEntries("/", "*.*", true))) { 
     try(InputStream input = url.openStream()){ 
      outputFile(input, url.getFile()); 
     } 
    } 
} else { 
    // When plugin installation we will unzip the source bundle JAR. 
    try(JarFile jar=new JarFile(srcbundle)){ 
     for (JarEntry ze : Collections.list(jar.entries())) { 
      try(InputStream input = jar.getInputStream(ze)){ 
       outputFile(input, ze.getName()); 
      } 
     } 
    } 
} 
関連する問題