@@ -73,16 +73,17 @@ protected boolean doInstall(boolean silent) {
73
73
VersionIdentifier installedVersion = getInstalledVersion ();
74
74
Step step = this .context .newStep (silent , "Install " + this .tool , configuredVersion );
75
75
try {
76
- // install configured version of our tool in the software repository if not already installed
77
- ToolInstallation installation = installInRepo (configuredVersion );
78
- // check if we already have this version installed (linked) locally in IDE_HOME/software
79
- VersionIdentifier resolvedVersion = installation .resolvedVersion ();
80
- if (resolvedVersion .equals (installedVersion ) && !installation .newInstallation ()) {
76
+ ToolRepository repository = this .context .getDefaultToolRepository ();
77
+ String edition = getEdition ();
78
+ VersionIdentifier resolvedVersion = repository .resolveVersion (this .tool , edition , configuredVersion );
79
+ if (resolvedVersion .equals (installedVersion )) {
81
80
IdeLogLevel level = silent ? IdeLogLevel .DEBUG : IdeLogLevel .INFO ;
82
81
this .context .level (level ).log ("Version {} of tool {} is already installed" , installedVersion , getToolWithEdition ());
83
82
step .success ();
84
83
return false ;
85
84
}
85
+ // install configured version of our tool in the software repository if not already installed
86
+ ToolInstallation installation = installInRepo (resolvedVersion , edition , repository );
86
87
// we need to link the version or update the link.
87
88
Path toolPath = getToolPath ();
88
89
FileAccess fileAccess = this .context .getFileAccess ();
@@ -145,30 +146,26 @@ public ToolInstallation installInRepo(VersionIdentifier version, String edition)
145
146
public ToolInstallation installInRepo (VersionIdentifier version , String edition , ToolRepository toolRepository ) {
146
147
147
148
VersionIdentifier resolvedVersion = toolRepository .resolveVersion (this .tool , edition , version );
148
-
149
- if (Files .exists (this .dependency .getDependencyJsonPath (getEdition ()))) {
150
- installDependencies (resolvedVersion );
151
- } else {
152
- this .context .trace ("No Dependencies file found" );
153
- }
154
-
155
149
Path toolPath = this .context .getSoftwareRepositoryPath ().resolve (toolRepository .getId ()).resolve (this .tool ).resolve (edition )
156
- .resolve (resolvedVersion .toString ());
150
+ .resolve (resolvedVersion .toString ());
157
151
Path toolVersionFile = toolPath .resolve (IdeContext .FILE_SOFTWARE_VERSION );
158
152
FileAccess fileAccess = this .context .getFileAccess ();
159
153
if (Files .isDirectory (toolPath )) {
160
154
if (Files .exists (toolVersionFile )) {
161
- if (this .context .isForceMode ()) {
162
- fileAccess .delete (toolPath );
163
- } else {
164
- this .context .debug ("Version {} of tool {} is already installed at {}" , resolvedVersion , getToolWithEdition (this .tool , edition ), toolPath );
165
- return createToolInstallation (toolPath , resolvedVersion , toolVersionFile );
166
- }
155
+ this .context .debug ("Version {} of tool {} is already installed at {}" , resolvedVersion , getToolWithEdition (this .tool , edition ), toolPath );
156
+ return createToolInstallation (toolPath , resolvedVersion , toolVersionFile );
167
157
} else {
168
- this .context .warning ("Deleting corrupted installation at {}" , toolPath );
169
- fileAccess .delete (toolPath );
158
+ this .context .warning ("Archiving corrupted installation at {}" , toolPath );
159
+ fileAccess .backup (toolPath );
170
160
}
171
161
}
162
+
163
+ if (Files .exists (this .dependency .getDependencyJsonPath (getEdition ()))) {
164
+ installDependencies (resolvedVersion );
165
+ } else {
166
+ this .context .trace ("No Dependencies file found" );
167
+ }
168
+
172
169
Path target = toolRepository .download (this .tool , edition , resolvedVersion );
173
170
fileAccess .mkdirs (toolPath .getParent ());
174
171
boolean extract = isExtract ();
@@ -262,13 +259,14 @@ public String getInstalledEdition(Path toolPath) {
262
259
263
260
}
264
261
262
+ @ Override
265
263
public void uninstall () {
266
264
267
265
try {
268
266
Path softwarePath = getToolPath ();
269
267
if (Files .exists (softwarePath )) {
270
268
try {
271
- context .getFileAccess ().delete (softwarePath );
269
+ this . context .getFileAccess ().delete (softwarePath );
272
270
this .context .success ("Successfully uninstalled " + this .tool );
273
271
} catch (Exception e ) {
274
272
this .context .error ("Couldn't uninstall " + this .tool );
@@ -290,13 +288,39 @@ private ToolInstallation createToolInstallation(Path rootDir, VersionIdentifier
290
288
if (Files .isDirectory (binFolder )) {
291
289
binDir = binFolder ;
292
290
}
293
- if (linkDir != rootDir ) {
291
+ if (newInstallation && ( linkDir != rootDir ) ) {
294
292
assert (!linkDir .equals (rootDir ));
295
293
this .context .getFileAccess ().copy (toolVersionFile , linkDir , FileCopyMode .COPY_FILE_OVERRIDE );
294
+ if (this .context .getSystemInfo ().isMac ()) {
295
+ Path macApp = findMacApp (linkDir );
296
+ if (macApp != null ) {
297
+ ProcessContext pc = this .context .newProcess ();
298
+ pc .executable ("sudo" ).addArgs ("xattr" , "-d" , "com.apple.quarantine" , macApp );
299
+ pc .run ();
300
+ }
301
+ }
296
302
}
297
303
return new ToolInstallation (rootDir , linkDir , binDir , resolvedVersion , newInstallation );
298
304
}
299
305
306
+ private Path findMacApp (Path path ) {
307
+
308
+ while (path != null ) {
309
+ Path fileName = path .getFileName ();
310
+ if (fileName == null ) {
311
+ return null ;
312
+ }
313
+ String filename = fileName .toString ();
314
+ if (filename .endsWith (".app" )) {
315
+ return path ;
316
+ } else if (filename .equals (IdeContext .FOLDER_CONTENTS )) {
317
+ return path .getParent ();
318
+ }
319
+ path = path .getParent ();
320
+ }
321
+ return null ;
322
+ }
323
+
300
324
private ToolInstallation createToolInstallation (Path rootDir , VersionIdentifier resolvedVersion , Path toolVersionFile ) {
301
325
302
326
return createToolInstallation (rootDir , resolvedVersion , toolVersionFile , false );
@@ -406,7 +430,7 @@ private void setDependencyEnvironmentPath(String dependencyEnvironmentName, Path
406
430
407
431
protected HashMap <String , String > listOfDependencyEnvVariableNames () {
408
432
409
- return dependenciesEnvVariableNames ;
433
+ return this . dependenciesEnvVariableNames ;
410
434
}
411
435
412
436
private String getDependencyEnvironmentName (String dependencyName ) {
0 commit comments