Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating waiters to use jmespath from io.burt #87

Merged
merged 1 commit into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<groupId>software.amazon.awssdk</groupId>
<version>${awsjavasdk.version}</version>
</dependency>
<dependency>
<groupId>io.burt</groupId>
<artifactId>jmespath-jackson</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<artifactId>org.eclipse.jdt.core</artifactId>
<groupId>org.eclipse.jdt</groupId>
Expand All @@ -65,10 +70,6 @@
<artifactId>javapoet</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<artifactId>jmespath-java</artifactId>
<groupId>software.amazon.awssdk</groupId>
</dependency>
<dependency>
<artifactId>commons-lang3</artifactId>
<groupId>org.apache.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@

package software.amazon.awssdk.codegen;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -32,13 +26,9 @@
import software.amazon.awssdk.codegen.model.service.Acceptor;
import software.amazon.awssdk.codegen.model.service.WaiterDefinition;
import software.amazon.awssdk.codegen.model.service.Waiters;
import software.amazon.awssdk.jmespath.JmesPathExpression;
import software.amazon.awssdk.utils.IoUtils;

class AddWaiters {

private static final ObjectMapper MAPPER = new ObjectMapper();

private final Waiters waiters;
private final Map<String, OperationModel> operations;

Expand All @@ -50,7 +40,6 @@ class AddWaiters {
Map<String, WaiterDefinitionModel> constructWaiters() throws IOException {

Map<String, WaiterDefinitionModel> javaWaiterModels = new HashMap<>();
Map<String, JmesPathExpression> argumentToAstMap = new HashMap<>();

for (Map.Entry<String, WaiterDefinition> entry : waiters.getWaiters().entrySet()) {

Expand All @@ -70,7 +59,6 @@ Map<String, WaiterDefinitionModel> constructWaiters() throws IOException {
acceptorModel.setState(acceptor.getState());
acceptorModel.setExpected(acceptor.getExpected());
acceptorModel.setArgument(acceptor.getArgument());
acceptorModel.setAst(getAstFromArgument(acceptor.getArgument(), argumentToAstMap));

acceptors.add(acceptorModel);
}
Expand All @@ -80,52 +68,4 @@ Map<String, WaiterDefinitionModel> constructWaiters() throws IOException {

return javaWaiterModels;
}

private JmesPathExpression getAstFromArgument(String argument, Map<String, JmesPathExpression> argumentToAstMap)
throws IOException {
if (argument != null && !argumentToAstMap.containsKey(argument)) {

final Process p = executeToAstProcess(argument);

if (p.exitValue() != 0) {
throw new RuntimeException(IoUtils.toString(p.getErrorStream()));
}

JsonNode jsonNode = MAPPER.readTree(IoUtils.toString(p.getInputStream()));
JmesPathExpression ast = AstJsonToAstJava.fromAstJsonToAstJava(jsonNode);

argumentToAstMap.put(argument, ast);
IoUtils.closeQuietly(p.getInputStream(), null);

return ast;

} else if (argument != null) {
return argumentToAstMap.get(argument);
}
return null;
}

/**
* Execute the jp-to-ast.py command and wait for it to complete.
*
* @param argument JP expression to compile to AST.
* @return Process with access to output streams.
*/
private Process executeToAstProcess(String argument) throws IOException {
try {
Process p = new ProcessBuilder("python", extractAstTransformer(), argument).start();
p.waitFor();
return p;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}

private String extractAstTransformer() throws IOException {
Path tempFile = Files.createTempFile("jp-to-ast", ".py");
tempFile.toFile().deleteOnExit();
Files.copy(CodeGenerator.class.getClassLoader().getResourceAsStream("jp-to-ast.py"), tempFile, REPLACE_EXISTING);
return tempFile.toString();
}
}

This file was deleted.

Loading