Commit bad4a70

mo khan <mo.khan@gmail.com>
2020-05-15 21:26:12
Enhance each dependency on a worker thread
1 parent e6f9eed
.github/licensed/bundler/strings-ansi.dep.yml
@@ -0,0 +1,34 @@
+---
+name: strings-ansi
+version: 0.1.0
+type: bundler
+summary: Methods for processing ANSI escape codes in strings.
+homepage: https://github.com/piotrmurach/strings
+license: mit
+licenses:
+- sources: LICENSE.txt
+  text: |
+    The MIT License (MIT)
+
+    Copyright (c) 2018 Piotr Murach
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+- sources: README.md
+  text: The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
+notices: []
.github/licensed/bundler/tty-cursor.dep.yml
@@ -0,0 +1,33 @@
+---
+name: tty-cursor
+version: 0.7.1
+type: bundler
+summary: Terminal cursor positioning, visibility and text manipulation.
+homepage: https://ttytoolkit.org
+license: mit
+licenses:
+- sources: LICENSE.txt
+  text: |
+    Copyright (c) 2015 Piotr Murach
+
+    MIT License
+
+    Permission is hereby granted, free of charge, to any person obtaining
+    a copy of this software and associated documentation files (the
+    "Software"), to deal in the Software without restriction, including
+    without limitation the rights to use, copy, modify, merge, publish,
+    distribute, sublicense, and/or sell copies of the Software, and to
+    permit persons to whom the Software is furnished to do so, subject to
+    the following conditions:
+
+    The above copyright notice and this permission notice shall be
+    included in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+notices: []
.github/licensed/bundler/tty-progressbar.dep.yml
@@ -0,0 +1,33 @@
+---
+name: tty-progressbar
+version: 0.17.0
+type: bundler
+summary: A flexible progress bars drawing in terminal emulators.
+homepage: https://piotrmurach.github.io/tty/
+license: mit
+licenses:
+- sources: LICENSE.txt
+  text: |
+    Copyright (c) 2014 Piotr Murach
+
+    MIT License
+
+    Permission is hereby granted, free of charge, to any person obtaining
+    a copy of this software and associated documentation files (the
+    "Software"), to deal in the Software without restriction, including
+    without limitation the rights to use, copy, modify, merge, publish,
+    distribute, sublicense, and/or sell copies of the Software, and to
+    permit persons to whom the Software is furnished to do so, subject to
+    the following conditions:
+
+    The above copyright notice and this permission notice shall be
+    included in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+notices: []
.github/licensed/bundler/tty-screen.dep.yml
@@ -0,0 +1,34 @@
+---
+name: tty-screen
+version: 0.7.1
+type: bundler
+summary: Terminal screen size detection which works on Linux, OS X and Windows/Cygwin
+  platforms and supports MRI, JRuby and Rubinius interpreters.
+homepage: https://ttytoolkit.org
+license: mit
+licenses:
+- sources: LICENSE.txt
+  text: |
+    Copyright (c) 2014 Piotr Murach
+
+    MIT License
+
+    Permission is hereby granted, free of charge, to any person obtaining
+    a copy of this software and associated documentation files (the
+    "Software"), to deal in the Software without restriction, including
+    without limitation the rights to use, copy, modify, merge, publish,
+    distribute, sublicense, and/or sell copies of the Software, and to
+    permit persons to whom the Software is furnished to do so, subject to
+    the following conditions:
+
+    The above copyright notice and this permission notice shall be
+    included in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+notices: []
.github/licensed/bundler/unicode-display_width.dep.yml
@@ -0,0 +1,33 @@
+---
+name: unicode-display_width
+version: 1.7.0
+type: bundler
+summary: Determines the monospace display width of a string in Ruby.
+homepage: https://github.com/janlelis/unicode-display_width
+license: mit
+licenses:
+- sources: MIT-LICENSE.txt
+  text: |
+    The MIT LICENSE
+
+    Copyright (c) 2011, 2015-2020 Jan Lelis
+
+    Permission is hereby granted, free of charge, to any person obtaining
+    a copy of this software and associated documentation files (the
+    "Software"), to deal in the Software without restriction, including
+    without limitation the rights to use, copy, modify, merge, publish,
+    distribute, sublicense, and/or sell copies of the Software, and to
+    permit persons to whom the Software is furnished to do so, subject to
+    the following conditions:
+
+    The above copyright notice and this permission notice shall be
+    included in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+notices: []
lib/spandx/cli/commands/scan.rb
@@ -34,18 +34,12 @@ module Spandx
           dependencies = ::Spandx::Core::Parser.for(file).parse(file)
           bar = TTY::ProgressBar.new("#{file} [:bar, :elapsed] :percent", total: dependencies.size)
           queue = Queue.new
-
-          Thread.new do
-            dependencies.each { |dependency| queue.enq(enhance(dependency)) }
-            queue.enq(:done)
+          dependencies.each do |dependency|
+            Spandx.thread_pool.schedule(dependency) { |item| queue.enq(enhance(item)) }
           end
-
-          loop do
-            item = queue.deq
-            break if item == :done
-
+          dependencies.size.times do
+            yield queue.deq
             bar.advance(1)
-            yield item
           end
         end
 
lib/spandx/core/data_file.rb
@@ -45,7 +45,7 @@ module Spandx
       end
 
       def open_file(mode: 'rb')
-        return unless absolute_path.exist?
+        return if mode == 'rb' && !absolute_path.exist?
 
         absolute_path.open(mode) { |io| yield io }
       rescue Errno::ENOENT => error