comparison graal/com.oracle.graal.options.processor/src/com/oracle/graal/options/processor/GraalJars.java @ 21521:107300758a4e

remove hotspot.sourcegen
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Thu, 28 May 2015 16:54:14 +0200
parents
children 28cbfacd0518
comparison
equal deleted inserted replaced
21520:b7ac67354c14 21521:107300758a4e
1 package com.oracle.graal.options.processor;
2
3 import java.io.*;
4 import java.util.*;
5 import java.util.stream.*;
6 import java.util.zip.*;
7
8 /*
9 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
10 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
11 *
12 * This code is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 only, as
14 * published by the Free Software Foundation.
15 *
16 * This code is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * version 2 for more details (a copy is included in the LICENSE file that
20 * accompanied this code).
21 *
22 * You should have received a copy of the GNU General Public License version
23 * 2 along with this work; if not, write to the Free Software Foundation,
24 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25 *
26 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
27 * or visit www.oracle.com if you need additional information or have any
28 * questions.
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 }