How to run a JAR application as a different user in IntelliJ? - intellij-idea

I would like to choose the user for run configuration so that my application runs with reduced permissions.
Unfortunately there doesn't seem to be any option available for this in Intellij.
Only way I can think of so far is to run as "Shell script" and clean/package my JAR in "before launch" configuration. This however requires a lot of manual configuration and cannot be used to run tests. It becomes even more annoying when the user has a password (which could be stored in Intellij's configuration like database passwords for example).
I've found the "shorten command line" option but I don't see any way to add my own configuration. If I could, it would be something like:
sudo -u nobody java [options] className [args]

If program can be run via command line - you can try using External Tools to run it.

Related

Buildsteps after each other

How do I run several buildsteps after each other in IntelliJ? I think I want a mini CI/CD build system inside the editor.
For example, the project I work on now is a Spring boot and javascript web site. I need to build it with maven with mvn clean package -Pdockerimage. This copies files for building the Docker image to target/dockerimgbuild.
Then I want to build the docker image using docker build -t scheduling-ui-dev . and after that run it with docker compose docker-compose up --build from src/main/resources/docker-compose.
I have built one run configuration for each of these steps but how do I run them after each other? I have found that you can have before launch but the system is clunky and complains if target/dockerimgbuild doesn't exists even before it have run the maven step which creates it. Latest problem I stumbled on was that a file prevented maven from removing target/dockerimgbuild and all run steps was automatically removed from the run configurations.
There is a run configuration called compound but that runs everything in parallell and you can not specify order which is a problem.
I wonder if it is feasible to start TeamCity in a container, do anyone have a clue about that (is teamcity easy to configure, how to make it launch a docker-compose container on my host machine etc)?
My solution right now is to have several terminals (if this gets more permanent I will replace it with a script) where I just press up and enter to execute the steps manually. Seems stupid as I guess maven itself can do all of this...but I don't know how or how much work it is.
There is a compound Run/Debug configuration: https://www.jetbrains.com/help/idea/run-debug-configuration-compound-run-configuration.html
Also, there is a multi-run plugin: https://plugins.jetbrains.com/plugin/7248-multirun

Can IntelliJ's Run/Debug configurations have prompts for input?

i was wondering, if i can configure a run configuration (like executing a ruby script on a deployment server) with a prompt for parameters on starting the config. Like it does for starting rake tasks from the 'Run Rake Task...' after selecting a task.
I couldn't find anything in the run/debug config view and with a google search.
I recently found out that this feature is in fact implemented, kind of.
On the Run/Debug Configurations page there is a checkbox at the bottom called "Show this page". If you check this, everytime you want to start the config, you get a somewhat smaller version of the config page, letting you edit for example arguments and stuff.
Serves me quite well and yes, it is not fully what i need, but it does the job.
It's not supported at the moment, related requests:
IDEA-152268 User prompted values in run configuration for "VM options" and "Program arguments"
IDEA-74031 Variables in command line parameters of run configuration

How do I run a EXE Go executable from within IntelliJ IDEA?

I have a Go program which I'm working on in IntelliJ IDEA on a Windows machine. The program's structure is a little unconventional (don't want to go into detail here as its besides the point) because of which I first have to compile the program using the following command:
go build -o cli.exe
And then I can run cli.exe directly in the command prompt.
But how do I configure the run configuration in IntelliJ IDEA so that it doesn't mind running a Windows executable ? Because if I try to tell it to run an EXE file as it's run configuration, it gives me error "Main file is invalid"
How do I solve this ?
Make sure you have a file name (not a folder name) in field File on Run/Debug Configuration window (In IntelliJ IDEA go to menu Run->Edit Configuration...->your_configuration). That was my case.
You may be able to install the Bash plugin on Windows, then create a run configuration using the Bash plugin, and just run your executable from a script.
Create a Go Application run configuration and that should work. You can choose to run either a file or a package. If you would share more details then the answer would be more complete. If you still have an issue with this, please open an issue to the bug tracker and I'll be able to help out (please follow the issue template there).

Is it possible to execute a command as a super user while using cmake?

I'm working on a project that uses the proxygen library by facebook.
The latter builds itself by means of a script called deps.sh which uses to invoke apt-get as a super user.
I've successfully created a custom target with cmake using the add_custom_target directive, but it fails because of the above call with the error sudo: no tty present and no askpass program specified and it makes sense, of course.
Anyway I've not been able to find a way of executing that script, thus invoking a command as a super user, using the add_custom_target.
I can safely install the library and write a FindProxygen module for my colleagues, so that the build process remains coherent, but I'd like to know if there is a clean solution to the problem of launching a command as root from cmake and thus put the library as a submodule of the project.
You can run installation script in new terminal, so sudo, executed by this script, will work as usual.
COMMAND x-terminal-emulator -e "<...>/deps.sh"
(This may be written as part of add_custom_target, add_custom_command, execute_process, etc.)
add_custom_target(
apt-downloads ALL
COMMAND sudo apt install -y ${DEPENDENCY_LIBRARIES}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "download required dependencies straight from apt on ubuntu"
)
Worked for me
The response is pretty simple: no.
As remarked in the comments, cmake expects to find all the required libraries already installed in the system (or at least, within the search paths) and any other solution would stop the execution and wait for user inputs.
As far as I've seen around, the usual approach, the one I've used too in the above mentioned project and in another one started immediately after, is to create a script that is in charge to download, compile and prepare the project environment, the same way proxygen itself does.
The final user will be asked to firstly executes that script, thus he will be able to proceed using cmake.
That's all, thank you for the comments.

Using a variable obtained using a pre-build shell command to set an option for the Maven build in Hudson

I have a Hudson job that runs a maven goal. Before this maven goal is executed I have added a step to run before the build starts, it is a shell script that obtains the version number that I want to use in the 'Goals and options' field.
So in my job configuration, under Build Environment I have checked the Configure M2 Extra Build Steps box and added a shell script before the build. The script looks like this:
export RELEASE={command to extract release version}
echo $RELEASE
And then under the Build section I point to my 'root pom'. In the Goals and options I then want to be able to do something like this:
-Dbuild.release.version=${RELEASE} deploy
Where build.release.version is a maven property referenced in the POM. However since the shell doesn't seem to make its variables global it doesn't work. Any ideas?
The only one I have is to install the Envfile plugin and get the shell script to write out the RELEASE property to a file and then get the plugin to read the file, but the order in which everything is run may cause problems and it seems like there must be simpler way...is there?
Thanks in advance.
I recently wanted to do the same, but AFAIK it's not possible to export values from a pre-build shell to the job environment. If there is a Hudson Plugin for this I've missed it.
What did work, however, was a setup similar to what you were suggesting: having the pre-build shell script write the desired value(s) to a property-file in the workspace, and then using the Parametrized Trigger Plugin to trigger another job that actually does the work (in your case, invoke the Maven job). The plugin can be configured to read the parameters it passes from the property file. So the first job has just the shell script and the post-build triggers, and the second one does the actual work, having the correct parameters available as environment variables.
General idea of the shell script:
echo "foo=bar
baz=`somecmd`" > build.properties
And for your Goals and options, something like:
-Dbuild.release.version=${foo} deploy
Granted, this isn't as elegant as one might want but worked really well for us, since our build was broken into several jobs to begin with, and we can actually reuse the other jobs that the first one triggers (that is, invoke them with different parameters).
When you say it doesn't work, do you mean that your RELEASE variable is not passed to the maven command? I believe the problem is that by default, each line of the shell script is executed separately, so environment variables get lost.
If you want the entire shell script to execute as if it was one script file, make the first line:
#!/bin/sh
I think this is described in the Help information alongside the shell script build step (and if I'm wrong, that's a good place to look for the right syntax).