<commit_before>package eu.scasefp7.eclipse.core.connect.uploader;

import java.io.File;
import java.util.ArrayList;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.QualifiedName;

import eu.scasefp7.eclipse.core.connect.Activator;

public class ProjectFileLoader {

	private static IContainer getProjectFolder(IProject project, String folderId) {
		String requirementsFolderLocation = null;
		try {
			requirementsFolderLocation = project.getPersistentProperty(new QualifiedName("", folderId));
		} catch (CoreException e) {
			Activator.log("Error retrieving project property (requirements folder location)", e);
		}
		IContainer container = project;
		if (requirementsFolderLocation != null) {
			if (project.findMember(new Path(requirementsFolderLocation)).exists())
				container = (IContainer) project.findMember(new Path(requirementsFolderLocation));
		}
		return container;
	}

	/**
	 * Finds the files of a container recursively.
	 * 
	 * @param container a workspace container (e.g. project or folder).
	 * @param files a list of files that is populated.
	 * @param extension the extension of the files that are to be retrieved.
	 */
	private static void processContainer(IContainer container, ArrayList<IFile> files, String extension) {
		try {
			IResource[] members = container.members();
			for (IResource member : members) {
				if (member instanceof IContainer) {
					processContainer((IContainer) member, files, extension);
				} else if (member instanceof IFile) {
					if (extension.equals("") || ((IFile) member).getName().endsWith("." + extension))
						files.add((IFile) member);
				}
			}
		} catch (CoreException e) {
			Activator.log("Error finding the files of a project", e);
		}
	}

	/**
	 * Returns the files of the given project.
	 * 
	 * @param project the project of which the files are returned.
	 * @param extension the extension of the returned files.
	 * @return a list of the files of the project with the given extension.
	 */
	protected static ArrayList<IFile> getFilesOfProject(IProject project, String extension) {
		ArrayList<IFile> files = new ArrayList<IFile>();
		IContainer container = null;
		if (extension.equals("rqs") || extension.equals("sbd"))
			container = getProjectFolder(project, "eu.scasefp7.eclipse.core.ui.rqsFolder");
		else if (extension.equals("scd") || extension.equals("sc") || extension.equals("cservice"))
			container = getProjectFolder(project, "eu.scasefp7.eclipse.core.ui.compFolder");
		else if (extension.equals("owl") || extension.equals("yaml"))
			container = getProjectFolder(project, "eu.scasefp7.eclipse.core.ui.modelsFolder");
		processContainer(container, files, extension);
		return files;
	}

	private static void processContainer(File container, ArrayList<File> files, String extension) {
		for (File member : container.listFiles()) {<commit_msg>Add support for reading uml and xmi files to assets registry connector<commit_after>package eu.scasefp7.eclipse.core.connect.uploader;

import java.io.File;
import java.util.ArrayList;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.QualifiedName;

import eu.scasefp7.eclipse.core.connect.Activator;

public class ProjectFileLoader {

	private static IContainer getProjectFolder(IProject project, String folderId) {
		String folderLocation = null;
		try {
			folderLocation = project.getPersistentProperty(new QualifiedName("", folderId));
		} catch (CoreException e) {
			Activator.log("Error retrieving project property (folder location)", e);
		}
		IContainer container = project;
		if (folderLocation != null) {
			if (project.findMember(new Path(folderLocation)).exists())
				container = (IContainer) project.findMember(new Path(folderLocation));
		}
		return container;
	}

	/**
	 * Finds the files of a container recursively.
	 * 
	 * @param container a workspace container (e.g. project or folder).
	 * @param files a list of files that is populated.
	 * @param extension the extension of the files that are to be retrieved.
	 */
	private static void processContainer(IContainer container, ArrayList<IFile> files, String extension) {
		try {
			IResource[] members = container.members();
			for (IResource member : members) {
				if (member instanceof IContainer) {
					processContainer((IContainer) member, files, extension);
				} else if (member instanceof IFile) {
					if (extension.equals("") || ((IFile) member).getName().endsWith("." + extension))
						files.add((IFile) member);
				}
			}
		} catch (CoreException e) {
			Activator.log("Error finding the files of a project", e);
		}
	}

	/**
	 * Returns the files of the given project.
	 * 
	 * @param project the project of which the files are returned.
	 * @param extension the extension of the returned files.
	 * @return a list of the files of the project with the given extension.
	 */
	protected static ArrayList<IFile> getFilesOfProject(IProject project, String extension) {
		ArrayList<IFile> files = new ArrayList<IFile>();
		IContainer container = null;
		if (extension.equals("rqs") || extension.equals("sbd") || extension.equals("uml"))
			container = getProjectFolder(project, "eu.scasefp7.eclipse.core.ui.rqsFolder");
		else if (extension.equals("scd") || extension.equals("sc") || extension.equals("cservice"))
			container = getProjectFolder(project, "eu.scasefp7.eclipse.core.ui.compFolder");
		else if (extension.equals("owl") || extension.equals("yaml"))
			container = getProjectFolder(project, "eu.scasefp7.eclipse.core.ui.modelsFolder");
		else if (extension.equals("xmi"))
			container = getProjectFolder(project, "eu.scasefp7.eclipse.core.ui.outputFolder");
		processContainer(container, files, extension);
		return files;
	}

	private static void processContainer(File container, ArrayList<File> files, String extension) {
		for (File member : container.listFiles()) {
{'fraction_non_alphanumeric': 0.11671171887422484, 'fraction_numerical': 0.0017490857051995548, 'mean_word_length': 4.728597449908925, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4829144', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1757, 'n_words': 501}