Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2016 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.syndesis.verifier;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;
import io.syndesis.model.connection.Connector;
import io.syndesis.project.converter.ProjectGenerator;
import org.springframework.util.FileSystemUtils;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
// Needs to be adapted to new API signature.
/*
* Sorry for messing this up to adapt to the new API which is used by the external verifier.
* Maybe its worth to have a look at the ExternalVerifier and whether we should not fully settle on
* this better decoupled, less resource hungry and more robust approach.
*/
//@Component
//@ConditionalOnProperty(value = "verifier.kind", havingValue = "forking")
@SuppressWarnings("PMD") // Perhaps we should just delete this class and put it out of it's missery
public class LocalProcessVerifier {
private final ProjectGenerator projectGenerator;
@SuppressFBWarnings("UWF_NULL_FIELD")
private String localMavenRepoLocation = null; // "/tmp/syndesis-local-mvn-repo";
public LocalProcessVerifier(ProjectGenerator projectGenerator) {
this.projectGenerator = projectGenerator;
}
// Return a list of verification results. Omit scope, use only a connector id for the verification
public Verifier.Result verify(Connector connector, Verifier.Scope scope, Map props) {
Properties configuredProperties = new Properties();
for (Map.Entry entry : props.entrySet()) {
configuredProperties.put(entry.getKey(), entry.getValue());
}
/*
// The connector must get the GAV from one of its associated Actions. There should be a 'default'
// or 'verifier' actions which is selected for doing the verification. The prefix should also come from
// the action, too.
if (!connector.getCamelConnectorGAV().isPresent() ||
!connector.getCamelConnectorPrefix().isPresent() ) {
return createResult(scope, Verifier.Result.Status.UNSUPPORTED, null);
}
*/
try {
// we could cache the connectorClasspath.
String connectorClasspath = getConnectorClasspath(connector);
// shell out to java to validate the properties.
Properties result = runValidator(connectorClasspath, scope, /* see commment above connector.getCamelConnectorPrefix().get() */ null, configuredProperties);
String value = result.getProperty("value");
if ("error".equals(value)) {
return createResult(scope, Verifier.Result.Status.ERROR, result);
}
if ( "unsupported".equals(value) ) {
return createResult(scope, Verifier.Result.Status.UNSUPPORTED, result);
}
if ( "ok".equals(value) ) {
return createResult(scope, Verifier.Result.Status.OK, result);
}
return createResult(scope, Verifier.Result.Status.ERROR, result);
} catch (IOException|InterruptedException e) {
return createResult(scope, Verifier.Result.Status.ERROR, null);
}
}
private ImmutableResult createResult(Verifier.Scope scope, Verifier.Result.Status status, Properties response) {
ImmutableResult.Builder builder = ImmutableResult.builder().scope(scope).status(status);
if( response != null ) {
LinkedHashMap errors = new LinkedHashMap<>();
for (Map.Entry