1 /*
2 * Copyright (c) 2015, 2018, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
970 }
971
972 private void updateModularJar(Path target, Path tempTarget,
973 ModuleHashes moduleHashes)
974 throws IOException
975 {
976 try (JarFile jf = new JarFile(target.toFile());
977 OutputStream out = Files.newOutputStream(tempTarget);
978 JarOutputStream jos = new JarOutputStream(out))
979 {
980 jf.stream().forEach(e -> {
981 try (InputStream in = jf.getInputStream(e)) {
982 if (e.getName().equals(MODULE_INFO)) {
983 // what about module-info.class in versioned entries?
984 ZipEntry ze = new ZipEntry(e.getName());
985 ze.setTime(System.currentTimeMillis());
986 jos.putNextEntry(ze);
987 recordHashes(in, jos, moduleHashes);
988 jos.closeEntry();
989 } else {
990 jos.putNextEntry(e);
991 jos.write(in.readAllBytes());
992 jos.closeEntry();
993 }
994 } catch (IOException x) {
995 throw new UncheckedIOException(x);
996 }
997 });
998 }
999 }
1000
1001 private void updateJmodFile(Path target, Path tempTarget,
1002 ModuleHashes moduleHashes)
1003 throws IOException
1004 {
1005
1006 try (JmodFile jf = new JmodFile(target);
1007 JmodOutputStream jos = JmodOutputStream.newOutputStream(tempTarget))
1008 {
1009 jf.stream().forEach(e -> {
|
1 /*
2 * Copyright (c) 2015, 2020, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
970 }
971
972 private void updateModularJar(Path target, Path tempTarget,
973 ModuleHashes moduleHashes)
974 throws IOException
975 {
976 try (JarFile jf = new JarFile(target.toFile());
977 OutputStream out = Files.newOutputStream(tempTarget);
978 JarOutputStream jos = new JarOutputStream(out))
979 {
980 jf.stream().forEach(e -> {
981 try (InputStream in = jf.getInputStream(e)) {
982 if (e.getName().equals(MODULE_INFO)) {
983 // what about module-info.class in versioned entries?
984 ZipEntry ze = new ZipEntry(e.getName());
985 ze.setTime(System.currentTimeMillis());
986 jos.putNextEntry(ze);
987 recordHashes(in, jos, moduleHashes);
988 jos.closeEntry();
989 } else {
990 // Setting "compressedSize" to "-1" prevents an error
991 // in ZipOutputStream.closeEntry() if the newly
992 // deflated entry will have another size than the
993 // original compressed entry. See:
994 // ZipOutputStream.putNextEntry()/closeEntry()
995 e.setCompressedSize(-1);
996 jos.putNextEntry(e);
997 jos.write(in.readAllBytes());
998 jos.closeEntry();
999 }
1000 } catch (IOException x) {
1001 throw new UncheckedIOException(x);
1002 }
1003 });
1004 }
1005 }
1006
1007 private void updateJmodFile(Path target, Path tempTarget,
1008 ModuleHashes moduleHashes)
1009 throws IOException
1010 {
1011
1012 try (JmodFile jf = new JmodFile(target);
1013 JmodOutputStream jos = JmodOutputStream.newOutputStream(tempTarget))
1014 {
1015 jf.stream().forEach(e -> {
|