List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath
void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException;
From source file:org.gw4e.eclipse.facade.ClasspathManager.java
License:Open Source License
/** * Make sure the passed folder is in the classpath * /*from ww w . ja v a2 s .c o m*/ * @param project * @param folderPath * @param monitor * @return * @throws JavaModelException */ public static IClasspathEntry ensureFolderInClasspath(IProject project, String folderPath, IProgressMonitor monitor) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); if (folderPath.startsWith("src")) { handleFolderExclusion(project, folderPath); } IClasspathEntry[] entries = javaProject.getRawClasspath(); boolean classpathentryFound = false; IPath folder = project.getFolder(folderPath).getFullPath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getPath().equals(folder)) { classpathentryFound = true; return entries[i]; } } if (!classpathentryFound) { IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); IPath srcPath = javaProject.getPath().append(folderPath); IClasspathEntry srcEntry = JavaCore.newSourceEntry(srcPath, null); newEntries[entries.length] = JavaCore.newSourceEntry(srcEntry.getPath()); javaProject.setRawClasspath(newEntries, monitor); return srcEntry; } return null; }
From source file:org.gw4e.eclipse.facade.ClasspathManager.java
License:Open Source License
/** * Remove GW4E ClassPath Container/* w w w.java 2s .co m*/ * * @param project * @param monitor * @throws JavaModelException */ public static void removeGW4EClassPathContainer(IProject project, IProgressMonitor monitor) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] entries = javaProject.getRawClasspath(); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); for (int i = 0; i < entries.length; i++) { if (!GW4ELibrariesContainer.isMe(entries[i])) { newEntries.add(entries[i]); } } entries = new IClasspathEntry[newEntries.size()]; newEntries.toArray(entries); javaProject.setRawClasspath(entries, monitor); }
From source file:org.gw4e.eclipse.facade.ClasspathManager.java
License:Open Source License
/** * Remove the passed folder from ClassPath * //w w w . ja v a 2 s . c o m * @param project * @param folderPath * @param monitor * @throws JavaModelException */ public static void removeFolderFromClasspath(IProject project, String folderPath, IProgressMonitor monitor) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] entries = javaProject.getRawClasspath(); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); IPath folder = project.getFolder(folderPath).getFullPath(); for (int i = 0; i < entries.length; i++) { if (!entries[i].getPath().equals(folder)) { newEntries.add(entries[i]); } } entries = new IClasspathEntry[newEntries.size()]; newEntries.toArray(entries); javaProject.setRawClasspath(entries, monitor); }
From source file:org.gw4e.eclipse.facade.GraphWalkerContextManager.java
License:Open Source License
public static void internal_configureProject(IProject project, SubMonitor subMonitor) throws Exception { ClasspathManager.addGW4EClassPathContainer(project); SubMonitor sm2 = subMonitor.newChild(10); ResourceManager.ensureFolder(project, Constant.SOURCE_MAIN_JAVA, sm2); ClasspathManager.ensureFolderInClasspath(project, Constant.SOURCE_MAIN_JAVA, sm2); SubMonitor sm3 = subMonitor.newChild(10); ResourceManager.ensureFolder(project, Constant.SOURCE_MAIN_RESOURCES, sm3); ClasspathManager.ensureFolderInClasspath(project, Constant.SOURCE_MAIN_RESOURCES, sm3); SubMonitor sm4 = subMonitor.newChild(10); ResourceManager.ensureFolder(project, Constant.SOURCE_TEST_JAVA, sm4); ClasspathManager.ensureFolderInClasspath(project, Constant.SOURCE_TEST_JAVA, sm4); SubMonitor sm5 = subMonitor.newChild(10); ResourceManager.ensureFolder(project, Constant.SOURCE_TEST_RESOURCES, sm5); ClasspathManager.ensureFolderInClasspath(project, Constant.SOURCE_TEST_RESOURCES, sm5); SubMonitor sm6 = subMonitor.newChild(10); PreferenceManager.setDefaultPreference(project.getName()); // Graphs in src/main/resources will generate interfaces in // target/generated-sources/ String targetMainFolderForInterface = getTargetFolderForTestInterface(project.getName(), true); IPath targetMainFolderForInterfacePath = JDTManager.guessPackageRootFragment(project, true); if (targetMainFolderForInterfacePath != null) { targetMainFolderForInterface = targetMainFolderForInterfacePath.makeRelativeTo(project.getFullPath()) .toString();/*ww w . ja v a2 s . c om*/ } //IResource resourceMain = ClasspathManager.childrenExistInClasspath(project, targetMainFolderForInterface, sm6); //if (resourceMain == null) { ResourceManager.ensureFolder(project, targetMainFolderForInterface, sm6); ClasspathManager.ensureFolderInClasspath(project, targetMainFolderForInterface, sm6); //} // Graphs in src/test/resources will generate interfaces in // target/generated-test-sources String targetTestFolderForInterface = getTargetFolderForTestInterface(project.getName(), false); IPath targetTestFolderForInterfacePath = JDTManager.guessPackageRootFragment(project, false); if (targetTestFolderForInterfacePath != null) { targetTestFolderForInterface = targetTestFolderForInterfacePath.makeRelativeTo(project.getFullPath()) .toString(); } // IResource resourceTest = ClasspathManager.childrenExistInClasspath(project, targetTestFolderForInterface, sm6); // if (resourceTest == null) { ResourceManager.ensureFolder(project, targetTestFolderForInterface, sm6); ClasspathManager.ensureFolderInClasspath(project, targetTestFolderForInterface, sm6); // } IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] entries = javaProject.getRawClasspath(); Arrays.sort(entries, new Comparator<IClasspathEntry>() { @Override public int compare(IClasspathEntry e1, IClasspathEntry e2) { if (e1.getEntryKind() > e2.getEntryKind()) return 1; if (e1.getEntryKind() < e2.getEntryKind()) return -1; return e1.getPath().toString().compareTo(e2.getPath().toString()); } }); javaProject.setRawClasspath(entries, null); // SubMonitor sm8 = subMonitor.newChild(10); ClasspathManager.setBuilder(project, sm8); // if (targetMainFolderForInterfacePath != null) { setTargetFolderForTestInterface( ResourceManager.getResource(targetMainFolderForInterfacePath.toString()), true); } if (targetTestFolderForInterfacePath != null) { setTargetFolderForTestInterface( ResourceManager.getResource(targetTestFolderForInterfacePath.toString()), false); } ICompilationUnit[] interfaces = JDTManager.getOrCreateGeneratedTestInterfaces(project); for (int i = 0; i < interfaces.length; i++) { new TestConvertor(interfaces[i]).apply(); } }
From source file:org.gw4e.eclipse.test.fwk.ProjectHelper.java
License:Open Source License
public static void addGWClassPathEntry(IJavaProject javaProject) throws JavaModelException { IClasspathEntry[] entries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); Path lcp = new Path(GW4ELibrariesContainer.ID); IClasspathEntry libEntry = JavaCore.newContainerEntry(lcp, true); newEntries[entries.length] = JavaCore.newContainerEntry(libEntry.getPath(), true); javaProject.setRawClasspath(newEntries, new NullProgressMonitor()); }
From source file:org.gw4e.eclipse.test.fwk.ProjectHelper.java
License:Open Source License
public static IJavaProject createProject(String name) throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(name); if (!project.exists()) { project.create(new NullProgressMonitor()); } else {//from www .j a v a 2s . c o m project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); } if (!project.isOpen()) { project.open(new NullProgressMonitor()); } IFolder binFolder = project.getFolder("bin"); if (!binFolder.exists()) { createFolder(binFolder, false, true, new NullProgressMonitor()); } IPath outputLocation = binFolder.getFullPath(); addNatureToProject(project, JavaCore.NATURE_ID, new NullProgressMonitor()); IJavaProject jproject = JavaCore.create(project); jproject.setOutputLocation(outputLocation, new NullProgressMonitor()); IClasspathEntry[] entries = PreferenceConstants.getDefaultJRELibrary(); jproject.setRawClasspath(entries, new NullProgressMonitor()); return jproject; }
From source file:org.gw4e.eclipse.test.fwk.ProjectHelper.java
License:Open Source License
public static void addToClasspath(IJavaProject jproject, IClasspathEntry cpe) throws JavaModelException { IClasspathEntry[] oldEntries = jproject.getRawClasspath(); for (int i = 0; i < oldEntries.length; i++) { if (oldEntries[i].equals(cpe)) { return; }/*w ww .j a va 2s .com*/ } int nEntries = oldEntries.length; IClasspathEntry[] newEntries = new IClasspathEntry[nEntries + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, nEntries); newEntries[nEntries] = cpe; jproject.setRawClasspath(newEntries, new NullProgressMonitor()); }
From source file:org.hibernate.eclipse.console.test.project.SimpleTestProject.java
License:Open Source License
private IPackageFragmentRoot buildSourceFolder(IProject project, IJavaProject javaProject) throws CoreException { IFolder folder = project.getFolder(SRC_FOLDER); folder.create(false, true, null);//from w w w .j ava2 s .com IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(folder); IClasspathEntry[] newEntries = { JavaCore.newSourceEntry(root.getPath()) }; javaProject.setRawClasspath(newEntries, null); return root; }
From source file:org.hibernate.eclipse.console.test.project.xpl.JavaProjectHelper.java
License:Open Source License
/** * Creates a IJavaProject.//from www. j av a2 s . c o m * @param projectName The name of the project * @param binFolderName Name of the output folder * @return Returns the Java project handle * @throws CoreException Project creation failed */ public static IJavaProject createJavaProject(String projectName, String binFolderName) throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(projectName); if (!project.exists()) { project.create(null); } else { project.refreshLocal(IResource.DEPTH_INFINITE, null); } if (!project.isOpen()) { project.open(null); } IPath outputLocation; if (binFolderName != null && binFolderName.length() > 0) { IFolder binFolder = project.getFolder(binFolderName); if (!binFolder.exists()) { CoreUtility.createFolder(binFolder, false, true, null); } outputLocation = binFolder.getFullPath(); } else { outputLocation = project.getFullPath(); } if (!project.hasNature(JavaCore.NATURE_ID)) { addNatureToProject(project, JavaCore.NATURE_ID, null); } IJavaProject jproject = JavaCore.create(project); jproject.setOutputLocation(outputLocation, null); jproject.setRawClasspath(new IClasspathEntry[0], null); return jproject; }
From source file:org.hibernate.eclipse.console.test.project.xpl.JavaProjectHelper.java
License:Open Source License
/** * Removes all files in the project and sets the given classpath * @param jproject The project to clear//from w w w . ja v a 2 s .c o m * @param entries The default class path to set * @throws CoreException Clearing the project failed */ public static void clear(final IJavaProject jproject, final IClasspathEntry[] entries) throws CoreException { performDummySearch(); IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { jproject.setRawClasspath(entries, null); IResource[] resources = jproject.getProject().members(); for (int i = 0; i < resources.length; i++) { if (!resources[i].getName().startsWith(".")) { //$NON-NLS-1$ resources[i].delete(true, null); } } } }; ResourcesPlugin.getWorkspace().run(runnable, null); }