Skip to content

Commit 6b02f9d

Browse files
author
jan
committed
Fix regression on download and install lib on usage.
1 parent 0891845 commit 6b02f9d

File tree

6 files changed

+61
-10
lines changed

6 files changed

+61
-10
lines changed

io.sloeber.core/src/io/sloeber/arduinoFramework/api/LibraryManager.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public static void installLibrary(String libName) {
142142
}
143143
}
144144

145+
145146
public static IStatus install(IArduinoLibraryVersion inLib, IProgressMonitor monitor) {
146147
if (!(inLib instanceof ArduinoLibraryVersion)) {
147148
return Status.error("Trying to install a library that is not a installable library" + inLib.getName()); //$NON-NLS-1$
@@ -470,4 +471,22 @@ public static IArduinoLibraryVersion getLibraryVersionFromLocation(IFolder libFo
470471
return getLibrariesPrivate().get(libFolder.getName());
471472
}
472473

474+
/**
475+
* Remove a lib based on the name of the lib
476+
*
477+
* @param libName the name of the lib
478+
* @return true if the lib has been removed or was not found
479+
* false if the lib was found and the removal failed.
480+
*/
481+
public static boolean uninstallLibrary(String libName) {
482+
Map<String, IArduinoLibraryVersion> installedLibs=getLibrariesAll(null);
483+
IPath libFQN=ArduinoLibraryVersion.calculateFQN(libName);
484+
IArduinoLibraryVersion libVersion = installedLibs.get(libFQN.toString());
485+
if(libVersion==null) {
486+
return true;
487+
488+
}
489+
return unInstall(libVersion, new NullProgressMonitor()).isOK();
490+
}
491+
473492
}

io.sloeber.core/src/io/sloeber/core/api/ConfigurationPreferences.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,21 @@ private static Duration getDuration(String key, Duration defaultValue) {
250250
return Duration.ofDays(ret);
251251
}
252252

253+
/**
254+
* Allow the library manager to download and install libraries based on include directive in the source code.
255+
*
256+
* @param selection true if you want to install libraries based on their usage else false
257+
*/
258+
public static void setInstallLibraries(boolean selection) {
259+
InstancePreferences.setInstallLibraries(selection);
260+
}
261+
262+
/**
263+
*
264+
* @return true when libraries can be downloaded and installed when referenced in the code.
265+
*/
266+
public static boolean getInstallLibraries() {
267+
return InstancePreferences.getInstallLibraries();
268+
}
269+
253270
}

io.sloeber.core/src/io/sloeber/core/api/Defaults.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class Defaults {
3636
public static final boolean useBonjour = true;
3737
public static final boolean autoInstallLibraries = true;
3838
public static final boolean useArduinoToolSelection = true;
39+
public static final boolean INSTALL_LIBRARIES =false; //Install libraries on usage
3940

4041
/**
4142
* Arduino has the default libraries in the user home directory in subfolder

io.sloeber.core/src/io/sloeber/core/common/InstancePreferences.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class InstancePreferences {
2828
private static final String KEY_PRAGMA_ONCE_HEADER = "add pragma once to headers"; //$NON-NLS-1$
2929
private static final String KEY_USE_ARDUINO_TOOLS_SELECTION_ALGORITHM="Use the algoritm to find the toolchain like Arduino IDE"; //$NON-NLS-1$
3030
private static final String KEY_USE_BONJOUR="use bonjour service to find devices"; //$NON-NLS-1$
31+
private static final String KEY_INSTALL_LIBRARIES= "download and install libraries on usage"; //$NON-NLS-1$
3132

3233
/**
3334
* Give back the user option if the libraries need to be added or not
@@ -141,4 +142,12 @@ public static boolean useBonjour() {
141142
public static void setUseBonjour(boolean newFlag) {
142143
setValue(KEY_USE_BONJOUR, newFlag);
143144
}
145+
146+
public static void setInstallLibraries(boolean selection) {
147+
setValue(KEY_INSTALL_LIBRARIES, selection);
148+
}
149+
150+
public static boolean getInstallLibraries() {
151+
return getBoolean(KEY_INSTALL_LIBRARIES, Defaults.INSTALL_LIBRARIES);
152+
}
144153
}

io.sloeber.core/src/io/sloeber/core/listeners/IndexerListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import io.sloeber.arduinoFramework.api.LibraryManager;
3636
import io.sloeber.core.Activator;
3737
import io.sloeber.core.Messages;
38+
import io.sloeber.core.api.ConfigurationPreferences;
3839
import io.sloeber.core.api.Const;
3940
import io.sloeber.core.api.IInstallLibraryHandler;
4041
import io.sloeber.core.api.ISloeberConfiguration;
@@ -124,7 +125,7 @@ private static void checkLibraries(ISloeberConfiguration SloeberCfg) {
124125

125126
//Check wether we need to download and install libraries
126127
IInstallLibraryHandler installHandler = LibraryManager.getInstallLibraryHandler();
127-
if (installHandler.autoInstall()) {
128+
if (ConfigurationPreferences.getInstallLibraries() && installHandler.autoInstall()) {
128129
// Check if there are libraries that are not found in
129130
// the installed libraries
130131
Set<String> uninstalledIncludedHeaders = new TreeSet<>(UnresolvedIncludedHeaders);

io.sloeber.ui/src/io/sloeber/ui/preferences/PreferencePage.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,23 @@ public class PreferencePage extends FieldEditorPreferencePage implements IWorkbe
6969
private static final String KEY_PRIVATE_HARDWARE_PATHS = "Gui entry for private hardware paths"; //$NON-NLS-1$
7070
private static final String KEY_PRIVATE_LIBRARY_PATHS = "Gui entry for private library paths"; //$NON-NLS-1$
7171
private static final String KEY_TOOLCHAIN_SELECTION = "Gui entry for toolchain selection"; //$NON-NLS-1$
72-
//private static final String KEY_USE_BONJOUR = "Gui entry for usage of bonjour"; //$NON-NLS-1$
72+
7373

7474
private PathEditor arduinoPrivateLibPathPathEditor;
7575
private PathEditor arduinoPrivateHardwarePathPathEditor;
7676
private ComboFieldEditor buildBeforeUploadOptionEditor;
7777
private BooleanFieldEditor openSerialMonitorOpensSerialsOptionEditor;
7878
private BooleanFieldEditor automaticallyImportLibrariesOptionEditor;
79-
//private BooleanFieldEditor automaticallyInstallLibrariesOptionEditor;
8079
private BooleanFieldEditor useArduinoToolchainSelectionEditor;
8180
private BooleanFieldEditor pragmaOnceHeaderOptionEditor;
8281
private BooleanFieldEditor cleanSerialMonitorAfterUploadEditor;
8382
private BooleanFieldEditor switchToSerialMonitorAfterUploadEditor;
8483
private BooleanFieldEditor enableParallelBuildForNewProjects;
85-
//private BooleanFieldEditor enableBonjour;
84+
8685
private Button myBonjourCheckBox;
8786
private Spinner myDelayNumberSpinner;
8887
private Combo myDelayUnitCombo;
88+
private Button myInstallLibCheckBox;
8989

9090
private static int[] durationUnits = new int[] { 1, 7, 30, 365, 36500 };
9191

@@ -154,6 +154,8 @@ public boolean performOk() {
154154
ConfigurationPreferences.setAutoImportLibraries(this.automaticallyImportLibrariesOptionEditor.getBooleanValue());
155155
ConfigurationPreferences.setPragmaOnceHeaders(this.pragmaOnceHeaderOptionEditor.getBooleanValue());
156156
ConfigurationPreferences.setUseBonjour(myBonjourCheckBox.getSelection());
157+
ConfigurationPreferences.setInstallLibraries(myInstallLibCheckBox.getSelection());
158+
157159
//TOFIX line below
158160
ConfigurationPreferences.setJsonUpdateDelay(Duration.ofDays(myDelayNumberSpinner.getSelection() * durationUnits[myDelayUnitCombo.getSelectionIndex()]));
159161
BoardsManager.setPrivateHardwarePaths(hardWarePaths);
@@ -321,12 +323,12 @@ protected void createFieldEditors() {
321323
Dialog.applyDialogFont(netWorkbox);
322324

323325
//Currently sloeber does not autoinstall librtaries
324-
// Button myInstallLibCheckBox = new Button(netWorkbox, SWT.CHECK | SWT.LEFT);
325-
// Label inStallLabel = new Label(netWorkbox, SWT.BEGINNING);
326-
// inStallLabel.setText(Messages.ui_auto_install_libraries);
327-
// GridData gd16 = new GridData(SWT.BEGINNING, SWT.TOP, true, false);
328-
// gd16.horizontalSpan=3;
329-
// inStallLabel.setLayoutData(gd16);
326+
myInstallLibCheckBox = new Button(netWorkbox, SWT.CHECK | SWT.LEFT);
327+
Label inStallLabel = new Label(netWorkbox, SWT.BEGINNING);
328+
inStallLabel.setText(Messages.ui_auto_install_libraries);
329+
GridData gd16 = new GridData(SWT.BEGINNING, SWT.TOP, true, false);
330+
gd16.horizontalSpan=3;
331+
inStallLabel.setLayoutData(gd16);
330332

331333

332334
myBonjourCheckBox = new Button(netWorkbox, SWT.CHECK | SWT.LEFT );
@@ -374,6 +376,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
374376

375377

376378
myBonjourCheckBox.setSelection(ConfigurationPreferences.useBonjour());
379+
myInstallLibCheckBox.setSelection(ConfigurationPreferences.getInstallLibraries());
377380
setJsonDurationComposites(ConfigurationPreferences.getJsonUpdateDelay());
378381

379382
}
@@ -412,6 +415,7 @@ protected void performApply() {
412415
protected void performDefaults() {
413416
super.performDefaults();
414417
myBonjourCheckBox.setSelection( Defaults.useBonjour);
418+
myInstallLibCheckBox.setSelection( Defaults.INSTALL_LIBRARIES);
415419
setJsonDurationComposites(Defaults.getJsonUpdateDuration());
416420

417421
}

0 commit comments

Comments
 (0)