Skip to content

Commit

Permalink
[ACLI] Clean the workbench on exit
Browse files Browse the repository at this point in the history
- Clean the workbench on exiting the ACLI

- If we don't do this we can end up with Archi plug-ins not showing up in Archi if we use a different Archi instance and ACLI instance (say, one one C: drive and one on D: drive)

- Also, support a -noCleanConfig option to over-ride the -cleanConfig one in case it's needed from the command line if there's problems
  • Loading branch information
Phillipus committed Aug 29, 2024
1 parent 2fda868 commit 331592e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.swt.widgets.Display;

import com.archimatetool.editor.WorkbenchCleaner;
import com.archimatetool.editor.utils.StringUtils;


Expand Down Expand Up @@ -63,23 +64,29 @@ public ProviderInfo(String id, String name, String description) {

@Override
public Object start(IApplicationContext context) throws Exception {
// Register providers
registerProviders();

// Process options
CommandLine commandLine = processOptions();

// Show help if set and exit
if(commandLine.hasOption("help")) { //$NON-NLS-1$
showHelp();
if(commandLine.hasOption("pause")) { //$NON-NLS-1$
pause();
try {
// Register providers
registerProviders();

// Process options
CommandLine commandLine = processOptions();

// Show help if set and exit
if(commandLine.hasOption("help")) { //$NON-NLS-1$
showHelp();
if(commandLine.hasOption("pause")) { //$NON-NLS-1$
pause();
}
return EXIT_OK;
}
return EXIT_OK;

// Run provider options
return runProviderOptions(commandLine);
}
// Clean the workbench config area on exit
finally {
WorkbenchCleaner.cleanConfigOnExit(false);
}

// Run provider options
return runProviderOptions(commandLine);
}

// Collect registered command line providers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.File;
import java.util.Arrays;
import java.util.List;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.dialogs.MessageDialog;
Expand Down Expand Up @@ -57,6 +58,9 @@ public class WorkbenchCleaner {
// If this is set in Program arguments then clean the config area
private static final String CLEAN_CONFIG = "-cleanConfig"; //$NON-NLS-1$

// This over-rides -cleanConfig in case we are running from the command line and don't want to edit the Archi.ini file
private static final String NO_CLEAN_CONFIG = "-noCleanConfig"; //$NON-NLS-1$

private static final String[] CONFIG_FILES_TO_DELETE = {
// Files
".baseConfigIniTimestamp", //$NON-NLS-1$
Expand Down Expand Up @@ -111,7 +115,7 @@ static void clean(boolean isRestart) {
/**
* Clean the workbench if requested
*/
private static void cleanWorkbench() {
static void cleanWorkbench() {
// Not set
if(cleanWorkBench == -1) {
return;
Expand All @@ -134,9 +138,11 @@ else if(cleanWorkBench == 1) {
* Clean the config area on exit
* See https://github.com/archimatetool/archi/issues/429
*/
private static void cleanConfigOnExit(boolean isRestart) {
// Don't clean if the "-cleanConfig" option is not set or we are in development mode
if(Platform.inDevelopmentMode() || !Arrays.asList(Platform.getApplicationArgs()).contains(CLEAN_CONFIG)) {
public static void cleanConfigOnExit(boolean isRestart) {
// Don't clean if we are in development mode or the "-noCleanConfig" option is set or "-cleanConfig" option is not set
List<String> appArgs = Arrays.asList(Platform.getApplicationArgs());

if(Platform.inDevelopmentMode() || appArgs.contains(NO_CLEAN_CONFIG) || !appArgs.contains(CLEAN_CONFIG)) {
return;
}

Expand All @@ -156,7 +162,7 @@ private static void cleanConfigOnExit(boolean isRestart) {
if(P2.USE_DROPINS) {
File p2Folder = P2.getP2Location(); // Get this before running the shutdown hook

Runnable runnable = (() -> {
Runnable runnable = () -> {
// Delete config files
for(String path : CONFIG_FILES_TO_DELETE) {
delete(new File(configLocationFolder, path));
Expand All @@ -175,7 +181,7 @@ private static void cleanConfigOnExit(boolean isRestart) {
if(!installationFolder.equals(artifactsFile.getParentFile())) {
delete(artifactsFile);
}
});
};

// Mac does not call shutdown hooks on Restart so run this now.
// Note, not all files will be deleted in this case.
Expand Down

0 comments on commit 331592e

Please sign in to comment.