Example usage for org.eclipse.jdt.core IPackageFragmentRoot getPath

List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getPath

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageFragmentRoot getPath.

Prototype

IPath getPath();

Source Link

Document

Returns the path to the innermost resource enclosing this element.

Usage

From source file:com.redhat.ceylon.eclipse.ui.test.headless.ModelAndPhasedUnitsTests.java

License:Open Source License

@Test
public void checkMainProjectPureJavaUnits() throws CoreException {
    if (compilationError != null) {
        throw compilationError;
    }/*from   w w  w  . jav a  2  s  .c  om*/

    IJavaProject javaProject = JavaCore.create(mainProject);

    String rootPath = null;
    ICompilationUnit javaElement = null;
    for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
        IPackageFragment pkg = root.getPackageFragment("mainModule");
        if (pkg.exists()
                && pkg.getCompilationUnit("JavaClassInCeylonModule_Main_Ceylon_Project.java").exists()) {
            javaElement = pkg.getCompilationUnit("JavaClassInCeylonModule_Main_Ceylon_Project.java");
            rootPath = root.getPath().toOSString();
            break;
        }
    }

    Module module = modelLoader.findModule("mainModule", "1.0.0");

    JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module,
            "mainModule.JavaClassInCeylonModule_Main_Ceylon_Project", JavaCompilationUnit.class,
            rootPath + "/" + "mainModule/JavaClassInCeylonModule_Main_Ceylon_Project.java",
            "mainModule/JavaClassInCeylonModule_Main_Ceylon_Project.java",
            "JavaClassInCeylonModule_Main_Ceylon_Project.java");
    Assert.assertEquals("Wrong Java Element for Pure Java Class : ", javaElement,
            javaClassCompilationUnit.getTypeRoot());
    Assert.assertNotNull("Project Resource  for Pure Java Class should not be null :",
            javaClassCompilationUnit.getProjectResource());
    Assert.assertNotNull("Root Folder Resource  Pure Java for Class should not be null :",
            javaClassCompilationUnit.getRootFolderResource());
    Assert.assertNotNull("File Resource should  Pure Java for Class not be null :",
            javaClassCompilationUnit.getFileResource());
}

From source file:com.redhat.ceylon.eclipse.ui.test.headless.ModelAndPhasedUnitsTests.java

License:Open Source License

@Test
public void checkReferencedProjectJavaCeylonUnits() throws CoreException {
    if (compilationError != null) {
        throw compilationError;
    }/*  w w  w.  jav a  2s . co m*/

    IJavaProject javaProject = JavaCore.create(referencedCeylonProject);

    String rootPath = null;
    ICompilationUnit javaClassElement = null;
    ICompilationUnit javaObjectElement = null;
    ICompilationUnit javaMethodElement = null;
    for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
        IPackageFragment pkg = root.getPackageFragment("referencedCeylonProject");
        if (pkg.exists()
                && pkg.getCompilationUnit("JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java").exists()) {
            javaClassElement = pkg.getCompilationUnit("JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java");
            javaObjectElement = pkg
                    .getCompilationUnit("javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java");
            javaMethodElement = pkg
                    .getCompilationUnit("javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java");
            rootPath = root.getPath().toOSString();
            break;
        }
    }
    Module module = modelLoader.findModule("referencedCeylonProject", "1.0.0");

    JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module,
            "referencedCeylonProject.JavaCeylonTopLevelClass_Referenced_Ceylon_Project",
            JavaCompilationUnit.class,
            rootPath + "/" + "referencedCeylonProject/JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java",
            "referencedCeylonProject/JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java",
            "JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java");
    Assert.assertEquals("Wrong Java Element for Class : ", javaClassElement,
            javaClassCompilationUnit.getTypeRoot());
    Assert.assertNotNull("Project Resource  for Class should not be null :",
            javaClassCompilationUnit.getProjectResource());
    Assert.assertNotNull("Root Folder Resource  for Class should not be null :",
            javaClassCompilationUnit.getRootFolderResource());
    Assert.assertNotNull("File Resource should  for Class not be null :",
            javaClassCompilationUnit.getFileResource());

    JavaCompilationUnit javaObjectCompilationUnit = checkDeclarationUnit(module,
            "referencedCeylonProject.javaCeylonTopLevelObject_Referenced_Ceylon_Project",
            JavaCompilationUnit.class,
            rootPath + "/" + "referencedCeylonProject/javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java",
            "referencedCeylonProject/javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java",
            "javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java");
    Assert.assertEquals("Wrong Java Element for Object : ", javaObjectElement,
            javaObjectCompilationUnit.getTypeRoot());
    Assert.assertNotNull("Project Resource  for Object should not be null :",
            javaObjectCompilationUnit.getProjectResource());
    Assert.assertNotNull("Root Folder Resource  for Object should not be null :",
            javaObjectCompilationUnit.getRootFolderResource());
    Assert.assertNotNull("File Resource should  for Object not be null :",
            javaObjectCompilationUnit.getFileResource());

    JavaCompilationUnit javaMethodCompilationUnit = checkDeclarationUnit(module,
            "referencedCeylonProject.javaCeylonTopLevelMethod_Referenced_Ceylon_Project_",
            JavaCompilationUnit.class,
            rootPath + "/" + "referencedCeylonProject/javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java",
            "referencedCeylonProject/javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java",
            "javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java");
    Assert.assertEquals("Wrong Java Element for Method : ", javaMethodElement,
            javaMethodCompilationUnit.getTypeRoot());
    Assert.assertNotNull("Project Resource  for Method should not be null :",
            javaMethodCompilationUnit.getProjectResource());
    Assert.assertNotNull("Root Folder Resource  for Method should not be null :",
            javaMethodCompilationUnit.getRootFolderResource());
    Assert.assertNotNull("File Resource should  for Method not be null :",
            javaMethodCompilationUnit.getFileResource());
}

From source file:com.redhat.ceylon.eclipse.ui.test.headless.ModelAndPhasedUnitsTests.java

License:Open Source License

@Test
public void checkReferencedProjectPureJavaUnits() throws CoreException {
    if (compilationError != null) {
        throw compilationError;
    }//  w  w w  .  j  av a 2s  . com

    IJavaProject javaProject = JavaCore.create(referencedCeylonProject);

    String rootPath = null;
    ICompilationUnit javaElement = null;
    for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
        IPackageFragment pkg = root.getPackageFragment("referencedCeylonProject");
        if (pkg.exists()
                && pkg.getCompilationUnit("JavaClassInCeylonModule_Referenced_Ceylon_Project.java").exists()) {
            javaElement = pkg.getCompilationUnit("JavaClassInCeylonModule_Referenced_Ceylon_Project.java");
            rootPath = root.getPath().toOSString();
            break;
        }
    }

    Module module = modelLoader.findModule("referencedCeylonProject", "1.0.0");

    JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module,
            "referencedCeylonProject.JavaClassInCeylonModule_Referenced_Ceylon_Project",
            JavaCompilationUnit.class,
            rootPath + "/" + "referencedCeylonProject/JavaClassInCeylonModule_Referenced_Ceylon_Project.java",
            "referencedCeylonProject/JavaClassInCeylonModule_Referenced_Ceylon_Project.java",
            "JavaClassInCeylonModule_Referenced_Ceylon_Project.java");
    Assert.assertEquals("Wrong Java Element for Pure Java Class : ", javaElement,
            javaClassCompilationUnit.getTypeRoot());
    Assert.assertNotNull("Project Resource  for Pure Java Class should not be null :",
            javaClassCompilationUnit.getProjectResource());
    Assert.assertNotNull("Root Folder Resource  Pure Java for Class should not be null :",
            javaClassCompilationUnit.getRootFolderResource());
    Assert.assertNotNull("File Resource should  Pure Java for Class not be null :",
            javaClassCompilationUnit.getFileResource());
}

From source file:com.redhat.ceylon.eclipse.ui.test.ModelAndPhasedUnitsTests.java

License:Open Source License

@Test
public void checkMainProjectJavaCeylonUnits() throws CoreException {
    if (compilationError != null) {
        throw compilationError;
    }/*w  w w.jav  a2 s.  c  om*/

    IJavaProject javaProject = JavaCore.create(mainProject);

    String rootPath = null;
    ICompilationUnit javaClassElement = null;
    ICompilationUnit javaObjectElement = null;
    ICompilationUnit javaMethodElement = null;
    for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
        IPackageFragment pkg = root.getPackageFragment("mainModule");
        if (pkg.exists()
                && pkg.getCompilationUnit("JavaCeylonTopLevelClass_Main_Ceylon_Project.java").exists()) {
            javaClassElement = pkg.getCompilationUnit("JavaCeylonTopLevelClass_Main_Ceylon_Project.java");
            javaObjectElement = pkg.getCompilationUnit("javaCeylonTopLevelObject_Main_Ceylon_Project_.java");
            javaMethodElement = pkg.getCompilationUnit("javaCeylonTopLevelMethod_Main_Ceylon_Project_.java");
            rootPath = root.getPath().toOSString();
            break;
        }
    }

    Module module = modelLoader.findModule("mainModule", "1.0.0");
    JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module,
            "mainModule.JavaCeylonTopLevelClass_Main_Ceylon_Project", JavaCompilationUnit.class,
            rootPath + "/" + "mainModule/JavaCeylonTopLevelClass_Main_Ceylon_Project.java",
            "mainModule/JavaCeylonTopLevelClass_Main_Ceylon_Project.java",
            "JavaCeylonTopLevelClass_Main_Ceylon_Project.java");
    Assert.assertEquals("Wrong Java Element for Class : ", javaClassElement,
            javaClassCompilationUnit.getJavaElement());
    Assert.assertNotNull("Project Resource  for Class should not be null :",
            javaClassCompilationUnit.getProjectResource());
    Assert.assertNotNull("Root Folder Resource  for Class should not be null :",
            javaClassCompilationUnit.getRootFolderResource());
    Assert.assertNotNull("File Resource should  for Class not be null :",
            javaClassCompilationUnit.getFileResource());

    JavaCompilationUnit javaObjectCompilationUnit = checkDeclarationUnit(module,
            "mainModule.javaCeylonTopLevelObject_Main_Ceylon_Project", JavaCompilationUnit.class,
            rootPath + "/" + "mainModule/javaCeylonTopLevelObject_Main_Ceylon_Project_.java",
            "mainModule/javaCeylonTopLevelObject_Main_Ceylon_Project_.java",
            "javaCeylonTopLevelObject_Main_Ceylon_Project_.java");
    Assert.assertEquals("Wrong Java Element for Object : ", javaObjectElement,
            javaObjectCompilationUnit.getJavaElement());
    Assert.assertNotNull("Project Resource  for Object should not be null :",
            javaObjectCompilationUnit.getProjectResource());
    Assert.assertNotNull("Root Folder Resource  for Object should not be null :",
            javaObjectCompilationUnit.getRootFolderResource());
    Assert.assertNotNull("File Resource should  for Object not be null :",
            javaObjectCompilationUnit.getFileResource());

    JavaCompilationUnit javaMethodCompilationUnit = checkDeclarationUnit(module,
            "mainModule.javaCeylonTopLevelMethod_Main_Ceylon_Project_", JavaCompilationUnit.class,
            rootPath + "/" + "mainModule/javaCeylonTopLevelMethod_Main_Ceylon_Project_.java",
            "mainModule/javaCeylonTopLevelMethod_Main_Ceylon_Project_.java",
            "javaCeylonTopLevelMethod_Main_Ceylon_Project_.java");
    Assert.assertEquals("Wrong Java Element for Method : ", javaMethodElement,
            javaMethodCompilationUnit.getJavaElement());
    Assert.assertNotNull("Project Resource  for Method should not be null :",
            javaMethodCompilationUnit.getProjectResource());
    Assert.assertNotNull("Root Folder Resource  for Method should not be null :",
            javaMethodCompilationUnit.getRootFolderResource());
    Assert.assertNotNull("File Resource should  for Method not be null :",
            javaMethodCompilationUnit.getFileResource());
}

From source file:com.redhat.ceylon.eclipse.ui.test.ModelAndPhasedUnitsTests.java

License:Open Source License

@Test
public void checkMainProjectPureJavaUnits() throws CoreException {
    if (compilationError != null) {
        throw compilationError;
    }//from w w w.ja  va  2 s  . c  o m

    IJavaProject javaProject = JavaCore.create(mainProject);

    String rootPath = null;
    ICompilationUnit javaElement = null;
    for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
        IPackageFragment pkg = root.getPackageFragment("mainModule");
        if (pkg.exists()
                && pkg.getCompilationUnit("JavaClassInCeylonModule_Main_Ceylon_Project.java").exists()) {
            javaElement = pkg.getCompilationUnit("JavaClassInCeylonModule_Main_Ceylon_Project.java");
            rootPath = root.getPath().toOSString();
            break;
        }
    }

    Module module = modelLoader.findModule("mainModule", "1.0.0");

    JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module,
            "mainModule.JavaClassInCeylonModule_Main_Ceylon_Project", JavaCompilationUnit.class,
            rootPath + "/" + "mainModule/JavaClassInCeylonModule_Main_Ceylon_Project.java",
            "mainModule/JavaClassInCeylonModule_Main_Ceylon_Project.java",
            "JavaClassInCeylonModule_Main_Ceylon_Project.java");
    Assert.assertEquals("Wrong Java Element for Pure Java Class : ", javaElement,
            javaClassCompilationUnit.getJavaElement());
    Assert.assertNotNull("Project Resource  for Pure Java Class should not be null :",
            javaClassCompilationUnit.getProjectResource());
    Assert.assertNotNull("Root Folder Resource  Pure Java for Class should not be null :",
            javaClassCompilationUnit.getRootFolderResource());
    Assert.assertNotNull("File Resource should  Pure Java for Class not be null :",
            javaClassCompilationUnit.getFileResource());
}

From source file:com.redhat.ceylon.eclipse.ui.test.ModelAndPhasedUnitsTests.java

License:Open Source License

@Test
public void checkReferencedProjectJavaCeylonUnits() throws CoreException {
    if (compilationError != null) {
        throw compilationError;
    }//from w ww .  ja v a 2 s . c  om

    IJavaProject javaProject = JavaCore.create(referencedCeylonProject);

    String rootPath = null;
    ICompilationUnit javaClassElement = null;
    ICompilationUnit javaObjectElement = null;
    ICompilationUnit javaMethodElement = null;
    for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
        IPackageFragment pkg = root.getPackageFragment("referencedCeylonProject");
        if (pkg.exists()
                && pkg.getCompilationUnit("JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java").exists()) {
            javaClassElement = pkg.getCompilationUnit("JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java");
            javaObjectElement = pkg
                    .getCompilationUnit("javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java");
            javaMethodElement = pkg
                    .getCompilationUnit("javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java");
            rootPath = root.getPath().toOSString();
            break;
        }
    }
    Module module = modelLoader.findModule("referencedCeylonProject", "1.0.0");

    JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module,
            "referencedCeylonProject.JavaCeylonTopLevelClass_Referenced_Ceylon_Project",
            JavaCompilationUnit.class,
            rootPath + "/" + "referencedCeylonProject/JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java",
            "referencedCeylonProject/JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java",
            "JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java");
    Assert.assertEquals("Wrong Java Element for Class : ", javaClassElement,
            javaClassCompilationUnit.getJavaElement());
    Assert.assertNotNull("Project Resource  for Class should not be null :",
            javaClassCompilationUnit.getProjectResource());
    Assert.assertNotNull("Root Folder Resource  for Class should not be null :",
            javaClassCompilationUnit.getRootFolderResource());
    Assert.assertNotNull("File Resource should  for Class not be null :",
            javaClassCompilationUnit.getFileResource());

    JavaCompilationUnit javaObjectCompilationUnit = checkDeclarationUnit(module,
            "referencedCeylonProject.javaCeylonTopLevelObject_Referenced_Ceylon_Project",
            JavaCompilationUnit.class,
            rootPath + "/" + "referencedCeylonProject/javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java",
            "referencedCeylonProject/javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java",
            "javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java");
    Assert.assertEquals("Wrong Java Element for Object : ", javaObjectElement,
            javaObjectCompilationUnit.getJavaElement());
    Assert.assertNotNull("Project Resource  for Object should not be null :",
            javaObjectCompilationUnit.getProjectResource());
    Assert.assertNotNull("Root Folder Resource  for Object should not be null :",
            javaObjectCompilationUnit.getRootFolderResource());
    Assert.assertNotNull("File Resource should  for Object not be null :",
            javaObjectCompilationUnit.getFileResource());

    JavaCompilationUnit javaMethodCompilationUnit = checkDeclarationUnit(module,
            "referencedCeylonProject.javaCeylonTopLevelMethod_Referenced_Ceylon_Project_",
            JavaCompilationUnit.class,
            rootPath + "/" + "referencedCeylonProject/javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java",
            "referencedCeylonProject/javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java",
            "javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java");
    Assert.assertEquals("Wrong Java Element for Method : ", javaMethodElement,
            javaMethodCompilationUnit.getJavaElement());
    Assert.assertNotNull("Project Resource  for Method should not be null :",
            javaMethodCompilationUnit.getProjectResource());
    Assert.assertNotNull("Root Folder Resource  for Method should not be null :",
            javaMethodCompilationUnit.getRootFolderResource());
    Assert.assertNotNull("File Resource should  for Method not be null :",
            javaMethodCompilationUnit.getFileResource());
}

From source file:com.redhat.ceylon.eclipse.ui.test.ModelAndPhasedUnitsTests.java

License:Open Source License

@Test
public void checkReferencedProjectPureJavaUnits() throws CoreException {
    if (compilationError != null) {
        throw compilationError;
    }//from  w w w  .  j a  v  a2 s  . c o  m

    IJavaProject javaProject = JavaCore.create(referencedCeylonProject);

    String rootPath = null;
    ICompilationUnit javaElement = null;
    for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
        IPackageFragment pkg = root.getPackageFragment("referencedCeylonProject");
        if (pkg.exists()
                && pkg.getCompilationUnit("JavaClassInCeylonModule_Referenced_Ceylon_Project.java").exists()) {
            javaElement = pkg.getCompilationUnit("JavaClassInCeylonModule_Referenced_Ceylon_Project.java");
            rootPath = root.getPath().toOSString();
            break;
        }
    }

    Module module = modelLoader.findModule("referencedCeylonProject", "1.0.0");

    JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module,
            "referencedCeylonProject.JavaClassInCeylonModule_Referenced_Ceylon_Project",
            JavaCompilationUnit.class,
            rootPath + "/" + "referencedCeylonProject/JavaClassInCeylonModule_Referenced_Ceylon_Project.java",
            "referencedCeylonProject/JavaClassInCeylonModule_Referenced_Ceylon_Project.java",
            "JavaClassInCeylonModule_Referenced_Ceylon_Project.java");
    Assert.assertEquals("Wrong Java Element for Pure Java Class : ", javaElement,
            javaClassCompilationUnit.getJavaElement());
    Assert.assertNotNull("Project Resource  for Pure Java Class should not be null :",
            javaClassCompilationUnit.getProjectResource());
    Assert.assertNotNull("Root Folder Resource  Pure Java for Class should not be null :",
            javaClassCompilationUnit.getRootFolderResource());
    Assert.assertNotNull("File Resource should  Pure Java for Class not be null :",
            javaClassCompilationUnit.getFileResource());
}

From source file:com.sabre.buildergenerator.ui.actions.GenerateBuilderAction.java

License:Open Source License

/**
 * Starts the generation procedure for the type
 *
 * @param type/*w ww.j  av a  2  s.c  o  m*/
 *            a type that the generator is going to be invoked for
 * @param shell
 *                        the shell of the running component
 * @throws CoreException
 */
@SuppressWarnings("deprecation")
public void execute(final IType type, final Shell shell, IRunnableContext runnableContext) throws Exception {
    if (!validateAndShowErrorMessageIfNeeded(type, shell)) {
        return;
    }

    GenerateBuilderWizard wizard = new GenerateBuilderWizard(new BuilderGenerationProperties(type));
    WizardDialog wizardDialog = new WizardDialog(shell, wizard);

    wizardDialog.setMinimumPageSize(200, 500);

    if (wizardDialog.open() == Dialog.OK) {
        final BuilderGenerationProperties properties = wizard.getBuilderGenerationProperties();

        IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {
            public void run(IProgressMonitor aMonitor) throws InvocationTargetException, InterruptedException {
                try {
                    aMonitor.beginTask("Generating class", 4);

                    IPackageFragmentRoot selectedSourceFolder = properties.getSourceFolder();

                    String packageName = properties.getPackageName();
                    String builderClassName = properties.getBuilderClassName();

                    aMonitor.worked(1);

                    // creating package
                    if (!selectedSourceFolder.getPackageFragment(packageName).exists()) {
                        selectedSourceFolder.createPackageFragment(packageName, false, aMonitor);
                    }

                    String source = generateSource(builderGenerator, properties);

                    aMonitor.worked(2);

                    // create source file
                    IPath builderPath = selectedSourceFolder.getPath();

                    for (String s : packageName.split("\\.")) {
                        builderPath = builderPath.append(s);
                    }

                    builderPath = builderPath.append(builderClassName).addFileExtension("java");

                    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(builderPath);

                    if (file.exists()) {
                        file.delete(false, aMonitor);
                    }

                    file.create(new StringBufferInputStream(source), false, aMonitor);
                } catch (Throwable e) {
                    throw new InvocationTargetException(e);
                } finally {
                    aMonitor.done();
                }
            }
        };

        try {
            runnableContext.run(true, false, runnableWithProgress);
        } catch (InvocationTargetException e) {
            Throwable t = e.getTargetException();
            StringWriter buf = new StringWriter();

            t.printStackTrace(new PrintWriter(buf));
            MessageDialog.openError(null, "Error", buf.toString());
            t.printStackTrace();
        } catch (InterruptedException e) {
            StringWriter buf = new StringWriter();

            e.printStackTrace(new PrintWriter(buf));
            MessageDialog.openError(null, "Error", buf.toString());
            e.printStackTrace();
        } catch (Throwable e) {
            StringWriter buf = new StringWriter();

            e.printStackTrace(new PrintWriter(buf));
            MessageDialog.openError(null, "Error", buf.toString());
            e.printStackTrace();
        }
    }
}

From source file:com.siteview.mde.internal.core.SearchablePluginsManager.java

License:Open Source License

private IPackageFragmentRoot findPackageFragmentRoot(IPath jarPath) {
    IJavaProject jProject = getProxyProject();
    if (jProject != null) {
        try {/*from   w w w  . ja v  a  2  s .  c  o m*/
            IPackageFragmentRoot[] roots = jProject.getAllPackageFragmentRoots();
            for (int i = 0; i < roots.length; i++) {
                IPackageFragmentRoot root = roots[i];
                IPath path = root.getPath();
                if (path.equals(jarPath))
                    return root;

            }
        } catch (JavaModelException e) {
        }
    }

    // Find in other plug-in (and fragments) projects dependencies
    IMonitorModelBase[] pluginModels = MonitorRegistry.getWorkspaceModels();
    for (int i = 0; i < pluginModels.length; i++) {
        IProject project = pluginModels[i].getUnderlyingResource().getProject();
        IJavaProject javaProject = JavaCore.create(project);
        try {
            IPackageFragmentRoot[] roots = javaProject.getAllPackageFragmentRoots();
            for (int j = 0; j < roots.length; j++) {
                IPackageFragmentRoot root = roots[j];
                IPath path = root.getPath();
                if (path.equals(jarPath))
                    return root;
            }
        } catch (JavaModelException e) {
        }
    }

    return null;
}

From source file:com.technophobia.substeps.step.ProjectStepImplementationLoader.java

License:Open Source License

/**
 * Returns the path for this fragment in a OS friendly string. Note that in
 * windows, the method for getting the absolute path varies for source
 * folders and jars//from   w ww.j a va  2s. co  m
 * 
 * @param fragmentRoot
 *            The fragment containing classes
 * @return The path of this fragment root, os-friendly
 */
private String getPathFor(final IPackageFragmentRoot fragmentRoot) {
    final IResource resource = fragmentRoot.getResource();
    final IPath path;
    if (resource != null) {
        path = resource.getRawLocation();
    } else {
        path = fragmentRoot.getPath().makeAbsolute();
    }
    return path.toOSString();
}