Search in sources :

Example 1 with Pattern

use of java.util.regex.Pattern in project camel by apache.

the class MarkerFileExclusiveReadLockStrategy method prepareOnStartup.

@Override
public void prepareOnStartup(GenericFileOperations<File> operations, GenericFileEndpoint<File> endpoint) {
    if (deleteOrphanLockFiles) {
        String dir = endpoint.getConfiguration().getDirectory();
        File file = new File(dir);
        LOG.debug("Prepare on startup by deleting orphaned lock files from: {}", dir);
        Pattern excludePattern = endpoint.getExcludePattern();
        Pattern includePattern = endpoint.getIncludePattern();
        String endpointPath = endpoint.getConfiguration().getDirectory();
        StopWatch watch = new StopWatch();
        deleteLockFiles(file, endpoint.isRecursive(), endpointPath, endpoint.getFilter(), endpoint.getAntFilter(), excludePattern, includePattern);
        // log anything that takes more than a second
        if (watch.taken() > 1000) {
            LOG.info("Prepared on startup by deleting orphaned lock files from: {} took {} millis to complete.", dir, watch.taken());
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) GenericFile(org.apache.camel.component.file.GenericFile) File(java.io.File) StopWatch(org.apache.camel.util.StopWatch)

Example 2 with Pattern

use of java.util.regex.Pattern in project camel by apache.

the class ArgumentSubstitutionParser method processResults.

@Override
public List<ApiMethodModel> processResults(List<ApiMethodModel> parseResult) {
    final List<ApiMethodModel> result = new ArrayList<ApiMethodModel>();
    for (ApiMethodModel model : parseResult) {
        // look for method name matches
        for (Map.Entry<Pattern, Map<Pattern, List<NameReplacement>>> methodEntry : methodMap.entrySet()) {
            // match the whole method name
            if (methodEntry.getKey().matcher(model.getName()).matches()) {
                // look for arg name matches
                final List<ApiMethodArg> updatedArguments = new ArrayList<ApiMethodArg>();
                final Map<Pattern, List<NameReplacement>> argMap = methodEntry.getValue();
                for (ApiMethodArg argument : model.getArguments()) {
                    final Class<?> argType = argument.getType();
                    final String typeArgs = argument.getTypeArgs();
                    final String argTypeName = argType.getCanonicalName();
                    for (Map.Entry<Pattern, List<NameReplacement>> argEntry : argMap.entrySet()) {
                        final Matcher matcher = argEntry.getKey().matcher(argument.getName());
                        // match argument name substring
                        if (matcher.find()) {
                            final List<NameReplacement> adapters = argEntry.getValue();
                            for (NameReplacement adapter : adapters) {
                                if (adapter.typePattern == null) {
                                    // no type pattern
                                    final String newName = getJavaArgName(matcher.replaceAll(adapter.replacement));
                                    argument = new ApiMethodArg(newName, argType, typeArgs);
                                } else {
                                    final Matcher typeMatcher = adapter.typePattern.matcher(argTypeName);
                                    if (typeMatcher.find()) {
                                        if (!adapter.replaceWithType) {
                                            // replace argument name
                                            final String newName = getJavaArgName(matcher.replaceAll(adapter.replacement));
                                            argument = new ApiMethodArg(newName, argType, typeArgs);
                                        } else {
                                            // replace name with argument type name
                                            final String newName = getJavaArgName(typeMatcher.replaceAll(adapter.replacement));
                                            argument = new ApiMethodArg(newName, argType, typeArgs);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    updatedArguments.add(argument);
                }
                model = new ApiMethodModel(model.getUniqueName(), model.getName(), model.getResultType(), updatedArguments, model.getMethod());
            }
        }
        result.add(model);
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with Pattern

use of java.util.regex.Pattern in project camel by apache.

the class FilterParametersTest method testPropertyPlaceholders.

public void testPropertyPlaceholders() throws Exception {
    CamelContext context = this.createPropertiesPlaceholderAwareContext();
    FilterParameters filter = new FilterParameters();
    filter.setCamelContext(context);
    filter.getInclude().add("{{filterParameters.include}}");
    filter.getExclude().add("{{filterParameters.exclude}}");
    FilterParameters.Patterns patterns = filter.getPatterns();
    List<Pattern> includes = patterns.getIncludes();
    List<Pattern> excludes = patterns.getExcludes();
    assertNotNull(includes);
    assertNotNull(excludes);
    assertEquals(1, includes.size());
    assertEquals(1, excludes.size());
    Matcher includeMatcher = includes.get(0).matcher("include");
    assertTrue(includeMatcher.matches());
    Matcher excludeMatcher = excludes.get(0).matcher("exclude");
    assertTrue(excludeMatcher.matches());
}
Also used : CamelContext(org.apache.camel.CamelContext) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Example 4 with Pattern

use of java.util.regex.Pattern in project camel by apache.

the class FilterParametersTest method testGetExcludePatterns.

public void testGetExcludePatterns() {
    FilterParameters filter = new FilterParameters();
    filter.getExclude().add("asdfsadfsadfsadf");
    List<Pattern> includes = filter.getIncludePatterns();
    List<Pattern> excludes = filter.getExcludePatterns();
    assertNotNull(excludes);
    assertEquals(1, excludes.size());
    assertNotNull(includes);
    assertEquals(0, includes.size());
    assertNotNull(excludes.get(0));
    Matcher matcher = excludes.get(0).matcher("asdfsadfsadfsadf");
    assertTrue(matcher.matches());
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Example 5 with Pattern

use of java.util.regex.Pattern in project camel by apache.

the class FilterParametersTest method testGetIncludePatterns.

public void testGetIncludePatterns() {
    FilterParameters filter = new FilterParameters();
    filter.getInclude().add("asdfsadfsadfsadf");
    List<Pattern> includes = filter.getIncludePatterns();
    List<Pattern> excludes = filter.getExcludePatterns();
    assertNotNull(includes);
    assertEquals(1, includes.size());
    assertNotNull(excludes);
    assertEquals(0, excludes.size());
    assertNotNull(includes.get(0));
    Matcher matcher = includes.get(0).matcher("asdfsadfsadfsadf");
    assertTrue(matcher.matches());
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Aggregations

Pattern (java.util.regex.Pattern)2745 Matcher (java.util.regex.Matcher)1806 ArrayList (java.util.ArrayList)334 Test (org.junit.Test)209 IOException (java.io.IOException)206 File (java.io.File)172 HashMap (java.util.HashMap)144 Field (java.lang.reflect.Field)118 BufferedReader (java.io.BufferedReader)108 Map (java.util.Map)97 PatternSyntaxException (java.util.regex.PatternSyntaxException)97 List (java.util.List)81 HashSet (java.util.HashSet)69 InputStreamReader (java.io.InputStreamReader)59 FileInputStream (java.io.FileInputStream)40 InputStream (java.io.InputStream)39 FileReader (java.io.FileReader)36 SmallTest (android.test.suitebuilder.annotation.SmallTest)31 URL (java.net.URL)29 LinkedHashMap (java.util.LinkedHashMap)28