001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: /*
042: * NbExecutor.java
043: *
044: * Created on March 28, 2001, 6:57 PM
045: */
046:
047: package org.netbeans.xtest.harness;
048:
049: import org.apache.tools.ant.*;
050: import org.apache.tools.ant.types.*;
051: import org.apache.tools.ant.taskdefs.*;
052:
053: import java.util.*;
054: import java.io.File;
055:
056: /**
057: *
058: * @author mk97936
059: * @version
060: */
061: public class MTestCompiler extends Task {
062:
063: String targetName = null;
064: String targetParamClasspathProp = null;
065: String targetParamTestConfigProp = "tbag.testtype";
066: String targetParamNameProp = null;
067: String targetParamExecutorProp = "tbag.executor";
068:
069: public void setTargetName(String name) {
070: this .targetName = name;
071: }
072:
073: public void setParamClasspathProp(String param) {
074: this .targetParamClasspathProp = param;
075: }
076:
077: public void setParamTestConfigProp(String param) {
078: this .targetParamTestConfigProp = param;
079: }
080:
081: public void setParamNameProp(String param) {
082: this .targetParamNameProp = param;
083: }
084:
085: public void setParamExecutorProp(String param) {
086: this .targetParamExecutorProp = param;
087: }
088:
089: public void executeDefinedCompiler(Testbag testbag, Ant antTask)
090: throws BuildException {
091:
092: MTestConfig.AntExecType compiler = testbag.getCompiler();
093:
094: antTask.setAntfile(compiler.getAntFile());
095: antTask.setTarget(compiler.getTarget());
096:
097: if (compiler.getDir() != null) {
098: antTask.setDir(antTask.getProject().resolveFile(
099: compiler.getDir()));
100: }
101:
102: //ant_new.init();
103:
104: /// ??????? add xtest.userdata| prefix ?????
105: // add all test properties for given testbag
106: /*
107: Testbag.TestProperty properties[] = testbag.getTestProperties();
108: if (properties != null)
109: for (int j=0; j<properties.length; j++) {
110: Property ant_prop = ant_new.createProperty();
111: ant_prop.setName( properties[j].getName() );
112: ant_prop.setValue( properties[j].getValue() );
113: }
114:
115: */
116: // set name of executed test config
117: Property cttprop = antTask.createProperty();
118: cttprop.setName(targetParamTestConfigProp);
119: cttprop
120: .setValue(MTestConfigTask.getMTestConfig()
121: .getTesttype());
122:
123: // set name of executed testbag
124: Property nameprop = antTask.createProperty();
125: nameprop.setName(targetParamNameProp);
126: nameprop.setValue(testbag.getName());
127:
128: // set name of executor for executed testbags
129: /*
130: Property execprop = ant_new.createProperty();
131: execprop.setName( targetParamExecutorProp );
132: execprop.setValue( testbag.getExecutor().getName() );
133: */
134:
135: // execute tests
136: antTask.execute();
137: }
138:
139: /*
140: public void executePluginCompiler(String pluginName, Ant antTask) throws BuildException {
141: }
142: */
143:
144: public void execute() throws BuildException {
145:
146: if (null == targetParamClasspathProp
147: || 0 == targetParamClasspathProp.length())
148: throw new BuildException(
149: "Attribute 'targetParamClasspathProp' has to be set.");
150:
151: Testbag testbags[] = MTestConfigTask.getTestbags();
152: if (null == testbags)
153: throw new BuildException(
154: "TestBag configuration wasn't chosen.",
155: getLocation());
156:
157: for (int i = 0; i < testbags.length; i++) {
158: // get TestBag
159: Testbag testbag = testbags[i];
160:
161: if (testbag.getCompiler() == null) {
162: throw new BuildException("Testbag " + testbag.getName()
163: + " has not a defined compiler.");
164: // check whether there is plugin
165: /*
166: if (testbag.getPluginName() == null) {
167: throw new BuildException("Testbag "+testbag.getName()+" has not a compiler, nor plugin defined.");
168: }
169: */
170: }
171:
172: //Ant ant_new = (Ant) getProject().createTask( "ant" );
173: Ant ant = new Ant();
174: ant.setOwningTarget(this.getOwningTarget());
175: ant.setProject(getProject());
176: executeDefinedCompiler(testbag, ant);
177: }
178:
179: }
180:
181: }
|