I want to create an Archetype in which the user can provide artifactId. Then I want to take this artifactId and create two files.
Here is an example.
artifactId= box
FILE 1: copy-box.txt
FILE 2 : Box.java
Creating copy-box.txt is quite easy. But how to create Box.java with B capital?
I looked through the code that creates the replacement in the filenames of the archetype resources (which can be found here). It seems that the values of the arguments are taken from the context, which means that they are not evaluated. In my opinion, for the moment it is not possible (sad, but true) to use the evaluation mechanism directly in the file names.
However, by simply implementing the FilesetArchetypeGenerator interface, a good contribution can be made to the archetypes generation.
There is a bug in maven archetype. See bug reports ARCHETYPE-406 and ARCHETYPE-397.
When fixed it will be possible to define and use custom requiredProperty for your case.
In archetype-metadata.xml add
<requiredProperties>
<requiredProperty key="classPrefix" >
<defaultValue>
${artifactId.substring(0,1).toUpperCase()}${artifactId.substring(1)}
</defaultValue>
</requiredProperty>
</requiredProperties>
Don't forget to add classPrefix to archetype.properties
Related
I am a bit new to eclipse plugin development. My requirement:
I want to show warning signs(like screenshot attached) in the import statements Java files and effective pom files of Java projects based on some parameters.
Assuming eclipse already has some classes and functions for this, I would like to know what dependencies I could add in my Manifest file of my Eclipse Plugin and which class I could extend and functions I could use to implement my requirement?
Any help would be very much appreciated. Thank you.
If you're willing this to happen at same time as compilation, you can add an extension to the org.eclipse.jdt.core.compilationParticipant extension point ( https://help.eclipse.org/2019-12/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_jdt_core_compilationParticipant.html ) and implement the CompilationParticipant.reconcile() method to look at the content of the file and use putProblems() to add problems.
You can also put it in a separate builder ( https://help.eclipse.org/2019-12/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Freference%2Fref-5.htm ), or resource listener, or document listener, that would invoke file.createMarker(...) to add the error markers.
All that depends on which layer you prefer to hook onto.
What is the best way to find the right dependency for a used class that are part of the maven-online-repository?
As far I see it is this approach:
lookup the import (e.g. org.whatever.X;) from your code at the maven-repository online (search.maven.org).
Pick one of the result list and include it in the dependency section of the POM.
Hope the chosen version and artifact of the dependency matches your requirements (compiling, runtime). If not try another artifact or version.
I'd like to share my way of doing it. What do you mean by "finding the ... for a used class that are part of the ..."? Do you mean that the dependancy is already used in somewhere else, or that you only know the package name that you may need?
I would first check which version I need for the current project.
If I'm working on a team project and someone has used the dependency in somewhere else, I would check their pom (to ensure we are using the same dependency).
Then I would look up the dependency in Maven repo and include it in my pom.
Hope this helps.
Essentially, yes this is what you have to do to obtain libraries/modules for your project.
Something that's helped me out though with this specific problem: versioning. You can set the versions you need for each of your dependencies with <properties> -> <gson.version>2.8.1</gson.version> (for example). That way, you can guarantee that your build matches with the reqs of the class or type of code you're trying to implement.
Maven doc ref: https://maven.apache.org/pom.html#Properties
XML being one of the reasons people move to Gradle, our project defines several pom packaged items. I assume that these are BOM's since they just used to pull in dependencies. So... how do you define a BOM in Gradle from a "best practices" / no XML perspective? I know that you can create a configuration that has dependencies and then just include it but I don't, for example, want "gradle build" to create a jar file for this sub-project as it would be pointless and slow down my build for no good reason. Am I on the right track or is there a better way and if so, what is it? Do I just turn off the jar creation somehow?
I think this is what I need. It's from right out of the Gradle User Guild in Chapter 52. Specifically it's Example 52.16. "Collections and arrays of dependencies".
List groovy = ["org.codehaus.groovy:groovy-all:2.4.4#jar",
"commons-cli:commons-cli:1.0#jar",
"org.apache.ant:ant:1.9.4#jar"]
List hibernate = ['org.hibernate:hibernate:3.0.5#jar',
'somegroup:someorg:1.0#jar']
dependencies {
runtime groovy, hibernate
}
I'm developing a plugin which I need to run on every single project in my Jenkins cluster. I need a way to ensure it is added by default when new projects are created (I can use groovy to add it to the existing projects).
I know from developing another plugin in the past, with ListViewColumn there is a shownByDefault() in the descriptor. I can't seem to find an equivalent for Recorder/Notifier/Publisher... although I'm happy to use any other class providing I can have the logic run after a build and add a BadgeAction.
Thanks
Will Inheritance and Template plugins suffice?
This can be achieved by implementing hudson.model.listeners.ItemListener.
It has onLoaded(), onCreated(Item item), onUpdated(Item item), which can be used to add in this case a Notifier to the project... the Item can be casted to AbstractProject, then getPublishersList().add(instance to add).
Don't forget when modifying the build or project objects in this way to call .save() to ensure your changes are persisited.
I would like to be able to determine what versions I am running of a dependency at runtime as well as the version of the web application itself.
Each web application I deploy is packaged with a pom.xml which I can read from, that part is trivial. The next part is parsing the pom without much effort.
As the web application is running, I want to be able to understand what version I am, and what versions my dependencies are.
Ideally, I would like to do something like:
MavenPom pom = new MavenPom(webApplicationPomInputStream);
pom.getVersion();
pom.getArtifactId();
pom.getGroupId();
for(Dependency dependency:pom.getDependencies())
{
dependency.getVersion();
dependency.getArtifactId();
dependency.getGroupId();
}
Should I just use XPath notation here, or is there a library I can call to do this type of thing?
After these posts, I am thinking the quickest/most reliable way is to generate a text file with the dependency tree in it: mvn dependency:tree. Then I will parse the text file, separate the groupId, artifactId, and version, and then determine the structure by the indentation level.
If I do that, can I export to XML instead of text? I can then use JAXB and easily parse that file without doing any/much work.
It is a hack, but looks promising.
Walter
I will just use the mvn dependency:tree plugin to generate a text file with the dependency tree. Then I will parse that in and create the dependency tree/graph from that. I will get the scope of the artifact, groupId, artifactId, version, and its parent.
I successfully implemented this type of lookup, it simply takes the dependency output, parses it and organizes dependencies simply using the indentation, nothing fancy. The artifact, group, version, and scope are easily parsed since the separator is a :.
Walter
Maven has of course such an API. Have a look at org.apache.maven.project.MavenProject. But, to be honest, I don't think it will be that easy to create a MavenProject instance. The source code will be helpful here, check for example MavenProjectTest or maybe the Maven Plugin API (actually, this task would be much, really much, simpler to achieve from a Mojo) for some guidance.
I'd suggest to search for or ask this question on the Maven Mailing Lists, org.apache.maven.dev would be appropriate here IMHO.