<commit_before>package com.redhat.ceylon.eclipse.core.classpath;

import static com.redhat.ceylon.eclipse.core.builder.CeylonBuilder.isModelTypeChecked;
import static org.eclipse.core.resources.IncrementalProjectBuilder.INCREMENTAL_BUILD;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

public class BuildProjectAfterClasspathChangeJob extends Job {
    protected final IProject project;
    private boolean buildReferencedProjects;
    private boolean buildReferencingProjects;
    private boolean forceRebuild;

    public BuildProjectAfterClasspathChangeJob(String name, IProject project, boolean buildReferencedProjects, boolean buildReferencingProjects, boolean forceRebuild) {
        super(name);
        this.project = project;
        this.buildReferencedProjects = buildReferencedProjects;
        this.buildReferencingProjects = buildReferencingProjects;
        this.forceRebuild = forceRebuild;
    }

    @Override
    protected IStatus run(IProgressMonitor monitor) {
        if (project.isOpen() && (forceRebuild || !isModelTypeChecked(project))) {
            try {
                List<IBuildConfiguration> configs = new ArrayList<IBuildConfiguration>();
                List<IProject> projectsToTouch = new ArrayList<IProject>();
                configs.add(project.getBuildConfig(IBuildConfiguration.DEFAULT_CONFIG_NAME));
                projectsToTouch.add(project);
                if (buildReferencingProjects) {
                    for (IProject p: project.getReferencingProjects()) {
                        if (p.isOpen()) {
                            configs.add(p.getBuildConfig(IBuildConfiguration.DEFAULT_CONFIG_NAME));
                            projectsToTouch.add(project);
                        }
                    }
                }
                if (buildReferencedProjects) {
                    for (IProject p: project.getReferencedProjects()) {
                        if (p.isOpen()) {
                            projectsToTouch.add(project);
                        }
                    }
                }
                for (IProject p : projectsToTouch) {
                    p.touch(monitor);
                }
                project.getWorkspace().build(configs.toArray(new IBuildConfiguration[1]), 
                        INCREMENTAL_BUILD, buildReferencedProjects, monitor);                                
            }
            catch (CoreException e) {
                e.printStackTrace();
            }
        }
        else {
            // System.out.println("Don't build the project " + project + " since it's already typechecked");
        }
        return Status.OK_STATUS;
    }

    
    
    @Override
    public boolean belongsTo(Object family) {
        if (family instanceof BuildProjectAfterClasspathChangeJob) {
            BuildProjectAfterClasspathChangeJob otherJob = (BuildProjectAfterClasspathChangeJob) family;
            return project.equals(otherJob.project) <commit_msg>Trigger an AUTO_BUILD at start or project opening if Autobuild is on<commit_after>package com.redhat.ceylon.eclipse.core.classpath;

import static com.redhat.ceylon.eclipse.core.builder.CeylonBuilder.isModelTypeChecked;
import static org.eclipse.core.resources.IncrementalProjectBuilder.AUTO_BUILD;
import static org.eclipse.core.resources.IncrementalProjectBuilder.INCREMENTAL_BUILD;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

public class BuildProjectAfterClasspathChangeJob extends Job {
    protected final IProject project;
    private boolean buildReferencedProjects;
    private boolean buildReferencingProjects;
    private boolean forceRebuild;

    public BuildProjectAfterClasspathChangeJob(String name, IProject project, boolean buildReferencedProjects, boolean buildReferencingProjects, boolean forceRebuild) {
        super(name);
        this.project = project;
        this.buildReferencedProjects = buildReferencedProjects;
        this.buildReferencingProjects = buildReferencingProjects;
        this.forceRebuild = forceRebuild;
    }

    @Override
    protected IStatus run(IProgressMonitor monitor) {
        if (project.isOpen() && (forceRebuild || !isModelTypeChecked(project))) {
            try {
                List<IBuildConfiguration> configs = new ArrayList<IBuildConfiguration>();
                List<IProject> projectsToTouch = new ArrayList<IProject>();
                configs.add(project.getBuildConfig(IBuildConfiguration.DEFAULT_CONFIG_NAME));
                projectsToTouch.add(project);
                if (buildReferencingProjects) {
                    for (IProject p: project.getReferencingProjects()) {
                        if (p.isOpen()) {
                            configs.add(p.getBuildConfig(IBuildConfiguration.DEFAULT_CONFIG_NAME));
                            projectsToTouch.add(project);
                        }
                    }
                }
                if (buildReferencedProjects) {
                    for (IProject p: project.getReferencedProjects()) {
                        if (p.isOpen()) {
                            projectsToTouch.add(project);
                        }
                    }
                }
                for (IProject p : projectsToTouch) {
                    p.touch(monitor);
                }
                int kind = project.getWorkspace().isAutoBuilding() ? AUTO_BUILD : INCREMENTAL_BUILD;
                project.getWorkspace().build(configs.toArray(new IBuildConfiguration[1]), 
                        kind, buildReferencedProjects, monitor);                                
            }
            catch (CoreException e) {
                e.printStackTrace();
            }
        }
        else {
            // System.out.println("Don't build the project " + project + " since it's already typechecked");
        }
        return Status.OK_STATUS;
    }

    
    
    @Override
    public boolean belongsTo(Object family) {
        if (family instanceof BuildProjectAfterClasspathChangeJob) {
            BuildProjectAfterClasspathChangeJob otherJob = (BuildProjectAfterClasspathChangeJob) family;
            return project.equals(otherJob.project) 
{'fraction_non_alphanumeric': 0.07995296884185774, 'fraction_numerical': 0.00029394473838918284, 'mean_word_length': 2.231244064577398, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '24147', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1643, 'n_words': 307}