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-2007 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: /*
043: * JavaProject.java
044: *
045: * Created on January 25, 2006, 1:38 PM
046: *
047: */
048:
049: package org.netbeans.test.umllib.project;
050:
051: import org.netbeans.jellytools.NewProjectWizardOperator;
052: import org.netbeans.jellytools.OutputTabOperator;
053: import org.netbeans.jellytools.ProjectsTabOperator;
054: import org.netbeans.jellytools.nodes.Node;
055: import org.netbeans.jellytools.nodes.ProjectRootNode;
056: import org.netbeans.jemmy.operators.JDialogOperator;
057: import org.netbeans.jemmy.operators.JButtonOperator;
058: import org.netbeans.jemmy.operators.JCheckBoxOperator;
059: import org.netbeans.jemmy.operators.JTextFieldOperator;
060: import org.netbeans.test.umllib.util.LabelsAndTitles;
061: import org.netbeans.test.umllib.util.Utils;
062:
063: /**
064: *
065: * @author Alexandr Scherbatiy
066: */
067:
068: public class JavaProject extends Project {
069:
070: /** Creates a new instance of JavaProject */
071: private static long TIME_WAIT = 1000;
072:
073: public static final String BUILD_FAILED = "BUILD FAILED";
074: public static final String BUILD_SUCCESSFUL = "BUILD SUCCESSFUL";
075:
076: String mainClass;
077: ProjectRootNode rootNode;
078:
079: JavaClassLoader classLoader;
080:
081: /**
082: *
083: * @param name
084: * @param type
085: */
086: public JavaProject(String name) {
087: this (name, ProjectType.JAVA_APPLICATION);
088: }
089:
090: /**
091: *
092: * @param name
093: * @param type
094: */
095: public JavaProject(String name, ProjectType type) {
096: this (name, type, Utils.WORK_DIR);
097: }
098:
099: /**
100: *
101: * @param name
102: * @param type
103: * @param location
104: */
105: public JavaProject(String name, ProjectType type, String location) {
106: this (name, type, location, null);
107: }
108:
109: /**
110: *
111: * @param name
112: * @param type
113: * @param location
114: * @param mainClass
115: */
116: public JavaProject(String name, ProjectType type, String location,
117: String mainClass) {
118: super (name, type, location);
119: this .mainClass = mainClass;
120: rootNode = new ProjectRootNode(ProjectsTabOperator.invoke()
121: .tree(), name);
122: }
123:
124: /**
125: *
126: * @return
127: */
128: public String getMainClass() {
129: return mainClass;
130: }
131:
132: /**
133: *
134: * @return
135: */
136: public ProjectRootNode getProjectNode() {
137: return rootNode;
138: }
139:
140: /**
141: *
142: * @param name
143: * @param type
144: * @return
145: */
146: public static JavaProject createProject(String name,
147: ProjectType type) {
148: return createProject(name, type, Utils.WORK_DIR);
149: }
150:
151: /**
152: *
153: * @param name
154: * @param type
155: * @param location
156: * @return
157: */
158: public static JavaProject createProject(String name,
159: ProjectType type, String location) {
160: return createProject(name, type, location, true);
161: }
162:
163: public static JavaProject createProject(String name,
164: ProjectType type, boolean setAsMain, boolean createMainClass) {
165: return createProject(name, type, Utils.WORK_DIR, setAsMain,
166: createMainClass, null);
167: }
168:
169: /**
170: *
171: * @param name
172: * @param type
173: * @param location
174: * @param setAsMain
175: * @return
176: */
177: public static JavaProject createProject(String name,
178: ProjectType type, String location, boolean setAsMain) {
179: return createProject(name, type, location, setAsMain, true,
180: null);
181: }
182:
183: /**
184: *
185: * @param name
186: * @param type
187: * @param location
188: * @param setAsMain
189: * @param createMainClass
190: * @return
191: */
192:
193: public static JavaProject createProject(String name,
194: ProjectType type, String location, boolean setAsMain,
195: boolean createMainClass) {
196: return createProject(name, type, location, setAsMain,
197: createMainClass, null);
198: }
199:
200: /**
201: *
202: * @param name
203: * @param type
204: * @param location
205: * @param setAsMain
206: * @param createMainClass
207: * @param mainClass
208: * @return
209: */
210: public static JavaProject createProject(String name,
211: ProjectType type, String location, boolean setAsMain,
212: boolean createMainClass, String mainClass) {
213:
214: location = (location == null) ? Utils.WORK_DIR : location;
215:
216: NewProjectWizardOperator newProject = NewProjectWizardOperator
217: .invoke();
218: //try{ Thread.sleep(TIME_WAIT); } catch(Exception e){}
219:
220: newProject
221: .selectCategory(LabelsAndTitles.PROJECT_CATEGORY_GENERAL);
222: newProject.selectProject(type.toString());
223:
224: newProject.next();
225:
226: //try{ Thread.sleep(TIME_WAIT); } catch(Exception e){}
227:
228: //newProject.setName(name);
229:
230: new JTextFieldOperator(newProject, 0).setText(name);
231:
232: //try{ Thread.sleep(TIME_WAIT); } catch(Exception e){}
233:
234: JTextFieldOperator projectLocation = new JTextFieldOperator(
235: newProject, 1);
236:
237: projectLocation.setText(location);
238:
239: new JCheckBoxOperator(newProject, 0).setSelected(setAsMain);
240: new JCheckBoxOperator(newProject, 1)
241: .setSelected(createMainClass);
242:
243: JTextFieldOperator mainClassTextField = new JTextFieldOperator(
244: newProject, 3);
245:
246: if (mainClass != null) {
247: mainClassTextField.setText(mainClass);
248: } else {
249: mainClass = mainClassTextField.getText();
250: }
251: try {
252: Thread.sleep(TIME_WAIT);
253: } catch (Exception e) {
254: }
255:
256: //this.location = location;
257: //this.mainClass = mainClass;
258:
259: new JButtonOperator(newProject, "Finish").push();
260: try {
261: Thread.sleep(TIME_WAIT);
262: } catch (Exception e) {
263: }
264:
265: Utils.waitScanningClassPath();
266:
267: return new JavaProject(name, type, location, mainClass);
268:
269: }
270:
271: public UMLProject reverseEngineer(String umlProjectName) {
272:
273: rootNode.performPopupActionNoBlock("Reverse Engineer...");
274: JDialogOperator dialog = new JDialogOperator("Reverse Engineer");
275:
276: new JTextFieldOperator(dialog, 2).setText(umlProjectName);
277: new JButtonOperator(dialog, "OK").pushNoBlock();
278:
279: return new UMLProject(umlProjectName,
280: ProjectType.UML_JAVA_REVERSE_ENGINEERING);
281:
282: //return UMLProject.createProject(umlProjectName, ProjectType.UML_JAVA_REVERSE_ENGINEERING, this);
283:
284: }
285:
286: public Node getSrcNode() {
287: return new Node(getProjectNode(), "Source Packages");
288: }
289:
290: public Class getJavaClass(String fullName) {
291:
292: if (classLoader == null) {
293: classLoader = new JavaClassLoader(getLocation() + "/"
294: + getName() + "/build/classes");
295: }
296:
297: try {
298: return classLoader.loadClass(fullName);
299: } catch (ClassNotFoundException ex) {
300: ex.printStackTrace();
301: }
302:
303: return null;
304:
305: }
306:
307: public void build() {
308: rootNode.buildProject();
309: }
310:
311: public void close() {
312: rootNode.performPopupActionNoBlock("Close");
313: }
314:
315: public Output getOutput() {
316: return new Output();
317: }
318:
319: public class Output {
320:
321: OutputTabOperator output = new OutputTabOperator(getName()
322: + " (jar) ");
323:
324: public boolean isCompiled() {
325: return getText().contains(BUILD_SUCCESSFUL);
326: }
327:
328: public String getText() {
329: return output.getText();
330: }
331:
332: public OutputTabOperator getOutputOperator() {
333: return output;
334: }
335:
336: }
337:
338: }
|