MavenHoe digged up from the dust (fake Maven repository made out of a directory)
Posted by ozizka in Ondrej Zizka's Blog on May 10, 2016 7:03:00 PMAfter Google code was discontinued, I am pulling my project out of there as needed. Hopefully I'll get all of them before they shut it down for good.
This one is already deleted, so I had to find it in an old SVN repo at one of of old drives.
MavenHoe turns a directory into a Maven repository.
Here's how it works:
Mavenhoe – fake Maven repository from .jar's in local directory tree
Purpose
QA dept often needs to run a maven project with "faked" dependencies - the actual .jar files must be taken from a product's distribution, which are not in any Maven repository (like EAP's .zip or RPM distribution).
This utility is one of the ways to solve this problem. It scans a given directory for .jar files, indexes them, and opens a server acting as a Maven repository, in the sense of serving the indexed .jar files.
Which file will be served is determined by match of strings in the provided Maven URL path (localhost:17283/<group>/<artifact>/<version>/<filename>.jar). This algorithm is a matter of future improvement. Using static mapping file is a possibility.
Usage
Maven project preparation
Optionally disable the central repository if you shouldn't need it - i.e. all your dependencies should be in the directories indexed by Mavenhoe.
See http://community.jboss.org/thread/89912 . One (IMO the best) option is to override it in pom.xml:
<repository>
<id>central</id>
<url>http://some.url</url>
<snapshots><enabled>false</enabled></snapshots>
<releases><enabled>false</enabled></releases>
</repository>
Add Mavenhoe repository to your pom.xml:
<repository>
<id>mavenhoe-repo</id>
<url>http://localhost:17283/jars?mvnPath=</url>
</repository>
Alternatively, you can also add the repo to ~/.m2/settings.xml (or any path and use `mvn -s settings-local.xml`):
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<localRepository>/home/ondra/work/hbn/runner/EAP-5.1/work-space/m2repo</localRepository>
<profiles>
<!-- Mavenhoe fake repository -->
<profile>
<id>mavenhoe-repo</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository>
<id>mavenhoe</id>
<url>http://localhost:17283/jars?mvnPath=</url>
</repository>
</repositories>
</profile>
</profiles>
</settings>
Mapping file
Mapping file tells Mavenhoe which file should be served for certain G:A:C:V axes.
You can provide multiple mapping files, using parameter -map <path/map.txt>
An example of such file is the extracted-metadata.txt.zip attached to https://docspace.corp.redhat.com/docs/DOC-53554 :
# Format:
# <real-file-name> <groupId> <artifactId> [@<cls>] <version> <virtual-file-name>
jboss-managed.jar org/jboss/man/ jboss-managed 2.1.0.SP1 jboss-managed-2.1.0.SP1.jar
getopt.jar gnu-getopt/ getopt 1.0.12-brew getopt-1.0.12-brew.jar
jboss-kernel.jar org/jboss/microcontainer/ jboss-kernel 2.0.6.GA jboss-kernel-2.0.6.GA.jar
jboss-logging-spi.jar org/jboss/logging/ jboss-logging-spi 2.1.0.GA jboss-logging-spi-2.1.0.GA.jar...
The first column is path to a file which should be served (base dir is the current) to Maven client.
Further columns are: groupId (with either slashes or dots), artifactId, [@classifier,] version, artifact file name, respectively.
Classifier can be optionally specified at fourth column, prepended with @ (shifting all remaining columns).
For JBoss products, these information info will be acquired from an online database (see https://docspace.corp.redhat.com/docs/DOC-52060#Versions_database ).
Command line options
Command Format (hopefully the syntax is clear ):
mavenhoe [-sp] ( -map [-fakepoms] <map.txt> | -i [-fakepoms] <dir> | -ipom <dir> )+
Header 1 | Header 2 |
---|---|
-i [-fakepom] <path/to/dir> | Indexes .jar files in this dir tree. G:A:V used: 1) META-INF/pom.xml if present. 2) filename : filename : MANIFEST.MF's Implementation-Version. |
-ipom <path/to/dir> | As with -i, only searches for pom.xml files. |
-map [-fakepom] <path/map.txt> | Mapping file to be used by FileBasedMapper. |
-sp | Strip paths from the 1st column in all map files. (applies to all -map's). |
-fakepom | Applied to next dir tree; Mavenhoe will serve fake .pom files with no dependencies. G:A:C:V used are as described above. |
Meta URLs
Will list all indexed jars.
Will list FileBasedMapper's maps.
Shuts the server down.
Artifact URLs
HTTP code | Meaning |
---|---|
200 | Requested artifact was found, and is server in the response body. See the DEBUG log messages for details. |
400 | Wrong G:A:V path - not in a format <groupId>/<artifactId>/<version>/<filename>.<packaging> . |
403 | Payment required - send donation to author's PayPal .-) |
404 | Requested artifact was not found. See DEBUG logs what was searched. |
409 | FileBasedMapper found a match in a mapping file, but the referenced artifact file does not exist (nothing to serve). |
500 | Internal exception - bug in the app. |
http://localhost:17283/jars?mvnPath=org/jboss/whatever/whatever/5.1.0.GA/whatever-5.1.0.GA.jar
- Should give 404
- Should let you download the hibernate-core-3.3.2.GA_CP03.jar
Build process tips
To ensure that your dependencies are not downloaded from local Maven repository, wipe them out:
mvn build-helper:remove-project-artifact
To use trully "local" repository solely for one project, set it to be in a directory.
This can be done by using modified settings.xml.
cp ~/.m2/settings.xml ./settings-local.xml
sed "s|<localRepository>\(.*\)</localRepository>|<localRepository>local_repo</localRepository>|" -i settings-local.xml
mvn -s settings-local.xml ...
Sample log output
2010-12-10 00:38:25,692 DEBUG org.jboss.qa.mavenhoe.mappers.OrMapper Looking for: jdom : jdom : 1.0 : jdom-1.0.jar
2010-12-10 00:38:25,693 DEBUG org.jboss.qa.mavenhoe.mappers.FileBasedMapper Looking for: jdom : jdom : 1.0 : jdom-1.0.jar
2010-12-10 00:38:25,693 DEBUG org.jboss.qa.mavenhoe.mappers.FileBasedMapper Thus for: 'jdom:jdom'
2010-12-10 00:38:25,693 DEBUG org.jboss.qa.mavenhoe.mappers.FileBasedMapper Supposed file name: null
2010-12-10 00:38:25,693 DEBUG org.jboss.qa.mavenhoe.mappers.ArtifactIdMapper Looking for: jdom : jdom : 1.0 : jar = jdom-1.0.jar
2010-12-10 00:38:25,693 DEBUG org.jboss.qa.mavenhoe.mappers.ArtifactIdMapper Supposed file name: jdom
2010-12-10 00:38:25,693 DEBUG org.jboss.qa.mavenhoe.MavenHoeAppFound: JarInfo{ name: jdom, version: 5.1.0 (build: SVNTag=JBPAPP_5_1_0 date=201009150028),
group: null,
path: eap/jboss-eap-5.1/jboss-as/server/production/deploy/admin-console.war/WEB-INF/lib/jdom.jar,
base: eap }
Comments