List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath
void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException;
From source file:hydrograph.ui.project.structure.wizard.ProjectStructureCreator.java
License:Apache License
/** * Creates the custom project structure at the specified location and name * The Project will have below natures:<br> * <b>Java</b> and Custom nature as per <b>ETL</b> project * @param projectName Project name/*w ww . j a va 2 s . c o m*/ * @param location Where should the project be saved * @return */ public IProject createProject(String projectName, URI location) { if (StringUtils.isNotBlank(projectName) && projectName.contains(" ")) { MessageBox messageBox = new MessageBox(new Shell(), SWT.ICON_ERROR | SWT.OK); messageBox.setText("Error"); messageBox.setMessage("The Project Name has spaces"); if (messageBox.open() == SWT.OK) { return null; } } else if (StringUtils.isBlank(projectName)) { throw new InvalidProjectNameException(); } IProject project = null; try { project = createBaseProject(projectName, location); if (project != null) { addNature(project); addToProjectStructure(project, paths); IJavaProject javaProject = JavaCore.create(project); IFolder binFolder = project.getFolder(CustomMessages.ProjectSupport_BIN); javaProject.setOutputLocation(binFolder.getFullPath(), null); List<IClasspathEntry> entries = addJavaLibrariesInClassPath(); IFolder libFolder = project.getFolder(CustomMessages.ProjectSupport_LIB); //add libs to project class path String installLocation = Platform.getInstallLocation().getURL().getPath(); //copyExternalLibAndAddToClassPath(installLocation + CustomMessages.ProjectSupport_LIB, libFolder, entries); copyBuildFile(installLocation + CustomMessages.ProjectSupport_CONFIG_FOLDER + "/" + CustomMessages.ProjectSupport_GRADLE + "/" + BUILD, project); copyBuildFile(installLocation + CustomMessages.ProjectSupport_CONFIG_FOLDER + "/" + CustomMessages.ProjectSupport_GRADLE + "/" + PROPERTIES, project); copyBuildFile(installLocation + CustomMessages.ProjectSupport_CONFIG_FOLDER + "/" + MAVEN, project); updateMavenFile(POM_XML, project); javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); //set source folder entry in classpath javaProject.setRawClasspath(setSourceFolderInClassPath(project, javaProject), null); } } catch (CoreException e) { logger.debug( "Failed to create Project with parameters as projectName : {} location : {}, exception : {}", new Object[] { projectName, location, e }); project = null; } return project; }
From source file:icy.icy4eclipse.core.NewIcyProjectWizard.java
License:Open Source License
@Override public boolean performFinish() { String pluginName = myPage.getPluginName(); String devName = Icy4EclipsePlugin.getIcyDeveloper(); String subpackageName = myPage.getSubpackageName(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(pluginName); String templateName = myPage.getTemplateName(); IcyTemplateLocator locator = Icy4EclipsePlugin.getDefault().getTemplateLocator(); locator.init();// ww w. j av a2 s. c o m IcyProjectTemplate template = locator.getTemplate(templateName); if (template == null) { Icy4EclipsePlugin.logError("Unable to find a template (" + templateName + ")"); return false; } try { // Project creation project.create(null); if (!project.isOpen()) { project.open(null); } } catch (CoreException e) { Icy4EclipsePlugin.logException(e); return false; } try { // Natures Icy4EclipsePlugin.addNature(project, JavaCore.NATURE_ID); IJavaProject javaProject = JavaCore.create(project); Icy4EclipsePlugin.addIcyNature(javaProject); // Folder IFolder src = project.getFolder("src"); if (!src.exists()) { src.create(true, true, null); } // Classpath List<IClasspathEntry> classpath = new ArrayList<IClasspathEntry>(); classpath.add(JavaCore.newSourceEntry(src.getFullPath())); for (String e : ICY_JARS) { classpath.add(JavaCore.newVariableEntry(new Path(ICY4ECLIPSE_HOME_VARIABLE + "/" + e), null, null)); } List<IClasspathEntry> templateEntries = template.getSpecificClasspathEntries(); if (templateEntries != null) { classpath.addAll(templateEntries); } IClasspathEntry[] jreEntries = PreferenceConstants.getDefaultJRELibrary(); for (IClasspathEntry cpe : jreEntries) { classpath.add(cpe); } javaProject.setRawClasspath(classpath.toArray(new IClasspathEntry[classpath.size()]), null); // Default plugin java file String packageName = Icy4EclipsePlugin.getFullPackageName(devName, subpackageName); IPackageFragmentRoot srcRoot = javaProject.getPackageFragmentRoot(src); IPackageFragment pack = srcRoot.createPackageFragment(packageName, false, null); String className = Icy4EclipsePlugin.fromPluginnameToClassname(pluginName); pack.createCompilationUnit(className + ".java", template.getPluginMainClassImplementation(pluginName, packageName, className), false, null); // Compile project.build(IncrementalProjectBuilder.FULL_BUILD, null); } catch (CoreException e) { Icy4EclipsePlugin.logException(e); try { project.delete(true, true, null); } catch (CoreException e1) { Icy4EclipsePlugin.logException(e1); } return false; } return true; }
From source file:in.cypal.studio.gwt.core.facet.InstallDelegate.java
License:Apache License
public static void addUserLibToClassPath(IProject project, IProgressMonitor monitor) { monitor = Util.getNonNullMonitor(monitor); try {//from ww w . j a v a 2s.c o m IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] oldClasspath = javaProject.getRawClasspath(); IClasspathEntry[] newClasspath = new IClasspathEntry[oldClasspath.length + 1]; System.arraycopy(oldClasspath, 0, newClasspath, 0, oldClasspath.length); IClasspathEntry gwtuserJarEntry = JavaCore.newVariableEntry(Util.getGwtUserLibPath(), null, null); gwtuserJarEntry = JavaCore.newVariableEntry(gwtuserJarEntry.getPath(), null, null, new IAccessRule[0], new IClasspathAttribute[0], false); newClasspath[oldClasspath.length] = gwtuserJarEntry; javaProject.setRawClasspath(newClasspath, monitor); } catch (CoreException e) { // the jar is already in the classpath. Activator.logException(e); } finally { monitor.done(); } }
From source file:in.cypal.studio.gwt.core.facet.InstallDelegate.java
License:Apache License
public static void addServletLibToWebInf(IProject project, IProgressMonitor monitor) { monitor = Util.getNonNullMonitor(monitor); try {//from w w w . ja va2 s. c om monitor.beginTask("", 1); IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] oldClasspath = javaProject.getRawClasspath(); IClasspathEntry[] newClasspath = new IClasspathEntry[oldClasspath.length + 1]; System.arraycopy(oldClasspath, 0, newClasspath, 0, oldClasspath.length); IClasspathEntry gwtServletJarEntry = JavaCore.newVariableEntry(Util.getGwtServletLibPath(), null, null); IClasspathAttribute attr = JavaCore.newClasspathAttribute("org.eclipse.jst.component.dependency", "/WEB-INF/lib"); gwtServletJarEntry = JavaCore.newVariableEntry(gwtServletJarEntry.getPath(), null, null, new IAccessRule[0], new IClasspathAttribute[] { attr }, false); newClasspath[oldClasspath.length] = gwtServletJarEntry; javaProject.setRawClasspath(newClasspath, monitor); } catch (JavaModelException e) { // the jar is already in the classpath. Activator.logException(e); } finally { monitor.done(); } }
From source file:in.cypal.studio.gwt.core.facet.UpgradeDelegate.java
License:Apache License
private void removeGWTEntries(IProject project, IProgressMonitor monitor) throws JavaModelException { monitor = Util.getNonNullMonitor(monitor); monitor.beginTask("Removing old entries...", 2); try {/*w ww. ja va2s. c o m*/ IJavaProject javaProject = JavaCore.create(project); List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); IClasspathEntry[] oldClasspath = javaProject.getRawClasspath(); for (IClasspathEntry classpathEntry : oldClasspath) { if (!classpathEntry.getPath().lastSegment().startsWith("gwt")) classpathEntries.add(classpathEntry); } javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), new SubProgressMonitor(monitor, 1)); IPath webContent = ComponentCore.createComponent(project).getRootFolder().getProjectRelativePath(); IFile theLink = project.getFile(webContent.append("WEB-INF").append("lib").append("gwt-servlet.jar")); theLink.delete(true, new SubProgressMonitor(monitor, 1)); } catch (CoreException e) { Activator.logException(e); } finally { monitor.done(); } }
From source file:in.cypal.studio.gwt.samples.wizards.SamplesWizard.java
License:Apache License
private void addSourceFolder(IJavaProject javaProject, IClasspathEntry[] classpathEntries) throws JavaModelException { IClasspathEntry[] newClasspathEntries = new IClasspathEntry[classpathEntries.length + 1]; System.arraycopy(classpathEntries, 0, newClasspathEntries, 0, classpathEntries.length); newClasspathEntries[classpathEntries.length] = JavaCore .newSourceEntry(javaProject.getProject().getFullPath().append(SAMPLE_SRC)); javaProject.setRawClasspath(newClasspathEntries, null); }
From source file:it.scoppelletti.sdk.ide.ui.NewProjectOperation.java
License:Apache License
/** * Imposta il class-path./*from w w w .j av a 2 s .c om*/ * * @param project Progetto. * @param monitor Gestore dell’avanzamento. */ private void setClasspath(IJavaProject project, IProgressMonitor monitor) throws CoreException, JavaModelException { IPath path; IFolder outputFolder, sourceFolder; IClasspathEntry[] classpath = new IClasspathEntry[3]; ProjectDirectory projectDir; SubMonitor progress; progress = SubMonitor.convert(monitor, "Setting class-path...", 2); try { projectDir = new ProjectDirectory(project.getProject()); outputFolder = projectDir.getBuildClassesFolder(); project.setOutputLocation(outputFolder.getFullPath(), progress.newChild(1)); progress.worked(1); sourceFolder = projectDir.getSourceJavaFolder(); classpath[0] = JavaCore.newSourceEntry(sourceFolder.getFullPath()); path = JavaRuntime.newDefaultJREContainerPath(); classpath[1] = JavaCore.newContainerEntry(path); classpath[2] = JavaCore.newContainerEntry(DependenciesContainer.PATH); project.setRawClasspath(classpath, progress.newChild(1)); progress.worked(1); } finally { if (monitor != null) { monitor.done(); } } }
From source file:it.scoppelletti.sdk.ide.ui.NewWebProjectOperation.java
License:Apache License
/** * Imposta il class-path./*from w ww . j a va2 s. c om*/ * * @param project Progetto. * @param monitor Gestione dell’avanzamento. */ private void setClasspath(IJavaProject project, IProgressMonitor monitor) throws CoreException, JavaModelException { IPath path; IFolder sourceFolder; IClasspathEntry[] classpath = new IClasspathEntry[3]; ProjectDirectory projectDir; projectDir = new ProjectDirectory(project.getProject()); // Il facet jst.web inserisce anche i seguenti class-path: // 1) org.eclipse.jst.j2ee.internal.web.container // 2) org.eclipse.jst.j2ee.internal.module.container sourceFolder = projectDir.getSourceJavaFolder(); classpath[0] = JavaCore.newSourceEntry(sourceFolder.getFullPath()); path = JavaRuntime.newDefaultJREContainerPath(); classpath[1] = JavaCore.newContainerEntry(path); classpath[2] = JavaCore.newContainerEntry(DependenciesContainer.PATH); project.setRawClasspath(classpath, monitor); }
From source file:it.wallgren.android.platform.project.AndroidPlatformProject.java
License:Apache License
private void addJavaNature(IProject project, IProgressMonitor monitor) throws CoreException { if (project == null) { throw new IllegalStateException("Project must be created before giving it a Java nature"); }// w ww .java2 s . com final IFolder repoLink = createRepoLink(monitor, project, repoPath); IFile classpath = repoLink.getFile("development/ide/eclipse/.classpath"); IFile classpathDestination = project.getFile(".classpath"); if (classpathDestination.exists()) { classpathDestination.delete(true, monitor); } classpath.copy(classpathDestination.getFullPath(), true, monitor); final IProjectDescription description = project.getDescription(); final String[] natures = description.getNatureIds(); final String[] newNatures = Arrays.copyOf(natures, natures.length + 1); newNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); final IJavaProject javaProject = JavaCore.create(project); @SuppressWarnings("rawtypes") final Map options = javaProject.getOptions(true); // Compliance level need to be 1.6 JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options); javaProject.setOptions(options); IClasspathEntry[] classPath = mangleClasspath(javaProject.getRawClasspath(), project, repoLink); javaProject.setRawClasspath(classPath, monitor); javaProject.setOutputLocation(javaProject.getPath().append("out"), monitor); }
From source file:it.wallgren.android.platform.project.PackagesProject.java
License:Apache License
private void addJavaNature(IClasspathEntry[] classPath, IProject project, IProgressMonitor monitor) throws CoreException { if (project == null) { throw new IllegalStateException("Project must be created before giving it a Java nature"); }//from w w w .jav a2s . co m final IProjectDescription description = project.getDescription(); final String[] natures = description.getNatureIds(); final String[] newNatures = Arrays.copyOf(natures, natures.length + 1); newNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); final IJavaProject javaProject = JavaCore.create(project); @SuppressWarnings("rawtypes") final Map options = javaProject.getOptions(true); // Compliance level need to be 1.6 JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options); javaProject.setOptions(options); javaProject.setRawClasspath(classPath, monitor); javaProject.setOutputLocation(javaProject.getPath().append("out"), monitor); }