google / closure-compiler-npm

Package for managing and documenting closure-compiler for use via npm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Java doesn't seem be looked for in the path

sbc100 opened this issue · comments

The docs say "Requires java to be installed and in the path" but this doesn't seem to be true.

The code in getFirstSupportedPlatform seems to return true for java if its the last option or if one sets "JAVA_HOME".

function getFirstSupportedPlatform(platforms) {                                     
  const platform = platforms.find((platform, index) => {                            
    switch (platform.toLowerCase()) {                                               
      case "java":                                                                  
        if (index === platforms.length - 1) {                                       
          return true;                                                              
        }                                                                           
        return process.env.JAVA_HOME;                                               
                                                                                    
      case "javascript":                                                            
        return true;                                                                
                                                                                    
      case "native":                                                                
        if (getNativeImagePath()) {                                                                                           
          return true;                                                              
        }                                                                           
    }                                                                               
  });       

We noticed this because the we are having trouble the JS version on windows and the javascript version was being chosen despite java being the PATH and the code looks like it prefers that version:

platform = getFirstSupportedPlatform(['native', 'java', 'javascript'])

Sorry, java itself is looked for in PATH, but the 'java' platform will be ignore unless JAVA_HOME is set.

This is unfortunately by design. Looking for the existence of a java executable in every path folder is non-trivial and potentially performance impacting. It's also pretty easy to just hard code the platform needed to bypass this check.