001/*
002 * JDrupes Builder
003 * Copyright (C) 2025 Michael N. Lipp
004 * 
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
017 */
018
019package org.jdrupes.builder.api;
020
021import java.nio.file.Path;
022import java.util.stream.Stream;
023import org.apache.commons.cli.CommandLine;
024
025/// The context of a build.
026///
027public interface BuildContext {
028
029    /// Returns the relative path from a project directory to
030    /// the JDrupes Builder directory.
031    ///
032    /// @return the path
033    ///
034    Path jdbldDirectory();
035
036    /// The command line as processed by Apache Commons CLI.
037    ///
038    /// @return the parsed command line
039    ///
040    CommandLine commandLine();
041
042    /// Obtains the stream of resources of the given type from the
043    /// given provider. The result from invoking the provider is
044    /// evaluated asynchronously and cached. Only when the returned
045    /// stream is terminated will the invocation block until the
046    /// result from the provider becomes available.
047    /// 
048    /// To avoid duplicate invocations of a non-project provider,
049    /// any intends are removed from the request before such a
050    /// provider is invoked.
051    ///
052    /// @param <T> the resource type
053    /// @param provider the provider
054    /// @param request the request
055    /// @return the results
056    ///
057    <T extends Resource> Stream<T> resources(ResourceProvider provider,
058            ResourceRequest<T> request);
059
060    /// Returns the value of the given property. Properties are defined by
061    /// (in order of precedence):
062    ///   1. command line options
063    ///   2. the file `.jdbld.properties` in the directory of the
064    ///      root project
065    ///   3. the file `.jdbld/jdbld.properties` in the user's home directory
066    ///
067    /// @param name the name
068    /// @param defaultValue the default value
069    /// @return the string
070    ///
071    String property(String name, String defaultValue);
072}