Changeset 13987


Ignore:
Timestamp:
Nov 7, 2019 3:29:44 PM (10 days ago)
Author:
mjohnsson
Message:

#5870 review fixes.

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

Legend:

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

    r13981 r13987  
    13711371        fc.guidManager().processDependentFiles();
    13721372        log.debug("Checksum for generated files");
    1373         fc.guidManager().writeFileMD5(log);
     1373        fc.guidManager().printFileChecksums(log);
    13741374        log.debug("... code generated.");
    13751375        ASTNode.endStep("generateCode()");
     
    21822182                log.debug("Generated file '" + file + "'.");
    21832183                if (fc != null) {
    2184                     try {
    2185                         fc.guidManager().createFileMD5(new FileReader(file), file.getName(), log);
    2186                     } catch (FileNotFoundException e) {
    2187                         throw e;
    2188                     } catch (IOException e) {
    2189                         // Should not happen
    2190                     }
     2184                    fc.guidManager().computeFileChecksum(new FileReader(file), file.getName(), log);
    21912185                    fc.guidManager().addDependentFile(file);
    21922186                }
  • branches/dev-mj-2630/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/GUIDManager.java

    r13981 r13987  
    55import java.io.ByteArrayOutputStream;
    66import java.io.File;
    7 import java.io.FileReader;
    8 import java.io.FileWriter;
    97import java.io.IOException;
    108import java.io.InputStream;
     
    9492    public ArrayList<String> filesMd5 = new ArrayList<String>();
    9593
    96     public void writeFileMD5(ModelicaLogger log) {
     94    public void printFileChecksums(ModelicaLogger log) {
    9795        for (String fileMd5 : filesMd5) {
    9896            log.debug(fileMd5);
     
    10098    }
    10199
    102     public void createFileMD5(Reader file, String fileName, ModelicaLogger log) throws IOException {
    103         MessageDigest md5;
    104         try {
    105             md5 = MessageDigest.getInstance("MD5");
    106         } catch (NoSuchAlgorithmException e) {
    107             return;
    108         }
    109 
    110         try (final BufferedReader reader = new BufferedReader(file)) {
    111             String line = reader.readLine();
    112             while (line != null) {
    113                 // A naive implementation that is expected to create a digest different from what a command
    114                 // line tool would create. No lines breaks are included in the digest, and no
    115                 // character encodings are specified.
    116                 md5.update(line.getBytes(Charset.forName("UTF-8")));
    117                 line = reader.readLine();
    118             }
    119         }
    120        
    121         String Value = new BigInteger(1,md5.digest()).toString(16);
    122         filesMd5.add("Generated file "+ fileName + " with checksum " + Value);
     100    public void computeFileChecksum(Reader file, String fileName, ModelicaLogger log) {
     101        String checksum = calculateMD5Checksum(file);
     102        filesMd5.add("Generated file "+ fileName + " with checksum " + checksum);
    123103    }
    124104
    125105    private String getGuid() {
    126         String guid;
     106        String guid = calculateMD5Checksum(new InputStreamReader(source.openInput()));
     107        for (Token token : tokens) {
     108            token.resetFoundFirst();
     109        }
     110
     111        return guid;
     112    }
     113   
     114    public String calculateMD5Checksum(Reader r) {
    127115        try {
    128116            final MessageDigest md5 = MessageDigest.getInstance("MD5");
    129117
    130             try (final BufferedReader reader = new BufferedReader(new InputStreamReader(source.openInput()))) {
     118            try (final BufferedReader reader = new BufferedReader(r)) {
    131119                String line = reader.readLine();
    132120                while (line != null) {
     
    138126                }
    139127            }
    140 
    141             guid = new BigInteger(1,md5.digest()).toString(16);
     128        return new BigInteger(1,md5.digest()).toString(16);
     129       
    142130        }  catch (IOException | NoSuchAlgorithmException e) {
    143131            throw new RuntimeException(e);
    144132        }
    145         for (Token token : tokens) {
    146             token.resetFoundFirst();
    147         }
    148 
    149         return guid;
    150133    }
    151134
Note: See TracChangeset for help on using the changeset viewer.