001package org.apache.maven.toolchain.io;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.File;
023import java.io.IOException;
024import java.io.InputStream;
025import java.io.Reader;
026import java.util.Map;
027
028import org.apache.maven.toolchain.model.PersistedToolchains;
029
030/**
031 * Handles deserialization of toolchains from some kind of textual format like XML.
032 *
033 * @author Robert Scholte
034 * @since 3.3.0
035 */
036public interface ToolchainsReader
037{
038
039    /**
040     * The key for the option to enable strict parsing. This option is of type {@link Boolean} and defaults to {@code
041     * true}. If {@code false}, unknown elements will be ignored instead of causing a failure.
042     */
043    String IS_STRICT = "org.apache.maven.toolchains.io.isStrict";
044
045    /**
046     * Reads the toolchains from the specified file.
047     *
048     * @param input The file to deserialize the toolchains from, must not be {@code null}.
049     * @param options The options to use for deserialization, may be {@code null} to use the default values.
050     * @return The deserialized toolchains, never {@code null}.
051     * @throws IOException If the toolchains could not be deserialized.
052     * @throws ToolchainsParseException If the input format could not be parsed.
053     */
054    PersistedToolchains read( File input, Map<String, ?> options )
055        throws IOException, ToolchainsParseException;
056
057    /**
058     * Reads the toolchains from the specified character reader. The reader will be automatically closed before the
059     * method returns.
060     *
061     * @param input The reader to deserialize the toolchains from, must not be {@code null}.
062     * @param options The options to use for deserialization, may be {@code null} to use the default values.
063     * @return The deserialized toolchains, never {@code null}.
064     * @throws IOException If the toolchains could not be deserialized.
065     * @throws ToolchainsParseException If the input format could not be parsed.
066     */
067    PersistedToolchains read( Reader input, Map<String, ?> options )
068        throws IOException, ToolchainsParseException;
069
070    /**
071     * Reads the toolchains from the specified byte stream. The stream will be automatically closed before the method
072     * returns.
073     *
074     * @param input The stream to deserialize the toolchains from, must not be {@code null}.
075     * @param options The options to use for deserialization, may be {@code null} to use the default values.
076     * @return The deserialized toolchains, never {@code null}.
077     * @throws IOException If the toolchains could not be deserialized.
078     * @throws ToolchainsParseException If the input format could not be parsed.
079     */
080    PersistedToolchains read( InputStream input, Map<String, ?> options )
081        throws IOException, ToolchainsParseException;
082
083}