test/tools/javac/4241573/T4241573.java

changeset 882
3d45cc94ee0f
parent 554
9d9f26857129
child 1013
8eb952f43b11
equal deleted inserted replaced
881:4ce95dc0b908 882:3d45cc94ee0f
1 /* 1 /*
2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2009, 2011 Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
121 /** Create a directory containing one or more files. */ 121 /** Create a directory containing one or more files. */
122 File createDir(File dir, String... entries) throws Exception { 122 File createDir(File dir, String... entries) throws Exception {
123 if (!dir.mkdirs()) 123 if (!dir.mkdirs())
124 throw new Exception("cannot create directories " + dir); 124 throw new Exception("cannot create directories " + dir);
125 for (String e: entries) { 125 for (String e: entries) {
126 writeFile(new File(dir, getPathForEntry(e)), getBodyForEntry(e)); 126 writeFile(new File(dir, getPathForDirEntry(e)), getBodyForEntry(e));
127 } 127 }
128 return dir; 128 return dir;
129 } 129 }
130 130
131 /** Create a jar file containing one or more entries. */ 131 /** Create a jar file containing one or more entries. */
132 File createJar(File jar, String... entries) throws IOException { 132 File createJar(File jar, String... entries) throws IOException {
133 OutputStream out = new FileOutputStream(jar); 133 OutputStream out = new FileOutputStream(jar);
134 try { 134 try {
135 JarOutputStream jos = new JarOutputStream(out); 135 JarOutputStream jos = new JarOutputStream(out);
136 for (String e: entries) { 136 for (String e: entries) {
137 jos.putNextEntry(new JarEntry(getPathForEntry(e))); 137 jos.putNextEntry(new JarEntry(getPathForZipEntry(e)));
138 jos.write(getBodyForEntry(e).getBytes()); 138 jos.write(getBodyForEntry(e).getBytes());
139 } 139 }
140 jos.close(); 140 jos.close();
141 } finally { 141 } finally {
142 out.close(); 142 out.close();
143 } 143 }
144 return jar; 144 return jar;
145 } 145 }
146 146
147 /** Return the path for an entry given to createDir or createJar. */ 147 /** Return the path for an entry given to createDir */
148 String getPathForEntry(String e) { 148 String getPathForDirEntry(String e) {
149 return e.replace(".", File.separator) + ".java"; 149 return e.replace(".", File.separator) + ".java";
150 }
151
152 /** Return the path for an entry given to createJar. */
153 String getPathForZipEntry(String e) {
154 return e.replace(".", "/") + ".java";
150 } 155 }
151 156
152 /** Return the body text for an entry given to createDir or createJar. */ 157 /** Return the body text for an entry given to createDir or createJar. */
153 String getBodyForEntry(String e) { 158 String getBodyForEntry(String e) {
154 int sep = e.lastIndexOf("."); 159 int sep = e.lastIndexOf(".");

mercurial