use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.
the class ClasspathUpdaterService method createModifiedEntry.
private IClasspathEntry[] createModifiedEntry(List<ClasspathEntryDto> entries) {
List<IClasspathEntry> coreClasspathEntries = new ArrayList<>(entries.size());
for (ClasspathEntryDto entry : entries) {
IPath path = fromOSString(entry.getPath());
int entryKind = entry.getEntryKind();
if (IClasspathEntry.CPE_LIBRARY == entryKind) {
coreClasspathEntries.add(newLibraryEntry(path, null, null));
} else if (IClasspathEntry.CPE_SOURCE == entryKind) {
coreClasspathEntries.add(newSourceEntry(path));
} else if (IClasspathEntry.CPE_VARIABLE == entryKind) {
coreClasspathEntries.add(newVariableEntry(path, null, null));
} else if (IClasspathEntry.CPE_CONTAINER == entryKind) {
coreClasspathEntries.add(newContainerEntry(path));
} else if (IClasspathEntry.CPE_PROJECT == entryKind) {
coreClasspathEntries.add(newProjectEntry(path));
}
}
return coreClasspathEntries.toArray(new IClasspathEntry[coreClasspathEntries.size()]);
}
use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.
the class ClasspathBuilderTest method classpathShouldBeUpdatedOnlyWithJREContainer.
@Test
public void classpathShouldBeUpdatedOnlyWithJREContainer() throws Exception {
classpathBuilder.generateClasspath(iJavaProject, sourceFolders, library);
ArgumentCaptor<IClasspathEntry[]> classpathEntries = ArgumentCaptor.forClass(IClasspathEntry[].class);
verify(iJavaProject).setRawClasspath(classpathEntries.capture(), eq(null));
assertEquals(1, classpathEntries.getValue().length);
assertEquals(new Path(JREContainerInitializer.JRE_CONTAINER), classpathEntries.getValue()[0].getPath());
}
use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.
the class ClasspathBuilder method addJars.
private void addJars(IJavaProject project, List<String> library, final List<IClasspathEntry> classpathEntries) {
if (library == null || library.isEmpty()) {
return;
}
for (String libFolder : library) {
if (libFolder.isEmpty()) {
continue;
}
IFolder libraryFolder = project.getProject().getFolder(libFolder);
if (!libraryFolder.exists()) {
return;
}
try {
libraryFolder.accept(proxy -> {
if (IResource.FILE != proxy.getType()) {
return true;
}
IPath path = proxy.requestFullPath();
if (!path.toString().endsWith(".jar")) {
return false;
}
IClasspathEntry libEntry = JavaCore.newLibraryEntry(proxy.requestResource().getLocation(), null, null);
classpathEntries.add(libEntry);
return false;
}, IContainer.INCLUDE_PHANTOMS);
} catch (CoreException e) {
LOG.warn("Can't read folder structure: " + libraryFolder.getFullPath().toString());
}
}
}
use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.
the class ClasspathBuilder method generateClasspath.
/**
* Generates classpath with default entries.
*
* @param project
* java project which need to contain classpath
* @param sourceFolders
* list of the project's source folders
* @param library
* list of the project's library folders
* @throws ServerException
* happens when some problems with setting classpath
*/
public void generateClasspath(IJavaProject project, List<String> sourceFolders, List<String> library) throws ServerException {
List<IClasspathEntry> classpathEntries = new ArrayList<>();
//create classpath container for default JRE
IClasspathEntry jreContainer = JavaCore.newContainerEntry(new Path(JREContainerInitializer.JRE_CONTAINER));
classpathEntries.add(jreContainer);
addSourceFolders(project, sourceFolders, classpathEntries);
addJars(project, library, classpathEntries);
try {
project.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), null);
} catch (JavaModelException e) {
LOG.warn("Can't set classpath for: " + project.getProject().getFullPath().toOSString(), e);
throw new ServerException(e);
}
}
use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.
the class JavaProjectHelper method addClassFolder.
/**
* Creates and adds a class folder to the class path.
* @param jproject The parent project
* @param containerName
* @param sourceAttachPath The source attachment path
* @param sourceAttachRoot The source attachment root path
* @return The handle of the created root
* @throws CoreException
*/
public static IPackageFragmentRoot addClassFolder(IJavaProject jproject, String containerName, IPath sourceAttachPath, IPath sourceAttachRoot) throws CoreException {
IProject project = jproject.getProject();
IContainer container = null;
if (containerName == null || containerName.length() == 0) {
container = project;
} else {
IFolder folder = project.getFolder(containerName);
if (!folder.exists()) {
CoreUtility.createFolder(folder, false, true, null);
}
container = folder;
}
IClasspathEntry cpe = JavaCore.newLibraryEntry(container.getFullPath(), sourceAttachPath, sourceAttachRoot);
addToClasspath(jproject, cpe);
return jproject.getPackageFragmentRoot(container);
}
Aggregations