summaryrefslogtreecommitdiff
path: root/support/arara/source/src/main/java/com/github/cereda/arara/utils
diff options
context:
space:
mode:
Diffstat (limited to 'support/arara/source/src/main/java/com/github/cereda/arara/utils')
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/ClassLoadingUtils.java166
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/CommonUtils.java954
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/ConfigurationUtils.java239
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/DatabaseUtils.java140
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/DirectiveAssembler.java106
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/DirectiveResolver.java59
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/DirectiveUtils.java438
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/DisplayUtils.java502
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/FileHandlingUtils.java124
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/FileSearchingUtils.java117
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/InterpreterUtils.java257
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/MessageUtils.java313
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/Methods.java1368
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/RuleUtils.java244
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/TeeOutputStream.java109
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/UnsafeUtils.java87
-rw-r--r--support/arara/source/src/main/java/com/github/cereda/arara/utils/VelocityUtils.java157
17 files changed, 0 insertions, 5380 deletions
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/ClassLoadingUtils.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/ClassLoadingUtils.java
deleted file mode 100644
index fdd642e21d..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/ClassLoadingUtils.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import com.github.cereda.arara.model.Pair;
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-
-/**
- * Implements utilitary methods for classloading and object instantiation.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class ClassLoadingUtils {
-
- /**
- * Loads a class from the provided file, potentially a Java archive.
- * @param file File containing the Java bytecode (namely, a JAR).
- * @param name The canonical name of the class.
- * @return A pair representing the status and the class.
- */
- public static Pair<Integer, Class> loadClass(File file, String name) {
-
- // status and class to be returned,
- // it defaults to an object class
- int status = 0;
- Class value = Object.class;
-
- // if file does not exist, nothing
- // can be done, status is changed
- if (!file.exists()) {
- status = 1;
- } else {
-
- // classloading involves defining
- // a classloader and fetching the
- // desired class from it, based on
- // the provided file archive
- try {
-
- // creates a new classloader with
- // the provided file (potentially
- // a JAR file)
- URLClassLoader classloader = new URLClassLoader(
- new URL[]{
- file.toURI().toURL()
- },
- ClassLoadingUtils.class.getClassLoader()
- );
-
- // fetches the class from the
- // instantiated classloader
- value = Class.forName(name, true, classloader);
-
- } catch (MalformedURLException nothandled1) {
-
- // the file URL is incorrect,
- // update status accordingly
- status = 2;
-
- } catch (ClassNotFoundException nothandled2) {
-
- // the class was not found,
- // update status accordingly
- status = 3;
-
- }
- }
-
- // return a new pair based on the
- // current status and class holder
- return new Pair<Integer, Class>(status, value);
- }
-
- /**
- * Loads a class from the provided file, instantiating it.
- * @param file File containing the Java bytecode (namely, a JAR).
- * @param name The canonical name of the class.
- * @return A pair representing the status and the class object.
- */
- public static Pair<Integer, Object> loadObject(File file, String name) {
-
- // load the corresponding class
- // based on the qualified name
- Pair<Integer, Class> pair = loadClass(file, name);
-
- // status and object to be returned,
- // it defaults to an object
- int status = pair.getFirstElement();
- Object value = new Object();
-
- // checks if the class actually
- // exists, otherwise simply
- // ignore instantiation
- if (status == 0) {
-
- // object instantiation relies
- // on the default constructor
- // (without arguments), class
- // must implement it
-
- // OBS: constructors with arguments
- // must be invoked through reflection
- try {
-
- // get the class reference from
- // the pair and instantiate it
- // by invoking the default
- // constructor (without arguments)
- value = pair.getSecondElement().newInstance();
-
- } catch (IllegalAccessException nothandled1) {
-
- // the object instantiation violated
- // an access policy, status is updated
- status = 4;
-
- } catch (InstantiationException nothandled2) {
-
- // an instantiation exception has
- // occurred, status is updated
- status = 5;
-
- }
- }
-
- // return a new pair based on the
- // current status and object holder
- return new Pair<Integer, Object>(status, value);
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/CommonUtils.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/CommonUtils.java
deleted file mode 100644
index 0263f64eac..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/CommonUtils.java
+++ /dev/null
@@ -1,954 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import com.github.cereda.arara.controller.ConfigurationController;
-import com.github.cereda.arara.controller.LanguageController;
-import com.github.cereda.arara.controller.SystemCallController;
-import com.github.cereda.arara.model.AraraException;
-import com.github.cereda.arara.model.Argument;
-import com.github.cereda.arara.model.Database;
-import com.github.cereda.arara.model.FileType;
-import com.github.cereda.arara.model.Messages;
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.MissingFormatArgumentException;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.Transformer;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.NameFileFilter;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.SystemUtils;
-
-/**
- * Implements common utilitary methods.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class CommonUtils {
-
- // the application messages obtained from the
- // language controller
- private static final LanguageController messages =
- LanguageController.getInstance();
-
- /**
- * Checks if the input string is equal to a valid boolean value.
- * @param value The input string.
- * @return A boolean value represented by the provided string.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean checkBoolean(String value) throws AraraException {
- List<String> yes = Arrays.asList(
- new String[]{"yes", "true", "1", "on"}
- );
- List<String> no = Arrays.asList(
- new String[]{"no", "false", "0", "off"}
- );
- if (!union(yes, no).contains(value.toLowerCase())) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_CHECKBOOLEAN_NOT_VALID_BOOLEAN,
- value
- )
- );
- } else {
- return yes.contains(value.toLowerCase());
- }
- }
-
- /**
- * Provides a union set operation between two lists.
- * @param <T> The list type.
- * @param list1 The first list.
- * @param list2 The second list.
- * @return The union of those two lists.
- */
- private static <T> List<T> union(List<T> list1, List<T> list2) {
- Set<T> elements = new HashSet<T>();
- elements.addAll(list1);
- elements.addAll(list2);
- return new ArrayList<T>(elements);
- }
-
- /**
- * Build a system-dependant path based on the path and the file.
- * @param path A string representing the path to be prepended.
- * @param file A string representing the file to be appended.
- * @return The full path as a string.
- */
- public static String buildPath(String path, String file) {
- return path.endsWith(File.separator) ?
- path.concat(file) : path.concat(File.separator).concat(file);
- }
-
- /**
- * Checks if the provided string is empty. It does not handle a null value.
- * @param string A string.
- * @return A boolean value indicating if the string is empty.
- */
- public static boolean checkEmptyString(String string) {
- return "".equals(string);
- }
-
- /**
- * Removes the keyword from the beginning of the provided string.
- * @param line A string to be analyzed.
- * @return The provided string without the keyword.
- */
- public static String removeKeyword(String line) {
- if (line != null) {
- Pattern pattern = Pattern.compile("^(\\s)*<arara>\\s");
- Matcher matcher = pattern.matcher(line);
- if (matcher.find()) {
- line = (line.substring(matcher.end(), line.length()));
- }
- line = line.trim();
- }
- return line;
- }
-
- /**
- * Discovers the file through string reference lookup and sets the
- * configuration accordingly.
- * @param reference The string reference.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static void discoverFile(String reference) throws AraraException {
- File file = lookupFile(reference);
- if (file == null) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_DISCOVERFILE_FILE_NOT_FOUND,
- reference,
- getFileTypesList()
- )
- );
- }
- }
-
- /**
- * Performs a file lookup based on a string reference.
- * @param reference The file reference as a string.
- * @return The file as result of the lookup operation.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- private static File lookupFile(String reference) throws AraraException {
- @SuppressWarnings("unchecked")
- List<FileType> types = (List<FileType>) ConfigurationController.
- getInstance().get("execution.filetypes");
- File file = new File(reference);
- String name = file.getName();
- String parent = getParentCanonicalPath(file);
- String path = buildPath(parent, name);
-
- // direct search, so we are considering
- // the reference as a complete name
- for (FileType type : types) {
- if (path.endsWith(".".concat(type.getExtension()))) {
- file = new File(path);
- if (file.exists()) {
- if (file.isFile()) {
- ConfigurationController.
- getInstance().
- put("execution.file.pattern",
- type.getPattern());
- ConfigurationController.
- getInstance().
- put("execution.reference", file);
- return file;
- }
- }
- }
- }
-
- // indirect search; in this case, we are considering
- // that the file reference has an implict extension,
- // so we need to add it and look again
- for (FileType type : types) {
- path = buildPath(parent, name.concat(".").
- concat(type.getExtension()));
- file = new File(path);
- if (file.exists()) {
- if (file.isFile()) {
- ConfigurationController.getInstance().
- put("execution.file.pattern", type.getPattern());
- ConfigurationController.getInstance().
- put("execution.reference", file);
- return file;
- }
- }
- }
- return null;
- }
-
- /**
- * Gets the parent canonical path of a file.
- * @param file The file.
- * @return The parent canonical path of a file.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static String getParentCanonicalPath(File file)
- throws AraraException {
- try {
- String path = file.getCanonicalFile().getParent();
- return path;
- } catch (IOException exception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_GETPARENTCANONICALPATH_IO_EXCEPTION
- ),
- exception
- );
- }
- }
-
- /**
- * Gets the canonical file from a file.
- * @param file The file.
- * @return The canonical file.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static File getCanonicalFile(String file) throws AraraException {
- try {
- return (new File(file)).getCanonicalFile();
- } catch (IOException exception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_GETCANONICALFILE_IO_EXCEPTION
- ),
- exception
- );
- }
- }
-
- /**
- * Checks if the provided object is from a certain class.
- * @param clazz The class.
- * @param object The object.
- * @return A boolean value indicating if the provided object is from a
- * certain class.
- */
- public static boolean checkClass(Class clazz, Object object) {
- return clazz.isInstance(object);
- }
-
- /**
- * Helper method to flatten a potential list of lists into a list of
- * objects.
- * @param list First list.
- * @param flat Second list.
- */
- private static void flatten(List<?> list, List<Object> flat) {
- for (Object item : list) {
- if (item instanceof List<?>) {
- flatten((List<?>) item, flat);
- } else {
- flat.add(item);
- }
- }
- }
-
- /**
- * Flattens a potential list of lists into a list of objects.
- * @param list The list to be flattened.
- * @return The flattened list.
- */
- public static List<Object> flatten(List<?> list) {
- List<Object> result = new ArrayList<Object>();
- flatten(list, result);
- return result;
- }
-
- /**
- * Gets the list of file types, in order.
- * @return A string representation of the list of file types, in order.
- */
- public static String getFileTypesList() {
- @SuppressWarnings("unchecked")
- List<FileType> types = (List<FileType>) ConfigurationController.
- getInstance().get("execution.filetypes");
- return getCollectionElements(types, "[ ", " ]", " | ");
- }
-
- /**
- * Gets a string representation of a collection.
- * @param collection The collection.
- * @param open The opening string.
- * @param close The closing string.
- * @param separator The element separator.
- * @return A string representation of the provided collection.
- */
- public static String getCollectionElements(Collection collection,
- String open, String close, String separator) {
- StringBuilder builder = new StringBuilder();
- builder.append(open);
- builder.append(StringUtils.join(collection, separator));
- builder.append(close);
- return builder.toString();
- }
-
- /**
- * Gets a set of strings containing unknown keys from a map and a list. It
- * is a set difference from the keys in the map and the entries in the list.
- * @param parameters The map of parameters.
- * @param arguments The list of arguments.
- * @return A set of strings representing unknown keys from a map and a list.
- */
- public static Set<String> getUnknownKeys(Map<String, Object> parameters,
- List<Argument> arguments) {
- Collection<String> found = parameters.keySet();
- Collection<String> expected = CollectionUtils.collect(
- arguments, new Transformer<Argument, String>() {
- public String transform(Argument argument) {
- return argument.getIdentifier();
- }
- });
- Collection<String> difference = CollectionUtils.
- subtract(found, expected);
- return new HashSet<String>(difference);
- }
-
- /**
- * Gets the rule error header, containing the identifier and the path, if
- * any.
- * @return A string representation of the rule error header, containing the
- * identifier and the path, if any.
- */
- public static String getRuleErrorHeader() {
- if ((ConfigurationController.getInstance().
- contains("execution.info.rule.id")) &&
- (ConfigurationController.getInstance().
- contains("execution.info.rule.path"))) {
- String id = (String) ConfigurationController.getInstance().
- get("execution.info.rule.id");
- String path = (String) ConfigurationController.getInstance().
- get("execution.info.rule.path");
- return messages.getMessage(
- Messages.ERROR_RULE_IDENTIFIER_AND_PATH,
- id,
- path
- ).concat(" ");
- } else {
- return "";
- }
- }
-
- /**
- * Trims spaces from every string of a list of strings.
- * @param input The list of strings.
- * @return A new list of strings, with each element trimmed.
- */
- public static List<String> trimSpaces(List<String> input) {
- Collection<String> result = CollectionUtils.collect(
- input, new Transformer<String, String>() {
- public String transform(String input) {
- return input.trim();
- }
- });
- return new ArrayList<String>(result);
- }
-
- /**
- * Gets a human readable representation of a file size.
- * @param file The file.
- * @return A string representation of the file size.
- */
- public static String calculateFileSize(File file) {
- return FileUtils.byteCountToDisplaySize(file.length());
- }
-
- /**
- * Gets the date the provided file was last modified.
- * @param file The file.
- * @return A string representation of the date the provided file was last
- * modified.
- */
- public static String getLastModifiedInformation(File file) {
- SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
- return format.format(file.lastModified());
- }
-
- /**
- * Gets a list of all rule paths.
- * @return A list of all rule paths.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static List<String> getAllRulePaths() throws AraraException {
- @SuppressWarnings("unchecked")
- List<String> paths = (List<String>) ConfigurationController.
- getInstance().get("execution.rule.paths");
- List<String> result = new ArrayList<String>();
- for (String path : paths) {
- File location = new File(InterpreterUtils.construct(path, "quack"));
- result.add(getParentCanonicalPath(location));
- }
- return result;
- }
-
- /**
- * Gets the reference of the current file in execution. Note that this
- * method might return a value different than the main file provided in
- * the command line.
- * @return A reference of the current file in execution. Might be different
- * than the main file provided in the command line.
- */
- private static File getCurrentReference() {
- return (File) ConfigurationController.getInstance().
- get("execution.file");
- }
-
- /**
- * Calculates the CRC32 checksum of the provided file.
- * @param file The file.
- * @return A string containing the CRC32 checksum of the provided file.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static String calculateHash(File file) throws AraraException {
- try {
- long result = FileUtils.checksumCRC32(file);
- return String.format("%08x", result);
- } catch (IOException exception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_CALCULATEHASH_IO_EXCEPTION
- ),
- exception
- );
- }
- }
-
- /**
- * Gets the file type of a file.
- * @param file The file.
- * @return The corresponding file type.
- */
- public static String getFiletype(File file) {
- return getFiletype(file.getName());
- }
-
- /**
- * Gets the file type of a string representing the file.
- * @param name A string representing the file.
- * @return The corresponding file type.
- */
- public static String getFiletype(String name) {
- name = name.lastIndexOf(".") != -1 ?
- name.substring(name.lastIndexOf(".") + 1, name.length()) : "";
- return name;
- }
-
- /**
- * Gets the base name of a file.
- * @param file The file.
- * @return The corresponding base name.
- */
- public static String getBasename(File file) {
- return getBasename(file.getName());
- }
-
- /**
- * Gets the base name of a string representing the file.
- * @param name A string representing the file.
- * @return The corresponding base name.
- */
- public static String getBasename(String name) {
- int index = name.lastIndexOf(".") != -1 ?
- name.lastIndexOf(".") : name.length();
- return name.substring(0, index);
- }
-
- /**
- * Encloses the provided object in double quotes.
- * @param object The object.
- * @return A string representation of the provided object enclosed in double
- * quotes.
- */
- public static String addQuotes(Object object) {
- return "\"".concat(String.valueOf(object)).concat("\"");
- }
-
- /**
- * Generates a string based on a list of objects, separating each one of
- * them by one space.
- * @param objects A list of objects.
- * @return A string based on the list of objects, separating each one of
- * them by one space. Empty values are not considered.
- */
- public static String generateString(Object... objects) {
- List<String> values = new ArrayList<String>();
- for (Object object : objects) {
- if (!CommonUtils.checkEmptyString(String.valueOf(object))) {
- values.add(String.valueOf(object));
- }
- }
- return StringUtils.join(values, " ");
- }
-
- /**
- * Checks if a file exists.
- * @param file The file.
- * @return A boolean value indicating if the file exists.
- */
- public static boolean exists(File file) {
- return file.exists();
- }
-
- /**
- * Checks if a file exists based on its extension.
- * @param extension The extension.
- * @return A boolean value indicating if the file exists.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean exists(String extension) throws AraraException {
- File file = new File(getPath(extension));
- return file.exists();
- }
-
- /**
- * Checks if a file has changed since the last verification.
- * @param file The file.
- * @return A boolean value indicating if the file has changed since the last
- * verification.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean hasChanged(File file) throws AraraException {
- Database database = DatabaseUtils.load();
- HashMap<String, String> map = database.getMap();
- String path = getCanonicalPath(file);
- if (!file.exists()) {
- if (map.containsKey(path)) {
- map.remove(path);
- database.setMap(map);
- DatabaseUtils.save(database);
- return true;
- } else {
- return false;
- }
- } else {
- String hash = calculateHash(file);
- if (map.containsKey(path)) {
- String value = map.get(path);
- if (hash.equals(value)) {
- return false;
- } else {
- map.put(path, hash);
- database.setMap(map);
- DatabaseUtils.save(database);
- return true;
- }
- } else {
- map.put(path, hash);
- database.setMap(map);
- DatabaseUtils.save(database);
- return true;
- }
- }
- }
-
- /**
- * Checks if the file has changed since the last verification based on the
- * provided extension.
- * @param extension The provided extension.
- * @return A boolean value indicating if the file has changed since the last
- * verification.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean hasChanged(String extension) throws AraraException {
- File file = new File(getPath(extension));
- return hasChanged(file);
- }
-
- /**
- * Gets the full file path based on the provided extension.
- * @param extension The extension.
- * @return A string containing the full file path.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- private static String getPath(String extension) throws AraraException {
- String name = getBasename(getCurrentReference());
- String path = getParentCanonicalPath(getCurrentReference());
- name = name.concat(".").concat(extension);
- return buildPath(path, name);
- }
-
- /**
- * Gets the canonical path from the provided file.
- * @param file The file.
- * @return The canonical path from the provided file.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static String getCanonicalPath(File file) throws AraraException {
- try {
- return file.getCanonicalPath();
- } catch (IOException exception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_GETCANONICALPATH_IO_EXCEPTION
- ),
- exception
- );
- }
- }
-
- /**
- * Checks if the file based on the provided extension contains the provided
- * regex.
- * @param extension The file extension.
- * @param regex The regex.
- * @return A boolean value indicating if the file contains the provided
- * regex.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean checkRegex(String extension, String regex)
- throws AraraException {
- File file = new File(getPath(extension));
- return checkRegex(file, regex);
- }
-
- /**
- * Checks if the file contains the provided regex.
- * @param file The file.
- * @param regex The regex.
- * @return A boolean value indicating if the file contains the provided
- * regex.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean checkRegex(File file, String regex)
- throws AraraException {
- Charset charset = (Charset) ConfigurationController.
- getInstance().get("directives.charset");
- try {
- String text = FileUtils.readFileToString(file, charset.name());
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(text);
- return matcher.find();
- } catch (IOException exception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_CHECKREGEX_IO_EXCEPTION,
- file.getName()
- ),
- exception
- );
- }
- }
-
- /**
- * Replicates a string pattern based on a list of objects, generating a list
- * as result.
- * @param pattern The string pattern.
- * @param values The list of objects to be merged with the pattern.
- * @return A list containing the string pattern replicated to each object
- * from the list.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static List<Object> replicateList(String pattern,
- List<Object> values) throws AraraException {
- List<Object> result = new ArrayList<Object>();
- for (Object value : values) {
- try {
- result.add(String.format(pattern, value));
- } catch (MissingFormatArgumentException exception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_REPLICATELIST_MISSING_FORMAT_ARGUMENTS_EXCEPTION
- ),
- exception
- );
- }
- }
- return result;
- }
-
- /**
- * Checks if the provided operating system string holds according to the
- * underlying operating system.
- * @param value A string representing an operating system.
- * @return A boolean value indicating if the provided string refers to the
- * underlying operating system.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean checkOS(String value) throws AraraException {
- Map<String, Boolean> values = new HashMap<String, Boolean>();
- values.put("windows", SystemUtils.IS_OS_WINDOWS);
- values.put("linux", SystemUtils.IS_OS_LINUX);
- values.put("mac", SystemUtils.IS_OS_MAC_OSX);
- values.put("unix", SystemUtils.IS_OS_UNIX);
- values.put("aix", SystemUtils.IS_OS_AIX);
- values.put("irix", SystemUtils.IS_OS_IRIX);
- values.put("os2", SystemUtils.IS_OS_OS2);
- values.put("solaris", SystemUtils.IS_OS_SOLARIS);
- values.put("cygwin", (Boolean) SystemCallController.
- getInstance().get("cygwin"));
- if (!values.containsKey(value.toLowerCase())) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_CHECKOS_INVALID_OPERATING_SYSTEM,
- value
- )
- );
- }
- return values.get(value.toLowerCase());
- }
-
- /**
- * Returns the exit status of the application.
- * @return An integer representing the exit status of the application.
- */
- public static int getExitStatus() {
- return (Integer) ConfigurationController.
- getInstance().get("execution.status");
- }
-
- /**
- * Gets the system property according to the provided key, or resort to the
- * fallback value if an exception is thrown or if the key is invalid.
- * @param key The system property key.
- * @param fallback The fallback value.
- * @return A string containing the system property value or the fallback.
- */
- public static String getSystemProperty(String key, String fallback) {
- try {
- String result = System.getProperty(key, fallback);
- return result.equals("") ? fallback : result;
- } catch (Exception exception) {
- return fallback;
- }
- }
-
- /**
- * Gets the preamble content, converting a single string into a list of
- * strings, based on new lines.
- * @return A list of strings representing the preamble content.
- */
- public static List<String> getPreambleContent() {
- if (((Boolean) ConfigurationController.
- getInstance().get("execution.preamble.active")) == true) {
- return new ArrayList<String>(
- Arrays.asList(
- ((String) ConfigurationController.getInstance().
- get("execution.preamble.content")
- ).split("\n"))
- );
- }
- else {
- return new ArrayList<String>();
- }
- }
-
- /**
- * Generates a list of filenames from the provided command based on a list
- * of extensions for each underlying operating system.
- * @param command A string representing the command.
- * @return A list of filenames.
- */
- private static List<String> appendExtensions(String command) {
-
- // the resulting list, to hold the
- // filenames generated from the
- // provided command
- List<String> result = new ArrayList<String>();
-
- // list of extensions, specific for
- // each operating system (in fact, it
- // is more Windows specific)
- List<String> extensions;
-
- // the application is running on
- // Windows, so let's look for the
- // following extensions in order
- if (SystemUtils.IS_OS_WINDOWS) {
-
- // this list is actually a sublist from
- // the original Windows PATHEXT environment
- // variable which holds the list of executable
- // extensions that Windows supports
- extensions = Arrays.asList(".com", ".exe", ".bat", ".cmd");
- }
- else {
-
- // no Windows, so the default
- // extension will be just an
- // empty string
- extensions = Arrays.asList("");
- }
-
- // for each and every extension in the
- // list, let's build the corresponding
- // filename and add to the result
- for (String extension : extensions) {
- result.add(command.concat(extension));
- }
-
- // return the resulting list
- // holding the filenames
- return result;
- }
-
- /**
- * Checks if the provided command name is reachable from the system path.
- * @param command A string representing the command.
- * @return A logic value.
- */
- public static boolean isOnPath(String command) {
- try {
-
- // first and foremost, let's build the list
- // of filenames based on the underlying
- // operating system
- List<String> filenames = appendExtensions(command);
-
- // break the path into several parts
- // based on the path separator symbol
- StringTokenizer tokenizer = new StringTokenizer(
- System.getenv("PATH"),
- File.pathSeparator
- );
-
- // iterate through every part of the
- // path looking for each filename
- while (tokenizer.hasMoreTokens()) {
-
- // if the search does not return an empty
- // list, one of the filenames got a match,
- // and the command is available somewhere
- // in the system path
- if (
- !FileUtils.listFiles(
- new File(tokenizer.nextToken()),
- new NameFileFilter(filenames),
- null
- ).isEmpty()) {
-
- // command is found somewhere,
- // so it is on path
- return true;
- }
- }
-
- // nothing was found,
- // command is not on path
- return false;
- }
- catch (Exception exception) {
-
- // an exception was raised, simply
- // return and forget about it
- return false;
- }
- }
-
- /**
- * Gets the full base name of a file.
- * @param file The file.
- * @return The corresponding full base name.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static String getFullBasename(File file) throws AraraException {
-
- // if the provided file does not contain a
- // file separator, fallback to the usual
- // base name lookup
- if (!file.toString().contains(File.separator)) {
- return getBasename(file);
- }
- else {
-
- // we need to get the parent file, get the
- // canonical path and build the corresponding
- // full base name path
- File parent = file.getParentFile();
- String path = getCanonicalPath(parent == null ? file : parent);
- return buildPath(path, getBasename(file));
- }
- }
-
- /**
- * Checks whether a directory is under a root directory.
- * @param f1 Directory to be inspected.
- * @param f2 Root directory.
- * @return Logical value indicating whether the directoy is under root.
- * @throws AraraException There was a problem with path retrieval.
- */
- public static boolean isSubDirectory(File f1, File f2)
- throws AraraException {
- if (f1.isDirectory()) {
- return getCanonicalPath(f1).
- startsWith(
- getParentCanonicalPath(f2).concat(File.separator)
- );
- }
- else {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_ISSUBDIRECTORY_NOT_A_DIRECTORY,
- f1.getName()
- )
- );
- }
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/ConfigurationUtils.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/ConfigurationUtils.java
deleted file mode 100644
index 7336110ebe..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/ConfigurationUtils.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import com.github.cereda.arara.Arara;
-import com.github.cereda.arara.controller.LanguageController;
-import com.github.cereda.arara.model.AraraException;
-import com.github.cereda.arara.model.FileType;
-import com.github.cereda.arara.model.FileTypeResource;
-import com.github.cereda.arara.model.Messages;
-import com.github.cereda.arara.model.Resource;
-import java.io.File;
-import java.io.FileReader;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.Predicate;
-import org.apache.commons.lang.SystemUtils;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.Constructor;
-import org.yaml.snakeyaml.error.MarkedYAMLException;
-import org.yaml.snakeyaml.nodes.Tag;
-import org.yaml.snakeyaml.representer.Representer;
-
-/**
- * Implements configuration utilitary methods.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class ConfigurationUtils {
-
- // the application messages obtained from the
- // language controller
- private static final LanguageController messages =
- LanguageController.getInstance();
-
- /**
- * Gets the list of default file types provided by nightingale, in order.
- * @return The list of default file types, in order.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static List<FileType> getDefaultFileTypes() throws AraraException {
- return Arrays.asList(
- new FileType("tex"),
- new FileType("dtx"),
- new FileType("ltx"),
- new FileType("drv"),
- new FileType("ins")
- );
- }
-
- /**
- * Gets the configuration file located at the user home directory, if any.
- * @return The file reference to the external configuration, if any.
- */
- public static File getConfigFile() {
- List<String> names = Arrays.asList(
- ".araraconfig.yaml",
- "araraconfig.yaml",
- ".arararc.yaml",
- "arararc.yaml"
- );
-
- // look for configuration files in the user's working directory first
- for (String name : names) {
- String path = CommonUtils.buildPath(SystemUtils.USER_DIR, name);
- File file = new File(path);
- if (file.exists()) {
- return file;
- }
- }
-
- // if no configuration files are found in the user's working directory,
- // try to look up in a global directory, that is, the user home
- for (String name : names) {
- String path = CommonUtils.buildPath(SystemUtils.USER_HOME, name);
- File file = new File(path);
- if (file.exists()) {
- return file;
- }
- }
- return null;
- }
-
- /**
- * Validates the configuration file.
- * @param file The configuration file.
- * @return The configuration file as a resource.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Resource validateConfiguration(File file)
- throws AraraException {
-
- Representer representer = new Representer();
- representer.addClassTag(Resource.class, new Tag("!config"));
- Yaml yaml = new Yaml(new Constructor(Resource.class), representer);
- try {
- Resource resource = yaml.loadAs(new FileReader(file),
- Resource.class);
- if (resource.getFiletypes() != null) {
- List<FileTypeResource> filetypes = resource.getFiletypes();
- if (CollectionUtils.exists(filetypes,
- new Predicate<FileTypeResource>() {
- public boolean evaluate(FileTypeResource filetype) {
- return (filetype.getExtension() == null);
- }
- })) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_CONFIGURATION_FILETYPE_MISSING_EXTENSION
- )
- );
- }
- }
- return resource;
- } catch (MarkedYAMLException yamlException) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_CONFIGURATION_INVALID_YAML
- ),
- yamlException
- );
- } catch (Exception exception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_CONFIGURATION_GENERIC_ERROR
- )
- );
- }
- }
-
- /**
- * Normalize a list of rule paths, removing all duplicates.
- * @param paths The list of rule paths.
- * @return A list of normalized paths, without duplicates.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static List<String> normalizePaths(List<String> paths)
- throws AraraException {
- paths.add(CommonUtils.buildPath(getApplicationPath(), "rules"));
- Set<String> set = new LinkedHashSet<String>(paths);
- List<String> result = new ArrayList<String>(set);
- return result;
- }
-
- /**
- * Normalize a list of file types, removing all duplicates.
- * @param types The list of file types.
- * @return A list of normalized file types, without duplicates.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static List<FileType> normalizeFileTypes(List<FileType> types)
- throws AraraException {
- types.addAll(getDefaultFileTypes());
- Set<FileType> set = new LinkedHashSet<FileType>(types);
- List<FileType> result = new ArrayList<FileType>(set);
- return result;
- }
-
- /**
- * Gets the canonical absolute application path.
- * @return The string representation of the canonical absolute application
- * path.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static String getApplicationPath() throws AraraException {
- try {
- String path = Arara.class.getProtectionDomain().
- getCodeSource().getLocation().getPath();
- path = URLDecoder.decode(path, "UTF-8");
- path = new File(path).getParentFile().getPath();
- return path;
- } catch (UnsupportedEncodingException exception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_GETAPPLICATIONPATH_ENCODING_EXCEPTION
- ),
- exception
- );
- }
- }
-
- /**
- * Cleans the file name to avoid invalid entries.
- * @param name The file name.
- * @return A cleaned file name.
- */
- public static String cleanFileName(String name) {
- String result = (new File(name)).getName().trim();
- if (CommonUtils.checkEmptyString(result)) {
- return "arara";
- } else {
- return result.trim();
- }
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/DatabaseUtils.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/DatabaseUtils.java
deleted file mode 100644
index 3a9b4eeea5..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/DatabaseUtils.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import com.github.cereda.arara.controller.ConfigurationController;
-import com.github.cereda.arara.controller.LanguageController;
-import com.github.cereda.arara.model.AraraException;
-import com.github.cereda.arara.model.Database;
-import com.github.cereda.arara.model.Messages;
-import java.io.File;
-import org.simpleframework.xml.Serializer;
-import org.simpleframework.xml.core.Persister;
-
-/**
- * Implements database utilitary methods.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class DatabaseUtils {
-
- // the application messages obtained from the
- // language controller
- private static final LanguageController messages =
- LanguageController.getInstance();
-
- /**
- * Loads the XML file representing the database.
- * @return The database object.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Database load() throws AraraException {
- if (!exists()) {
- return new Database();
- } else {
- File file = new File(getPath());
- try {
- Serializer serializer = new Persister();
- Database database = serializer.read(Database.class, file);
- return database;
- } catch (Exception exception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_LOAD_COULD_NOT_LOAD_XML,
- file.getName()
- ),
- exception
- );
- }
- }
- }
-
- /**
- * Saves the database on a XML file.
- * @param database The database object.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static void save(Database database) throws AraraException {
- File file = new File(getPath());
- try {
- Serializer serializer = new Persister();
- serializer.write(database, file);
- } catch (Exception exception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_SAVE_COULD_NOT_SAVE_XML,
- file.getName()
- ),
- exception
- );
- }
- }
-
- /**
- * Checks if the XML file representing the database exists.
- * @return A boolean value indicating if the XML file exists.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- private static boolean exists() throws AraraException {
- File file = new File(getPath());
- return file.exists();
- }
-
- /**
- * Gets the path to the XML file representing the database.
- * @return A string representing the path to the XML file.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- private static String getPath() throws AraraException {
- String name = ((String) ConfigurationController.
- getInstance().get("execution.database.name")).concat(".xml");
- String path = CommonUtils.getParentCanonicalPath(getReference());
- return CommonUtils.buildPath(path, name);
- }
-
- /**
- * Gets the main file reference.
- * @return The main file reference.
- */
- private static File getReference() {
- return (File) ConfigurationController.
- getInstance().get("execution.reference");
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/DirectiveAssembler.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/DirectiveAssembler.java
deleted file mode 100644
index 6f6f676ab5..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/DirectiveAssembler.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Implements a directive assembler in order to help build a directive from a
- * list of strings.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class DirectiveAssembler {
-
- // this variable holds a list of
- // line numbers indicating which
- // lines composed the resulting
- // potential directive
- private final List<Integer> lineNumbers;
-
- // this variable holds the textual
- // representation of the directive
- private String text;
-
- /**
- * Constructor.
- */
- public DirectiveAssembler() {
- lineNumbers = new ArrayList<Integer>();
- text = "";
- }
-
- /**
- * Checks if an append operation is allowed.
- * @return A boolean value indicating if an append operation is allowed.
- */
- public boolean isAppendAllowed() {
- return !lineNumbers.isEmpty();
- }
-
- /**
- * Adds a line number to the assembler.
- * @param line An integer representing the line number.
- */
- public void addLineNumber(int line) {
- lineNumbers.add(line);
- }
-
- /**
- * Appends the provided line to the assembler text.
- * @param line The provided line.
- */
- public void appendLine(String line) {
- text = text.concat(" ").concat(line.trim());
- }
-
- /**
- * Gets the list of line numbers.
- * @return The list of line numbers.
- */
- public List<Integer> getLineNumbers() {
- return lineNumbers;
- }
-
- /**
- * Gets the text.
- * @return The assembler text, properly trimmed.
- */
- public String getText() {
- return text.trim();
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/DirectiveResolver.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/DirectiveResolver.java
deleted file mode 100644
index b0a1af850b..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/DirectiveResolver.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import org.yaml.snakeyaml.nodes.Tag;
-import org.yaml.snakeyaml.resolver.Resolver;
-
-/**
- * This class implements a directive resolver.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class DirectiveResolver extends Resolver {
-
- /**
- * Adds implicit resolvers to the YAML model. For arara, I disabled
- * boolean and numeric values to be automatically parsed. They still can
- * be used through an explicit conversion in the rule context.
- */
- @Override
- protected void addImplicitResolvers() {
- addImplicitResolver(Tag.MERGE, MERGE, "<");
- addImplicitResolver(Tag.NULL, NULL, "~nN\0");
- addImplicitResolver(Tag.NULL, EMPTY, null);
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/DirectiveUtils.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/DirectiveUtils.java
deleted file mode 100644
index 6ea0404f72..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/DirectiveUtils.java
+++ /dev/null
@@ -1,438 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import com.github.cereda.arara.controller.ConfigurationController;
-import com.github.cereda.arara.controller.LanguageController;
-import com.github.cereda.arara.model.AraraException;
-import com.github.cereda.arara.model.Conditional;
-import com.github.cereda.arara.model.Directive;
-import com.github.cereda.arara.model.Messages;
-import com.github.cereda.arara.model.Pair;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.yaml.snakeyaml.DumperOptions;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.Constructor;
-import org.yaml.snakeyaml.error.MarkedYAMLException;
-import org.yaml.snakeyaml.representer.Representer;
-
-/**
- * Implements directive utilitary methods.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class DirectiveUtils {
-
- // the application messages obtained from the
- // language controller
- private static final LanguageController messages =
- LanguageController.getInstance();
-
- // get the logger context from a factory
- private static final Logger logger =
- LoggerFactory.getLogger(DirectiveUtils.class);
-
- /**
- * Extracts a list of directives from a list of strings.
- * @param lines List of strings.
- * @return A list of directives.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static List<Directive> extractDirectives(List<String> lines)
- throws AraraException {
-
- boolean header = (Boolean) ConfigurationController.
- getInstance().get("execution.header");
- String regex = (String) ConfigurationController.
- getInstance().get("execution.file.pattern");
- Pattern linecheck = Pattern.compile(regex);
- regex = regex.concat((String) ConfigurationController.
- getInstance().get("application.pattern"));
- Pattern pattern = Pattern.compile(regex);
- List<Pair<Integer, String>> pairs =
- new ArrayList<Pair<Integer, String>>();
- Matcher matcher;
- for (int i = 0; i < lines.size(); i++) {
- matcher = pattern.matcher(lines.get(i));
- if (matcher.find()) {
- String line = lines.get(i).substring(
- matcher.end(),
- lines.get(i).length()
- );
- Pair<Integer, String> pair =
- new Pair<Integer, String>(i + 1, line);
- pairs.add(pair);
-
- logger.info(
- messages.getMessage(
- Messages.LOG_INFO_POTENTIAL_PATTERN_FOUND,
- (i + 1),
- line.trim()
- )
- );
- }
- else {
- if (header) {
- if (!checkLinePattern(linecheck, lines.get(i))) {
- break;
- }
- }
- }
- }
-
- if (pairs.isEmpty()) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_VALIDATE_NO_DIRECTIVES_FOUND
- )
- );
- }
-
- List<DirectiveAssembler> assemblers
- = new ArrayList<DirectiveAssembler>();
- DirectiveAssembler assembler = new DirectiveAssembler();
- regex = (String) ConfigurationController.getInstance().
- get("directives.linebreak.pattern");
- pattern = Pattern.compile(regex);
- for (Pair<Integer, String> pair : pairs) {
- matcher = pattern.matcher(pair.getSecondElement());
- if (matcher.find()) {
- if (!assembler.isAppendAllowed()) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_VALIDATE_ORPHAN_LINEBREAK,
- pair.getFirstElement()
- )
- );
- } else {
- assembler.addLineNumber(pair.getFirstElement());
- assembler.appendLine(matcher.group(1));
- }
- } else {
- if (assembler.isAppendAllowed()) {
- assemblers.add(assembler);
- }
- assembler = new DirectiveAssembler();
- assembler.addLineNumber(pair.getFirstElement());
- assembler.appendLine(pair.getSecondElement());
- }
- }
- if (assembler.isAppendAllowed()) {
- assemblers.add(assembler);
- }
-
- List<Directive> directives = new ArrayList<Directive>();
- for (DirectiveAssembler current : assemblers) {
- directives.add(generateDirective(current));
- }
- return directives;
-
- }
-
- /**
- * Generates a directive from a directive assembler.
- * @param assembler The directive assembler.
- * @return The corresponding directive.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Directive generateDirective(DirectiveAssembler assembler)
- throws AraraException {
- String regex = (String) ConfigurationController.getInstance().
- get("directives.pattern");
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(assembler.getText());
- if (matcher.find()) {
- Directive directive = new Directive();
- directive.setIdentifier(matcher.group(1));
- directive.setParameters(
- getParameters(matcher.group(3), assembler.getLineNumbers())
- );
- Conditional conditional = new Conditional();
- conditional.setType(getType(matcher.group(5)));
- conditional.setCondition(getCondition(matcher.group(6)));
- directive.setConditional(conditional);
- directive.setLineNumbers(assembler.getLineNumbers());
-
- logger.info(
- messages.getMessage(
- Messages.LOG_INFO_POTENTIAL_DIRECTIVE_FOUND,
- directive
- )
- );
-
- return directive;
- } else {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_VALIDATE_INVALID_DIRECTIVE_FORMAT,
- CommonUtils.getCollectionElements(
- assembler.getLineNumbers(),
- "(",
- ")",
- ", "
- )
- )
- );
- }
- }
-
- /**
- * Gets the conditional type based on the input string.
- * @param text The input string.
- * @return The conditional type.
- */
- private static Conditional.ConditionalType getType(String text) {
- if (text == null) {
- return Conditional.ConditionalType.NONE;
- } else {
- if (text.equals("if")) {
- return Conditional.ConditionalType.IF;
- } else {
- if (text.equals("while")) {
- return Conditional.ConditionalType.WHILE;
- } else {
- if (text.equals("until")) {
- return Conditional.ConditionalType.UNTIL;
- } else {
- return Conditional.ConditionalType.UNLESS;
- }
- }
- }
- }
- }
-
- /**
- * Gets the condition from the input string.
- * @param text The input string.
- * @return A string representing the condition.
- */
- private static String getCondition(String text) {
- return text == null ? "" : text;
- }
-
- /**
- * Gets the parameters from the input string.
- * @param text The input string.
- * @param numbers The list of line numbers.
- * @return A map containing the directive parameters.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- private static Map<String, Object> getParameters(String text,
- List<Integer> numbers) throws AraraException {
-
- if (text == null) {
- return new HashMap<String, Object>();
- }
-
- Yaml yaml = new Yaml(
- new Constructor(),
- new Representer(),
- new DumperOptions(),
- new DirectiveResolver()
- );
- try {
- @SuppressWarnings("unchecked")
- HashMap<String, Object> map = yaml.loadAs(text, HashMap.class);
- return map;
- } catch (MarkedYAMLException exception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_VALIDATE_YAML_EXCEPTION,
- CommonUtils.getCollectionElements(
- numbers,
- "(",
- ")",
- ", "
- )
- ),
- exception
- );
- }
- }
-
- /**
- * Validates the list of directives, returning a new list.
- * @param directives The list of directives.
- * @return A new list of directives.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static List<Directive> validate(List<Directive> directives)
- throws AraraException {
-
- ArrayList<Directive> result = new ArrayList<Directive>();
- for (Directive directive : directives) {
- Map<String, Object> parameters = directive.getParameters();
-
- if (parameters.containsKey("file")) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_VALIDATE_FILE_IS_RESERVED,
- CommonUtils.getCollectionElements(
- directive.getLineNumbers(),
- "(",
- ")",
- ", "
- )
- )
- );
- }
-
- if (parameters.containsKey("reference")) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_VALIDATE_REFERENCE_IS_RESERVED,
- CommonUtils.getCollectionElements(
- directive.getLineNumbers(),
- "(",
- ")",
- ", "
- )
- )
- );
- }
-
- if (parameters.containsKey("files")) {
-
- Object holder = parameters.get("files");
- if (holder instanceof List) {
- @SuppressWarnings("unchecked")
- List<Object> files = (List<Object>) holder;
- parameters.remove("files");
- if (files.isEmpty()) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_VALIDATE_EMPTY_FILES_LIST,
- CommonUtils.getCollectionElements(
- directive.getLineNumbers(),
- "(",
- ")",
- ", "
- )
- )
- );
- }
- for (Object file : files) {
- Map<String, Object> map = new HashMap<String, Object>();
- for (String key : parameters.keySet()) {
- map.put(key, parameters.get(key));
- }
- File representation = CommonUtils.
- getCanonicalFile(String.valueOf(file));
-
- map.put("reference", representation);
- map.put("file", representation.getName());
-
- Directive addition = new Directive();
- Conditional conditional = new Conditional();
- conditional.setCondition(directive.getConditional().
- getCondition()
- );
- conditional.setType(directive.getConditional().
- getType()
- );
- addition.setIdentifier(directive.getIdentifier());
- addition.setConditional(conditional);
- addition.setParameters(map);
- addition.setLineNumbers(directive.getLineNumbers());
- result.add(addition);
- }
- } else {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_VALIDATE_FILES_IS_NOT_A_LIST,
- CommonUtils.getCollectionElements(
- directive.getLineNumbers(),
- "(",
- ")",
- ", "
- )
- )
- );
- }
- } else {
- File representation = (File) ConfigurationController.
- getInstance().get("execution.reference");
- parameters.put("file", representation.getName());
- parameters.put("reference", representation);
- directive.setParameters(parameters);
- result.add(directive);
- }
- }
-
- logger.info(
- messages.getMessage(
- Messages.LOG_INFO_VALIDATED_DIRECTIVES
- )
- );
- logger.info(DisplayUtils.displayOutputSeparator(
- messages.getMessage(
- Messages.LOG_INFO_DIRECTIVES_BLOCK
- )
- ));
- for (Directive directive : result) {
- logger.info(directive.toString());
- }
-
- logger.info(DisplayUtils.displaySeparator());
-
- return result;
- }
-
- /**
- * Checks if the provided line contains the corresponding pattern, based on
- * the file type, or an empty line.
- * @param pattern Pattern to be matched, based on the file type.
- * @param line Provided line.
- * @return Logical value indicating if the provided line contains the
- * corresponding pattern, based on the file type, or an empty line.
- */
- private static boolean checkLinePattern(Pattern pattern, String line) {
- return CommonUtils.checkEmptyString(line.trim()) ||
- pattern.matcher(line).find();
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/DisplayUtils.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/DisplayUtils.java
deleted file mode 100644
index 75cda6f99a..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/DisplayUtils.java
+++ /dev/null
@@ -1,502 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import com.github.cereda.arara.controller.ConfigurationController;
-import com.github.cereda.arara.controller.LanguageController;
-import com.github.cereda.arara.model.AraraException;
-import com.github.cereda.arara.model.Conditional;
-import com.github.cereda.arara.model.Messages;
-import com.github.cereda.arara.model.StopWatch;
-import java.io.File;
-import java.util.List;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.WordUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Implements display utilitary methods.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class DisplayUtils {
-
- // the application messages obtained from the
- // language controller
- private static final LanguageController messages =
- LanguageController.getInstance();
-
- // get the logger context from a factory
- private static final Logger logger =
- LoggerFactory.getLogger(DisplayUtils.class);
-
- /**
- * Displays the short version of the current entry in the terminal.
- * @param name Rule name.
- * @param task Task name.
- */
- private static void buildShortEntry(String name, String task) {
- int width = getWidth();
- int result = getLongestMatch();
- if (result >= width) {
- result = 10;
- }
- int space = width - result - 1;
- StringBuilder entry = new StringBuilder();
- entry.append("(").append(name).append(") ");
- entry.append(task).append(" ");
- String line = StringUtils.abbreviate(entry.toString(), space - 4);
- entry = new StringBuilder();
- entry.append(StringUtils.rightPad(line, space, ".")).append(" ");
- System.out.print(entry);
- }
-
- /**
- * Displays the short version of the current entry result in the terminal.
- * @param value The boolean value to be displayed.
- */
- private static void buildShortResult(boolean value) {
- int result = getLongestMatch();
- System.out.println(StringUtils.leftPad(getResult(value), result));
- }
-
- /**
- * Displays the current entry result in the terminal.
- * @param value The boolean value to be displayed.
- */
- public static void printEntryResult(boolean value) {
- ConfigurationController.getInstance().put("display.line", false);
- ConfigurationController.getInstance().put("display.result", true);
- ConfigurationController.getInstance()
- .put("execution.status", value ? 0 : 1);
- logger.info(
- messages.getMessage(
- Messages.LOG_INFO_TASK_RESULT
- ).concat(" ").concat(getResult(value))
- );
- if (!isDryRunMode()) {
- if (!isVerboseMode()) {
- buildShortResult(value);
- } else {
- buildLongResult(value);
- }
- }
- }
-
- /**
- * Displays a long version of the current entry result in the terminal.
- * @param value The boolean value to be displayed
- */
- private static void buildLongResult(boolean value) {
- int width = getWidth();
- System.out.println("\n".concat(StringUtils.leftPad(
- " ".concat(getResult(value)), width, "-"
- )));
- }
-
- /**
- * Displays the current entry in the terminal.
- * @param name The rule name.
- * @param task The task name.
- */
- public static void printEntry(String name, String task) {
- logger.info(
- messages.getMessage(
- Messages.LOG_INFO_INTERPRET_TASK,
- task,
- name
- )
- );
- ConfigurationController.getInstance().put("display.line", true);
- ConfigurationController.getInstance().put("display.result", false);
- if (!isDryRunMode()) {
- if (!isVerboseMode()) {
- buildShortEntry(name, task);
- } else {
- buildLongEntry(name, task);
- }
- } else {
- buildDryRunEntry(name, task);
- }
- }
-
- /**
- * Gets the length of the longest result match.
- * @return An integer value representing the longest result match.
- */
- private static int getLongestMatch() {
- String[] values = new String[]{
- messages.getMessage(Messages.INFO_LABEL_ON_SUCCESS),
- messages.getMessage(Messages.INFO_LABEL_ON_FAILURE),
- messages.getMessage(Messages.INFO_LABEL_ON_ERROR)
- };
- int max = values[0].length();
- for (String value : values) {
- if (max < value.length()) {
- max = value.length();
- }
- }
- return max;
- }
-
- /**
- * Displays a long version of the current entry in the terminal.
- * @param name Rule name.
- * @param task Task name.
- */
- private static void buildLongEntry(String name, String task) {
- if (ConfigurationController.getInstance().contains("display.rolling")) {
- addNewLine();
- } else {
- ConfigurationController.getInstance().put("display.rolling", true);
- }
- StringBuilder line = new StringBuilder();
- line.append("(").append(name).append(") ");
- line.append(task);
- System.out.println(displaySeparator());
- System.out.println(StringUtils.abbreviate(line.toString(), getWidth()));
- System.out.println(displaySeparator());
- }
-
- /**
- * Displays a dry-run version of the current entry in the terminal.
- * @param name The rule name.
- * @param task The task name.
- */
- private static void buildDryRunEntry(String name, String task) {
- if (ConfigurationController.getInstance().contains("display.rolling")) {
- addNewLine();
- } else {
- ConfigurationController.getInstance().put("display.rolling", true);
- }
- StringBuilder line = new StringBuilder();
- line.append("[DR] (").append(name).append(") ");
- line.append(task);
- System.out.println(StringUtils.abbreviate(line.toString(), getWidth()));
- System.out.println(displaySeparator());
- }
-
- /**
- * Displays the exception in the terminal.
- * @param exception The exception object.
- */
- public static void printException(AraraException exception) {
- ConfigurationController.getInstance().put("display.exception", true);
- ConfigurationController.getInstance().put("execution.status", 2);
- boolean display = false;
- if (ConfigurationController.getInstance().contains("display.line")) {
- display = (Boolean) ConfigurationController.
- getInstance().get("display.line");
- }
- if (ConfigurationController.getInstance().contains("display.result")) {
- if (((Boolean) ConfigurationController.
- getInstance().get("display.result")) == true) {
- addNewLine();
- }
- }
- if (display) {
- if (!isDryRunMode()) {
- if (!isVerboseMode()) {
- buildShortError();
- } else {
- buildLongError();
- }
- addNewLine();
- }
- }
- String text = exception.hasException() ?
- exception.getMessage().concat(" ").concat(
- messages.getMessage(
- Messages.INFO_DISPLAY_EXCEPTION_MORE_DETAILS
- )
- )
- : exception.getMessage();
- logger.error(text);
- wrapText(text);
- if (exception.hasException()) {
- addNewLine();
- displayDetailsLine();
- String details = exception.getException().getMessage();
- logger.error(details);
- wrapText(details);
- }
- }
-
- /**
- * Gets the string representation of the provided boolean value.
- * @param value The boolean value.
- * @return The string representation.
- */
- private static String getResult(boolean value) {
- return (value == true ?
- messages.getMessage(
- Messages.INFO_LABEL_ON_SUCCESS
- )
- : messages.getMessage(Messages.INFO_LABEL_ON_FAILURE));
- }
-
- /**
- * Displays the short version of an error in the terminal.
- */
- private static void buildShortError() {
- int result = getLongestMatch();
- System.out.println(StringUtils.leftPad(
- messages.getMessage(
- Messages.INFO_LABEL_ON_ERROR
- ),
- result
- ));
- }
-
- /**
- * Displays the long version of an error in the terminal.
- */
- private static void buildLongError() {
- String line = StringUtils.leftPad(
- " ".concat(messages.getMessage(Messages.INFO_LABEL_ON_ERROR)),
- getWidth(), "-");
- System.out.println(line);
- }
-
- /**
- * Gets the default terminal width defined in the settings.
- * @return An integer representing the terminal width.
- */
- private static int getWidth() {
- return (Integer) ConfigurationController.
- getInstance().get("application.width");
- }
-
- /**
- * Displays the provided text wrapped nicely according to the default
- * terminal width.
- * @param text The text to be displayed.
- */
- public static void wrapText(String text) {
- System.out.println(WordUtils.wrap(text, getWidth()));
- }
-
- /**
- * Checks if the execution is in dry-run mode.
- * @return A boolean value indicating if the execution is in dry-run mode.
- */
- private static boolean isDryRunMode() {
- return (Boolean) ConfigurationController.
- getInstance().get("execution.dryrun");
- }
-
- /**
- * Checks if the execution is in verbose mode.
- * @return A boolean value indicating if the execution is in verbose mode.
- */
- private static boolean isVerboseMode() {
- return (Boolean) ConfigurationController.
- getInstance().get("execution.verbose");
- }
-
- /**
- * Displays the rule authors in the terminal.
- * @param authors The list of authors.
- */
- public static void printAuthors(List<String> authors) {
- StringBuilder line = new StringBuilder();
- line.append(authors.size() == 1 ?
- messages.getMessage(Messages.INFO_LABEL_AUTHOR)
- : messages.getMessage(Messages.INFO_LABEL_AUTHORS));
- String text = authors.isEmpty() ?
- messages.getMessage(Messages.INFO_LABEL_NO_AUTHORS)
- : CommonUtils.getCollectionElements(
- CommonUtils.trimSpaces(authors), "", "", ", ");
- line.append(" ").append(text);
- wrapText(line.toString());
- }
-
- /**
- * Displays the current conditional in the terminal.
- * @param conditional The conditional object.
- */
- public static void printConditional(Conditional conditional) {
- if (conditional.getType() != Conditional.ConditionalType.NONE) {
- StringBuilder line = new StringBuilder();
- line.append(messages.getMessage(Messages.INFO_LABEL_CONDITIONAL));
- line.append(" (");
- line.append(String.valueOf(conditional.getType()));
- line.append(") ").append(conditional.getCondition());
- wrapText(line.toString());
- }
- }
-
- /**
- * Displays the file information in the terminal.
- */
- public static void printFileInformation() {
- File file = (File) ConfigurationController.
- getInstance().get("execution.reference");
- String version = (String) ConfigurationController.
- getInstance().get("application.version");
- String revision = (String) ConfigurationController.
- getInstance().get("application.revision");
- String line = messages.getMessage(
- Messages.INFO_DISPLAY_FILE_INFORMATION,
- file.getName(),
- CommonUtils.calculateFileSize(file),
- CommonUtils.getLastModifiedInformation(file)
- );
- logger.info(messages.getMessage(
- Messages.LOG_INFO_WELCOME_MESSAGE,
- version,
- revision
- ));
- logger.info(displaySeparator());
- logger.info(String.format("::: arara @ %s",
- getApplicationPath()
- ));
- logger.info(String.format("::: Java %s, %s",
- CommonUtils.getSystemProperty("java.version",
- "[unknown version]"),
- CommonUtils.getSystemProperty("java.vendor",
- "[unknown vendor]")
- ));
- logger.info(String.format("::: %s",
- CommonUtils.getSystemProperty("java.home",
- "[unknown location]")
- ));
- logger.info(String.format("::: %s, %s, %s",
- CommonUtils.getSystemProperty("os.name",
- "[unknown OS name]"),
- CommonUtils.getSystemProperty("os.arch",
- "[unknown OS arch]"),
- CommonUtils.getSystemProperty("os.version",
- "[unknown OS version]")
- ));
- logger.info(String.format("::: user.home @ %s",
- CommonUtils.getSystemProperty("user.home",
- "[unknown user's home directory]")
- ));
- logger.info(String.format("::: user.dir @ %s",
- CommonUtils.getSystemProperty("user.dir",
- "[unknown user's working directory]")
- ));
- logger.info(String.format("::: CF @ %s",
- (String) ConfigurationController.
- getInstance().get("execution.configuration.name")
- ));
- logger.info(displaySeparator());
- logger.info(line);
- wrapText(line);
- addNewLine();
- }
-
- /**
- * Displays the elapsed time in the terminal.
- */
- public static void printTime() {
- if (ConfigurationController.getInstance().contains("display.time")) {
- if ((ConfigurationController.getInstance().contains("display.line"))
- || (ConfigurationController.getInstance().
- contains("display.exception"))) {
- addNewLine();
- }
- String text = messages.getMessage(
- Messages.INFO_DISPLAY_EXECUTION_TIME, StopWatch.getTime());
- logger.info(text);
- wrapText(text);
- }
- }
-
- /**
- * Displays the application logo in the terminal.
- */
- public static void printLogo() {
- StringBuilder builder = new StringBuilder();
- builder.append(" __ _ _ __ __ _ _ __ __ _ ").append("\n");
- builder.append(" / _` | '__/ _` | '__/ _` |").append("\n");
- builder.append("| (_| | | | (_| | | | (_| |").append("\n");
- builder.append(" \\__,_|_| \\__,_|_| \\__,_|");
- System.out.println(builder.toString());
- addNewLine();
- }
-
- /**
- * Adds a new line in the terminal.
- */
- private static void addNewLine() {
- System.out.println();
- }
-
- /**
- * Displays a line containing details.
- */
- private static void displayDetailsLine() {
- String line = messages.getMessage(
- Messages.INFO_LABEL_ON_DETAILS).concat(" ");
- line = StringUtils.rightPad(
- StringUtils.abbreviate(line, getWidth()), getWidth(), "-");
- System.out.println(line);
- }
-
- /**
- * Gets the output separator with the provided text.
- * @param message The provided text.
- * @return A string containing the output separator with the provided text.
- */
- public static String displayOutputSeparator(String message) {
- return StringUtils.center(" ".concat(message).concat(" "),
- getWidth(), "-");
- }
-
- /**
- * Gets the line separator.
- * @return A string containing the line separator.
- */
- public static String displaySeparator() {
- return StringUtils.repeat("-", getWidth());
- }
-
- /**
- * Gets the application path.
- * @return A string containing the application path.
- */
- private static String getApplicationPath() {
- try {
- return ConfigurationUtils.getApplicationPath();
- }
- catch (AraraException ae) {
- return "[unknown application path]";
- }
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/FileHandlingUtils.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/FileHandlingUtils.java
deleted file mode 100644
index fdd1ab36c6..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/FileHandlingUtils.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.commons.io.FileUtils;
-
-/**
- * Implements file handling utilitary methods.
- *
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class FileHandlingUtils {
-
- /**
- * Writes the string to a file, using UTF-8 as default encoding.
- * @param file The file.
- * @param text The string to be written.
- * @param append A flag whether to append the content.
- * @return A logical value indicating whether it was successful.
- */
- public static boolean writeToFile(File file, String text, boolean append) {
- try {
-
- // try to write the provided
- // string to the file, with
- // UTF-8 as encoding
- FileUtils.writeStringToFile(file, text, "UTF-8", append);
- return true;
-
- } catch (IOException nothandled) {
-
- // if something bad happens,
- // gracefully fallback to
- // reporting the failure
- return false;
- }
- }
-
- /**
- * Writes the string list to a file, using UTF-8 as default encoding.
- * @param file The file.
- * @param lines The string list to be written.
- * @param append A flag whether to append the content.
- * @return A logical value indicating whether it was successful.
- */
- public static boolean writeToFile(File file, List<String> lines,
- boolean append) {
- try {
-
- // try to write the provided
- // string lists to the file,
- // with UTF-8 as encoding
- FileUtils.writeLines(file, "UTF-8", lines, append);
- return true;
-
- } catch (IOException nothandled) {
-
- // if something bad happens,
- // gracefully fallback to
- // reporting the failure
- return false;
- }
- }
-
- /**
- * Reads the provided file into a list of strings.
- * @param file The file.
- * @return A list of strings.
- */
- public static List<String> readFromFile(File file) {
- try {
-
- // returns the contents of
- // the provided file as
- // a list of strings
- return FileUtils.readLines(file, "UTF-8");
-
- } catch (IOException nothandled) {
-
- // if something bad happens,
- // gracefully fallback to
- // an empty file list
- return new ArrayList<String>();
- }
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/FileSearchingUtils.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/FileSearchingUtils.java
deleted file mode 100644
index 9f0c03c143..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/FileSearchingUtils.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.FalseFileFilter;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.apache.commons.io.filefilter.WildcardFileFilter;
-
-/**
- * Implements file searching utilitary methods.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class FileSearchingUtils {
-
- /**
- * List all files from the provided directory according to the list of
- * extensions. The leading dot must be omitted, unless it is part of the
- * extension.
- * @param directory The provided directory.
- * @param extensions The list of extensions.
- * @param recursive A flag indicating whether the search is recursive.
- * @return A list of files.
- */
- public static List<File> listFilesByExtensions(File directory,
- List<String> extensions, boolean recursive) {
- try {
-
- // convert the provided extension
- // list to an extension array
- String[] array = new String[extensions.size()];
- array = extensions.toArray(array);
-
- // return the result of the
- // provided search
- return new ArrayList<File>(
- FileUtils.listFiles(directory, array, recursive)
- );
- } catch (Exception nothandled) {
-
- // if something bad happens,
- // gracefully fallback to
- // an empty file list
- return new ArrayList<File>();
- }
- }
-
- /**
- * List all files from the provided directory matching the list of file
- * name patterns. Such list can contain wildcards.
- * @param directory The provided directory.
- * @param patterns The list of file name patterns.
- * @param recursive A flag indicating whether the search is recursive.
- * @return A list of files.
- */
- public static List<File> listFilesByPatterns(File directory,
- List<String> patterns, boolean recursive) {
- try {
-
- // return the result of the provided
- // search, with the wildcard filter
- // and a potential recursive search
- return new ArrayList<File>(
- FileUtils.listFiles(
- directory,
- new WildcardFileFilter(patterns),
- recursive
- ? TrueFileFilter.INSTANCE
- : FalseFileFilter.INSTANCE
- )
- );
- } catch (Exception nothandled) {
-
- // if something bad happens,
- // gracefully fallback to
- // an empty file list
- return new ArrayList<File>();
- }
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/InterpreterUtils.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/InterpreterUtils.java
deleted file mode 100644
index d60de0884b..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/InterpreterUtils.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import com.github.cereda.arara.controller.ConfigurationController;
-import com.github.cereda.arara.controller.LanguageController;
-import com.github.cereda.arara.model.AraraException;
-import com.github.cereda.arara.model.Argument;
-import com.github.cereda.arara.model.Command;
-import com.github.cereda.arara.model.Conditional;
-import com.github.cereda.arara.model.Messages;
-import com.github.cereda.arara.model.Rule;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.Transformer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.zeroturnaround.exec.InvalidExitValueException;
-import org.zeroturnaround.exec.ProcessExecutor;
-import org.zeroturnaround.exec.listener.ShutdownHookProcessDestroyer;
-
-/**
- * Implements interpreter utilitary methods.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class InterpreterUtils {
-
- // the application messages obtained from the
- // language controller
- private static final LanguageController messages =
- LanguageController.getInstance();
-
- // get the logger context from a factory
- private static final Logger logger =
- LoggerFactory.getLogger(InterpreterUtils.class);
-
- /**
- * Gets a list of all rule arguments.
- * @param rule The provided rule.
- * @return A list of strings containing all rule arguments.
- */
- public static List<String> getRuleArguments(Rule rule) {
- Collection<String> result = CollectionUtils.collect(
- rule.getArguments(), new Transformer<Argument, String>() {
- public String transform(Argument input) {
- return input.getIdentifier();
- }
- });
- return new ArrayList<String>(result);
- }
-
- /**
- * Checks if the current conditional has a prior evaluation.
- * @param conditional The current conditional object.
- * @return A boolean value indicating if the current conditional has a prior
- * evaluation.
- */
- public static boolean runPriorEvaluation(Conditional conditional) {
- if (((Boolean) ConfigurationController.getInstance().
- get("execution.dryrun")) == true) {
- return false;
- }
- switch (conditional.getType()) {
- case IF:
- case WHILE:
- case UNLESS:
- return true;
- default:
- return false;
- }
- }
-
- /**
- * Runs the command in the underlying operating system.
- * @param command An object representing the command.
- * @return An integer value representing the exit code.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static int run(Object command) throws AraraException {
- boolean verbose = (Boolean) ConfigurationController.
- getInstance().get("execution.verbose");
- boolean timeout = (Boolean) ConfigurationController.
- getInstance().get("execution.timeout");
- long value = (Long) ConfigurationController.
- getInstance().get("execution.timeout.value");
- TimeUnit unit = (TimeUnit) ConfigurationController.
- getInstance().get("execution.timeout.unit");
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- ProcessExecutor executor = new ProcessExecutor();
- if (CommonUtils.checkClass(Command.class, command)) {
- executor = executor.command(((Command) command).getElements());
- if (((Command) command).hasWorkingDirectory()) {
- executor = executor.directory(
- ((Command) command).getWorkingDirectory()
- );
- }
- } else {
- executor = executor.commandSplit((String) command);
- }
- if (timeout) {
- if (value == 0) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_RUN_TIMEOUT_INVALID_RANGE
- )
- );
- }
- executor = executor.timeout(value, unit);
- }
- TeeOutputStream tee;
- if (verbose) {
- tee = new TeeOutputStream(System.out, buffer);
- executor = executor.redirectInput(System.in);
- } else {
- tee = new TeeOutputStream(buffer);
- }
- executor = executor.redirectOutput(tee).redirectError(tee);
- ShutdownHookProcessDestroyer hook = new ShutdownHookProcessDestroyer();
- executor = executor.addDestroyer(hook);
- try {
- int exit = executor.execute().getExitValue();
- logger.info(DisplayUtils.displayOutputSeparator(
- messages.getMessage(
- Messages.LOG_INFO_BEGIN_BUFFER
- )
- ));
- logger.info(buffer.toString());
- logger.info(DisplayUtils.displayOutputSeparator(
- messages.getMessage(
- Messages.LOG_INFO_END_BUFFER
- )
- ));
- return exit;
- } catch (IOException ioexception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_RUN_IO_EXCEPTION
- ),
- ioexception
- );
- } catch (InterruptedException iexception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_RUN_INTERRUPTED_EXCEPTION
- ),
- iexception
- );
- } catch (InvalidExitValueException ievexception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_RUN_INVALID_EXIT_VALUE_EXCEPTION
- ),
- ievexception
- );
- } catch (TimeoutException texception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_RUN_TIMEOUT_EXCEPTION
- ),
- texception
- );
- } catch (Exception exception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_RUN_GENERIC_EXCEPTION
- ),
- exception
- );
- }
- }
-
- /**
- * Builds the rule path based on the rule name and returns the corresponding
- * file location.
- * @param name The rule name.
- * @return The rule file.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static File buildRulePath(String name) throws AraraException {
- @SuppressWarnings("unchecked")
- List<String> paths = (List<String>) ConfigurationController.
- getInstance().get("execution.rule.paths");
- for (String path : paths) {
- File location = new File(construct(path, name));
- if (location.exists()) {
- return location;
- }
- }
- return null;
- }
-
- /**
- * Constructs the path given the current path and the rule name.
- * @param path The current path.
- * @param name The rule name.
- * @return The constructed path.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static String construct(String path, String name)
- throws AraraException {
- name = name.concat(".yaml");
- File location = new File(path);
- if (location.isAbsolute()) {
- return CommonUtils.buildPath(path, name);
- } else {
- File reference = (File) ConfigurationController.
- getInstance().get("execution.reference");
- String parent = CommonUtils.buildPath(
- CommonUtils.getParentCanonicalPath(reference), path);
- return CommonUtils.buildPath(parent, name);
- }
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/MessageUtils.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/MessageUtils.java
deleted file mode 100644
index b36bda8808..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/MessageUtils.java
+++ /dev/null
@@ -1,313 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import com.github.cereda.arara.controller.ConfigurationController;
-import javax.swing.JOptionPane;
-import javax.swing.UIManager;
-
-/**
- * Implements utilitary methods for displaying messages.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class MessageUtils {
-
- // holds the default width for the
- // message body, in pixels
- private static final int WIDTH = 250;
-
- // let's start the UI manager and set
- // the default look and feel to be as
- // close as possible to the system
- static {
-
- // get the current look and feel
- String laf = (String) ConfigurationController.
- getInstance().get("ui.lookandfeel");
-
- // check if one is actually set
- if (!laf.equals("none")) {
-
- // use a special keyword to indicate
- // the use of a system look and feel
- if (laf.equals("system")) {
- laf = UIManager.getSystemLookAndFeelClassName();
- }
-
- // let's try it, in case it fails,
- // rely to the default look and feel
- try {
-
- // get the system look and feel name
- // and try to set it as default
- UIManager.setLookAndFeel(laf);
- }
- catch (Exception exception) {
- // quack, quack, quack
- }
-
- }
- }
-
- /**
- * Normalizes the icon type to one of the five available icons.
- * @param value An integer value.
- * @return The normalized integer value.
- */
- private static int normalizeIconType(int value) {
-
- // do the normalization according to the available
- // icons in the underlying message implementation
- switch (value) {
- case 1:
- value = JOptionPane.ERROR_MESSAGE;
- break;
- case 2:
- value = JOptionPane.INFORMATION_MESSAGE;
- break;
- case 3:
- value = JOptionPane.WARNING_MESSAGE;
- break;
- case 4:
- value = JOptionPane.QUESTION_MESSAGE;
- break;
- default:
- value = JOptionPane.PLAIN_MESSAGE;
- break;
- }
- return value;
- }
-
- /**
- * Normalizes the message width, so only valid nonzero values are accepted.
- * @param value An integer value corresponding to the message width.
- * @return The normalized width.
- */
- private static int normalizeMessageWidth(int value) {
- return (value > 0 ? value : WIDTH);
- }
-
- /**
- * Shows the message.
- * @param width Integer value, in pixels.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- */
- public static void showMessage(int width, int type,
- String title, String text) {
-
- // effectively shows the message based
- // on the provided parameters
- JOptionPane.showMessageDialog(
- null,
- String.format(
- "<html><body style=\"width:%dpx\">%s</body></html>",
- normalizeMessageWidth(width),
- text
- ),
- title,
- normalizeIconType(type)
- );
- }
-
- /**
- * Shows the message. It relies on the default width.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- */
- public static void showMessage(int type, String title, String text) {
- showMessage(WIDTH, type, title, text);
- }
-
- /**
- * Shows a message with options presented as an array of buttons.
- * @param width Integer value, in pixels.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- * @param buttons An array of objects to be presented as buttons.
- * @return The index of the selected button, starting from 1.
- */
- public static int showOptions(int width, int type, String title,
- String text, Object... buttons) {
-
- // returns the index of the selected button,
- // zero if nothing is selected
- return JOptionPane.showOptionDialog(
- null,
- String.format(
- "<html><body style=\"width:%dpx\">%s</body></html>",
- normalizeMessageWidth(width),
- text
- ),
- title,
- JOptionPane.DEFAULT_OPTION,
- normalizeIconType(type),
- null,
- buttons,
- buttons[0]
- ) + 1;
- }
-
- /**
- * Shows a message with options presented as an array of buttons. It relies
- * on the default width.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- * @param buttons An array of objects to be presented as buttons.
- * @return The index of the selected button, starting from 1.
- */
- public static int showOptions(int type, String title,
- String text, Object... buttons) {
- return showOptions(WIDTH, type, title, text, buttons);
- }
-
- /**
- * Shows a message with a text input.
- * @param width Integer value, in pixels.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- * @return The string representing the input text.
- */
- public static String showInput(int width, int type,
- String title, String text) {
-
- // get the string from the
- // input text, if any
- String input = JOptionPane.showInputDialog(
- null,
- String.format(
- "<html><body style=\"width:%dpx\">%s</body></html>",
- normalizeMessageWidth(width),
- text
- ),
- title,
- normalizeIconType(type)
- );
-
- // if the input is not null, that is,
- // the user actually typed something
- if (input != null) {
-
- // return the trimmed string
- return input.trim();
- }
-
- // nothing was typed, so let's
- // return an empty string
- return "";
- }
-
- /**
- * Shows a message with a text input. It relies on the default width.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- * @return The string representing the input text.
- */
- public static String showInput(int type, String title, String text) {
- return showInput(WIDTH, type, title, text);
- }
-
- /**
- * Shows a message with options presented as a dropdown list of elements.
- * @param width Integer value, in pixels.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- * @param elements An array of objects representing the elements.
- * @return The index of the selected element, starting from 1.
- */
- public static int showDropdown(int width, int type, String title,
- String text, Object... elements) {
-
- // show the dropdown list and get
- // the selected object, if any
- Object index = JOptionPane.showInputDialog(
- null,
- String.format(
- "<html><body style=\"width:%dpx\">%s</body></html>",
- normalizeMessageWidth(width),
- text
- ),
- title,
- normalizeIconType(type),
- null,
- elements,
- elements[0]
- );
-
- // if it's not a null object, let's
- // find the corresponding index
- if (index != null) {
-
- // iterate through the array of elements
- for (int i = 0; i < elements.length; i++) {
-
- // if the element is found, simply
- // return the index plus 1, as zero
- // corresponds to no selection at all
- if (elements[i].equals(index)) {
- return i + 1;
- }
-
- }
- }
-
- // nothing was selected,
- // simply return zero
- return 0;
- }
-
- /**
- * Shows a message with options presented as a dropdown list of elements. It
- * relies on the default width.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- * @param elements An array of objects representing the elements.
- * @return The index of the selected element, starting from 1.
- */
- public static int showDropdown(int type, String title,
- String text, Object... elements) {
- return showDropdown(WIDTH, type, title, text, elements);
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/Methods.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/Methods.java
deleted file mode 100644
index 24982dace9..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/Methods.java
+++ /dev/null
@@ -1,1368 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import com.github.cereda.arara.controller.ConfigurationController;
-import com.github.cereda.arara.controller.LanguageController;
-import com.github.cereda.arara.model.AraraException;
-import com.github.cereda.arara.model.Command;
-import com.github.cereda.arara.model.Messages;
-import com.github.cereda.arara.model.Pair;
-import com.github.cereda.arara.model.Session;
-import com.github.cereda.arara.model.Trigger;
-import java.io.File;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Implements some auxiliary methods for runtime evaluation.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class Methods {
-
- // the language controller
- private static final LanguageController messages =
- LanguageController.getInstance();
-
- // the session controller
- private static final Session session = new Session();
-
- /**
- * Adds the rule methods to the provided map.
- * @param map The map.
- */
- public static void addRuleMethods(Map<String, Object> map) {
- addConditionalMethods(map);
- try {
- map.put("getOriginalFile", Methods.class.getMethod("getOriginalFile"));
- map.put("getOriginalReference", Methods.class.getMethod("getOriginalReference"));
- map.put("isEmpty", Methods.class.getMethod("isEmpty", String.class));
- map.put("isNotEmpty", Methods.class.getMethod("isNotEmpty", String.class));
- map.put("isEmpty", Methods.class.getMethod("isEmpty", String.class, Object.class));
- map.put("isNotEmpty", Methods.class.getMethod("isNotEmpty", String.class, Object.class));
- map.put("isEmpty", Methods.class.getMethod("isEmpty", String.class, Object.class, Object.class));
- map.put("isNotEmpty", Methods.class.getMethod("isNotEmpty", String.class, Object.class, Object.class));
- map.put("isTrue", Methods.class.getMethod("isTrue", String.class));
- map.put("isFalse", Methods.class.getMethod("isFalse", String.class));
- map.put("isTrue", Methods.class.getMethod("isTrue", String.class, Object.class));
- map.put("isFalse", Methods.class.getMethod("isFalse", String.class, Object.class));
- map.put("isTrue", Methods.class.getMethod("isTrue", String.class, Object.class, Object.class));
- map.put("isFalse", Methods.class.getMethod("isFalse", String.class, Object.class, Object.class));
- map.put("isTrue", Methods.class.getMethod("isTrue", String.class, Object.class, Object.class, Object.class));
- map.put("isFalse", Methods.class.getMethod("isFalse", String.class, Object.class, Object.class, Object.class));
- map.put("trimSpaces", Methods.class.getMethod("trimSpaces", String.class));
- map.put("isTrue", Methods.class.getMethod("isTrue", boolean.class, Object.class));
- map.put("isFalse", Methods.class.getMethod("isFalse", boolean.class, Object.class));
- map.put("isTrue", Methods.class.getMethod("isTrue", boolean.class, Object.class, Object.class));
- map.put("isFalse", Methods.class.getMethod("isFalse", boolean.class, Object.class, Object.class));
- map.put("getBasename", Methods.class.getMethod("getBasename", File.class));
- map.put("getBasename", Methods.class.getMethod("getBasename", String.class));
- map.put("getFullBasename", Methods.class.getMethod("getFullBasename", File.class));
- map.put("getFullBasename", Methods.class.getMethod("getFullBasename", String.class));
- map.put("getFiletype", Methods.class.getMethod("getFiletype", File.class));
- map.put("getFiletype", Methods.class.getMethod("getFiletype", String.class));
- map.put("throwError", Methods.class.getMethod("throwError", String.class));
- map.put("getSession", Methods.class.getMethod("getSession"));
- map.put("isWindows", Methods.class.getMethod("isWindows"));
- map.put("isLinux", Methods.class.getMethod("isLinux"));
- map.put("isMac", Methods.class.getMethod("isMac"));
- map.put("isUnix", Methods.class.getMethod("isUnix"));
- map.put("isAIX", Methods.class.getMethod("isAIX"));
- map.put("isIrix", Methods.class.getMethod("isIrix"));
- map.put("isOS2", Methods.class.getMethod("isOS2"));
- map.put("isSolaris", Methods.class.getMethod("isSolaris"));
- map.put("isCygwin", Methods.class.getMethod("isCygwin"));
- map.put("isWindows", Methods.class.getMethod("isWindows", Object.class, Object.class));
- map.put("isLinux", Methods.class.getMethod("isLinux", Object.class, Object.class));
- map.put("isMac", Methods.class.getMethod("isMac", Object.class, Object.class));
- map.put("isUnix", Methods.class.getMethod("isUnix", Object.class, Object.class));
- map.put("isAIX", Methods.class.getMethod("isAIX", Object.class, Object.class));
- map.put("isIrix", Methods.class.getMethod("isIrix", Object.class, Object.class));
- map.put("isOS2", Methods.class.getMethod("isOS2", Object.class, Object.class));
- map.put("isSolaris", Methods.class.getMethod("isSolaris", Object.class, Object.class));
- map.put("isCygwin", Methods.class.getMethod("isCygwin", Object.class, Object.class));
- map.put("replicatePattern", Methods.class.getMethod("replicatePattern", String.class, List.class));
- map.put("buildString", Methods.class.getMethod("buildString", Object[].class));
- map.put("addQuotes", Methods.class.getMethod("addQuotes", Object.class));
- map.put("getCommand", Methods.class.getMethod("getCommand", List.class));
- map.put("getCommand", Methods.class.getMethod("getCommand", Object[].class));
- map.put("getTrigger", Methods.class.getMethod("getTrigger", String.class));
- map.put("getTrigger", Methods.class.getMethod("getTrigger", String.class, Object[].class));
- map.put("checkClass", Methods.class.getMethod("checkClass", Class.class, Object.class));
- map.put("isString", Methods.class.getMethod("isString", Object.class));
- map.put("isList", Methods.class.getMethod("isList", Object.class));
- map.put("isMap", Methods.class.getMethod("isMap", Object.class));
- map.put("isBoolean", Methods.class.getMethod("isBoolean", Object.class));
- map.put("isVerboseMode", Methods.class.getMethod("isVerboseMode"));
- map.put("showMessage", Methods.class.getMethod("showMessage", int.class, String.class, String.class));
- map.put("showMessage", Methods.class.getMethod("showMessage", int.class, int.class, String.class, String.class));
- map.put("isOnPath", Methods.class.getMethod("isOnPath", String.class));
- map.put("unsafelyExecuteSystemCommand", Methods.class.getMethod("unsafelyExecuteSystemCommand", Command.class));
- map.put("mergeVelocityTemplate", Methods.class.getMethod("mergeVelocityTemplate", File.class, File.class, Map.class));
- map.put("getCommandWithWorkingDirectory", Methods.class.getMethod("getCommandWithWorkingDirectory", String.class, List.class));
- map.put("getCommandWithWorkingDirectory", Methods.class.getMethod("getCommandWithWorkingDirectory", String.class, Object[].class));
- map.put("getCommandWithWorkingDirectory", Methods.class.getMethod("getCommandWithWorkingDirectory", File.class, List.class));
- map.put("getCommandWithWorkingDirectory", Methods.class.getMethod("getCommandWithWorkingDirectory", File.class, Object[].class));
- map.put("listFilesByExtensions", Methods.class.getMethod("listFilesByExtensions", File.class, List.class, boolean.class));
- map.put("listFilesByExtensions", Methods.class.getMethod("listFilesByExtensions", String.class, List.class, boolean.class));
- map.put("listFilesByPatterns", Methods.class.getMethod("listFilesByPatterns", File.class, List.class, boolean.class));
- map.put("listFilesByPatterns", Methods.class.getMethod("listFilesByPatterns", String.class, List.class, boolean.class));
- map.put("writeToFile", Methods.class.getMethod("writeToFile", File.class, String.class, boolean.class));
- map.put("writeToFile", Methods.class.getMethod("writeToFile", File.class, List.class, boolean.class));
- map.put("writeToFile", Methods.class.getMethod("writeToFile", String.class, String.class, boolean.class));
- map.put("writeToFile", Methods.class.getMethod("writeToFile", String.class, List.class, boolean.class));
- map.put("readFromFile", Methods.class.getMethod("readFromFile", File.class));
- map.put("readFromFile", Methods.class.getMethod("readFromFile", String.class));
- map.put("isSubdirectory", Methods.class.getMethod("isSubdirectory", File.class));
- } catch (Exception exception) {
- // quack, quack, quack
- }
- }
-
- /**
- * Adds conditional methods to the provided map.
- * @param map The map.
- */
- public static void addConditionalMethods(Map<String, Object> map) {
- try {
- map.put("exists", Methods.class.getMethod("exists", String.class));
- map.put("exists", Methods.class.getMethod("exists", File.class));
- map.put("missing", Methods.class.getMethod("missing", String.class));
- map.put("missing", Methods.class.getMethod("missing", File.class));
- map.put("changed", Methods.class.getMethod("changed", String.class));
- map.put("changed", Methods.class.getMethod("changed", File.class));
- map.put("unchanged", Methods.class.getMethod("unchanged", String.class));
- map.put("unchanged", Methods.class.getMethod("unchanged", File.class));
- map.put("found", Methods.class.getMethod("found", String.class, String.class));
- map.put("found", Methods.class.getMethod("found", File.class, String.class));
- map.put("toFile", Methods.class.getMethod("toFile", String.class));
- map.put("showDropdown", Methods.class.getMethod("showDropdown", int.class, String.class, String.class, Object[].class));
- map.put("showDropdown", Methods.class.getMethod("showDropdown", int.class, int.class, String.class, String.class, Object[].class));
- map.put("showInput", Methods.class.getMethod("showInput", int.class, String.class, String.class));
- map.put("showInput", Methods.class.getMethod("showInput", int.class, int.class, String.class, String.class));
- map.put("showOptions", Methods.class.getMethod("showOptions", int.class, String.class, String.class, Object[].class));
- map.put("showOptions", Methods.class.getMethod("showOptions", int.class, int.class, String.class, String.class, Object[].class));
- map.put("currentFile", Methods.class.getMethod("currentFile"));
- map.put("loadClass", Methods.class.getMethod("loadClass", File.class, String.class));
- map.put("loadClass", Methods.class.getMethod("loadClass", String.class, String.class));
- map.put("loadObject", Methods.class.getMethod("loadObject", File.class, String.class));
- map.put("loadObject", Methods.class.getMethod("loadObject", String.class, String.class));
- } catch (Exception exception) {
- // quack, quack, quack
- }
- }
-
- /**
- * Gets the original file.
- * @return The original file.
- */
- public static String getOriginalFile() {
- File file = (File) ConfigurationController.getInstance().get("execution.reference");
- return file.getName();
- }
-
- /**
- * Gets the original reference.
- * @return The original reference.
- */
- public static File getOriginalReference() {
- return (File) ConfigurationController.getInstance().get("execution.reference");
- }
-
- /**
- * Checks if the string is empty.
- * @param string The string.
- * @return A boolean value.
- */
- public static boolean isEmpty(String string) {
- return CommonUtils.checkEmptyString(string);
- }
-
- /**
- * Checks if the string is not empty.
- * @param string The string.
- * @return A boolean value.
- */
- public static boolean isNotEmpty(String string) {
- return !isEmpty(string);
- }
-
- /**
- * Checks if the string is empty.
- * @param string The string.
- * @param yes Object to return if true.
- * @return An object or empty string.
- */
- public static Object isEmpty(String string, Object yes) {
- return isEmpty(string) ? yes : "";
- }
-
- /**
- * Checks if the string is not empty.
- * @param string The string.
- * @param yes Object to return if true.
- * @return An object or empty string.
- */
- public static Object isNotEmpty(String string, Object yes) {
- return isNotEmpty(string) ? yes : "";
- }
-
- /**
- * Checks if the string is empty.
- * @param string The string.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- */
- public static Object isEmpty(String string, Object yes, Object no) {
- return isEmpty(string) ? yes : no;
- }
-
- /**
- * Checks if the string is not empty.
- * @param string The string.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- */
- public static Object isNotEmpty(String string, Object yes, Object no) {
- return isNotEmpty(string) ? yes : no;
- }
-
- /**
- * Checks if the string holds a true value.
- * @param string The string.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean isTrue(String string) throws AraraException {
- return isEmpty(string) ? false : CommonUtils.checkBoolean(string);
- }
-
- /**
- * Checks if the string holds a false value.
- * @param string The string.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean isFalse(String string) throws AraraException {
- return isEmpty(string) ? false : !CommonUtils.checkBoolean(string);
- }
-
- /**
- * Checks if the string holds a true value.
- * @param string The string.
- * @param yes Object to return if true.
- * @return An object or an empty string.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isTrue(String string, Object yes)
- throws AraraException {
- return isTrue(string) ? yes : "";
- }
-
- /**
- * Checks if the string holds a false value.
- * @param string The string.
- * @param yes Object to return if true.
- * @return An object or an empty string.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isFalse(String string, Object yes)
- throws AraraException {
- return (isFalse(string) ? yes : "");
- }
-
- /**
- * Checks if the string holds a true value.
- * @param string The string.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isTrue(String string, Object yes, Object no)
- throws AraraException {
- return (isTrue(string) ? yes : no);
- }
-
- /**
- * Checks if the string holds a false value.
- * @param string The string.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isFalse(String string, Object yes, Object no)
- throws AraraException {
- return (isFalse(string) ? yes : no);
- }
-
- /**
- * Checks if the string holds a true value.
- * @param string The string.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @param fallback Object to return if string is empty.
- * @return One of the three options.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isTrue(String string, Object yes, Object no,
- Object fallback) throws AraraException {
- return isEmpty(string) ? fallback : (isTrue(string) ? yes : no);
- }
-
- /**
- * Checks if the string holds a false value.
- * @param string The string.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @param fallback Object to return if string is empty.
- * @return One of the three options.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isFalse(String string, Object yes, Object no,
- Object fallback) throws AraraException {
- return isEmpty(string) ? fallback : (isFalse(string) ? yes : no);
- }
-
- /**
- * Trim spaces from the string.
- * @param string The string.
- * @return A trimmed string.
- */
- public static String trimSpaces(String string) {
- return string.trim();
- }
-
- /**
- * Checks if the expression resolves to true.
- * @param value The expression.
- * @param yes Object to return if true.
- * @return An object or an empty string.
- */
- public static Object isTrue(boolean value, Object yes) {
- return value ? yes : "";
- }
-
- /**
- * Checks if the expression resolves to false.
- * @param value The expression.
- * @param yes Object to return if true.
- * @return An object or an empty string.
- */
- public static Object isFalse(boolean value, Object yes) {
- return !value ? yes : "";
- }
-
- /**
- * Checks if the expression resolves to true.
- * @param value The expression.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- */
- public static Object isTrue(boolean value, Object yes, Object no) {
- return value ? yes : no;
- }
-
- /**
- * Checks if the expression resolves to false.
- * @param value The expression.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- */
- public static Object isFalse(boolean value, Object yes, Object no) {
- return !value ? yes : no;
- }
-
- /**
- * Gets the basename.
- * @param file The file.
- * @return The basename of the provided file.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static String getBasename(File file) throws AraraException {
- if (file.isFile()) {
- return CommonUtils.getBasename(file);
- } else {
- throw new AraraException(
- CommonUtils.getRuleErrorHeader().concat(
- messages.getMessage(
- Messages.ERROR_BASENAME_NOT_A_FILE,
- file.getName()
- )
- )
- );
- }
- }
-
- /**
- * Gets the basename.
- * @param filename The string.
- * @return The basename.
- */
- public static String getBasename(String filename) {
- return CommonUtils.getBasename(filename);
- }
-
- /**
- * Gets the file type.
- * @param file The provided file.
- * @return The file type.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static String getFiletype(File file) throws AraraException {
- if (file.isFile()) {
- return CommonUtils.getFiletype(file);
- } else {
- throw new AraraException(
- CommonUtils.getRuleErrorHeader().concat(
- messages.getMessage(
- Messages.ERROR_FILETYPE_NOT_A_FILE,
- file.getName()
- )
- )
- );
- }
- }
-
- /**
- * Gets the file type.
- * @param filename The provided string.
- * @return The file type.
- */
- public static String getFiletype(String filename) {
- return CommonUtils.getFiletype(filename);
- }
-
- /**
- * Replicates the pattern to each element of a list.
- * @param pattern The pattern.
- * @param values The list.
- * @return A list of strings containing the pattern applied to the list.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static List<Object> replicatePattern(String pattern,
- List<Object> values) throws AraraException {
- return CommonUtils.replicateList(pattern, values);
- }
-
- /**
- * Throws an exception.
- * @param text The text to be thrown as the exception message.
- * @throws AraraException The exception to be thrown by this method.
- */
- public static void throwError(String text) throws AraraException {
- throw new AraraException(text);
- }
-
- /**
- * Gets the session.
- * @return The session.
- */
- public static Session getSession() {
- return session;
- }
-
- /**
- * Checks if Windows is the underlying operating system.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean isWindows() throws AraraException {
- return CommonUtils.checkOS("windows");
- }
-
- /**
- * Checks if we are inside a Cygwin environment.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean isCygwin() throws AraraException {
- return CommonUtils.checkOS("cygwin");
- }
-
- /**
- * Checks if Linux is the underlying operating system.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean isLinux() throws AraraException {
- return CommonUtils.checkOS("linux");
- }
-
- /**
- * Checks if Mac is the underlying operating system.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean isMac() throws AraraException {
- return CommonUtils.checkOS("mac");
- }
-
- /**
- * Checks if Unix is the underlying operating system.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean isUnix() throws AraraException {
- return CommonUtils.checkOS("unix");
- }
-
- /**
- * Checks if AIX is the underlying operating system.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean isAIX() throws AraraException {
- return CommonUtils.checkOS("aix");
- }
-
- /**
- * Checks if Irix is the underlying operating system.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean isIrix() throws AraraException {
- return CommonUtils.checkOS("irix");
- }
-
- /**
- * Checks if OS2 is the underlying operating system.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean isOS2() throws AraraException {
- return CommonUtils.checkOS("os2");
- }
-
- /**
- * Checks if Solaris is the underlying operating system.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean isSolaris() throws AraraException {
- return CommonUtils.checkOS("solaris");
- }
-
- /**
- * Checks if Windows is the underlying operating system.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isWindows(Object yes, Object no)
- throws AraraException {
- return CommonUtils.checkOS("windows") ? yes : no;
- }
-
- /**
- * Checks if we are inside a Cygwin environment.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isCygwin(Object yes, Object no) throws AraraException {
- return CommonUtils.checkOS("cygwin") ? yes : no;
- }
-
- /**
- * Checks if Linux is the underlying operating system.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isLinux(Object yes, Object no) throws AraraException {
- return CommonUtils.checkOS("linux") ? yes : no;
- }
-
- /**
- * Checks if Mac is the underlying operating system.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isMac(Object yes, Object no) throws AraraException {
- return CommonUtils.checkOS("mac") ? yes : no;
- }
-
- /**
- * Checks if Unix is the underlying operating system.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isUnix(Object yes, Object no) throws AraraException {
- return CommonUtils.checkOS("unix") ? yes : no;
- }
-
- /**
- * Checks if AIX is the underlying operating system.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isAIX(Object yes, Object no) throws AraraException {
- return CommonUtils.checkOS("aix") ? yes : no;
- }
-
- /**
- * Checks if Irix is the underlying operating system.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isIrix(Object yes, Object no) throws AraraException {
- return CommonUtils.checkOS("irix") ? yes : no;
- }
-
- /**
- * Checks if OS2 is the underlying operating system.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isOS2(Object yes, Object no) throws AraraException {
- return CommonUtils.checkOS("os2") ? yes : no;
- }
-
- /**
- * Checks if Solaris is the underlying operating system.
- * @param yes Object to return if true.
- * @param no Object to return if false.
- * @return One of the two objects.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Object isSolaris(Object yes, Object no) throws AraraException {
- return CommonUtils.checkOS("solaris") ? yes : no;
- }
-
- /**
- * Checks if the file exists according to its extension.
- * @param extension The extension.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean exists(String extension) throws AraraException {
- return CommonUtils.exists(extension);
- }
-
- /**
- * Checks if the file is missing according to its extension.
- * @param extension The extension.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean missing(String extension) throws AraraException {
- return !exists(extension);
- }
-
- /**
- * Checks if the file has changed, according to its extension.
- * @param extension The extension.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean changed(String extension) throws AraraException {
- return CommonUtils.hasChanged(extension);
- }
-
- /**
- * Checks if the file is unchanged according to its extension.
- * @param extension The extension.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean unchanged(String extension) throws AraraException {
- return !changed(extension);
- }
-
- /**
- * Checks if the file exists.
- * @param filename The file.
- * @return A boolean value.
- */
- public static boolean exists(File filename) {
- return CommonUtils.exists(filename);
- }
-
- /**
- * Checks if the file is missing.
- * @param filename The file.
- * @return A boolean value.
- */
- public static boolean missing(File filename) {
- return !exists(filename);
- }
-
- /**
- * Checks if the file has changed.
- * @param filename The file.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean changed(File filename) throws AraraException {
- return CommonUtils.hasChanged(filename);
- }
-
- /**
- * Checks if the file is unchanged.
- * @param filename The file.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean unchanged(File filename) throws AraraException {
- return !changed(filename);
- }
-
- /**
- * Build a string based on an array of objects.
- * @param objects Array of objects.
- * @return A string built from the array.
- */
- public static String buildString(Object... objects) {
- return CommonUtils.generateString(objects);
- }
-
- /**
- * Encloses the provided object into double quotes.
- * @param object The object.
- * @return The object enclosed in double quotes.
- */
- public static String addQuotes(Object object) {
- return CommonUtils.addQuotes(object);
- }
-
- /**
- * Checks if the file contains the regex, based on its extension.
- * @param extension The extension.
- * @param regex The regex.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean found(String extension, String regex)
- throws AraraException {
- return CommonUtils.checkRegex(extension, regex);
- }
-
- /**
- * Checks if the file contains the provided regex.
- * @param file The file.
- * @param regex The regex.
- * @return A boolean value.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static boolean found(File file, String regex)
- throws AraraException {
- return CommonUtils.checkRegex(file, regex);
- }
-
- /**
- * Gets the command based on a list of strings.
- * @param elements The list of strings.
- * @return A command.
- */
- public static Command getCommand(List<String> elements) {
- return new Command(elements);
- }
-
- /**
- * Gets the command based on an array of objects.
- * @param elements Array of objects.
- * @return A command.
- */
- public static Command getCommand(Object... elements) {
- return new Command(elements);
- }
-
- /**
- * Gets the command based on an array of objects and with the provided
- * working directory as string.
- * @param path String path representing the working directory.
- * @param elements Array of elements.
- * @return A command.
- */
- public static Command getCommandWithWorkingDirectory(String path,
- Object... elements) {
- Command command = new Command(elements);
- command.setWorkingDirectory(new File(path));
- return command;
- }
-
- /**
- * Gets the command based on an array of objects and with the provided
- * working directory as file.
- * @param file File representing the working directory.
- * @param elements Array of elements.
- * @return A command.
- */
- public static Command getCommandWithWorkingDirectory(File file,
- Object... elements) {
- Command command = new Command(elements);
- command.setWorkingDirectory(file);
- return command;
- }
-
- /**
- * Gets the command based on a list of strings and with the provided
- * working directory as string.
- * @param path String path representing the working directory.
- * @param elements List of strings.
- * @return A command.
- */
- public static Command getCommandWithWorkingDirectory(String path,
- List<String> elements) {
- Command command = new Command(elements);
- command.setWorkingDirectory(new File(path));
- return command;
- }
-
- /**
- * Gets the command based on a list of strings and with the provided
- * working directory as file.
- * @param file File representing the working directory.
- * @param elements List of strings.
- * @return A command.
- */
- public static Command getCommandWithWorkingDirectory(File file,
- List<String> elements) {
- Command command = new Command(elements);
- command.setWorkingDirectory(file);
- return command;
- }
-
- /**
- * Gets the trigger.
- * @param action The action name.
- * @return The trigger.
- */
- public static Trigger getTrigger(String action) {
- return new Trigger(action, null);
- }
-
- /**
- * Gets the trigger.
- * @param action The action name.
- * @param parameters The trigger parameters.
- * @return A trigger.
- */
- public static Trigger getTrigger(String action, Object... parameters) {
- return new Trigger(action, Arrays.asList(parameters));
- }
-
- /**
- * Checks if the object is an intance of the provided class.
- * @param clazz The class.
- * @param object The object.
- * @return A boolean value.
- */
- public static boolean checkClass(Class clazz, Object object) {
- return CommonUtils.checkClass(clazz, object);
- }
-
- /**
- * Checks if the object is a string.
- * @param object The object.
- * @return A boolean value.
- */
- public static boolean isString(Object object) {
- return checkClass(String.class, object);
- }
-
- /**
- * Checks if the object is a list.
- * @param object The object.
- * @return A boolean value.
- */
- public static boolean isList(Object object) {
- return checkClass(List.class, object);
- }
-
- /**
- * Checks if the object is a map.
- * @param object The object.
- * @return A boolean value.
- */
- public static boolean isMap(Object object) {
- return checkClass(Map.class, object);
- }
-
- /**
- * Checks if the object is a boolean.
- * @param object The object.
- * @return A boolean value.
- */
- public static boolean isBoolean(Object object) {
- return checkClass(Boolean.class, object);
- }
-
- /**
- * Checks if the execution is in verbose mode.
- * @return A boolean value indicating if the execution is in verbose mode.
- */
- public static boolean isVerboseMode() {
- return (Boolean) ConfigurationController.
- getInstance().get("execution.verbose");
- }
-
- /**
- * Returns a file object based on the provided name.
- * @param name The file name.
- * @return A file object.
- */
- public static File toFile(String name) {
- return new File(name);
- }
-
- /**
- * Shows the message.
- * @param width Integer value, in pixels.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- */
- public static void showMessage(int width, int type,
- String title, String text) {
- MessageUtils.showMessage(width, type, title, text);
- }
-
- /**
- * Shows the message. It relies on the default width.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- */
- public static void showMessage(int type, String title, String text) {
- MessageUtils.showMessage(type, title, text);
- }
-
- /**
- * Shows a message with options presented as an array of buttons.
- * @param width Integer value, in pixels.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- * @param buttons An array of objects to be presented as buttons.
- * @return The index of the selected button, starting from 1.
- */
- public static int showOptions(int width, int type, String title,
- String text, Object... buttons) {
- return MessageUtils.showOptions(width, type, title, text, buttons);
- }
-
- /**
- * Shows a message with options presented as an array of buttons. It relies
- * on the default width.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- * @param buttons An array of objects to be presented as buttons.
- * @return The index of the selected button, starting from 1.
- */
- public static int showOptions(int type, String title,
- String text, Object... buttons) {
- return MessageUtils.showOptions(type, title, text, buttons);
- }
-
- /**
- * Shows a message with a text input.
- * @param width Integer value, in pixels.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- * @return The string representing the input text.
- */
- public static String showInput(int width, int type,
- String title, String text) {
- return MessageUtils.showInput(width, type, title, text);
- }
-
- /**
- * Shows a message with a text input. It relies on the default width.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- * @return The string representing the input text.
- */
- public static String showInput(int type, String title, String text) {
- return MessageUtils.showInput(type, title, text);
- }
-
- /**
- * Shows a message with options presented as a dropdown list of elements.
- * @param width Integer value, in pixels.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- * @param elements An array of objects representing the elements.
- * @return The index of the selected element, starting from 1.
- */
- public static int showDropdown(int width, int type, String title,
- String text, Object... elements) {
- return MessageUtils.showDropdown(width, type, title, text, elements);
- }
-
- /**
- * Shows a message with options presented as a dropdown list of elements. It
- * relies on the default width.
- * @param type Type of message.
- * @param title Title of the message.
- * @param text Text of the message.
- * @param elements An array of objects representing the elements.
- * @return The index of the selected element, starting from 1.
- */
- public static int showDropdown(int type, String title,
- String text, Object... elements) {
- return MessageUtils.showDropdown(type, title, text, elements);
- }
-
- /**
- * Checks if the provided command name is reachable from the system path.
- * @param command A string representing the command.
- * @return A logic value.
- */
- public static boolean isOnPath(String command) {
- return CommonUtils.isOnPath(command);
- }
-
- /**
- * Gets the full basename.
- * @param file The file.
- * @return The full basename of the provided file.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static String getFullBasename(File file) throws AraraException {
- if (file.isFile()) {
- return CommonUtils.getFullBasename(file);
- } else {
- throw new AraraException(
- CommonUtils.getRuleErrorHeader().concat(
- messages.getMessage(
- Messages.ERROR_BASENAME_NOT_A_FILE,
- file.getName()
- )
- )
- );
- }
- }
-
- /**
- * Gets the full basename.
- * @param name The string.
- * @return The full basename.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static String getFullBasename(String name) throws AraraException {
- return getFullBasename(new File(name));
- }
-
- /**
- * Unsafely executes a system command from the underlying operating system
- * and returns a pair containing the exit status and the command output as a
- * string.
- * @param command The system command to be executed.
- * @return A pair containing the exit status and the system command output
- * as a string.
- */
- public static Pair<Integer, String>
- unsafelyExecuteSystemCommand(Command command) {
- return UnsafeUtils.executeSystemCommand(command);
- }
-
- /**
- * Merges the provided template with a context map and writes the result in
- * an output file. This method relies on Apache Velocity.
- * @param input The input file.
- * @param output The output file.
- * @param map The context map.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static void mergeVelocityTemplate(File input, File output,
- Map<String, Object> map) throws AraraException {
- VelocityUtils.mergeVelocityTemplate(input, output, map);
- }
-
- /**
- * Gets the file reference for the current directive. It is important to
- * observe that version 4.0 of arara replicates the directive when 'files'
- * is detected amongst the parameters, so each instance will have a
- * different reference.
- * @return A file reference for the current directive.
- */
- public static File currentFile() {
- return (File) ConfigurationController.getInstance().
- get("execution.directive.reference");
- }
-
- /**
- * Loads a class from the provided file, potentially a Java archive.
- * @param file File containing the Java bytecode (namely, a JAR).
- * @param name The canonical name of the class.
- * @return A pair representing the status and the class.
- */
- public static Pair<Integer, Class> loadClass(File file, String name) {
- return ClassLoadingUtils.loadClass(file, name);
- }
-
- /**
- * Loads a class from the provided string reference, representing a file.
- * @param ref String reference representing a file.
- * @param name The canonical name of the class.
- * @return A pair representing the status and the class.
- */
- public static Pair<Integer, Class> loadClass(String ref, String name) {
- return ClassLoadingUtils.loadClass(new File(ref), name);
- }
-
- /**
- * Loads a class from the provided file, instantiating it.
- * @param file File containing the Java bytecode (namely, a JAR).
- * @param name The canonical name of the class.
- * @return A pair representing the status and the class object.
- */
- public static Pair<Integer, Object> loadObject(File file, String name) {
- return ClassLoadingUtils.loadObject(file, name);
- }
-
- /**
- * Loads a class from the provided string reference, instantiating it.
- * @param ref String reference representing a file.
- * @param name The canonical name of the class.
- * @return A pair representing the status and the class object.
- */
- public static Pair<Integer, Object> loadObject(String ref, String name) {
- return ClassLoadingUtils.loadObject(new File(ref), name);
- }
-
- /**
- * List all files from the provided directory according to the list of
- * extensions. The leading dot must be omitted, unless it is part of the
- * extension.
- * @param directory The provided directory.
- * @param extensions The list of extensions.
- * @param recursive A flag indicating whether the search is recursive.
- * @return A list of files.
- */
- public static List<File> listFilesByExtensions(File directory,
- List<String> extensions, boolean recursive) {
- return FileSearchingUtils.listFilesByExtensions(
- directory,
- extensions,
- recursive
- );
- }
-
- /**
- * List all files from the provided string path according to the list of
- * extensions. The leading dot must be omitted, unless it is part of the
- * extension.
- * @param path The provided path as plain string.
- * @param extensions The list of extensions.
- * @param recursive A flag indicating whether the search is recursive.
- * @return A list of files.
- */
- public static List<File> listFilesByExtensions(String path,
- List<String> extensions, boolean recursive) {
- return FileSearchingUtils.listFilesByExtensions(
- new File(path),
- extensions,
- recursive
- );
- }
-
- /**
- * List all files from the provided directory matching the list of file
- * name patterns. Such list can contain wildcards.
- * @param directory The provided directory.
- * @param patterns The list of file name patterns.
- * @param recursive A flag indicating whether the search is recursive.
- * @return A list of files.
- */
- public static List<File> listFilesByPatterns(File directory,
- List<String> patterns, boolean recursive) {
- return FileSearchingUtils.listFilesByPatterns(
- directory,
- patterns,
- recursive
- );
- }
-
- /**
- * List all files from the provided path matching the list of file
- * name patterns. Such list can contain wildcards.
- * @param path The provided path as plain string.
- * @param patterns The list of file name patterns.
- * @param recursive A flag indicating whether the search is recursive.
- * @return A list of files.
- */
- public static List<File> listFilesByPatterns(String path,
- List<String> patterns, boolean recursive) {
- return FileSearchingUtils.listFilesByPatterns(
- new File(path),
- patterns,
- recursive
- );
- }
-
- /**
- * Writes the string to a file, using UTF-8 as default encoding.
- * @param file The file.
- * @param text The string to be written.
- * @param append A flag whether to append the content.
- * @return A logical value indicating whether it was successful.
- */
- public static boolean writeToFile(File file, String text, boolean append) {
- return FileHandlingUtils.writeToFile(file, text, append);
- }
-
- /**
- * Writes the string to a file, using UTF-8 as default encoding.
- * @param path The path.
- * @param text The string to be written.
- * @param append A flag whether to append the content.
- * @return A logical value indicating whether it was successful.
- */
- public static boolean writeToFile(String path, String text,
- boolean append) {
- return FileHandlingUtils.writeToFile(new File(path), text, append);
- }
-
- /**
- * Writes the string list to a file, using UTF-8 as default encoding.
- * @param file The file.
- * @param lines The string list to be written.
- * @param append A flag whether to append the content.
- * @return A logical value indicating whether it was successful.
- */
- public static boolean writeToFile(File file, List<String> lines,
- boolean append) {
- return FileHandlingUtils.writeToFile(file, lines, append);
- }
-
- /**
- * Writes the string list to a file, using UTF-8 as default encoding.
- * @param path The path.
- * @param lines The string list to be written.
- * @param append A flag whether to append the content.
- * @return A logical value indicating whether it was successful.
- */
- public static boolean writeToFile(String path, List<String> lines,
- boolean append) {
- return FileHandlingUtils.writeToFile(new File(path), lines, append);
- }
-
- /**
- * Reads the provided file into a list of strings.
- * @param file The file.
- * @return A list of strings.
- */
- public static List<String> readFromFile(File file) {
- return FileHandlingUtils.readFromFile(file);
- }
-
- /**
- * Reads the provided file into a list of strings.
- * @param path The path.
- * @return A list of strings.
- */
- public static List<String> readFromFile(String path) {
- return FileHandlingUtils.readFromFile(new File(path));
- }
-
- /**
- * Checks whether a directory is under the project directory.
- * @param directory The directory to be inspected.
- * @return Logical value indicating whether the directoy is under root.
- * @throws AraraException There was a problem with path retrieval.
- */
- public static boolean isSubdirectory(File directory)
- throws AraraException {
- return CommonUtils.isSubDirectory(directory, getOriginalReference());
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/RuleUtils.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/RuleUtils.java
deleted file mode 100644
index f2fb1c8570..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/RuleUtils.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import com.github.cereda.arara.controller.LanguageController;
-import com.github.cereda.arara.model.AraraException;
-import com.github.cereda.arara.model.Argument;
-import com.github.cereda.arara.model.Messages;
-import com.github.cereda.arara.model.RuleCommand;
-import com.github.cereda.arara.model.Rule;
-import java.io.File;
-import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.Predicate;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.Constructor;
-import org.yaml.snakeyaml.error.MarkedYAMLException;
-import org.yaml.snakeyaml.nodes.Tag;
-import org.yaml.snakeyaml.representer.Representer;
-
-/**
- * Implements rule utilitary methods.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class RuleUtils {
-
- // the application messages obtained from the
- // language controller
- private static final LanguageController messages =
- LanguageController.getInstance();
-
- /**
- * Parses the provided file, checks the identifier and returns a rule
- * representation.
- * @param file The rule file.
- * @param identifier The directive identifier.
- * @return The rule object.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- public static Rule parseRule(File file, String identifier)
- throws AraraException {
- Representer representer = new Representer();
- representer.addClassTag(Rule.class, new Tag("!config"));
- Yaml yaml = new Yaml(new Constructor(Rule.class), representer);
- Rule rule = null;
- try {
- rule = yaml.loadAs(new FileReader(file), Rule.class);
- } catch (MarkedYAMLException yamlException) {
- throw new AraraException(
- CommonUtils.getRuleErrorHeader().concat(
- messages.getMessage(
- Messages.ERROR_PARSERULE_INVALID_YAML
- )
- ),
- yamlException
- );
- } catch (Exception exception) {
- throw new AraraException(
- CommonUtils.getRuleErrorHeader().concat(
- messages.getMessage(
- Messages.ERROR_PARSERULE_GENERIC_ERROR
- )
- )
- );
- }
- validateHeader(rule, identifier);
- validateBody(rule);
- return rule;
- }
-
- /**
- * Validates the rule header according to the directive identifier.
- * @param rule The rule object.
- * @param identifier The directive identifier.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- private static void validateHeader(Rule rule, String identifier)
- throws AraraException {
- if (rule.getIdentifier() != null) {
- if (!rule.getIdentifier().equals(identifier)) {
- throw new AraraException(CommonUtils.getRuleErrorHeader().
- concat(
- messages.getMessage(
- Messages.ERROR_VALIDATEHEADER_WRONG_IDENTIFIER,
- rule.getIdentifier(),
- identifier
- )
- )
- );
- }
- } else {
- throw new AraraException(
- CommonUtils.getRuleErrorHeader().concat(
- messages.getMessage(
- Messages.ERROR_VALIDATEHEADER_NULL_ID
- )
- )
- );
- }
- if (rule.getName() == null) {
- throw new AraraException(
- CommonUtils.getRuleErrorHeader().concat(
- messages.getMessage(
- Messages.ERROR_VALIDATEHEADER_NULL_NAME
- )
- )
- );
- }
- }
-
- /**
- * Validates the rule body.
- * @param rule The rule object.
- * @throws AraraException Something wrong happened, to be caught in the
- * higher levels.
- */
- private static void validateBody(Rule rule) throws AraraException {
- if (rule.getCommands() == null) {
- throw new AraraException(
- CommonUtils.getRuleErrorHeader().concat(
- messages.getMessage(
- Messages.ERROR_VALIDATEBODY_NULL_COMMANDS_LIST
- )
- )
- );
- } else {
- if (CollectionUtils.exists(rule.getCommands(),
- new Predicate<RuleCommand>() {
- public boolean evaluate(RuleCommand command) {
- return (command.getCommand() == null);
- }
- })) {
- throw new AraraException(CommonUtils.getRuleErrorHeader().
- concat(
- messages.getMessage(
- Messages.ERROR_VALIDATEBODY_NULL_COMMAND
- )
- )
- );
- }
- }
- if (rule.getArguments() == null) {
- throw new AraraException(
- CommonUtils.getRuleErrorHeader().concat(
- messages.getMessage(
- Messages.ERROR_VALIDATEBODY_ARGUMENTS_LIST
- )
- )
- );
- } else {
- String[] keywords = new String[]{"file", "files", "reference"};
-
- List<String> arguments = new ArrayList<String>();
- for (Argument argument : rule.getArguments()) {
- if (argument.getIdentifier() != null) {
- if ((argument.getFlag() != null) ||
- (argument.getDefault() != null)) {
- arguments.add(argument.getIdentifier());
- } else {
- throw new AraraException(
- CommonUtils.getRuleErrorHeader().concat(
- messages.getMessage(
- Messages.ERROR_VALIDATEBODY_MISSING_KEYS
- )
- )
- );
- }
- } else {
- throw new AraraException(
- CommonUtils.getRuleErrorHeader().concat(
- messages.getMessage(
- Messages.ERROR_VALIDATEBODY_NULL_ARGUMENT_ID
- )
- )
- );
- }
- }
-
- for (String keyword : keywords) {
- if (arguments.contains(keyword)) {
- throw new AraraException(
- CommonUtils.getRuleErrorHeader().concat(
- messages.getMessage(
- Messages.ERROR_VALIDATEBODY_ARGUMENT_ID_IS_RESERVED,
- keyword
- )
- )
- );
- }
- }
-
- int expected = arguments.size();
- int found = (new HashSet<String>(arguments)).size();
- if (expected != found) {
- throw new AraraException(
- CommonUtils.getRuleErrorHeader().concat(
- messages.getMessage(
- Messages.ERROR_VALIDATEBODY_DUPLICATE_ARGUMENT_IDENTIFIERS
- )
- )
- );
- }
- }
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/TeeOutputStream.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/TeeOutputStream.java
deleted file mode 100644
index 58418ea62d..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/TeeOutputStream.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import org.apache.commons.io.IOUtils;
-
-/**
- * Implements a stream splitter.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class TeeOutputStream extends OutputStream {
-
- // an array of streams in which
- // an object of this class will
- // split data
- private final OutputStream[] streams;
-
- /**
- * Constructor.
- * @param outputStreams An array of output streams.
- */
- public TeeOutputStream(OutputStream... outputStreams) {
- streams = outputStreams;
- }
-
- /**
- * Writes the provided integer to each stream.
- * @param b The provided integer
- * @throws IOException An IO exception.
- */
- @Override
- public void write(int b) throws IOException {
- for (OutputStream ostream : streams) {
- ostream.write(b);
- }
- }
-
- /**
- * Writes the provided byte array to each stream, with the provided offset
- * and length.
- * @param b The byte array.
- * @param offset The offset.
- * @param length The length.
- * @throws IOException An IO exception.
- */
- @Override
- public void write(byte[] b, int offset, int length) throws IOException {
- for (OutputStream ostream : streams) {
- ostream.write(b, offset, length);
- }
- }
-
- /**
- * Flushes every stream.
- * @throws IOException An IO exception.
- */
- @Override
- public void flush() throws IOException {
- for (OutputStream ostream : streams) {
- ostream.flush();
- }
- }
-
- /**
- * Closes every stream silently.
- */
- @Override
- public void close() {
- for (OutputStream ostream : streams) {
- IOUtils.closeQuietly(ostream);
- }
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/UnsafeUtils.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/UnsafeUtils.java
deleted file mode 100644
index d5a4058b3e..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/UnsafeUtils.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import com.github.cereda.arara.model.Command;
-import com.github.cereda.arara.model.Pair;
-import org.zeroturnaround.exec.ProcessExecutor;
-import org.zeroturnaround.exec.ProcessResult;
-
-/**
- * Implements unsafe utilitary methods.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class UnsafeUtils {
-
- /**
- * Executes a system command from the underlying operating system and
- * returns a pair containing the exit status and the command output as a
- * string.
- * @param command The system command to be executed.
- * @return A pair containing the exit status and the system command output
- * as a string.
- */
- public static Pair<Integer, String> executeSystemCommand(Command command) {
-
- try {
-
- // create a process result with the provided
- // command, capturing the output
- ProcessResult result = new ProcessExecutor(
- command.getElements()
- ).readOutput(true).execute();
-
- // return the pair containing the exit status
- // and the output string as UTF-8
- return new Pair<Integer, String>(
- result.getExitValue(),
- result.outputUTF8()
- );
-
- } catch (Exception exception) {
-
- // quack, quack, do nothing, just
- // return a default error code
-
- // if something goes wrong, the default
- // error branch returns an exit status of
- // -99 and an empty string
- return new Pair<Integer, String>(-99, "");
-
- }
- }
-
-}
diff --git a/support/arara/source/src/main/java/com/github/cereda/arara/utils/VelocityUtils.java b/support/arara/source/src/main/java/com/github/cereda/arara/utils/VelocityUtils.java
deleted file mode 100644
index 3f94adc909..0000000000
--- a/support/arara/source/src/main/java/com/github/cereda/arara/utils/VelocityUtils.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/**
- * Arara, the cool TeX automation tool
- * Copyright (c) 2012 -- 2019, Paulo Roberto Massa Cereda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the project's author nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
- * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.github.cereda.arara.utils;
-
-import com.github.cereda.arara.controller.LanguageController;
-import com.github.cereda.arara.model.AraraException;
-import com.github.cereda.arara.model.Messages;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.util.Map;
-import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.exception.MethodInvocationException;
-import org.apache.velocity.exception.ParseErrorException;
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.runtime.RuntimeConstants;
-
-/**
- * Implements the template merging from Apache Velocity.
- * @author Paulo Roberto Massa Cereda
- * @version 4.0
- * @since 4.0
- */
-public class VelocityUtils {
-
- // the language controller
- private static final LanguageController messages =
- LanguageController.getInstance();
-
- /**
- * Merges the provided template with the context map and writes the result
- * in an output file. The operation relies on the Apache Velocity project.
- * @param input The input file.
- * @param output The output file.
- * @param map The context map.
- * @throws AraraException Something terribly wrong happened, to be caught
- * in the higher levels.
- */
- public static void mergeVelocityTemplate(File input, File output,
- Map<String, Object> map) throws AraraException {
-
- // let us try
- try {
-
- // create the template engine instance
- VelocityEngine engine = new VelocityEngine();
-
- // use the resource path trick: set the default
- // location to the input file's parent directory,
- // so our file is easily located
- engine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,
- input.getCanonicalFile().getParent());
-
- // set the logging feature of Apache Velocity to
- // register the occurrences in a null provider
- // (we do not want unnecessary verbose output)
- engine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
- "org.apache.velocity.runtime.log.NullLogSystem");
-
- // init the engine with the
- // provided settings
- engine.init();
-
- // create a context for Apache Velocity,
- // based on the provided map
- VelocityContext context = new VelocityContext(map);
-
- // get the template from the engine and
- // read it as an UTF-8 file
- Template template = engine.getTemplate(input.getName(), "UTF-8");
-
- // create an output stream from
- // the file output reference
- FileOutputStream stream = new FileOutputStream(output);
-
- // create a writer based on the
- // previously created stream
- Writer writer = new OutputStreamWriter(stream, "UTF-8");
-
- // merge the context map with the
- // template file and write the result
- // to the output stream writer
- template.merge(context, writer);
-
- // close both writer
- // and output stream
- writer.close();
- stream.close();
-
- } catch(ResourceNotFoundException rnfexception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_VELOCITY_FILE_NOT_FOUND
- ),
- rnfexception
- );
- } catch(ParseErrorException peexception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_VELOCITY_PARSE_EXCEPTION
- ),
- peexception
- );
- } catch(MethodInvocationException miexception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_VELOCITY_METHOD_INVOCATION_EXCEPTION
- ),
- miexception
- );
- } catch (IOException ioexception) {
- throw new AraraException(
- messages.getMessage(
- Messages.ERROR_VELOCITY_FILE_NOT_FOUND
- ),
- ioexception
- );
- }
-
- }
-
-}