use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.
the class RefactoringTest method restoreTestProject.
private void restoreTestProject() throws Exception {
IJavaProject javaProject = getRoot().getJavaProject();
if (javaProject.exists()) {
IClasspathEntry srcEntry = getRoot().getRawClasspathEntry();
IClasspathEntry jreEntry = RefactoringTestSetup.getJRELibrary().getRawClasspathEntry();
IClasspathEntry[] cpes = javaProject.getRawClasspath();
ArrayList newCPEs = new ArrayList();
boolean cpChanged = false;
for (int i = 0; i < cpes.length; i++) {
IClasspathEntry cpe = cpes[i];
if (cpe.equals(srcEntry) || cpe.equals(jreEntry)) {
newCPEs.add(cpe);
} else {
cpChanged = true;
}
}
if (cpChanged) {
IClasspathEntry[] newCPEsArray = (IClasspathEntry[]) newCPEs.toArray(new IClasspathEntry[newCPEs.size()]);
javaProject.setRawClasspath(newCPEsArray, null);
}
Object[] nonJavaResources = javaProject.getNonJavaResources();
for (int i = 0; i < nonJavaResources.length; i++) {
Object kid = nonJavaResources[i];
if (kid instanceof IResource) {
IResource resource = (IResource) kid;
if (!PROJECT_RESOURCE_CHILDREN.contains(resource.getName())) {
JavaProjectHelper.delete(resource);
}
}
}
}
}
use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.
the class MavenClasspathUtil method readMavenClasspath.
public static IClasspathContainer readMavenClasspath(IJavaProject javaProject) {
IFile file = javaProject.getProject().getFile(".che/classpath.maven");
IClasspathEntry[] entries;
if (file.exists()) {
try {
char[] chars = Util.getResourceContentsAsCharArray(file);
String content = new String(chars);
if (!content.isEmpty()) {
String[] pathToJars = content.split(":");
List<IClasspathEntry> classpathEntry = new ArrayList<>();
for (String path : pathToJars) {
String srcPath = path.substring(0, path.lastIndexOf('.')) + "-sources.jar";
classpathEntry.add(JavaCore.newLibraryEntry(new org.eclipse.core.runtime.Path(path), new org.eclipse.core.runtime.Path(srcPath), null));
}
entries = classpathEntry.toArray(new IClasspathEntry[classpathEntry.size()]);
} else {
entries = EMPTY;
}
} catch (JavaModelException e) {
LOG.error("Can't read maven classpath.", e);
entries = EMPTY;
}
} else {
entries = EMPTY;
}
return new MavenClasspathContainer(entries);
}
use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.
the class ClasspathManager method updateClasspath.
public void updateClasspath(MavenProject mavenProject) {
IJavaProject javaProject = JavaCore.create(mavenProject.getProject());
if (javaProject != null) {
IClasspathEntry[] entries = getClasspath(mavenProject);
MavenClasspathContainer container = new MavenClasspathContainer(entries);
try {
JavaCore.setClasspathContainer(new Path(MavenClasspathContainer.CONTAINER_ID), new IJavaProject[] { javaProject }, new IClasspathContainer[] { container }, new NullProgressMonitor());
} catch (JavaModelException e) {
LOG.error(e.getMessage(), e);
}
}
}
use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.
the class ClasspathManager method downloadSources.
private boolean downloadSources(IPackageFragmentRoot fragmentRoot) throws JavaModelException {
fragmentRoot.getAdapter(MavenArtifactKey.class);
IClasspathEntry classpathEntry = fragmentRoot.getResolvedClasspathEntry();
MavenArtifactKey artifactKey = getArtifactKey(classpathEntry);
if (artifactKey != null) {
MavenServerWrapper mavenServer = wrapperManager.getMavenServer(MavenWrapperManager.ServerType.DOWNLOAD);
try {
mavenServer.customize(projectManager.copyWorkspaceCache(), terminal, notifier, false, false);
MavenArtifactKey sourceKey = new MavenArtifactKey(artifactKey.getGroupId(), artifactKey.getArtifactId(), artifactKey.getVersion(), artifactKey.getPackaging(), SOURCES);
MavenArtifact mavenArtifact = mavenServer.resolveArtifact(sourceKey, Collections.emptyList());
if (mavenArtifact.isResolved()) {
updateClasspath(projectManager.findMavenProject(fragmentRoot.getJavaProject().getProject()));
}
return mavenArtifact.isResolved();
} finally {
wrapperManager.release(mavenServer);
}
}
return false;
}
use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.
the class WorkspaceTest method testShouldContainsDefaultTestSourceDirectory.
@Test
public void testShouldContainsDefaultTestSourceDirectory() throws Exception {
String pom = "<groupId>test</groupId>" + "<artifactId>testArtifact</artifactId>" + "<version>42</version>" + "<dependencies>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.12</version>" + " </dependency>" + "</dependencies>" + "<build>" + "</build>";
createTestProject("test", pom);
IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
mavenWorkspace.update(Collections.singletonList(test));
mavenWorkspace.waitForUpdate();
JavaProject javaProject = (JavaProject) JavaCore.create(test);
IClasspathEntry[] classpath = javaProject.getResolvedClasspath();
assertThat(classpath).onProperty("path").is(new Condition<Object[]>() {
@Override
public boolean matches(Object[] value) {
return Stream.of(value).filter(o -> {
if (o instanceof IPath) {
return ((IPath) o).toOSString().endsWith("src/test/java");
}
return false;
}).findFirst().isPresent();
}
});
}
Aggregations