<commit_before>/**
 * Copyright (C) 2006-2018 Talend Inc. - www.talend.com
 *
 * 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 org.talend.runtime.documentation;

import static java.lang.String.format;
import static java.nio.file.FileVisitResult.CONTINUE;
import static java.util.Collections.emptyMap;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.stream.Collectors.joining;
import static javax.ws.rs.client.Entity.entity;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
import static javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE;
import static lombok.AccessLevel.PRIVATE;
import static org.apache.ziplock.JarLocation.jarLocation;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.stream.Stream;

import javax.ws.rs.ProcessingException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.text.StringSubstitutor;
import org.apache.meecrowave.Meecrowave;

import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@NoArgsConstructor(access = PRIVATE)
public class ApiMockUpdate {

    public static void main(final String[] args) throws Exception {
        if (Boolean.parseBoolean(System.getenv("APIMOCK_SKIP"))) {
            log.warn("Api mock update skipped");
            return;
        }
        if (args.length < 3 || args[1] == null) {
            log.warn("No credentials, skipping mock update");
            return;
        }
        doMain(args, new File(args[0]));
    }

    private static void doMain(final String[] args, final File output)
            throws IOException, ExecutionException, InterruptedException {
        System.setProperty("talend.component.manager.m2.repository", createM2WithComponents(output).getAbsolutePath());
        System.setProperty("talend.component.server.component.coordinates", "org.talend.demo:components:1.0.0");

        final FTPClient ftp = new FTPClient();
        ftp.setSoTimeout(60000);
        ftp.setDataTimeout(60000);
        ftp.setConnectTimeout(60000);
        ftp.setControlKeepAliveTimeout(60000);
        ftp.setControlKeepAliveReplyTimeout(60000);
        try {
            ftp.connect("files.000webhost.com");
            final int reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                return;
            }
            if (!ftp.login(args[1], args[2])) {
                ftp.disconnect();
                throw new IllegalArgumentException("Invalid credentials (" + args[1] + ")");
            }
            updateMocks(ftp);
            ftp.logout();
        } finally {
            if (ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch (IOException ioe) {
                    // do nothing
                }
            }
        }<commit_msg>avoid npe in ftp client<commit_after>/**
 * Copyright (C) 2006-2018 Talend Inc. - www.talend.com
 *
 * 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 org.talend.runtime.documentation;

import static java.lang.String.format;
import static java.nio.file.FileVisitResult.CONTINUE;
import static java.util.Collections.emptyMap;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.stream.Collectors.joining;
import static javax.ws.rs.client.Entity.entity;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
import static javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE;
import static lombok.AccessLevel.PRIVATE;
import static org.apache.ziplock.JarLocation.jarLocation;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.stream.Stream;

import javax.ws.rs.ProcessingException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.text.StringSubstitutor;
import org.apache.meecrowave.Meecrowave;

import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@NoArgsConstructor(access = PRIVATE)
public class ApiMockUpdate {

    public static void main(final String[] args) throws Exception {
        if (Boolean.parseBoolean(System.getenv("APIMOCK_SKIP"))) {
            log.warn("Api mock update skipped");
            return;
        }
        if (args.length < 3 || args[1] == null) {
            log.warn("No credentials, skipping mock update");
            return;
        }
        doMain(args, new File(args[0]));
    }

    private static void doMain(final String[] args, final File output)
            throws IOException, ExecutionException, InterruptedException {
        System.setProperty("talend.component.manager.m2.repository", createM2WithComponents(output).getAbsolutePath());
        System.setProperty("talend.component.server.component.coordinates", "org.talend.demo:components:1.0.0");

        final FTPClient ftp = new FTPClient();
        ftp.setConnectTimeout(60000);
        try {
            ftp.connect("files.000webhost.com");
            ftp.setSoTimeout(60000);
            ftp.setDataTimeout(60000);
            ftp.setControlKeepAliveTimeout(60000);
            ftp.setControlKeepAliveReplyTimeout(60000);
            final int reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                return;
            }
            if (!ftp.login(args[1], args[2])) {
                ftp.disconnect();
                throw new IllegalArgumentException("Invalid credentials (" + args[1] + ")");
            }
            updateMocks(ftp);
            ftp.logout();
        } finally {
            if (ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch (IOException ioe) {
                    // do nothing
                }
            }
        }
{'fraction_non_alphanumeric': 0.10444697833523375, 'fraction_numerical': 0.012314709236031927, 'mean_word_length': 3.2229176697159363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3875823', 'n_tokens_mistral': 2596, 'n_tokens_neox': 2461, 'n_words': 568}