Java 类org.eclipse.jdt.core.IJavaProject 实例源码

项目:ContentAssist    文件:WorkspaceUtilities.java   
/**
 * Collects all compilation units within the project.
 * @return the collection of the compilation units
 */
public static List<ICompilationUnit> collectAllCompilationUnits() {
    List<ICompilationUnit> units = new ArrayList<ICompilationUnit>();

    try {
        IProject[] projects =  getWorkspace().getRoot().getProjects();
        for (int i = 0; i < projects.length; i++) {
            IJavaProject project = (IJavaProject)JavaCore.create((IProject)projects[i]);

            IPackageFragment[] packages = project.getPackageFragments();
            for (int j = 0; j < packages.length; j++) {

                ICompilationUnit[] cus = packages[j].getCompilationUnits();
                for (int k = 0; k < cus.length; k++) {
                    IResource res = cus[k].getResource();
                    if (res.getType() == IResource.FILE) {
                        String name = cus[k].getPath().toString();
                        if (name.endsWith(".java")) { 
                            units.add(cus[k]);
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }

    return units;
}
项目:gw4e.project    文件:JDTManagerTest.java   
@Test
public void testEnrichClass() throws Exception {
    IJavaProject pj = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME,true,false);

    IFile impl = ProjectHelper.createDummyClass (pj);
    ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(impl);
    IMethod m = compilationUnit.getTypes() [0].getMethod("runFunctionalTest",new String[0]);
    assertFalse (m.exists());

    IFile file = (IFile) ResourceManager.getResource(pj.getProject().getFullPath().append("src/test/resources/Simple.json").toString());
    ResourceContext context =  GenerationFactory.getResourceContext(file);
    ClassExtension ce = context.getClassExtension();
    ce.setGenerateRunFunctionalTest(true);
    ce.setStartElementForJunitTest("start_app");    
    TestResourceGeneration trg = new TestResourceGeneration(context);    
    JDTManager.enrichClass(impl, trg, new NullProgressMonitor());

    m = compilationUnit.getTypes() [0].getMethod("runFunctionalTest",new String[0]);
    assertTrue (m.exists());

}
项目:gw4e.project    文件:ClasspathManager.java   
/**
 * Add JUnit libraries to the passed project
 * 
 * @param project
 * @throws JavaModelException
 */
private static void addJunit4Libraries(IProject project) throws JavaModelException {
    IClasspathEntry entry = JavaCore.newContainerEntry(JUnitCore.JUNIT4_CONTAINER_PATH);
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    boolean junitFound = false;
    String s = entry.getPath().toString();
    for (int i = 0; i < entries.length; i++) {
        if (entries[i].getPath().toString().indexOf(s) != -1) {
            junitFound = true;
            break;
        }
    }
    if (!junitFound) {
        IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
        System.arraycopy(entries, 0, newEntries, 0, entries.length);
        newEntries[entries.length] = entry;
        javaProject.setRawClasspath(newEntries, null);
    }
}
项目:gw4e.project    文件:JDTManager.java   
/**
 * @param projectName
 * @return
 * @throws JavaModelException
 */
private static List<IType> findClassesWithAnnotation(String projectName, Class annotationClass, String attributName,
        boolean valued) throws JavaModelException {
    List<IType> classList = new ArrayList<IType>();
    IProject project = ResourceManager.getProject(projectName);
    IJavaProject javaProject = JavaCore.create(project);
    IPackageFragment[] packages = javaProject.getPackageFragments();
    for (IPackageFragment packageFragment : packages) {
        for (final ICompilationUnit compilationUnit : packageFragment.getCompilationUnits()) {
            if (compilationUnit.exists()) {
                IType type = getClassesWithAnnotation(compilationUnit, annotationClass, attributName, valued);
                if (type != null)
                    classList.add(type);
            }
        }
    }
    return classList;
}
项目:gw4e.project    文件:GraphWalkerContextManager.java   
public static IJavaProject[] getGW4EProjects() {
    IJavaProject[] projects;
    try {
        projects = JavaCore.create(ResourceManager.getWorkspaceRoot()).getJavaProjects();
    } catch (JavaModelException e) {
        ResourceManager.logException(e);
        projects = new IJavaProject[0];
    }
    List<IJavaProject> gwps = new ArrayList<IJavaProject>();
    for (int i = 0; i < projects.length; i++) {
        if (GW4ENature.hasGW4ENature(projects[i].getProject())) {
            gwps.add(projects[i]);
        }
    }

    IJavaProject[] gwprojects = new IJavaProject[gwps.size()];
    gwps.toArray(gwprojects);
    return gwprojects;
}
项目:gw4e.project    文件:GraphWalkerContextManager.java   
public static IJavaProject chooseGW4EProject(IJavaProject javaProject) {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    IJavaProject[] projects = getGW4EProjects();
    ILabelProvider labelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
    ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, labelProvider);
    dialog.setTitle(MessageUtil.getString("projectdialog_title"));
    dialog.setMessage(MessageUtil.getString("projectdialog_message"));
    dialog.setElements(projects);

    if (javaProject != null) {
        dialog.setInitialSelections(new Object[] { javaProject });
    }
    if (dialog.open() == Window.OK) {
        return (IJavaProject) dialog.getFirstResult();
    }
    return null;
}
项目:gw4e.project    文件:ResourceManager.java   
/**
 * @param project
 * @param qualifiedName
 * @return
 * @throws CoreException
 */
public static IFile getIFileFromQualifiedName(String projectname, String qualifiedName) throws CoreException {
    IProject project = getProject(projectname);
    IJavaProject jproject = JavaCore.create(project);
    IPackageFragment[] pkgs = jproject.getPackageFragments();
    String spath = qualifiedName.replace(".", "/");
    for (int i = 0; i < pkgs.length; i++) {
        if (pkgs[i].getKind() != IPackageFragmentRoot.K_SOURCE)
            continue;
        IPath path = pkgs[i].getPath().append(spath);
        IFile iFile = (IFile) ResourceManager.getResource(path.toString() + ".java");
        if (iFile != null && iFile.exists())
            return iFile;
    }
    return null;
}
项目:gw4e.project    文件:ResourceManager.java   
/**
 * @param projectName
 * @return the direct child folders of the project
 * @throws CoreException
 */
public static List<String> getFilteredSourceFolders(String projectName, String[] excludes) throws CoreException {
    List<String> ret = new ArrayList<String>();
    IJavaProject javaProject = (IJavaProject) JavaCore.create(getProject(projectName));
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath path = entry.getPath().makeRelativeTo(new Path(projectName));
            boolean isExcluded = false;
            for (int j = 0; j < excludes.length; j++) {

                if (excludes[j].equalsIgnoreCase(path.toString())) {
                    isExcluded = true;
                    break;
                }
            }
            if (!isExcluded) {
                String p = path.toString();
                ret.add(p);
            }
        }
    }

    return ret;
}
项目:gw4e.project    文件:ProjectHelper.java   
public static IMarker[] getMarkers(IJavaProject project, int problemID) throws CoreException {
    IMarker[] markers = project.getProject().findMarkers(GW4EBuilder.MARKER_TYPE, true, IResource.DEPTH_INFINITE);
    List<IMarker> ms = new ArrayList<IMarker>();
    for (IMarker iMarker : markers) {
        Object attr = iMarker.getAttribute(IJavaModelMarker.ID);
        Integer pbid = (Integer) attr;
        if (pbid == null)
            continue;
        if (pbid.equals(problemID)) {
            ms.add(iMarker);
        }
    }
    IMarker[] ret = new IMarker[ms.size()];
    ms.toArray(ret);
    return ret;
}
项目:gw4e.project    文件:ResourceManager.java   
/**
 * Return a path relative to its package fragment root
 * 
 * @param project
 * @param path
 * @return
 * @throws JavaModelException
 */
public static IPath getPathWithinPackageFragment(IResource ifile) throws JavaModelException {
    IProject project = ifile.getProject();
    IPath path = ifile.getFullPath();
    String[] segments = path.segments();
    IJavaProject jproject = JavaCore.create(project);
    IPackageFragment[] pkgs = jproject.getPackageFragments();
    IPath p = new Path("/");
    for (int i = 0; i < segments.length; i++) {
        for (int j = 0; j < pkgs.length; j++) {
            if (pkgs[j].getPath().equals(p)) {
                IPath ret = path.makeRelativeTo(pkgs[j].getPath());
                return ret;
            }
        }
        p = p.append(segments[i]);
    }
    return null;
}
项目:gw4e.project    文件:ResourceManager.java   
/**
 * Lets get the path of hat have been selected in the UI - the complete path
 * a path is something like "src/main/resources"
 * 
 * @param receiver
 * @return
 */
public static String getSelectedPathInProject(Object receiver) {
    if (!ResourceManager.isPackageFragmentRoot(receiver)) {
        return null;
    }
    IPackageFragmentRoot pkg = (IPackageFragmentRoot) receiver;

    IJavaProject javaProject = pkg.getJavaProject();
    if (javaProject == null)
        return null;

    IProject project = javaProject.getProject();

    if (!GW4ENature.hasGW4ENature(project))
        return null;

    String projectName = pkg.getJavaProject().getElementName();
    int pos = projectName.length();
    String input = pkg.getPath().toString().substring(pos + 2);
    return input;
}
项目:gw4e.project    文件:ResourceManager.java   
/**
 * Return whether the resource is in of the passed folders
 * 
 * @param resource
 * @param folders
 * @return
 */
public static boolean isFileInFolders(IFile resource, String[] folders) {
    if (resource == null)
        return false;
    IProject p = resource.getProject();
    IJavaProject javaProject = JavaCore.create(p);
    for (int i = 0; i < folders.length; i++) {
        IPath folderPath = javaProject.getPath().append(folders[i]);
        String allowedPAth = folderPath.toString();
        String resourcePath = resource.getFullPath().toString();
        if (resourcePath.startsWith(allowedPAth)) {
            return true;
        }
    }
    return false;
}
项目:gw4e.project    文件:GW4EProject.java   
public void assertHasSourceFolders(String[] folders) throws JavaModelException {
    IProject project = getRoot().getProject(this.projectName);
    IJavaProject jproject = JavaCore.create(project);
    IPackageFragmentRoot[] pkgs = jproject.getPackageFragmentRoots();

    for (int i = 0; i < folders.length; i++) {
        String folder = folders[i];
        boolean found = false;
        for (int j = 0; j < pkgs.length; j++) {
            IPackageFragmentRoot pkg = pkgs[j];
            IPath path = new Path("/").append(this.projectName).append(folder);
            if (pkg.getPath().toString().equalsIgnoreCase(path.toString())) {
                found = true;
            }
            ;
        }
        assertTrue("Expected folder: " + folder, found);
    }
}
项目:java-debug    文件:JavaHotCodeReplaceProvider.java   
/**
 * Returns the class file or compilation unit containing the given fully
 * qualified name in the specified project. All registered java like file
 * extensions are considered.
 *
 * @param qualifiedTypeName
 *            fully qualified type name
 * @param project
 *            project to search in
 * @return class file or compilation unit or <code>null</code>
 * @throws CoreException
 *             if an exception occurs
 */
public static IJavaElement findElement(String qualifiedTypeName, IJavaProject project) throws CoreException {
    String path = qualifiedTypeName;

    final String[] javaLikeExtensions = JavaCore.getJavaLikeExtensions();
    int pos = path.indexOf('$');
    if (pos != -1) {
        path = path.substring(0, pos);
    }
    path = path.replace('.', IPath.SEPARATOR);
    path += "."; //$NON-NLS-1$
    for (String ext : javaLikeExtensions) {
        IJavaElement element = project.findElement(new Path(path + ext));
        if (element != null) {
            return element;
        }
    }
    return null;
}
项目:vertigo-chroma-kspplugin    文件:ResourceUtils.java   
/**
 * Obtient la map Project vers Projet Java du workspace courant.
 * 
 * @return Map des projets.
 */
public static JavaProjectMap getProjectMap() {
    JavaProjectMap projects = new JavaProjectMap();

    /* Racine du workspace courant. */
    IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();

    /* Parcourt les projets de la racine. */
    for (IProject project : wsRoot.getProjects()) {

        /* Vérication que le projet est un projet Java accessible. */
        if (!project.isAccessible() || !JdtUtils.isJavaProject(project)) {
            continue;
        }

        /* Obtient l'AST du projet. */
        IJavaProject javaProject = JavaCore.create(project);
        projects.put(project, javaProject);
    }
    return projects;
}
项目:gw4e.project    文件:ResourceManagerTest.java   
@Test
public void testStripFileExtension() throws Exception {
    IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true, false);
    IFile f = (IFile) ResourceManager
            .getResource(project.getProject().getFullPath().append("src/test/resources/Simple.json").toString());
    IStructuredSelection selection = new StructuredSelection(f);
    String s = ResourceManager.stripFileExtension(selection);
    assertEquals("Simple", s);
}
项目:vertigo-chroma-kspplugin    文件:ServiceManager.java   
@Override
public List<ServiceImplementation> getItems(FileProvider fileProvider) {
    IFile file = fileProvider.getFile();
    IJavaProject javaProject = fileProvider.getJavaProject();

    /* Parse le fichier d'implémentation de service. */
    ServiceFile serviceFile = createServiceFile(file, javaProject);
    if (serviceFile == null) {
        return null; // NOSONAR
    }

    /* Récupère toutes les implémentations. */
    return serviceFile.getServiceImplementations();
}
项目:gw4e.project    文件:GraphWalkerFacadeTest.java   
@Test
public void testGetGraphModels() throws Exception {
    IJavaProject jp = ProjectHelper.createSimpleCompleteProject(PROJECT_NAME);
    List<IFile> models = new ArrayList<IFile> ();
    GraphWalkerFacade.getGraphModels(jp.getProject(),models);
    assertTrue (models.size()==1);
}
项目:bdf2    文件:NodeListManager.java   
private Class<?> getSpecifiedClass(IJavaProject jProject,
        String packageName, String name) throws MalformedURLException,
        ClassNotFoundException, CoreException {
    return Class.forName(
            packageName + "." + name.substring(0, name.indexOf('.')),
            false, ClassHelper.getProjectClassLoader(jProject));
}
项目:Equella    文件:JPFPluginModelManager.java   
@Override
protected IStatus run(IProgressMonitor monitor)
{
    try
    {
        boolean more = false;
        do
        {
            IJavaProject[] projects = null;
            IClasspathContainer[] containers = null;
            synchronized( fProjects )
            {
                projects = fProjects.toArray(new IJavaProject[fProjects.size()]);
                containers = fContainers.toArray(new IClasspathContainer[fContainers.size()]);
                fProjects.clear();
                fContainers.clear();
            }
            JavaCore.setClasspathContainer(JPFClasspathPlugin.CONTAINER_PATH, projects, containers, monitor);
            synchronized( fProjects )
            {
                more = !fProjects.isEmpty();
            }
        }
        while( more );

    }
    catch( JavaModelException e )
    {
        return e.getStatus();
    }
    return Status.OK_STATUS;
}
项目:java-debug    文件:ResolveClasspathsHandler.java   
/**
 * Compute runtime classpath of a java project.
 *
 * @param javaProject
 *            java project
 * @return class path
 * @throws CoreException
 *             CoreException
 */
private static String[][] computeClassPath(IJavaProject javaProject) throws CoreException {
    if (javaProject == null) {
        throw new IllegalArgumentException("javaProject is null");
    }
    String[][] result = new String[2][];
    if (JavaRuntime.isModularProject(javaProject)) {
        result[0] = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
        result[1] = new String[0];
    } else {
        result[0] = new String[0];
        result[1] = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
    }
    return result;
}
项目:gw4e.project    文件:ProjectHelper.java   
public static IFile createDummyClass(IJavaProject project) throws CoreException, IOException {
    String clazz = "import org.graphwalker.core.machine.ExecutionContext ; public class Dummy extends org.gw4e.core.machine.ExecutionContext {}";
    IFolder folder = project.getProject().getFolder("src/test/java");
    IPackageFragmentRoot srcFolder = project.getPackageFragmentRoot(folder);
    IPackageFragment pkg = srcFolder.getPackageFragment("");
    ICompilationUnit cu = pkg.createCompilationUnit("Dummy.java", clazz, false, new NullProgressMonitor());
    cu.save(new NullProgressMonitor (), true);

    return (IFile) cu.getResource();
}
项目:gw4e.project    文件:GW4ECreationWizard.java   
@Override
public IWizardPage getNextPage(IWizardPage page) {
    IWizardPage p = super.getNextPage(page);
    if (page instanceof GW4ETemplatePage) {
        IJavaProject newElement = javaPage.getJavaProject();
        fMavenPage.setProject(newElement.getProject());
    }

    return p;
}
项目:gw4e.project    文件:FolderSelectionGroup.java   
@Override
public Image getImage(Object element) {
    IResource resource = (IResource) element;
    IJavaElement javaElement = JavaCore.create(resource);

    if (javaElement instanceof IJavaProject) {
        return PlatformUI.getWorkbench().getSharedImages().getImage(org.eclipse.ui.ide.IDE.SharedImages.IMG_OBJ_PROJECT);
    }

    org.eclipse.ui.ISharedImages sharedImages= PlatformUI.getWorkbench().getSharedImages();

    Image image = sharedImages.getImage(org.eclipse.ui.ISharedImages.IMG_OBJ_FOLDER);
    return image;

}
项目:gw4e.project    文件:JDTManagerTest.java   
@Test
public void testOpenFileEditor() throws Exception {
    IJavaProject pj = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME,true,false);
    IFile impl = ProjectHelper.createDummyClass (pj);
    IWorkbenchWindow iww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    JDTManager.openFileEditor(impl, "org.eclipse.ui.DefaultTextEditor", iww);
    Waiter.waitUntil(new EditorOpenedCondition("Dummy.java"));
}
项目:gw4e.project    文件:GW4ELaunchConfigurationTab.java   
/**
 * Here is what happen when the button is selected (Selection of a project)
 */
private void handleProjectButtonSelected() {
    IJavaProject project = GraphWalkerContextManager.chooseGW4EProject(getJavaProject());
    if (project == null) {
        return;
    }

    String projectName = project.getElementName();
    fProjText.setText(projectName);
}
项目:gw4e.project    文件:ResourceManagerTest.java   
@Test
public void testFindIContainerString() throws Exception {
    IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true, true);
    IFile impl = (IFile) ResourceManager
            .getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
    IPath p = ResourceManager.find(project.getProject(), impl.getFullPath().toString());
    assertNotNull(p);
}
项目:gw4e.project    文件:MarkerManagerTest.java   
private void addMarker(String msg,int severity) throws Exception {
    IJavaProject pj = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME,true,false);
    IFile file = (IFile) ResourceManager.getResource(pj.getProject().getFullPath().append("src/test/resources/Simple.json").toString());
    MarkerManager.addMarker(file, this, createParserException(msg), severity);
    MarkerCondition mc = new MarkerCondition(pj.getProject(),GW4EBuilder.MARKER_TYPE, msg, severity);
    Waiter.waitUntil(mc);
}
项目:vertigo-chroma-kspplugin    文件:DtoManager.java   
/**
 * Parse un fichier candidat de DTO.
 * 
 * @param file Fichier.
 * @param javaProject Projet Java du fichier.
 * @return Le DTO, <code>null</code> sinon.
 */
private DtoFile createDtoFile(IFile file, IJavaProject javaProject) {

    /* Charge l'AST du fichier Java. */
    ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(file, javaProject);
    if (compilationUnit == null) {
        return null;
    }
    List<String> dtoParentClassesList = LegacyManager.getInstance().getDtoParentsClasseList(javaProject.getProject());
    try {
        LegacyStrategy strategy = LegacyManager.getInstance().getStrategy(file);
        /* Parcourt les types du fichier Java. */
        for (IType type : compilationUnit.getAllTypes()) {

            /* Vérifie que c'est un Dto */
            boolean isDtoType = strategy.isDtoType(type) || JdtUtils.isSubclass(type, dtoParentClassesList);

            if (!isDtoType) {
                continue;
            }

            /* Parse les champs. */
            List<DtoField> fields = strategy.parseDtoFields(type);

            /* Créé le DtoFile. */
            String javaName = type.getElementName();
            String packageName = type.getPackageFragment().getElementName();
            ISourceRange nameRange = type.getNameRange();
            FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
            return new DtoFile(fileRegion, javaName, packageName, fields);
        }
    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }

    return null;
}
项目:gw4e.project    文件:ResourceManagerTest.java   
@Test
public void testIsPackageFragmentRoot() throws Exception {
    IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true, false);
    ResourceManager.createFile(project.getProject().getName(), "src/test/resources", "mypkg/subpkg", "test.java",
            "");

    IPackageFragment frag = (IPackageFragment) project.findElement(new Path("mypkg/subpkg"));
    IPackageFragmentRoot pfr = ResourceManager.getPackageFragmentRoot(project.getProject(), frag);

    boolean b = ResourceManager.isPackageFragmentRoot(pfr);
    assertTrue(b);

    b = ResourceManager.isPackageFragmentRoot(project);
    assertFalse(b);
}
项目:gw4e.project    文件:JDTManagerTest.java   
@Test
public void testToJavaProject() throws Exception {
    IJavaProject pj = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME,true,false);
    IProject p = JDTManager.toJavaProject(pj);
    assertNotNull (p);
    p = JDTManager.toJavaProject(pj.getProject());
    assertNotNull (p);
}
项目:gw4e.project    文件:ClasspathManager.java   
/**
 * Return whether folderPath has children in the classpath
 * 
 * @param project
 * @param folderPath
 * @param monitor
 * @return
 * @throws JavaModelException
 */
public static IResource childrenExistInClasspath(IProject project, String folderPath, IProgressMonitor monitor)
        throws JavaModelException {
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    IPath folder = project.getFolder(folderPath).getFullPath();
    for (int i = 0; i < entries.length; i++) {
        if (folder.isPrefixOf(entries[i].getPath())) {
            IPath path = entries[i].getPath();
            IResource resource = ResourceManager.getResource(path.toString());
            return resource;
        }
    }
    return null;
}
项目:visuflow-plugin    文件:JimpleBuilder.java   
/**
 * @param javaProject
 * @return Set of the locations of jars for the soot classpath
 * @throws JavaModelException
 * 
 * This method computes the locations of the jar files necessary for the soot run
 */
protected Set<String> getJarFilesLocation(IJavaProject javaProject) throws JavaModelException {
    Set<String> jars = new HashSet<>();
    IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(true);
    for (IClasspathEntry classpathEntry : resolvedClasspath) {
        String path = classpathEntry.getPath().toOSString();
        if (path.endsWith(".jar")) {
            IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(classpathEntry.getPath());
            if (file != null && file.getRawLocation() != null)
                path = file.getRawLocation().toOSString();
            jars.add(path);
        }
    }
    return jars;
}
项目:gw4e.project    文件:ClasspathManager.java   
/**
 * Remove GW4E ClassPath Container
 * 
 * @param project
 * @param monitor
 * @throws JavaModelException
 */
public static void removeGW4EClassPathContainer(IProject project, IProgressMonitor monitor)
        throws JavaModelException {
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
    for (int i = 0; i < entries.length; i++) {
        if (!GW4ELibrariesContainer.isMe(entries[i])) {
            newEntries.add(entries[i]);
        }
    }
    entries = new IClasspathEntry[newEntries.size()];
    newEntries.toArray(entries);
    javaProject.setRawClasspath(entries, monitor);
}
项目:visuflow-plugin    文件:WizardHandler.java   
private void doFinish(
        String targetProjectPath,
        String analysisProjectName,
        IProgressMonitor monitor)
                throws CoreException, IOException {
    monitor.beginTask("Creating " +analysisProjectName, 2);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    ProjectGenerator projectGen = new ProjectGenerator();
    IJavaProject sourceProject = projectGen.createProject(wizardInput);
    IResource resourceTarget = root.findMember(new Path(targetProjectPath));
    IJavaProject targetProject = JavaCore.create(resourceTarget.getProject());
    GlobalSettings.put("Target_Path",resourceTarget.getLocation().toOSString()+ File.separator +  targetProject.getOutputLocation().lastSegment());
    GlobalSettings.put("AnalysisProject", sourceProject.getProject().getName());
    GlobalSettings.put("TargetProject", targetProject.getProject().getName());
    ProjectPreferences projPref = new ProjectPreferences();
    projPref.createPreferences();
    AddRemoveVisuFlowNatureHandler addNature = new AddRemoveVisuFlowNatureHandler();
    try {
        if(!sourceProject.getProject().isNatureEnabled("JimpleBuilder.VisuFlowNature"))
            addNature.toggleNature(sourceProject.getProject());
    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    ServiceUtil.getService(DataModel.class).triggerProjectRebuild();
    monitor.worked(1);
    monitor.setTaskName("Opening file for editing...");
    getShell().getDisplay().asyncExec(new Runnable() {
        @Override
        public void run() {

        }
    });
    monitor.worked(1);
}
项目:gw4e.project    文件:JDTManager.java   
/**
 * Return a package fragment with the passed path
 * 
 * @param project
 * @param path
 * @return
 * @throws JavaModelException
 */
public static IPackageFragmentRoot getPackageFragmentRoot(IProject project, IPath path) throws JavaModelException {
    IJavaProject javaProject = JavaCore.create(project);
    IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
    for (int i = 0; i < roots.length; i++) {
        if (roots[i].getPath().equals(path))
            return roots[i];
    }
    return null;
}
项目:Hydrograph    文件:CategoriesDialogSourceComposite.java   
@SuppressWarnings("restriction")
private void loadComboJarListFromBuildPath(Combo comboJarList, String newJarName) {
    comboJarList.removeAll();
    IProject iProject = BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject();
    IJavaProject iJavaProject=null;
    try {
        iJavaProject = JavaCore.create(iProject);
        PackageFragmentRoot srcfragmentRoot= BuildExpressionEditorDataSturcture.INSTANCE.getSrcPackageFragment(iJavaProject);
        comboJarList.add(hydrograph.ui.common.util.Constants.ProjectSupport_SRC);
        comboJarList.setData(String.valueOf(comboJarList.getItemCount() - 1), srcfragmentRoot);

        for (IPackageFragmentRoot iPackageFragmentRoot : iJavaProject.getAllPackageFragmentRoots()) {
            if (isJarPresentInLibFolder(iPackageFragmentRoot.getPath())
                    && iPackageFragmentRoot.getKind() != IPackageFragmentRoot.K_SOURCE) {
                comboJarList.add(iPackageFragmentRoot.getElementName());
                comboJarList.setData(String.valueOf(comboJarList.getItemCount() - 1), iPackageFragmentRoot);
            }
        }
        selectAndLoadJarData(newJarName);
    } catch (JavaModelException javaModelException) {
        LOGGER.error("Error occurred while loading engines-transform jar", javaModelException);
    }
    finally{
        if(iJavaProject!=null){
            try {
                iJavaProject.close();
            } catch (JavaModelException e) {
                LOGGER.warn("JavaModelException occurred while closing java-project"+e);
            }
        }
    }

}
项目:gw4e.project    文件:JDTManagerTest.java   
@Test
public void testFindGeneratorFactoryParseInvocation() throws Exception {
    IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true,true);
    IFile impl = (IFile) ResourceManager
            .getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());

    IOHelper.appendParseGeneratorCall (impl);
    IType type = project.findType("SimpleImpl");
    Set<String> invocations = JDTManager.findGeneratorFactoryParseInvocation(project.getProject(), type);
    assertEquals (1,invocations.size());
    String value = invocations.iterator().next();
    assertEquals("random(edge_coverage(100))", value);
}
项目:gw4e.project    文件:ClasspathManagerTest.java   
@Test
public void testRemoveGraphWalkerClassPathContainer() throws Exception {
    IJavaProject p = ProjectHelper.getProject(PROJECT_NAME);
    ClasspathManager.addGW4EClassPathContainer(p.getProject());
    boolean has = ClasspathManager.hasGW4EClassPathContainer(p.getProject());
    assertTrue("Project has GW Library ", has);
    ClasspathManager.removeGW4EClassPathContainer(p.getProject(), null);
    has = ClasspathManager.hasGW4EClassPathContainer(p.getProject());
    assertFalse("Project has not GW Library ", has);
}
项目:gw4e.project    文件:JDTManagerTest.java   
@Test
public void testHasGraphWalkerAnnotation() throws Exception {
    IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true,true);
    IFile impl = (IFile) ResourceManager
            .getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
    ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(impl);
    boolean b = JDTManager.hasGraphWalkerAnnotation(compilationUnit);
    assertEquals(true, b);
}