Class: Licenserec::CompatibilityCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/licensecompatibility.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCompatibilityCheck

Returns a new instance of CompatibilityCheck.



185
186
# File 'lib/licensecompatibility.rb', line 185

def initialize()
end

Class Method Details

.compatibilitycheck(repo_path, ninka_path) ⇒ Object

兼容性检查,输入1为项目路径,输入2为ninka路径,输出为“OK”,或项目种包含互不兼容许可证的提示信息的集合、对应文件路径的列表



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/licensecompatibility.rb', line 189

def self.compatibilitycheck(repo_path,ninka_path)
  file_licenses_hash,licenses_set = CompatibilityFilter.license_detection(repo_path,ninka_path)
  cur_path=String(Pathname.new(File.dirname(__FILE__)).realpath)
  c_table = CSV.read(cur_path+"\\compatibility_63.csv",headers:true)
  check_license_list = c_table["license"]
  conflict_copyleft_infoset = Set.new
  conflict_licenses = Set.new
  licenses_set.each do |licenseA|
    licenses_set.each do |licenseB|
      if (licenseA.include? " or ") == false
        iscompatibility = 0
        ischeck = 0
        if (licenseB.include? " or ") == false
          ischeck = 1
          compatibility_result_ab = CompatibilityFilter.compatibility_lookup(licenseA, licenseB)
          compatibility_result_ba = CompatibilityFilter.compatibility_lookup(licenseB, licenseA)
          if compatibility_result_ab != '0' or compatibility_result_ba != '0'
            iscompatibility = 1
          end
          if iscompatibility == 0 and ischeck == 1
            if (conflict_copyleft_infoset.include? licenseA+ "" + licenseB + "互不兼容。") == false and (conflict_copyleft_infoset.include? licenseB+ "" + licenseA + "互不兼容。") == false
              conflict_copyleft_infoset.add(licenseA + "" + licenseB + "互不兼容。")
              conflict_licenses.add(licenseA)
              conflict_licenses.add(licenseB)
            end
          end
        else
          licenseBs = licenseB.split(' or ')
          licenseBs.each do |lB|
            if check_license_list.include? lB
              ischeck = 1
              compatibility_result_ab = CompatibilityFilter.compatibility_lookup(licenseA, lB)
              compatibility_result_ba = CompatibilityFilter.compatibility_lookup(lB, licenseA)
              if compatibility_result_ab != '0' or compatibility_result_ba != '0'
                iscompatibility = 1
              end
            end
          end
          if iscompatibility == 0 and ischeck == 1
            if (conflict_copyleft_infoset.include? licenseA+ "" + licenseB + "互不兼容。") == false and (conflict_copyleft_infoset.include? licenseB+ "" + licenseA + "互不兼容。") == false
              conflict_copyleft_infoset.add(licenseA + "" + licenseB + "互不兼容。")
              conflict_licenses.add(licenseA)
              conflict_licenses.add(licenseB)
            end
          end
        end
      else
        iscompatibility = 0
        ischeck = 0
        licenseAs = licenseA.split(' or ')
        if (licenseB.include? " or ") == false
          licenseAs.each do |lA|
            if check_license_list.include? lA
              ischeck = 1
              compatibility_result_ab = CompatibilityFilter.compatibility_lookup(lA, licenseB)
              compatibility_result_ba = CompatibilityFilter.compatibility_lookup(licenseB, lA)
              if compatibility_result_ab != '0' or compatibility_result_ba != '0'
                iscompatibility = 1
                if iscompatibility == 0 and ischeck == 1
                  if (conflict_copyleft_infoset.include? licenseA+ "" + licenseB + "互不兼容。") == false and (conflict_copyleft_infoset.include? licenseB+ "" + licenseA + "互不兼容。") == false
                    conflict_copyleft_infoset.add(licenseA + "" + licenseB + "互不兼容。")
                    conflict_licenses.add(licenseA)
                    conflict_licenses.add(licenseB)
                  end
                end
              end
            end
          end
        else
          licenseBs = licenseB.split(' or ')
          licenseAs.each do |lA|
            licenseBs.each do |lB|
              if check_license_list.include? lA and check_license_list.include? lB
                ischeck = 1
                compatibility_result_ab = CompatibilityFilter.compatibility_lookup(lA, lB)
                compatibility_result_ba = CompatibilityFilter.compatibility_lookup(lB, lA)
                if compatibility_result_ab != '0' or compatibility_result_ba != '0'
                  iscompatibility = 1
                end
                if iscompatibility == 0 and ischeck == 1
                  if (conflict_copyleft_infoset.include? licenseA+ "" + licenseB + "互不兼容。") == false and (conflict_copyleft_infoset.include? licenseB+ "" + licenseA + "互不兼容。") == false
                    conflict_copyleft_infoset.add(licenseA + "" + licenseB + "互不兼容。")
                    conflict_licenses.add(licenseA)
                    conflict_licenses.add(licenseB)
                  end
                end
              end
            end
          end
        end
      end
    end
  end
  conflict_filepath = []
  if conflict_copyleft_infoset.nil?
    return "OK",nil
  else
    conflict_licenses.each do |one_license|
      file_licenses_hash.each do |file_path,file_license|
        if file_license == one_license
          conflict_filepath.push(file_path + "----------" + file_license)
        end
      end
    end
    return conflict_copyleft_infoset,conflict_filepath
  end
end