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    /// The relative path to the JDrupes Builder directory from a 
030    /// project 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 string[]
039    ///
040    CommandLine commandLine();
041
042    /// Obtains the resource stream for the given resource 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    /// @param <T> the resource type
049    /// @param provider the provider
050    /// @param request the request
051    /// @return the results
052    ///
053    <T extends Resource> Stream<T> get(ResourceProvider provider,
054            ResourceRequest<T> request);
055
056    /// Return the value of the given property. Properties are defined by
057    /// (in order of precedence):
058    ///   1. command line options
059    ///   2. the file `.jdbld.properties` in the directory of the
060    ///      root project
061    ///   3. the file `.jdbld/jdbld.properties` in the user's home directory
062    ///
063    /// @param name the name
064    /// @return the string
065    ///
066    String property(String name);
067}