Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.espressif.idf.core.tools;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.eclipse.core.runtime.Platform;

import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.tools.vo.EimJson;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand All @@ -13,35 +15,43 @@ public class EimIdfConfiguratinParser
{
private EimJson eimJson;
private Gson gson;

public EimIdfConfiguratinParser()
{
gson = new GsonBuilder().setPrettyPrinting().enableComplexMapKeySerialization()
.excludeFieldsWithoutExposeAnnotation().create();
}

private void load() throws IOException
{
try (FileReader fileReader = new FileReader(
Platform.getOS().equals(Platform.OS_WIN32) ? EimConstants.EIM_WIN_PATH : EimConstants.EIM_POSIX_PATH))
String path = Platform.getOS().equals(Platform.OS_WIN32) ? EimConstants.EIM_WIN_PATH
: EimConstants.EIM_POSIX_PATH;

File file = new File(path);
if (!file.exists())
{
Logger.log("EIM config file not found: " + path); //$NON-NLS-1$
return;
}

try (FileReader fileReader = new FileReader(file))
{
eimJson = gson.fromJson(fileReader, EimJson.class);
}
}


public EimJson getEimJson(boolean reload) throws IOException
{
if (reload)
{
load();
}

if (eimJson == null)
{
load();
}

return eimJson;
}
}
Loading