1 package org.objectweb.celtix.maven_plugin; 2 3 import java.io.File ; 4 import java.util.ArrayList ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 8 import org.apache.maven.plugin.AbstractMojo; 9 import org.apache.maven.plugin.MojoExecutionException; 10 import org.apache.maven.project.MavenProject; 11 import org.apache.tools.ant.ExitException; 12 import org.apache.tools.ant.util.optional.NoExitSecurityManager; 13 import org.objectweb.celtix.tools.WSDLToJava; 14 18 public class WSDL2JavaMojo extends AbstractMojo { 19 22 String testSourceRoot; 23 24 28 String sourceRoot; 29 30 34 String classesDirectory; 35 36 40 List classpathElements; 41 42 46 MavenProject project; 47 48 49 52 WsdlOption wsdlOptions[]; 53 54 public void execute() throws MojoExecutionException { 55 String outputDir = testSourceRoot == null ? sourceRoot : testSourceRoot; 56 File outputDirFile = new File (outputDir); 57 outputDirFile.mkdirs(); 58 59 File classesDir = new File (classesDirectory); 60 classesDir.mkdirs(); 61 62 StringBuffer buf = new StringBuffer (); 63 Iterator it = classpathElements.iterator(); 64 while (it.hasNext()) { 65 buf.append(it.next().toString()); 66 buf.append(File.pathSeparatorChar); 67 } 68 String newCp = buf.toString(); 69 70 String cp = System.getProperty("java.class.path"); 71 SecurityManager oldSm = System.getSecurityManager(); 72 long timestamp = CodegenUtils.getCodegenTimestamp(); 73 try { 74 System.setProperty("java.class.path", newCp); 75 System.setSecurityManager(new NoExitSecurityManager()); 76 77 for (int x = 0; x < wsdlOptions.length; x++) { 78 processWsdl(wsdlOptions[x], outputDirFile, timestamp); 79 } 80 } finally { 81 System.setSecurityManager(oldSm); 82 System.setProperty("java.class.path", cp); 83 } 84 if (project != null && sourceRoot != null) { 85 project.addCompileSourceRoot(sourceRoot); 86 } 87 if (project != null && testSourceRoot != null) { 88 project.addTestCompileSourceRoot(testSourceRoot); 89 } 90 } 91 92 private void processWsdl(WsdlOption wsdlOption, 93 File outputDirFile, 94 long cgtimestamp) throws MojoExecutionException { 95 File file = new File (wsdlOption.getWsdl()); 96 File doneFile = new File (outputDirFile, "." + file.getName() + ".DONE"); 97 boolean doWork = cgtimestamp > doneFile.lastModified(); 98 if (!doneFile.exists()) { 99 doWork = true; 100 } else if (file.lastModified() > doneFile.lastModified()) { 101 doWork = true; 102 } else { 103 File files[] = wsdlOption.getDependencies(); 104 if (files != null) { 105 for (int z = 0; z < files.length; ++z) { 106 if (files[z].lastModified() > doneFile.lastModified()) { 107 doWork = true; 108 } 109 } 110 } 111 } 112 113 if (doWork) { 114 115 List list = new ArrayList (); 116 if (wsdlOption.getPackagenames() != null) { 117 Iterator it = wsdlOption.getPackagenames().iterator(); 118 while (it.hasNext()) { 119 list.add("-p"); 120 list.add(it.next().toString()); 121 } 122 } 123 list.add("-d"); 126 list.add(outputDirFile.toString()); 127 128 if (wsdlOption.getExtraargs() != null) { 129 Iterator it = wsdlOption.getExtraargs().iterator(); 130 while (it.hasNext()) { 131 list.add(it.next().toString()); 132 } 133 } 134 list.add(wsdlOption.getWsdl()); 135 136 137 try { 138 try { 139 WSDLToJava.main((String [])list.toArray(new String [list.size()])); 140 doneFile.delete(); 141 doneFile.createNewFile(); 142 } catch (ExitException e) { 143 if (e.getStatus() == 0) { 144 doneFile.delete(); 145 doneFile.createNewFile(); 146 } else { 147 throw e; 148 } 149 } 150 } catch (Throwable e) { 151 e.printStackTrace(); 152 throw new MojoExecutionException(e.getMessage(), e); 153 } 154 } 155 } 156 } 157
| Popular Tags
|