1+ /*
2+ * Copyright 2014 original authors
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+ package grails.dev.commands.io
17+
18+ import org.grails.io.support.Resource
19+
20+
21+ /**
22+ * Utility methods exposed to scripts for interacting with resources (found on the file system or jars) and the file system
23+ *
24+ * @author Graeme Rocher
25+ * @since 3.0
26+ */
27+ interface FileSystemInteraction {
28+
29+ /**
30+ * Makes a directory
31+ *
32+ * @param path The path to the directory
33+ */
34+ FileSystemInteraction mkdir (path )
35+ /**
36+ * Deletes a file
37+ *
38+ * @param path The path to the file
39+ */
40+ FileSystemInteraction delete (path )
41+ /**
42+ * Allows Gradle style simple copy specs
43+ *
44+ * @param callable The callable
45+ * @return this
46+ */
47+ FileSystemInteraction copy (@DelegatesTo (CopySpec ) Closure callable )
48+ /**
49+ * Copies a resource to the target destination
50+ *
51+ * @param path The path
52+ * @param destination The destination
53+ */
54+ FileSystemInteraction copy (path , destination )
55+ /**
56+ * Copies resources to the target destination
57+ *
58+ * @param path The path
59+ * @param destination The destination
60+ */
61+ FileSystemInteraction copyAll (Iterable resources , destination )
62+ /**
63+ * Copy a Resource from the given location to the given directory or location
64+ *
65+ * @param from The resource to copy
66+ * @param to The location to copy to
67+ * @return The {@FileSystemInteraction} instance
68+ */
69+ FileSystemInteraction copy (Resource from , File to )
70+ /**
71+ * Obtain a file for the given path
72+ *
73+ * @param path The path
74+ * @return The file
75+ */
76+ File file (Object path )
77+ /**
78+ * @return The target build directory
79+ */
80+ File getBuildDir ()
81+ /**
82+ * @return The directory where resources are processed to
83+ */
84+ File getResourcesDir ()
85+ /**
86+ * @return The directory where classes are compiled to
87+ */
88+ File getClassesDir ()
89+ /**
90+ * Finds a source file for the given class name
91+ * @param className The class name
92+ * @return The source resource
93+ */
94+ Resource source (String className )
95+ /**
96+ * Obtain a resource for the given path
97+ * @param path The path
98+ * @return The resource
99+ */
100+ Resource resource (Object path )
101+ /**
102+ * Obtain resources for the given pattern
103+ *
104+ * @param pattern The pattern
105+ * @return The resources
106+ */
107+ Collection<Resource > resources (String pattern )
108+ /**
109+ * Obtain the path of the resource relative to the current project
110+ *
111+ * @param path The path to inspect
112+ * @return The relative path
113+ */
114+ String projectPath (Object path )
115+
116+ /**
117+ * The class name of the given resource
118+ *
119+ * @param resource The resource
120+ * @return The class name
121+ */
122+ String className (Resource resource )
123+
124+ /**
125+ * Get files matching the given pattern
126+ *
127+ * @param pattern The pattern
128+ * @return the files
129+ */
130+ Collection<File > files (String pattern )
131+
132+ static class CopySpec {
133+ def from
134+ def into
135+ void from (path ) {
136+ this . from = path
137+ }
138+ void into (path ) {
139+ this . into = path
140+ }
141+ }
142+ }
0 commit comments