<commit_before>/*
 * FindBugs - Find bugs in Java programs
 * Copyright (C) 2003-2008 University of Maryland
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package edu.umd.cs.findbugs;

import java.awt.GraphicsEnvironment;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.math.BigInteger;
import java.net.URL;
import java.net.URLConnection;
import java.security.MessageDigest;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.WillClose;
import javax.annotation.WillNotClose;
import javax.xml.transform.TransformerException;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

import edu.umd.cs.findbugs.ba.AnalysisContext;
import edu.umd.cs.findbugs.ba.MissingClassException;
import edu.umd.cs.findbugs.charsets.UTF8;
import edu.umd.cs.findbugs.cloud.Cloud;
import edu.umd.cs.findbugs.cloud.CloudFactory;
import edu.umd.cs.findbugs.log.Profiler;
import edu.umd.cs.findbugs.model.ClassFeatureSet;
import edu.umd.cs.findbugs.util.Util;
import edu.umd.cs.findbugs.xml.Dom4JXMLOutput;
import edu.umd.cs.findbugs.xml.OutputStreamXMLOutput;
import edu.umd.cs.findbugs.xml.XMLAttributeList;
import edu.umd.cs.findbugs.xml.XMLOutput;
import edu.umd.cs.findbugs.xml.XMLOutputUtil;

/**
 * An implementation of {@link BugCollection} that keeps the BugInstances sorted
 * by class (using the native comparison ordering of BugInstance's compareTo()
 * method as a tie-breaker).
 *
 * @see BugInstance
 * @author <NAME>
 */
public class SortedBugCollection implements BugCollection {
    private static final Logger LOGGER = Logger.getLogger(SortedBugCollection.class.getName());

    long analysisTimestamp = System.currentTimeMillis();

    String analysisVersion = Version.RELEASE;

    private boolean withMessages = false;

    private boolean minimalXML = false;
    
    private boolean synced = false;

    private boolean applySuppressions = false;

    private @CheckForNull Cloud cloud;

    boolean shouldNotUsePlugin;

    long timeStartedLoading, timeFinishedLoading;

    String dataSource = "";

    private Map<String, String> xmlCloudDetails = Collections.emptyMap();

    /**
     * @return Returns the timeStartedLoading.
     */
    public long getTimeStartedLoading() {
        return timeStartedLoading;
    }

    /**
     * @return Returns the timeFinishedLoading.
     */
    public long getTimeFinishedLoading() {
        return timeFinishedLoading;
    }

    public String getDataSource() {
        return dataSource;
    }

    final Project project;

    public Project getProject() {
        return project;
    }
    
    public @CheckForNull Cloud getCloudLazily() {
        if (cloud != null && bugsPopulated) 
           cloud.bugsPopulated();
        return cloud;
    }
        

    public @Nonnull Cloud getCloud() {
        if (shouldNotUsePlugin) {
            return CloudFactory.getPlainCloud(this);
        }
        Cloud result = cloud;
        if (result == null) {
            IGuiCallback callback = getProject().getGuiCallback();
            result = cloud = CloudFactory.createCloudWithoutInitializing(this);
            callback.registerCloud(getProject(), this, result);
            try {
                CloudFactory.initializeCloud(this, result);
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, "Could not load cloud plugin "+ result.getCloudName(), e);
                callback.showMessageDialog("Unable to connect to " + result.getCloudName() + ": " + Util.getNetworkErrorMessage(e));
                if (CloudFactory.FAIL_ON_CLOUD_ERROR)
                    throw new IllegalStateException("Could not load FindBugs Cloud plugin - to avoid this message, " +
                            "set -D" + CloudFactory.FAIL_ON_CLOUD_ERROR_PROP + "=false", e);
                result = cloud = CloudFactory.getPlainCloud(this);
            }
            
        }
        if (bugsPopulated)
            result.bugsPopulated();
        return result;
    }

    public boolean isApplySuppressions() {
        return applySuppressions;
    }

    public void setApplySuppressions(boolean applySuppressions) {
        this.applySuppressions = applySuppressions;<commit_msg>register with the correct cloud<commit_after>/*
 * FindBugs - Find bugs in Java programs
 * Copyright (C) 2003-2008 University of Maryland
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package edu.umd.cs.findbugs;

import java.awt.GraphicsEnvironment;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.math.BigInteger;
import java.net.URL;
import java.net.URLConnection;
import java.security.MessageDigest;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.WillClose;
import javax.annotation.WillNotClose;
import javax.xml.transform.TransformerException;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

import edu.umd.cs.findbugs.ba.AnalysisContext;
import edu.umd.cs.findbugs.ba.MissingClassException;
import edu.umd.cs.findbugs.charsets.UTF8;
import edu.umd.cs.findbugs.cloud.Cloud;
import edu.umd.cs.findbugs.cloud.CloudFactory;
import edu.umd.cs.findbugs.log.Profiler;
import edu.umd.cs.findbugs.model.ClassFeatureSet;
import edu.umd.cs.findbugs.util.Util;
import edu.umd.cs.findbugs.xml.Dom4JXMLOutput;
import edu.umd.cs.findbugs.xml.OutputStreamXMLOutput;
import edu.umd.cs.findbugs.xml.XMLAttributeList;
import edu.umd.cs.findbugs.xml.XMLOutput;
import edu.umd.cs.findbugs.xml.XMLOutputUtil;

/**
 * An implementation of {@link BugCollection} that keeps the BugInstances sorted
 * by class (using the native comparison ordering of BugInstance's compareTo()
 * method as a tie-breaker).
 *
 * @see BugInstance
 * @author <NAME>
 */
public class SortedBugCollection implements BugCollection {
    private static final Logger LOGGER = Logger.getLogger(SortedBugCollection.class.getName());

    long analysisTimestamp = System.currentTimeMillis();

    String analysisVersion = Version.RELEASE;

    private boolean withMessages = false;

    private boolean minimalXML = false;
    
    private boolean synced = false;

    private boolean applySuppressions = false;

    private @CheckForNull Cloud cloud;

    boolean shouldNotUsePlugin;

    long timeStartedLoading, timeFinishedLoading;

    String dataSource = "";

    private Map<String, String> xmlCloudDetails = Collections.emptyMap();

    /**
     * @return Returns the timeStartedLoading.
     */
    public long getTimeStartedLoading() {
        return timeStartedLoading;
    }

    /**
     * @return Returns the timeFinishedLoading.
     */
    public long getTimeFinishedLoading() {
        return timeFinishedLoading;
    }

    public String getDataSource() {
        return dataSource;
    }

    final Project project;

    public Project getProject() {
        return project;
    }
    
    public @CheckForNull Cloud getCloudLazily() {
        if (cloud != null && bugsPopulated) 
           cloud.bugsPopulated();
        return cloud;
    }
        

    public @Nonnull Cloud getCloud() {
        if (shouldNotUsePlugin) {
            return CloudFactory.getPlainCloud(this);
        }
        Cloud result = cloud;
        if (result == null) {
            IGuiCallback callback = getProject().getGuiCallback();
            result = cloud = CloudFactory.createCloudWithoutInitializing(this);
             try {
                CloudFactory.initializeCloud(this, result);
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, "Could not load cloud plugin "+ result.getCloudName(), e);
                callback.showMessageDialog("Unable to connect to " + result.getCloudName() + ": " + Util.getNetworkErrorMessage(e));
                if (CloudFactory.FAIL_ON_CLOUD_ERROR)
                    throw new IllegalStateException("Could not load FindBugs Cloud plugin - to avoid this message, " +
                            "set -D" + CloudFactory.FAIL_ON_CLOUD_ERROR_PROP + "=false", e);
                result = cloud = CloudFactory.getPlainCloud(this);
            }
            callback.registerCloud(getProject(), this, result);
             
            
        }
        if (bugsPopulated)
            result.bugsPopulated();
        return result;
    }

    public boolean isApplySuppressions() {
        return applySuppressions;
    }

    public void setApplySuppressions(boolean applySuppressions) {
        this.applySuppressions = applySuppressions;
{'fraction_non_alphanumeric': 0.08977263193220908, 'fraction_numerical': 0.004866180048661801, 'mean_word_length': 3.414814814814815, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 24}, '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': '6613381', 'n_tokens_mistral': 3477, 'n_tokens_neox': 3333, 'n_words': 909}