Skip to content

Commit

Permalink
Only updat the json files every 10 days
Browse files Browse the repository at this point in the history
  • Loading branch information
jan committed Oct 19, 2024
1 parent 3be09fc commit 48ab9cf
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ public class BoardsManager {

private static boolean myIsDirty = true;

private static boolean myIsUpdating =false;

static {
getPersistentPackageURLList();
}

public static boolean isReady() {
return !myIsDirty;
return !(myIsDirty || myIsUpdating);
}

/**
Expand Down Expand Up @@ -178,7 +180,7 @@ public static void setPackageURLs(Collection<String> packageUrls) {
*/
public static void installsubsetOfLatestPlatforms(int fromIndex, int toIndex) {
String DEPRECATED = "DEPRECATED"; //$NON-NLS-1$
if (!isReady()) {
if (myIsDirty) {
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
return;
}
Expand Down Expand Up @@ -218,7 +220,7 @@ public static void installAllLatestPlatforms() {
}

public static void installLatestPlatform(String JasonName, String packagerName, String architectureName) {
if (!isReady()) {
if (myIsDirty) {
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
return;
}
Expand Down Expand Up @@ -379,7 +381,7 @@ private static String[] getHardwarePaths() {

public static IStatus updatePlatforms(List<IArduinoPlatformVersion> platformsToInstall,
List<IArduinoPlatformVersion> platformsToRemove, IProgressMonitor monitor, MultiStatus status) {
if (!isReady()) {
if (myIsDirty) {
status.add(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, null));
return status;
}
Expand Down Expand Up @@ -603,7 +605,7 @@ private static IPath getThirdPartyURLStoragePath() {
}

public static void removeAllInstalledPlatforms() {
if (!isReady()) {
if (myIsDirty) {
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
return;
}
Expand Down Expand Up @@ -678,7 +680,7 @@ public static List<IArduinoPlatformPackageIndex> getPackageIndices() {
// }

public static IArduinoPlatform getPlatform(String vendor, String architecture) {
if (!isReady()) {
if (myIsDirty) {
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
return null;
}
Expand All @@ -701,7 +703,7 @@ public static IArduinoPlatform getPlatform(String vendor, String architecture) {
* @return the found platform otherwise null
*/
public static IArduinoPlatformVersion getPlatform(IPath platformPath) {
if (!isReady()) {
if (myIsDirty) {
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
return null;
}
Expand Down Expand Up @@ -739,7 +741,7 @@ public static IArduinoPlatformVersion getPlatform(IPath platformPath) {
* @return a platform or null if no platforms are installed
*/
static public IArduinoPlatformVersion getAnyInstalledPlatform() {
if (!isReady()) {
if (myIsDirty) {
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
return null;
}
Expand All @@ -766,7 +768,7 @@ static private boolean areThereInstalledBoards() {

static public List<IArduinoPackage> getPackages() {
List<IArduinoPackage> packages = new ArrayList<>();
if (!isReady()) {
if (myIsDirty) {
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
return packages;
}
Expand Down Expand Up @@ -801,7 +803,7 @@ static private IArduinoPackage getPackage(String jasonURL, String packageName) {
* Remove all packages that have a more recent version
*/
public static void onlyKeepLatestPlatforms() {
if (!isReady()) {
if (myIsDirty) {
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
return;
}
Expand Down Expand Up @@ -841,7 +843,7 @@ public static IArduinoPlatformVersion getPlatform(String vendor, String architec
}

public static IArduinoPackage getPackageByProvider(String packager) {
if (!isReady()) {
if (myIsDirty) {
Activator.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
return null;
}
Expand All @@ -868,6 +870,7 @@ public static IArduinoPackage getPackageByProvider(String packager) {
*/
public static void update(boolean reloadFromInternet) {
synchronized (packageIndices) {
myIsUpdating =true;
if (myIsDirty) {
downloadJsons(reloadFromInternet);
readJsons();
Expand Down Expand Up @@ -898,9 +901,8 @@ public static void update(boolean reloadFromInternet) {
}
envVarsNeedUpdating = false;
}

}

myIsUpdating=false;
}

}
20 changes: 19 additions & 1 deletion io.sloeber.core/src/io/sloeber/core/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.time.Instant;

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
Expand Down Expand Up @@ -463,7 +465,23 @@ public static void log(IStatus status) {
* @param monitor
*/
private static synchronized void startup_BoardsManager(IProgressMonitor monitor) {
BoardsManager.update( ConfigurationPreferences.getUpdateJasonFilesFlag());
//ConfigurationPreferences.getUpdateJasonFilesFlag();
Instant currentTime=Instant.now();
Instant latestUpdate= ConfigurationPreferences.getLatestUpdateTime();
Duration requestedDelay=ConfigurationPreferences.getUpdateDelay();
Instant nextUpdate=latestUpdate.plus(requestedDelay);
boolean needsUpdate = nextUpdate.isBefore(currentTime);

// long latestUpdate= getLatestUpdateTime();
// long requestedDelay=getUpdateDelay();
// long currentTime= System.currentTimeMillis();
// boolean needsUpdate = currentTime>(requestedDelay+latestUpdate);
if(needsUpdate) {
BoardsManager.update(true );
ConfigurationPreferences.setLatestUpdateTime(currentTime);
}else {
BoardsManager.update(false );
}

if (!LibraryManager.libsAreInstalled()) {
LibraryManager.InstallDefaultLibraries(monitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static io.sloeber.core.api.Const.*;

import java.io.File;
import java.time.Duration;
import java.time.Instant;

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

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


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

private static boolean getBoolean(String key, boolean defaultValue) {

private static Instant getInstant(String key, Instant defaultValue) {
IEclipsePreferences myScope = ConfigurationScope.INSTANCE.getNode(NODE_ARDUINO);
return myScope.getBoolean(key, defaultValue);
long ret = myScope.getLong(key, 0);
if(ret==0) {
return defaultValue;
}
return Instant.ofEpochSecond(ret);
}

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

public static boolean getUpdateJasonFilesFlag() {
return getBoolean(KEY_UPDATE_JASONS, Defaults.updateJsonFiles);
public static Instant getLatestUpdateTime() {
return getInstant(KEY_LATEST_JSON_UPDATE_TIME, Instant.now());
}

public static void setLatestUpdateTime(Instant currentTime) {
setInstant(KEY_LATEST_JSON_UPDATE_TIME,currentTime);

}

public static void setUpdateJasonFilesFlag(boolean newFlag) {
setBoolean(KEY_UPDATE_JASONS, newFlag);
public static Duration getUpdateDelay() {
// TODO Auto-generated method stub
return Duration.ofDays(10);
}

}

0 comments on commit 48ab9cf

Please sign in to comment.