I'm developing a code-sharing plugin for eclipse (for a bachelor thesis project).
Currently I'm trying to scan a maven repository and generate a package list.
I can download and parse a pom.xml using the maven.model classes, but I can't figure out which maven classes are responsible for parsing of archetype-catalog.xml
Is there a non maven parser?
Can I just scan the entire repository tree for pom.xml files?
edit: Ive found nexus-indexer but i have no idea hot to use it :(
It took ages but i finally found a working example
PlexusContainer plexus = new DefaultPlexusContainer(); NexusIndexer n = (NexusIndexer) plexus.lookup(NexusIndexer.class); IndexUpdater iu = (IndexUpdater) plexus.lookup(IndexUpdater.class); // DefaultNexusIndexer n = new DefaultNexusIndexer(); List indexCreators=new ArrayList(); // IndexingContext c = n.addIndexingContext("test", "test",new File( "/home/tomas/Desktop/test"),new File( "/home/tomas/Desktop/index"), "http://repository.jboss.org/", null); Directory tempIndexDirectory = new RAMDirectory(); // IndexCreator min = new MinimalArtifactInfoIndexCreator(); // MavenPluginArtifactInfoIndexCreator mavenPlugin = new MavenPluginArtifactInfoIndexCreator(); // MavenArchetypeArtifactInfoIndexCreator mavenArchetype = new MavenArchetypeArtifactInfoIndexCreator(); // JarFileContentsIndexCreator jar = new JarFileContentsIndexCreator(); // IndexCreator min = plexus.lookup( IndexCreator.class, MinimalArtifactInfoIndexCreator.ID ); IndexCreator mavenPlugin = plexus.lookup( IndexCreator.class, MavenPluginArtifactInfoIndexCreator.ID ); IndexCreator mavenArchetype = plexus.lookup( IndexCreator.class, MavenArchetypeArtifactInfoIndexCreator.ID ); IndexCreator jar = plexus.lookup( IndexCreator.class, JarFileContentsIndexCreator.ID ); indexCreators.add(min); indexCreators.add(mavenPlugin); indexCreators.add(mavenArchetype); indexCreators.add(jar); IndexingContext c = n.addIndexingContext( "temp", "test", new File("/home/tomas/Desktop/mavenTest"), tempIndexDirectory, "http://repository.jboss.org/maven2/", null, indexCreators ); IndexUpdateRequest ur=new IndexUpdateRequest(c); ur.setForceFullUpdate(true); iu.fetchAndUpdateIndex(ur); // for (String s : c.getAllGroups()) { // System.out.println(s); // } BooleanQuery q = new BooleanQuery(); q.add(n.constructQuery(ArtifactInfo.GROUP_ID, "*"), Occur.SHOULD); FlatSearchRequest request = new FlatSearchRequest(q); FlatSearchResponse response = n.searchFlat(request); for (ArtifactInfo a : response.getResults()) { String bUrl=url+a `enter code here`.groupId+"/"+a.artifactId+"/"+a.version+"/"; String fileName=a.artifactId+"-"+a.version; System.out.println(bUrl+fileName+"."+a.packaging); )}
For future reference, the nexus-indexer
has been donated to the Apache Foundation and is now known as the maven-indexer
. There is a github mirror and the project is also listed at the Apache Git page
Scanning my local repository for packages would be pretty slick. I would have a ton of duplicated packages that would need to be considered before I shared anything. Since yesterday I was building version 1.1.1-SNAPSHOT to my repository and today I'm building version 1.1.2-SNAPSHOT, directories for both versions would share the same packages.
Now, if you were wanting to show which artifacts being used in a project, you could just use the dependency plugin. Two of my favorite commands at the beginning of a maven project are:
mvn dependency:tree
and
mvn dependency:resolve
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.