@@ -13,7 +13,7 @@ import * as requirements from './requirements';
13
13
import { initialize as initializeRecommendation } from './recommendation' ;
14
14
import { Commands } from './commands' ;
15
15
import { 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' ;
17
17
import { onConfigurationChange , getJavaServerMode , ServerMode , ACTIVE_BUILD_TOOL_STATE } from './settings' ;
18
18
import { logger , initializeLogFile } from './log' ;
19
19
import glob = require( 'glob' ) ;
@@ -610,9 +610,7 @@ async function cleanWorkspace(workspacePath) {
610
610
const doIt = 'Restart and delete' ;
611
611
window . showWarningMessage ( 'Are you sure you want to clean the Java language server workspace?' , 'Cancel' , doIt ) . then ( selection => {
612
612
if ( selection === doIt ) {
613
- if ( ! fs . existsSync ( workspacePath ) ) {
614
- fs . mkdirSync ( workspacePath ) ;
615
- }
613
+ ensureExists ( workspacePath ) ;
616
614
const file = path . join ( workspacePath , cleanWorkspaceFileName ) ;
617
615
fs . closeSync ( fs . openSync ( file , 'w' ) ) ;
618
616
commands . executeCommand ( Commands . RELOAD_WINDOW ) ;
@@ -690,9 +688,7 @@ async function openFormatter(extensionPath) {
690
688
relativePath = fileName ;
691
689
} else {
692
690
const root = path . join ( extensionPath , '..' , 'redhat.java' ) ;
693
- if ( ! fs . existsSync ( root ) ) {
694
- fs . mkdirSync ( root ) ;
695
- }
691
+ ensureExists ( root ) ;
696
692
file = path . join ( root , fileName ) ;
697
693
}
698
694
if ( ! fs . existsSync ( file ) ) {
@@ -765,9 +761,7 @@ async function addFormatter(extensionPath, formatterUrl, defaultFormatter, relat
765
761
relativePath = fileName ;
766
762
} else {
767
763
const root = path . join ( extensionPath , '..' , 'redhat.java' ) ;
768
- if ( ! fs . existsSync ( root ) ) {
769
- fs . mkdirSync ( root ) ;
770
- }
764
+ ensureExists ( root ) ;
771
765
f = path . join ( root , fileName ) ;
772
766
}
773
767
} else {
@@ -780,9 +774,14 @@ async function addFormatter(extensionPath, formatterUrl, defaultFormatter, relat
780
774
const action = 'Yes' ;
781
775
window . showWarningMessage ( msg , action , 'No' ) . then ( ( selection ) => {
782
776
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
+ }
786
785
}
787
786
} ) ;
788
787
} else {
0 commit comments