Skip to content

Commit 4f1907b

Browse files
committed
Adds the ability to wait for the server to start before attempting to run commands. Reorganises command package structure. Factors out declarative application logic into separate services. Improves docs.
1 parent 9145205 commit 4f1907b

102 files changed

Lines changed: 1964 additions & 996 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [Unreleased]
7+
### Added
8+
- Adds the ability to wait for the server to start before attempting to run commands.
9+
- Improvements to internal code structure.
10+
611
## [0.2.3] - 2016-09-22
712
### Added
813
- Adds support for multiple versions of an API in the same declaration file.

src/main/java/io/apiman/cli/Cli.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2016 Pete Cornish
2+
* Copyright 2017 Pete Cornish
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,14 +17,17 @@
1717
package io.apiman.cli;
1818

1919
import com.google.common.collect.Lists;
20-
import io.apiman.cli.command.AbstractCommand;
21-
import io.apiman.cli.command.Command;
22-
import io.apiman.cli.core.api.command.ApiCommand;
23-
import io.apiman.cli.core.declarative.command.ApplyCommand;
24-
import io.apiman.cli.core.gateway.command.GatewayCommand;
25-
import io.apiman.cli.core.org.command.OrgCommand;
26-
import io.apiman.cli.core.plugin.command.PluginCommand;
20+
import io.apiman.cli.command.api.command.ApiCommand;
21+
import io.apiman.cli.command.core.AbstractCommand;
22+
import io.apiman.cli.command.core.Command;
23+
import io.apiman.cli.command.declarative.command.ApplyCommand;
24+
import io.apiman.cli.command.gateway.command.GatewayCommand;
25+
import io.apiman.cli.command.org.command.OrgCommand;
26+
import io.apiman.cli.command.plugin.command.PluginCommand;
27+
import io.apiman.cli.service.ManagementApiService;
28+
import io.apiman.cli.util.InjectionUtil;
2729

30+
import javax.inject.Inject;
2831
import java.util.Map;
2932

3033
/**
@@ -33,8 +36,13 @@
3336
* @author Pete Cornish {@literal <outofcoffee@gmail.com>}
3437
*/
3538
public class Cli extends AbstractCommand {
39+
@Inject
40+
public Cli(ManagementApiService managementApiService) {
41+
super(managementApiService);
42+
}
43+
3644
public static void main(String... args) {
37-
new Cli().run(Lists.newArrayList(args));
45+
InjectionUtil.getInjector().getInstance(Cli.class).run(Lists.newArrayList(args));
3846
}
3947

4048
@Override

src/main/java/io/apiman/cli/core/api/ApiMixin.java renamed to src/main/java/io/apiman/cli/command/api/ApiMixin.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2016 Pete Cornish
2+
* Copyright 2017 Pete Cornish
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.apiman.cli.core.api;
17+
package io.apiman.cli.command.api;
1818

19-
import io.apiman.cli.core.common.command.ModelAction;
20-
import io.apiman.cli.core.api.model.Api;
19+
import io.apiman.cli.command.api.model.Api;
20+
import io.apiman.cli.command.common.command.ModelAction;
2121

2222
/**
2323
* @author Pete Cornish {@literal <outofcoffee@gmail.com>}

src/main/java/io/apiman/cli/core/api/Version11xServerApi.java renamed to src/main/java/io/apiman/cli/command/api/Version11xServerApi.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2016 Pete Cornish
2+
* Copyright 2017 Pete Cornish
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,12 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.apiman.cli.core.api;
17+
package io.apiman.cli.command.api;
1818

19-
import io.apiman.cli.core.api.model.Api;
20-
import io.apiman.cli.core.api.model.ApiPolicy;
21-
import io.apiman.cli.core.api.model.ApiVersion;
22-
import io.apiman.cli.core.api.model.ServiceConfig;
19+
import io.apiman.cli.command.api.model.Api;
20+
import io.apiman.cli.command.api.model.ApiPolicy;
21+
import io.apiman.cli.command.api.model.ApiVersion;
22+
import io.apiman.cli.command.api.model.ServiceConfig;
2323
import retrofit.client.Response;
2424
import retrofit.http.*;
2525

src/main/java/io/apiman/cli/core/api/Version12xServerApi.java renamed to src/main/java/io/apiman/cli/command/api/Version12xServerApi.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2016 Pete Cornish
2+
* Copyright 2017 Pete Cornish
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,12 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.apiman.cli.core.api;
17+
package io.apiman.cli.command.api;
1818

19-
import io.apiman.cli.core.api.model.Api;
20-
import io.apiman.cli.core.api.model.ApiConfig;
21-
import io.apiman.cli.core.api.model.ApiPolicy;
22-
import io.apiman.cli.core.api.model.ApiVersion;
19+
import io.apiman.cli.command.api.model.Api;
20+
import io.apiman.cli.command.api.model.ApiConfig;
21+
import io.apiman.cli.command.api.model.ApiPolicy;
22+
import io.apiman.cli.command.api.model.ApiVersion;
2323
import retrofit.client.Response;
2424
import retrofit.http.*;
2525

src/main/java/io/apiman/cli/core/api/VersionAgnosticApi.java renamed to src/main/java/io/apiman/cli/command/api/VersionAgnosticApi.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 Pete Cornish
2+
* Copyright 2017 Pete Cornish
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,12 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.apiman.cli.core.api;
17+
package io.apiman.cli.command.api;
1818

19-
import io.apiman.cli.core.api.model.Api;
20-
import io.apiman.cli.core.api.model.ApiConfig;
21-
import io.apiman.cli.core.api.model.ApiPolicy;
22-
import io.apiman.cli.core.api.model.ApiVersion;
19+
import io.apiman.cli.command.api.model.ApiPolicy;
20+
import io.apiman.cli.command.api.model.Api;
21+
import io.apiman.cli.command.api.model.ApiConfig;
22+
import io.apiman.cli.command.api.model.ApiVersion;
2323
import retrofit.client.Response;
2424

2525
import java.util.List;

src/main/java/io/apiman/cli/core/api/command/AbstractApiCommand.java renamed to src/main/java/io/apiman/cli/command/api/command/AbstractApiCommand.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2016 Pete Cornish
2+
* Copyright 2017 Pete Cornish
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,13 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.apiman.cli.core.api.command;
17+
package io.apiman.cli.command.api.command;
1818

19-
import io.apiman.cli.core.common.command.AbstractModelCommand;
20-
import io.apiman.cli.core.api.Version12xServerApi;
21-
import io.apiman.cli.core.api.ApiMixin;
22-
import io.apiman.cli.core.api.model.Api;
23-
import io.apiman.cli.core.common.model.ManagementApiVersion;
19+
import io.apiman.cli.command.common.command.AbstractModelCommand;
20+
import io.apiman.cli.command.api.Version12xServerApi;
21+
import io.apiman.cli.command.api.ApiMixin;
22+
import io.apiman.cli.command.api.model.Api;
23+
import io.apiman.cli.command.common.model.ManagementApiVersion;
24+
import io.apiman.cli.service.ManagementApiService;
2425
import org.kohsuke.args4j.Option;
2526

2627
/**
@@ -34,4 +35,8 @@ public abstract class AbstractApiCommand extends AbstractModelCommand<Api, Versi
3435

3536
@Option(name = "--serverVersion", aliases = {"-sv"}, usage = "Management API server version")
3637
protected ManagementApiVersion serverVersion = ManagementApiVersion.DEFAULT_VERSION;
38+
39+
AbstractApiCommand(ManagementApiService managementApiService) {
40+
super(managementApiService);
41+
}
3742
}

src/main/java/io/apiman/cli/core/api/command/ApiCommand.java renamed to src/main/java/io/apiman/cli/command/api/command/ApiCommand.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2016 Pete Cornish
2+
* Copyright 2017 Pete Cornish
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,11 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.apiman.cli.core.api.command;
17+
package io.apiman.cli.command.api.command;
1818

19-
import io.apiman.cli.command.AbstractCommand;
20-
import io.apiman.cli.command.Command;
19+
import io.apiman.cli.command.core.AbstractCommand;
20+
import io.apiman.cli.command.core.Command;
21+
import io.apiman.cli.service.ManagementApiService;
2122

23+
import javax.inject.Inject;
2224
import java.util.Map;
2325

2426
/**
@@ -27,6 +29,11 @@
2729
* @author Pete Cornish {@literal <outofcoffee@gmail.com>}
2830
*/
2931
public class ApiCommand extends AbstractCommand {
32+
@Inject
33+
public ApiCommand(ManagementApiService managementApiService) {
34+
super(managementApiService);
35+
}
36+
3037
@Override
3138
protected void populateCommands(Map<String, Class<? extends Command>> commandMap) {
3239
commandMap.put("create", ApiCreateCommand.class);

src/main/java/io/apiman/cli/core/api/command/ApiCreateCommand.java renamed to src/main/java/io/apiman/cli/command/api/command/ApiCreateCommand.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2016 Pete Cornish
2+
* Copyright 2017 Pete Cornish
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,21 +14,23 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.apiman.cli.core.api.command;
17+
package io.apiman.cli.command.api.command;
1818

1919
import com.google.common.collect.Lists;
20-
import io.apiman.cli.core.api.ApiMixin;
21-
import io.apiman.cli.core.api.model.Api;
22-
import io.apiman.cli.core.api.model.ApiConfig;
23-
import io.apiman.cli.core.api.model.ApiGateway;
24-
import io.apiman.cli.core.api.VersionAgnosticApi;
20+
import io.apiman.cli.command.api.ApiMixin;
21+
import io.apiman.cli.command.api.model.Api;
22+
import io.apiman.cli.command.api.model.ApiConfig;
23+
import io.apiman.cli.command.api.model.ApiGateway;
24+
import io.apiman.cli.command.api.VersionAgnosticApi;
2525
import io.apiman.cli.exception.CommandException;
2626
import io.apiman.cli.management.ManagementApiUtil;
27+
import io.apiman.cli.service.ManagementApiService;
2728
import org.apache.logging.log4j.LogManager;
2829
import org.apache.logging.log4j.Logger;
2930
import org.kohsuke.args4j.CmdLineParser;
3031
import org.kohsuke.args4j.Option;
3132

33+
import javax.inject.Inject;
3234
import java.text.MessageFormat;
3335

3436
/**
@@ -60,6 +62,11 @@ public class ApiCreateCommand extends AbstractApiCommand implements ApiMixin {
6062
@Option(name = "--gateway", aliases = {"-g"}, usage = "Gateway")
6163
private String gateway = "TheGateway";
6264

65+
@Inject
66+
public ApiCreateCommand(ManagementApiService managementApiService) {
67+
super(managementApiService);
68+
}
69+
6370
@Override
6471
protected String getCommandDescription() {
6572
return MessageFormat.format("Create {0}", getModelName());

src/main/java/io/apiman/cli/core/api/command/ApiListCommand.java renamed to src/main/java/io/apiman/cli/command/api/command/ApiListCommand.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2016 Pete Cornish
2+
* Copyright 2017 Pete Cornish
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,18 +14,20 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.apiman.cli.core.api.command;
17+
package io.apiman.cli.command.api.command;
1818

19-
import io.apiman.cli.core.api.ApiMixin;
20-
import io.apiman.cli.core.api.model.Api;
21-
import io.apiman.cli.core.api.VersionAgnosticApi;
19+
import io.apiman.cli.command.api.ApiMixin;
20+
import io.apiman.cli.command.api.VersionAgnosticApi;
21+
import io.apiman.cli.command.api.model.Api;
2222
import io.apiman.cli.exception.CommandException;
23+
import io.apiman.cli.service.ManagementApiService;
2324
import io.apiman.cli.util.LogUtil;
2425
import io.apiman.cli.util.MappingUtil;
2526
import org.apache.logging.log4j.LogManager;
2627
import org.apache.logging.log4j.Logger;
2728
import org.kohsuke.args4j.CmdLineParser;
2829

30+
import javax.inject.Inject;
2931
import java.text.MessageFormat;
3032
import java.util.List;
3133

@@ -37,6 +39,11 @@
3739
public class ApiListCommand extends AbstractApiCommand implements ApiMixin {
3840
private static final Logger LOGGER = LogManager.getLogger(ApiListCommand.class);
3941

42+
@Inject
43+
public ApiListCommand(ManagementApiService managementApiService) {
44+
super(managementApiService);
45+
}
46+
4047
@Override
4148
protected String getCommandDescription() {
4249
return MessageFormat.format("List {0}s", getModelName());

0 commit comments

Comments
 (0)