| 1 |  |  | 
            
  
    | 2 |  |  | 
            
  
    | 3 |  |  | 
            
  
    | 4 |  |  | 
            
  
    | 5 |  |  | 
            
  
    | 6 |  |  | 
            
  
    | 7 |  |  | 
            
  
    | 8 |  |  | 
            
  
    | 9 |  |  | 
            
  
    | 10 |  |  | 
            
  
    | 11 |  |  | 
            
  
    | 12 |  |  | 
            
  
    | 13 |  |  | 
            
  
    | 14 |  |  | 
            
  
    | 15 |  |  | 
            
  
    | 16 |  | package org.kuali.student.common.util; | 
            
  
    | 17 |  |  | 
            
  
    | 18 |  | import java.util.HashSet; | 
            
  
    | 19 |  | import java.util.Properties; | 
            
  
    | 20 |  |  | 
            
  
    | 21 |  | import org.springframework.beans.BeansException; | 
            
  
    | 22 |  | import org.springframework.beans.factory.BeanDefinitionStoreException; | 
            
  
    | 23 |  | import org.springframework.beans.factory.BeanFactory; | 
            
  
    | 24 |  | import org.springframework.beans.factory.InitializingBean; | 
            
  
    | 25 |  | import org.springframework.beans.factory.config.BeanDefinition; | 
            
  
    | 26 |  | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | 
            
  
    | 27 |  | import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; | 
            
  
    | 28 |  | import org.springframework.core.io.DefaultResourceLoader; | 
            
  
    | 29 |  | import org.springframework.core.io.Resource; | 
            
  
    | 30 |  | import org.springframework.util.StringValueResolver; | 
            
  
    | 31 |  |  | 
               
        |  |  | 
           
           |  | 68.5% | Uncovered Elements: 23 (73) | Complexity: 20 | Complexity Density: 0.39 |  | 
  
  
    | 32 |  | public class ModPropertyPlaceholderConfigurer extends | 
            
  
    | 33 |  | PropertyPlaceholderConfigurer implements InitializingBean  { | 
            
  
    | 34 |  |  | 
            
  
    | 35 |  | private String customConfigSystemProperty; | 
            
  
    | 36 |  | private String customConfigFileLocation; | 
            
  
    | 37 |  | private Resource[] locations; | 
            
  
    | 38 |  |  | 
            
  
    | 39 |  | private String beanName; | 
            
  
    | 40 |  | private BeanFactory beanFactory; | 
            
  
    | 41 |  | private String nullValue; | 
            
  
    | 42 |  |  | 
            
  
    | 43 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 44 | 0 |  public String getCustomConfigSystemProperty() {... | 
            
  
    | 45 | 0 | return customConfigSystemProperty; | 
            
  
    | 46 |  | } | 
            
  
    | 47 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 48 | 21 |  public void setCustomConfigSystemProperty(String customConfigSystemProperty) {... | 
            
  
    | 49 | 21 | this.customConfigSystemProperty = customConfigSystemProperty; | 
            
  
    | 50 |  | } | 
            
  
    | 51 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (2) | Complexity: 1 | Complexity Density: 0.5 |  | 
  
  
    | 52 | 22 |  @Override... | 
            
  
    | 53 |  | public void setLocations(Resource[] locations) { | 
            
  
    | 54 | 22 | this.locations=locations; | 
            
  
    | 55 | 22 | super.setLocations(locations); | 
            
  
    | 56 |  |  | 
            
  
    | 57 |  | } | 
            
  
    | 58 |  |  | 
               
        |  |  | 
           
           |  | 59.5% | Uncovered Elements: 15 (37) | Complexity: 7 | Complexity Density: 0.24 |  | 
  
  
    | 59 | 22 |  @Override... | 
            
  
    | 60 |  | public void afterPropertiesSet() throws Exception { | 
            
  
    | 61 | 22 | if(customConfigSystemProperty!=null){ | 
            
  
    | 62 | 21 | String customConfigLocation = System.getProperty(customConfigSystemProperty); | 
            
  
    | 63 | 21 | try{ | 
            
  
    | 64 | 21 | customConfigLocation = this.parseStringValue(customConfigLocation, System.getProperties(), new HashSet<String>()); | 
            
  
    | 65 |  |  | 
            
  
    | 66 | 0 | Resource customConfigResource = new DefaultResourceLoader().getResource(customConfigLocation); | 
            
  
    | 67 | 0 | if(customConfigResource.exists()){ | 
            
  
    | 68 | 0 | Resource[] finalLocations = new Resource[locations.length+1]; | 
            
  
    | 69 | 0 | int i=0; | 
            
  
    | 70 | 0 | for(Resource resource:locations){ | 
            
  
    | 71 | 0 | finalLocations[i]=resource; | 
            
  
    | 72 | 0 | i++; | 
            
  
    | 73 |  | } | 
            
  
    | 74 | 0 | finalLocations[i]=customConfigResource; | 
            
  
    | 75 |  |  | 
            
  
    | 76 | 0 | super.setLocations(finalLocations); | 
            
  
    | 77 |  | }else{ | 
            
  
    | 78 | 0 | logger.warn("File does not exist:"+customConfigLocation); | 
            
  
    | 79 |  | } | 
            
  
    | 80 |  | }catch(Exception e){ | 
            
  
    | 81 | 21 | logger.warn("Could not load custom properties from property:"+customConfigSystemProperty+" location:"+customConfigLocation); | 
            
  
    | 82 |  | } | 
            
  
    | 83 |  | } | 
            
  
    | 84 | 22 | if(customConfigFileLocation!=null){ | 
            
  
    | 85 | 1 | String location = this.parseStringValue(customConfigFileLocation, System.getProperties(), new HashSet<String>()); | 
            
  
    | 86 | 1 | try{ | 
            
  
    | 87 | 1 | Resource customConfigResource = new DefaultResourceLoader().getResource(location); | 
            
  
    | 88 |  |  | 
            
  
    | 89 | 1 | if(customConfigResource.exists()){ | 
            
  
    | 90 | 1 | Resource[] finalLocations = new Resource[locations.length+1]; | 
            
  
    | 91 | 1 | int i=0; | 
            
  
    | 92 | 1 | for(Resource resource:locations){ | 
            
  
    | 93 | 1 | finalLocations[i] = resource; | 
            
  
    | 94 | 1 | i++; | 
            
  
    | 95 |  | } | 
            
  
    | 96 | 1 | finalLocations[i] = customConfigResource; | 
            
  
    | 97 |  |  | 
            
  
    | 98 | 1 | super.setLocations(finalLocations); | 
            
  
    | 99 |  | }else{ | 
            
  
    | 100 | 0 | logger.warn("File does not exist:"+location); | 
            
  
    | 101 |  | } | 
            
  
    | 102 |  | }catch(Exception e){ | 
            
  
    | 103 | 0 | logger.warn("Could not load custom properties from file:"+location); | 
            
  
    | 104 |  | } | 
            
  
    | 105 |  | } | 
            
  
    | 106 |  | } | 
            
  
    | 107 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (2) | Complexity: 1 | Complexity Density: 0.5 |  | 
  
  
    | 108 | 22 |  @Override... | 
            
  
    | 109 |  | public void setBeanName(String beanName) { | 
            
  
    | 110 | 22 | this.beanName = beanName; | 
            
  
    | 111 | 22 | super.setBeanName(beanName); | 
            
  
    | 112 |  | } | 
            
  
    | 113 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (2) | Complexity: 1 | Complexity Density: 0.5 |  | 
  
  
    | 114 | 22 |  @Override... | 
            
  
    | 115 |  | public void setBeanFactory(BeanFactory beanFactory) { | 
            
  
    | 116 | 22 | this.beanFactory = beanFactory; | 
            
  
    | 117 | 22 | super.setBeanFactory(beanFactory); | 
            
  
    | 118 |  | } | 
            
  
    | 119 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 2 (2) | Complexity: 1 | Complexity Density: 0.5 |  | 
  
  
    | 120 | 0 |  @Override... | 
            
  
    | 121 |  | public void setNullValue(String nullValue) { | 
            
  
    | 122 | 0 | this.nullValue = nullValue; | 
            
  
    | 123 | 0 | super.setNullValue(nullValue); | 
            
  
    | 124 |  | } | 
            
  
    | 125 |  |  | 
               
        |  |  | 
           
           |  | 92.9% | Uncovered Elements: 1 (14) | Complexity: 5 | Complexity Density: 0.5 |  | 
  
  
    | 126 | 22 |  @Override... | 
            
  
    | 127 |  | protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) | 
            
  
    | 128 |  | throws BeansException { | 
            
  
    | 129 |  |  | 
            
  
    | 130 | 22 | StringValueResolver valueResolver = new PlaceholderResolvingStringValueResolver(props); | 
            
  
    | 131 | 22 | ModBeanDefinitionVisitor visitor = new ModBeanDefinitionVisitor(valueResolver); | 
            
  
    | 132 |  |  | 
            
  
    | 133 | 22 | String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames(); | 
            
  
    | 134 | 819 | for (int i = 0; i < beanNames.length; i++) { | 
            
  
    | 135 |  |  | 
            
  
    | 136 |  |  | 
            
  
    | 137 | 797 | if (!(beanNames[i].equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) { | 
            
  
    | 138 | 775 | BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(beanNames[i]); | 
            
  
    | 139 | 775 | try { | 
            
  
    | 140 | 775 | visitor.visitBeanDefinition(bd); | 
            
  
    | 141 |  | } | 
            
  
    | 142 |  | catch (BeanDefinitionStoreException ex) { | 
            
  
    | 143 | 0 | throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i], ex.getMessage()); | 
            
  
    | 144 |  | } | 
            
  
    | 145 |  | } | 
            
  
    | 146 |  | } | 
            
  
    | 147 |  |  | 
            
  
    | 148 |  |  | 
            
  
    | 149 | 22 | beanFactoryToProcess.resolveAliases(valueResolver); | 
            
  
    | 150 |  | } | 
            
  
    | 151 |  |  | 
            
  
    | 152 |  |  | 
            
  
    | 153 |  |  | 
            
  
    | 154 |  |  | 
            
  
    | 155 |  |  | 
            
  
    | 156 |  |  | 
               
        |  |  | 
           
           |  | 94.1% | Uncovered Elements: 1 (17) | Complexity: 5 | Complexity Density: 0.5 |  | 
  
  
    | 157 |  | public class PlaceholderResolvingStringValueResolver implements StringValueResolver { | 
            
  
    | 158 |  |  | 
            
  
    | 159 |  | private final Properties props; | 
            
  
    | 160 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 161 | 22 |  public PlaceholderResolvingStringValueResolver(Properties props) {... | 
            
  
    | 162 | 22 | this.props = props; | 
            
  
    | 163 |  | } | 
            
  
    | 164 |  |  | 
               
        |  |  | 
           
           |  | 75% | Uncovered Elements: 1 (4) | Complexity: 2 | Complexity Density: 1 |  | 
  
  
    | 165 | 3621 |  public String resolveStringValue(String strVal) throws BeansException {... | 
            
  
    | 166 | 3621 | String value = parseStringValue(strVal, this.props, new HashSet<String>()); | 
            
  
    | 167 | 3621 | return (value.equals(nullValue) ? null : value); | 
            
  
    | 168 |  | } | 
            
  
    | 169 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (9) | Complexity: 2 | Complexity Density: 0.29 |  | 
  
  
    | 170 | 57 |  public Properties resolvePropertyValue(String strVal){... | 
            
  
    | 171 | 57 | Properties prefixedProps = new Properties(); | 
            
  
    | 172 |  |  | 
            
  
    | 173 | 57 | for(Object key:props.keySet()){ | 
            
  
    | 174 | 3021 | String keyStr = (String)key; | 
            
  
    | 175 | 3021 | if(keyStr.startsWith(strVal)){ | 
            
  
    | 176 | 494 | String newKeyStr = keyStr.substring(strVal.length()+1); | 
            
  
    | 177 | 494 | prefixedProps.put(newKeyStr, resolveStringValue((String)props.get(key))); | 
            
  
    | 178 |  | } | 
            
  
    | 179 |  | } | 
            
  
    | 180 |  |  | 
            
  
    | 181 | 57 | return prefixedProps; | 
            
  
    | 182 |  | } | 
            
  
    | 183 |  |  | 
            
  
    | 184 |  | } | 
            
  
    | 185 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 186 | 0 |  public String getCustomConfigFileLocation() {... | 
            
  
    | 187 | 0 | return customConfigFileLocation; | 
            
  
    | 188 |  | } | 
            
  
    | 189 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 190 | 1 |  public void setCustomConfigFileLocation(String customConfigFileLocation) {... | 
            
  
    | 191 | 1 | this.customConfigFileLocation = customConfigFileLocation; | 
            
  
    | 192 |  | } | 
            
  
    | 193 |  | } |