J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * @test |
| 26 | * @bug 4408526 |
| 27 | * @summary Index the non-meta files in META-INF, such as META-INF/services. |
| 28 | */ |
| 29 | |
| 30 | import java.io.*; |
| 31 | import java.util.jar.*; |
| 32 | import sun.tools.jar.Main; |
| 33 | |
| 34 | public class MetaInf { |
| 35 | |
| 36 | static String jarName = "a.jar"; |
| 37 | static String INDEX = "META-INF/INDEX.LIST"; |
| 38 | static String SERVICES = "META-INF/services"; |
| 39 | static String contents = |
| 40 | System.getProperty("test.src") + File.separatorChar + "jarcontents"; |
| 41 | |
| 42 | // Options passed to "jar" command. |
| 43 | static String[] jarArgs1 = new String[] { |
| 44 | "cf", jarName, "-C", contents, SERVICES |
| 45 | }; |
| 46 | static String[] jarArgs2 = new String[] { |
| 47 | "i", jarName |
| 48 | }; |
| 49 | |
| 50 | public static void main(String[] args) throws IOException { |
| 51 | |
| 52 | // Create a jar to be indexed. |
| 53 | Main jarTool = new Main(System.out, System.err, "jar"); |
| 54 | if (!jarTool.run(jarArgs1)) { |
| 55 | throw new Error("Could not create jar file."); |
| 56 | } |
| 57 | |
| 58 | // Index the jar. |
| 59 | jarTool = new Main(System.out, System.err, "jar"); |
| 60 | if (!jarTool.run(jarArgs2)) { |
| 61 | throw new Error("Could not index jar file."); |
| 62 | } |
| 63 | |
| 64 | // Read the index. Verify that META-INF/services is indexed. |
| 65 | JarFile f = new JarFile(jarName); |
| 66 | BufferedReader index = |
| 67 | new BufferedReader( |
| 68 | new InputStreamReader( |
| 69 | f.getInputStream(f.getJarEntry(INDEX)))); |
| 70 | String line; |
| 71 | while ((line = index.readLine()) != null) { |
| 72 | if (line.equals(SERVICES)) { |
| 73 | return; |
| 74 | } |
| 75 | } |
| 76 | throw new Error(SERVICES + " not indexed."); |
| 77 | } |
| 78 | } |