| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package nl.toolforge.karma.core.module; |
| 20 |
|
|
| 21 |
|
import org.apache.commons.logging.Log; |
| 22 |
|
import org.apache.commons.logging.LogFactory; |
| 23 |
|
|
| 24 |
|
import java.io.BufferedWriter; |
| 25 |
|
import java.io.File; |
| 26 |
|
import java.io.FileWriter; |
| 27 |
|
import java.io.IOException; |
| 28 |
|
import java.io.Writer; |
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
public class ModuleDescriptor { |
| 35 |
|
|
| 36 |
14 |
protected static Log logger = LogFactory.getLog(ModuleDescriptor.class); |
| 37 |
|
|
| 38 |
28 |
private Module.Type moduleType = null; |
| 39 |
|
|
| 40 |
44 |
public ModuleDescriptor(Module module) { |
| 41 |
22 |
|
| 42 |
60 |
if (module == null) { |
| 43 |
44 |
throw new IllegalArgumentException("Module type cannot be null."); |
| 44 |
32 |
} |
| 45 |
44 |
|
| 46 |
32 |
|
| 47 |
44 |
|
| 48 |
28 |
if (module instanceof LibModule) { |
| 49 |
7 |
this.moduleType = Module.LIBRARY_MODULE; |
| 50 |
21 |
} else if (module instanceof SourceModule) { |
| 51 |
7 |
this.moduleType = Module.JAVA_SOURCE_MODULE; |
| 52 |
46 |
} else if (module instanceof JavaEnterpriseApplicationModule) { |
| 53 |
59 |
this.moduleType = Module.JAVA_ENTERPRISE_APPLICATION; |
| 54 |
42 |
} else if (module instanceof JavaWebApplicationModule) { |
| 55 |
48 |
this.moduleType = Module.JAVA_WEB_APPLICATION; |
| 56 |
27 |
} else if (module instanceof OtherModule) { |
| 57 |
30 |
this.moduleType = Module.OTHER_MODULE; |
| 58 |
19 |
} |
| 59 |
47 |
} |
| 60 |
11 |
|
| 61 |
0 |
|
| 62 |
|
|
| 63 |
32 |
|
| 64 |
44 |
|
| 65 |
|
|
| 66 |
|
public void createFile(File dir) throws IOException { |
| 67 |
|
|
| 68 |
28 |
StringBuffer buffer = new StringBuffer(); |
| 69 |
|
|
| 70 |
28 |
buffer.append("<?xml version=\ŕ.0\"?>\n"); |
| 71 |
|
|
| 72 |
60 |
buffer.append("<module-descriptor version=\ŕ-0\">\n"); |
| 73 |
72 |
buffer.append(" <type>").append(moduleType.getType()).append("</type>\n"); |
| 74 |
60 |
buffer.append(" <layout-specification/> <!-- for future usage -->\n"); |
| 75 |
72 |
buffer.append("</module-descriptor>\n"); |
| 76 |
32 |
|
| 77 |
104 |
Writer writer = new BufferedWriter(class="keyword">new FileWriter(class="keyword">new File(dir, "module-descriptor.xml"))); |
| 78 |
104 |
writer.write(buffer.toString()); |
| 79 |
76 |
|
| 80 |
72 |
logger.debug("Creating `module-descriptor.xml` for type : " + moduleType.getType()); |
| 81 |
32 |
|
| 82 |
104 |
writer.flush(); |
| 83 |
72 |
} |
| 84 |
32 |
|
| 85 |
44 |
} |