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 * published by the Free Software Foundation. Oracle designates this |
|
7 * particular file as subject to the "Classpath" exception as provided |
|
8 * by Oracle in the LICENSE file that accompanied this code. |
|
9 * |
|
10 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 * version 2 for more details (a copy is included in the LICENSE file that |
|
14 * accompanied this code). |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License version |
|
17 * 2 along with this work; if not, write to the Free Software Foundation, |
|
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 * |
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 * or visit www.oracle.com if you need additional information or have any |
|
22 * questions. |
|
23 */ |
|
24 |
|
25 package jdk.incubator.jpackage; |
|
26 |
|
27 import jdk.incubator.jpackage.internal.JPackageToolProvider; |
|
28 import java.io.PrintWriter; |
|
29 import java.util.Optional; |
|
30 import java.util.spi.ToolProvider; |
|
31 |
|
32 /** |
|
33 * A factory class to obtain a {@linkplain ToolProvider tool provider} |
|
34 * for the incubating {@code jpackage} tool. |
|
35 * |
|
36 * It is planned to implement {@code jpackage} tool as a service provider |
|
37 * to {@link ToolProvider} in a future release at which point |
|
38 * {@link ToolProvider#findFirst} can be used to look up jpackage tool. |
|
39 * |
|
40 * @since 14 |
|
41 */ |
|
42 |
|
43 public class ToolProviderFactory { |
|
44 |
|
45 private static ToolProvider provider = new JPackageToolProvider(); |
|
46 |
|
47 // Prevent creating an instance of this class |
|
48 private ToolProviderFactory() { |
|
49 } |
|
50 |
|
51 /** |
|
52 * Returns an {@link Optional} containing the {@code ToolProvider} |
|
53 * if the given toolname is "jpackage". Returns an empty |
|
54 * {@code Optional} if the given toolname is not "jpackage". |
|
55 * |
|
56 * @param toolname {@code String} name of tool to look for. |
|
57 * @return an {@link Optional} containing the {@code ToolPovider} |
|
58 * |
|
59 * @since 14 |
|
60 */ |
|
61 public static Optional<ToolProvider> findFirst(String toolName) { |
|
62 if ("jpackage".equals(toolName)) { |
|
63 return Optional.of(provider); |
|
64 } else { |
|
65 return Optional.empty(); |
|
66 } |
|
67 } |
|
68 |
|
69 } |
|