Last active
December 19, 2015 15:39
-
-
Save pcarrier/5978022 to your computer and use it in GitHub Desktop.
This file contains 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
/* Outputs gem filenames from spec files. | |
* Full set of public gems: | |
* https://rubygems.org/specs.4.8 | |
* + https://rubygems.org/prerelease_specs.4.8 | |
*/ | |
import org.jruby.Ruby; | |
import org.jruby.RubyArray; | |
import org.jruby.RubyObject; | |
import org.jruby.runtime.marshal.UnmarshalStream; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class gemlist { | |
public static void main(String[] args) throws IOException { | |
final long l1 = System.currentTimeMillis(); | |
final File file = new File(args[0]); | |
final FileInputStream fileInputStream = new FileInputStream(file); | |
final Ruby ruby = Ruby.newInstance(); | |
ruby.evalScriptlet("module Gem; class Version; def marshal_load array; @version = array[0]; end; end; end"); | |
final UnmarshalStream stream = new UnmarshalStream(ruby, fileInputStream, null, false); | |
final RubyArray array = stream.unmarshalObject().convertToArray(); | |
final List<String> filenames = new ArrayList<String>(); | |
for (Object o : array) { | |
RubyArray arr = ((RubyObject) o).convertToArray(); | |
final String name = arr.get(0).toString(); | |
final String version = ((RubyObject) arr.get(1)).getInstanceVariable("@version").toString(); | |
final String platform = arr.get(2).toString(); | |
final StringBuilder builder = new StringBuilder(name); | |
builder.append('-'); | |
builder.append(version); | |
if (!"ruby".equals(platform)) { | |
builder.append('-'); | |
builder.append(platform); | |
} | |
builder.append(".gem"); | |
filenames.add(builder.toString()); | |
} | |
final long l2 = System.currentTimeMillis(); | |
for (String filename : filenames) { | |
System.out.println(filename); | |
} | |
System.err.println(filenames.size()); | |
System.err.println((l2 - l1) + "ms"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment