From 2eccd6b0e261eb52be6495c9a40224351b006a6d Mon Sep 17 00:00:00 2001 From: richc7 Date: Wed, 22 Apr 2015 17:25:43 -0600 Subject: [PATCH] Fix compatibility issue for Windows (Issue#1). Replace "which" command with "where" for Windows instances. Fixes https://github.com/chriseppstein/compass-validator/issues/1. "By default, the search is done along the current directory and in the paths specified by the PATH environment variable" (from "where" command-line help). In some cases, this fails to find a Java installation located on a different drive than the drive from which the validator is being called. To counter this, this code adds a second "where" call with the C:\ path hard-coded should the default search path(s) fail. This hard-coded path should eventually be converted to a configuration value to allow override. Tested successfully on Windows Server 2012 R2 Standard. --- lib/compass-validator.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/compass-validator.rb b/lib/compass-validator.rb index c8701f4..e9e2df9 100644 --- a/lib/compass-validator.rb +++ b/lib/compass-validator.rb @@ -1,5 +1,6 @@ # This file was extracted from the blueprint project and then modified. require "open3" +require "rbconfig" module Compass # Validates generated CSS against the W3 using Java @@ -28,7 +29,14 @@ def self.execute(*directories) # Validates all three CSS files def validate - java_path = `which java`.rstrip + if (!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)) + java_path = `which java`.rstrip + else + java_path = `where java`.rstrip + if (!java_path || java_path.empty?) + java_path = `WHERE /R C:\\ java`.rstrip + end + end raise "You do not have a Java installed, but it is required." unless java_path && !java_path.empty? Dir.glob(File.join(css_directory, "**", "*.css")).each do |file_name| @@ -87,4 +95,4 @@ def output_results end end end -end \ No newline at end of file +end