1 /*
2 * Copyright (c) 2014, 2015, 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 */
143 String testSrc = System.getProperty("test.src");
144 return Files.list(Paths.get(testSrc))
145 .filter(p -> p.getFileName().toString().endsWith(".java"))
146 .collect(Collectors.toList());
147 }
148
149 private FileSystem zipfs;
150 private List<Path> zipPaths;
151
152 /**
153 * Returns a series of paths for artifacts in a non-default file system.
154 * A zip file is created containing copies of the .java files in the
155 * test.src directory. The paths that are returned refer to these files.
156 *
157 * @return a list of paths
158 * @throws IOException
159 */
160 List<Path> getTestZipPaths() throws IOException {
161 if (zipfs == null) {
162 Path testZip = createSourceZip();
163 zipfs = FileSystems.newFileSystem(testZip, null);
164 closeables.add(zipfs);
165 zipPaths = Files.list(zipfs.getRootDirectories().iterator().next())
166 .filter(p -> p.getFileName().toString().endsWith(".java"))
167 .collect(Collectors.toList());
168 }
169 return zipPaths;
170 }
171
172 /**
173 * Create a zip file containing the contents of the test.src directory.
174 *
175 * @return a path for the zip file.
176 * @throws IOException if there is a problem creating the file
177 */
178 private Path createSourceZip() throws IOException {
179 Path testSrc = Paths.get(System.getProperty("test.src"));
180 Path testZip = Paths.get("test.zip");
181 try (OutputStream os = Files.newOutputStream(testZip)) {
182 try (ZipOutputStream zos = new ZipOutputStream(os)) {
183 Files.list(testSrc)
|
1 /*
2 * Copyright (c) 2014, 2019, 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 */
143 String testSrc = System.getProperty("test.src");
144 return Files.list(Paths.get(testSrc))
145 .filter(p -> p.getFileName().toString().endsWith(".java"))
146 .collect(Collectors.toList());
147 }
148
149 private FileSystem zipfs;
150 private List<Path> zipPaths;
151
152 /**
153 * Returns a series of paths for artifacts in a non-default file system.
154 * A zip file is created containing copies of the .java files in the
155 * test.src directory. The paths that are returned refer to these files.
156 *
157 * @return a list of paths
158 * @throws IOException
159 */
160 List<Path> getTestZipPaths() throws IOException {
161 if (zipfs == null) {
162 Path testZip = createSourceZip();
163 zipfs = FileSystems.newFileSystem(testZip, (ClassLoader)null);
164 closeables.add(zipfs);
165 zipPaths = Files.list(zipfs.getRootDirectories().iterator().next())
166 .filter(p -> p.getFileName().toString().endsWith(".java"))
167 .collect(Collectors.toList());
168 }
169 return zipPaths;
170 }
171
172 /**
173 * Create a zip file containing the contents of the test.src directory.
174 *
175 * @return a path for the zip file.
176 * @throws IOException if there is a problem creating the file
177 */
178 private Path createSourceZip() throws IOException {
179 Path testSrc = Paths.get(System.getProperty("test.src"));
180 Path testZip = Paths.get("test.zip");
181 try (OutputStream os = Files.newOutputStream(testZip)) {
182 try (ZipOutputStream zos = new ZipOutputStream(os)) {
183 Files.list(testSrc)
|