@@ -152,6 +152,27 @@ bool ValidateSyntax::CheckAllFiles(RtePackage* pKg)
152152 return (true );
153153}
154154
155+ bool ValidateSyntax::CheckLicenseFile (RteItem* item, const string& path) {
156+ bool bOk = false ;
157+ const auto lineNo = item->GetLineNumber ();
158+
159+ if (!path.empty ()) {
160+ if (XmlValueAdjuster::IsAbsolute (path)) {
161+ LogMsg (" M326" , PATH (path), lineNo); // error : absolute paths are not permitted
162+ }
163+ else if (path.find (' \\ ' ) != string::npos) {
164+ if (XmlValueAdjuster::IsURL (path)) {
165+ LogMsg (" M370" , URL (path), lineNo); // error : backslash are non permitted in URL
166+ }
167+ else {
168+ LogMsg (" M327" , PATH (path), lineNo); // error : backslash are not recommended
169+ }
170+ }
171+ }
172+
173+ return bOk;
174+ }
175+
155176/* *
156177 * @brief check (for) license file
157178 * @param pKg package under test
@@ -160,23 +181,82 @@ bool ValidateSyntax::CheckAllFiles(RtePackage* pKg)
160181 */
161182bool ValidateSyntax::CheckLicense (RtePackage* pKg, CheckFilesVisitor& fileVisitor)
162183{
184+ bool bLicFound = false ;
163185 const string& licPath = pKg->GetItemValue (" license" );
164- if (licPath.empty ()) {
165- return true ;
186+ if (!licPath.empty ()) {
187+ bLicFound = true ;
188+ CheckLicenseFile (pKg, licPath);
166189 }
167190
168- if (XmlValueAdjuster::IsAbsolute (licPath)) {
169- LogMsg (" M326" , PATH (licPath)); // error : absolute paths are not permitted
170- }
171- else if (licPath.find (' \\ ' ) != string::npos) {
172- if (XmlValueAdjuster::IsURL (licPath)) {
173- LogMsg (" M370" , URL (licPath)); // error : backslash are non permitted in URL
191+ const auto licenseSets = pKg->GetLicenseSets ();
192+ if (licenseSets) {
193+ const auto & children = licenseSets->GetChildren ();
194+ if (children.empty ()) {
195+ LogMsg (" M601" , TAG (" licenseSet" ), TAG2 (" licenseSets" )); // license set must be defined if <licenseSets>
174196 }
175- else {
176- LogMsg (" M327" , PATH (licPath)); // error : backslash are not recommended
197+
198+ map<string, RteItem*> licenseSetIds;
199+ RteItem* defaultLicenseSet = nullptr ;
200+
201+ for (const auto & child : children) {
202+ bLicFound = true ;
203+ const auto & id = child->GetID ();
204+ if (id.empty ()) {
205+ LogMsg (" M308" , TAG (" id" ), TAG2 (" licenseSet" )); // Attribute '%TAG%' missing on '%TAG2%'
206+ continue ;
207+ }
208+
209+ const auto & found = licenseSetIds.find (id);
210+ if (found != licenseSetIds.end ()) {
211+ const auto & foundId = found->first ;
212+ const auto foundChild = found->second ;
213+ LogMsg (" M367" , TYP (" id" ), NAME (foundId), LINE (foundChild->GetLineNumber ()), child->GetLineNumber ()); // Redefined %TYPE% '%NAME%' found, see Line %LINE%
214+ }
215+ else {
216+ licenseSetIds[id] = child;
217+ }
218+
219+ if (child->GetAttribute (" default" ) == " 1" ) {
220+ if (defaultLicenseSet) {
221+ LogMsg (" M602" , VAL (" ATTR" , " default" )); // Attribute '%ATTR%' already set, see Line %LINE%
222+ }
223+ else {
224+ defaultLicenseSet = child;
225+ }
226+ }
227+
228+ const auto & lincenseChilds = child->GetChildren ();
229+ if (lincenseChilds.empty ()) {
230+ LogMsg (" M601" , TAG (" license" ), TAG2 (" licenseSet" )); // '%TAG%' missing on '%TAG2%'
231+ }
232+ else {
233+ for (const auto lincenseChild : lincenseChilds) {
234+ const auto & licensePath = lincenseChild->GetAttribute (" name" );
235+ if (licensePath.empty ()) {
236+ LogMsg (" M601" , TAG (" name" ), TAG2 (" license" )); // '%TAG%' missing on '%TAG2%'
237+ }
238+ else {
239+ CheckLicenseFile (lincenseChild, licensePath);
240+ }
241+
242+ const auto & title = lincenseChild->GetAttribute (" title" );
243+ if (!title.length ()) {
244+ LogMsg (" M601" , TAG (" title" ), TAG2 (" license" )); // '%TAG%' missing on '%TAG2%'
245+ }
246+
247+ const auto & url = lincenseChild->GetAttribute (" url" );
248+ if (!url.empty ()) {
249+ CheckLicenseFile (lincenseChild, url);
250+ }
251+ }
252+ }
177253 }
178254 }
179255
256+ if (!bLicFound) {
257+ LogMsg (" M603" ); // no license information found
258+ }
259+
180260 CheckFiles& checkFiles = fileVisitor.GetCheckFiles ();
181261 if (!checkFiles.CheckFileExists (licPath, -1 )) {
182262 return false ;
0 commit comments