All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yiwowang.intellij.finding.base.util.CacheUtils Maven / Gradle / Ivy

The newest version!
package com.yiwowang.intellij.finding.base.util;

import com.google.gson.Gson;
import com.yiwowang.intellij.finding.base.bean.ComponentCache;
import com.yiwowang.intellij.finding.base.bean.GradleData;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

public class CacheUtils {
    public static File getComponentsFile(File projectDir) {
        if (projectDir == null) {
            return null;
        }
        return new File(projectDir, "build/finding/dependencies.json");
    }

    public static File getComponentCacheFile(File projectDir) {
        if (projectDir == null) {
            return null;
        }
        return new File(projectDir, "build/finding/component-cache.json");
    }

    public static void saveComponentCache(File file, ComponentCache componentCache) {
        String json = new Gson().toJson(componentCache);
        try {
            FileUtils.write(file, json, Charset.defaultCharset());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static ComponentCache parseComponentCache(File file) {
        try {
            String json = FileUtils.readFileToString(file, Charset.defaultCharset());
            return new Gson().fromJson(json, ComponentCache.class);
        } catch (IOException e) {
        }
        return null;
    }

    public static GradleData parseGradleData(File file) {
        try {
            String json = FileUtils.readFileToString(file, Charset.defaultCharset());
            return new Gson().fromJson(json, GradleData.class);
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return null;
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy