jdk

Форк
0
/
JNativeScanTestBase.java 
86 строк · 3.1 Кб
1
/*
2
 * Copyright (c) 2024, 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

24
import java.io.IOException;
25
import java.io.PrintWriter;
26
import java.nio.file.Path;
27
import java.util.Arrays;
28

29
import java.io.StringWriter;
30
import java.util.spi.ToolProvider;
31

32
import jdk.test.lib.process.OutputAnalyzer;
33
import jdk.test.lib.util.JarUtils;
34

35
public class JNativeScanTestBase {
36

37
    public static final String MODULE_PATH = "mods";
38

39
    private static final ToolProvider JNATIVESCAN_TOOL = ToolProvider.findFirst("jnativescan")
40
            .orElseThrow(() -> new RuntimeException("jnativescan tool not found"));
41

42
    public static OutputAnalyzer jnativescan(String... args) {
43
        return run(JNATIVESCAN_TOOL, args);
44
    }
45

46
    private static OutputAnalyzer run(ToolProvider tp, String[] commands) {
47
        int rc;
48
        StringWriter sw = new StringWriter();
49
        StringWriter esw = new StringWriter();
50

51
        try (PrintWriter pw = new PrintWriter(sw);
52
             PrintWriter epw = new PrintWriter(esw)) {
53
            System.out.println("Running " + tp.name() + ", Command: " + Arrays.toString(commands));
54
            rc = tp.run(pw, epw, commands);
55
        }
56
        OutputAnalyzer output = new OutputAnalyzer(sw.toString(), esw.toString(), rc);
57
        output.outputTo(System.out);
58
        output.errorTo(System.err);
59
        return output;
60
    }
61

62
    public static Path makeModularJar(String moduleName) throws IOException {
63
        Path jarPath = Path.of(MODULE_PATH, moduleName + ".jar");
64
        Path moduleRoot = moduleRoot(moduleName);
65
        JarUtils.createJarFile(jarPath, moduleRoot);
66
        return jarPath;
67
    }
68

69
    public static Path moduleRoot(String name) {
70
        return Path.of(System.getProperty("test.module.path")).resolve(name);
71
    }
72

73
    public static OutputAnalyzer assertSuccess(OutputAnalyzer output) {
74
        if (output.getExitValue() != 0) {
75
            throw new IllegalStateException("tool run failed");
76
        }
77
        return output;
78
    }
79

80
    public static OutputAnalyzer assertFailure(OutputAnalyzer output) {
81
        if (output.getExitValue() == 0) {
82
            throw new IllegalStateException("tool run succeeded");
83
        }
84
        return output;
85
    }
86
}
87

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.