Module: Albacore::Tasks::ProjectLint

Defined in:
lib/albacore/tasks/projectlint.rb

Overview

Project Lint is a task to check for simple errors in msbuild/project files

Defined Under Namespace

Classes: Config, FileReference

Class Method Summary collapse

Class Method Details

.new(*sym) {|c| ... } ⇒ Object

Yields:

  • (c)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/albacore/tasks/projectlint.rb', line 35

def self.new *sym
  c = Albacore::Tasks::ProjectLint::Config.new
  yield c if block_given?      
  
  body = proc {
    p = Project.new c.project
    ignores = c.ignores 
    ignores = [] if ignores == nil
    ignores += [/^bin/i, /^obj/, # bin, obj usually contain result of compilation
      /csproj$/, /fsproj$/, # project files should not be part of a project file 
      /\.user$/, /\.suo$/ # user settings, source control user settings 
    ]

    files = p.included_files.select { |file|
      file.link == nil
    }.map {|file| FileReference.new(file.include) } 
    srcfolder = File.dirname(c.project)
    fsfiles = nil
    FileUtils.cd (srcfolder) {
      fsfiles = Dir[File.join('**','*.*')].select { |file|
        ! ignores.any? { |r| file.match(r) }
      }.map { |file|
        FileReference.new(file)
      }
    }

    failure_msg = []
    (files-fsfiles).tap do |list|
      if (list.length>0)
        failure_msg.push("- Files in #{c.project} but not on filesystem: \n#{list}")
      end
    end
    (fsfiles-files).tap do |list|
      if (list.length>0)
        failure_msg.push("+ Files not in #{c.project} but on filesystem: \n#{list}")
      end
    end
    fail failure_msg.join("\n") if failure_msg.length>0
  }

  Albacore.define_task *sym, &body
end