List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath
void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException;
From source file:com.googlecode.osde.internal.ui.wizards.newrestprj.RestfulAccessProjectFactory.java
License:Apache License
private void applyClasspath(IProgressMonitor monitor, final IJavaProject javaProject, Set<IClasspathEntry> entries, IPath libPath, IFolder libDir) throws JavaModelException { IClasspathContainer libContainer = new ClasspathContainerImpl(libDir, libPath); JavaCore.setClasspathContainer(libPath, new IJavaProject[] { javaProject }, new IClasspathContainer[] { libContainer }, null); ///*from ww w . jav a 2 s. c o m*/ IClasspathEntry libEntry = JavaCore.newContainerEntry(libPath, null, new IClasspathAttribute[] {}, false); entries.add(libEntry); // entries.add(JavaRuntime.getDefaultJREContainerEntry()); javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor); }
From source file:com.gwtplatform.plugin.wizard.NewProjectWizard.java
License:Apache License
@SuppressWarnings({ "rawtypes", "unchecked" }) protected boolean finish(IProgressMonitor desiredMonitor) { IProgressMonitor monitor = desiredMonitor; if (monitor == null) { monitor = new NullProgressMonitor(); }//from www . jav a2 s . co m try { if (GWTPreferences.getDefaultRuntime().getVersion().isEmpty()) { IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No default GWT SDK."); ErrorDialog.openError(getShell(), null, null, status); return false; } monitor.beginTask("GWT-Platform project creation", 4); // Project base creation monitor.subTask("Base project creation"); formattedName = projectNameToClassName(page.getProjectName(), page.isRemoveEnabled()); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(page.getProjectName()); // Project location URI location = null; String workspace = ResourcesPlugin.getWorkspace().getRoot().getLocationURI().toString() + "/"; if (page.getProjectLocation() != null && !workspace.equals(page.getProjectLocation().toString())) { location = page.getProjectLocation(); } IProjectDescription description = project.getWorkspace().newProjectDescription(project.getName()); description.setLocationURI(location); // Project natures and builders ICommand javaBuilder = description.newCommand(); javaBuilder.setBuilderName(JavaCore.BUILDER_ID); ICommand webAppBuilder = description.newCommand(); webAppBuilder.setBuilderName(WebAppProjectValidator.BUILDER_ID); ICommand gwtBuilder = description.newCommand(); // TODO use the BUILDER_UI field gwtBuilder.setBuilderName("com.google.gwt.eclipse.core.gwtProjectValidator"); if (page.useGAE()) { ICommand gaeBuilder = description.newCommand(); gaeBuilder.setBuilderName(GaeProjectValidator.BUILDER_ID); // TODO use the BUILDER_UI field ICommand enhancer = description.newCommand(); // TODO use the BUILDER_UI field enhancer.setBuilderName("com.google.appengine.eclipse.core.enhancerbuilder"); description.setBuildSpec( new ICommand[] { javaBuilder, webAppBuilder, gwtBuilder, gaeBuilder, enhancer }); description.setNatureIds( new String[] { JavaCore.NATURE_ID, GWTNature.NATURE_ID, GaeNature.NATURE_ID }); } else { description.setBuildSpec(new ICommand[] { javaBuilder, webAppBuilder, gwtBuilder }); description.setNatureIds(new String[] { JavaCore.NATURE_ID, GWTNature.NATURE_ID }); } project.create(description, monitor); if (!project.isOpen()) { project.open(monitor); } monitor.worked(1); // Java Project creation monitor.subTask("Classpath entries creation"); IJavaProject javaProject = JavaCore.create(project); // war/WEB-INF/lib folder creation IPath warPath = new Path("war"); project.getFolder(warPath).create(false, true, monitor); IPath webInfPath = warPath.append("WEB-INF"); project.getFolder(webInfPath).create(false, true, monitor); IPath libPath = webInfPath.append("lib"); project.getFolder(libPath).create(false, true, monitor); Thread.sleep(1000); Jar[] libs = VersionTool.getLibs(project, libPath); // Classpath Entries creation List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); // Default output location IPath outputPath = new Path("/" + page.getProjectName()).append(webInfPath).append("classes"); javaProject.setOutputLocation(outputPath, monitor); // Source folder IPath srcPath = new Path("src"); project.getFolder(srcPath).create(false, true, monitor); entries.add(JavaCore.newSourceEntry(javaProject.getPath().append("src"))); // GWT SDK container IPath gwtContainer = GWTRuntimeContainer.CONTAINER_PATH; ClasspathContainerInitializer gwtInitializer = JavaCore .getClasspathContainerInitializer(gwtContainer.segment(0)); gwtInitializer.initialize(gwtContainer, javaProject); entries.add(JavaCore.newContainerEntry(gwtContainer)); // GAE SDK container if (page.useGAE()) { IPath gaeContainer = GaeSdkContainer.CONTAINER_PATH; ClasspathContainerInitializer gaeInitializer = JavaCore .getClasspathContainerInitializer(gaeContainer.segment(0)); gaeInitializer.initialize(gaeContainer, javaProject); entries.add(JavaCore.newContainerEntry(gaeContainer)); } // JRE container entries.addAll(Arrays.asList(PreferenceConstants.getDefaultJRELibrary())); // GWTP libs for (Jar lib : libs) { entries.add(JavaCore.newLibraryEntry(lib.getFile().getFullPath(), null, null)); } javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor); monitor.worked(1); monitor.subTask("Default classes creation"); IPackageFragmentRoot root = javaProject.findPackageFragmentRoot(javaProject.getPath().append("src")); // Create sources if (page.useGAE()) { Log4j log4j = new Log4j(project, srcPath); log4j.createFile(); IPath metaInfPath = srcPath.append("META-INF"); project.getFolder(metaInfPath).create(false, true, monitor); Jdoconfig jdoconfig = new Jdoconfig(project, metaInfPath); jdoconfig.createFile(); } IPackageFragment projectPackage = root.createPackageFragment(page.getProjectPackage(), false, monitor); // Client package IPackageFragment clientPackage = root.createPackageFragment(projectPackage.getElementName() + ".client", false, monitor); // Place package IPackageFragment placePackage = root.createPackageFragment(clientPackage.getElementName() + ".place", false, monitor); PlaceAnnotation defaultPlace = new PlaceAnnotation(root, placePackage.getElementName(), "DefaultPlace", sourceWriterFactory); PlaceManager placeManager = new PlaceManager(root, placePackage.getElementName(), "ClientPlaceManager", sourceWriterFactory); IField defaultPlaceField = placeManager.createPlaceRequestField(defaultPlace.getType()); placeManager.createConstructor(new IType[] { defaultPlace.getType() }, new IField[] { defaultPlaceField }); placeManager.createRevealDefaultPlaceMethod(defaultPlaceField); Tokens tokens = new Tokens(root, placePackage.getElementName(), "NameTokens", sourceWriterFactory); // Gin package IPackageFragment ginPackage = root.createPackageFragment(clientPackage.getElementName() + ".gin", false, monitor); PresenterModule presenterModule = new PresenterModule(root, ginPackage.getElementName(), "ClientModule", sourceWriterFactory); presenterModule.createConfigureMethod(placeManager.getType()); Ginjector ginjector = new Ginjector(root, ginPackage.getElementName(), "ClientGinjector", presenterModule.getType(), sourceWriterFactory); ginjector.createDefaultGetterMethods(); // Client package contents EntryPoint entryPoint = new EntryPoint(root, clientPackage.getElementName(), formattedName, sourceWriterFactory); entryPoint.createGinjectorField(ginjector.getType()); entryPoint.createOnModuleLoadMethod(); // Project package contents GwtXmlModule gwtXmlModule = new GwtXmlModule(root, projectPackage.getElementName(), formattedName); gwtXmlModule.createFile(entryPoint.getType(), ginjector.getType()); // Server package IPackageFragment serverPackage = root.createPackageFragment(projectPackage.getElementName() + ".server", false, monitor); // Guice package IPackageFragment guicePackage = root.createPackageFragment(serverPackage.getElementName() + ".guice", false, monitor); String gwtVersion = GWTPreferences.getDefaultRuntime().getVersion(); ServletModule servletModule = new ServletModule(root, guicePackage.getElementName(), "DispatchServletModule", sourceWriterFactory); servletModule.createConfigureServletsMethod(gwtVersion); GuiceHandlerModule handlerModule = new GuiceHandlerModule(root, guicePackage.getElementName(), "ServerModule", sourceWriterFactory); handlerModule.createConfigureHandlersMethod(); GuiceServletContextListener guiceServletContextListener = new GuiceServletContextListener(root, guicePackage.getElementName(), "GuiceServletConfig", sourceWriterFactory); guiceServletContextListener.createInjectorGetterMethod(handlerModule.getType(), servletModule.getType()); // Shared package root.createPackageFragment(projectPackage.getElementName() + ".shared", false, monitor); // Basic sample creation if (page.isSample()) { BasicSampleBuilder sampleBuilder = new BasicSampleBuilder(root, projectPackage, sourceWriterFactory); sampleBuilder.createSample(ginjector, presenterModule, tokens, defaultPlace, handlerModule); } // Commit presenterModule.commit(); ginjector.commit(); defaultPlace.commit(); placeManager.commit(); tokens.commit(); entryPoint.commit(); servletModule.commit(); handlerModule.commit(); guiceServletContextListener.commit(); // war contents ProjectHTML projectHTML = new ProjectHTML(project, warPath, project.getName()); projectHTML.createFile(); ProjectCSS projectCSS = new ProjectCSS(project, warPath, project.getName()); projectCSS.createFile(); // war/WEB-INF contents WebXml webXml = new WebXml(project, webInfPath); webXml.createFile(projectHTML.getFile(), guiceServletContextListener.getType()); if (page.useGAE()) { AppengineWebXml appengineWebXml = new AppengineWebXml(project, webInfPath); appengineWebXml.createFile(); Logging logging = new Logging(project, webInfPath); logging.createFile(); } monitor.worked(1); // Launch Config monitor.subTask("Launch config creation"); ILaunchConfigurationWorkingCopy launchConfig = WebAppLaunchUtil.createLaunchConfigWorkingCopy( project.getName(), project, WebAppLaunchUtil.determineStartupURL(project, false), false); ILaunchGroup[] groups = DebugUITools.getLaunchGroups(); ArrayList groupsNames = new ArrayList(); for (ILaunchGroup group : groups) { if ((!("org.eclipse.debug.ui.launchGroup.debug".equals(group.getIdentifier()))) && (!("org.eclipse.debug.ui.launchGroup.run".equals(group.getIdentifier())))) { continue; } groupsNames.add(group.getIdentifier()); } launchConfig.setAttribute("org.eclipse.debug.ui.favoriteGroups", groupsNames); launchConfig.doSave(); project.getProject().setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "nametokens"), tokens.getType().getFullyQualifiedName()); project.getProject().setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "ginjector"), ginjector.getType().getFullyQualifiedName()); project.getProject().setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "presentermodule"), presenterModule.getType().getFullyQualifiedName()); project.getProject().setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "handlermodule"), handlerModule.getType().getFullyQualifiedName()); project.getProject().setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "action"), "com.gwtplatform.dispatch.shared.ActionImpl"); // Remove bin folder IFolder binFolder = project.getFolder(new Path("/bin")); if (binFolder.exists()) { binFolder.delete(true, monitor); } monitor.worked(1); } catch (Exception e) { IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "An unexpected error has happened. Close the wizard and retry.", e); ErrorDialog.openError(getShell(), null, null, status); return false; } monitor.done(); return true; }
From source file:com.ibm.xsp.extlib.designer.relational.utils.ProjectUtils.java
License:Open Source License
public static IProject createPluginProject(final ProjectDef projectDef) throws Exception { IProject project = null;/*w w w . j a v a2s .co m*/ try { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); project = root.getProject(projectDef.name + "_" + projectDef.version); if (project.exists()) { project.delete(true, true, null); } project.create(null); project.open(null); IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] { "org.eclipse.pde.PluginNature", JavaCore.NATURE_ID }); // $NON-NLS-1$ project.setDescription(description, null); IJavaProject javaProject = JavaCore.create(project); // Contruct the classpath List<IClasspathEntry> classpathList = new ArrayList<IClasspathEntry>(); // Source folders for (String folderName : projectDef.srcFolders) { IFolder folder = project.getFolder(folderName); // Create the src folders in the project if (!folder.exists()) { folder.create(false, true, null); } IClasspathEntry srcClasspathEntry = JavaCore.newSourceEntry(folder.getFullPath()); classpathList.add(srcClasspathEntry); } // Add Lib Classpaths if (!StringUtil.isEmpty(projectDef.libFolder)) { IFolder folder = project.getFolder(projectDef.libFolder); // Create the lib folder in the project if (!folder.exists()) { folder.create(true, true, null); } for (String lib : projectDef.libs) { IClasspathEntry srcClasspathEntry = JavaCore.newLibraryEntry( new Path(folder.getFullPath() + "/" + new File(lib).getName()), null, null, true); classpathList.add(srcClasspathEntry); } } classpathList.add(JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER"))); // $NON-NLS-1$ classpathList.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins"))); // $NON-NLS-1$ // Set the project classpath javaProject.setRawClasspath(classpathList.toArray(new IClasspathEntry[classpathList.size()]), null); } catch (Exception e) { if (project != null) { closeAndDeleteProject(project, true); } throw new Exception("Error creating temporary Plug-in project in the Workspace", e); // $NLX-ProjectUtils.ErrorcreatingtemporaryPluginproje-1$ } return project; }
From source file:com.iw.plugins.spindle.ui.properties.ProjectPropertyPage.java
License:Mozilla Public License
private void doOk(IProgressMonitor monitor) throws CoreException { // store the values as properties IResource resource = (IResource) getElement(); // resource.setPersistentProperty( // new QualifiedName("", PROJECT_TYPE_PROPERTY), // new Integer(TapestryProject.APPLICATION_PROJECT_TYPE).toString()); resource.setPersistentProperty(new QualifiedName("", CONTEXT_ROOT_PROPERTY), fWebContextRoot.getText()); resource.setPersistentProperty(new QualifiedName("", VALIDATE_WEBXML_PROPERTY), Boolean.toString(fValidateWebXML.getSelection())); final IProject workspaceProject = (IProject) (this.getElement().getAdapter(IProject.class)); IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { if (fIsTapestryProjectCheck.getSelection()) { String projectName = workspaceProject.getProject().getName(); String temp = fWebContextRoot.getText(); createFolderIfRequired(projectName + temp); fNewProjectMetadata.setWebContext(temp); fNewProjectMetadata.setValidateWebXML(fValidateWebXML.getSelection()); fNewProjectMetadata.saveProperties(monitor); IJavaProject jproject = getJavaProject(); TapestryProject prj = getTapestryProject(); if (prj == null) { TapestryProject.addTapestryNature(jproject, true); } else { prj.clearMetadata(); }/*ww w . j a v a2 s . co m*/ try { if (jproject .findType(TapestryCore.getString("TapestryComponentSpec.specInterface")) == null) { MessageDialog dialog = new MessageDialog(getShell(), "Tapestry jars missing", null, "Add the Tapestry jars to the classpath?", MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0); // OK is the default int result = dialog.open(); if (result == 0) { List entries = Arrays.asList(jproject.getRawClasspath()); ArrayList useEntries = new ArrayList(entries); useEntries.add(JavaCore.newContainerEntry(new Path(TapestryCore.CORE_CONTAINER))); jproject.setRawClasspath( (IClasspathEntry[]) useEntries.toArray(new IClasspathEntry[entries.size()]), monitor); } } } catch (JavaModelException e) { UIPlugin.log(e); } } else { TapestryProject.removeTapestryNature(getJavaProject()); } if (fIsTapestryProjectCheck.getSelection()) { IProject project = getJavaProject().getProject(); project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); } } }; UIPlugin.getWorkspace().run(runnable, monitor); }
From source file:com.iw.plugins.spindle.wizards.project.NewProjectUtils.java
License:Mozilla Public License
private static void addToClasspath(String jarFileName, IJavaProject jproject, IProgressMonitor monitor) throws InterruptedException, CoreException { URL installUrl = TapestryPlugin.getDefault().getDescriptor().getInstallURL(); URL jarURL = null;/*from w ww . j a va 2 s . c o m*/ try { jarURL = new URL(installUrl, jarFileName); jarURL = Platform.resolve(jarURL); } catch (IOException e) { } if (jarURL == null) { return; } IClasspathEntry[] classpath = jproject.getRawClasspath(); IClasspathEntry[] newClasspath = new IClasspathEntry[classpath.length + 1]; System.arraycopy(classpath, 0, newClasspath, 0, classpath.length); newClasspath[classpath.length] = new ClasspathEntry(IPackageFragmentRoot.K_BINARY, ClasspathEntry.CPE_LIBRARY, new Path(jarURL.getFile()), new Path[] {}, null, null, null, false); jproject.setRawClasspath(newClasspath, monitor); }
From source file:com.jaspersoft.studio.wizards.dataadapter.PluginHelper.java
License:Open Source License
/** * Create a plugin project in the workspace. Project will contains * the folder libs and images included also into the build file, to * allow to easily add images and libraries * // w ww. j a v a 2s . co m * @param adapterInfo the information of the plugin * @param srcFolders the source folders of the project * @param requiredBundles the bundles required by the project * @param requiredLibs the jar libraries required by the project * @param progressMonitor a progress monitor * @return the generated project */ public static IProject createPluginProject(AdapterInfo adapterInfo, List<String> srcFolders, List<String> requiredBundles, List<File> requiredLibs, IProgressMonitor progressMonitor) { IProject project = null; try { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); project = workspace.getRoot().getProject(adapterInfo.getProjectName()); final IJavaProject javaProject = JavaCore.create(project); final IProjectDescription projectDescription = ResourcesPlugin.getWorkspace() .newProjectDescription(adapterInfo.getProjectName()); projectDescription.setLocation(null); project.create(projectDescription, progressMonitor); final List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); projectDescription.setNatureIds(new String[] { JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature" }); final ICommand java = projectDescription.newCommand(); java.setBuilderName(JavaCore.BUILDER_ID); final ICommand manifest = projectDescription.newCommand(); manifest.setBuilderName("org.eclipse.pde.ManifestBuilder"); final ICommand schema = projectDescription.newCommand(); schema.setBuilderName("org.eclipse.pde.SchemaBuilder"); final ICommand oaw = projectDescription.newCommand(); projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema, oaw }); project.open(progressMonitor); project.setDescription(projectDescription, progressMonitor); Collections.reverse(srcFolders); for (final String src : srcFolders) { final IFolder srcContainer = project.getFolder(src); if (!srcContainer.exists()) { srcContainer.create(false, true, progressMonitor); } final IClasspathEntry srcClasspathEntry = JavaCore.newSourceEntry(srcContainer.getFullPath()); classpathEntries.add(0, srcClasspathEntry); } //Add the jar libraries to the project IFolder libsFolder = project.getFolder("libs"); libsFolder.create(false, true, progressMonitor); List<IFile> externalLibs = new ArrayList<IFile>(); for (File libFile : requiredLibs) { if (libFile != null && libFile.exists()) { InputStream resourceAsStream = new FileInputStream(libFile); PluginHelper.createFile(libFile.getName(), libsFolder, resourceAsStream, progressMonitor); IFile file = libsFolder.getFile(libFile.getName()); IPath path = file.getFullPath(); classpathEntries.add(JavaCore.newLibraryEntry(path, path, null, true)); externalLibs.add(file); } } classpathEntries.add(JavaCore.newContainerEntry(new Path( "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"))); classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins"))); javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), progressMonitor); javaProject.setOutputLocation(new Path("/" + adapterInfo.getProjectName() + "/bin"), progressMonitor); ProjectUtil.createJRClasspathContainer(progressMonitor, javaProject); IFolder imagesFolder = project.getFolder("images"); imagesFolder.create(false, true, progressMonitor); createManifest(adapterInfo, requiredBundles, externalLibs, progressMonitor, project); createBuildProps(progressMonitor, project, srcFolders); } catch (final Exception exception) { exception.printStackTrace(); JaspersoftStudioPlugin.getInstance().logError(exception); } return project; }
From source file:com.javadude.antxr.eclipse.core.AntxrNature.java
License:Open Source License
public void configure() throws CoreException { if (AntxrNature.DEBUG) { System.out.println("configuring ANTXR nature"); }//w ww . ja va 2s. c o m IProject project = getProject(); IProjectDescription projectDescription = project.getDescription(); List<ICommand> commands = new ArrayList<ICommand>(Arrays.asList(projectDescription.getBuildSpec())); ICommand antxrBuilderCommand = projectDescription.newCommand(); antxrBuilderCommand.setBuilderName(AntxrBuilder.BUILDER_ID); ICommand warningCleanerBuilderCommand = projectDescription.newCommand(); warningCleanerBuilderCommand.setBuilderName(WarningCleanerBuilder.BUILDER_ID); ICommand smapBuilderCommand = projectDescription.newCommand(); smapBuilderCommand.setBuilderName(SMapInstallerBuilder.BUILDER_ID); if (!commands.contains(antxrBuilderCommand)) { commands.add(0, antxrBuilderCommand); // add at start } if (!commands.contains(warningCleanerBuilderCommand)) { commands.add(warningCleanerBuilderCommand); // add at end } if (!commands.contains(smapBuilderCommand)) { commands.add(smapBuilderCommand); // add at end } // Commit the spec change into the project projectDescription.setBuildSpec(commands.toArray(new ICommand[commands.size()])); getProject().setDescription(projectDescription, null); // // add the antxr.jar file to a lib dir // IFolder folder = getProject().getFolder("lib"); // if (!folder.exists()) { // folder.create(true, true, null); // } // IPath rawLocation = folder.getRawLocation(); // URL antxrJarUrl = AntxrCorePlugin.getDefault().getBundle().getEntry("lib/antxr.jar"); // // BufferedOutputStream bout = null; // BufferedInputStream bin = null; // int b; // try { // try { // bout = new BufferedOutputStream(new FileOutputStream(new File(rawLocation.toFile(), "antxr.jar"))); // bin = new BufferedInputStream(antxrJarUrl.openStream()); // while ((b = bin.read()) != -1) { // bout.write(b); // } // } finally { // if (bout != null) { // bout.close(); // } // if (bin != null) { // bin.close(); // } // } // } catch (IOException e) { // e.printStackTrace(); // } // // folder.refreshLocal(IResource.DEPTH_ONE, null); // // // add the jar to the classpath if not present // String jarPath = "/" + getProject().getName() + "/lib/antxr.jar"; IFolder antxr3GeneratedFolder = getProject().getFolder("antxr-generated"); if (!antxr3GeneratedFolder.exists()) { antxr3GeneratedFolder.create(true, true, null); } String generatedSourcePath = "/" + getProject().getName() + "/antxr-generated"; final IJavaProject javaProject = JavaCore.create(getProject()); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); boolean generatedSourceDirFound = false; for (IClasspathEntry classpathEntry : rawClasspath) { // if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // if (classpathEntry.getPath().toString().equals(jarPath)) { // found = true; // } // } if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (classpathEntry.getPath().toString().equals(generatedSourcePath)) { generatedSourceDirFound = true; } } } int toAdd = 0; if (!generatedSourceDirFound) { toAdd++; } if (!generatedSourceDirFound) { final IClasspathEntry newEntries[] = new IClasspathEntry[rawClasspath.length + toAdd]; System.arraycopy(rawClasspath, 0, newEntries, 0, rawClasspath.length); // newEntries[rawClasspath.length] = JavaCore.newLibraryEntry(new Path(jarPath), Path.EMPTY, Path.ROOT); if (!generatedSourceDirFound) { newEntries[newEntries.length - 1] = JavaCore.newSourceEntry(new Path(generatedSourcePath)); } JavaCore.run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { javaProject.setRawClasspath(newEntries, null); } }, null); } }
From source file:com.javadude.antxr.eclipse.core.AntxrNature.java
License:Open Source License
public void deconfigure() throws CoreException { if (AntxrNature.DEBUG) { System.out.println("deconfiguring ANTXR nature"); }/* w ww .ja v a2 s . c om*/ IProject project = getProject(); IProjectDescription desc = project.getDescription(); List<ICommand> commands = new ArrayList<ICommand>(Arrays.asList(desc.getBuildSpec())); for (Iterator i = commands.iterator(); i.hasNext();) { ICommand command = (ICommand) i.next(); if (command.getBuilderName().equals(AntxrBuilder.BUILDER_ID) || command.getBuilderName().equals(SMapInstallerBuilder.BUILDER_ID) || command.getBuilderName().equals(WarningCleanerBuilder.BUILDER_ID)) { i.remove(); } } // Commit the spec change into the project desc.setBuildSpec(commands.toArray(new ICommand[commands.size()])); project.setDescription(desc, null); // remove the jar from the classpath if present // delete the jar from the lib dir // if the lib dir is empty, delete it // String jarPath = "/" + getProject().getName() + "/lib/antxr.jar"; String generatedSourcePath = "/" + getProject().getName() + "/antxr-generated"; final IJavaProject javaProject = JavaCore.create(getProject()); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); final List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : rawClasspath) { // if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // if (entry.getPath().toString().equals(jarPath)) { // found = i; // break; // } if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (entry.getPath().toString().equals(generatedSourcePath)) { continue; // skip the antxr-generated source folder } } newEntries.add(entry); } JavaCore.run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { IClasspathEntry entries[] = newEntries.toArray(new IClasspathEntry[newEntries.size()]); javaProject.setRawClasspath(entries, null); IFolder folder = getProject().getFolder("antxr-generated"); if (folder.exists() && !hasNonAntxrGeneratedFile(folder)) { folder.delete(true, null); } else { AntxrCorePlugin.getUtil().warning(4211, "Did not delete antxr-generated source directory; it contains non-generated source. You should move that source to another source dir; it really doesn't belong there..."); } } }, null); }
From source file:com.legstar.eclipse.plugin.common.wizards.AbstractWizardPage.java
License:Open Source License
/** * The target Java project needs a container library on its classpath. * This assumes a classpath initializer did define the library * container and all what is left to do is to update the project with yet * another classpath entry.//from w ww . j a v a 2 s . c o m * * @param jproject the target java project * @param libraryName the name of the container library * @throws JavaModelException if seting up classpath fails */ public void setupContainerLibrary(final IJavaProject jproject, final String libraryName) throws JavaModelException { IClasspathEntry varEntry = JavaCore.newContainerEntry(new Path(libraryName), false); java.util.List<IClasspathEntry> sourceEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : jproject.getRawClasspath()) { sourceEntries.add(entry); } sourceEntries.add(varEntry); IClasspathEntry[] entries = (IClasspathEntry[]) sourceEntries .toArray(new IClasspathEntry[sourceEntries.size()]); jproject.setRawClasspath(entries, null); }
From source file:com.liferay.ide.gradle.core.LiferayGradleProject.java
License:Open Source License
private IFolder createResorcesFolder(IProject project) { try {/*from w w w . j ava 2 s. c om*/ IJavaProject javaProject = JavaCore.create(project); List<IClasspathEntry> existingRawClasspath; existingRawClasspath = Arrays.asList(javaProject.getRawClasspath()); List<IClasspathEntry> newRawClasspath = new ArrayList<IClasspathEntry>(); IClasspathAttribute[] attributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute("FROM_GRADLE_MODEL", "true") }; //$NON-NLS-1$ //$NON-NLS-2$ IClasspathEntry resourcesEntry = JavaCore.newSourceEntry( project.getFullPath().append("src/main/resources"), new IPath[0], new IPath[0], null, attributes); for (IClasspathEntry entry : existingRawClasspath) { newRawClasspath.add(entry); } if (!existingRawClasspath.contains(resourcesEntry)) { newRawClasspath.add(resourcesEntry); } javaProject.setRawClasspath(newRawClasspath.toArray(new IClasspathEntry[0]), new NullProgressMonitor()); project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); IFolder[] sourceFolders = getSourceFolders(); for (IFolder folder : sourceFolders) { if (folder.getName().equals("resources")) { return folder; } } } catch (CoreException e) { GradleCore.logError(e); } return null; }