Changeset 297:e37157a42ed5 in make_builder


Ignore:
Timestamp:
24.12.2010 02:07:54 (9 years ago)
Author:
Max Reichardt <reichardt@…>
Branch:
default
Phase:
public
Transplant:
f364168b1df3426613abedf74b5ba247923a59e5
Message:

Internet connection no longer mandatory for make.xml files with DTD.
Added more intuitive/robust handling of parsing errors - possibly related to corrupted cache.

Location:
src/makebuilder
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/makebuilder/MakeFileBuilder.java

    r260 r297  
    7777 
    7878    /** Cache for source files */ 
    79     protected final SourceScanner sources; 
     79    protected SourceScanner sources; 
    8080 
    8181    /** Temporary directory for merged files */ 
     
    156156        // read/process/cache source files 
    157157        System.out.println("Caching and processing local source files..."); 
    158         sources.scan(makefile, buildFileLoaders, contentHandlers, true, getSourceDirs()); 
     158        try { 
     159            sources.scan(makefile, buildFileLoaders, contentHandlers, true, getSourceDirs()); 
     160        } catch (Exception e) { 
     161            e.printStackTrace(); 
     162            System.out.println(Util.color("Error scanning files. A corrupted cache can cause errors. Trying again without cache.", Util.Color.RED, true)); 
     163            try { 
     164                sources = new SourceScanner(HOME, this); 
     165                sources.scan(makefile, buildFileLoaders, contentHandlers, false, getSourceDirs()); 
     166            } catch (Exception e2) { 
     167                e2.printStackTrace(); 
     168                System.out.println(Util.color("Error still occured. Exiting.", Util.Color.RED, true)); 
     169                System.exit(-1); 
     170            } 
     171        } 
    159172 
    160173        // find local dependencies in "external libraries" 
  • src/makebuilder/SourceScanner.java

    r272 r297  
    9999     * @param sourceDirs Relative source directories 
    100100     */ 
    101     public void scan(Makefile makefile, Collection<BuildFileLoader> loaders, Collection<SourceFileHandler> handlers, boolean useCache, String... sourceDirs) { 
     101    public void scan(Makefile makefile, Collection<BuildFileLoader> loaders, Collection<SourceFileHandler> handlers, boolean useCache, String... sourceDirs) throws Exception { 
    102102 
    103103        // find/register all source directories and files 
     
    140140        } 
    141141 
    142         try { 
    143             ArrayList<SrcFile> tempFiles = new ArrayList<SrcFile>(files.values()); // make copy 
    144  
    145             // load build files 
     142        ArrayList<SrcFile> tempFiles = new ArrayList<SrcFile>(files.values()); // make copy 
     143 
     144        // load build files 
     145        for (SrcFile file : tempFiles) { 
     146            for (BuildFileLoader loader : loaders) { 
     147                loader.process(file, builder.buildEntities, this, builder); 
     148            } 
     149        } 
     150 
     151        // set ownership of files: relate SrcFile instances to BuildEntity instances 
     152        // heuristic: all files with same base name (no extension) as one of build entity's source files belong to build entity 
     153        for (BuildEntity be : builder.buildEntities) { 
     154            for (SrcFile sf : be.sources) { 
     155                String baseName = sf.dir.relative + FS + sf.getRawName(); 
     156                for (SrcFile sf2 : files.subMap(baseName + ".aaa", baseName + ".zzz").values()) { 
     157                    sf2.setOwner(be); 
     158                } 
     159            } 
     160        } 
     161 
     162        // scan/process source files 
     163        for (SourceFileHandler handler : handlers) { 
    146164            for (SrcFile file : tempFiles) { 
    147                 for (BuildFileLoader loader : loaders) { 
    148                     loader.process(file, builder.buildEntities, this, builder); 
     165                if (!file.relative.startsWith("/")) { 
     166                    handler.processSourceFile(file, makefile, this, builder); 
    149167                } 
    150168            } 
    151  
    152             // set ownership of files: relate SrcFile instances to BuildEntity instances 
    153             // heuristic: all files with same base name (no extension) as one of build entity's source files belong to build entity 
    154             for (BuildEntity be : builder.buildEntities) { 
    155                 for (SrcFile sf : be.sources) { 
    156                     String baseName = sf.dir.relative + FS + sf.getRawName(); 
    157                     for (SrcFile sf2 : files.subMap(baseName + ".aaa", baseName + ".zzz").values()) { 
    158                         sf2.setOwner(be); 
    159                     } 
    160                 } 
    161             } 
    162  
    163             // scan/process source files 
    164             for (SourceFileHandler handler : handlers) { 
    165                 for (SrcFile file : tempFiles) { 
    166                     if (!file.relative.startsWith("/")) { 
    167                         handler.processSourceFile(file, makefile, this, builder); 
    168                     } 
    169                 } 
    170             } 
    171  
    172             // release resources (cached lines) 
    173             for (SrcFile file : tempFiles) { 
    174                 file.scanCompleted(); 
    175             } 
    176  
    177         } catch (Exception e) { 
    178             e.printStackTrace(); 
     169        } 
     170 
     171        // release resources (cached lines) 
     172        for (SrcFile file : tempFiles) { 
     173            file.scanCompleted(); 
    179174        } 
    180175 
  • src/makebuilder/handler/MakeXMLLoader.java

    r260 r297  
    2323 
    2424import java.io.File; 
     25import java.net.UnknownHostException; 
    2526import java.util.ArrayList; 
    2627import java.util.List; 
     
    3132import javax.xml.parsers.DocumentBuilder; 
    3233import javax.xml.parsers.DocumentBuilderFactory; 
     34import javax.xml.parsers.ParserConfigurationException; 
    3335 
    3436import org.w3c.dom.Document; 
     
    5961    private final Class<?>[] buildEntityClasses; 
    6062 
     63    /** Objects for parsing XML */ 
     64    static private final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
     65    static private DocumentBuilder dbuilder; 
     66 
     67    static { 
     68 
     69        // Initialize document builder 
     70        try { 
     71            dbuilder = factory.newDocumentBuilder(); 
     72        } catch (ParserConfigurationException e) { 
     73            e.printStackTrace(); 
     74            System.exit(-1); 
     75        } 
     76    } 
     77 
    6178    public MakeXMLLoader(Class<?>... buildEntityClasses) { 
    6279        this.buildEntityClasses = buildEntityClasses; 
     
    8097 
    8198        // parse XML 
    82         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
    83         DocumentBuilder dbuilder = factory.newDocumentBuilder(); 
    84         Document doc = dbuilder.parse(file.absolute); 
     99        Document doc = null; 
     100        try { 
     101            doc = dbuilder.parse(file.absolute); 
     102        } catch (UnknownHostException ex) { 
     103            System.out.println(Util.color("Disabling DTD parsing, because there seems to be no internet connection available.", Util.Color.Y, false)); 
     104 
     105            // ok, we're not connected to the internet - disable DTD 
     106            factory.setValidating(false); 
     107            factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); 
     108            dbuilder = factory.newDocumentBuilder(); 
     109            doc = dbuilder.parse(file.absolute); 
     110        } 
    85111 
    86112        for (Class<?> c : buildEntityClasses) { 
Note: See TracChangeset for help on using the changeset viewer.