1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
19 # Cmd that finds the ini file related to an `mentity`
24 var ini
: nullable IniFile = null
26 redef fun init_command
do
28 if not res
isa CmdSuccess then return res
29 var mentity
= self.mentity
.as(not null)
31 if not mentity
isa MPackage then return new WarningNoIni(mentity
)
34 if ini
== null then return new WarningNoIni(mentity
)
42 # No ini file for `mentity`
49 redef fun to_s
do return "No ini file for `{mentity.full_name}`"
52 # Cmd that finds the ini description related to an `mentity`
53 class CmdIniDescription
57 var desc
: nullable String = null
59 redef fun init_command
do
61 if not res
isa CmdSuccess then return res
63 var mentity
= self.mentity
.as(not null)
64 var ini
= self.ini
.as(not null)
66 var desc
= ini
["package.desc"]
67 if desc
== null then return new WarningNoDescription(mentity
)
74 # No git clone url for `mentity`
75 class WarningNoDescription
81 redef fun to_s
do return "No description for `{mentity.full_name}`"
84 # Cmd that finds the clone url related to an `mentity`
89 var url
: nullable String = null
91 redef fun init_command
do
93 if not res
isa CmdSuccess then return res
95 var mentity
= self.mentity
.as(not null)
96 var ini
= self.ini
.as(not null)
98 var url
= ini
["upstream.git"]
99 if url
== null then return new WarningNoGitUrl(mentity
)
106 # No git url for `mentity`
107 class WarningNoGitUrl
113 redef fun to_s
do return "No git url for `{mentity.full_name}`"
116 # Cmd that finds the git clone command related to an `mentity`
117 class CmdIniCloneCommand
121 var command
: nullable String is lazy
do
123 if url
== null then return null
124 return "git clone {url}"
128 # Cmd that finds the issues link related to an `mentity`
129 class CmdIniIssuesUrl
133 var url
: nullable String = null
135 redef fun init_command
do
137 if not res
isa CmdSuccess then return res
139 var mentity
= self.mentity
.as(not null)
140 var ini
= self.ini
.as(not null)
142 var url
= ini
["upstream.issues"]
143 if url
== null then return new WarningNoIssuesUrl(mentity
)
150 # No issues url for `mentity`
151 class WarningNoIssuesUrl
157 redef fun to_s
do return "No issues url for `{mentity.full_name}`"
160 # Cmd that finds the maintainer name of an `mentity`
161 class CmdIniMaintainer
165 var maintainer
: nullable String = null
167 redef fun init_command
do
169 if not res
isa CmdSuccess then return res
171 var mentity
= self.mentity
.as(not null)
172 var ini
= self.ini
.as(not null)
174 var maintainer
= ini
["package.maintainer"]
175 if maintainer
== null then return new WarningNoMaintainer(mentity
)
176 self.maintainer
= maintainer
182 # No maintainer for `mentity`
183 class WarningNoMaintainer
189 redef fun to_s
do return "No maintainer for `{mentity.full_name}`"
192 # Cmd that finds the contributors list of an `mentity`
193 class CmdIniContributors
197 var contributors
: nullable Array[String] = null
199 redef fun init_command
do
201 if not res
isa CmdSuccess then return res
203 var mentity
= self.mentity
.as(not null)
204 var ini
= self.ini
.as(not null)
206 var names
= ini
["package.more_contributors"]
207 if names
== null then return new WarningNoContributor(mentity
)
209 var contributors
= new Array[String]
210 for name
in names
.split
(",") do
211 contributors
.add name
.trim
213 if contributors
.is_empty
then return new WarningNoContributor(mentity
)
214 self.contributors
= contributors
220 # No contributor for `mentity`
221 class WarningNoContributor
227 redef fun to_s
do return "No contributor for `{mentity.full_name}`"
230 # Cmd that finds the license related to an `mentity`
235 var license
: nullable String = null
237 redef fun init_command
do
239 if not res
isa CmdSuccess then return res
241 var mentity
= self.mentity
.as(not null)
242 var ini
= self.ini
.as(not null)
244 var license
= ini
["package.license"]
245 if license
== null then return new WarningNoLicense(mentity
)
246 self.license
= license
252 # No ini license string for `mentity`
253 class WarningNoLicense
259 redef fun to_s
do return "No license for `{mentity.full_name}`"
262 abstract class CmdEntityFile
266 var file
: nullable String = null is writable
268 # Accepted file names
269 fun file_names
: Array[String] is abstract
271 # Init file related data
272 fun init_file
: CmdMessage do
273 var mentity
= self.mentity
.as(not null)
275 var source_file
= mentity
.location
.file
276 if source_file
== null then return throw_warning
278 for file_name
in file_names
do
279 var file
= source_file
.filename
/ file_name
280 if not file
.file_exists
then continue
285 if file
== null then return throw_warning
287 return new CmdSuccess
290 redef fun init_command
do
292 if not res
isa CmdSuccess then return res
296 fun throw_warning
: CmdWarning is abstract
299 abstract class CmdEntityFileContent
303 var content
: nullable String = null is writable
305 redef fun init_file
do
307 if not res
isa CmdSuccess then return res
309 var file
= self.file
.as(not null)
310 content
= file
.to_path
.read_all
315 # Cmd that finds the license file related to an `mentity`
319 redef var file_names
= ["LICENSE", "LICENSE.md", "LICENSE.txt"]
320 redef fun throw_warning
do return new WarningNoLicenseFile(mentity
.as(not null))
323 # Cmd that finds the license file content related to an `mentity`
324 class CmdLicenseFileContent
325 super CmdEntityFileContent
329 # No license file for `mentity`
330 class WarningNoLicenseFile
336 redef fun to_s
do return "No license file for `{mentity.full_name}`"
339 # Cmd that finds the contributing file related to an `mentity`
343 redef var file_names
= ["CONTRIBUTING", "CONTRIBUTING.md", "CONTRIBUTING.txt"]
344 redef fun throw_warning
do return new WarningNoContribFile(mentity
.as(not null))
347 # Cmd that finds the contrib file content related to an `mentity`
348 class CmdContribFileContent
349 super CmdEntityFileContent
353 # No license file for `mentity`
354 class WarningNoContribFile
360 redef fun to_s
do return "No contributing file for `{mentity.full_name}`"