package com.microchip.mplab.ipelib; import com.microchip.crownking.mplabinfo.DeviceSupport; import com.microchip.mplab.libs.packmanagerservice.interfaces.Device; import com.microchip.mplab.libs.packmanagerservice.interfaces.DeviceProvider; import com.microchip.mplab.libs.packmanagerservice.interfaces.MPLABPackContext; import com.microchip.mplab.libs.packmanagerservice.interfaces.PackRelease; import com.microchip.mplab.libs.packmanagerservice.interfaces.PackRepoProvider; import com.microchip.mplab.libs.packmanagerservice.packmanagerservicefactory.PackManagerService; import com.microchip.mplab.logger.MPLABLogger; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.Map.Entry; import java.util.logging.Level; public final class PackUtils { private final PackRepoProvider packRepoProvider = PackManagerService.getPackRepoProvider(); private final DeviceProvider deviceProvider = PackManagerService.getDeviceProvider(); private static PackUtils packUtils; private MPLABPackContext pack = null; private PackUtils() { } public static PackUtils getPackUtils() { if (packUtils == null) { packUtils = new PackUtils(); } return packUtils; } public boolean isDeviceDeprecated(String deviceName) { Device deviceInfo = this.packRepoProvider.getDevice(deviceName); boolean isDeprecated = false; try { isDeprecated = deviceInfo.isDeprecated(); } catch (Exception var5) { MPLABLogger.mplog.log(Level.INFO, var5.toString()); } return isDeprecated; } public boolean isPackDeprecated(String deviceName) { boolean packDeprecated = false; MPLABPackContext compatiblePack = this.getInstalledLatestCompatibleDFP(deviceName); try { packDeprecated = this.packRepoProvider.isPackDeprecated(compatiblePack.getName()); } catch (Exception var5) { MPLABLogger.mplog.log(Level.INFO, var5.toString()); } return packDeprecated; } public String getReplacementForDeprecatedPack(String deviceName) { String replacementPackName = "NA"; MPLABPackContext compatiblePack = this.getInstalledLatestCompatibleDFP(deviceName); if (compatiblePack != null) { MPLABPackContext replacementPack = this.packRepoProvider.getReplacementPack(compatiblePack.getName()); if (replacementPack != null) { replacementPackName = replacementPack.getName(); } } return replacementPackName; } public MPLABPackContext getInstalledLatestCompatibleDFP(String deviceName) { MPLABPackContext compatiblePack = null; try { compatiblePack = this.packRepoProvider.getLatestInstalledCompatibleDFP(deviceName, "MPLAB X IDE", this.getMPLABXVersion()); } catch (Exception var4) { MPLABLogger.mplog.log(Level.INFO, var4.toString()); } return compatiblePack; } public String getMPLABXVersion() { String version = "0.0"; Optional> mplabVersionInfo = DeviceSupport.getMPLABIPEVersionInfo(); if (mplabVersionInfo.isPresent() && !"0.0".equalsIgnoreCase(mplabVersionInfo.get().getValue())) { version = mplabVersionInfo.get().getValue(); } return version; } public String getMPLABXName() { String mplabxName = ""; Optional> mplabVersionInfo = DeviceSupport.getMPLABIPEVersionInfo(); if (mplabVersionInfo.isPresent() && !mplabVersionInfo.get().getKey().isEmpty()) { mplabxName = mplabVersionInfo.get().getKey(); } return mplabxName; } public List getInstalledCompatiblePackReleases(String packName, String deviceName) { new ArrayList(); List installedCompatiblePacks = new ArrayList<>(); try { for (PackRelease pack : this.packRepoProvider.getInstalledReleases(packName)) { MPLABPackContext packContext = new MPLABPackContext(packName, pack.getVersion(), pack.getVendor()); boolean value = this.packRepoProvider.isPackCompatible(deviceName, packContext, this.getMPLABXName(), this.getMPLABXVersion()); if (value) { installedCompatiblePacks.add(pack); } } } catch (Exception var9) { MPLABLogger.mplog.log(Level.INFO, var9.toString()); } return installedCompatiblePacks; } public void UpdateCache() { try { this.packRepoProvider.updateCache(); } catch (Exception var2) { MPLABLogger.mplog.log(Level.INFO, var2.toString()); } } public void SetPackInfo(String packName, String packVersion, String packVendor) { this.pack = new MPLABPackContext(packName, packVersion, packVendor); } public MPLABPackContext GetPackInfo() { return this.pack; } }