protected void doFormatFile(File file, ResultCollector rc, Properties hashCache, String basedirPath, boolean dryRun)
            throws IOException, BadLocationException, MojoFailureException, MojoExecutionException {
        Log log = getLog();
        log.debug("Processing file: " + file);
        String code = readFileAsString(file);
        String originalHash = sha512hash(code);

        String canonicalPath = file.getCanonicalPath();
        String path = canonicalPath.substring(basedirPath.length());
        String cachedHash = hashCache.getProperty(path);
        if (cachedHash != null && cachedHash.equals(originalHash)) {
            rc.skippedCount++;
            log.debug("File is already formatted.");
            return;
        }

        Result result;
        if (file.getName().endsWith(".java") && javaFormatter.isInitialized()) {
            if (skipJavaFormatting) {
                getLog().info("Java formatting is skipped");
                result = Result.SKIPPED;
            } else {
                result = this.javaFormatter.formatFile(file, this.lineEnding, dryRun);
            }
        } else if (file.getName().endsWith(".js") && jsFormatter.isInitialized()) {
            if (skipJsFormatting) {
                getLog().info("Javascript formatting is skipped");
                result = Result.SKIPPED;
            } else {
                result = this.jsFormatter.formatFile(file, this.lineEnding, dryRun);
            }
        } else if (file.getName().endsWith(".html") && htmlFormatter.isInitialized()) {
            if (skipHtmlFormatting) {
                getLog().info("Html formatting is skipped");
                result = Result.SKIPPED;
            } else {
                result = this.htmlFormatter.formatFile(file, this.lineEnding, dryRun);
            }
        } else if (file.getName().endsWith(".xml") && xmlFormatter.isInitialized()) {
            if (skipXmlFormatting) {
                getLog().info("Xml formatting is skipped");
                result = Result.SKIPPED;
            } else {
                result = this.xmlFormatter.formatFile(file, this.lineEnding, dryRun);
            }
        } else if (file.getName().endsWith(".json") && jsonFormatter.isInitialized()) {
            if (skipJsonFormatting) {
                getLog().info("json formatting is skipped");
                result = Result.SKIPPED;
            } else {
                result = this.jsonFormatter.formatFile(file, this.lineEnding, dryRun);
            }
        } else if (file.getName().endsWith(".css") && cssFormatter.isInitialized()) {
            if (skipCssFormatting) {
                getLog().info("css formatting is skipped");
                result = Result.SKIPPED;
            } else {
                result = this.cssFormatter.formatFile(file, this.lineEnding, dryRun);
            }
        } else {
            result = Result.SKIPPED;
        }

        switch (result) {
        case SKIPPED:
            rc.skippedCount++;
            return;
        case SUCCESS:
            rc.successCount++;
            break;
        case FAIL:
            rc.failCount++;
            return;
        default:
            break;
        }

        String formattedCode = readFileAsString(file);
        String formattedHash = sha512hash(formattedCode);
        hashCache.setProperty(path, formattedHash);

        if (originalHash.equals(formattedHash)) {
            rc.skippedCount++;
            log.debug("Equal hash code. Not writing result to file.");
            return;
        }

        writeStringToFile(formattedCode, file);
    }
protected void doFormatFile ( File file , ResultCollector rc , Properties hashCache , String basedirPath , boolean dryRun ) throws IOException , BadLocationException , MojoFailureException , MojoExecutionException { Log log = getLog ( ) ; log . debug ( "Processing file: " + file ) ; String code = readFileAsString ( file ) ; String originalHash = sha512hash ( code ) ; String canonicalPath = file . getCanonicalPath ( ) ; String path = canonicalPath . substring ( basedirPath . length ( ) ) ; String cachedHash = hashCache . getProperty ( path ) ; if ( cachedHash != null && cachedHash . equals ( originalHash ) ) { rc . skippedCount ++ ; log . debug ( "File is already formatted." ) ; return ; } Result result ; if ( file . getName ( ) . endsWith ( ".java" ) && javaFormatter . isInitialized ( ) ) { if ( skipJavaFormatting ) { getLog ( ) . info ( "Java formatting is skipped" ) ; result = Result . SKIPPED ; } else { result = this . javaFormatter . formatFile ( file , this . lineEnding , dryRun ) ; } } else if ( file . getName ( ) . endsWith ( ".js" ) && jsFormatter . isInitialized ( ) ) { if ( skipJsFormatting ) { getLog ( ) . info ( "Javascript formatting is skipped" ) ; result = Result . SKIPPED ; } else { result = this . jsFormatter . formatFile ( file , this . lineEnding , dryRun ) ; } } else if ( file . getName ( ) . endsWith ( ".html" ) && htmlFormatter . isInitialized ( ) ) { if ( skipHtmlFormatting ) { getLog ( ) . info ( "Html formatting is skipped" ) ; result = Result . SKIPPED ; } else { result = this . htmlFormatter . formatFile ( file , this . lineEnding , dryRun ) ; } } else if ( file . getName ( ) . endsWith ( ".xml" ) && xmlFormatter . isInitialized ( ) ) { if ( skipXmlFormatting ) { getLog ( ) . info ( "Xml formatting is skipped" ) ; result = Result . SKIPPED ; } else { result = this . xmlFormatter . formatFile ( file , this . lineEnding , dryRun ) ; } } else if ( file . getName ( ) . endsWith ( ".json" ) && jsonFormatter . isInitialized ( ) ) { if ( skipJsonFormatting ) { getLog ( ) . info ( "json formatting is skipped" ) ; result = Result . SKIPPED ; } else { result = this . jsonFormatter . formatFile ( file , this . lineEnding , dryRun ) ; } } else if ( file . getName ( ) . endsWith ( ".css" ) && cssFormatter . isInitialized ( ) ) { if ( skipCssFormatting ) { getLog ( ) . info ( "css formatting is skipped" ) ; result = Result . SKIPPED ; } else { result = this . cssFormatter . formatFile ( file , this . lineEnding , dryRun ) ; } } else { result = Result . SKIPPED ; } switch ( result ) { case SKIPPED : rc . skippedCount ++ ; return ; case SUCCESS : rc . successCount ++ ; break ; case FAIL : rc . failCount ++ ; return ; default : break ; } String formattedCode = readFileAsString ( file ) ; String formattedHash = sha512hash ( formattedCode ) ; hashCache . setProperty ( path , formattedHash ) ; if ( originalHash . equals ( formattedHash ) ) { rc . skippedCount ++ ; log . debug ( "Equal hash code. Not writing result to file." ) ; return ; } writeStringToFile ( formattedCode , file ) ; }
Format individual file.

@param file
the file
@param rc
the rc
@param hashCache
the hash cache
@param basedirPath
the basedir path
@throws IOException
Signals that an I/O exception has occurred.
@throws BadLocationException
the bad location exception