@@ -13,7 +13,7 @@ import * as requirements from './requirements';
1313import { initialize as initializeRecommendation } from './recommendation' ;
1414import { Commands } from './commands' ;
1515import { ExtensionAPI , ClientStatus } from './extension.api' ;
16- import { getJavaConfiguration , deleteDirectory , getBuildFilePatterns , getInclusionPatternsFromNegatedExclusion , convertToGlob , getExclusionBlob } from './utils' ;
16+ import { getJavaConfiguration , deleteDirectory , getBuildFilePatterns , getInclusionPatternsFromNegatedExclusion , convertToGlob , getExclusionBlob , ensureExists } from './utils' ;
1717import { onConfigurationChange , getJavaServerMode , ServerMode , ACTIVE_BUILD_TOOL_STATE } from './settings' ;
1818import { logger , initializeLogFile } from './log' ;
1919import glob = require( 'glob' ) ;
@@ -610,9 +610,7 @@ async function cleanWorkspace(workspacePath) {
610610 const doIt = 'Restart and delete' ;
611611 window . showWarningMessage ( 'Are you sure you want to clean the Java language server workspace?' , 'Cancel' , doIt ) . then ( selection => {
612612 if ( selection === doIt ) {
613- if ( ! fs . existsSync ( workspacePath ) ) {
614- fs . mkdirSync ( workspacePath ) ;
615- }
613+ ensureExists ( workspacePath ) ;
616614 const file = path . join ( workspacePath , cleanWorkspaceFileName ) ;
617615 fs . closeSync ( fs . openSync ( file , 'w' ) ) ;
618616 commands . executeCommand ( Commands . RELOAD_WINDOW ) ;
@@ -690,9 +688,7 @@ async function openFormatter(extensionPath) {
690688 relativePath = fileName ;
691689 } else {
692690 const root = path . join ( extensionPath , '..' , 'redhat.java' ) ;
693- if ( ! fs . existsSync ( root ) ) {
694- fs . mkdirSync ( root ) ;
695- }
691+ ensureExists ( root ) ;
696692 file = path . join ( root , fileName ) ;
697693 }
698694 if ( ! fs . existsSync ( file ) ) {
@@ -765,9 +761,7 @@ async function addFormatter(extensionPath, formatterUrl, defaultFormatter, relat
765761 relativePath = fileName ;
766762 } else {
767763 const root = path . join ( extensionPath , '..' , 'redhat.java' ) ;
768- if ( ! fs . existsSync ( root ) ) {
769- fs . mkdirSync ( root ) ;
770- }
764+ ensureExists ( root ) ;
771765 f = path . join ( root , fileName ) ;
772766 }
773767 } else {
@@ -780,9 +774,14 @@ async function addFormatter(extensionPath, formatterUrl, defaultFormatter, relat
780774 const action = 'Yes' ;
781775 window . showWarningMessage ( msg , action , 'No' ) . then ( ( selection ) => {
782776 if ( action === selection ) {
783- fs . createReadStream ( defaultFormatter )
784- . pipe ( fs . createWriteStream ( f ) )
785- . on ( 'finish' , ( ) => openDocument ( extensionPath , f , defaultFormatter , relativePath ) ) ;
777+ try {
778+ ensureExists ( path . dirname ( f ) ) ;
779+ fs . createReadStream ( defaultFormatter )
780+ . pipe ( fs . createWriteStream ( f ) )
781+ . on ( 'finish' , ( ) => openDocument ( extensionPath , f , defaultFormatter , relativePath ) ) ;
782+ } catch ( error ) {
783+ window . showErrorMessage ( `Failed to create ${ f } : ${ error } ` ) ;
784+ }
786785 }
787786 } ) ;
788787 } else {
0 commit comments