Search in sources :

Example 11 with PackageFragmentRoot

use of org.eclipse.jdt.internal.core.PackageFragmentRoot in project jbosstools-hibernate by jbosstools.

the class MappingTestsBase method allTestsRunForProject.

/**
 * Inspect all it's packages of the current testProject and
 * execute all tests from TestSet, considering one test package as active.
 * @throws CoreException
 */
public void allTestsRunForProject() throws CoreException {
    testProject.fullBuild();
    IPackageFragmentRoot[] roots = testProject.getIJavaProject().getAllPackageFragmentRoots();
    for (int i = 0; i < roots.length; i++) {
        if (roots[i].getClass() != PackageFragmentRoot.class) {
            continue;
        }
        PackageFragmentRoot packageFragmentRoot = (PackageFragmentRoot) roots[i];
        IJavaElement[] els = packageFragmentRoot.getChildren();
        for (int j = 0; j < els.length; j++) {
            IJavaElement javaElement = els[j];
            if (!(javaElement instanceof IPackageFragment)) {
                continue;
            }
            testPackage = (IPackageFragment) javaElement;
            // use packages only with compilation units
            if (testPackage.getCompilationUnits().length == 0) {
                continue;
            }
            if (Customization.U_TEST_PACKS_PATTERN) {
                if (!Pattern.matches(Customization.TEST_PACKS_PATTERN, javaElement.getElementName())) {
                    continue;
                }
            }
            long st_pack_time = System.currentTimeMillis();
            int prev_failCount = result.failureCount();
            int prev_errCount = result.errorCount();
            // 
            TestSuite suite = TestSet.createTestSuite(consoleConfigName, testPackage, testProject);
            // 
            customizeCfgXml(testPackage);
            /**
             * /
             *				suite.run(result);
             *				/*
             */
            for (int k = 0; k < suite.testCount(); k++) {
                Test test = suite.testAt(k);
                test.run(result);
                closeAllEditors();
            }
            /**/
            closeAllEditors();
            // ==============================
            executions++;
            if (Customization.USE_CONSOLE_OUTPUT) {
                // $NON-NLS-1$
                System.out.print(result.errorCount() - prev_errCount + ConsoleTestMessages.HibernateAllMappingTests_errors + " \t");
                // $NON-NLS-1$
                System.out.print(result.failureCount() - prev_failCount + ConsoleTestMessages.HibernateAllMappingTests_fails + "\t");
                long period = System.currentTimeMillis() - st_pack_time;
                // $NON-NLS-1$
                String time = period / 1000 + "." + (period % 1000) / 100;
                System.out.println(time + ConsoleTestMessages.HibernateAllMappingTests_seconds + " {" + javaElement.getElementName() + // $NON-NLS-1$//$NON-NLS-2$
                "}");
            }
            if (Customization.STOP_AFTER_MISSING_PACK) {
                if (result.failureCount() > prev_failCount) {
                    break;
                }
            }
            prev_failCount = result.failureCount();
            prev_errCount = result.errorCount();
        }
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) TestSuite(junit.framework.TestSuite) Test(junit.framework.Test) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 12 with PackageFragmentRoot

use of org.eclipse.jdt.internal.core.PackageFragmentRoot in project jbosstools-hibernate by jbosstools.

the class NewHibernateMappingFileWizard method processJavaElements.

protected void processJavaElements(Object obj, int depth) {
    if (depth < 0) {
        return;
    }
    try {
        if (obj instanceof ICompilationUnit) {
            ICompilationUnit cu = (ICompilationUnit) obj;
            selectionCU.add(cu);
        } else if (obj instanceof JavaProject && depth > 0) {
            JavaProject javaProject = (JavaProject) obj;
            IPackageFragmentRoot[] pfr = javaProject.getAllPackageFragmentRoots();
            for (IPackageFragmentRoot element : pfr) {
                processJavaElements(element, depth - 1);
            }
        } else if (obj instanceof PackageFragment) {
            PackageFragment packageFragment = (PackageFragment) obj;
            ICompilationUnit[] cus = packageFragment.getCompilationUnits();
            for (ICompilationUnit cu : cus) {
                selectionCU.add(cu);
            }
        } else if (obj instanceof PackageFragmentRoot && depth > 0) {
            JavaElement javaElement = (JavaElement) obj;
            JavaElementInfo javaElementInfo = (JavaElementInfo) javaElement.getElementInfo();
            IJavaElement[] je = javaElementInfo.getChildren();
            for (IJavaElement element : je) {
                processJavaElements(element, depth - 1);
            }
        } else if (obj instanceof JavaElement) {
            JavaElement javaElement = (JavaElement) obj;
            ICompilationUnit cu = javaElement.getCompilationUnit();
            selectionCU.add(cu);
        }
    } catch (JavaModelException e) {
    // just ignore it!
    // HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ", e); //$NON-NLS-1$
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) PackageFragment(org.eclipse.jdt.internal.core.PackageFragment) IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaProject(org.eclipse.jdt.internal.core.JavaProject) PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) JavaElement(org.eclipse.jdt.internal.core.JavaElement) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaElementInfo(org.eclipse.jdt.internal.core.JavaElementInfo) JavaModelException(org.eclipse.jdt.core.JavaModelException) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Aggregations

PackageFragmentRoot (org.eclipse.jdt.internal.core.PackageFragmentRoot)12 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)9 IJavaElement (org.eclipse.jdt.core.IJavaElement)7 IJavaProject (org.eclipse.jdt.core.IJavaProject)6 IPath (org.eclipse.core.runtime.IPath)5 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)5 Path (org.eclipse.core.runtime.Path)4 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 JavaProject (org.eclipse.jdt.internal.core.JavaProject)4 IResource (org.eclipse.core.resources.IResource)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)3 JavaElement (org.eclipse.jdt.internal.core.JavaElement)3 PackageFragment (org.eclipse.jdt.internal.core.PackageFragment)3 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)2 JavaElementInfo (org.eclipse.jdt.internal.core.JavaElementInfo)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Test (junit.framework.Test)1