ceving
ceving

Reputation: 23826

How to calculate the URL of a POM file by group, artifact and version?

It is possible to download a POM file from via the URL

http://search.maven.org/remotecontent?filepath

The POM file for the Apache Commons Daemon package for example is identified by the three attributes

The resulting URL is:

http://search.maven.org/remotecontent?filepath=commons-daemon/commons-daemon/1.0.13/commons-daemon-1.0.13.pom

This URL gets calculated by the central repository, if I search by the three attributes using the interactive search. The same search can be done using the REST API, which returns an XML document. This is the result node of the XML response:

<result name="response" numFound="1" start="0">
  <doc>
    <str name="a">commons-daemon</str>
    <arr name="ec">
      <str>-javadoc.jar</str>
      <str>-sources.jar</str>
      <str>.jar</str>
      <str>-bin-windows.zip</str>
      <str>-native-src.tar.gz</str>
      <str>-src.zip</str>
      <str>-src.tar.gz</str>
      <str>-native-src.zip</str>
      <str>.pom</str>
      <str>-bin.tar.gz</str>
      <str>-bin.zip</str>
    </arr>
    <str name="g">commons-daemon</str>
    <str name="id">commons-daemon:commons-daemon:1.0.13</str>
    <str name="p">jar</str>
    <arr name="tags">
      <str>software</str>
      <str>commons</str>
      <str>invocation</str>
      <str>provides</str>
      <str>alternative</str>
      <str>mechanism</str>
      <str>apache</str>
      <str>daemon</str>
      <str>java</str>
      <str>code</str>
      <str>like</str>
      <str>unix</str>
    </arr>
    <long name="timestamp">1360214551000</long>
    <str name="v">1.0.13</str>
  </doc>
</result>

Result lists all available files, but only the suffixes. The URLs are missing and it is not obvious to me how to calculate them.

What is the correct rule to calculate the complete filepath?

As far as I can see the directory seems to be created by appending group, artifact and version and by replacing any dots with slashes. And the version number is also the last part of the file name. But how to calculate the beginning of the file name? Is it always the artifact?

Upvotes: 0

Views: 251

Answers (1)

FrVaBe
FrVaBe

Reputation: 49341

Have a look at the Repository Layout specification that was written by @Brett Porter.

Quote:

For primary artifacts:

/$groupId[0]/../$groupId[n]/$artifactId/$version/$artifactId-$version.$extension

For secondary artifacts:

/$groupId[0]/../$groupId[n]/$artifactId/$version/$artifactId-$version-$classifier.$extension

He self referenced to it in this SO answer.

Upvotes: 2

Related Questions