Tapatalk

Applying Artistic Style Formatting to multiple .java scripts

Applying Artistic Style Formatting to multiple .java scripts

2

    14:43 - Oct 29#1

    I'm using the following version of UltraEdit:
    0g60iyzr.png (14.85KiB)
    I'm trying to apply Artisitc Style Formatting to a list of java files/scripts via the command line.

    The formatting settings that I'm trying to apply, are as follows:
    Artisitc Style Formatter Java.png (32.97KiB)
    When I click the Reformat button while having a java script open, it works as expected.
    The command line options which are the result of the above setup are as follows (copied from the above screenshot):

    Code: Select all

    --style=java --mode=java -Y --convert-tabs --break-blocks --break-elseifs -j --break-after-logical --pad-oper --pad-header
    The way I am trying to apply this formatting in bulk, is with a following batch file:

    Code: Select all

    cd "C:\PathToFolderStructureWithJavaFiles"
    dir/s/b *.java > FileList.txt
    timeout 3
    "C:\Program Files\IDM Computer Solutions\UltraEdit\uedit64.exe" /fni /f FileList.txt --style=java --mode=java -Y --convert-tabs --break-blocks --break-elseifs -j --break-after-logical --pad-oper --pad-header
    I'm changing the current directory to the folder with all the subfolder that contain the Java scripts.
    Then I'm generating the list of files (FileList.txt) with the ".java" extension in the current directory with:

    Code: Select all

    dir/s/b *.java > FileList.txt
    I use the timeout command to make sure that the file list is generated.
    Then, using the information I found on UltraEdit online help I run the final command, which should open the new instance of UltraEdit (/fni) and apply to the files specified in a separate TXT file (/f FileList.txt) the prescribed formatting.
    What happens is the instance of UltraEdit is opened, along with all the files specified in the FileList.txt file, however they are not being reformatted.

    6,688587
    Grand MasterGrand Master
    6,688587

      18:12 - Oct 29#2

      Some hints first:

      The version information in the About window can be selected with a pointing device (mouse) and copied into the clipboard as text with Ctrl+C for pasting it as text with Ctrl+V into another application.

      Code: Select all

      dir/s/b *.java > FileList.txt
      That command line is of invalid syntax. It works nevertheless because of cmd.exe accesses the file system several times to find out that there is no subdirectory dir with a subdirectory s with a program or script with file name b to execute. The automatic error correction applied by cmd.exe is inserting now first a space before / and detecting now that the command to execute is the cmd internal command dir (argument 0) which for a valid syntax must be separated with a space from the first option /s (argument 1). dir finds out next that /s/b is most likely not a file or directory with wrong directory separator, but the option /s (argument 1) and the option /b (argument 2) with a space missing between the two options two define them as two argument strings and not just one. I recommend reading the Microsoft documentation about Naming Files, Paths, and Namespaces. Run also in a command prompt window cmd /? and next dir /? and read the output usage helps. Some Windows commands support combining options into one argument string like findstr (executable with full name %SystemRoot%\System32\findstr.exe) with something like /IRV (case-insensitive regular expression with inverted result), but most Windows commands do not (at least not officially).

      The command line options shown in the Artistic Style Formatter window are not those supported by uedit64.exe. These are the options used by UltraEdit on running in background astyle.exe installed with UltraEdit into the subdirectory GNU of the program files directory of UltraEdit.

      There could be most likely used a batch file with following single command line (not tested):

      Code: Select all

      @for /R "C:\PathTo\Folder\Structure\WithJavaFiles" %%I in (*.java) do @"C:\Program Files\IDM Computer Solutions\UltraEdit\GNU\astyle.exe" --style=java --mode=java -Y --convert-tabs --break-blocks --break-elseifs -j --break-after-logical --pad-oper --pad-header "%%I"
      Even better would be:

      Code: Select all

      @for /F "delims=" %%I in ('dir "C:\PathTo\Folder\Structure\WithJavaFiles\*.java" /A-D /B /S 2^>nul') do @"C:\Program Files\IDM Computer Solutions\UltraEdit\GNU\astyle.exe" --style=java --mode=java -Y --convert-tabs --break-blocks --break-elseifs -j --break-after-logical --pad-oper --pad-header "%%I"
      The documentation of the open source application Artistic Style Formatter is available online if you are interested in the options and how to use this console application for reformatting lots of files from withing a command prompt window or with using a batch file. The latest version of this application in binary can be downloaded also online and used with UltraEdit on replacing astyle.exe in the subdirectory GNU in the program files directory with the downloaded latest version. But rename the existing astyle.exe installed with UltraEdit before copying the downloaded latest version into the subdirectory GNU as there is no guarantee that the currently latest version is 100% compatible with the options passed by UltraEdit to the executable on reformatting a file opened in UltraEdit.

        18:35 - Oct 29#3

        One more information:

        When the Windows Command Processor executes a batch file, it never reads the next command line from a batch file before the execution of the cmd internal command or the started executable finished, even if the executable is a Windows GUI application. The usage of %SystemRoot%\System32\timeout.exe is therefore not necessary in a batch file, except a user should see something for a specified number of seconds. The executable timeout.exe does not terminate until the specified number of seconds expired or the user pressed a key to break the waiting for the timeout. If cmd would not wait with opening the batch file, reading the next line, parsing it and closing the batch file before a started executable terminated itself, timeout would never work and also no batch file.

        There is the cmd internal command start which can be used in a batch file to instruct cmd to start an application different like starting the executable as separate, parallel executed and detached process, or with option /B running the executable as child process using same standard input, standard output, standard error streams as cmd.exe processing the batch file, or with option /WAIT as separate and parallel executed process, but wait for self-termination of the parallel running process before continue the batch processing. The usage of start with option /WAIT makes in most cases no sense in a batch file.

        The execution of an executable from within a command prompt window is different. In this case cmd.exe waits by default only for the self-termination of a started console application before the prompt becomes available again for next user input. But if a Windows GUI executable like notepad.exe is started from within a command prompt window, the program is started as parallel executed, detached process giving the user the possibility to switch back from Notepad window to the command prompt window and type the next command line to execute by the Windows Command Processor. If notepad.exe is written as posted here into a batch file and the next line is @echo Notepad exited.& pause and the batch file is executed, there is Notepad started and the user can see on switching to the console window, that no message is output. The user must exit Notepad started by cmd processing the batch file (not any other instance of Notepad) before the user can see the message in the console window and the prompt to press any key to finish the batch file processing as no more line in the batch file.
        Best regards from an UC/UE/UES for Windows user from Austria

        2

          9:46 - Oct 30#4

          Thanks a lot @Mofi for the comprehensive answer. Based on that I realized I don't need to use a batch file to run the reformat in bulk.
          The reformat was part of a larger Excel VBA subroutine, and I now I'm just calling the command line, using the Shell command in VBA.
          Based on your response I settled on the following command line syntax to achieve my goal (this is the command that I pass to the Shell call in VBA):

          Code: Select all

          cmd.exe /C for /R "C:\PathTo\Folder\Structure\WithJavaFiles" %I in (*.java) do "C:\Program Files\IDM Computer Solutions\UltraEdit\GNU\astyle.exe" --style=java --mode=java -Y --convert-tabs --break-blocks --break-elseifs -j --break-after-logical --pad-oper --pad-header --suffix=none "%I"
          I added the --suffix=none option for the Artistic Style Formatter executable, because otherwise the reformatting was also producing backup files with an .orig suffix.