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());
}
}
}
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;
}
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());
}
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());
}
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());
}
Aggregations