execute git blame command in java - java

I'm trying to use the following Java syntax to execute a Git blame command:
Process process = Runtime.getRuntime().exec("/usr/bin/git blame https://github.com/git/git/alloc.c > TestGit.txt");
But, when I run the code in Java, it doesn't give any result. And, when I tried to execute it in the Terminal, it just creates an empty "TestGit.txt" file, and I got the error: fatal: Not a git repository (or any of the parent directories): .git.

Be sure to change directories into the git repository prior to launching the command
Process process = Runtime.getRuntime().exec("cd /path/to/repository; /usr/bin/git blame https://github.com/git/git/alloc.c > TestGit.txt");

I think for git blame to work, you'll need to be inside the repository. You'd need to be inside the repository directory (which means you'll need to check it out first), and run:
git blame alloc.c

The following is the right syntax to execute blame command in Java for linux:
git --git-dir=/home/gh/git/.git --work-tree=/home/gh/git blame builtin/tag.c

The javier way:
Process process = Runtime.getRuntime().exec("/usr/bin/git blame https://github.com/git/git/alloc.c > TestGit.txt", null, new File('/path/to/repository'));

Related

Issue with Building Java Application in Docker

I am at the Java Directory. And When I execute the build command:
docker build -t karthikjohnbabu/hello-world-java:0.0.2.RELEASE .
I get the below error message. Please help me???
failed to solve with frontend dockerfile.v0: failed to create LLB definition: no match for platform in manifest sha256:195e9c227ad891282e80602cac2372a3085ecf4ceefbb395558ffe0f7bb0b9aa: not found.
Complete details of error below:
Try adding the following arg to the command:
--platform=linux/amd64
or alternatively use the following command to set an env var:
export DOCKER_DEFAULT_PLATFORM=linux/amd64
The information you gave leaves room for guessing.
I believe the important part is no match for platform in manifest.
Thus I believe in your dockerfile you start FROM someimage, and this someimage is not available for the platform you are using (which could mean MacOS).

Karaf command not found exception how to troubleshoot?

Downloaded karaf 4.0.9 just following getting started doc but keep getting this
org.apache.felix.gogo.runtime.CommandNotFoundException: Command not found: feature:install
whenever i try to do feature:install wrapper from shell
Finding it very difficult to find any help or doc how to trouble shoot? is it a permissions thing? I chowned everything to the same user for simplicity...
Is distribution missing a library? Where do i get it/put it?
New to karaf... Following this: http://karaf.apache.org/manual/latest/#_installation
Just trying to get some basic JDBC/JMS stuff working, install drivers, recieve some msgs, query db, etc
Spent a few hours of reading docs + trial and error to figure this out:
ssh karaf#localhost -p 8101
Will get you full admin shell, apparently this isn't available if you just ./shell from KARAF_HOME/bin
You can check your configurations in users.properties in karaf/etc folder .
Open karaf shell using admin rights.
Start Karaf shell from its bin folder.
Now run karaf console using below command.
ssh username#localhost -p8101
now you can run any command of karaf shell.

DOCKER_HOST environment variable on windows

I'm running Docker 1.12.0 on a Windows 10 machine. I'm developing a Java program, using Maven 3.3.9 as a dependency manager. I have a maven docker plugin (https://github.com/fabric8io/docker-maven-plugin), which gives the following error on clean install.
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.15.16:build (docker-build-start) on project integration-test: Execution docker-build-start of goal io.fabric8:docker-maven-plugin:0.15.16:build failed: No <dockerHost> or <machine> given, no DOCKER_HOST environment variable, and no read/writable '/var/run/docker.sock' -> [Help 1]
When I run a clean install with the following configuration option in the POM file:
<dockerHost>tcp://0.0.0.0:2376</dockerHost>
the following result is shown.
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.15.16:build (docker-build-start) on project integration-test: Cannot create docker access object: Cannot extract API version from server https://0.0.0.0:2376: Connect to 0.0.0.0:2376 [/0.0.0.0] failed: Connection refused: connect -> [Help 1]
My question: is there an IP address I can use to tell this maven plugin where it can reach the daemon? Normal docker commands work perfectly fine. The plugin works without any problems on OS X.
After nearly a day of fruitless Googling I found this solution by myself. Trivial, but might still help others.
You need to enable the checkbox 'Expose daemon on...' under Settings -> General
On Windows 10 with Docker for Windows, the Docker Engine API is available in these two locations:
npipe:////./pipe/docker_engine
http://localhost:2375
I recommend trying with the localhost one.
Details here: https://docs.docker.com/docker-for-windows/faqs/#/how-do-i-connect-to-the-remote-docker-engine-api
It seems the user which is running Maven goals doesn't have access to docker.sock . The error message is telling which options are there to resolve the problem.
No <dockerHost> or <machine> given, no DOCKER_HOST environment
variable, and no read/writable '/var/run/docker.sock'
Last option is the easiest one because it requires a file permission and it doesn't need to create any docker machine or set a DOCKER_HOST, On Linux you can change read/write permission of docker.sock with the following:
sudo chmod 776 /var/run/docker.sock
On windows go through this article : Microsoft article
I had the same issue when I tried to build a project in a custom GitLab CI/CD runner, with another than root user defined in a custom build image. I fixed by setting the read/write permission for users to the docker-socket.
chmod o+rw /var/run/docker.sock
If you are using Window and Maven in eclipse to build your java project
but continue seeing that error, then you have to perform these steps:
Step1:
You need to enable the checkbox 'Expose daemon on...' under Settings -> General
As mentioned by #Adriaan Koster
If step1 does not solve the issue,then
Step2: Run your eclipse in administration mode.
Now it should work without issues.
If someone just wants to skip fabric8 docker-maven-plugin execution that prevents build to succeed with error
No given, no DOCKER_HOST environment variable, no
read/writable '/var/run/docker.sock' or '//./pipe/docker_engine' and
no external provider like Docker machine configured
then this can be achieved with -Ddocker.skip=true according to https://dmp.fabric8.io/#global-configuration.
use docker-machine if you are using toolbox.
<machine>
<name>default</name>
<autoCreate>true</autoCreate>
<createOptions>
<driver>virtualbox</driver>
<virtualbox-cpu-count>2</virtualbox-cpu-count>
</createOptions>
</machine>

Biginsights 3.0 silent installation using Chef

I am doing silent installation of Biginsights 3.0 using Chef. Strange thing is that if I invoke the installation without Chef recipe i.e manually "./silent-install.sh install.xml" it works fine. But when I invoke it through Chef recipe , it fails. It does not install bigsql1,sheets and due that it fails. I am pasting the error. It is not getting required files as bigsql1 installation is not completing successfully.
[ERROR] DeployManager - bigsql1 failed
com.ibm.xap.mgmt.ConfigurationException: initialize failed because /opt/ibm/biginsights/hdm/components/bigsql1/binary/bigsql1-dist.tar.gz is not found
at com.ibm.xap.mgmt.bigsql.BigSQL1Deployer.installInitialize(BigSQL1Deployer.java:73)
at com.ibm.xap.mgmt.DeployManager$InstallThread.doInstall(DeployManager.java:2760)
at com.ibm.xap.mgmt.DeployManager$InstallThread.work(DeployManager.java:2818)
at com.ibm.xap.mgmt.DeployManager$WorkerThread.run(DeployManager.java:2725)
Any help will be appreciated. I am sure somewhere Chef is failing to invoke bigsql1 install script and most probably it is terminal issue.
Here is my recipe code
bash "BI3.0" do
user "biadmin"
group "biadmin"
cwd "/home/biadmin/biginsights-3.0.0.1-SNAPSHOT-enterprise-production-Linux-amd64-b20140711_1047/silent-install"
code <<-EOH
sh silent-install.sh BI30.xml 2>&1 >> /tmp/console.out
EOH
end

Git returning null on hudson

I am working on a project using git with hudson to build some tests. I have done all the hudson configurations (at least think I did) and I downloaded git for windows. The repository is located on our office linux machine. When I build the tests here is the error I'm getting:
Started by user anonymous
Checkout:workspace / C:\Users\username\.hudson\jobs\GitTest\workspace - hudson.remoting.LocalChannel#35e5abf2
Using strategy: Default
Checkout:test2 / C:\Users\username\git\test2 - hudson.remoting.LocalChannel#35e5abf2
Fetching changes from the remote Git repository
Fetching upstream changes from user#gitrepo:/var/gitrepo/test
ERROR: Problem fetching from origin / origin - could be unavailable. Continuing anyway
ERROR: (Underlying report) : Error performing command: C:\Program Files (x86)\Git\cmd\git.exe fetch -t user#gitrepo:/var/gitrepo/test +refs/heads/master:refs/remotes/origin/master
null
ERROR: Could not fetch from any repository
FATAL: Could not fetch from any repository
hudson.plugins.git.GitException: Could not fetch from any repository
at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:931)
at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:889)
at hudson.FilePath.act(FilePath.java:791)
at hudson.FilePath.act(FilePath.java:773)
at hudson.plugins.git.GitSCM.gerRevisionToBuild(GitSCM.java:889)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:668)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1515)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:521)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:428)
at hudson.model.Run.run(Run.java:1390)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:40)
at hudson.model.ResourceController.execute(ResourceController.java:81)
at hudson.model.Executor.run(Executor.java:137)
For some reason the fetch command returns null. When I try the command on command line, it just hangs with no output until I have to kill it. I've been researching this for a while now but could not find any answer.
Any help would be much appreciated.
I had something like this happened, it turned out it was the fingerprint (if your git is using RSA verification) that wasn't automatically accepted the first time we queried the repo>.
I solved it by doing a manual query on the repo as the hudson user:
git ls-remote -h git#yourepo.git HEAD
i am able to solve this problem by adding windows Environment Variable.
Name: HOME
Value: $USERPROFILE
for more info go to below URL,
http://element34.ca/blog/jenkins-remote-windows-nodes-and-private-github-repos

Categories

Resources