LoopPerfect / buckaroo

The decentralized package manager for C++ and friends 🏝️
https://buckaroo.pm
MIT License
934 stars 33 forks source link

Maven Support #314

Open nikhedonia opened 5 years ago

nikhedonia commented 5 years ago

Buck supports Java and downloads from Maven.

remote_file(
  name = 'httpmime-jar',
  sha1 = '54ffde537682aea984c22fbcf0106f21397c5f9b',
  url = 'mvn:org.apache.httpcomponents:httpmime:jar:4.3.4',
  out = 'httpmime.jar',
)

To implement Maven support, Buckaroo would need: 1) to be able to parse maven uri's 2) find and parse pom.xml manifest from maven 3) fetch transitive dependencies 4) generate an appropriate buck file on install

nikhedonia commented 5 years ago

Some more info: A maven repository has a predictable file-structure: http://central.maven.org/maven2/

A maven coordonate eg. com.google.guava:guava maps to http://central.maven.org/maven2/com/google/guava/guava

This folder contains several important files:

A listing of all available versions: http://central.maven.org/maven2/com/google/guava/guava/maven-metadata.xml

<metadata modelVersion="1.1.0">
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <versioning>
    <latest>27.1-jre</latest>
    <release>27.1-jre</release>
    <versions>
      <version>r03</version>
      <version>22.0-rc1-android</version>
      <version>18.0-android</version>
      <version>18.0-jre</version>
...

And foreach version eg. http://central.maven.org/maven2/com/google/guava/guava/22.0-rc1-android

the artefact: http://central.maven.org/maven2/com/google/guava/guava/22.0-rc1-android/guava-22.0-rc1-android.jar

And the Manifest: http://central.maven.org/maven2/com/google/guava/guava/22.0-rc1-android/guava-22.0-rc1-android.pom

Which includes a list of dependencies:


<dependencies>
  <dependency>
    <groupId>com.google.code.findbugs</groupId>
    <artifactId>jsr305</artifactId>
  </dependency>
  <dependency>
    <groupId>com.google.errorprone</groupId>
    <artifactId>error_prone_annotations</artifactId>
  </dependency>
  <dependency>
     <groupId>org.codehaus.mojo</groupId>
     <artifactId>animal-sniffer-annotations</artifactId>
     <version>${animal.sniffer.version}</version>
   </dependency>

Some of the entries may refer to properties:

 <properties>
    <aaa.bbb.ccc>1.7</aaa.bbb.ccc>
  </properties>

Every file also has a corresponding .sha1: http://central.maven.org/maven2/com/google/guava/guava/22.0-rc1-android/guava-22.0-rc1-android.jar.sha1

1) Define a Maven PackageIdentifer & Location

0) download artefact into cache folder 1) copy artefact from cache folder to buckaroo/central/maven/org/maven2/com/google/guava/guava/22.0-rc1-android/

generate a BUCK file:

load('//buckaroo_macros.bzl', 'buckaroo_deps')
prebuilt_jar(
  name = 'guava-22.0-rc1-android-prebuilt',
  binary_jar = 'guava-22.0-rc1-android.jar',
  source_jar = 'guava-22.0-rc1-android.sources.jar', # optional
  javadoc_url = 'http://kentbeck.github.com/junit/javadoc/4.8/', # optional
)

java_library(
  name = 'guava-22.0-rc1-android',
  visibility = ['PUBLIC'],
  deps = buckaroo_deps()
)

https://buckbuild.com/rule/prebuilt_jar.html