List of usage examples for org.eclipse.jdt.core JavaCore newSourceEntry
public static IClasspathEntry newSourceEntry(IPath path, IPath[] exclusionPatterns, IPath specificOutputLocation)
CPE_SOURCE for the project's source folder identified by the given absolute workspace-relative path but excluding all source files with paths matching any of the given patterns, and associated with a specific output location (that is, ".class" files are not going to the project default output location). From source file:bndtools.wizards.project.NewBndProjectWizardPageOne.java
License:Open Source License
@Override public IClasspathEntry[] getSourceClasspathEntries() { IPath projectPath = new Path(getProjectName()).makeAbsolute(); ProjectPaths projectPaths = ProjectPaths.DEFAULT; List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(2); newEntries.add(JavaCore.newSourceEntry(projectPath.append(projectPaths.getSrc()), null, projectPath.append(projectPaths.getBin()))); boolean enableTestSrcDir; try {/* w ww.j a v a 2 s. c om*/ if (template == null) enableTestSrcDir = true; else { ObjectClassDefinition templateMeta = template.getMetadata(); enableTestSrcDir = findAttribute(templateMeta, ProjectTemplateParam.TEST_SRC_DIR.getString()) != null; } } catch (Exception e) { Plugin.getDefault().getLog() .log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error accessing template parameters", e)); enableTestSrcDir = true; } if (enableTestSrcDir) newEntries.add(JavaCore.newSourceEntry(projectPath.append(projectPaths.getTestSrc()), null, projectPath.append(projectPaths.getTestBin()))); return newEntries.toArray(new IClasspathEntry[0]); }
From source file:com.aliyun.odps.eclipse.create.wizard.ProjectNature.java
License:Apache License
/** * Configures an Eclipse project as a Map/Reduce project by adding the Hadoop libraries to a * project's classpath.//from w w w .ja v a2 s. co m */ public void configure() throws CoreException { String path = project.getPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "ODPS.runtime.path")); File dir = new File(path); final ArrayList<File> coreJars = new ArrayList<File>(); dir.listFiles(new FileFilter() { public boolean accept(File pathname) { String fileName = pathname.getName(); // get the hadoop core jar without touching test or examples // older version of hadoop don't use the word "core" -- eyhung if ((fileName.indexOf("hadoop") != -1) && (fileName.endsWith("jar")) && (fileName.indexOf("test") == -1) && (fileName.indexOf("examples") == -1)) { coreJars.add(pathname); } return false; // we don't care what this returns } }); File dir2 = new File(path + File.separatorChar + "lib"); if (dir2.exists() && dir2.isDirectory()) { dir2.listFiles(new FileFilter() { public boolean accept(File pathname) { if ((!pathname.isDirectory()) && (pathname.getName().endsWith("jar"))) { coreJars.add(pathname); } return false; // we don't care what this returns } }); } // Add Hadoop libraries onto classpath IJavaProject javaProject = JavaCore.create(getProject()); // Bundle bundle = Activator.getDefault().getBundle(); try { IClasspathEntry[] currentCp = javaProject.getRawClasspath(); IClasspathEntry[] newCp = new IClasspathEntry[currentCp.length + coreJars.size() + 1]; System.arraycopy(currentCp, 0, newCp, 0, currentCp.length); final Iterator<File> i = coreJars.iterator(); int count = 0; while (i.hasNext()) { // for (int i = 0; i < s_coreJarNames.length; i++) { final File f = (File) i.next(); // URL url = FileLocator.toFileURL(FileLocator.find(bundle, new // Path("lib/" + s_coreJarNames[i]), null)); URL url = f.toURI().toURL(); log.finer("hadoop library url.getPath() = " + url.getPath()); newCp[newCp.length - 2 - count] = JavaCore.newLibraryEntry(new Path(url.getPath()), null, null); count++; } // add examples to class-path IPath sourceFolderPath = new Path(javaProject.getProject().getName()).makeAbsolute(); IPath exampleSrc = sourceFolderPath.append(new Path(CONST.EXAMPLE_SRC_PATH)); IPath exampleClasses = sourceFolderPath.append(new Path(CONST.EXAMPLE_BIN)); IClasspathEntry exampleSrcEntry = JavaCore.newSourceEntry(exampleSrc, new IPath[] {}, exampleClasses); newCp[newCp.length - 1] = exampleSrcEntry; javaProject.setRawClasspath(newCp, new NullProgressMonitor()); } catch (Exception e) { log.log(Level.SEVERE, "IOException generated in " + this.getClass().getCanonicalName(), e); } }
From source file:com.google.gwt.eclipse.core.compile.GWTCompileRunnerTest.java
License:Open Source License
/** * Create a source entry (including the dir structure) and add it to the raw * classpath.// w w w.j a v a 2s.co m * * @param javaProject The Java project that receives the source entry * @param directoryName The source directory name * @param outputDirectoryName The optional output location of this source * directory. Pass null for the default output location. */ private static void addAndCreateSourceEntry(IJavaProject javaProject, String directoryName, String outputDirectoryName) throws CoreException { IFolder srcFolder = javaProject.getProject().getFolder(directoryName); ResourceUtils.createFolderStructure(javaProject.getProject(), srcFolder.getProjectRelativePath()); IPath workspaceRelOutPath = null; if (outputDirectoryName != null) { // Ensure output directory exists IFolder outFolder = javaProject.getProject().getFolder(outputDirectoryName); ResourceUtils.createFolderStructure(javaProject.getProject(), outFolder.getProjectRelativePath()); workspaceRelOutPath = outFolder.getFullPath(); } JavaProjectUtilities.addRawClassPathEntry(javaProject, JavaCore.newSourceEntry(srcFolder.getFullPath(), ClasspathEntry.EXCLUDE_NONE, workspaceRelOutPath)); }
From source file:com.googlecode.osde.internal.ui.wizards.newrestprj.RestfulAccessProjectFactory.java
License:Apache License
public void run(IProgressMonitor monitor) throws InvocationTargetException { try {/*from ww w .j a v a 2 s . c om*/ newProjectHandle.create(monitor); newProjectHandle.open(monitor); // applyJavaNature(monitor); // IJavaProject javaProject = JavaCore.create(newProjectHandle); Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(); // IPath sourcePath = javaProject.getPath().append(srcFolderName); IFolder sourceDir = createSourceDirectory(); // IPath outputPath = createOutputDirectory(javaProject); // IClasspathEntry srcEntry = JavaCore.newSourceEntry(sourcePath, new IPath[] {}, outputPath); entries.add(srcEntry); // IPath libPath = javaProject.getPath().append(libFolderName); IFolder libDir = createLibraryDirectory(); // copyLibraries(libDir); // applyClasspath(monitor, javaProject, entries, libPath, libDir); // IFolder examplesDir = createExamplesDirectory(sourceDir); // final IFile sampleFile = createSampleCode(examplesDir); // workbench.getDisplay().syncExec(new Runnable() { public void run() { IWorkbenchWindow dw = workbench.getActiveWorkbenchWindow(); try { if (dw != null) { IWorkbenchPage page = dw.getActivePage(); if (page != null) { IDE.openEditor(page, sampleFile); } } } catch (PartInitException e) { throw new RuntimeException(e); } } }); // monitor.worked(1); monitor.done(); } catch (CoreException e) { throw new InvocationTargetException(e); } }
From source file:com.mountainminds.eclemma.core.JavaProjectKit.java
License:Open Source License
public IPackageFragmentRoot createSourceFolder(String foldername, String output) throws CoreException { IFolder folder = project.getFolder(foldername); folder.create(false, true, null);//from ww w. j a v a 2s . c o m IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(folder); IFolder outputFolder = project.getFolder(output); outputFolder.create(false, true, null); addClassPathEntry(JavaCore.newSourceEntry(packageRoot.getPath(), null, outputFolder.getFullPath())); return packageRoot; }
From source file:com.siteview.mde.internal.core.project.ProjectModifyOperation.java
License:Open Source License
/** * Returns source folder class path entries. * // ww w . j av a 2 s. c o m * @param project Java project * @param description project description * @return source folder class path entries, possibly empty. * @exception CoreException if source folder class path entry creation fails */ private IClasspathEntry[] getSourceFolderEntries(IJavaProject project, IBundleProjectDescription description) throws CoreException { IBundleClasspathEntry[] folders = description.getBundleClasspath(); if (folders == null || folders.length == 0) { return new IClasspathEntry[0]; } List entries = new ArrayList(); for (int i = 0; i < folders.length; i++) { IBundleClasspathEntry folder = folders[i]; if (folder.getSourcePath() == null) { // no source indicates class file folder or library IPath bin = folder.getBinaryPath(); if (bin == null) { // nested library bin = folder.getLibrary(); } if (bin != null) { IPath output = project.getProject().getFullPath().append(bin); entries.add(JavaCore.newLibraryEntry(output, null, null)); } } else { // source folder IPath path = project.getProject().getFullPath().append(folder.getSourcePath()); IPath output = folder.getBinaryPath(); if (output != null) { output = project.getProject().getFullPath().append(output); } entries.add(JavaCore.newSourceEntry(path, EXCLUDE_NONE, output)); } } return (IClasspathEntry[]) entries.toArray(new IClasspathEntry[entries.size()]); }
From source file:de.ovgu.featureide.core.mpl.io.writer.JavaProjectWriter.java
License:Open Source License
private IJavaProject createJavaProject(String projectName) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(projectName); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); ICommand build = description.newCommand(); build.setBuilderName(JavaCore.BUILDER_ID); description.setBuildSpec(new ICommand[] { build }); try {/*from w w w .java 2 s . c o m*/ project.delete(true, true, null); project.create(description, null); project.open(null); IJavaProject javaProject = JavaCore.create(project); javaProject.open(null); List<IClasspathEntry> entries = new LinkedList<IClasspathEntry>(); IPath sourcePath = Path.fromPortableString("src"); IFolder sourceFolder = project.getFolder(sourcePath); sourceFolder.create(true, true, null); sourcePath = project.getFolder(sourcePath).getFullPath(); IPath binPath = Path.fromPortableString("bin"); project.getFolder(binPath).create(false, true, null); binPath = project.getFolder(binPath).getFullPath(); entries.add(JavaCore.newSourceEntry(sourcePath, new IPath[0], binPath)); IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall(); for (LibraryLocation location : JavaRuntime.getLibraryLocations(vmInstall)) { entries.add(JavaCore.newLibraryEntry(location.getSystemLibraryPath(), null, null)); } javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); return javaProject; } catch (Exception e) { MPLPlugin.getDefault().logError(e); } return null; }
From source file:egovframework.hdev.imp.ide.wizards.operation.NewDeviceAPIWebProjectCreationOperation.java
License:Apache License
/** * ? // ww w. ja v a2 s . c o m */ @Override protected void configureClasspath(IProgressMonitor monitor) throws CoreException { IPath projectPath = getWebProject().getFullPath(); List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); entries.add(JavaCore.newSourceEntry(projectPath.append(ResourceConstants.WEB_RESOURCE_FOLDER), new IPath[] { ResourceConstants.WEB_EXCLUDING_PATH }, projectPath.append(ResourceConstants.WEB_DEFAULT_OUTPUT_FOLDER))); entries.add(JavaCore.newSourceEntry(projectPath.append(ResourceConstants.WEB_TEST_SOURCE_FOLDER), new IPath[0], projectPath.append(ResourceConstants.WEB_TEST_OUTPUT_FOLDER))); entries.add(JavaCore.newSourceEntry(projectPath.append(ResourceConstants.WEB_TEST_RESOURCE_FOLDER), new IPath[] { ResourceConstants.WEB_EXCLUDING_PATH }, projectPath.append(ResourceConstants.WEB_TEST_OUTPUT_FOLDER))); IClasspathEntry[] classpathEntrys = (IClasspathEntry[]) entries .toArray(new IClasspathEntry[entries.size()]); DeviceAPIIdeUtils.assignClasspathEntryToJavaProject(getWebProject(), classpathEntrys, true); }
From source file:gov.redhawk.ide.codegen.java.JavaGeneratorUtils.java
License:Open Source License
public static void addSourceClassPaths(final IJavaProject jproject, final IPath srcPath, final IPath binPath, final IProgressMonitor monitor) throws CoreException { final SubMonitor progress = SubMonitor.convert(monitor, 1); final Set<IClasspathEntry> entries = new LinkedHashSet<IClasspathEntry>( Arrays.asList(jproject.getRawClasspath())); // Add source code to the java project classpath for (final IClasspathEntry path : entries) { if ((path.getEntryKind() == IClasspathEntry.CPE_SOURCE) && path.getPath().equals(jproject.getProject().getFullPath())) { continue; }/*ww w . j a v a 2 s . c o m*/ entries.add(path); } final IClasspathEntry e = JavaCore.newSourceEntry(srcPath, new Path[0], binPath); entries.add(e); jproject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), progress.newChild(1)); }
From source file:net.sf.eclipse.tomcat.TomcatProject.java
License:Open Source License
/** * ouput could be null (project default output will be used) *//*from w w w . j av a2s. c o m*/ private void setFolderAsSourceEntry(IFolder folderHandle, IFolder output) throws CoreException { IClasspathEntry[] entries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); IPath outputPath = null; if (output != null) { outputPath = output.getFullPath(); } IPath[] emptyPath = {}; newEntries[entries.length] = JavaCore.newSourceEntry(folderHandle.getFullPath(), emptyPath, outputPath); javaProject.setRawClasspath(newEntries, null); }