Coverage Report - org.mule.module.launcher.descriptor.PropertiesDescriptorParser
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertiesDescriptorParser
0%
0/23
0%
0/8
0
 
 1  
 /*
 2  
  * $Id: PropertiesDescriptorParser.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.module.launcher.descriptor;
 12  
 
 13  
 import org.mule.util.PropertiesUtils;
 14  
 import org.mule.util.StringUtils;
 15  
 
 16  
 import java.io.File;
 17  
 import java.io.FileInputStream;
 18  
 import java.io.IOException;
 19  
 import java.util.HashMap;
 20  
 import java.util.Map;
 21  
 import java.util.Properties;
 22  
 
 23  
 import org.apache.commons.lang.BooleanUtils;
 24  
 
 25  
 /**
 26  
  *
 27  
  */
 28  0
 public class PropertiesDescriptorParser implements DescriptorParser
 29  
 {
 30  
 
 31  
     public ApplicationDescriptor parse(File descriptor) throws IOException
 32  
     {
 33  0
         final Properties p = new Properties();
 34  0
         p.load(new FileInputStream(descriptor));
 35  
 
 36  0
         ApplicationDescriptor d = new ApplicationDescriptor();
 37  0
         d.setEncoding(p.getProperty("encoding"));
 38  0
         d.setConfigurationBuilder(p.getProperty("config.builder"));
 39  0
         d.setDomain(p.getProperty("domain"));
 40  
 
 41  
         // get a ref to an optional app props file (right next to the descriptor)
 42  0
         final File appPropsFile = new File(descriptor.getParent(), "mule-app.properties");
 43  0
         if (appPropsFile.exists() && appPropsFile.canRead())
 44  
         {
 45  0
             final Properties props = PropertiesUtils.loadProperties(appPropsFile.toURI().toURL());
 46  
             // ugh, no straightforward way to convert to a map
 47  0
             Map<String, String> m = new HashMap<String, String>(props.size());
 48  0
             for (String key : m.keySet())
 49  
             {
 50  0
                 m.put(key, props.getProperty(key));
 51  
             }
 52  0
             d.setAppProperties(m);
 53  
         }
 54  
         
 55  
         // supports true (case insensitive), yes, on as positive values
 56  0
         d.setParentFirstClassLoader(BooleanUtils.toBoolean(p.getProperty("classloader.parentFirst", Boolean.TRUE.toString())));
 57  
 
 58  0
         final String resProps = p.getProperty("config.resources");
 59  
         String[] urls;
 60  0
         if (StringUtils.isBlank(resProps))
 61  
         {
 62  0
             urls = new String[] {ApplicationDescriptor.DEFAULT_CONFIGURATION_RESOURCE};
 63  
         }
 64  
         else
 65  
         {
 66  0
             urls = resProps.split(",");
 67  
         }
 68  0
         d.setConfigResources(urls);
 69  
 
 70  
         // supports true (case insensitive), yes, on as positive values
 71  0
         d.setRedeploymentEnabled(BooleanUtils.toBoolean(p.getProperty("redeployment.enabled", Boolean.TRUE.toString())));
 72  
 
 73  0
         return d;
 74  
     }
 75  
 
 76  
     public String getSupportedFormat()
 77  
     {
 78  0
         return "properties";
 79  
     }
 80  
 }