<commit_before>/*******************************************************************************
 * Copyright (c) 2012-2015 Codenvy, S.A.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Codenvy, S.A. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.ide.extension.ant.client.wizard;

import org.eclipse.che.api.project.shared.dto.ImportProject;
import org.eclipse.che.ide.api.project.type.wizard.ProjectWizardMode;
import org.eclipse.che.ide.api.wizard.AbstractWizardPage;
import org.eclipse.che.ide.extension.ant.shared.AntAttributes;

import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.inject.Inject;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import static org.eclipse.che.ide.api.project.type.wizard.ProjectWizardMode.CREATE;
import static org.eclipse.che.ide.api.project.type.wizard.ProjectWizardRegistrar.WIZARD_MODE_KEY;

/**
 * Wizard page for Ant project.
 *
 * @author <NAME>
 * @author <NAME>
 */
public class AntPagePresenter extends AbstractWizardPage<ImportProject> implements AntPageView.ActionDelegate {

    private final AntPageView view;

    /** Create instance of {@link AntPagePresenter}. */
    @Inject
    public AntPagePresenter(AntPageView view) {
        super();
        this.view = view;
        view.setDelegate(this);
    }

    @Override
    public void init(ImportProject dataObject) {
        super.init(dataObject);

        final ProjectWizardMode wizardMode = ProjectWizardMode.parse(context.get(WIZARD_MODE_KEY));
        if (CREATE == wizardMode) {
            // set default values
            Map<String, List<String>> attributes = dataObject.getProject().getAttributes();
            attributes.put(AntAttributes.SOURCE_FOLDER, Arrays.asList(AntAttributes.DEF_SRC_PATH));
            attributes.put(AntAttributes.TEST_SOURCE_FOLDER, Arrays.asList(AntAttributes.DEF_TEST_SRC_PATH));
        }
    }

    /** {@inheritDoc} */
    @Override
    public boolean canSkip() {
        return true;
    }

    /** {@inheritDoc} */
    @Override
    public void go(AcceptsOneWidget container) {
        container.setWidget(view);
    }
}
<commit_msg>IDEX-2266. Estimate project at update.<commit_after>/*******************************************************************************
 * Copyright (c) 2012-2015 <NAME>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   <NAME>. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.ide.extension.ant.client.wizard;

import org.eclipse.che.api.project.gwt.client.ProjectServiceClient;
import org.eclipse.che.api.project.shared.dto.ImportProject;
import org.eclipse.che.ide.api.project.type.wizard.ProjectWizardMode;
import org.eclipse.che.ide.api.wizard.AbstractWizardPage;
import org.eclipse.che.ide.extension.ant.shared.AntAttributes;
import org.eclipse.che.ide.rest.AsyncRequestCallback;
import org.eclipse.che.ide.rest.StringMapListUnmarshaller;
import org.eclipse.che.ide.util.loging.Log;

import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.inject.Inject;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import static org.eclipse.che.ide.api.project.type.wizard.ProjectWizardMode.CREATE;
import static org.eclipse.che.ide.api.project.type.wizard.ProjectWizardMode.UPDATE;
import static org.eclipse.che.ide.api.project.type.wizard.ProjectWizardRegistrar.PROJECT_PATH_KEY;
import static org.eclipse.che.ide.api.project.type.wizard.ProjectWizardRegistrar.WIZARD_MODE_KEY;
import static org.eclipse.che.ide.extension.ant.shared.AntAttributes.ANT_ID;

/**
 * Wizard page for Ant project.
 *
 * @author <NAME>
 * @author <NAME>
 */
public class AntPagePresenter extends AbstractWizardPage<ImportProject> implements AntPageView.ActionDelegate {

    private final AntPageView          view;
    private final ProjectServiceClient projectServiceClient;

    /** Create instance of {@link AntPagePresenter}. */
    @Inject
    public AntPagePresenter(AntPageView view, ProjectServiceClient projectServiceClient) {
        super();
        this.view = view;
        view.setDelegate(this);
        this.projectServiceClient = projectServiceClient;
    }

    @Override
    public void init(ImportProject dataObject) {
        super.init(dataObject);

        final ProjectWizardMode wizardMode = ProjectWizardMode.parse(context.get(WIZARD_MODE_KEY));
        if (CREATE == wizardMode) {
            // set default values
            Map<String, List<String>> attributes = dataObject.getProject().getAttributes();
            attributes.put(AntAttributes.SOURCE_FOLDER, Arrays.asList(AntAttributes.DEF_SRC_PATH));
            attributes.put(AntAttributes.TEST_SOURCE_FOLDER, Arrays.asList(AntAttributes.DEF_TEST_SRC_PATH));
            return;
        }

        if (UPDATE == wizardMode) {
            projectServiceClient.estimateProject(context.get(PROJECT_PATH_KEY), ANT_ID, getEstimateProjectCallback());
        }
    }

    public AsyncRequestCallback<Map<String, List<String>>> getEstimateProjectCallback() {
        return new AsyncRequestCallback<Map<String, List<String>>>(new StringMapListUnmarshaller()) {
            @Override
            protected void onSuccess(Map<String, List<String>> result) {
                List<String> srcFolder = result.get(AntAttributes.SOURCE_FOLDER);
                srcFolder = srcFolder != null && !srcFolder.isEmpty() ? srcFolder : Arrays.asList(AntAttributes.DEF_SRC_PATH);
                setAttribute(AntAttributes.SOURCE_FOLDER, srcFolder);


                List<String> testSrcFolder = result.get(AntAttributes.TEST_SOURCE_FOLDER);
                testSrcFolder = testSrcFolder != null && !testSrcFolder.isEmpty() ? testSrcFolder : Arrays.asList(AntAttributes.DEF_TEST_SRC_PATH);
                setAttribute(AntAttributes.TEST_SOURCE_FOLDER, testSrcFolder);
            }

            @Override
            protected void onFailure(Throwable exception) {
                Log.error(getClass(), exception.getMessage());
            }
        };
    }


    /** {@inheritDoc} */
    @Override
    public boolean canSkip() {
        return true;
    }

    /** {@inheritDoc} */
    @Override
    public void go(AcceptsOneWidget container) {
        container.setWidget(view);
    }

    /** Sets single value of attribute of data-object. */
    private void setAttribute(String attrId, List<String> value) {
        Map<String, List<String>> attributes = dataObject.getProject().getAttributes();
        attributes.put(attrId, value);
    }
}

{'fraction_non_alphanumeric': 0.14687191074706962, 'fraction_numerical': 0.003954243750882644, 'mean_word_length': 3.6745874587458744, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '989465', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1951, 'n_words': 377}