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