Search in sources :

Example 61 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project xtext-xtend by eclipse.

the class XbaseEditorOpenClassFileTest method addJarToClassPath.

public IPackageFragmentRoot addJarToClassPath(final IJavaProject jp, final String fileName, final String fileNameOfSource) {
    try {
        IProject _project = jp.getProject();
        Path _path = new Path(fileName);
        final IFile jarFile = _project.getFile(_path);
        jarFile.create(this.getClass().getResourceAsStream(fileName), true, null);
        IFile _xifexpression = null;
        if ((fileNameOfSource != null)) {
            IFile _xblockexpression = null;
            {
                IProject _project_1 = jp.getProject();
                Path _path_1 = new Path(fileNameOfSource);
                final IFile source = _project_1.getFile(_path_1);
                source.create(this.getClass().getResourceAsStream(fileNameOfSource), true, null);
                _xblockexpression = source;
            }
            _xifexpression = _xblockexpression;
        }
        final IFile sourceFile = _xifexpression;
        IPath _fullPath = jarFile.getFullPath();
        IPath _fullPath_1 = null;
        if (sourceFile != null) {
            _fullPath_1 = sourceFile.getFullPath();
        }
        final IClasspathEntry cp = JavaCore.newLibraryEntry(_fullPath, _fullPath_1, null);
        JavaProjectSetupUtil.addToClasspath(jp, cp);
        return JavaCore.createJarPackageFragmentRootFrom(jarFile);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IProject(org.eclipse.core.resources.IProject)

Example 62 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project xtext-xtend by eclipse.

the class PerformanceTestProjectSetup method createJavaProject.

public static IJavaProject createJavaProject(final String projectName, String[] projectNatures) {
    IProject project = null;
    IJavaProject javaProject = null;
    try {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        project = workspace.getRoot().getProject(projectName);
        deleteProject(project);
        javaProject = JavaCore.create(project);
        IProjectDescription projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
        project.create(projectDescription, null);
        List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
        projectDescription.setNatureIds(projectNatures);
        final ICommand java = projectDescription.newCommand();
        java.setBuilderName(JavaCore.BUILDER_ID);
        final ICommand manifest = projectDescription.newCommand();
        manifest.setBuilderName("org.eclipse.pde.ManifestBuilder");
        final ICommand schema = projectDescription.newCommand();
        schema.setBuilderName("org.eclipse.pde.SchemaBuilder");
        projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema });
        project.open(null);
        project.setDescription(projectDescription, null);
        classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5")));
        classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins")));
        javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), null);
        makeJava5Compliant(javaProject);
        javaProject.setOutputLocation(new Path("/" + projectName + "/bin"), null);
        createManifest(projectName, project);
        // project.build(IncrementalProjectBuilder.FULL_BUILD, null);
        refreshExternalArchives(javaProject);
        refresh(javaProject);
    } catch (final Exception exception) {
        throw new RuntimeException(exception);
    }
    return javaProject;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ICommand(org.eclipse.core.resources.ICommand) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException)

Example 63 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project jop by jop-devel.

the class JOPizer method getClassesClasspathEntry.

private IClasspathEntry getClassesClasspathEntry() throws JavaModelException {
    IPreferenceStore prefs = JOPUIPlugin.getDefault().getPreferenceStore();
    String jopHome = prefs.getString(IJOPLaunchConfigurationConstants.ATTR_JOP_HOME);
    IPath jopClasses = new Path(jopHome).append(new Path("java/target/dist/lib/classes.zip"));
    IClasspathEntry[] entries = currentProject.getRawClasspath();
    for (IClasspathEntry entry : entries) {
        if (entry.getPath().equals(jopClasses)) {
            return entry;
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 64 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class ClasspathBuilder method addSourceFolders.

private void addSourceFolders(IJavaProject project, List<String> sourceFolders, List<IClasspathEntry> classpathEntries) {
    for (String source : sourceFolders) {
        IFolder src = project.getProject().getFolder(source);
        if (src.exists()) {
            IClasspathEntry sourceEntry = JavaCore.newSourceEntry(src.getFullPath());
            classpathEntries.add(sourceEntry);
        }
    }
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IFolder(org.eclipse.core.resources.IFolder)

Example 65 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class PlainJavaInitHandler method initializeClasspath.

@Override
protected void initializeClasspath(IJavaProject javaProject) throws ServerException {
    IClasspathEntry[] projectClasspath;
    try {
        projectClasspath = javaProject.getRawClasspath();
    } catch (JavaModelException e) {
        LOG.warn("Can't get classpath for: " + javaProject.getProject().getFullPath().toOSString(), e);
        throw new ServerException(e);
    }
    //default classpath
    IClasspathEntry[] defaultClasspath = new IClasspathEntry[] { JavaCore.newSourceEntry(javaProject.getPath()) };
    if (!Arrays.equals(defaultClasspath, projectClasspath)) {
        //classpath is already initialized
        return;
    }
    RegisteredProject project = projectRegistryProvider.get().getProject(javaProject.getPath().toOSString());
    List<String> sourceFolders = project.getAttributes().get(Constants.SOURCE_FOLDER);
    List<String> library = project.getAttributes().get(LIBRARY_FOLDER);
    classpathBuilder.generateClasspath(javaProject, sourceFolders, library);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) ServerException(org.eclipse.che.api.core.ServerException) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject)

Aggregations

IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)123 IPath (org.eclipse.core.runtime.IPath)55 IJavaProject (org.eclipse.jdt.core.IJavaProject)44 ArrayList (java.util.ArrayList)35 Path (org.eclipse.core.runtime.Path)27 JavaModelException (org.eclipse.jdt.core.JavaModelException)23 IProject (org.eclipse.core.resources.IProject)20 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)16 File (java.io.File)15 IFolder (org.eclipse.core.resources.IFolder)13 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 CoreException (org.eclipse.core.runtime.CoreException)12 IJavaElement (org.eclipse.jdt.core.IJavaElement)12 JavaProject (org.eclipse.jdt.internal.core.JavaProject)11 IFile (org.eclipse.core.resources.IFile)10 IResource (org.eclipse.core.resources.IResource)10 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)8 IOException (java.io.IOException)7 URL (java.net.URL)7