示例#1
0
        private FzFileAndComponents FindComponentNamesReferencedInFile(FzServiceComponent serviceComponent)
        {
            var fileAndComponents = new FzFileAndComponents {
                File = serviceComponent.File
            };
            var flatFileContents = serviceComponent.File.Content.Replace("\r", "").Replace("\n", "").Replace("\t", "");

            // Find any @Resource component
            // @Resource(name = "retrieveServiceDefinitionsService")
            var resourceComponentMatches = Regex.Matches(flatFileContents, @"@Resource\(name = ""(\w+)");

            foreach (Match resourceComponent in resourceComponentMatches)
            {
                if ((resourceComponent.Value.Contains("Service") ||
                     resourceComponent.Value.Contains("Step")) &&
                    !serviceComponent.File.FileName.Equals("MitStepConfiguration.java")
                    )
                {
                    fileAndComponents.ComponentNames.Add(resourceComponent.Value.Substring(18));
                }
            }

            // Find any inherited / extends component
            var resourceInheritedMatches = Regex.Matches(serviceComponent.File.Content, @"extends (\w+)");

            foreach (Match resourceInherited in resourceInheritedMatches)
            {
                if (resourceInherited.Value.Contains("Service") ||
                    resourceInherited.Value.Contains("Step"))
                {
                    fileAndComponents.ComponentNames.Add(resourceInherited.Value.Substring(8));
                }
            }

            // Special case when inside the big step configuration file
            if (serviceComponent.File.FileName.Equals("MitStepConfiguration.java"))
            {
            }

            return(fileAndComponents);
        }
示例#2
0
        public static FzFileAndComponents ExtractBeanResource(string componentName, FzFile file)
        {
            var beanMethodMatch = Regex.Match(file.Content, @"@Bean(\s+)public (\S+) " + componentName + @"\(\)(\s+){(\s+)return new (\S+)\((.*)");

            if (!beanMethodMatch.Success)
            {
                return(null);
            }

            // Get all resources
            var beanResourceNamesAndVariableNames = new Dictionary <string, string>();
            var beanResourceMatches = Regex.Matches(file.Content, @"@Resource(.*)(\s+)(.*)");

            foreach (Match match in beanResourceMatches)
            {
                var resourceName     = Regex.Match(match.Value, @"""(\w+)""");
                var resourceVariable = Regex.Match(match.Value, @"(\w+);");

                beanResourceNamesAndVariableNames.Add(resourceName.Value, resourceVariable.Value.Substring(0, resourceVariable.Value.Length - 1));
            }

            // See if a resource matches from the method match
            foreach (var resourceAndVariableName in beanResourceNamesAndVariableNames)
            {
                if (beanMethodMatch.Value.Contains(resourceAndVariableName.Value))
                {
                    var newFileAndComponent = new FzFileAndComponents {
                        File = file
                    };
                    newFileAndComponent.ComponentNames.Add(resourceAndVariableName.Key);
                    return(newFileAndComponent);
                }
            }

            return(null);
        }
示例#3
0
        private List <FzFileAndComponents> FindComponentFilesReferencedByName(FzFileAndComponents fileAndComponents, FzServiceComponent serviceComponent, List <FzFile> flatFileCache)
        {
            var matchingSubComponentFiles = new List <FzFileAndComponents>();

            foreach (var subComponentName in fileAndComponents.ComponentNames)
            {
                foreach (var file in flatFileCache)
                {
                    // Ignore certain files
                    if (file.FileName.Equals("MitBaseStep.java") ||
                        file.FileName.Equals("MitBaseInnerServiceStep.java") ||
                        file.FileName.Equals("MitBaseCompoundStep.java") ||
                        file.FileName.Equals("MitBaseStepDecorator.java") ||
                        file.FileName.Equals("MitBasicServiceRecorderProxy.java") ||
                        file.FileName.Equals("MitNestedTransformerHttpJsonServiceAgentService.java") ||
                        file.FileName.Equals("MitBasicNestedTransformerHttpServiceAgentService.java") ||
                        file.FileName.Equals("MitBasicStepStateMachine.java") ||
                        file.FileName.Equals("MitBaseSimpleCachedStep.java") ||
                        file.FileName.Equals("MitNestedTransformerServiceAgentService.java"))
                    {
                        continue;
                    }

                    var flatFileContent = file.Content.Replace("\r", "").Replace("\n", "").Replace("\t", "");

                    // Find any @Component component
                    var componentComponentMatch = Regex.Match(file.Content, @"@Component(.*)""" + subComponentName + @"""");

                    if (componentComponentMatch.Success)
                    {
                        var matchedFileAndComponent = new FzFileAndComponents {
                            File = file
                        };

                        matchedFileAndComponent.ComponentNames.Add(subComponentName);
                        matchingSubComponentFiles.Add(matchedFileAndComponent);
                    }

                    // Find a @Component from a @Bean resource
                    var beanComponentMatch = Regex.Match(file.Content, @"@Component(.*)""" + serviceComponent.PreviousReferencedComponent + @"""");

                    if (beanComponentMatch.Success)
                    {
                        var matchedFileAndComponent = new FzFileAndComponents {
                            File = file
                        };

                        matchedFileAndComponent.ComponentNames.Add(subComponentName);
                        matchingSubComponentFiles.Add(matchedFileAndComponent);
                    }

                    // Find any base class used as a component
                    var baseClassComponentMatch = Regex.Match(flatFileContent, @"class " + subComponentName);

                    if (baseClassComponentMatch.Success)
                    {
                        var baseClassMatchedFileAndComponent = new FzFileAndComponents {
                            File = file
                        };

                        baseClassMatchedFileAndComponent.ComponentNames.Add(subComponentName);
                        matchingSubComponentFiles.Add(baseClassMatchedFileAndComponent);
                    }

                    // Find any @Bean match where the component is named after a method
                    var beanResource = BeanFinder.ExtractBeanResource(subComponentName, file);

                    if (beanResource != null)
                    {
                        matchingSubComponentFiles.Add(beanResource);
                    }


                    //var beanMethodComponentMatch = Regex.Match(file.Content, @"@Bean(\s+)public (\S+) " + subComponentName + @"\(\)(\s+){(\s+)return new (\S+)\((\w+)");

                    //if (beanMethodComponentMatch.Success)
                    //{
                    //    // Stop if step has caching
                    //    if (subComponentName.ToUpper().Contains("CACHING"))
                    //        continue;

                    //    // Get bean variable name
                    //    var beanVariableNameMatch = Regex.Match(beanMethodComponentMatch.Value, @"\((\w+)");
                    //    var beanVariableName = beanVariableNameMatch.Value.Substring(1);

                    //    // Get bean variable's corresponding resource name
                    //    var beanResourceDefinitionMatch = Regex.Match(file.Content, @"@Resource\(name = ""(\w+)""\)(\s+)private (\S+) " + beanVariableName);
                    //    var beanResourceNameMatch = Regex.Match(beanResourceDefinitionMatch.Value, @"""(\w+)""");
                    //    var beanResourceName = beanResourceNameMatch.Value.Substring(1, beanResourceNameMatch.Length - 2);

                    //    var beanClassMatchedFileAndComponent = new FzFileAndComponents { File = file };
                    //    beanClassMatchedFileAndComponent.ComponentNames.Add(beanResourceName);
                    //    matchingSubComponentFiles.Add(beanClassMatchedFileAndComponent);
                    //}



                    // Find any @Bean match where the component name is a method
                    //if (file.FileName.Equals("MitEmailConfirmationStepConfiguration.java") && subComponentName.Contains("Email"))
                    //{
                    //    var a = 1;
                    //}

                    //var beanMethodComponentMatch = Regex.Match(flatFileContent, @"@Beanpublic (\S*) " + subComponentName + @"\(\) {return new (\S*)\((\w+)(,|\))");

                    //if (beanMethodComponentMatch.Success)
                    //{
                    //    // Figure out the @Bean's resource variable name
                    //    var beanVariableName = Regex.Match(beanMethodComponentMatch.Value, @"(\w+)(,|\))");
                    //    var variableName = beanVariableName.Value.Substring(0, beanVariableName.Length - 1);

                    //    // Figure out the @Bean's resource name
                    //    var wholeResourceStatment = Regex.Match(flatFileContent, @"@Resource\(name = ""(\w+)""\)(\s*)private (\S*) " + variableName + ";");
                    //    var rawResourceName = Regex.Match(wholeResourceStatment.Value, @"""(\w+)""");

                    //    if (!wholeResourceStatment.Success)
                    //    {
                    //        continue;
                    //    }

                    //    var beanResourceName = rawResourceName.Value.Substring(1, rawResourceName.Value.Length - 2);

                    //    // Add matching component
                    //    var beanMethodMatchedFileAndComponent = new FzFileAndComponents { File = file };

                    //    beanMethodMatchedFileAndComponent.ComponentNames.Add(beanResourceName);
                    //    matchingSubComponentFiles.Add(beanMethodMatchedFileAndComponent);
                    //}
                }
            }

            return(matchingSubComponentFiles);
        }