1 /*
2 * Copyright (c) 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 */
23 package jdk.jpackage.test;
24
25 import java.io.FileOutputStream;
26 import java.io.IOException;
27 import java.io.PrintStream;
28 import java.lang.reflect.InvocationTargetException;
29 import java.nio.file.*;
30 import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
31 import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
32 import java.util.*;
33 import java.util.concurrent.TimeUnit;
34 import java.util.concurrent.atomic.AtomicInteger;
35 import java.util.function.BiPredicate;
36 import java.util.function.Consumer;
37 import java.util.function.Predicate;
38 import java.util.function.Supplier;
39 import java.util.stream.Collectors;
40 import java.util.stream.Stream;
41 import jdk.jpackage.test.Functional.ExceptionBox;
42 import jdk.jpackage.test.Functional.ThrowingConsumer;
43 import jdk.jpackage.test.Functional.ThrowingRunnable;
44 import jdk.jpackage.test.Functional.ThrowingSupplier;
45
159 // and test function name.
160 // Say the test name is `FooTest.testBasic`. Then app name would be `BasicFooTest`.
161 String appNamePrefix = currentTest.functionName();
162 if (appNamePrefix != null && appNamePrefix.startsWith("test")) {
163 appNamePrefix = appNamePrefix.substring("test".length());
164 }
165 return Stream.of(appNamePrefix, currentTest.baseName()).filter(
166 v -> v != null && !v.isEmpty()).collect(Collectors.joining());
167 }
168
169 public static boolean isWindows() {
170 return (OS.contains("win"));
171 }
172
173 public static boolean isOSX() {
174 return (OS.contains("mac"));
175 }
176
177 public static boolean isLinux() {
178 return ((OS.contains("nix") || OS.contains("nux")));
179 }
180
181 static void log(String v) {
182 System.out.println(v);
183 if (extraLogStream != null) {
184 extraLogStream.println(v);
185 }
186 }
187
188 public static void createTextFile(Path propsFilename, Collection<String> lines) {
189 createTextFile(propsFilename, lines.stream());
190 }
191
192 public static void createTextFile(Path propsFilename, Stream<String> lines) {
193 trace(String.format("Create [%s] text file...",
194 propsFilename.toAbsolutePath().normalize()));
195 ThrowingRunnable.toRunnable(() -> Files.write(propsFilename,
196 lines.peek(TKit::trace).collect(Collectors.toList()))).run();
197 trace("Done");
198 }
|
1 /*
2 * Copyright (c) 2019, 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.
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 package jdk.jpackage.test;
24
25 import java.io.BufferedReader;
26 import java.io.File;
27 import java.io.FileOutputStream;
28 import java.io.FileReader;
29 import java.io.IOException;
30 import java.io.PrintStream;
31 import java.lang.reflect.InvocationTargetException;
32 import java.nio.file.*;
33 import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
34 import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
35 import java.util.*;
36 import java.util.concurrent.TimeUnit;
37 import java.util.concurrent.atomic.AtomicInteger;
38 import java.util.function.BiPredicate;
39 import java.util.function.Consumer;
40 import java.util.function.Predicate;
41 import java.util.function.Supplier;
42 import java.util.stream.Collectors;
43 import java.util.stream.Stream;
44 import jdk.jpackage.test.Functional.ExceptionBox;
45 import jdk.jpackage.test.Functional.ThrowingConsumer;
46 import jdk.jpackage.test.Functional.ThrowingRunnable;
47 import jdk.jpackage.test.Functional.ThrowingSupplier;
48
162 // and test function name.
163 // Say the test name is `FooTest.testBasic`. Then app name would be `BasicFooTest`.
164 String appNamePrefix = currentTest.functionName();
165 if (appNamePrefix != null && appNamePrefix.startsWith("test")) {
166 appNamePrefix = appNamePrefix.substring("test".length());
167 }
168 return Stream.of(appNamePrefix, currentTest.baseName()).filter(
169 v -> v != null && !v.isEmpty()).collect(Collectors.joining());
170 }
171
172 public static boolean isWindows() {
173 return (OS.contains("win"));
174 }
175
176 public static boolean isOSX() {
177 return (OS.contains("mac"));
178 }
179
180 public static boolean isLinux() {
181 return ((OS.contains("nix") || OS.contains("nux")));
182 }
183
184 public static boolean isUbuntu() {
185 File releaseFile = new File("/etc/os-release");
186 if (releaseFile.exists()) {
187 try (BufferedReader lineReader = new BufferedReader(new FileReader(releaseFile))) {
188 String lineText = null;
189 while ((lineText = lineReader.readLine()) != null) {
190 if (lineText.indexOf("NAME=\"Ubuntu") != -1) {
191 lineReader.close();
192 return true;
193 }
194 }
195 } catch (IOException e) {
196 e.printStackTrace();
197 }
198 }
199 return false;
200 }
201
202 static void log(String v) {
203 System.out.println(v);
204 if (extraLogStream != null) {
205 extraLogStream.println(v);
206 }
207 }
208
209 public static void createTextFile(Path propsFilename, Collection<String> lines) {
210 createTextFile(propsFilename, lines.stream());
211 }
212
213 public static void createTextFile(Path propsFilename, Stream<String> lines) {
214 trace(String.format("Create [%s] text file...",
215 propsFilename.toAbsolutePath().normalize()));
216 ThrowingRunnable.toRunnable(() -> Files.write(propsFilename,
217 lines.peek(TKit::trace).collect(Collectors.toList()))).run();
218 trace("Done");
219 }
|