1 16 package org.apache.commons.vfs.tasks; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.vfs.FileObject; 20 import org.apache.commons.vfs.FileSystemException; 21 import org.apache.commons.vfs.impl.StandardFileSystemManager; 22 import org.apache.tools.ant.BuildEvent; 23 import org.apache.tools.ant.Project; 24 import org.apache.tools.ant.SubBuildListener; 25 import org.apache.tools.ant.Task; 26 27 34 public class VfsTask 35 extends Task 36 { 37 private static StandardFileSystemManager manager; 38 39 44 protected FileObject resolveFile(final String uri) 45 throws FileSystemException 46 { 47 if (manager == null) 48 { 49 manager = new StandardFileSystemManager(); 50 manager.setLogger(new AntLogger()); 51 manager.init(); 52 getProject().addBuildListener(new CloseListener()); 53 } 54 return manager.resolveFile(getProject().getBaseDir(), uri); 55 } 56 57 60 protected void closeManager() 61 { 62 if (manager != null) 63 { 64 manager.close(); 65 manager = null; 66 } 67 } 68 69 72 private class CloseListener 73 implements SubBuildListener 74 { 75 public void subBuildStarted(BuildEvent buildEvent) 76 { 77 } 78 79 public void subBuildFinished(BuildEvent buildEvent) 80 { 81 closeManager(); 82 } 83 84 public void buildFinished(BuildEvent event) 85 { 86 closeManager(); 87 } 88 89 public void buildStarted(BuildEvent event) 90 { 91 } 92 93 public void messageLogged(BuildEvent event) 94 { 95 } 96 97 public void targetFinished(BuildEvent event) 98 { 99 } 100 101 public void targetStarted(BuildEvent event) 102 { 103 } 104 105 public void taskFinished(BuildEvent event) 106 { 107 } 108 109 public void taskStarted(BuildEvent event) 110 { 111 } 112 } 113 114 117 private class AntLogger 118 implements Log 119 { 120 public void debug(final Object o) 121 { 122 log(String.valueOf(o), Project.MSG_DEBUG); 123 } 124 125 public void debug(Object o, Throwable throwable) 126 { 127 debug(o); 128 } 129 130 public void error(Object o) 131 { 132 log(String.valueOf(o), Project.MSG_ERR); 133 } 134 135 public void error(Object o, Throwable throwable) 136 { 137 error(o); 138 } 139 140 public void fatal(Object o) 141 { 142 log(String.valueOf(o), Project.MSG_ERR); 143 } 144 145 public void fatal(Object o, Throwable throwable) 146 { 147 fatal(o); 148 } 149 150 public void info(Object o) 151 { 152 log(String.valueOf(o), Project.MSG_INFO); 153 } 154 155 public void info(Object o, Throwable throwable) 156 { 157 info(o); 158 } 159 160 public void trace(Object o) 161 { 162 } 163 164 public void trace(Object o, Throwable throwable) 165 { 166 } 167 168 public void warn(Object o) 169 { 170 log(String.valueOf(o), Project.MSG_WARN); 171 } 172 173 public void warn(Object o, Throwable throwable) 174 { 175 warn(o); 176 } 177 178 public boolean isDebugEnabled() 179 { 180 return true; 181 } 182 183 public boolean isErrorEnabled() 184 { 185 return true; 186 } 187 188 public boolean isFatalEnabled() 189 { 190 return true; 191 } 192 193 public boolean isInfoEnabled() 194 { 195 return true; 196 } 197 198 public boolean isTraceEnabled() 199 { 200 return false; 201 } 202 203 public boolean isWarnEnabled() 204 { 205 return true; 206 } 207 } 208 } 209 | Popular Tags |