I want to encrypt a password with maven, from within a Java program. Basically, I want to achieve the equivalent of calling mvn --encrypt-password p4ssw0rd, but without dropping to the command line.
I've looked into Apache Maven Invoker. I've found setters on InvocationRequest for _some command line options, such as InvocationRequest.setShowVersion(..) for --show-version. But I can't find one for --encrypt-password.
Is there a way to do this, either with Apache Maven Invoker or another way? I do not want to drop to or call a command line directly, since I want to be platform independent.
How do I invoke mvn --encrypt-password p4ssw0rd from a Java program?
It looks like you can use the plexus-cipher library, which is apparently what Maven uses to do the encryption.
See the code at https://github.com/sonatype/plexus-cipher
The unit tests will probably be enut to get you started.
Related
I am undergoing trouble writing the custom protoc plugin. I posted this question but no response. Atleast Kindly please let me know answers to few questions. I really need to do this. I havent gone past first step itself.
From this question, how do they link shell script with plugin name protoc-gen-code.
java -cp ./codegen.jar CodeGeneratorMain "$#"
With respect to the above implementation in the question and google proto buffer documentation, what exactly would be there in the path.. is it the path of the Shell Script? would the shell script be named as protoc-gen-code?
Can someone please respond to these queries.
protoc can generate code for several different languages with one invocation. The way you specify which languages you want is to use the command line arguments of the form --LANG_out where LANG is the language you want. So --cpp_out gives you C++ code, directory, --js_out gives you JavaScript etc. If protoc doesn't recognize LANG then it looks for a plugin called protoc-gen-LANG and uses it as the code generator.
The shell script can be called whatever. Let's say you call it mygen.sh and you decide you want to use mylang as LANG. Then the protoc invocation looks like:
protoc --plugin=protoc-gen-mylang=/path/to/mygen.sh --mylang_out=/some/dir some.proto
I am currently working on a small project. The idea is to use jQAssistant to fill the neo4j database so that the data can be used by an rest api. The plan is to upload a jar, war or ear to a java backend so that it can be scanned (scan -f) and then start the neo4j server on port 7474.
What I already have tried:
1. Trying to execute "scan" and "server" with Java ProcessBuilder and Runtime.
2. Importing JQAssistant Commandline Neo4jv3 - 1.6.0 with gradle and trying to use the run-Method in Main.class with the commandline arguments (scan -f foldername).
Server-start works without any problems in both cases, but scanning is a huge problem. It does not seem to scan the specified folder correctly. The jqassistant-folder which has been created does not have any scanned data.
I assume that the root of the problem is the plugins folder and the variables JQASSISTANT_HOME and JQASSISTANT_OPTS appearing in the jqassistant.cmd and .sh files.
Is it actually possible to execute "server" and especially "scan" within java code?
It is possible to use jQAssistant from Java code but I'd not recommend it as the underlying APIs are subject to change. What remains downwards compatible over releases are the command line arguments, so going for the Main class as described in your question should be safe for a while. This approach is also used by the Gradle integration provided by Kontext E (http://techblog.kontext-e.de/jqassistant-with-gradle/).
Assuming that you're encountering the same problem with missing data when using the provided shell scripts for Windows/Linux. A common issue is that for scanning folders containing Java classes you need to specify a scope:
scan -f java:classpath::build/classes/main
The java:classpath prefix provides a hint that the folder shall be treated as a classpath element, see http://buschmais.github.io/jqassistant/doc/1.6.0/#_scanner and http://buschmais.github.io/jqassistant/doc/1.6.0/#cli:scan.
How to I setup the IDEA IDE, so that it shows real param names for methods in build-in classes?
mvn clean install dependency:sources did not help me
upd:
HttpExchange from package
import com.sun.net.httpserver.HttpExchange
The library you want to use does not have debug information included in the bytecode which is (for now) needed for this to work. Source is not enough.
If you cannot locate a debug build you may have to compile it yourself. If you cannot access the source, you may need to ask the vendor politely.
I'm trying to use the exec-maven-plugin as a way to integrate a 3rd party Java API. I'm using the exec:java goal to call my java main class. I need to parse the output of the API, however I do not see anything specific in the plugin that allows for this.
Is there a way in maven and/or the exec-maven-plugin to capture/save the output of the executions?
With the exec:exec goal, you can use the outputFile parameter (or using the command line property exec.outputFile).
I work on a Scala project that uses c++ code, using sbt. Once compiled, this c++ code is imported into Scala through Java code that uses jna.
Now, currently the Java wrapper are manually written, and I like to automatize this. I've found jnaerator that can do that, but I don't know how I should use it in sbt.
I see two general approaches:
use command line, such as java -jar jnaerator ... but I don't know how to setup such command line task in sbt? Also, I would need to know the typical project structure to follow: where to output the jna generated code?
Use jnaerator maven plugin through sbt, if it is possible?
This might take some iteration until we get it do what you need.
For the first approach, here is how you can run custom system command on sbt (you essentially solve this using Scala code). Add the following to your build.sbt file:
lazy val runJnaerator= taskKey[Unit]("This task generates libraries from native code")
runJnaerator := {
import sys.process._
Seq("java" , "-jar", "jnaerator", "..." ).!
}
To execute:
>sbt runJnaerator
Now the question is where do you need these files files to go? Finally, how do you want to invoke everything?