1 17 18 package org.apache.geronimo.deployment.cli; 19 20 import java.io.BufferedReader ; 21 import java.io.IOException ; 22 import java.io.StringReader ; 23 import java.util.Collection ; 24 import java.util.LinkedList ; 25 import java.util.List ; 26 import javax.enterprise.deploy.spi.TargetModuleID ; 27 import org.apache.geronimo.common.DeploymentException; 28 import org.apache.geronimo.deployment.plugin.ConfigIDExtractor; 29 import org.apache.geronimo.kernel.repository.Artifact; 30 31 36 public class DeployUtils extends ConfigIDExtractor { 37 46 public static String reformat(String source, int indent, int endCol) { 47 if(endCol-indent < 10) { 48 throw new IllegalArgumentException ("This is ridiculous!"); 49 } 50 StringBuffer buf = new StringBuffer ((int)(source.length()*1.1)); 51 String prefix = indent == 0 ? "" : buildIndent(indent); 52 try { 53 BufferedReader in = new BufferedReader (new StringReader (source)); 54 String line; 55 int pos; 56 while((line = in.readLine()) != null) { 57 if(buf.length() > 0) { 58 buf.append('\n'); 59 } 60 while(line.length() > 0) { 61 line = prefix + line; 62 if(line.length() > endCol) { 63 pos = line.lastIndexOf(' ', endCol); 64 if(pos < indent) { 65 pos = line.indexOf(' ', endCol); 66 if(pos < indent) { 67 pos = line.length(); 68 } 69 } 70 buf.append(line.substring(0, pos)).append('\n'); 71 if(pos < line.length()-1) { 72 line = line.substring(pos+1); 73 } else { 74 break; 75 } 76 } else { 77 buf.append(line).append("\n"); 78 break; 79 } 80 } 81 } 82 } catch (IOException e) { 83 throw new AssertionError ("This should be impossible"); 84 } 85 return buf.toString(); 86 } 87 88 private static String buildIndent(int indent) { 89 StringBuffer buf = new StringBuffer (indent); 90 for(int i=0; i<indent; i++) { 91 buf.append(' '); 92 } 93 return buf.toString(); 94 } 95 96 97 } 98 | Popular Tags |