Java/Maven: integrating org.freedesktop.NetworkManager - java

Is there a published reliable way to pull the org.freedesktop.NetworkManager package into a Maven build? Searching on https://mvnrepository.com I find this but I think it's not org.freedesktop.NetworkManager and in any case the artifact no longer exists on https://jcenter.bintray.com/.

What is normally done in this case is to generate the code using the introspection data. There are a number of introspection XML files in the repository for NetworkManager depending on what you're attempting to control.
If you are using the original dbus-java 2.7 bindings, you would use the CreateInterface class. If you are using the updated 3.2 bindings from hypfvieh, you can generate the code using the InterfaceCodeGenerator class. I would recommend using the 3.2 bindings, as a number of bugs have been fixed and it is available via Maven Central.

Related

Use cases of bootstrapping maven

I've seen some companies using maven bootstrap binary, instead of the one You get by the package manager.
What are the typical use cases of bootstrapping maven?
It is useful when you want to use different Maven versions on different projects. Besides that it requires less setup on new environment, because the required version is encapsulated and under configuration control. Also, it can be the case of using a newer version that the one provided by the package manager.
maven-wrapper is a tool that simplifies this pattern.
When you willing Docker as containers to build your app in clouds for example.

How to register custom rules in a plugin for SonarQube 4.5?

SonarQube version: 4.5
I created a Java project based on the sonar-xoo-plugin.
Then I added a simple rule which inherits BaseTreeVisitor and always raises an issue in visitMethod(MethodTree). I annotated the class with #Rule(key = "x1") and used the same key in the class MyRulesDefinition when creating a new rule in the repository.
I built the project, put the jar file into the plugins folder and started the sonar server. The plugin was loaded and the rule existed. I activated it for the selected quality profile and ran an analysis but no issues were found by the rule.
What am I doing wrong? How is the rule template in MyRulesDefinition mapped to the logic of the rule?
Do any other examples exist for SonarQube plugins using the latest API?
Do any other examples exist for SonarQube plugins using the latest API?
No, I faced exactly the same issue today and couldn't find any. But here is the solution :
Create a class implementing RulesDefinition -> it is a ServerExtension whose sole purpose is to make your custom rules appear in SonarQube's UI if you've explicitly provided a definition (programatically, or in a XML file, or through annotations). This extension is loaded at server startup.
Create a class implementing BatchExtension and JavaFileScannersFactory -> its purpose is to make all your custom java rules available during batch analysis by returning instances of your rules. This extension is loaded during analysis.
Create a class extending SonarPlugin which returns Extensions created in points 1 and 2 above.
Your custom rules will then be both available in UI and during analysis. If you don't do 1. you won't be able to activate / configure them. If you forget 2, they will be activable / configurable, but will never be executed (and no error will be raised neither)
It's a slight difference with RulesRepository : your CustomRulesRepository extending RulesRepository could directly implement BatchExtension and JavaFilesScanner.
I exposed sample example (based on gradle) on github: https://github.com/misak69/misak69-sonar-custom. All important facts are based on previous answer from #kraal. Feel free to look for https://github.com/misak69/misak69-sonar-custom/blob/master/README.md
You can take a look at the Java Custom Rules example plugin. This one should give you all the answers you need.

How to depend on two different versions of a library?

I am using ElasticSearch and JackRabbit (or...I am trying too). JackRabbit seems to be depending on Lucene 3.6.x and ElasticSearch is depending on 4.3.1. I am using Maven and JBoss 7.1.1. I get Lucene 4.3.1 on the classpath but then h*** is breaking loose in the log because JackRabbit requires something from the older Lucene.
How do I solve this?
you will need to take the conflicting libraries that you wish to use (elastic search and jackrabbit) and make both into jboss as7 modules. with jboss 7 modular classloading you can "contain" each of them with its own dependencies as a separate module and expose to your application only the api that you use.
its a bit complicated (full docs here) but will allow you to have each of them use their own version of lucene - they will each be packed into a module with all of theor dependency tree.
EDIT - there's some more info on how to export only some of a module's content in te jboss modules documentation. you want to make sure you dont export lucene out of any of the modules
You can create two custom classloaders instances and load ElasticSearch class with one of them and JackRabbit with the other. The first one must be loading classes from Lucene 3.6.x jar, the other from v.4.3.1 jar

How to find out which dependencies need to be included?

I'm fairly new to Java/Spring and am trying to put together a simple app which will include some basic CRUD operations and I'd like to use Hibernate for data access.
I'm using Maven as my build tool. My question is: how can I find out which dependencies are required to use Hibernate? For example, I'm using Spring 3.0.6, but how would I know what version of Hibernate to use with that version of Spring? More over, if there are multiple possible Hibernate dependencies, how would I know which ones to include for the functionality I need? So far this seems to be partially reading documentation and partially trial and error.
Is there a definitive way of knowing which Maven dependencies to use with certain version of other dependencies? Any which dependencies to use for particular bits of functionality?
Thanks,
James.
I follow these steps when starting to use a new framework:
Go to framework's web site. In your case hibernate web site and try to find latest (or a specific) version. For hibernate it is 3.6.8-Final at the time of writing.
Search for a maven dependency definition on the framework web site. If you can not find any dependency definition, them simply google for "frameworkname _version_ maven dependency" and you'll most probably find necessary definition, as well as the necessary repository information. For example you can find the dependency definition for hibernate on mvnrepository.com and necessary artifact repository information on Hibernate 3.6.8 release page:
The artifacts have all been published to the JBoss Nexus repository under the org.hibernate groupId at http://repository.jboss.org/nexus/content/groups/public-jboss/
The question of which dependencies are necessary and which are optional depends entirely on the framework to be used. So for example in order to use hibernate, as stated on Hibernate Quick Start Guide:
hibernate-core: The main artifact, which contains all the Hibernate classes, in packageorg.hibernate. You need these to build applications using the native Hibernate APIs. It includes capabilities for using native Hibernate mapping in hbm.xml files, as well as annotations.
About compatibility issues (which version of hibernate is compatible with spring 3.0.6), all I can say is you have to read about integration manuals for those frameworks. Since Spring and Hibernate are two exclusively distinct frameworks, I don't think you can find a constant location to look for version compatibility matrix or something like that.
The purpose of Maven is to avoid handling dependencies by hand. Just choose which version of Hibernate to use and include it in your pom; Spring supports many different versions.
If you know what parts of Spring you want to use, just include those parts in your pom; they'll include their own requirements.
Is there a specific module and/or version combination you're having an issue with?
The only way to know for sure that you've got all dependencies is by running your app.
Maven resolves for you transitive dependencies so you can quickly detect missing ones by compiling the java code.
However, in a web app there are many dependencies that are required in runtime only, so they are not detected at compilation time.
you can find out the dependencies by running mvn dependency:tree and analyze if they are required or not by running mvn dependency:analyze.
Taking the newest ones usally works as long as they are stable.
Start with hibernate and spring core, context, tx.
After you added some could you will probably recognize that something else is missing.
Try and error doesn't sound good, but its working pretty well for spring dependencies.

How do you manage Hibernate's zillion JAR files

For my previous employer I've worked with Hibernate, and now that I'm in a small startup I would like to use it again. However, downloading both the Hibernate core and the Hibernate annotations distributions is rather painful, as it requires putting a lot of JAR files together. Because the JARs are split up into categories such as "required" and "optional" I would assume that every developer ends up with a different contents of his lib folder.
What is the common way to handle this problem? Basically I want to have a formal way to get all the JARs for Hibernate, so that (in theory) I would end up with exactly the same stuff if I would need again for another project next month.
Edit: I know roughly what Maven does, but I was wondering if there was another way to manage this sort of thing.
As Aaron has already mentioned, Maven is an option.
If you want something a bit more flexible you could use Apache Ant with Ivy.
Ivy is a dependency resolution tool which works in a similar way to Maven, you just define what libraries your project needs and it will go off and download all the dependencies for you.
Maybe this is not much of an answer, but I really don't see any problem with Hibernate dependencies. Along with hibernate3.jar, you need to have:
6 required jars, out of which commons-collections, dom4j and slf4j are more often used in other open-source projects
1 of either javassist or CGLIB jars
depending on cache and connection pooling, up to 2 jar files, which are pretty much Hibernate specific
So, at the very worst, you will have a maximum of 10 jars, Hibernate's own jar included. And out of those, only commons-collections, dom4j and slf4j will probably be used by some other library in your project. That is hardly a zillion, it can be managed easily, and surely does not warrant using an "elephant" like Maven.
I use Maven 2 and have it manage my dependencies for me.
One word of caution when considering using Maven or Ivy for managing dependencies is that the quality of the repository directly affects your build experience. If the repo is unavailable or the meta-data for the artifacts (pom.xml or ivy.xml) is incorrect you might not be able to build. Building your own local repository takes some work but is probably worth the effort. Ivy, for example, has an ANT task that will import artifacts from a Maven repository and publish them to you own Ivy repository. Once you have a local copy of the Maven repo, you can adjust the meta-data to fit what ever scheme you see fit to use. Sometimes the latest and greatest release is not in the public repository which can sometimes be an issue.
I assume you use the Hibernate APIs explicitly? Is it an option to use a standard API, let's say JPA, and let a J2EE container manage the implementation for you?
Otherwise, go with Maven or Ivy, depending on your current build system of choice.

Categories

Resources