use of org.eclipse.core.resources.IProject in project generator by mybatis.
the class GeneratorLaunchShortcut method getJavaProjectNameFromResource.
/**
* This will return null if there isn't a JavaProject associated with this
* resource.
*
* @param resource
* @return the JavaProject name if there is one
*/
public static String getJavaProjectNameFromResource(IResource resource) {
String name = null;
IProject project = resource.getProject();
try {
if (project != null && project.exists() && project.hasNature(JavaCore.NATURE_ID)) {
// add the JavaProject name to the launch - this will add it to the
// classpath of the launch automatically
IJavaProject javaProject = JavaCore.create(project);
name = javaProject.getElementName();
}
} catch (CoreException e) {
// just ignore it - no ultimate harm done if we can't find the Java project
}
return name;
}
use of org.eclipse.core.resources.IProject in project generator by mybatis.
the class RunGeneratorThread method getJavaProject.
private IJavaProject getJavaProject() {
IJavaProject answer = null;
IProject project = inputFile.getProject();
try {
if (project.hasNature(JavaCore.NATURE_ID)) {
answer = JavaCore.create(project);
}
} catch (CoreException e) {
// ignore - something is wrong
;
}
return answer;
}
use of org.eclipse.core.resources.IProject in project generator by mybatis.
the class EclipseShellCallback method getJavaProject.
private IJavaProject getJavaProject(String javaProjectName) throws ShellException {
IJavaProject javaProject = projects.get(javaProjectName);
if (javaProject == null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(javaProjectName);
if (project.exists()) {
boolean isJavaProject;
try {
isJavaProject = project.hasNature(JavaCore.NATURE_ID);
} catch (CoreException e) {
throw new ShellException(e.getStatus().getMessage(), e);
}
if (isJavaProject) {
javaProject = JavaCore.create(project);
} else {
StringBuffer sb = new StringBuffer();
sb.append("Project ");
sb.append(javaProjectName);
sb.append(" is not a Java project");
throw new ShellException(sb.toString());
}
} else {
StringBuffer sb = new StringBuffer();
sb.append("Project ");
sb.append(javaProjectName);
sb.append(" does not exist");
throw new ShellException(sb.toString());
}
projects.put(javaProjectName, javaProject);
}
return javaProject;
}
use of org.eclipse.core.resources.IProject in project che by eclipse.
the class ClasspathBuilderTest method rawClasspathShouldBeContained3Arguments.
@Test
public void rawClasspathShouldBeContained3Arguments() throws Exception {
createTestProject();
library.add("/lib");
sourceFolders.add("/src");
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("/project");
IJavaProject iJavaProject = JavaCore.create(project);
classpathBuilder.generateClasspath(iJavaProject, sourceFolders, library);
List<IClasspathEntry> classpathEntries = Arrays.asList(iJavaProject.getRawClasspath());
assertThat(classpathEntries).onProperty("path").containsOnly(new Path(JREContainerInitializer.JRE_CONTAINER), new Path("/project/src"), new Path(root + "/project/lib/a.jar"));
}
use of org.eclipse.core.resources.IProject 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