File tree Expand file tree Collapse file tree 4 files changed +22
-11
lines changed
java/com/github/dockerjava/core
resources/META-INF/services
test/java/com/github/dockerjava Expand file tree Collapse file tree 4 files changed +22
-11
lines changed Original file line number Diff line number Diff line change 1- package com .github .dockerjava .jaxrs ;
1+ package com .github .dockerjava .core ;
2+
3+ import java .util .ServiceLoader ;
24
35import com .github .dockerjava .api .DockerClient ;
46import com .github .dockerjava .api .command .DockerCmdExecFactory ;
5- import com .github .dockerjava .core .DockerClientConfig ;
6- import com .github .dockerjava .core .DockerClientImpl ;
77
88public class DockerClientBuilder {
9+
10+ private static ServiceLoader <DockerCmdExecFactory > serviceLoader = ServiceLoader .load (DockerCmdExecFactory .class );
911
1012 private DockerClientImpl dockerClient = null ;
1113
@@ -29,8 +31,19 @@ public static DockerClientBuilder getInstance(String serverUrl) {
2931
3032 private static DockerClientImpl withDefaultDockerCmdExecFactory (
3133 DockerClientImpl dockerClient ) {
34+
35+ DockerCmdExecFactory dockerCmdExecFactory = getDefaultDockerCmdExecFactory ();
36+
3237 return dockerClient
33- .withDockerCmdExecFactory (new DockerCmdExecFactoryImpl ());
38+ .withDockerCmdExecFactory (dockerCmdExecFactory );
39+ }
40+
41+ public static DockerCmdExecFactory getDefaultDockerCmdExecFactory () {
42+ if (!serviceLoader .iterator ().hasNext ()) {
43+ throw new RuntimeException ("Fatal: Can't find any implementation of '" + DockerCmdExecFactory .class .getName () + "' in the current classpath." );
44+ }
45+
46+ return serviceLoader .iterator ().next ();
3447 }
3548
3649 public DockerClientBuilder withDockerCmdExecFactory (
Original file line number Diff line number Diff line change 1+ com.github.dockerjava.jaxrs.DockerCmdExecFactoryImpl
Original file line number Diff line number Diff line change 1616
1717import com .github .dockerjava .api .DockerClient ;
1818import com .github .dockerjava .api .DockerException ;
19+ import com .github .dockerjava .core .DockerClientBuilder ;
1920import com .github .dockerjava .core .TestDockerCmdExecFactory ;
20- import com .github .dockerjava .jaxrs .DockerClientBuilder ;
21- import com .github .dockerjava .jaxrs .DockerCmdExecFactoryImpl ;
2221
2322public abstract class AbstractDockerClientTest extends Assert {
2423
@@ -27,7 +26,7 @@ public abstract class AbstractDockerClientTest extends Assert {
2726
2827 protected DockerClient dockerClient ;
2928
30- protected TestDockerCmdExecFactory dockerCmdExecFactory = new TestDockerCmdExecFactory (new DockerCmdExecFactoryImpl ());
29+ protected TestDockerCmdExecFactory dockerCmdExecFactory = new TestDockerCmdExecFactory (DockerClientBuilder . getDefaultDockerCmdExecFactory ());
3130
3231 public void beforeTest () {
3332 LOG .info ("======================= BEFORETEST =======================" );
Original file line number Diff line number Diff line change 1313import com .github .dockerjava .api .DockerException ;
1414import com .github .dockerjava .api .UnauthorizedException ;
1515import com .github .dockerjava .client .AbstractDockerClientTest ;
16+ import com .github .dockerjava .core .DockerClientBuilder ;
1617import com .github .dockerjava .core .DockerClientConfig ;
17- import com .github .dockerjava .jaxrs .DockerClientBuilder ;
1818
1919public class AuthCmdImplTest extends AbstractDockerClientTest {
2020
@@ -53,8 +53,6 @@ public void testAuthInvalid() throws Exception {
5353 fail ("Expected a UnauthorizedException caused by a bad password." );
5454 } catch (UnauthorizedException e ) {
5555
56- } finally {
57- client .close ();
58- }
56+ }
5957 }
6058}
You can’t perform that action at this time.
0 commit comments