How to specify the file encoding in IntelliJ's command line formatter - intellij-idea

After running IntelliJ's command line code formatter on a set of Java source files the German characters in the source are replaced with "garbage".
How can I configure the input and output encoding of the formatter?
I tried adding -encoding iso-8859-15 -docencoding iso-8859-15 as an option to the formatter command line but those options are not recognized.
I also tried creating an idea.properties file with the following content:
-Dfile.encoding=ISO-8859-15
And running the formatter with the environment variable IDEA_PROPERTIES set pointing to this file:
C:\>set IDEA_PROPERTIES="E:\project\config-files\idea.properties"
I also tried inserting the option -Dfile.encoding=ISO-8859-15 directly in the idea.bat file (which is called by the format.bat.
None of these worked.
How can I ensure that the formatter respects the encoding of these source files?
Command line used now is like
C:\>"C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2.4\bin\format.bat" -r E:\project\java style -m *.java -s e:\project\config-files\CodeStyleSettings.xml
Note: If I convert the source file to UTF-8 before running the formatter the formatting works as expected (the German characters are preserved).
Another note: If the format code is run within the IDE GUI it is possible to set the file encoding in the project options. The command line formatter does not make use of a project so these settings are not respected.
The goal is to turn this into a step in our automated process that can be run by any of a number of users. So I'd like to avoid changes to config files in a user's specific directory like the IDE configuration directory.

Related

How to set the user define path for log/output/report file of robot framework on command line

I am using robot framework with pycharm.
I am running all the tests of my folder using
testfolder>robot .
I want to set the path of log/output/report file to my customized location.
I have change the path of screenshot as D:/Screenshot folder in my variables.robot.
But How to set the path for mentioned file?
I also wanted to know
What is the common to run on terminal/cmd to run all the scripts of same folder with defined log file path?
Robot Framework User Guide walks you through the Basic Usage in quite good detail. Additionally the same document contains a section for the Different Command Line Options Available where you can get quite good picture on the options you have available.
Specifically --outputdir or -d will make Robot to save Log.html, Report.html and output.xml to the specified folder.
As mentioned by #Morkkis, the -d or --outputdir would do the trick. Also, it works for both command line and PyCharm Arguments field
For the screenshots, you could use the screenshot_directory command line argument. Please, check the Keyworkd documentation for more details ScreenShot Library Documentation
Also, for the report/logs file location, you can use these variables:
${LOG LEVEL} Current log level.
${OUTPUT FILE} An absolute path to the output file.
${LOG FILE} An absolute path to the log file or string NONE when no log file is created.
${REPORT FILE} An absolute path to the report file or string NONE when no report is created.
${DEBUG FILE} An absolute path to the debug file or string NONE when no debug file is created.
${OUTPUT DIR} An absolute path to the output directory.

javadoc: error cannot read Input length = 1 (IntelliJ - no maven) [duplicate]

I know there are plenty of questions about this problem, but no one of the solved it for me! I'm using the Community Edition of IntelliJ and I tried to run JavaDoc through the IDE. Everytime and it doesn't matter fo which file, I run JavaDoc I got the following output:
javadoc: error - cannot read Input length = 1
I already figured out, that it might be an encoding problem... I'm working on a Windows 10 maschine. I already tried the following:
JavaDoc argfile encoding error
Start the terminal from IntelliJ with cmd.exe /K chcp 65001 instead of the default one cmd.exe to set the charset to UTF-8
I also set the project's default charset through the IntelliJ settings to UTF-8 (See: This Guide)
The problem seems to be the javadoc_args file respectively the path to that file... The path is C:\Users\Somebody Müller\AppData\Local\Temp\javadoc_args. Also if I view the file from IntelliJ, all ü characters are replaced by an unknown symbol.
I know that I could generate the documentation through a maven plugin, but I would prefer to do it via the IntelliJ IDE...
Could somebody identify the problem in detail and/or provide a solution or maybe parts of it?
EDIT
skomisa described the situation/behaviour in easy words:
For me the javadoc_args file does not exist! I see it is named in the Javadoc window as an argument to javadoc.exe, and if I click the link its content is shown in a pop up window within Intellij IDEA, but if I check in File Explorer there is no such file. Is this the case for you as well? I have no idea how it gets generated. Also, I created a project in a folder named Müller and the ü was rendered as � within the popup window that showed the content of javadoc_args.
UPDATE 04/12/2018
As skomisa already commented, JetBrains plans to fix this bug in a future version, likely in version 2019.1 (Build 191.2458).
UPDATE 22/02/2019
I know this question is quite old but it seems to be still relevant. I didn't check up to now if JetBrains fixed the bug but a similar one occurred for me when I try to open an JavaFX fxml externally inside of the SceneBuilder. In another post about renaming a Windows 10 user directory I found a possible workaround at least for Windows users! Just create an additional user directory without ü in the path and link to the existing one:
C:
CD\Users
MKLINK /J Müller Mueller
If you now uses the link as directory for project paths it should work fine.
I am unable to generate the Javadoc for a project in Intellij IDEA if the name of the path contains the character ü (u with umlaut). The workaround is to rename the project so that the project directory file path does not contain an umlaut.
To reproduce:
Use the project wizard to create a trivial Java Hello World project where the root directory name contains ü. I used Müller for testing purposes.
Ensure that the class for main() contains valid Javadoc documentation.
Build and run the project to verify that there are no unexpected issues.
Select Tools > Generate Javadoc, specify an empty Output Directory and click OK.
Javadoc creation fails with the error - cannot read Input length = 1 (shown below), and clicking the link to C:\Users\johndoe\AppData\Local\Temp\javadoc_args shows that the ü in the file path is (mis)represented as �, which presumably is the cause of the Javadoc error.
However, once the root directory is renamed from Müller to Muller (to remove the umlaut) the Javadoc creation works:
As a sanity check, rename the project from Muller back to Müller to reintroduce the error:
Notes:
As noted in the comments, the javadoc_args file does not exist, and I see no way to prevent its use during the Javadoc creation process.
Having the project name as Müller is not an issue; it's having ü within the project's file path that causes the problem.
Environment: Windows 10 + Intellij IDEA 2018 3.1 EAP (Ultimate Edition) + Open JDK 10.
I raised a bug report with JetBrains for this: https://youtrack.jetbrains.com/issue/IDEA-202849
Update 11/25/18
There is a workaround for this issue without needing to rename the project's path:
Run Generate Javadoc and let it fail.
Click the link to the file .../javadoc_args shown in the Javadoc window.
Copy and paste the content of the file javadoc_args into a text editor.
Correct any characters that are misrepresented (e.g. change M�ller to Müller).
Save the file using UTF-8 encoding, and the same absolute filename.
Open a Command Prompt window.
Copy the entire javadoc.exe command from the Javadoc window in Intellij IDEA and paste it to the Command Prompt window.
Submit the line that was pasted. It will now work because the project's path is correctly specified in the file javadoc_args.
Today (21-aug-2021) I tried to generate a javadoc but it failed. The error message was:
javadoc: error - cannot read Input length = 1
In my case it referred to the length of the path to the file, which is shown below.
D:\Tecnologia(ytrabajo)ysistemas26sep2020\misiontic2022\U El Bosque\UEB académico\Ciclo 2\Programación Básica\NetBProjects\R5DTO_DAOMVC_GUI
So I shortened the path to the following:
D:\Tecnologia(ytrabajo)ysistemas26sep2020\misiontic2022\NBProjects(m)\R5DTO_DAOMVC_GUI
As one can see, this route is shorter than the first so NetBeans could access it and generate the javadoc.
Note: It is not possible that NetBeans could not read the location because of the following characters: é and á in the words académico and Básica that I used in the first file location. Because, in that location, I tried to generate a JavaDoc in another project located there and NetBeans generated the Doc. So the error is more about the length of the path and the names of the files in the project.

Using clang-format with IAR embedded workbench

I have a project in IAR embedded workbench. Is there a way using the tools menu to add in a code formatter such as clang-format? I've managed to call it, but have not set the command line options correctly in order to feed the current file into the formatter.
Simon
Yes it is possible:
Here are the settings I used.
Menu Text: Clang Format
Command: C:\Program Files\LLVM\bin\clang-format.exe
Argument: --style=file $FILE_PATH$ -i
Initial Directory: $FILE_DIR$
These settings require a file .clang-format to be saved in the project directory, no bad thing in my view as if checked in with the project it sets a standard for the project code format.
I think simply using clang-format for the command would work if the directory is added to the PATH environment variable. Or you'll need to browse to the location of clang-format on your system if it's different you mine.
Screenshot of dialog window

Run code formatter from the command line with PhpStorm open

If I go to my PhpStorm\bin folder I can run the format.bat command to format files from the command line e.g.
phpstorm format -r C:\path\to\my\code -r -s c:\path\to\my\settings.xml
and that works great. However I cannot run the command if PhpStorm is open, I get an error:
Only one instance of PhpStorm can be run at a time
Not ideal to have to close my IDE or have to use a 3rd party code formatter. Is there any workaround? Without installing another copy of PhpStorm.
It's a known issue, please see: https://youtrack.jetbrains.com/issue/IDEA-160462
The link from y.bedrov led me to here https://confluence.jetbrains.com/display/IDEADEV/Command-Line+Source+Code+Formatter with a potential solution.
Unfortunately I don't seem to be able to get it to work, I had to resort to copying my PhpStorm directory and using the copy instead. But I add it here in hopes that it helps others
Running Command-Line Formatter when the IDE is Running
On Linux/MacOS
Go to /bin directory where is a directory where Intellij IDEA or Intellij IDEA-based product is installed.
Copy idea.properties to some other file, for example, format.properties
Modify format.properties as follows:
Uncomment the lines:
# idea.config.path=${user.home}/.IntelliJIdea/config
# idea.system.path=${user.home}/.IntelliJIdea/system
Change them to point to some directories which differ from defaults, for example:
idea.config.path=${user.home}/.IntelliJIdea/format/config
idea.system.path=${user.home}/.IntelliJIdea/format/system
Modify format.sh by adding the line with IDEA_PROPERTIES variable:
\#!/bin/sh
\# ------------------------------------------------------
\# IntelliJ IDEA formatting script.
\# ------------------------------------------------------
IDE_BIN_HOME="${0%/*}"
export IDEA_PROPERTIES=$IDE_BIN_HOME/format.properties
exec "$IDE_BIN_HOME/idea.sh" format "$#"
Run format.sh without closing the IDE, it should give the following output:
IntelliJ IDEA ..., build ... Formatter
Usage: format [-h] [-r|-R] [-s|-settings settingsPath] path1 path2...
-h|-help Show a help message and exit.
-s|-settings A path to Intellij IDEA code style settings .xml file.
-r|-R Scan directories recursively.
-m|-mask A comma-separated list of file masks.
path.. A path to a file or a directory.
On Windows
You have to create a separate format.properties file as described above for Linux/MacOS.
Change format.bat file by adding a line with IDEA_PROPERTIES variable as follows:
#ECHO OFF
::----------------------------------------------------------------------
:: IntelliJ IDEA formatting script.
::----------------------------------------------------------------------
SET IDE_BIN_DIR=%~dp0
SET IDEA_PROPERTIES=%IDE_BIN_DIR%\format.properties
CALL "%IDE_BIN_DIR%\idea.bat" format %*
Run format.bat, it will list the command-line formatter options.
This guide works for me. But ensure use PHPSTORM_PROPERTIES instead of IDEA_PROPERTIES when export environment variable as described in the article:
export IDEA_PROPERTIES=$IDE_BIN_HOME/format.properties
And what's more, from version 2022.1, IntelliJ IDEA supports dry run which is very useful for format validation based pre-commit git hook.

Error in running trace32 with command line

I have a .cmm file which helps in debugging of Qcomm chipsets.
This file has a line : cd ../../../../../modem_proc
When I run this same cmm file using T32 GUI, it runs fine and does the work. But when I am trying to run the same file using windows command line using,
C:\T32\bin\windows64>t32mqdsp6.exe -c C:\T32\config.t32 -s D:\path\to\xxx.cmm
Following error is thrown in T32: syntax error in B::cd ../../../../../modem_proc
What am I missing here? I have no hands-on experience with T32 what-so-ever.
The problem probably results from different working directories. Type
PRINT OS.PWD()
in the GUI and add it to the top of the script. I'd suspect they are different.
Don't use working directory relative paths, instead use paths relative to the script, e.g.
CD ~~~~/../../../../modem_proc
The four tilde (~) symbols mean "directory of the currently executed script". There's still a possible issue with this solution when using multiple GUIs and the intercom, but for most use-cases this should be OK.
When starting TRACE32 (up to build 99518) without option "-s", it starts a default script t32.cmm form your TRACE32 installation directory. But t32.cmm is not executed, when "-s" is used.
So probably your t32.cmm is changing your working directory. If so you can fix the issue by adding the line
DO ~~/t32.cmm
to the top of your script xxx.cmm.
See also https://www.lauterbach.com/frames.html?help_autostart.html
The default working path is also set by the TRACE32 configuration file. That is the file passed with "-c". So if your are using a different configuration file than C:\T32\config.t32 when starting your TRACE32 GUI the normal way, then you should use that configuration file also when starting TRACE32 from the command line.
To get the path of the configuration file usually used, start TRACE32, execute command AREAand then command PRINT OS.PCF()
Furthermore dev15 is probably right here https://stackoverflow.com/a/53671657/4727717:
Use paths relative to the PRACTICE script (cmm-file) by starting each path with four tildes.