@Test public void generateJavaInspectionWithCompressionTest() throws Exception { DataShape source1 = new DataShape.Builder() .type(MyShape.class.getTypeName()) .kind(DataShapeKinds.JAVA) .build(); DataShape source2 = new DataShape.Builder() .type(MyShape.class.getTypeName()) .kind(DataShapeKinds.JAVA) .putMetadata(DataShapeMetaData.SHOULD_COMPRESS, "true") .build(); DataShape enriched1 = GenerateConnectorInspectionsMojo.generateInspections(new URL[0], source1); DataShape enriched2 = GenerateConnectorInspectionsMojo.generateInspections(new URL[0], source2); assertThat(enriched1.getSpecification()).isNotEmpty(); assertThat(enriched2.getSpecification()).isNotEmpty(); byte[] data = Base64.getDecoder().decode(enriched2.getSpecification()); try (InputStream is = new GZIPInputStream(new ByteArrayInputStream(data))) { String expected = enriched1.getSpecification(); String decoded = IOUtils.toString(is, StandardCharsets.UTF_8); assertThat(decoded).isEqualTo(expected); } }
private List<ConnectorAction> generateInspections(Connector connector) throws IOException, DependencyResolutionRequiredException, ClassNotFoundException { final List<ConnectorAction> actions = new ArrayList<>(); for (ConnectorAction action : connector.getActions()) { Optional<DataShape> inputDataShape = action.getDescriptor().getInputDataShape(); Optional<DataShape> outputDataShape = action.getDescriptor().getOutputDataShape(); if (inputDataShape.isPresent()) { inputDataShape = Optional.of(generateInspections(connector, inputDataShape.get())); } if (outputDataShape.isPresent()) { outputDataShape = Optional.of(generateInspections(connector, outputDataShape.get())); } if (inputDataShape.isPresent() || outputDataShape.isPresent()) { ConnectorDescriptor descriptor = new ConnectorDescriptor.Builder() .createFrom(action.getDescriptor()) .inputDataShape(inputDataShape) .outputDataShape(outputDataShape) .build(); action = new ConnectorAction.Builder() .createFrom(action) .descriptor(descriptor) .build(); } actions.add(action); } return actions; }
GenerateConnectorInspectionsMojo extends AbstractMojo { private List<ConnectorAction> generateInspections(Connector connector) throws IOException, DependencyResolutionRequiredException, ClassNotFoundException { final List<ConnectorAction> actions = new ArrayList<>(); for (ConnectorAction action : connector.getActions()) { Optional<DataShape> inputDataShape = action.getDescriptor().getInputDataShape(); Optional<DataShape> outputDataShape = action.getDescriptor().getOutputDataShape(); if (inputDataShape.isPresent()) { inputDataShape = Optional.of(generateInspections(connector, inputDataShape.get())); } if (outputDataShape.isPresent()) { outputDataShape = Optional.of(generateInspections(connector, outputDataShape.get())); } if (inputDataShape.isPresent() || outputDataShape.isPresent()) { ConnectorDescriptor descriptor = new ConnectorDescriptor.Builder() .createFrom(action.getDescriptor()) .inputDataShape(inputDataShape) .outputDataShape(outputDataShape) .build(); action = new ConnectorAction.Builder() .createFrom(action) .descriptor(descriptor) .build(); } actions.add(action); } return actions; } }
GenerateConnectorInspectionsMojo extends AbstractMojo { private List<ConnectorAction> generateInspections(Connector connector) throws IOException, DependencyResolutionRequiredException, ClassNotFoundException { final List<ConnectorAction> actions = new ArrayList<>(); for (ConnectorAction action : connector.getActions()) { Optional<DataShape> inputDataShape = action.getDescriptor().getInputDataShape(); Optional<DataShape> outputDataShape = action.getDescriptor().getOutputDataShape(); if (inputDataShape.isPresent()) { inputDataShape = Optional.of(generateInspections(connector, inputDataShape.get())); } if (outputDataShape.isPresent()) { outputDataShape = Optional.of(generateInspections(connector, outputDataShape.get())); } if (inputDataShape.isPresent() || outputDataShape.isPresent()) { ConnectorDescriptor descriptor = new ConnectorDescriptor.Builder() .createFrom(action.getDescriptor()) .inputDataShape(inputDataShape) .outputDataShape(outputDataShape) .build(); action = new ConnectorAction.Builder() .createFrom(action) .descriptor(descriptor) .build(); } actions.add(action); } return actions; } GenerateConnectorInspectionsMojo(); }
GenerateConnectorInspectionsMojo extends AbstractMojo { private List<ConnectorAction> generateInspections(Connector connector) throws IOException, DependencyResolutionRequiredException, ClassNotFoundException { final List<ConnectorAction> actions = new ArrayList<>(); for (ConnectorAction action : connector.getActions()) { Optional<DataShape> inputDataShape = action.getDescriptor().getInputDataShape(); Optional<DataShape> outputDataShape = action.getDescriptor().getOutputDataShape(); if (inputDataShape.isPresent()) { inputDataShape = Optional.of(generateInspections(connector, inputDataShape.get())); } if (outputDataShape.isPresent()) { outputDataShape = Optional.of(generateInspections(connector, outputDataShape.get())); } if (inputDataShape.isPresent() || outputDataShape.isPresent()) { ConnectorDescriptor descriptor = new ConnectorDescriptor.Builder() .createFrom(action.getDescriptor()) .inputDataShape(inputDataShape) .outputDataShape(outputDataShape) .build(); action = new ConnectorAction.Builder() .createFrom(action) .descriptor(descriptor) .build(); } actions.add(action); } return actions; } GenerateConnectorInspectionsMojo(); @Override void execute(); JsonNode validateWithSchema(File jsonFile); static DataShape generateInspections(URL[] classpath, DataShape shape); static JavaClass inspect(URL[] classpath, DataShape shape); }
GenerateConnectorInspectionsMojo extends AbstractMojo { private List<ConnectorAction> generateInspections(Connector connector) throws IOException, DependencyResolutionRequiredException, ClassNotFoundException { final List<ConnectorAction> actions = new ArrayList<>(); for (ConnectorAction action : connector.getActions()) { Optional<DataShape> inputDataShape = action.getDescriptor().getInputDataShape(); Optional<DataShape> outputDataShape = action.getDescriptor().getOutputDataShape(); if (inputDataShape.isPresent()) { inputDataShape = Optional.of(generateInspections(connector, inputDataShape.get())); } if (outputDataShape.isPresent()) { outputDataShape = Optional.of(generateInspections(connector, outputDataShape.get())); } if (inputDataShape.isPresent() || outputDataShape.isPresent()) { ConnectorDescriptor descriptor = new ConnectorDescriptor.Builder() .createFrom(action.getDescriptor()) .inputDataShape(inputDataShape) .outputDataShape(outputDataShape) .build(); action = new ConnectorAction.Builder() .createFrom(action) .descriptor(descriptor) .build(); } actions.add(action); } return actions; } GenerateConnectorInspectionsMojo(); @Override void execute(); JsonNode validateWithSchema(File jsonFile); static DataShape generateInspections(URL[] classpath, DataShape shape); static JavaClass inspect(URL[] classpath, DataShape shape);  }