<commit_before>/*
 * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
 * 
 * #SNAPSHOT#
 */
package fr.jayasoft.ivy.report;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

import fr.jayasoft.ivy.Ivy;
import fr.jayasoft.ivy.IvyNode;
import fr.jayasoft.ivy.License;
import fr.jayasoft.ivy.ModuleDescriptor;
import fr.jayasoft.ivy.ModuleId;
import fr.jayasoft.ivy.ModuleRevisionId;
import fr.jayasoft.ivy.util.FileUtil;
import fr.jayasoft.ivy.util.Message;

/**
 * @author <NAME>
 *
 */
public class XmlReportOutputter implements ReportOutputter {

    public void output(ResolveReport report, File destDir) {
        String[] confs = report.getConfigurations();
        for (int i = 0; i < confs.length; i++) {
            output(report.getConfigurationReport(confs[i]), destDir);
        }
    }
    
    public void output(ConfigurationResolveReport report, File destDir) {
    	PrintWriter out = null;
    	try {
    	    destDir.mkdirs();
    		File reportFile = new File(destDir, getReportFileName(report));
			out = new PrintWriter(new FileOutputStream(reportFile));
    		ModuleRevisionId mrid = report.getModuleDescriptor().getModuleRevisionId();
            out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
            out.println("<?xml-stylesheet type=\"text/xsl\" href=\"ivy-report.xsl\"?>");
    		out.println("<ivy-report version=\"1.0\">");
    		out.println("\t<info");
    		out.println("\t\torganisation=\""+mrid.getOrganisation()+"\"");
    		out.println("\t\tmodule=\""+mrid.getName()+"\"");
    		out.println("\t\tconf=\""+report.getConfiguration()+"\"");
    		out.println("\t\tdate=\""+Ivy.DATE_FORMAT.format(report.getDate())+"\"/>");
    		
    		out.println("\t<dependencies>");
    		for (Iterator iter = report.getModuleIds().iterator(); iter.hasNext();) {
    			ModuleId mid = (ModuleId) iter.next();
				out.println("\t\t<module organisation=\""+mid.getOrganisation()+"\"" +
						" name=\""+mid.getName()+"\"" +
						" resolver=\""+report.getIvy().getResolverName(mid)+"\">");
				for (Iterator it2 = report.getNodes(mid).iterator(); it2.hasNext();) {
                    IvyNode dep = (IvyNode)it2.next();
                    ModuleDescriptor md = null;
                    if (dep.getModuleRevision() != null) {
                        md = dep.getModuleRevision().getDescriptor();
                    }
                    String details = "";
                    if  (dep.isLoaded()) {
                        details += " status=\""+dep.getDescriptor().getStatus()+"\"" +
                            " pubdate=\""+Ivy.DATE_FORMAT.format(new Date(dep.getPublication()))+"\"" +
                            " resolver=\""+dep.getModuleRevision().getResolver().getName()+"\"";
                    }
                    if (dep.isEvicted(report.getConfiguration())) {
                        IvyNode.EvictionData ed = dep.getEvictedData(report.getConfiguration());
                        if (ed.getConflictManager() != null) {
                            details += " evicted=\""+ed.getConflictManager()+"\"";
                        } else {
                            details += " evicted=\"transitive\"";
                        }
                    }
                    if (dep.hasProblem()) {
                        details += " error=\""+dep.getProblem().getMessage()+"\"";
                    }
                    if (md != null && md.getHomePage() != null) {
                        details += " homepage=\""+md.getHomePage()+"\"";
                    }
					out.println("\t\t\t<revision name=\""+dep.getResolvedId().getRevision()+"\"" +
							 details +
                             " downloaded=\""+dep.isDownloaded()+"\""+
                             " searched=\""+dep.isSearched()+"\""+
                             " default=\""+dep.getDescriptor().isDefault()+"\""+
							 " conf=\""+toString(dep.getConfigurations(report.getConfiguration()))+"\">");
                    if (md != null) {
                        License[] licenses = md.getLicenses();
                        for (int i = 0; i < licenses.length; i++) {
                            String lurl;
                            if (licenses[i].getUrl() != null) {
                                lurl = " url=\""+licenses[i].getUrl()+"\"";
                            } else {
                                lurl = "";
                            }
                            out.println("\t\t\t\t<license name=\""+licenses[i].getName()+"\""+lurl+"/>");
                        }
                    }
                    if (dep.isEvicted(report.getConfiguration())) {
                        IvyNode.EvictionData ed = dep.getEvictedData(report.getConfiguration());
                        Collection selected = ed.getSelected();
                        if (selected != null) {
                            for (Iterator it3 = selected.iterator(); it3.hasNext();) {<commit_msg>FIX NPE when a node has no descriptor<commit_after>/*
 * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
 * 
 * #SNAPSHOT#
 */
package fr.jayasoft.ivy.report;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

import fr.jayasoft.ivy.Ivy;
import fr.jayasoft.ivy.IvyNode;
import fr.jayasoft.ivy.License;
import fr.jayasoft.ivy.ModuleDescriptor;
import fr.jayasoft.ivy.ModuleId;
import fr.jayasoft.ivy.ModuleRevisionId;
import fr.jayasoft.ivy.util.FileUtil;
import fr.jayasoft.ivy.util.Message;

/**
 * @author <NAME>
 *
 */
public class XmlReportOutputter implements ReportOutputter {

    public void output(ResolveReport report, File destDir) {
        String[] confs = report.getConfigurations();
        for (int i = 0; i < confs.length; i++) {
            output(report.getConfigurationReport(confs[i]), destDir);
        }
    }
    
    public void output(ConfigurationResolveReport report, File destDir) {
    	PrintWriter out = null;
    	try {
    	    destDir.mkdirs();
    		File reportFile = new File(destDir, getReportFileName(report));
			out = new PrintWriter(new FileOutputStream(reportFile));
    		ModuleRevisionId mrid = report.getModuleDescriptor().getModuleRevisionId();
            out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
            out.println("<?xml-stylesheet type=\"text/xsl\" href=\"ivy-report.xsl\"?>");
    		out.println("<ivy-report version=\"1.0\">");
    		out.println("\t<info");
    		out.println("\t\torganisation=\""+mrid.getOrganisation()+"\"");
    		out.println("\t\tmodule=\""+mrid.getName()+"\"");
    		out.println("\t\tconf=\""+report.getConfiguration()+"\"");
    		out.println("\t\tdate=\""+Ivy.DATE_FORMAT.format(report.getDate())+"\"/>");
    		
    		out.println("\t<dependencies>");
    		for (Iterator iter = report.getModuleIds().iterator(); iter.hasNext();) {
    			ModuleId mid = (ModuleId) iter.next();
				out.println("\t\t<module organisation=\""+mid.getOrganisation()+"\"" +
						" name=\""+mid.getName()+"\"" +
						" resolver=\""+report.getIvy().getResolverName(mid)+"\">");
				for (Iterator it2 = report.getNodes(mid).iterator(); it2.hasNext();) {
                    IvyNode dep = (IvyNode)it2.next();
                    ModuleDescriptor md = null;
                    if (dep.getModuleRevision() != null) {
                        md = dep.getModuleRevision().getDescriptor();
                    }
                    String details = "";
                    if  (dep.isLoaded()) {
                        details += " status=\""+dep.getDescriptor().getStatus()+"\"" +
                            " pubdate=\""+Ivy.DATE_FORMAT.format(new Date(dep.getPublication()))+"\"" +
                            " resolver=\""+dep.getModuleRevision().getResolver().getName()+"\"";
                    }
                    if (dep.isEvicted(report.getConfiguration())) {
                        IvyNode.EvictionData ed = dep.getEvictedData(report.getConfiguration());
                        if (ed.getConflictManager() != null) {
                            details += " evicted=\""+ed.getConflictManager()+"\"";
                        } else {
                            details += " evicted=\"transitive\"";
                        }
                    }
                    if (dep.hasProblem()) {
                        details += " error=\""+dep.getProblem().getMessage()+"\"";
                    }
                    if (md != null && md.getHomePage() != null) {
                        details += " homepage=\""+md.getHomePage()+"\"";
                    }
					String defaultValue = dep.getDescriptor() != null ? " default=\""+dep.getDescriptor().isDefault()+"\"" : "";
                    out.println("\t\t\t<revision name=\""+dep.getResolvedId().getRevision()+"\"" +
							 details +
                             " downloaded=\""+dep.isDownloaded()+"\""+
                             " searched=\""+dep.isSearched()+"\""+
                             defaultValue+
							 " conf=\""+toString(dep.getConfigurations(report.getConfiguration()))+"\">");
                    if (md != null) {
                        License[] licenses = md.getLicenses();
                        for (int i = 0; i < licenses.length; i++) {
                            String lurl;
                            if (licenses[i].getUrl() != null) {
                                lurl = " url=\""+licenses[i].getUrl()+"\"";
                            } else {
                                lurl = "";
                            }
                            out.println("\t\t\t\t<license name=\""+licenses[i].getName()+"\""+lurl+"/>");
                        }
                    }
                    if (dep.isEvicted(report.getConfiguration())) {
                        IvyNode.EvictionData ed = dep.getEvictedData(report.getConfiguration());
                        Collection selected = ed.getSelected();
                        if (selected != null) {
                            for (Iterator it3 = selected.iterator(); it3.hasNext();) {
{'fraction_non_alphanumeric': 0.16474352758654126, 'fraction_numerical': 0.0031028798603704062, 'mean_word_length': 1.7629252611840343, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 2, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2764835', 'n_tokens_mistral': 3064, 'n_tokens_neox': 2864, 'n_words': 456}