<commit_before>/**
 *  Copyright (c) 2012, 2015 Sme.UP and others.
 *  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.smeup.sys.os.file.base.api;

import javax.inject.Inject;

import org.smeup.sys.il.data.QCharacter;
import org.smeup.sys.il.data.QDataStructWrapper;
import org.smeup.sys.il.data.QEnum;
import org.smeup.sys.il.data.annotation.DataDef;
import org.smeup.sys.il.data.annotation.Entry;
import org.smeup.sys.il.data.annotation.Program;
import org.smeup.sys.os.cmd.QCallableCommand;
import org.smeup.sys.os.cmd.QCommandManager;
import org.smeup.sys.os.core.OperatingSystemRuntimeException;
import org.smeup.sys.os.core.Scope;
import org.smeup.sys.os.core.jobs.QJob;
import org.smeup.sys.os.core.jobs.QJobLogManager;
import org.smeup.sys.os.core.resources.QResourceManager;
import org.smeup.sys.os.core.resources.QResourceReader;
import org.smeup.sys.os.file.QFile;
import org.smeup.sys.os.file.QFileMember;
import org.smeup.sys.os.file.QFileMemberManager;
import org.smeup.sys.os.file.QFileMemberRow;
import org.smeup.sys.os.file.QFileMembered;

@Program(name = "QASRUNMB")
public class FileMemberRunner {

	@Inject
	private QResourceManager resourceManager;
	@Inject
	private QCommandManager commandManager;
	@Inject
	private QJobLogManager jobLogManager;
	@Inject
	private QFileMemberManager fileMemberManager;
	@Inject
	private QJob job;

	public @Entry void main(@DataDef(qualified = true) SourceFile sourceFile, @DataDef(length = 10) QCharacter sourceMember) {

		QResourceReader<QFile> fileReader = null;

		switch (sourceFile.library.asEnum()) {
		case CURLIB:
			fileReader = resourceManager.getResourceReader(job, QFile.class, Scope.CURRENT_LIBRARY);
			break;
		case LIBL:
			fileReader = resourceManager.getResourceReader(job, QFile.class, Scope.LIBRARY_LIST);
			break;
		case OTHER:
			fileReader = resourceManager.getResourceReader(job, QFile.class, sourceFile.library.asData().trimR());
			break;
		}

		QFile qFile = fileReader.lookup(sourceFile.name.trimR());

		if (qFile == null)
			throw new OperatingSystemRuntimeException("File not found: " + sourceFile);

		if (!(qFile instanceof QFileMembered))
			throw new OperatingSystemRuntimeException("Invalid file: " + sourceFile);

		QFileMembered fileMembered = (QFileMembered) qFile;

		QFileMember fileMember = fileMemberManager.lookup(job.getContext(), sourceFile.library.asData().trimR(), fileMembered, sourceMember.trimR() + ".XMI");
		if (fileMember == null)
			throw new OperatingSystemRuntimeException("File membe not found: " + sourceFile + "/" + sourceMember);

		for (QFileMemberRow fileMemberRow : fileMember.getRows()) {
			String line = fileMemberRow.getContent();

			if (line.trim().isEmpty())
				continue;

			if (line.trim().startsWith("//"))
				continue;

			try {
				QCallableCommand command = commandManager.prepareCommand(job.getJobID(), line.trim(), null, true);
				commandManager.executeCommand(job.getJobID(), command);
			} catch (Exception e) {
				jobLogManager.error(job, e.getMessage());<commit_msg>RUNMBR - Pacth su ricerca membro<commit_after>/**
 *  Copyright (c) 2012, 2015 Sme.UP and others.
 *  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.smeup.sys.os.file.base.api;

import javax.inject.Inject;

import org.smeup.sys.il.data.QCharacter;
import org.smeup.sys.il.data.QDataStructWrapper;
import org.smeup.sys.il.data.QEnum;
import org.smeup.sys.il.data.annotation.DataDef;
import org.smeup.sys.il.data.annotation.Entry;
import org.smeup.sys.il.data.annotation.Program;
import org.smeup.sys.os.cmd.QCallableCommand;
import org.smeup.sys.os.cmd.QCommandManager;
import org.smeup.sys.os.core.OperatingSystemRuntimeException;
import org.smeup.sys.os.core.Scope;
import org.smeup.sys.os.core.jobs.QJob;
import org.smeup.sys.os.core.jobs.QJobLogManager;
import org.smeup.sys.os.core.resources.QResourceManager;
import org.smeup.sys.os.core.resources.QResourceReader;
import org.smeup.sys.os.file.QFile;
import org.smeup.sys.os.file.QFileMember;
import org.smeup.sys.os.file.QFileMemberManager;
import org.smeup.sys.os.file.QFileMemberRow;
import org.smeup.sys.os.file.QFileMembered;

@Program(name = "QASRUNMB")
public class FileMemberRunner {

	@Inject
	private QResourceManager resourceManager;
	@Inject
	private QCommandManager commandManager;
	@Inject
	private QJobLogManager jobLogManager;
	@Inject
	private QFileMemberManager fileMemberManager;
	@Inject
	private QJob job;

	public @Entry void main(@DataDef(qualified = true) SourceFile sourceFile, @DataDef(length = 10) QCharacter sourceMember) {

		QResourceReader<QFile> fileReader = null;

		switch (sourceFile.library.asEnum()) {
		case CURLIB:
			fileReader = resourceManager.getResourceReader(job, QFile.class, Scope.CURRENT_LIBRARY);
			break;
		case LIBL:
			fileReader = resourceManager.getResourceReader(job, QFile.class, Scope.LIBRARY_LIST);
			break;
		case OTHER:
			fileReader = resourceManager.getResourceReader(job, QFile.class, sourceFile.library.asData().trimR());
			break;
		}

		QFile qFile = fileReader.lookup(sourceFile.name.trimR());

		if (qFile == null)
			throw new OperatingSystemRuntimeException("File not found: " + sourceFile);

		if (!(qFile instanceof QFileMembered))
			throw new OperatingSystemRuntimeException("Invalid file: " + sourceFile);

		QFileMembered fileMembered = (QFileMembered) qFile;

		QFileMember fileMember = fileMemberManager.lookup(job.getContext(), sourceFile.library.asData().trimR(), fileMembered, sourceMember.trimR());
		if (fileMember == null)
			throw new OperatingSystemRuntimeException("File member not found: " + sourceFile + "/" + sourceMember);

		for (QFileMemberRow fileMemberRow : fileMember.getRows()) {
			String line = fileMemberRow.getContent();

			if (line.trim().isEmpty())
				continue;

			if (line.trim().startsWith("//"))
				continue;

			try {
				QCallableCommand command = commandManager.prepareCommand(job.getJobID(), line.trim(), null, true);
				commandManager.executeCommand(job.getJobID(), command);
			} catch (Exception e) {
				jobLogManager.error(job, e.getMessage());
{'fraction_non_alphanumeric': 0.11959981809913597, 'fraction_numerical': 0.00424435349401243, 'mean_word_length': 4.901610017889087, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2657521', 'n_tokens_mistral': 2317, 'n_tokens_neox': 2149, 'n_words': 438}