首页 文章

从Eclipse source-bundle访问java文件

提问于
浏览
0

如何从Eclipse / OSGI源包中访问源代码?

我使用Maven / Tycho使用source-feature包装生成源包 . 这适用于附加第三方开发的源 . 它们在JAR上被引用为“Java Source Attachement”的“外部位置” .

但是,我如何以编程方式访问源包?源包不能作为常规包访问,即 Platform.getBundle('com.myplugin.source') ,并且源文件无法通过主包访问,即'com.myplugin'插件清单头中也没有引用 . 是否有我应该使用的Eclipse OSGI服务?任何帮助,将不胜感激 .

1 回答

  • 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());
                }
            }
        }
    }
    

相关问题