Search in sources :

Example 21 with IFileSystemOperations

use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method replaceTextInFile.

/**
     * Replaces specific text in file. Supports regular expressions
     *
     * @param filePath the file to work with
     * @param searchText the text to replace
     * @param newText the replacement text
     * @param isRegex if the searched text is a regular expression
     */
@PublicAtsApi
public void replaceTextInFile(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, @Validate(name = "searchText", type = ValidationType.STRING_NOT_EMPTY) String searchText, @Validate(name = "newText", type = ValidationType.NONE) String newText, @Validate(name = "isRegex", type = ValidationType.NONE) boolean isRegex) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, searchText, newText, isRegex });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.replaceTextInFile(filePath, searchText, newText, isRegex);
    // log the result of the operation
    log.info("Successfully replaced text '" + searchText + "' with '" + newText + "' in file '" + filePath + "'" + getHostDescriptionSuffix());
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 22 with IFileSystemOperations

use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method fileGrep.

/**
     * Returns file lines that match some regular expression. <br />
     * <em>Note</em> that search pattern should match whole line, i.e. it should
     * start/end with some wildcard matcher if you search for text somewhere in the line.
     *
     * @param filePath the file to work with
     * @param searchPattern the search pattern
     * @param isSimpleMode
     * <blockquote>
     * true - expects match using only these (DOS/Win-style) special characters:
     *      <blockquote>
     *      '*' character - matches a sequence of any characters<br/>
     *      '?' character - matches one single character
     *      </blockquote>
     * false - supports any Java regular expression
     * </blockquote>
     * <em>Example:</em>
     * <ul>
     *   <li>for simple mode (true): '*Hello*' matches lines like ' Hello colleagues,' and 'Hello'</li>
     *   <li>for not simple mode: '.*Hello.*' matches lines ' Hello colleagues,' and 'Hello'</li>
     * </ul>
     * @return the matched lines
     *
     */
@PublicAtsApi
public String[] fileGrep(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, @Validate(name = "searchPattern", type = ValidationType.STRING_NOT_EMPTY) String searchPattern, @Validate(name = "isSimpleMode", type = ValidationType.NONE) boolean isSimpleMode) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, searchPattern, isSimpleMode });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    return operations.fileGrep(filePath, searchPattern, isSimpleMode);
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 23 with IFileSystemOperations

use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method doesFileExist.

/**
     * Check if a file exists
     *
     * @param filePath the target file path
     * @return <code>true</code> if the file exists and <code>false</code> if it doesn't
     */
@PublicAtsApi
public boolean doesFileExist(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    return operations.doesFileExist(filePath);
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 24 with IFileSystemOperations

use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method getFileUniqueId.

/**
     * @param filePath the file to work with
     * @return unique id formed by the file name, last modification time, GID and UID values,
     * separated with dots
     */
public String getFileUniqueId(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    return operations.getFileUniqueId(filePath);
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator)

Example 25 with IFileSystemOperations

use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method getFilePermissions.

/**
     * Get the permissions ( in octal format ) of a file or directory. E.g. 0644 or 1750 or 7605
     *
     * @param filePath the file to work with
     * @return the permissions
     */
@PublicAtsApi
public String getFilePermissions(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath });
    String result = null;
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    result = operations.getFilePermissions(filePath);
    // log the result of the operation
    log.debug("Successfully got the permissions of " + filePath + getHostDescriptionSuffix());
    return result;
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

IFileSystemOperations (com.axway.ats.core.filesystem.model.IFileSystemOperations)46 Validator (com.axway.ats.core.validation.Validator)45 PublicAtsApi (com.axway.ats.common.PublicAtsApi)44 LocalFileSystemOperations (com.axway.ats.core.filesystem.LocalFileSystemOperations)6 FileMatchInfo (com.axway.ats.common.filesystem.FileMatchInfo)1 IProcessExecutor (com.axway.ats.core.process.model.IProcessExecutor)1 MobileOperationException (com.axway.ats.uiengine.exceptions.MobileOperationException)1 NotSupportedOperationException (com.axway.ats.uiengine.exceptions.NotSupportedOperationException)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1