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 24 /* 25 * @test 26 * @bug 4408526 6854795 27 * @modules jdk.jartool/sun.tools.jar 28 * @summary Index the non-meta files in META-INF, such as META-INF/services. 29 */ 30 31 import java.io.*; 32 import java.util.Arrays; 33 import java.util.jar.*; 34 import sun.tools.jar.Main; 35 import java.util.zip.ZipFile; 36 37 public class MetaInf { 38 39 static String jarName = "a.jar"; 40 static String INDEX = "META-INF/INDEX.LIST"; 41 static String SERVICES = "META-INF/services"; 42 static String contents = 43 System.getProperty("test.src") + File.separatorChar + "jarcontents"; 44 45 static void run(String ... args) { 46 if (! new Main(System.out, System.err, "jar").run(args)) 47 throw new Error("jar failed: args=" + Arrays.toString(args)); 48 } 49 50 static void copy(File from, File to) throws IOException { 51 FileInputStream in = new FileInputStream(from); 52 FileOutputStream out = new FileOutputStream(to); 53 try { 54 byte[] buf = new byte[8192]; 55 int n; 56 while ((n = in.read(buf)) != -1) 57 out.write(buf, 0, n); 58 } finally { 59 in.close(); 60 out.close(); 61 } 62 } 63 64 static boolean contains(File jarFile, String entryName) 65 throws IOException { 66 ZipFile zf = new ZipFile(jarFile); | 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 24 /* 25 * @test 26 * @bug 4408526 6854795 27 * @modules jdk.jartool 28 * @summary Index the non-meta files in META-INF, such as META-INF/services. 29 */ 30 31 import java.io.*; 32 import java.util.Arrays; 33 import java.util.jar.*; 34 import java.util.spi.ToolProvider; 35 import java.util.zip.ZipFile; 36 37 public class MetaInf { 38 static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar") 39 .orElseThrow(() -> 40 new RuntimeException("jar tool not found") 41 ); 42 43 static String jarName = "a.jar"; 44 static String INDEX = "META-INF/INDEX.LIST"; 45 static String SERVICES = "META-INF/services"; 46 static String contents = 47 System.getProperty("test.src") + File.separatorChar + "jarcontents"; 48 49 static void run(String ... args) { 50 if (JAR_TOOL.run(System.out, System.err, args) != 0) 51 throw new Error("jar failed: args=" + Arrays.toString(args)); 52 } 53 54 static void copy(File from, File to) throws IOException { 55 FileInputStream in = new FileInputStream(from); 56 FileOutputStream out = new FileOutputStream(to); 57 try { 58 byte[] buf = new byte[8192]; 59 int n; 60 while ((n = in.read(buf)) != -1) 61 out.write(buf, 0, n); 62 } finally { 63 in.close(); 64 out.close(); 65 } 66 } 67 68 static boolean contains(File jarFile, String entryName) 69 throws IOException { 70 ZipFile zf = new ZipFile(jarFile); |