001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.ant.extensions;
019:
020: import java.io.File;
021: import java.io.IOException;
022:
023: import org.apache.cxf.common.util.StringUtils;
024: import org.apache.cxf.tools.java2wsdl.JavaToWSDL;
025: import org.apache.tools.ant.AntClassLoader;
026: import org.apache.tools.ant.BuildException;
027: import org.apache.tools.ant.Project;
028: import org.apache.tools.ant.taskdefs.Execute;
029: import org.apache.tools.ant.taskdefs.LogStreamHandler;
030: import org.apache.tools.ant.types.Path;
031: import org.apache.tools.ant.types.Reference;
032:
033: public class Java2WSDLTask extends CxfAntTask {
034:
035: private Path classpath;
036:
037: private File wsdlDir;
038: private String protocol;
039: private String className;
040:
041: public void setGenwsdl(boolean gw) {
042: //the point of this is to gen the wsdl, always do it
043: }
044:
045: public Path createClasspath() {
046: if (classpath == null) {
047: classpath = new Path(getProject());
048: }
049: return classpath.createPath();
050: }
051:
052: public void setClasspath(Path c) {
053: if (classpath == null) {
054: classpath = c;
055: } else {
056: classpath.append(c);
057: }
058: }
059:
060: public void setClasspathRef(Reference r) {
061: createClasspath().setRefid(r);
062: }
063:
064: public void setProtocol(String p) {
065: protocol = p;
066: }
067:
068: public void setResourcedestdir(File f) {
069: wsdlDir = f;
070: }
071:
072: public void setSei(String clz) {
073: className = clz;
074: }
075:
076: public void execute() throws BuildException {
077: buildCommandLine();
078:
079: LogStreamHandler log = new LogStreamHandler(this ,
080: Project.MSG_INFO, Project.MSG_WARN);
081: Execute exe = new Execute(log);
082: exe.setAntRun(getProject());
083: exe.setCommandline(cmd.getCommandline());
084: try {
085: int rc = exe.execute();
086: if (exe.killedProcess() || rc != 0) {
087: throw new BuildException("java2wsdl failed",
088: getLocation());
089: }
090: } catch (IOException e) {
091: throw new BuildException(e, getLocation());
092: }
093: }
094:
095: public void buildCommandLine() {
096: ClassLoader loader = this .getClass().getClassLoader();
097: Path runCp = new Path(getProject());
098: if (loader instanceof AntClassLoader) {
099: runCp = new Path(getProject(), ((AntClassLoader) loader)
100: .getClasspath());
101: }
102: cmd.createClasspath(getProject()).append(runCp);
103: cmd.createVmArgument().setLine(
104: "-Djava.util.logging.config.file=");
105:
106: cmd.setClassname(JavaToWSDL.class.getName());
107:
108: if (classpath != null && !classpath.toString().equals("")) {
109: cmd.createArgument().setValue("-cp");
110: cmd.createArgument().setPath(classpath);
111: }
112:
113: if (null != classesDir
114: && !StringUtils.isEmpty(classesDir.getName())) {
115: cmd.createArgument().setValue("-classdir");
116: cmd.createArgument().setFile(classesDir);
117: }
118: if (null != sourcesDir
119: && !StringUtils.isEmpty(sourcesDir.getName())) {
120: cmd.createArgument().setValue("-s");
121: cmd.createArgument().setFile(sourcesDir);
122: }
123:
124: // verbose option
125: if (verbose) {
126: cmd.createArgument().setValue("-verbose");
127: }
128:
129: if ("Xsoap1.2".equals(protocol)) {
130: cmd.createArgument().setValue("-soap12");
131: }
132:
133: cmd.createArgument().setValue("-createxsdimports");
134:
135: if (null != wsdlDir && !StringUtils.isEmpty(wsdlDir.getName())) {
136: cmd.createArgument().setValue("-d");
137: cmd.createArgument().setFile(wsdlDir);
138: }
139:
140: if (!StringUtils.isEmpty(className)) {
141: cmd.createArgument().setValue(className);
142: }
143: }
144: }
|