Changeset 13954


Ignore:
Timestamp:
Nov 5, 2019 12:34:03 PM (12 days ago)
Author:
mjohnsson
Message:

Check sum of files.

Location:
branches/dev-mj-2630/Compiler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-mj-2630/Compiler/ModelicaCompiler/src/jastadd/ModelicaCompiler.jrag

    r13946 r13954  
    21772177            SplitFilesCodeStream stream = new SplitFilesCodeStream(outFile, debugGen, header);
    21782178            gen.generate(tmpl, stream, header);
     2179           
    21792180            for (File file : stream.files()) {
     2181                try {
     2182                    fc.guidManager().createFileMD5(outFile, new File(outDir, outFile.getName()), log);
     2183                } catch (IOException e) {}
     2184               
    21802185                log.debug("Generated file '" + file + "'.");
    21812186                if (fc != null) {
  • branches/dev-mj-2630/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/GUIDManager.java

    r13732 r13954  
    55import java.io.ByteArrayOutputStream;
    66import java.io.File;
     7import java.io.FileReader;
     8import java.io.FileWriter;
    79import java.io.IOException;
    810import java.io.InputStream;
     
    2123import java.util.List;
    2224
     25import org.jmodelica.util.logging.ModelicaLogger;
     26
    2327public class GUIDManager {
    2428
     
    8589    public void addDependentString(String input, ByteArrayOutputStream output) {
    8690        dependentFiles.add(new StringOpenable(input, output));
     91    }
     92
     93    public void createFileMD5(File file, File outDirectory, ModelicaLogger log) throws IOException {
     94        MessageDigest md5;
     95        try {
     96            md5 = MessageDigest.getInstance("MD5");
     97        } catch (NoSuchAlgorithmException e) {
     98            return;
     99        }
     100
     101        try (final BufferedReader reader = new BufferedReader(new FileReader(file))) {
     102            String line = reader.readLine();
     103            while (line != null) {
     104                // A naive implementation that is expected to create a digest different from what a command
     105                // line tool would create. No lines breaks are included in the digest, and no
     106                // character encodings are specified.
     107                md5.update(line.getBytes(Charset.forName("UTF-8")));
     108                line = reader.readLine();
     109            }
     110        }
     111        try (final FileWriter fw = new FileWriter(outDirectory)) {
     112            String Value = new BigInteger(1,md5.digest()).toString(16);
     113            log.debug("CheckSum of " + file.getName() + " :" + Value);
     114            fw.write("CheckSum of " + file.getName() + " :" + Value);
     115           
     116        }
    87117    }
    88118
Note: See TracChangeset for help on using the changeset viewer.