Skip to content

Commit 48ab9cf

Browse files
author
jan
committed
Only updat the json files every 10 days
1 parent 3be09fc commit 48ab9cf

File tree

3 files changed

+56
-23
lines changed

3 files changed

+56
-23
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ public class BoardsManager {
6969

7070
private static boolean myIsDirty = true;
7171

72+
private static boolean myIsUpdating =false;
73+
7274
static {
7375
getPersistentPackageURLList();
7476
}
7577

7678
public static boolean isReady() {
77-
return !myIsDirty;
79+
return !(myIsDirty || myIsUpdating);
7880
}
7981

8082
/**
@@ -178,7 +180,7 @@ public static void setPackageURLs(Collection<String> packageUrls) {
178180
*/
179181
public static void installsubsetOfLatestPlatforms(int fromIndex, int toIndex) {
180182
String DEPRECATED = "DEPRECATED"; //$NON-NLS-1$
181-
if (!isReady()) {
183+
if (myIsDirty) {
182184
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
183185
return;
184186
}
@@ -218,7 +220,7 @@ public static void installAllLatestPlatforms() {
218220
}
219221

220222
public static void installLatestPlatform(String JasonName, String packagerName, String architectureName) {
221-
if (!isReady()) {
223+
if (myIsDirty) {
222224
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
223225
return;
224226
}
@@ -379,7 +381,7 @@ private static String[] getHardwarePaths() {
379381

380382
public static IStatus updatePlatforms(List<IArduinoPlatformVersion> platformsToInstall,
381383
List<IArduinoPlatformVersion> platformsToRemove, IProgressMonitor monitor, MultiStatus status) {
382-
if (!isReady()) {
384+
if (myIsDirty) {
383385
status.add(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, null));
384386
return status;
385387
}
@@ -603,7 +605,7 @@ private static IPath getThirdPartyURLStoragePath() {
603605
}
604606

605607
public static void removeAllInstalledPlatforms() {
606-
if (!isReady()) {
608+
if (myIsDirty) {
607609
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
608610
return;
609611
}
@@ -678,7 +680,7 @@ public static List<IArduinoPlatformPackageIndex> getPackageIndices() {
678680
// }
679681

680682
public static IArduinoPlatform getPlatform(String vendor, String architecture) {
681-
if (!isReady()) {
683+
if (myIsDirty) {
682684
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
683685
return null;
684686
}
@@ -701,7 +703,7 @@ public static IArduinoPlatform getPlatform(String vendor, String architecture) {
701703
* @return the found platform otherwise null
702704
*/
703705
public static IArduinoPlatformVersion getPlatform(IPath platformPath) {
704-
if (!isReady()) {
706+
if (myIsDirty) {
705707
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
706708
return null;
707709
}
@@ -739,7 +741,7 @@ public static IArduinoPlatformVersion getPlatform(IPath platformPath) {
739741
* @return a platform or null if no platforms are installed
740742
*/
741743
static public IArduinoPlatformVersion getAnyInstalledPlatform() {
742-
if (!isReady()) {
744+
if (myIsDirty) {
743745
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
744746
return null;
745747
}
@@ -766,7 +768,7 @@ static private boolean areThereInstalledBoards() {
766768

767769
static public List<IArduinoPackage> getPackages() {
768770
List<IArduinoPackage> packages = new ArrayList<>();
769-
if (!isReady()) {
771+
if (myIsDirty) {
770772
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
771773
return packages;
772774
}
@@ -801,7 +803,7 @@ static private IArduinoPackage getPackage(String jasonURL, String packageName) {
801803
* Remove all packages that have a more recent version
802804
*/
803805
public static void onlyKeepLatestPlatforms() {
804-
if (!isReady()) {
806+
if (myIsDirty) {
805807
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
806808
return;
807809
}
@@ -841,7 +843,7 @@ public static IArduinoPlatformVersion getPlatform(String vendor, String architec
841843
}
842844

843845
public static IArduinoPackage getPackageByProvider(String packager) {
844-
if (!isReady()) {
846+
if (myIsDirty) {
845847
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
846848
return null;
847849
}
@@ -868,6 +870,7 @@ public static IArduinoPackage getPackageByProvider(String packager) {
868870
*/
869871
public static void update(boolean reloadFromInternet) {
870872
synchronized (packageIndices) {
873+
myIsUpdating =true;
871874
if (myIsDirty) {
872875
downloadJsons(reloadFromInternet);
873876
readJsons();
@@ -898,9 +901,8 @@ public static void update(boolean reloadFromInternet) {
898901
}
899902
envVarsNeedUpdating = false;
900903
}
901-
902904
}
903-
905+
myIsUpdating=false;
904906
}
905907

906908
}

io.sloeber.core/src/io/sloeber/core/Activator.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import java.io.InputStream;
99
import java.net.MalformedURLException;
1010
import java.net.URL;
11+
import java.time.Duration;
12+
import java.time.Instant;
1113

1214
import org.eclipse.cdt.core.CCorePlugin;
1315
import org.eclipse.cdt.core.model.CoreModel;
@@ -463,7 +465,23 @@ public static void log(IStatus status) {
463465
* @param monitor
464466
*/
465467
private static synchronized void startup_BoardsManager(IProgressMonitor monitor) {
466-
BoardsManager.update( ConfigurationPreferences.getUpdateJasonFilesFlag());
468+
//ConfigurationPreferences.getUpdateJasonFilesFlag();
469+
Instant currentTime=Instant.now();
470+
Instant latestUpdate= ConfigurationPreferences.getLatestUpdateTime();
471+
Duration requestedDelay=ConfigurationPreferences.getUpdateDelay();
472+
Instant nextUpdate=latestUpdate.plus(requestedDelay);
473+
boolean needsUpdate = nextUpdate.isBefore(currentTime);
474+
475+
// long latestUpdate= getLatestUpdateTime();
476+
// long requestedDelay=getUpdateDelay();
477+
// long currentTime= System.currentTimeMillis();
478+
// boolean needsUpdate = currentTime>(requestedDelay+latestUpdate);
479+
if(needsUpdate) {
480+
BoardsManager.update(true );
481+
ConfigurationPreferences.setLatestUpdateTime(currentTime);
482+
}else {
483+
BoardsManager.update(false );
484+
}
467485

468486
if (!LibraryManager.libsAreInstalled()) {
469487
LibraryManager.InstallDefaultLibraries(monitor);

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import static io.sloeber.core.api.Const.*;
44

55
import java.io.File;
6+
import java.time.Duration;
7+
import java.time.Instant;
68

79
import org.eclipse.core.runtime.IPath;
810
import org.eclipse.core.runtime.Path;
@@ -26,7 +28,7 @@ public class ConfigurationPreferences {
2628
private static final String PRE_PROCESSING_BOARDS_TXT = "pre_processing_boards.txt"; //$NON-NLS-1$
2729
private static final String POST_PROCESSING_BOARDS_TXT = "post_processing_boards.txt"; //$NON-NLS-1$
2830

29-
private static final String KEY_UPDATE_JASONS = "Update jsons files"; //$NON-NLS-1$
31+
private static final String KEY_LATEST_JSON_UPDATE_TIME ="latest time the json files were updated";//$NON-NLS-1$
3032

3133

3234
public static void removeKey(String key) {
@@ -39,14 +41,19 @@ public static String getString(String key, String defaultValue) {
3941
return myScope.get(key, defaultValue);
4042
}
4143

42-
private static boolean getBoolean(String key, boolean defaultValue) {
44+
45+
private static Instant getInstant(String key, Instant defaultValue) {
4346
IEclipsePreferences myScope = ConfigurationScope.INSTANCE.getNode(NODE_ARDUINO);
44-
return myScope.getBoolean(key, defaultValue);
47+
long ret = myScope.getLong(key, 0);
48+
if(ret==0) {
49+
return defaultValue;
50+
}
51+
return Instant.ofEpochSecond(ret);
4552
}
4653

47-
private static void setBoolean(String key, boolean value) {
54+
private static void setInstant(String key, Instant value) {
4855
IEclipsePreferences myScope = ConfigurationScope.INSTANCE.getNode(NODE_ARDUINO);
49-
myScope.putBoolean(key, value);
56+
myScope.putLong(key, value.getEpochSecond());
5057
try {
5158
myScope.flush();
5259
} catch (BackingStoreException e) {
@@ -123,12 +130,18 @@ public static IPath getAwkPath() {
123130
return new Path(getInstallationPath().append("tools/awk").toString()); //$NON-NLS-1$
124131
}
125132

126-
public static boolean getUpdateJasonFilesFlag() {
127-
return getBoolean(KEY_UPDATE_JASONS, Defaults.updateJsonFiles);
133+
public static Instant getLatestUpdateTime() {
134+
return getInstant(KEY_LATEST_JSON_UPDATE_TIME, Instant.now());
135+
}
136+
137+
public static void setLatestUpdateTime(Instant currentTime) {
138+
setInstant(KEY_LATEST_JSON_UPDATE_TIME,currentTime);
139+
128140
}
129141

130-
public static void setUpdateJasonFilesFlag(boolean newFlag) {
131-
setBoolean(KEY_UPDATE_JASONS, newFlag);
142+
public static Duration getUpdateDelay() {
143+
// TODO Auto-generated method stub
144+
return Duration.ofDays(10);
132145
}
133146

134147
}

0 commit comments

Comments
 (0)