comparison graal/com.oracle.jvmci.options.processor/src/com/oracle/jvmci/options/processor/GraalJars.java @ 21562:47bebae7454f

Merge.
author Doug Simon <doug.simon@oracle.com>
date Thu, 28 May 2015 21:58:33 +0200
parents graal/com.oracle.graal.options.processor/src/com/oracle/graal/options/processor/GraalJars.java@28cbfacd0518
children
comparison
equal deleted inserted replaced
21561:ce2113326bc8 21562:47bebae7454f
1 /*
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.jvmci.options.processor;
24
25 import java.io.*;
26 import java.util.*;
27 import java.util.stream.*;
28 import java.util.zip.*;
29
30 public class GraalJars implements Iterable<ZipEntry> {
31 private final List<ZipFile> jars = new ArrayList<>(2);
32
33 public GraalJars() {
34 String classPath = System.getProperty("java.class.path");
35 for (String e : classPath.split(File.pathSeparator)) {
36 if (e.endsWith(File.separatorChar + "graal.jar") || e.endsWith(File.separatorChar + "graal-truffle.jar")) {
37 try {
38 jars.add(new ZipFile(e));
39 } catch (IOException ioe) {
40 throw new InternalError(ioe);
41 }
42 }
43 }
44 if (jars.size() != 2) {
45 throw new InternalError("Could not find graal.jar or graal-truffle.jar on class path: " + classPath);
46 }
47 }
48
49 public Iterator<ZipEntry> iterator() {
50 Stream<ZipEntry> entries = jars.stream().flatMap(ZipFile::stream);
51 return entries.iterator();
52 }
53
54 public InputStream getInputStream(String classFilePath) throws IOException {
55 for (ZipFile jar : jars) {
56 ZipEntry entry = jar.getEntry(classFilePath);
57 if (entry != null) {
58 return jar.getInputStream(entry);
59 }
60 }
61 return null;
62 }
63 }