github.com/tiagovtristao/plz@v13.4.0+incompatible/tools/please_maven/maven/maven_test.go (about) 1 // This is a more or less end-to-end test with a fake web server on the whole package 2 // as a black box. Expected outputs are taken from the older version of the tool, so 3 // may not be 100% correct, but empirically they are pretty reasonable and so are 4 // a good place to start for testing the new version. 5 6 package maven 7 8 import ( 9 "net/http" 10 "net/http/httptest" 11 "os" 12 "strings" 13 "testing" 14 15 "github.com/stretchr/testify/assert" 16 17 "github.com/thought-machine/please/src/cli" 18 "sort" 19 ) 20 21 // concurrency is the number of concurrent goroutines we use during the test. 22 // TODO(peterebden): Make this configurable so we test with different numbers. 23 const concurrency = 10 24 25 // Packages that we exclude (they should be test-only dependencies but aren't marked as such) 26 var excludes = []string{"junit", "easymock", "easymockclassextension"} 27 28 var server *httptest.Server 29 var errorProne, grpc []Artifact 30 31 func TestAllDependenciesGRPC(t *testing.T) { 32 f := NewFetch([]string{server.URL}, excludes, nil) 33 expected := []string{ 34 "io.grpc:grpc-auth:1.1.2:src:BSD 3-Clause", 35 "io.grpc:grpc-core:1.1.2:src:BSD 3-Clause", 36 "com.google.guava:guava:20.0:src:The Apache Software License, Version 2.0", 37 "com.google.errorprone:error_prone_annotations:2.0.11:src:Apache 2.0", 38 "com.google.code.findbugs:jsr305:3.0.0:src:The Apache Software License, Version 2.0", 39 "io.grpc:grpc-context:1.1.2:src:BSD 3-Clause", 40 "com.google.instrumentation:instrumentation-api:0.3.0:src:Apache License, Version 2.0", 41 "com.google.auth:google-auth-library-credentials:0.4.0:src:BSD New license", 42 "io.grpc:grpc-netty:1.1.2:src:BSD 3-Clause", 43 "io.netty:netty-codec-http2:4.1.8.Final:src:Apache License, Version 2.0", 44 "io.netty:netty-codec-http:4.1.8.Final:src:Apache License, Version 2.0", 45 "io.netty:netty-codec:4.1.8.Final:src:Apache License, Version 2.0", 46 "io.netty:netty-transport:4.1.8.Final:src:Apache License, Version 2.0", 47 "io.netty:netty-buffer:4.1.8.Final:src:Apache License, Version 2.0", 48 "io.netty:netty-common:4.1.8.Final:src:Apache License, Version 2.0", 49 "io.netty:netty-resolver:4.1.8.Final:src:Apache License, Version 2.0", 50 "io.netty:netty-handler:4.1.8.Final:src:Apache License, Version 2.0", 51 "com.google.code.gson:gson:2.7:no_src:Apache 2.0", 52 "io.netty:netty-handler-proxy:4.1.8.Final:src:Apache License, Version 2.0", 53 "io.netty:netty-codec-socks:4.1.8.Final:src:Apache License, Version 2.0", 54 "io.grpc:grpc-okhttp:1.1.2:src:BSD 3-Clause", 55 "com.squareup.okhttp:okhttp:2.5.0:src:Apache 2.0", 56 "com.squareup.okio:okio:1.6.0:no_src:Apache 2.0", 57 "io.grpc:grpc-protobuf:1.1.2:src:BSD 3-Clause", 58 "com.google.protobuf:protobuf-java:3.1.0:src:New BSD license", 59 "com.google.protobuf:protobuf-java-util:3.1.0:src:New BSD license", 60 "io.grpc:grpc-protobuf-lite:1.1.2:src:BSD 3-Clause", 61 "com.google.protobuf:protobuf-lite:3.0.1:src:New BSD license", 62 "io.grpc:grpc-protobuf-nano:1.1.2:src:BSD 3-Clause", 63 "com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-5:src:New BSD license", 64 "io.grpc:grpc-stub:1.1.2:src:BSD 3-Clause", 65 } 66 actual := AllDependencies(f, grpc, concurrency, false, false, &Graph{}) 67 assert.Equal(t, expected, actual) 68 } 69 70 func TestAllDependenciesGRPCWithIndent(t *testing.T) { 71 f := NewFetch([]string{server.URL}, excludes, nil) 72 expected := []string{ 73 "io.grpc:grpc-auth:1.1.2:src:BSD 3-Clause", 74 " io.grpc:grpc-core:1.1.2:src:BSD 3-Clause", 75 " com.google.guava:guava:20.0:src:The Apache Software License, Version 2.0", 76 " com.google.errorprone:error_prone_annotations:2.0.11:src:Apache 2.0", 77 " com.google.code.findbugs:jsr305:3.0.0:src:The Apache Software License, Version 2.0", 78 " io.grpc:grpc-context:1.1.2:src:BSD 3-Clause", 79 " com.google.instrumentation:instrumentation-api:0.3.0:src:Apache License, Version 2.0", 80 " com.google.auth:google-auth-library-credentials:0.4.0:src:BSD New license", 81 "io.grpc:grpc-netty:1.1.2:src:BSD 3-Clause", 82 " io.netty:netty-codec-http2:4.1.8.Final:src:Apache License, Version 2.0", 83 " io.netty:netty-codec-http:4.1.8.Final:src:Apache License, Version 2.0", 84 " io.netty:netty-codec:4.1.8.Final:src:Apache License, Version 2.0", 85 " io.netty:netty-transport:4.1.8.Final:src:Apache License, Version 2.0", 86 " io.netty:netty-buffer:4.1.8.Final:src:Apache License, Version 2.0", 87 " io.netty:netty-common:4.1.8.Final:src:Apache License, Version 2.0", 88 " io.netty:netty-resolver:4.1.8.Final:src:Apache License, Version 2.0", 89 " io.netty:netty-handler:4.1.8.Final:src:Apache License, Version 2.0", 90 " com.google.code.gson:gson:2.7:no_src:Apache 2.0", 91 " io.netty:netty-handler-proxy:4.1.8.Final:src:Apache License, Version 2.0", 92 " io.netty:netty-codec-socks:4.1.8.Final:src:Apache License, Version 2.0", 93 "io.grpc:grpc-okhttp:1.1.2:src:BSD 3-Clause", 94 " com.squareup.okhttp:okhttp:2.5.0:src:Apache 2.0", 95 " com.squareup.okio:okio:1.6.0:no_src:Apache 2.0", 96 "io.grpc:grpc-protobuf:1.1.2:src:BSD 3-Clause", 97 " com.google.protobuf:protobuf-java:3.1.0:src:New BSD license", 98 " com.google.protobuf:protobuf-java-util:3.1.0:src:New BSD license", 99 " io.grpc:grpc-protobuf-lite:1.1.2:src:BSD 3-Clause", 100 " com.google.protobuf:protobuf-lite:3.0.1:src:New BSD license", 101 "io.grpc:grpc-protobuf-nano:1.1.2:src:BSD 3-Clause", 102 " com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-5:src:New BSD license", 103 "io.grpc:grpc-stub:1.1.2:src:BSD 3-Clause", 104 } 105 actual := AllDependencies(f, grpc, concurrency, true, false, &Graph{}) 106 assert.Equal(t, expected, actual) 107 } 108 109 func TestAllDependenciesErrorProne(t *testing.T) { 110 f := NewFetch([]string{server.URL}, nil, nil) 111 expected := []string{ 112 "com.google.errorprone:error_prone_annotation:2.0.14:src:Apache 2.0", 113 "com.google.guava:guava:19.0:no_src:The Apache Software License, Version 2.0", 114 "com.google.errorprone:error_prone_check_api:2.0.14:src:Apache 2.0", 115 "com.google.code.findbugs:jsr305:3.0.0:src:The Apache Software License, Version 2.0", 116 "org.checkerframework:dataflow:1.8.10:src:GNU General Public License, version 2 (GPL2), with the classpath exception|The MIT License", 117 "org.checkerframework:javacutil:1.8.10:src:GNU General Public License, version 2 (GPL2), with the classpath exception|The MIT License", 118 "com.google.errorprone:javac:1.9.0-dev-r2973-2:src:GNU General Public License, version 2, with the Classpath Exception", 119 "com.googlecode.java-diff-utils:diffutils:1.3.0:src:The Apache Software License, Version 2.0", 120 "com.google.errorprone:error_prone_annotations:2.0.14:no_src:Apache 2.0", 121 "com.github.stephenc.jcip:jcip-annotations:1.0-1:src:Apache License, Version 2.0", 122 "org.pcollections:pcollections:2.1.2:src:The MIT License", 123 "com.google.auto:auto-common:0.7:src:Apache 2.0", 124 "com.google.code.findbugs:jFormatString:3.0.0:src:GNU Lesser Public License", 125 } 126 actual := AllDependencies(f, errorProne, concurrency, false, false, &Graph{}) 127 assert.Equal(t, expected, actual) 128 } 129 130 func TestAllDependenciesErrorProneWithIndent(t *testing.T) { 131 f := NewFetch([]string{server.URL}, nil, nil) 132 expected := []string{ 133 "com.google.errorprone:error_prone_annotation:2.0.14:src:Apache 2.0", 134 " com.google.guava:guava:19.0:no_src:The Apache Software License, Version 2.0", 135 "com.google.errorprone:error_prone_check_api:2.0.14:src:Apache 2.0", 136 " com.google.code.findbugs:jsr305:3.0.0:src:The Apache Software License, Version 2.0", 137 " org.checkerframework:dataflow:1.8.10:src:GNU General Public License, version 2 (GPL2), with the classpath exception|The MIT License", 138 " org.checkerframework:javacutil:1.8.10:src:GNU General Public License, version 2 (GPL2), with the classpath exception|The MIT License", 139 " com.google.errorprone:javac:1.9.0-dev-r2973-2:src:GNU General Public License, version 2, with the Classpath Exception", 140 " com.googlecode.java-diff-utils:diffutils:1.3.0:src:The Apache Software License, Version 2.0", 141 " com.google.errorprone:error_prone_annotations:2.0.14:no_src:Apache 2.0", 142 "com.github.stephenc.jcip:jcip-annotations:1.0-1:src:Apache License, Version 2.0", 143 "org.pcollections:pcollections:2.1.2:src:The MIT License", 144 "com.google.auto:auto-common:0.7:src:Apache 2.0", 145 "com.google.code.findbugs:jFormatString:3.0.0:src:GNU Lesser Public License", 146 } 147 actual := AllDependencies(f, errorProne, concurrency, true, false, &Graph{}) 148 assert.Equal(t, expected, actual) 149 } 150 151 func TestAllDependenciesTogether(t *testing.T) { 152 f := NewFetch([]string{server.URL}, excludes, nil) 153 expected := []string{ 154 "com.google.errorprone:error_prone_annotation:2.0.14:src:Apache 2.0", 155 "com.google.guava:guava:20.0:src:The Apache Software License, Version 2.0", 156 "com.google.errorprone:error_prone_check_api:2.0.14:src:Apache 2.0", 157 "com.google.code.findbugs:jsr305:3.0.0:src:The Apache Software License, Version 2.0", 158 "org.checkerframework:dataflow:1.8.10:src:GNU General Public License, version 2 (GPL2), with the classpath exception|The MIT License", 159 "org.checkerframework:javacutil:1.8.10:src:GNU General Public License, version 2 (GPL2), with the classpath exception|The MIT License", 160 "com.google.errorprone:javac:1.9.0-dev-r2973-2:src:GNU General Public License, version 2, with the Classpath Exception", 161 "com.googlecode.java-diff-utils:diffutils:1.3.0:src:The Apache Software License, Version 2.0", 162 "com.google.errorprone:error_prone_annotations:2.0.14:no_src:Apache 2.0", 163 "com.github.stephenc.jcip:jcip-annotations:1.0-1:src:Apache License, Version 2.0", 164 "org.pcollections:pcollections:2.1.2:src:The MIT License", 165 "com.google.auto:auto-common:0.7:src:Apache 2.0", 166 "com.google.code.findbugs:jFormatString:3.0.0:src:GNU Lesser Public License", 167 "io.grpc:grpc-auth:1.1.2:src:BSD 3-Clause", 168 "io.grpc:grpc-core:1.1.2:src:BSD 3-Clause", 169 "io.grpc:grpc-context:1.1.2:src:BSD 3-Clause", 170 "com.google.instrumentation:instrumentation-api:0.3.0:src:Apache License, Version 2.0", 171 "com.google.auth:google-auth-library-credentials:0.4.0:src:BSD New license", 172 "io.grpc:grpc-netty:1.1.2:src:BSD 3-Clause", 173 "io.netty:netty-codec-http2:4.1.8.Final:src:Apache License, Version 2.0", 174 "io.netty:netty-codec-http:4.1.8.Final:src:Apache License, Version 2.0", 175 "io.netty:netty-codec:4.1.8.Final:src:Apache License, Version 2.0", 176 "io.netty:netty-transport:4.1.8.Final:src:Apache License, Version 2.0", 177 "io.netty:netty-buffer:4.1.8.Final:src:Apache License, Version 2.0", 178 "io.netty:netty-common:4.1.8.Final:src:Apache License, Version 2.0", 179 "io.netty:netty-resolver:4.1.8.Final:src:Apache License, Version 2.0", 180 "io.netty:netty-handler:4.1.8.Final:src:Apache License, Version 2.0", 181 "com.google.code.gson:gson:2.7:no_src:Apache 2.0", 182 "io.netty:netty-handler-proxy:4.1.8.Final:src:Apache License, Version 2.0", 183 "io.netty:netty-codec-socks:4.1.8.Final:src:Apache License, Version 2.0", 184 "io.grpc:grpc-okhttp:1.1.2:src:BSD 3-Clause", 185 "com.squareup.okhttp:okhttp:2.5.0:src:Apache 2.0", 186 "com.squareup.okio:okio:1.6.0:no_src:Apache 2.0", 187 "io.grpc:grpc-protobuf:1.1.2:src:BSD 3-Clause", 188 "com.google.protobuf:protobuf-java:3.1.0:src:New BSD license", 189 "com.google.protobuf:protobuf-java-util:3.1.0:src:New BSD license", 190 "io.grpc:grpc-protobuf-lite:1.1.2:src:BSD 3-Clause", 191 "com.google.protobuf:protobuf-lite:3.0.1:src:New BSD license", 192 "io.grpc:grpc-protobuf-nano:1.1.2:src:BSD 3-Clause", 193 "com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-5:src:New BSD license", 194 "io.grpc:grpc-stub:1.1.2:src:BSD 3-Clause", 195 } 196 both := append(errorProne, grpc...) 197 actual := AllDependencies(f, both, concurrency, false, false, &Graph{}) 198 assert.Equal(t, expected, actual) 199 } 200 201 func TestBuildRulesErrorProne(t *testing.T) { 202 const expected = `maven_jar( 203 name = 'jsr305', 204 id = 'com.google.code.findbugs:jsr305:3.0.0', 205 hash = '', 206 ) 207 208 maven_jar( 209 name = 'error_prone_annotations', 210 id = 'com.google.errorprone:error_prone_annotations:2.0.14', 211 hash = '', 212 ) 213 214 maven_jar( 215 name = 'guava', 216 id = 'com.google.guava:guava:19.0', 217 hash = '', 218 ) 219 220 maven_jar( 221 name = 'error_prone_annotation', 222 id = 'com.google.errorprone:error_prone_annotation:2.0.14', 223 hash = '', 224 deps = [ 225 ':guava', 226 ], 227 ) 228 229 maven_jar( 230 name = 'javacutil', 231 id = 'org.checkerframework:javacutil:1.8.10', 232 hash = '', 233 ) 234 235 maven_jar( 236 name = 'dataflow', 237 id = 'org.checkerframework:dataflow:1.8.10', 238 hash = '', 239 deps = [ 240 ':javacutil', 241 ], 242 ) 243 244 maven_jar( 245 name = 'javac', 246 id = 'com.google.errorprone:javac:1.9.0-dev-r2973-2', 247 hash = '', 248 ) 249 250 maven_jar( 251 name = 'diffutils', 252 id = 'com.googlecode.java-diff-utils:diffutils:1.3.0', 253 hash = '', 254 ) 255 256 maven_jar( 257 name = 'error_prone_check_api', 258 id = 'com.google.errorprone:error_prone_check_api:2.0.14', 259 hash = '', 260 deps = [ 261 ':error_prone_annotation', 262 ':jsr305', 263 ':dataflow', 264 ':javac', 265 ':diffutils', 266 ':error_prone_annotations', 267 ], 268 ) 269 270 maven_jar( 271 name = 'jcip-annotations', 272 id = 'com.github.stephenc.jcip:jcip-annotations:1.0-1', 273 hash = '', 274 ) 275 276 maven_jar( 277 name = 'pcollections', 278 id = 'org.pcollections:pcollections:2.1.2', 279 hash = '', 280 ) 281 282 maven_jar( 283 name = 'auto-common', 284 id = 'com.google.auto:auto-common:0.7', 285 hash = '', 286 deps = [ 287 ':guava', 288 ], 289 ) 290 291 maven_jar( 292 name = 'jFormatString', 293 id = 'com.google.code.findbugs:jFormatString:3.0.0', 294 hash = '', 295 ) 296 297 maven_jar( 298 name = 'error_prone_core', 299 id = 'com.google.errorprone:error_prone_core:2.0.14', 300 hash = '', 301 deps = [ 302 ':error_prone_annotation', 303 ':error_prone_check_api', 304 ':jcip-annotations', 305 ':pcollections', 306 ':guava', 307 ':auto-common', 308 ':jFormatString', 309 ':jsr305', 310 ':dataflow', 311 ':javac', 312 ':error_prone_annotations', 313 ], 314 )` 315 f := NewFetch([]string{server.URL}, nil, nil) 316 actual := AllDependencies(f, errorProne, concurrency, false, true, &Graph{}) 317 // The rules come out in a different order to the original tool; this doesn't 318 // really matter since order of rules in a BUILD file is unimportant. 319 expectedSlice := strings.Split(expected, "\n\n") 320 sort.Strings(actual) 321 sort.Strings(expectedSlice) 322 assert.Equal(t, expectedSlice, actual) 323 } 324 325 func TestBuildRulesGRPC(t *testing.T) { 326 const expected = `maven_jar( 327 name = 'guava', 328 id = 'com.google.guava:guava:20.0', 329 hash = '', 330 ) 331 332 maven_jar( 333 name = 'error_prone_annotations', 334 id = 'com.google.errorprone:error_prone_annotations:2.0.11', 335 hash = '', 336 ) 337 338 maven_jar( 339 name = 'jsr305', 340 id = 'com.google.code.findbugs:jsr305:3.0.0', 341 hash = '', 342 ) 343 344 maven_jar( 345 name = 'grpc-context', 346 id = 'io.grpc:grpc-context:1.1.2', 347 hash = '', 348 ) 349 350 maven_jar( 351 name = 'instrumentation-api', 352 id = 'com.google.instrumentation:instrumentation-api:0.3.0', 353 hash = '', 354 deps = [ 355 ':jsr305', 356 ], 357 ) 358 359 maven_jar( 360 name = 'grpc-core', 361 id = 'io.grpc:grpc-core:1.1.2', 362 hash = '', 363 deps = [ 364 ':guava', 365 ':error_prone_annotations', 366 ':jsr305', 367 ':grpc-context', 368 ':instrumentation-api', 369 ], 370 ) 371 372 maven_jar( 373 name = 'google-auth-library-credentials', 374 id = 'com.google.auth:google-auth-library-credentials:0.4.0', 375 hash = '', 376 ) 377 378 maven_jar( 379 name = 'grpc-auth', 380 id = 'io.grpc:grpc-auth:1.1.2', 381 hash = '', 382 deps = [ 383 ':grpc-core', 384 ':google-auth-library-credentials', 385 ], 386 ) 387 388 maven_jar( 389 name = 'netty-common', 390 id = 'io.netty:netty-common:4.1.8.Final', 391 hash = '', 392 ) 393 394 maven_jar( 395 name = 'netty-buffer', 396 id = 'io.netty:netty-buffer:4.1.8.Final', 397 hash = '', 398 deps = [ 399 ':netty-common', 400 ], 401 ) 402 403 maven_jar( 404 name = 'netty-resolver', 405 id = 'io.netty:netty-resolver:4.1.8.Final', 406 hash = '', 407 deps = [ 408 ':netty-common', 409 ], 410 ) 411 412 maven_jar( 413 name = 'netty-transport', 414 id = 'io.netty:netty-transport:4.1.8.Final', 415 hash = '', 416 deps = [ 417 ':netty-buffer', 418 ':netty-resolver', 419 ], 420 ) 421 422 maven_jar( 423 name = 'netty-codec', 424 id = 'io.netty:netty-codec:4.1.8.Final', 425 hash = '', 426 deps = [ 427 ':netty-transport', 428 ], 429 ) 430 431 maven_jar( 432 name = 'netty-codec-http', 433 id = 'io.netty:netty-codec-http:4.1.8.Final', 434 hash = '', 435 deps = [ 436 ':netty-codec', 437 ], 438 ) 439 440 maven_jar( 441 name = 'netty-handler', 442 id = 'io.netty:netty-handler:4.1.8.Final', 443 hash = '', 444 deps = [ 445 ':netty-buffer', 446 ':netty-transport', 447 ':netty-codec', 448 ], 449 ) 450 451 maven_jar( 452 name = 'gson', 453 id = 'com.google.code.gson:gson:2.7', 454 hash = '', 455 ) 456 457 maven_jar( 458 name = 'netty-codec-http2', 459 id = 'io.netty:netty-codec-http2:4.1.8.Final', 460 hash = '', 461 deps = [ 462 ':netty-codec-http', 463 ':netty-handler', 464 ':gson', 465 ], 466 ) 467 468 maven_jar( 469 name = 'netty-codec-socks', 470 id = 'io.netty:netty-codec-socks:4.1.8.Final', 471 hash = '', 472 deps = [ 473 ':netty-codec', 474 ], 475 ) 476 477 maven_jar( 478 name = 'netty-handler-proxy', 479 id = 'io.netty:netty-handler-proxy:4.1.8.Final', 480 hash = '', 481 deps = [ 482 ':netty-transport', 483 ':netty-codec-socks', 484 ':netty-codec-http', 485 ], 486 ) 487 488 maven_jar( 489 name = 'grpc-netty', 490 id = 'io.grpc:grpc-netty:1.1.2', 491 hash = '', 492 deps = [ 493 ':grpc-core', 494 ':netty-codec-http2', 495 ':netty-handler-proxy', 496 ], 497 ) 498 499 maven_jar( 500 name = 'okio', 501 id = 'com.squareup.okio:okio:1.6.0', 502 hash = '', 503 ) 504 505 maven_jar( 506 name = 'okhttp', 507 id = 'com.squareup.okhttp:okhttp:2.5.0', 508 hash = '', 509 deps = [ 510 ':okio', 511 ], 512 ) 513 514 maven_jar( 515 name = 'grpc-okhttp', 516 id = 'io.grpc:grpc-okhttp:1.1.2', 517 hash = '', 518 deps = [ 519 ':grpc-core', 520 ':okhttp', 521 ':okio', 522 ], 523 ) 524 525 maven_jar( 526 name = 'protobuf-java', 527 id = 'com.google.protobuf:protobuf-java:3.1.0', 528 hash = '', 529 deps = [ 530 ':junit', 531 ':easymock', 532 ':easymockclassextension', 533 ], 534 ) 535 536 maven_jar( 537 name = 'protobuf-java-util', 538 id = 'com.google.protobuf:protobuf-java-util:3.1.0', 539 hash = '', 540 deps = [ 541 ':protobuf-java', 542 ':guava', 543 ':gson', 544 ':junit', 545 ':easymock', 546 ':easymockclassextension', 547 ], 548 ) 549 550 maven_jar( 551 name = 'protobuf-lite', 552 id = 'com.google.protobuf:protobuf-lite:3.0.1', 553 hash = '', 554 deps = [ 555 ':junit', 556 ':easymock', 557 ':easymockclassextension', 558 ], 559 ) 560 561 maven_jar( 562 name = 'grpc-protobuf-lite', 563 id = 'io.grpc:grpc-protobuf-lite:1.1.2', 564 hash = '', 565 deps = [ 566 ':grpc-core', 567 ':protobuf-lite', 568 ':guava', 569 ], 570 ) 571 572 maven_jar( 573 name = 'grpc-protobuf', 574 id = 'io.grpc:grpc-protobuf:1.1.2', 575 hash = '', 576 deps = [ 577 ':grpc-core', 578 ':protobuf-java', 579 ':guava', 580 ':protobuf-java-util', 581 ':grpc-protobuf-lite', 582 ], 583 ) 584 585 maven_jar( 586 name = 'protobuf-javanano', 587 id = 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-5', 588 hash = '', 589 ) 590 591 maven_jar( 592 name = 'grpc-protobuf-nano', 593 id = 'io.grpc:grpc-protobuf-nano:1.1.2', 594 hash = '', 595 deps = [ 596 ':grpc-core', 597 ':protobuf-javanano', 598 ':guava', 599 ], 600 ) 601 602 maven_jar( 603 name = 'grpc-stub', 604 id = 'io.grpc:grpc-stub:1.1.2', 605 hash = '', 606 deps = [ 607 ':grpc-core', 608 ], 609 ) 610 611 maven_jar( 612 name = 'grpc-all', 613 id = 'io.grpc:grpc-all:1.1.2', 614 hash = '', 615 deps = [ 616 ':grpc-auth', 617 ':grpc-core', 618 ':grpc-context', 619 ':grpc-netty', 620 ':grpc-okhttp', 621 ':grpc-protobuf', 622 ':grpc-protobuf-lite', 623 ':grpc-protobuf-nano', 624 ':grpc-stub', 625 ], 626 )` 627 f := NewFetch([]string{server.URL}, excludes, nil) 628 actual := AllDependencies(f, grpc, concurrency, false, true, &Graph{}) 629 // The rules come out in a different order to the original tool; this doesn't 630 // really matter since order of rules in a BUILD file is unimportant. 631 expectedSlice := strings.Split(expected, "\n\n") 632 sort.Strings(actual) 633 sort.Strings(expectedSlice) 634 assert.Equal(t, expectedSlice, actual) 635 } 636 637 func TestBuildRulesErrorProneWithGraph(t *testing.T) { 638 const expected = `maven_jar( 639 name = 'error_prone_annotations', 640 id = 'com.google.errorprone:error_prone_annotations:2.0.14', 641 hash = '', 642 ) 643 644 maven_jar( 645 name = 'javacutil', 646 id = 'org.checkerframework:javacutil:1.8.10', 647 hash = '', 648 ) 649 650 maven_jar( 651 name = 'dataflow', 652 id = 'org.checkerframework:dataflow:1.8.10', 653 hash = '', 654 deps = [ 655 ':javacutil', 656 ], 657 ) 658 659 maven_jar( 660 name = 'javac', 661 id = 'com.google.errorprone:javac:1.9.0-dev-r2973-2', 662 hash = '', 663 ) 664 665 maven_jar( 666 name = 'diffutils', 667 id = 'com.googlecode.java-diff-utils:diffutils:1.3.0', 668 hash = '', 669 ) 670 671 maven_jar( 672 name = 'error_prone_check_api', 673 id = 'com.google.errorprone:error_prone_check_api:2.0.14', 674 hash = '', 675 deps = [ 676 '//third_party/java:error_prone_annotation', 677 '//third_party/java:jsr305', 678 ':dataflow', 679 ':javac', 680 ':diffutils', 681 ':error_prone_annotations', 682 ], 683 ) 684 685 maven_jar( 686 name = 'jcip-annotations', 687 id = 'com.github.stephenc.jcip:jcip-annotations:1.0-1', 688 hash = '', 689 ) 690 691 maven_jar( 692 name = 'pcollections', 693 id = 'org.pcollections:pcollections:2.1.2', 694 hash = '', 695 ) 696 697 maven_jar( 698 name = 'auto-common', 699 id = 'com.google.auto:auto-common:0.7', 700 hash = '', 701 deps = [ 702 '//third_party/java:guava', 703 ], 704 ) 705 706 maven_jar( 707 name = 'jFormatString', 708 id = 'com.google.code.findbugs:jFormatString:3.0.0', 709 hash = '', 710 ) 711 712 maven_jar( 713 name = 'error_prone_core', 714 id = 'com.google.errorprone:error_prone_core:2.0.14', 715 hash = '', 716 deps = [ 717 '//third_party/java:error_prone_annotation', 718 ':error_prone_check_api', 719 ':jcip-annotations', 720 ':pcollections', 721 '//third_party/java:guava', 722 ':auto-common', 723 ':jFormatString', 724 '//third_party/java:jsr305', 725 ':dataflow', 726 ':javac', 727 ':error_prone_annotations', 728 ], 729 )` 730 g := &Graph{ 731 Packages: map[string]pkg{ 732 "third_party/java": { 733 Targets: map[string]target{ 734 "guava": { 735 Labels: []string{"mvn:com.google.guava:guava:19.0"}, 736 }, 737 "error_prone_annotation": { 738 Labels: []string{"mvn:com.google.errorprone:error_prone_annotation:2.0.14"}, 739 }, 740 "jsr305": { 741 Labels: []string{"mvn:com.google.code.findbugs:jsr305:3.0.0"}, 742 }, 743 }, 744 }, 745 }, 746 } 747 748 f := NewFetch([]string{server.URL}, nil, nil) 749 actual := AllDependencies(f, errorProne, concurrency, false, true, g) 750 // The rules come out in a different order to the original tool; this doesn't 751 // really matter since order of rules in a BUILD file is unimportant. 752 expectedSlice := strings.Split(expected, "\n\n") 753 sort.Strings(actual) 754 sort.Strings(expectedSlice) 755 assert.Equal(t, expectedSlice, actual) 756 } 757 758 func TestMain(m *testing.M) { 759 cli.InitLogging(4) // Suppress informational messages which there can be an awful lot of 760 errorProne = []Artifact{{}} 761 grpc = []Artifact{{}} 762 errorProne[0].FromID("com.google.errorprone:error_prone_core:2.0.14") 763 grpc[0].FromID("io.grpc:grpc-all:1.1.2") 764 server = httptest.NewServer(http.FileServer(http.Dir("tools/please_maven/maven/test_data"))) 765 ret := m.Run() 766 server.Close() 767 os.Exit(ret) 768 }