jtharnesssuiteutil.java

来自「cqME :java framework for TCK test.」· Java 代码 · 共 173 行

JAVA
173
字号
/*
 * $Id$
 *
 * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version
 * 2 only, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License version 2 for more details (a copy is
 * included at /legal/license.txt).
 *
 * You should have received a copy of the GNU General Public License
 * version 2 along with this work; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
 * Clara, CA 95054 or visit www.sun.com if you need additional
 * information or have any questions.
 *
 */

package com.sun.testme.jtharness.testsuite;

import com.sun.javatest.InterviewParameters;
import com.sun.javatest.TestSuite;
import com.sun.javatest.WorkDirectory;
import com.sun.javatest.exec.ExecTool;
import com.sun.javatest.exec.ExecToolManager;
import com.sun.javatest.tool.Desktop;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.swing.SwingUtilities;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ui.OpenProjects;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;

/**
 *
 */
public class JTharnessSuiteUtil {
    
    /** Creates a new instance of JTharnessSuiteInfo */
    public JTharnessSuiteUtil(Project project) {
        setProject(project);
    }
    
    public Project getProject() {
        return project;
    }
    
    public void setProject(Project project) {
        this.project = project;
    }
    
    public void openTestSuite() {
        init();
    }
    
    protected void init() {
        if (project != null) {
            try {
                File testSuiteFile = FileUtil.toFile(project.getProjectDirectory());
                suite = TestSuite.open(testSuiteFile);
            } catch (FileNotFoundException ex) {
                ex.printStackTrace();
            } catch (TestSuite.Fault ex) {
                ex.printStackTrace();
            }
        }
        SwingUtilities.invokeLater(
            new Runnable() {
                public void run() {
                    createExecTool();
                }
            });
    }    
    
    private void createExecTool() {
        if (d == null) {
            d = new Desktop();
        }
        ExecToolManager m = (ExecToolManager) (d.getToolManager(ExecToolManager.class)); 
        
        try {
            if (project == null) {
                return;
            }
            FileObject fob = project.getProjectDirectory().getFileObject("build/plugin.properties");
            if (fob == null) {
                return;
            }
            Properties prop = new Properties();
            try {
                InputStream in = fob.getInputStream();
                prop.load(in);
                in.close();
                String wrkDir = prop.getProperty("wrkDir");
                if (wrkDir != null) {
                    WorkDirectory workDir = WorkDirectory.open(new File(wrkDir));
                    t = new ExecTool(m, workDir);
                } else {
                    t = new ExecTool(m, suite);
                }
            } catch (FileNotFoundException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    public void showInterviewEditor() {
        if (t == null) {
            setProject(OpenProjects.getDefault().getMainProject());
            createExecTool();
        }
        t.showConfigEditor();
    }
    
    public File getWorkDirectory() {
        if (t == null) {
            setProject(OpenProjects.getDefault().getMainProject());
            createExecTool();
        }
        WorkDirectory wd = t.getWorkDirectory();
        if (wd != null) {
            return wd.getRoot();
        }
        return null;
    }

    public WorkDirectory getWorkDirectory0() {
        if (t == null) {
            setProject(OpenProjects.getDefault().getMainProject());
            createExecTool();
        }
        
        WorkDirectory wd = t.getWorkDirectory();
        return wd;
    }
    
    public File getInterviewFile() {
        if (t == null) {
            setProject(OpenProjects.getDefault().getMainProject());
            createExecTool();
        }
        
        InterviewParameters interview = t.getInterviewParameters();
        if (interview != null) {
            return interview.getFile();
        }
        return null;
    }
    
    private Project project;
    private ExecTool t;
    private TestSuite suite;
    private Desktop d;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?