src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/ToolProviderFactory.java
author herrick
Fri, 08 Nov 2019 14:53:03 -0500
branchJDK-8200758-branch
changeset 58994 b09ba68c6a19
permissions -rw-r--r--
8233636 : Make jpackage an incubator and remove tool provider implementation Reviewed-by: asemenyuk, almatvee, kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58994
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
     1
/*
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
     4
 *
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
     9
 *
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    14
 * accompanied this code).
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    15
 *
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    19
 *
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    22
 * questions.
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    23
 */
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    24
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    25
package jdk.incubator.jpackage;
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    26
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    27
import jdk.incubator.jpackage.internal.JPackageToolProvider;
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    28
import java.io.PrintWriter;
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    29
import java.util.Optional;
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    30
import java.util.spi.ToolProvider;
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    31
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    32
/**
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    33
 * A factory class to obtain a {@linkplain ToolProvider tool provider}
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    34
 * for the incubating {@code jpackage} tool.
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    35
 * 
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    36
 * It is planned to implement {@code jpackage} tool as a service provider
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    37
 * to {@link ToolProvider} in a future release at which point
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    38
 * {@link ToolProvider#findFirst} can be used to look up jpackage tool.
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    39
 *
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    40
 * @since   14
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    41
 */
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    42
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    43
public class ToolProviderFactory { 
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    44
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    45
    private static ToolProvider provider = new JPackageToolProvider();
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    46
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    47
    // Prevent creating an instance of this class
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    48
    private ToolProviderFactory() {
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    49
    }
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    50
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    51
    /**
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    52
     * Returns an {@link Optional} containing the {@code ToolProvider}
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    53
     * if the given toolname is "jpackage". Returns an empty
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    54
     * {@code Optional} if the given toolname is not "jpackage".
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    55
     *
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    56
     * @param   toolname {@code String} name of tool to look for.
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    57
     * @return  an {@link Optional} containing the {@code ToolPovider}
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    58
     *
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    59
     * @since 14
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    60
     */
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    61
    public static Optional<ToolProvider> findFirst(String toolName) {
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    62
        if ("jpackage".equals(toolName)) {
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    63
            return Optional.of(provider);
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    64
        } else {
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    65
            return Optional.empty();
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    66
        }
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    67
    } 
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    68
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
diff changeset
    69
}