You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Jan Engler <Ja...@sick.de> on 2013/03/18 14:00:27 UTC
Custom Maven Plugin
Hi,
I am writing my first custom plugin for maven.
I`m now facing 2 problem.
- I need to know the absolute location of every dependency (incl.
transitive deps)
- Is there a solution for workspace dependencies (i would like to have a
"jar" of them as well) like "disable workspace resolution" as a method
call in the plugin?
Thx in advance!
Jan
Mit freundlichen Grüßen / Best regards
Jan Engler
Central Research & Development
SICK AG
Erwin-Sick-Str. 1
79183 Waldkirch, Germany
Phone +49 7681 202-3214
mailto:jan.engler@sick.de
http://www.sick.com
SICK AG - Sitz: Waldkirch i. Br. - Handelsregister: Freiburg i. Br. HRB
280355
Vorstand: Dr. Robert Bauer (Vorsitzender) - Reinhard Bösl - Dr. Martin
Krämer - Markus Paschmann - Markus Vatter
Aufsichtsrat: Gisela Sick (Ehrenvorsitzende) - Klaus M. Bukenberger
(Vorsitzender)
Antwort: Re: Re: Custom Maven Plugin
Posted by Jan Engler <Ja...@sick.de>.
Hey,
thanks a lot! That solved my problems!
Mit freundlichen Grüßen / Best regards
Jan Engler
Central Research & Development
SICK AG
Erwin-Sick-Str. 1
79183 Waldkirch, Germany
Phone +49 7681 202-3214
mailto:jan.engler@sick.de
http://www.sick.com
Von: Thomas Broyer <t....@gmail.com>
An: Maven Users List <us...@maven.apache.org>
Datum: 18.03.2013 14:28
Betreff: Re: Re: Custom Maven Plugin
Try project.getCompileClasspathElements(), it resolves transitive
dependencies and gives you their location as absolute file names.
http://maven.apache.org/ref/3.0.5/maven-core/apidocs/org/apache/maven/project/MavenProject.html#getCompileClasspathElements()
On Mon, Mar 18, 2013 at 2:22 PM, Jan Engler <Ja...@sick.de> wrote:
> Ok,
>
> I am adapting the jni4net maven plugin (see
> https://code.google.com/p/jni4net/) to fit our needs. In short, this
> plugin collects a set of classes with the intention to generate .net
> wrapper for. Furthermore, the tool that create those wrappers
> (proxygen.exe) needs the complete dependecies as 'classpath' argument.
It
> works so far, but beneath the direct dependencies of the maven project
my
> plugin is running on, I also need the transitive dependencies. All the
> information about that is passed to the proxygen.exe using an xml
file...
> In the case of a dependency that is described by a workspace resolution
I
> would like to pass a jar....
> I tried your hint with @requiresDependencyResolution compile but that
> didn't work. Here is a snippet of my code:
>
> /**
> * @requiresDependencyResolution compile
> * @goal proxygen
> *
> * @phase process-sources
> */
> public class ProxygenMojo extends AbstractMojo {
> /**
> * @parameter expression="${proxygen.exe}"
> * @required
> */
> private File exe;
>
> /** @parameter expression="${proxygen.xml}" default-
> value="proxygen.xml" */
> private File xml;
> /** @parameter expression="${proxygen.bin}" default-
> value="target/classes" */
> private String bin;
>
> /**
> * @parameter
> */
> private List<String> artifacts;
> /**
> * @parameter
> */
> private List<String> classes;
>
> /**
> * @parameter expression="${proxygen.targetDirJvm}"
> * default-value="<TargetDirJvm>java</TargetDirJvm>"
> */
> String targetDirJvm;
>
> /**
> * @parameter expression="${proxygen.targetDirClr}"
> * default-value="<TargetDirClr>csharp</TargetDirClr>"
> */
> String targetDirClr;
>
> /** @parameter default-value="${project}" */
> MavenProject project;
>
> @SuppressWarnings("unchecked")
> public void execute() throws MojoExecutionException {
> if (artifacts == null)
> artifacts = Collections.emptyList();
>
> getLog().info("exe = " + exe.getPath());
>
> String jarPath;
> ArrayList<String> classPathList = null;
> ArrayList<String> classList = null;
>
> Set<Artifact> artifactSet = project
> .getDependencyArtifacts();
> project.getDependencies();
> for (Artifact artifact : artifactSet) {
> try {
> JarFile depFile = new
> JarFile(artifact.getFile());
> if (classPathList == null) {
> classPathList = new
> ArrayList<String>();
> }
> classPathList.add(depFile.getName());
> } catch (IOException e1) {
>
> e1.printStackTrace();
> }
> jarPath = null;
>
> getLog().info("artifact " +
> artifact.getFile().getPath());
> }
>
> StringBuilder xmlBuilder = new StringBuilder(
> "<?xml version=\"1.0\"
encoding=\"utf-8\"
> ?>");
> xmlBuilder
> .append("\n<jni4net-proxygen xmlns=\"
> http://jni4net.sf.net/0.8.0.0/toolConfig.xsd\">\n");
> xmlBuilder.append("\n<TargetDirJvm>").append(targetDirJvm)
> .append("</TargetDirJvm>");
> xmlBuilder.append("\n<TargetDirClr>").append(targetDirClr)
> .append("</TargetDirClr>\n");
>
> if (classPathList == null) {
> getLog().warn("no artifacts found");
> } else {
> for (String artifact : classPathList) {
> xmlBuilder.append("\n<ClassPath Path=\""
+
> artifact + "\"/>");
> }
> xmlBuilder.append("\n<ClassPath Path=\"" + bin +
> "\"/>");
> xmlBuilder.append('\n');
> }
> for (String clazzAsString : classes) {
> if (classList == null) {
> classList = new ArrayList<String>();
> }
> classList.add(clazzAsString);
> }
> if (classList == null) {
> getLog().warn("no classes found");
> } else {
> for (String className : classList) {
> xmlBuilder.append("\n<JavaClass
> TypeName=\"" + className
> + "\"/>");
> }
> }
> xmlBuilder.append("\n\n</jni4net-proxygen>\n");
>
>
> Any ideas?
>
> Mit freundlichen Grüßen / Best regards
>
> Jan Engler
> Central Research & Development
>
> SICK AG
> Erwin-Sick-Str. 1
> 79183 Waldkirch, Germany
>
> Phone +49 7681 202-3214
> mailto:jan.engler@sick.de
> http://www.sick.com
>
>
>
>
>
> Von: Stephen Connolly <st...@gmail.com>
> An: Maven Users List <us...@maven.apache.org>
> Datum: 18.03.2013 14:05
> Betreff: Re: Custom Maven Plugin
>
>
>
> I would start by describing what you want to do and why. That way we can
> determine if you approach fits best with "the maven way" and suggest the
> best way to align with that... There are some alarm bells ringing
>
> On Monday, 18 March 2013, Jan Engler wrote:
>
>> Hi,
>>
>> I am writing my first custom plugin for maven.
>> I`m now facing 2 problem.
>> - I need to know the absolute location of every dependency (incl.
>> transitive deps)
>
> You need @requiresDependencyResolution in the java doc annotations or
the
> equivalent (on a phone so cannot look up) for java 1.5 annotations
>
>
>> - Is there a solution for workspace dependencies (i would like to have
a
>> "jar" of them as well) like "disable workspace resolution" as a method
>> call in the plugin?
>
>
> Here is the alarm bell FYI
>
>>
>> Thx in advance!
>> Jan
>>
>> Mit freundlichen Grüßen / Best regards
>>
>> Jan Engler
>> Central Research & Development
>>
>> SICK AG
>> Erwin-Sick-Str. 1
>> 79183 Waldkirch, Germany
>>
>> Phone +49 7681 202-3214
>> mailto:jan.engler@sick.de <javascript:;>
>> http://www.sick.com
>>
>>
>>
>> SICK AG - Sitz: Waldkirch i. Br. - Handelsregister: Freiburg i. Br. HRB
>> 280355
>> Vorstand: Dr. Robert Bauer (Vorsitzender) - Reinhard Bösl - Dr.
> Martin
>> Krämer - Markus Paschmann - Markus Vatter
>> Aufsichtsrat: Gisela Sick (Ehrenvorsitzende) - Klaus M. Bukenberger
>> (Vorsitzender)
>>
>
>
> --
> Sent from my phone
>
>
>
> SICK AG - Sitz: Waldkirch i. Br. - Handelsregister: Freiburg i. Br. HRB
> 280355
> Vorstand: Dr. Robert Bauer (Vorsitzender) - Reinhard Bösl - Dr.
Martin
> Krämer - Markus Paschmann - Markus Vatter
> Aufsichtsrat: Gisela Sick (Ehrenvorsitzende) - Klaus M. Bukenberger
> (Vorsitzender)
--
Thomas Broyer
/tɔ.ma.bʁwa.je/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
SICK AG - Sitz: Waldkirch i. Br. - Handelsregister: Freiburg i. Br. HRB
280355
Vorstand: Dr. Robert Bauer (Vorsitzender) - Reinhard Bösl - Dr. Martin
Krämer - Markus Paschmann - Markus Vatter
Aufsichtsrat: Gisela Sick (Ehrenvorsitzende) - Klaus M. Bukenberger
(Vorsitzender)
Re: Re: Custom Maven Plugin
Posted by Thomas Broyer <t....@gmail.com>.
Try project.getCompileClasspathElements(), it resolves transitive
dependencies and gives you their location as absolute file names.
http://maven.apache.org/ref/3.0.5/maven-core/apidocs/org/apache/maven/project/MavenProject.html#getCompileClasspathElements()
On Mon, Mar 18, 2013 at 2:22 PM, Jan Engler <Ja...@sick.de> wrote:
> Ok,
>
> I am adapting the jni4net maven plugin (see
> https://code.google.com/p/jni4net/) to fit our needs. In short, this
> plugin collects a set of classes with the intention to generate .net
> wrapper for. Furthermore, the tool that create those wrappers
> (proxygen.exe) needs the complete dependecies as 'classpath' argument. It
> works so far, but beneath the direct dependencies of the maven project my
> plugin is running on, I also need the transitive dependencies. All the
> information about that is passed to the proxygen.exe using an xml file...
> In the case of a dependency that is described by a workspace resolution I
> would like to pass a jar....
> I tried your hint with @requiresDependencyResolution compile but that
> didn't work. Here is a snippet of my code:
>
> /**
> * @requiresDependencyResolution compile
> * @goal proxygen
> *
> * @phase process-sources
> */
> public class ProxygenMojo extends AbstractMojo {
> /**
> * @parameter expression="${proxygen.exe}"
> * @required
> */
> private File exe;
>
> /** @parameter expression="${proxygen.xml}" default-
> value="proxygen.xml" */
> private File xml;
> /** @parameter expression="${proxygen.bin}" default-
> value="target/classes" */
> private String bin;
>
> /**
> * @parameter
> */
> private List<String> artifacts;
> /**
> * @parameter
> */
> private List<String> classes;
>
> /**
> * @parameter expression="${proxygen.targetDirJvm}"
> * default-value="<TargetDirJvm>java</TargetDirJvm>"
> */
> String targetDirJvm;
>
> /**
> * @parameter expression="${proxygen.targetDirClr}"
> * default-value="<TargetDirClr>csharp</TargetDirClr>"
> */
> String targetDirClr;
>
> /** @parameter default-value="${project}" */
> MavenProject project;
>
> @SuppressWarnings("unchecked")
> public void execute() throws MojoExecutionException {
> if (artifacts == null)
> artifacts = Collections.emptyList();
>
> getLog().info("exe = " + exe.getPath());
>
> String jarPath;
> ArrayList<String> classPathList = null;
> ArrayList<String> classList = null;
>
> Set<Artifact> artifactSet = project
> .getDependencyArtifacts();
> project.getDependencies();
> for (Artifact artifact : artifactSet) {
> try {
> JarFile depFile = new
> JarFile(artifact.getFile());
> if (classPathList == null) {
> classPathList = new
> ArrayList<String>();
> }
> classPathList.add(depFile.getName());
> } catch (IOException e1) {
>
> e1.printStackTrace();
> }
> jarPath = null;
>
> getLog().info("artifact " +
> artifact.getFile().getPath());
> }
>
> StringBuilder xmlBuilder = new StringBuilder(
> "<?xml version=\"1.0\" encoding=\"utf-8\"
> ?>");
> xmlBuilder
> .append("\n<jni4net-proxygen xmlns=\"
> http://jni4net.sf.net/0.8.0.0/toolConfig.xsd\">\n");
> xmlBuilder.append("\n<TargetDirJvm>").append(targetDirJvm)
> .append("</TargetDirJvm>");
> xmlBuilder.append("\n<TargetDirClr>").append(targetDirClr)
> .append("</TargetDirClr>\n");
>
> if (classPathList == null) {
> getLog().warn("no artifacts found");
> } else {
> for (String artifact : classPathList) {
> xmlBuilder.append("\n<ClassPath Path=\"" +
> artifact + "\"/>");
> }
> xmlBuilder.append("\n<ClassPath Path=\"" + bin +
> "\"/>");
> xmlBuilder.append('\n');
> }
> for (String clazzAsString : classes) {
> if (classList == null) {
> classList = new ArrayList<String>();
> }
> classList.add(clazzAsString);
> }
> if (classList == null) {
> getLog().warn("no classes found");
> } else {
> for (String className : classList) {
> xmlBuilder.append("\n<JavaClass
> TypeName=\"" + className
> + "\"/>");
> }
> }
> xmlBuilder.append("\n\n</jni4net-proxygen>\n");
>
>
> Any ideas?
>
> Mit freundlichen Grüßen / Best regards
>
> Jan Engler
> Central Research & Development
>
> SICK AG
> Erwin-Sick-Str. 1
> 79183 Waldkirch, Germany
>
> Phone +49 7681 202-3214
> mailto:jan.engler@sick.de
> http://www.sick.com
>
>
>
>
>
> Von: Stephen Connolly <st...@gmail.com>
> An: Maven Users List <us...@maven.apache.org>
> Datum: 18.03.2013 14:05
> Betreff: Re: Custom Maven Plugin
>
>
>
> I would start by describing what you want to do and why. That way we can
> determine if you approach fits best with "the maven way" and suggest the
> best way to align with that... There are some alarm bells ringing
>
> On Monday, 18 March 2013, Jan Engler wrote:
>
>> Hi,
>>
>> I am writing my first custom plugin for maven.
>> I`m now facing 2 problem.
>> - I need to know the absolute location of every dependency (incl.
>> transitive deps)
>
> You need @requiresDependencyResolution in the java doc annotations or the
> equivalent (on a phone so cannot look up) for java 1.5 annotations
>
>
>> - Is there a solution for workspace dependencies (i would like to have a
>> "jar" of them as well) like "disable workspace resolution" as a method
>> call in the plugin?
>
>
> Here is the alarm bell FYI
>
>>
>> Thx in advance!
>> Jan
>>
>> Mit freundlichen Grüßen / Best regards
>>
>> Jan Engler
>> Central Research & Development
>>
>> SICK AG
>> Erwin-Sick-Str. 1
>> 79183 Waldkirch, Germany
>>
>> Phone +49 7681 202-3214
>> mailto:jan.engler@sick.de <javascript:;>
>> http://www.sick.com
>>
>>
>>
>> SICK AG - Sitz: Waldkirch i. Br. - Handelsregister: Freiburg i. Br. HRB
>> 280355
>> Vorstand: Dr. Robert Bauer (Vorsitzender) - Reinhard Bösl - Dr.
> Martin
>> Krämer - Markus Paschmann - Markus Vatter
>> Aufsichtsrat: Gisela Sick (Ehrenvorsitzende) - Klaus M. Bukenberger
>> (Vorsitzender)
>>
>
>
> --
> Sent from my phone
>
>
>
> SICK AG - Sitz: Waldkirch i. Br. - Handelsregister: Freiburg i. Br. HRB
> 280355
> Vorstand: Dr. Robert Bauer (Vorsitzender) - Reinhard Bösl - Dr. Martin
> Krämer - Markus Paschmann - Markus Vatter
> Aufsichtsrat: Gisela Sick (Ehrenvorsitzende) - Klaus M. Bukenberger
> (Vorsitzender)
--
Thomas Broyer
/tɔ.ma.bʁwa.je/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Antwort: Re: Custom Maven Plugin
Posted by Jan Engler <Ja...@sick.de>.
Ok,
I am adapting the jni4net maven plugin (see
https://code.google.com/p/jni4net/) to fit our needs. In short, this
plugin collects a set of classes with the intention to generate .net
wrapper for. Furthermore, the tool that create those wrappers
(proxygen.exe) needs the complete dependecies as 'classpath' argument. It
works so far, but beneath the direct dependencies of the maven project my
plugin is running on, I also need the transitive dependencies. All the
information about that is passed to the proxygen.exe using an xml file...
In the case of a dependency that is described by a workspace resolution I
would like to pass a jar....
I tried your hint with @requiresDependencyResolution compile but that
didn't work. Here is a snippet of my code:
/**
* @requiresDependencyResolution compile
* @goal proxygen
*
* @phase process-sources
*/
public class ProxygenMojo extends AbstractMojo {
/**
* @parameter expression="${proxygen.exe}"
* @required
*/
private File exe;
/** @parameter expression="${proxygen.xml}" default-
value="proxygen.xml" */
private File xml;
/** @parameter expression="${proxygen.bin}" default-
value="target/classes" */
private String bin;
/**
* @parameter
*/
private List<String> artifacts;
/**
* @parameter
*/
private List<String> classes;
/**
* @parameter expression="${proxygen.targetDirJvm}"
* default-value="<TargetDirJvm>java</TargetDirJvm>"
*/
String targetDirJvm;
/**
* @parameter expression="${proxygen.targetDirClr}"
* default-value="<TargetDirClr>csharp</TargetDirClr>"
*/
String targetDirClr;
/** @parameter default-value="${project}" */
MavenProject project;
@SuppressWarnings("unchecked")
public void execute() throws MojoExecutionException {
if (artifacts == null)
artifacts = Collections.emptyList();
getLog().info("exe = " + exe.getPath());
String jarPath;
ArrayList<String> classPathList = null;
ArrayList<String> classList = null;
Set<Artifact> artifactSet = project
.getDependencyArtifacts();
project.getDependencies();
for (Artifact artifact : artifactSet) {
try {
JarFile depFile = new
JarFile(artifact.getFile());
if (classPathList == null) {
classPathList = new
ArrayList<String>();
}
classPathList.add(depFile.getName());
} catch (IOException e1) {
e1.printStackTrace();
}
jarPath = null;
getLog().info("artifact " +
artifact.getFile().getPath());
}
StringBuilder xmlBuilder = new StringBuilder(
"<?xml version=\"1.0\" encoding=\"utf-8\"
?>");
xmlBuilder
.append("\n<jni4net-proxygen xmlns=\"
http://jni4net.sf.net/0.8.0.0/toolConfig.xsd\">\n");
xmlBuilder.append("\n<TargetDirJvm>").append(targetDirJvm)
.append("</TargetDirJvm>");
xmlBuilder.append("\n<TargetDirClr>").append(targetDirClr)
.append("</TargetDirClr>\n");
if (classPathList == null) {
getLog().warn("no artifacts found");
} else {
for (String artifact : classPathList) {
xmlBuilder.append("\n<ClassPath Path=\"" +
artifact + "\"/>");
}
xmlBuilder.append("\n<ClassPath Path=\"" + bin +
"\"/>");
xmlBuilder.append('\n');
}
for (String clazzAsString : classes) {
if (classList == null) {
classList = new ArrayList<String>();
}
classList.add(clazzAsString);
}
if (classList == null) {
getLog().warn("no classes found");
} else {
for (String className : classList) {
xmlBuilder.append("\n<JavaClass
TypeName=\"" + className
+ "\"/>");
}
}
xmlBuilder.append("\n\n</jni4net-proxygen>\n");
Any ideas?
Mit freundlichen Grüßen / Best regards
Jan Engler
Central Research & Development
SICK AG
Erwin-Sick-Str. 1
79183 Waldkirch, Germany
Phone +49 7681 202-3214
mailto:jan.engler@sick.de
http://www.sick.com
Von: Stephen Connolly <st...@gmail.com>
An: Maven Users List <us...@maven.apache.org>
Datum: 18.03.2013 14:05
Betreff: Re: Custom Maven Plugin
I would start by describing what you want to do and why. That way we can
determine if you approach fits best with "the maven way" and suggest the
best way to align with that... There are some alarm bells ringing
On Monday, 18 March 2013, Jan Engler wrote:
> Hi,
>
> I am writing my first custom plugin for maven.
> I`m now facing 2 problem.
> - I need to know the absolute location of every dependency (incl.
> transitive deps)
You need @requiresDependencyResolution in the java doc annotations or the
equivalent (on a phone so cannot look up) for java 1.5 annotations
> - Is there a solution for workspace dependencies (i would like to have a
> "jar" of them as well) like "disable workspace resolution" as a method
> call in the plugin?
Here is the alarm bell FYI
>
> Thx in advance!
> Jan
>
> Mit freundlichen Grüßen / Best regards
>
> Jan Engler
> Central Research & Development
>
> SICK AG
> Erwin-Sick-Str. 1
> 79183 Waldkirch, Germany
>
> Phone +49 7681 202-3214
> mailto:jan.engler@sick.de <javascript:;>
> http://www.sick.com
>
>
>
> SICK AG - Sitz: Waldkirch i. Br. - Handelsregister: Freiburg i. Br. HRB
> 280355
> Vorstand: Dr. Robert Bauer (Vorsitzender) - Reinhard Bösl - Dr.
Martin
> Krämer - Markus Paschmann - Markus Vatter
> Aufsichtsrat: Gisela Sick (Ehrenvorsitzende) - Klaus M. Bukenberger
> (Vorsitzender)
>
--
Sent from my phone
SICK AG - Sitz: Waldkirch i. Br. - Handelsregister: Freiburg i. Br. HRB
280355
Vorstand: Dr. Robert Bauer (Vorsitzender) - Reinhard Bösl - Dr. Martin
Krämer - Markus Paschmann - Markus Vatter
Aufsichtsrat: Gisela Sick (Ehrenvorsitzende) - Klaus M. Bukenberger
(Vorsitzender)
Re: Custom Maven Plugin
Posted by Stephen Connolly <st...@gmail.com>.
I would start by describing what you want to do and why. That way we can
determine if you approach fits best with "the maven way" and suggest the
best way to align with that... There are some alarm bells ringing
On Monday, 18 March 2013, Jan Engler wrote:
> Hi,
>
> I am writing my first custom plugin for maven.
> I`m now facing 2 problem.
> - I need to know the absolute location of every dependency (incl.
> transitive deps)
You need @requiresDependencyResolution in the java doc annotations or the
equivalent (on a phone so cannot look up) for java 1.5 annotations
> - Is there a solution for workspace dependencies (i would like to have a
> "jar" of them as well) like "disable workspace resolution" as a method
> call in the plugin?
Here is the alarm bell FYI
>
> Thx in advance!
> Jan
>
> Mit freundlichen Grüßen / Best regards
>
> Jan Engler
> Central Research & Development
>
> SICK AG
> Erwin-Sick-Str. 1
> 79183 Waldkirch, Germany
>
> Phone +49 7681 202-3214
> mailto:jan.engler@sick.de <javascript:;>
> http://www.sick.com
>
>
>
> SICK AG - Sitz: Waldkirch i. Br. - Handelsregister: Freiburg i. Br. HRB
> 280355
> Vorstand: Dr. Robert Bauer (Vorsitzender) - Reinhard Bösl - Dr. Martin
> Krämer - Markus Paschmann - Markus Vatter
> Aufsichtsrat: Gisela Sick (Ehrenvorsitzende) - Klaus M. Bukenberger
> (Vorsitzender)
>
--
Sent from my phone