Coverage Report - org.jtheque.core.utils.SystemProperty
 
Classes in this File Line Coverage Branch Coverage Complexity
SystemProperty
0 %
0/11
N/A
1.25
SystemProperty$1
0 %
0/6
0 %
0/2
1.25
SystemProperty$2
0 %
0/5
0 %
0/2
1.25
SystemProperty$3
0 %
0/2
N/A
1.25
SystemProperty$4
0 %
0/2
N/A
1.25
 
 1  
 package org.jtheque.core.utils;
 2  
 
 3  
 import org.jtheque.utils.io.FileUtils;
 4  
 
 5  
 import java.io.File;
 6  
 import java.security.AccessController;
 7  
 import java.security.PrivilegedAction;
 8  
 
 9  
 /*
 10  
  * This file is part of JTheque.
 11  
  *            
 12  
  * JTheque is free software: you can redistribute it and/or modify
 13  
  * it under the terms of the GNU General Public License as published by
 14  
  * the Free Software Foundation, either version 3 of the License. 
 15  
  *
 16  
  * JTheque is distributed in the hope that it will be useful,
 17  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 19  
  * GNU General Public License for more details.
 20  
  *
 21  
  * You should have received a copy of the GNU General Public License
 22  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 23  
  */
 24  
 
 25  
 /**
 26  
  * A system property enumeration.
 27  
  *
 28  
  * @author Baptiste Wicht
 29  
  */
 30  0
 public enum SystemProperty {
 31  0
     JAVA_IO_TMP_DIR("java.io.tmpdir") {
 32  
         @Override
 33  
         public String get() {
 34  0
             String value = super.get();
 35  
 
 36  0
             if (!value.endsWith(File.separator)) {
 37  0
                 value += File.separator;
 38  
             }
 39  
 
 40  0
             FileUtils.createIfNotExists(new File(value));
 41  
 
 42  0
             return value;
 43  
         }
 44  
     },
 45  
 
 46  0
     USER_DIR("user.dir") {
 47  
         @Override
 48  
         public String get() {
 49  0
             String value = super.get();
 50  
 
 51  0
             if (!value.endsWith("/")) {
 52  0
                 value += "/";
 53  
             }
 54  
 
 55  0
             return value;
 56  
         }
 57  
     },
 58  
 
 59  0
     JTHEQUE_LOG("jtheque.log");
 60  
 
 61  
     private final String name;
 62  
 
 63  
     /**
 64  
      * Construct a new SystemProperty.
 65  
      *
 66  
      * @param name the name of the property.
 67  
      */
 68  0
     SystemProperty(String name) {
 69  0
         this.name = name;
 70  0
     }
 71  
 
 72  
     /**
 73  
      * Return the value of the property.
 74  
      *
 75  
      * @return The value of the property.
 76  
      */
 77  
     public String get() {
 78  0
         return AccessController.doPrivileged(new PrivilegedAction<String>() {
 79  
             @Override
 80  
             public String run() {
 81  0
                 return System.getProperty(getName());
 82  
             }
 83  
         });
 84  
     }
 85  
 
 86  
     /**
 87  
      * Set the value of the property.
 88  
      *
 89  
      * @param value The value of the property.
 90  
      */
 91  
     public final void set(final String value) {
 92  0
         AccessController.doPrivileged(new PrivilegedAction<String>() {
 93  
             @Override
 94  
             public String run() {
 95  0
                 return System.setProperty(getName(), value);
 96  
             }
 97  
         });
 98  0
     }
 99  
 
 100  
     /**
 101  
      * Return the name of the property.
 102  
      *
 103  
      * @return The name of the property. 
 104  
      */
 105  
     public final String getName() {
 106  0
         return name;
 107  
     }
 108  
 }