@@ -29,14 +29,10 @@ public ExtractArchiveStep(String rawArchiveUri) {
29
29
30
30
@ Override
31
31
public LocalToolInstallationDetails executeInstallStep (File installationRoot , LocalToolInstallationDetails intermediateInstallationDetails ) throws LocalToolInstallationStepException {
32
- try {
33
- Path localArchivePath = downloadArchive ();
34
- extractArchive (localArchivePath , installationRoot );
32
+ Path localArchivePath = downloadArchive ();
33
+ extractArchive (localArchivePath , installationRoot );
35
34
36
- return intermediateInstallationDetails ;
37
- } catch (IOException e ) {
38
- throw new LocalToolInstallationStepException ("failed to extract archive from URI " + rawArchiveUri , e );
39
- }
35
+ return intermediateInstallationDetails ;
40
36
}
41
37
42
38
@ Override
@@ -49,7 +45,7 @@ public void updateChecksum(MessageDigest digest) {
49
45
digest .update (rawArchiveUri .getBytes (StandardCharsets .UTF_8 ));
50
46
}
51
47
52
- private Path downloadArchive () throws IOException {
48
+ private Path downloadArchive () throws LocalToolInstallationStepException {
53
49
Path archiveCachePath = getArchiveCachePath ();
54
50
if (Files .exists (archiveCachePath )) {
55
51
ProcessOutput .writeDebugMessage ("using cached archive from {0}" , archiveCachePath );
@@ -65,13 +61,17 @@ private Path downloadArchive() throws IOException {
65
61
ProcessOutput .writeDebugMessage ("cached archive at {0}" , archiveCachePath );
66
62
return archiveCachePath ;
67
63
} catch (IOException e ) {
68
- Files . deleteIfExists (archiveCachePath );
69
- throw e ;
64
+ deleteIfExists (archiveCachePath );
65
+ throw new LocalToolInstallationStepException ( "failed to download archive from URI " + rawArchiveUri , e ) ;
70
66
}
71
67
}
72
68
73
- private Path getArchiveCachePath () throws IOException {
74
- return getCacheDirectory ().resolve (FilenameUtils .getName (rawArchiveUri ));
69
+ private Path getArchiveCachePath () throws LocalToolInstallationStepException {
70
+ try {
71
+ return getCacheDirectory ().resolve (FilenameUtils .getName (rawArchiveUri ));
72
+ } catch (IOException e ) {
73
+ throw new LocalToolInstallationStepException ("failed to resolve archive cache path for URI " + rawArchiveUri , e );
74
+ }
75
75
}
76
76
77
77
private Path getCacheDirectory () throws IOException {
@@ -82,8 +82,21 @@ private Path getCacheDirectory() throws IOException {
82
82
});
83
83
}
84
84
85
- private void extractArchive (Path localArchivePath , File installationRoot ) throws IOException {
86
- ArchiveExtractorFactory .createArchiveExtractor ().extractArchive (localArchivePath .toFile (), installationRoot );
85
+ private void extractArchive (Path localArchivePath , File installationRoot ) throws LocalToolInstallationStepException {
86
+ try {
87
+ ArchiveExtractorFactory .createArchiveExtractor ().extractArchive (localArchivePath .toFile (), installationRoot );
88
+ } catch (IOException e ) {
89
+ deleteIfExists (localArchivePath );
90
+ throw new LocalToolInstallationStepException ("failed to extract archive from URI " + rawArchiveUri , e );
91
+ }
92
+ }
93
+
94
+ private void deleteIfExists (Path path ) {
95
+ try {
96
+ Files .deleteIfExists (path );
97
+ } catch (IOException ignored ) {
98
+
99
+ }
87
100
}
88
101
89
102
}
0 commit comments