2017-04-25 7 views
0

Eclipse/OSGI 소스 번들에서 소스 코드에 액세스하려면 어떻게합니까?Eclipse 소스 번들에서 java 파일에 액세스

소스 피처 패키징을 사용하여 Maven/Tycho를 사용하여 소스 번들을 생성합니다. 이는 타사 개발을위한 소스를 첨부하는 데 적합합니다. JAR에서 'Java 소스 첨부 파일'의 '외부 위치'로 참조됩니다.

그러나 어떻게 프로그래밍 방식으로 소스 번들에 도달합니까? 소스 번들은 일반 번들 (예 : 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()); 
      } 
     } 
    } 
}