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; 023 024/// The representation of a file tree. A file tree is a collection 025/// of [FileResource]s that are contained in a directory hierarchy 026/// with a common root. 027/// 028/// Implementations of this interface must provide a [ResourceFactory] 029/// that supports the invocation of [ResourceFactory#create] with 030/// arguments 031/// 032/// * [Project] the project 033/// * [Path] the root directory 034/// * [String] the pattern 035/// * `boolean` whether to include directories (optional, defaults to `false`) 036/// 037/// Implementations of this interface must ensure that the content 038/// of the file tree is not evaluated before a terminal operation 039/// is performed on the [Stream] returned by [#entries]. The delayed 040/// evaluation includes resolving a relative path for root against 041/// the project's directory. 042/// 043/// @param <T> the contained type 044/// 045public interface FileTree<T extends FileResource> extends Resources<T> { 046 047 /// Includes directories in the file tree. 048 /// 049 /// @return the file tree 050 /// 051 FileTree<T> withDirectories(); 052 053 /// Add a file name pattern to exclude from the tree. 054 /// 055 /// @param pattern the pattern 056 /// @return the file tree 057 /// 058 FileTree<T> exclude(String pattern); 059 060 /// Returns the root of the file tree containing the files. 061 /// 062 /// @param relativize whether to return a path relative to the project's 063 /// directory 064 /// @return the path 065 /// 066 Path root(boolean relativize); 067 068 /// Returns the root of the file tree searched for files 069 /// as an absolute path. 070 /// 071 /// @return the path 072 /// 073 default Path root() { 074 return root(false); 075 } 076 077 /// Returns the paths of the files in this file tree relative to 078 /// its root. 079 /// 080 /// @return the stream 081 /// 082 Stream<Path> entries(); 083 084 /// Re-scans the file tree for changes. 085 /// 086 /// @return the file tree 087 /// 088 @Override 089 FileTree<T> clear(); 090 091 /// Deletes all files in this file tree and directories that are 092 /// empty after deletion of the files (expect for root, which is 093 /// not deleted). 094 /// 095 /// @return the file tree 096 /// 097 FileTree<T> delete(); 098}