Example usage for org.eclipse.jdt.core IJavaProject getProject

List of usage examples for org.eclipse.jdt.core IJavaProject getProject

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getProject.

Prototype

IProject getProject();

Source Link

Document

Returns the IProject on which this IJavaProject was created.

Usage

From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonClasspathInitializer.java

License:Apache License

public Object getComparisonID(IPath containerPath, IJavaProject project) {
    return project.getProject().getName() + "/" + containerPath;
}

From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonProjectModulesContainer.java

License:Apache License

/**
 * Resolves the classpath entries for this container.
 * @param monitor//from   w  w w. j  a v  a 2s .  c om
 * @param reparse
 * @return true if the classpath was changed, false otherwise.
 */
public boolean resolveClasspath(IProgressMonitor monitor, boolean reparse) {
    IJavaProject javaProject = getJavaProject();
    IProject project = javaProject.getProject();

    try {

        TypeChecker typeChecker = null;
        if (!reparse) {
            typeChecker = getProjectTypeChecker(project);
        }
        IClasspathEntry[] oldEntries = classpathEntries;
        if (typeChecker == null) {
            IClasspathEntry explodeFolderEntry = null;
            if (oldEntries != null) {
                for (IClasspathEntry entry : oldEntries) {
                    if (entry.getPath() != null
                            && entry.getPath().equals(getCeylonClassesOutputFolder(project).getFullPath())) {
                        explodeFolderEntry = entry;
                        break;
                    }
                }
            }

            IClasspathEntry[] resetEntries = explodeFolderEntry == null ? new IClasspathEntry[] {}
                    : new IClasspathEntry[] { explodeFolderEntry };

            JavaCore.setClasspathContainer(getPath(), new IJavaProject[] { javaProject },
                    new IClasspathContainer[] { new CeylonProjectModulesContainer(javaProject, getPath(),
                            resetEntries, attributes) },
                    monitor);
            typeChecker = parseCeylonModel(project, monitor);
        }

        IFolder explodedModulesFolder = getCeylonClassesOutputFolder(project);
        if (isExplodeModulesEnabled(project)) {
            if (!explodedModulesFolder.exists()) {
                CoreUtility.createDerivedFolder(explodedModulesFolder, true, true, monitor);
            } else {
                if (!explodedModulesFolder.isDerived()) {
                    explodedModulesFolder.setDerived(true, monitor);
                }
            }
        } else {
            if (explodedModulesFolder.exists()) {
                explodedModulesFolder.delete(true, monitor);
            }
        }

        final Collection<IClasspathEntry> paths = findModuleArchivePaths(javaProject, project, typeChecker);

        CeylonProjectModulesContainer currentContainer = (CeylonProjectModulesContainer) JavaCore
                .getClasspathContainer(path, javaProject);
        if (oldEntries == null || oldEntries != currentContainer.classpathEntries
                || !paths.equals(asList(oldEntries))) {
            this.classpathEntries = paths.toArray(new IClasspathEntry[paths.size()]);
            return true;
        }
    } catch (CoreException e) {
        e.printStackTrace();
    }
    return false;

}

From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonProjectModulesContainer.java

License:Apache License

public void refreshClasspathContainer(IProgressMonitor monitor) throws JavaModelException {
    IJavaProject javaProject = getJavaProject();
    setClasspathContainer(path, new IJavaProject[] { javaProject },
            new IClasspathContainer[] { new CeylonProjectModulesContainer(this) },
            new SubProgressMonitor(monitor, 1));
    JDTModelLoader modelLoader = CeylonBuilder.getProjectModelLoader(javaProject.getProject());
    if (modelLoader != null) {
        modelLoader.refreshNameEnvironment();
    }//from  ww  w  .  j a v a 2  s. c  o  m
    //update the package manager UI
    new Job("update package manager") {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            notifyUpdateClasspathEntries();
            return Status.OK_STATUS;
        }
    }.schedule();
}

From source file:com.redhat.ceylon.eclipse.core.classpath.FakeProjectManager.java

License:Apache License

public static boolean isFake(IJavaProject project) {
    // a fake project doesn't have real path
    return project.getProject().getLocation() == null;
}

From source file:com.redhat.ceylon.eclipse.core.model.JDTModelLoader.java

License:Open Source License

public static JDTModelLoader getModelLoader(IJavaProject javaProject) {
    return getModelLoader(javaProject.getProject());
}

From source file:com.redhat.ceylon.eclipse.core.model.JDTModule.java

License:Open Source License

synchronized void setArtifact(ArtifactResult artifactResult) {
    artifact = artifactResult.artifact();
    repositoryDisplayString = artifactResult.repositoryDisplayString();

    if (artifact.getName().endsWith(ArtifactContext.SRC)) {
        moduleType = ModuleType.CEYLON_SOURCE_ARCHIVE;
    } else if (artifact.getName().endsWith(ArtifactContext.CAR)) {
        moduleType = ModuleType.CEYLON_BINARY_ARCHIVE;
    } else if (artifact.getName().endsWith(ArtifactContext.JAR)) {
        moduleType = ModuleType.JAVA_BINARY_ARCHIVE;
    }/*  w  w w  .j a  v a2s .  c  o m*/

    artifactType = artifactResult.type();
    if (isCeylonBinaryArchive()) {
        String carPath = artifact.getPath();
        sourceArchivePath = carPath.substring(0, carPath.length() - ArtifactContext.CAR.length())
                + ArtifactContext.SRC;
        try {
            classesToSources = CarUtils.retrieveMappingFile(returnCarFile());
            javaImplFilesToCeylonDeclFiles = CarUtils.searchCeylonFilesForJavaImplementations(classesToSources,
                    new File(sourceArchivePath));
        } catch (Exception e) {
            CeylonPlugin.getInstance().getLog().log(new Status(IStatus.WARNING, CeylonPlugin.PLUGIN_ID,
                    "Cannot find the source archive for the Ceylon binary module " + getSignature(), e));
        }
        class BinaryPhasedUnits extends PhasedUnitMap<ExternalPhasedUnit, SoftReference<ExternalPhasedUnit>> {
            Set<String> sourceCannotBeResolved = new HashSet<String>();

            public BinaryPhasedUnits() {
                String fullPathPrefix = sourceArchivePath + "!/";
                for (Object value : classesToSources.values()) {
                    String sourceRelativePath = (String) value;
                    String path = fullPathPrefix + sourceRelativePath;
                    phasedUnitPerPath.put(path, new SoftReference<ExternalPhasedUnit>(null));
                    relativePathToPath.put(sourceRelativePath, path);
                }
            }

            @Override
            public ExternalPhasedUnit getPhasedUnit(String path) {
                if (!phasedUnitPerPath.containsKey(path)) {
                    if (path.endsWith(".ceylon")) {
                        // Case of a Ceylon file with a Java implementation, the classesToSources key is the Java source file.
                        String javaFileRelativePath = getJavaImplementationFile(
                                path.replace(sourceArchivePath + "!/", ""));
                        if (javaFileRelativePath != null) {
                            return super.getPhasedUnit(sourceArchivePath + "!/" + javaFileRelativePath);
                        }
                    }
                    return null;
                }
                return super.getPhasedUnit(path);
            }

            @Override
            public ExternalPhasedUnit getPhasedUnitFromRelativePath(String relativePath) {
                if (relativePath.startsWith("/")) {
                    relativePath = relativePath.substring(1);
                }
                if (!relativePathToPath.containsKey(relativePath)) {
                    if (relativePath.endsWith(".ceylon")) {
                        // Case of a Ceylon file with a Java implementation, the classesToSources key is the Java source file.
                        String javaFileRelativePath = getJavaImplementationFile(relativePath);
                        if (javaFileRelativePath != null) {
                            return super.getPhasedUnitFromRelativePath(javaFileRelativePath);
                        }
                    }
                    return null;
                }
                return super.getPhasedUnitFromRelativePath(relativePath);
            }

            @Override
            protected ExternalPhasedUnit fromStoredType(SoftReference<ExternalPhasedUnit> storedValue,
                    String path) {
                ExternalPhasedUnit result = storedValue.get();
                if (result == null) {
                    if (!sourceCannotBeResolved.contains(path)) {
                        result = buildPhasedUnitForBinaryUnit(path);
                        if (result != null) {
                            phasedUnitPerPath.put(path, toStoredType(result));
                        } else {
                            sourceCannotBeResolved.add(path);
                        }
                    }
                }
                return result;
            }

            @Override
            protected void addInReturnedList(List<ExternalPhasedUnit> list, ExternalPhasedUnit phasedUnit) {
                if (phasedUnit != null) {
                    list.add(phasedUnit);
                }
            }

            @Override
            protected SoftReference<ExternalPhasedUnit> toStoredType(ExternalPhasedUnit phasedUnit) {
                return new SoftReference<ExternalPhasedUnit>(phasedUnit);
            }

            @Override
            public void removePhasedUnitForRelativePath(String relativePath) {
                // Don't clean the Package since we are in the binary case 
                String path = relativePathToPath.get(relativePath);
                relativePathToPath.remove(relativePath);
                phasedUnitPerPath.remove(path);
            }

        }
        ;
        binaryModulePhasedUnits = new BinaryPhasedUnits();
    }

    if (isSourceArchive()) {
        sourceArchivePath = artifact.getPath();
        try {
            classesToSources = CarUtils.retrieveMappingFile(returnCarFile());
            javaImplFilesToCeylonDeclFiles = CarUtils.searchCeylonFilesForJavaImplementations(classesToSources,
                    artifact);
        } catch (Exception e) {
            e.printStackTrace();
        }
        sourceModulePhasedUnits = new WeakReference<ExternalModulePhasedUnits>(null);
    }

    try {
        IJavaProject javaProject = moduleManager.getJavaProject();
        if (javaProject != null) {
            for (IProject refProject : javaProject.getProject().getReferencedProjects()) {
                if (artifact.getAbsolutePath().contains(
                        CeylonBuilder.getCeylonModulesOutputDirectory(refProject).getAbsolutePath())) {
                    originalProject = refProject;
                }
            }
        }
    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if (isJavaBinaryArchive()) {
        String carPath = artifact.getPath();
        sourceArchivePath = carPath.substring(0, carPath.length() - ArtifactContext.JAR.length())
                + (artifactResult.type().equals(ArtifactResultType.MAVEN) ? ArtifactContext.MAVEN_SRC
                        : ArtifactContext.SRC);
    }
}

From source file:com.redhat.ceylon.eclipse.core.model.JDTModule.java

License:Open Source License

public synchronized List<IPackageFragmentRoot> getPackageFragmentRoots() {
    if (packageFragmentRoots.isEmpty() && !moduleManager.isExternalModuleLoadedFromSource(getNameAsString())) {
        IJavaProject javaProject = moduleManager.getJavaProject();
        if (javaProject != null) {
            if (this.equals(getLanguageModule())) {
                IClasspathEntry runtimeClasspathEntry = null;

                try {
                    for (IClasspathEntry entry : javaProject.getRawClasspath()) {
                        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().segment(0)
                                .equals(CeylonLanguageModuleContainer.CONTAINER_ID)) {
                            runtimeClasspathEntry = entry;
                            break;
                        }/*w w  w.  jav a  2s .  c  om*/
                    }

                    if (runtimeClasspathEntry != null) {
                        for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
                            if (root.exists() && javaProject.isOnClasspath(root)
                                    && root.getRawClasspathEntry().equals(runtimeClasspathEntry)) {
                                packageFragmentRoots.add(root);
                            }
                        }
                    }
                } catch (JavaModelException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } else {
                File jarToSearch = null;
                try {
                    jarToSearch = returnCarFile();
                    if (jarToSearch == null) {
                        RepositoryManager repoMgr = CeylonBuilder
                                .getProjectRepositoryManager(javaProject.getProject());
                        if (repoMgr != null) {
                            jarToSearch = CeylonProjectModulesContainer.getModuleArtifact(repoMgr, this);
                        }
                    }

                    if (jarToSearch != null) {
                        IPackageFragmentRoot root = moduleManager.getJavaProject()
                                .getPackageFragmentRoot(jarToSearch.toString());
                        if (root instanceof JarPackageFragmentRoot) {
                            JarPackageFragmentRoot jarRoot = (JarPackageFragmentRoot) root;
                            if (jarRoot.getJar().getName().equals(jarToSearch.getPath())) {
                                packageFragmentRoots.add(root);
                            }
                        }
                    }
                } catch (CoreException e) {
                    if (jarToSearch != null) {
                        System.err.println("Exception trying to get Jar file '" + jarToSearch + "' :");
                    }
                    e.printStackTrace();
                }
            }
        }
    }
    return packageFragmentRoots;
}

From source file:com.redhat.ceylon.eclipse.core.model.JDTModule.java

License:Open Source License

private ModuleDependencies getProjectModuleDependencies() {
    if (projectModuleDependencies == null) {
        IJavaProject javaProject = moduleManager.getJavaProject();
        if (javaProject != null) {
            projectModuleDependencies = CeylonBuilder.getModuleDependenciesForProject(javaProject.getProject());
        }/* ww w . jav  a2  s .c o  m*/
    }
    return projectModuleDependencies;
}

From source file:com.redhat.ceylon.eclipse.core.model.JDTModuleManager.java

License:Open Source License

public JDTModuleManager(Context context, IJavaProject javaProject) {
    super(context);
    this.javaProject = javaProject;
    if (javaProject == null) {
        loadDependenciesFromModelLoaderFirst = false;
    } else {//from w w  w. j  a v  a  2 s  .c o m
        loadDependenciesFromModelLoaderFirst = CeylonBuilder
                .loadDependenciesFromModelLoaderFirst(javaProject.getProject());
    }
    sourceModules = new HashSet<String>();
    if (!loadDependenciesFromModelLoaderFirst) {
        sourceModules.add(Module.LANGUAGE_MODULE_NAME);
    }
}

From source file:com.sabre.buildergenerator.TestHelper.java

License:Open Source License

public static void deleteJavaProject(IJavaProject javaProject) throws CoreException {
    WaitingProgressMonitor progressMonitor = new WaitingProgressMonitor();
    javaProject.getProject().delete(true, progressMonitor);
    progressMonitor.waitTillDone(5000);/* ww  w  . ja va  2 s . c  o  m*/
}