import { Uri , workspace } from "vscode" ; export namespace Settings { export function excludedFolders ( resource ) { const ret = _getMavenSection < string [ ] > ( "excludedFolders" , resource ) ; return ret !== undefined ? ret : [ ] ; } export function showInExplorerContextMenu ( ) { return ! ! _getMavenSection < boolean > ( "maven.showInExplorerContextMenu" ) ; } export function enableConflictDiagnostics ( ) { return ! ! _getMavenSection < boolean > ( "dependency.enableConflictDiagnostics" ) ; } export function viewType ( ) { return _getMavenSection ( "view" ) ; } export function changeToFlatView ( ) { workspace . getConfiguration ( ) . update ( "maven.view" , "flat" , false ) ; } export function changeToHierarchicalView ( ) { workspace . getConfiguration ( ) . update ( "maven.view" , "hierarchical" , false ) ; } export function setMavenExecutablePath ( mvnPath ) { workspace . getConfiguration ( ) . update ( "maven.executable.path" , mvnPath , true ) ; } export function getSettingsFilePath ( ) { return _getMavenSection < string > ( "settingsFile" ) ; } export namespace External { export function javaHome ( ) { return workspace . getConfiguration ( "java" ) . get < string > ( "home" ) ; } export function defaultWindowsShell ( ) { return workspace . getConfiguration ( "terminal" ) . get < string > ( "integrated.shell.windows" ) ; } } export namespace Terminal { export function useJavaHome ( ) { return ! ! _getMavenSection < boolean > ( "terminal.useJavaHome" ) ; } export function customEnv ( resourceOrFilepath ? ) { return _getMavenSection ( "terminal.customEnv" , resourceOrFilepath ) ; } export function favorites ( resource ) { return _getMavenSection ( "terminal.favorites" , resource ) ; } } export namespace Executable { export function path ( resourceOrFilepath ? ) { return _getMavenSection ( "executable.path" , resourceOrFilepath ) ; } export function options ( resourceOrFilepath ? ) { return _getMavenSection ( "executable.options" , resourceOrFilepath ) ; } export function preferMavenWrapper ( resourceOrFilepath ? ) { return ! ! _getMavenSection < boolean > ( "executable.preferMavenWrapper" , resourceOrFilepath ) ; } } export namespace Pomfile { export function autoUpdateEffectivePOM ( ) { return ! ! _getMavenSection < boolean > ( "pomfile.autoUpdateEffectivePOM" ) ; } export function globPattern ( ) { const ret = _getMavenSection < string > ( "pomfile.globPattern" ) ; return ret !== undefined ? ret : "**/pom.xml" ; } export function prefetchEffectivePom ( ) { return ! ! _getMavenSection < string > ( "pomfile.prefetchEffectivePom" ) ; } } function _getMavenSection < T > ( section , resourceOrFilepath ? ) { let resource ; if ( typeof resourceOrFilepath === "string" ) { resource = Uri . file ( resourceOrFilepath ) ; } else if ( resourceOrFilepath instanceof Uri ) { resource = resourceOrFilepath ; } return workspace . getConfiguration ( "maven" , resource ) . get < T > ( section ) ; } export function getEnvironment ( resourceOrFilepath ? ) { const customEnv = _getJavaHomeEnvIfAvailable ( ) ; type EnvironmentSetting = { environmentVariable : string ; value : string ; } ; const environmentSettings = Terminal . customEnv ( resourceOrFilepath ) ; if ( environmentSettings ) { environmentSettings . forEach ( ( s ) => { customEnv [ s . environmentVariable ] = s . value ; } ) ; } return customEnv ; } function _getJavaHomeEnvIfAvailable ( ) { const useJavaHome = Terminal . useJavaHome ( ) ; const javaHome = External . javaHome ( ) ; if ( useJavaHome && javaHome ) { return { JAVA_HOME : javaHome } ; } else { return { } ; } } }