1 /*
   2  * Copyright (c) 2010, 2014, Oracle and/or its affiliates. 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 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 import java.io.File;
  24 import java.io.FileOutputStream;
  25 import java.io.IOException;
  26 import java.util.Map;
  27 import java.util.jar.JarFile;
  28 import java.util.jar.Pack200;
  29 /*
  30  * @test
  31  * @bug 7007157
  32  * @summary make sure the strip command works on an attribute
  33  * @compile -XDignore.symbol.file Utils.java T7007157.java
  34  * @run main T7007157
  35  * @author ksrini
  36  */
  37 public class T7007157 {
  38 
  39     public static void main(String... args) throws IOException {
  40         File sdkHome = Utils.JavaSDK;
  41         File testJar = new File("test.jar");
  42         Utils.jar("cvf", testJar.getName(), Utils.TEST_CLS_DIR.getAbsolutePath());
  43         JarFile jarFile = new JarFile(testJar);
  44         File packFile = new File("foo.pack");
  45         Pack200.Packer packer = Pack200.newPacker();
  46         Map<String, String> p = packer.properties();
  47         // Take the time optimization vs. space
  48         p.put(packer.EFFORT, "1");  // CAUTION: do not use 0.
  49         // Make the memory consumption as effective as possible
  50         p.put(packer.SEGMENT_LIMIT, "10000");
  51         // ignore all JAR deflation requests to save time
  52         p.put(packer.DEFLATE_HINT, packer.FALSE);
  53         // save the file ordering of the original JAR
  54         p.put(packer.KEEP_FILE_ORDER, packer.TRUE);
  55         // strip the StackMapTables
  56         p.put(packer.CODE_ATTRIBUTE_PFX + "StackMapTable", packer.STRIP);
  57         FileOutputStream fos = null;
  58         try {
  59             // Write out to a jtreg scratch area
  60             fos = new FileOutputStream(packFile);
  61             // Call the packer
  62             packer.pack(jarFile, fos);
  63         } finally {
  64             Utils.close(fos);
  65             Utils.close(jarFile);
  66         }
  67         Utils.cleanup();
  68     }
  69 }