maven_rules.bzl: Fix maven coordinates order mismatch 

Classifier should be provided in the form:

  "groupId:artifactId:version[:packaging][:classifier]"

because that's what maven-dependency-plugin expects and not in the form:

  "groupId:artifactId[:packaging][:classifier]:version"

as documented here: [1]. Also it was missed to reflect the classifier in
the output artifact name.

TEST PLAN:

WORKSPACE:

  load("//tools:maven_rules.bzl", "maven_jar",
     "maven_dependency_plugin")
  maven_dependency_plugin()
  maven_jar(
    name = "jetty_server_sources",
    artifact = "org.eclipse.jetty:jetty-server:9.3.11.v20160721:jar:sources",
    sha1 = "b23cac190808baed928260b2c9beca3b1ed232b4",
  )

BUILD:

  java_library(
    name = "jetty-server-sources",
    exports = ["@jetty_server_sources//jar"],
  )

  $ bazel build :jetty-server-sources
  [...]
  Target //:jetty-server-sources up-to-date:
  bazel-bin/libjetty-server-sources.jar

[1] https://maven.apache.org/pom.html#Maven_Coordinates

Fixes #2049.

--
Change-Id: I3297fb3676324cc6b4bb6ff6b2b6e18ce33f633c
Reviewed-on: https://cr.bazel.build/7213
PiperOrigin-RevId: 144972944
MOS_MIGRATED_REVID=144972944
diff --git a/tools/build_defs/repo/maven_rules.bzl b/tools/build_defs/repo/maven_rules.bzl
index 90b1e37..9a15166 100644
--- a/tools/build_defs/repo/maven_rules.bzl
+++ b/tools/build_defs/repo/maven_rules.bzl
@@ -24,7 +24,10 @@
 # 3) maven_dependency_plugin()
 #    This rule downloads the maven-dependency-plugin used internally
 #    for testing and the implementation for the fetching of artifacts.
-
+#
+# Maven coordinates are expected to be in this form:
+# groupId:artifactId:version[:packaging][:classifier]
+#
 # Installation requirements prior to using this rule:
 # 1) Maven binary: `mvn`
 # 2) Maven plugin: `maven-dependency-plugin:2.10`
@@ -78,9 +81,9 @@
     # downloads the correct artifact.
     fully_qualified_name = "%s:%s" % (fully_qualified_name, packaging)
   elif len(parts) == 4:
-    group_id, artifact_id, packaging, version = parts
+    group_id, artifact_id, version, packaging = parts
   elif len(parts) == 5:
-    group_id, artifact_id, packaging, classifier, version = parts
+    group_id, artifact_id, version, packaging, classifier = parts
   else:
     fail("Invalid fully qualified name for artifact: %s" % fully_qualified_name)
 
@@ -102,9 +105,11 @@
   """Creates a struct that contains the paths to create the cache WORKSPACE"""
 
   # e.g. guava-18.0.jar
-  artifact_filename = "%s-%s.%s" % (coordinates.artifact_id,
-                                    coordinates.version,
-                                    coordinates.packaging)
+  artifact_filename = "%s-%s" % (coordinates.artifact_id,
+                                 coordinates.version)
+  if coordinates.classifier:
+    artifact_filename += "-" + coordinates.classifier
+  artifact_filename += "." + coordinates.packaging
   sha1_filename = "%s.sha1" % artifact_filename
 
   # e.g. com/google/guava/guava/18.0