1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import org.apache.tools.ant.*; 25 import org.apache.tools.ant.types.*; 26 27 30 public class GetModuleName extends Task { 31 String name = null; 32 File root = null; 33 34 public void setName (String name) { 37 this.name = name; 38 } 39 40 41 public void setRoot( File root ) { 42 this.root = root; 43 } 44 45 public void execute() throws BuildException { 46 if (name == null) 47 throw new BuildException("You must set the property name, where to store the module name", this.getLocation()); 48 if (root == null) 49 throw new BuildException("You must set the root dir", this.getLocation()); 50 try { 51 File dir = this.getProject ().getBaseDir (); 52 if (dir.toString ().endsWith (java.io.File.separatorChar + "test")) { 53 dir = dir.getParentFile (); 55 } 56 String rootdir = root.getCanonicalPath(); 57 StringBuffer modulename = new StringBuffer (); 58 while (dir != null) { 59 if (dir.getCanonicalPath ().equals (rootdir)) { 60 break; 61 } 62 if (modulename.length () > 0) { 63 modulename.insert (0, '/'); 64 } 65 modulename.insert (0, dir.getName ()); 66 dir = dir.getParentFile (); 67 } 68 69 if (dir == null) throw new BuildException( "This module in on different path than the root dir",this.getLocation()); 71 this.getProject().setProperty(name, modulename.toString()); } 73 catch (IOException ex) { 74 throw new BuildException("Root dir or module's base dir wasn't recognized", ex, this.getLocation()); 75 } 76 } 77 78 } 79 | Popular Tags |