Search in sources :

Example 1 with EtaInfo

use of com.typelead.gradle.utils.EtaInfo in project gradle-eta by typelead.

the class EtaSetupEnvironment method fetchEtaInfo.

private EtaInfo fetchEtaInfo(EtlasCommand etlas, ResolvedExecutable eta, boolean changed) {
    File infoFile = getProject().getLayout().getBuildDirectory().file(INFO_FILENAME).get().getAsFile();
    List<String> lines;
    if (!infoFile.exists() || changed) {
        lines = etlas.getLanguagesAndExtensions();
        final StringBuilder sb = new StringBuilder();
        for (String line : lines) {
            println(sb, line);
        }
        FileUtils.write(infoFile, sb.toString());
    } else {
        try {
            lines = new ArrayList<String>();
            BufferedReader in = null;
            try {
                in = new BufferedReader(new FileReader(infoFile));
                String line = null;
                while ((line = in.readLine()) != null) {
                    lines.add(line);
                }
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        } catch (IOException io) {
            throw new GradleException("fetchEtaInfo: While reading " + infoFile.getPath() + ", encountered an IOException", io);
        }
    }
    Set<String> validLanguages = new LinkedHashSet<String>();
    Set<String> validExtensions = new LinkedHashSet<String>();
    Iterator<String> it = lines.iterator();
    validLanguages.add(it.next());
    validLanguages.add(it.next());
    while (it.hasNext()) {
        validExtensions.add(it.next());
    }
    return new EtaInfo(PrintHelper.friendlyVersion(eta.getVersion()), validLanguages, validExtensions);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) BufferedReader(java.io.BufferedReader) EtaInfo(com.typelead.gradle.utils.EtaInfo) FileReader(java.io.FileReader) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile)

Aggregations

EtaInfo (com.typelead.gradle.utils.EtaInfo)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 GradleException (org.gradle.api.GradleException)1 OutputFile (org.gradle.api.tasks.OutputFile)1