Created
January 13, 2010 22:07
-
-
Save alk/276620 to your computer and use it in GitHub Desktop.
Nice way to build IntelliJ IDEA's global libraries list from installed java packages on your Debian/Ubuntu system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # this script builds applicationLibraries.xml for IDEA from java | |
| # packages on your debian/ubuntu system | |
| # | |
| # This is public domain | |
| require 'rubygems' | |
| require 'activesupport' | |
| require 'erb' | |
| require 'pp' | |
| out = `dpkg -S /usr/share/java`.strip | |
| if out.empty? | |
| raise "No java libs?" | |
| end | |
| out = out.chomp(': /usr/share/java').strip | |
| if out.empty? | |
| raise "No java libs?" | |
| end | |
| packages = out.split(",").map(&:strip) | |
| package_jars = {} | |
| packages.each do |package| | |
| STDERR.puts "processing #{package}..." | |
| relevant_files = `dpkg -L #{package} | grep /usr/share/java`.split.map(&:chomp) | |
| real_relevant_files = relevant_files.select do |p| | |
| File.file?(p) && !File.symlink?(p) | |
| end | |
| next if real_relevant_files.empty? | |
| relevant_files.each do |path| | |
| next unless File.symlink?(path) | |
| target = File.expand_path(File.readlink(path), File.dirname(path)) | |
| if real_relevant_files.include?(target) | |
| real_relevant_files.delete target | |
| real_relevant_files << path | |
| end | |
| end | |
| info = package_jars[package] = { | |
| :package => package, | |
| :jars => real_relevant_files, | |
| } | |
| # now try to finding javadoc | |
| candidates = ["/usr/share/doc/#{package}/api", | |
| "/usr/share/doc/#{package}/doc/api", | |
| "/usr/share/doc/#{package}-doc/api", | |
| "/usr/share/doc/#{package}-doc/doc/api"] | |
| javadoc_path = candidates.detect(&File.method(:exists?)) | |
| unless javadoc_path | |
| STDERR.print "missing javadoc for #{package}: " | |
| # check if doc package exists / installed | |
| system "apt-cache show #{package}-doc >/dev/null 2>&1" | |
| if $?.exitstatus != 0 | |
| STDERR.puts "no javadoc package detected" | |
| else | |
| system "dpkg -L #{package}-doc >/dev/null 2>&1" | |
| if $?.exitstatus != 0 | |
| STDERR.puts "package #{package}-doc is not installed" | |
| else | |
| STDERR.puts "should be there, but failed to locate !" | |
| end | |
| end | |
| else | |
| info[:javadoc] = javadoc_path | |
| end | |
| end | |
| TEMPLATE = <<HERE | |
| <library name="<%= p[:package] %>"> | |
| <CLASSES> | |
| <% p[:jars].each do |path| -%> | |
| <root url="jar://<%= path %>!/" /> | |
| <% end -%> | |
| </CLASSES> | |
| <% if p[:javadoc] -%> | |
| <JAVADOC> | |
| <root url="file://<%= p[:javadoc] %>"/> | |
| </JAVADOC><% else -%> | |
| <JAVADOC /><% end -%><SOURCES /> | |
| </library> | |
| HERE | |
| print <<HERE | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <application> | |
| <component name="libraryTable"> | |
| HERE | |
| package_jars.values.each do |p| | |
| print ERB.new(TEMPLATE, 3, '-').result(binding) | |
| end | |
| print <<HERE | |
| </component> | |
| </application> | |
| HERE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment