List of usage examples for org.eclipse.jdt.core JavaCore BUILDER_ID
String BUILDER_ID
To view the source code for org.eclipse.jdt.core JavaCore BUILDER_ID.
Click Source Link
"org.eclipse.jdt.core.javabuilder"
). From source file:at.bestsolution.fxide.jdt.maven.MavenModuleTypeService.java
License:Open Source License
@Override public Status createModule(IProject project, IResource resource) { IProjectDescription description = project.getWorkspace().newProjectDescription(project.getName()); description.setNatureIds(new String[] { JavaCore.NATURE_ID, "org.eclipse.m2e.core.maven2Nature" }); ICommand[] commands = new ICommand[2]; {//from ww w. j a v a2 s . c om ICommand cmd = description.newCommand(); cmd.setBuilderName(JavaCore.BUILDER_ID); commands[0] = cmd; } { ICommand cmd = description.newCommand(); cmd.setBuilderName("org.eclipse.m2e.core.maven2Builder"); commands[1] = cmd; } if (resource != null) { // If we get a parent path we create a nested project try { if (resource.getProject().getNature("org.eclipse.m2e.core.maven2Nature") != null) { IFolder folder = resource.getProject().getFolder(project.getName()); if (folder.exists()) { return Status.status(State.ERROR, -1, "Folder already exists", null); } folder.create(true, true, null); description.setLocation(folder.getLocation()); } } catch (CoreException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return Status.status(State.ERROR, -1, "Could not create parent relation", e1); } } description.setBuildSpec(commands); try { project.create(description, null); project.open(null); project.getFolder(new Path("target")).create(true, true, null); project.getFolder(new Path("target").append("classes")).create(true, true, null); project.getFolder(new Path("target")).setDerived(true, null); project.getFolder(new Path("target").append("classes")).setDerived(true, null); project.getFolder(new Path("src")).create(true, true, null); project.getFolder(new Path("src").append("main")).create(true, true, null); project.getFolder(new Path("src").append("main").append("java")).create(true, true, null); project.getFolder(new Path("src").append("main").append("resources")).create(true, true, null); project.getFolder(new Path("src").append("test")).create(true, true, null); project.getFolder(new Path("src").append("test").append("java")).create(true, true, null); project.getFolder(new Path("src").append("test").append("resources")).create(true, true, null); { IFile file = project.getFile(new Path("pom.xml")); try (InputStream templateStream = getClass().getResourceAsStream("template-pom.xml")) { String pomContent = IOUtils.readToString(templateStream, Charset.forName("UTF-8")); Map<String, String> map = new HashMap<>(); map.put("groupId", project.getName()); map.put("artifactId", project.getName()); map.put("version", "1.0.0"); file.create(new ByteArrayInputStream(StrSubstitutor.replace(pomContent, map).getBytes()), true, null); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } IJavaProject jProject = JavaCore.create(project); jProject.setOutputLocation(project.getFolder(new Path("target").append("classes")).getFullPath(), null); List<IClasspathEntry> entries = new ArrayList<>(); { IClasspathAttribute[] attributes = new IClasspathAttribute[2]; attributes[0] = JavaCore.newClasspathAttribute("optional", "true"); attributes[1] = JavaCore.newClasspathAttribute("maven.pomderived", "true"); IPath path = new Path("src").append("main").append("java"); IPath output = new Path("target").append("classes"); IClasspathEntry sourceEntry = JavaCore.newSourceEntry( project.getProject().getFullPath().append(path), null, null, project.getProject().getFullPath().append(output), attributes); entries.add(sourceEntry); } { IClasspathAttribute[] attributes = new IClasspathAttribute[1]; attributes[0] = JavaCore.newClasspathAttribute("maven.pomderived", "true"); IPath path = new Path("src").append("main").append("resources"); IPath output = new Path("target").append("classes"); IPath[] exclusions = new IPath[] { new Path("**") }; entries.add(JavaCore.newSourceEntry(project.getProject().getFullPath().append(path), null, exclusions, project.getProject().getFullPath().append(output), attributes)); } { IClasspathAttribute[] attributes = new IClasspathAttribute[2]; attributes[0] = JavaCore.newClasspathAttribute("optional", "true"); attributes[1] = JavaCore.newClasspathAttribute("maven.pomderived", "true"); IPath path = new Path("src").append("test").append("java"); IPath output = new Path("target").append("test-classes"); IClasspathEntry sourceEntry = JavaCore.newSourceEntry( project.getProject().getFullPath().append(path), null, null, project.getProject().getFullPath().append(output), attributes); entries.add(sourceEntry); } { IClasspathAttribute[] attributes = new IClasspathAttribute[1]; attributes[0] = JavaCore.newClasspathAttribute("maven.pomderived", "true"); IPath path = new Path("src").append("test").append("resources"); IPath output = new Path("target").append("test-classes"); IPath[] exclusions = new IPath[] { new Path("**") }; entries.add(JavaCore.newSourceEntry(project.getProject().getFullPath().append(path), null, exclusions, project.getProject().getFullPath().append(output), attributes)); } { IClasspathAttribute[] attributes = new IClasspathAttribute[1]; attributes[0] = JavaCore.newClasspathAttribute("maven.pomderived", "true"); IPath path = JavaRuntime.newDefaultJREContainerPath(); entries.add(JavaCore.newContainerEntry(path, null, attributes, false)); } { IClasspathAttribute[] attributes = new IClasspathAttribute[1]; attributes[0] = JavaCore.newClasspathAttribute("maven.pomderived", "true"); IPath path = new Path("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"); entries.add(JavaCore.newContainerEntry(path, null, attributes, false)); } jProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]), null); project.getWorkspace().save(true, null); return Status.ok(); } catch (CoreException ex) { //TODO ex.printStackTrace(); return Status.status(State.ERROR, -1, "Failed to create project", ex); } }
From source file:at.bestsolution.fxide.jdt.services.JDTModuleTypeService.java
License:Open Source License
@Override public Status createModule(IProject project, IResource resource) { IProjectDescription description = project.getWorkspace().newProjectDescription(project.getName()); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); ICommand cmd = description.newCommand(); cmd.setBuilderName(JavaCore.BUILDER_ID); description.setBuildSpec(new ICommand[] { cmd }); try {/* w ww .j av a 2 s. c o m*/ project.create(description, null); project.open(null); project.getFolder(new Path("target")).create(true, true, null); project.getFolder(new Path("target").append("classes")).create(true, true, null); project.getFolder(new Path("target")).setDerived(true, null); project.getFolder(new Path("target").append("classes")).setDerived(true, null); project.getFolder(new Path("src")).create(true, true, null); project.getFolder(new Path("src").append("main")).create(true, true, null); project.getFolder(new Path("src").append("main").append("java")).create(true, true, null); project.getFolder(new Path("src").append("main").append("resources")).create(true, true, null); project.getFolder(new Path("src").append("test")).create(true, true, null); project.getFolder(new Path("src").append("test").append("java")).create(true, true, null); project.getFolder(new Path("src").append("test").append("resources")).create(true, true, null); // IExecutionEnvironmentsManager executionEnvironmentsManager = JavaRuntime.getExecutionEnvironmentsManager(); // IExecutionEnvironment[] executionEnvironments = executionEnvironmentsManager.getExecutionEnvironments(); // System.err.println(JavaRuntime.getDefaultVMInstall().getInstallLocation()); IJavaProject jProject = JavaCore.create(project); jProject.setOutputLocation(project.getFolder(new Path("target").append("classes")).getFullPath(), null); List<IClasspathEntry> entries = new ArrayList<>(); entries.add(JavaCore.newSourceEntry( project.getProject().getFullPath().append("src").append("main").append("java"))); entries.add(JavaCore.newSourceEntry( project.getProject().getFullPath().append("src").append("main").append("resources"))); entries.add(JavaCore.newSourceEntry( project.getProject().getFullPath().append("src").append("test").append("java"))); entries.add(JavaCore.newSourceEntry( project.getProject().getFullPath().append("src").append("test").append("resources"))); entries.add(JavaCore.newContainerEntry(JavaRuntime.newDefaultJREContainerPath())); jProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]), null); project.getWorkspace().save(true, null); return Status.ok(); } catch (CoreException ex) { return Status.status(State.ERROR, -1, "Failed to create project", ex); } }
From source file:com.ebmwebsourcing.petals.services.jsr181.v11.Jsr181ProvidesWizard11.java
License:Open Source License
/** * Completes the wizard for a WSDL-first approach. * * @param jp the Java project/*from w w w.j a v a 2s .co m*/ * @param ae * @param resourcesToSelect * @param monitor */ private void wsdlFirstApproach(IJavaProject jp, AbstractEndpoint ae, IProgressMonitor monitor) { try { // Create the WS implementation IProject project = jp.getProject(); URI wsdlUri = UriAndUrlHelper.urlToUri(this.page.getWsdlUriAsString()); IFolder srcFolder = project.getFolder(PetalsConstants.LOC_SRC_FOLDER); File srcDirectory = srcFolder.getLocation().toFile(); Map<String, String> buildOptions = new HashMap<String, String>(); JaxWsUtils.INSTANCE.generateWsClient(wsdlUri, srcDirectory); srcFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor); project.build(IncrementalProjectBuilder.FULL_BUILD, JavaCore.BUILDER_ID, buildOptions, monitor); srcFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor); JaxWsUtils.removeWebServiceClient(jp, monitor); Map<String, String> serviceNameToClassName = JaxWsUtils.createJaxWsImplementation(jp, monitor); srcFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor); project.build(IncrementalProjectBuilder.FULL_BUILD, JavaCore.BUILDER_ID, buildOptions, monitor); // Update JBI JbiBasicBean bean = WsdlUtils.INSTANCE.parse(this.page.getWsdlUriAsString()).get(0); ae.eSet(JbiPackage.Literals.ABSTRACT_ENDPOINT__INTERFACE_NAME, bean.getInterfaceName()); ae.eSet(JbiPackage.Literals.ABSTRACT_ENDPOINT__SERVICE_NAME, bean.getServiceName()); ae.eSet(JbiPackage.Literals.ABSTRACT_ENDPOINT__ENDPOINT_NAME, bean.getEndpointName()); ae.eSet(Jsr181Package.Literals.JSR181_PROVIDES__CLAZZ, serviceNameToClassName.values().iterator().next()); // Import the WSDL in the project IFolder resFolder = project.getFolder(PetalsConstants.LOC_RES_FOLDER); File resFile = resFolder.getLocation().toFile(); Map<String, File> uriToFile = new WsdlImportHelper().importWsdlOrXsdAndDependencies(resFile, this.page.getWsdlUriAsString()); File f = uriToFile.get(this.page.getWsdlUriAsString()); String wsdlName = f == null ? wsdlUri.toURL().getFile() : f.getName(); ae.eSet(Cdk5Package.Literals.CDK5_PROVIDES__WSDL, wsdlName); resFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor); // Open the implementation file final List<IFile> javaFiles = new ArrayList<IFile>(); for (String className : serviceNameToClassName.values()) { IFile javaFile = srcFolder.getFile(className.replaceAll("\\.", "/") + ".java"); javaFiles.add(javaFile); } this.resourcesToSelect.addAll(javaFiles); Display.getDefault().asyncExec(new Runnable() { @Override public void run() { try { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); for (IFile file : javaFiles) IDE.openEditor(page, file); } catch (PartInitException e) { PetalsJsr181Plugin.log(e, IStatus.ERROR); } } }); } catch (Exception e) { PetalsJsr181Plugin.log(e, IStatus.ERROR); } }
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 ww w. j ava 2s .c om*/ 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.ifedorenko.m2e.binaryproject.tests.BinaryProjectTest.java
License:Open Source License
public void testBasic() throws Exception { IProject project = BinaryProjectPlugin.getInstance().create("org.apache.maven", "maven-core", "3.0.4", null, monitor);// w w w. j a va 2 s . c o m assertTrue(project.hasNature(IMavenConstants.NATURE_ID)); assertTrue(project.hasNature(JavaCore.NATURE_ID)); assertNotNull(BuildPathManager.getMaven2ClasspathContainer(JavaCore.create(project))); assertFalse(hasBuilder(project, JavaCore.BUILDER_ID)); IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().create(project, monitor); assertNotNull(facade); assertEquals(BinaryProjectPlugin.LIFECYCLE_MAPPING_ID, facade.getLifecycleMappingId()); IJavaProject javaProject = JavaCore.create(project); ClasspathHelpers.assertClasspath( new String[] { "org.eclipse.jdt.launching.JRE_CONTAINER/.*", "org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER", ".*/maven-core-3.0.4.jar" }, javaProject.getRawClasspath()); IClasspathEntry[] mavenClasspath = BuildPathManager.getMaven2ClasspathContainer(javaProject) .getClasspathEntries(); assertTrue(mavenClasspath.length > 0); }
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 * //from w ww. j a v a 2 s. com * @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.siteview.mde.internal.ui.editor.monitor.ExecutionEnvironmentSection.java
License:Open Source License
private void doFullBuild(final IProject project) { Job buildJob = new Job(MDEUIMessages.CompilersConfigurationBlock_building) { public boolean belongsTo(Object family) { return ResourcesPlugin.FAMILY_MANUAL_BUILD == family; }//from ww w. ja v a 2 s. c om protected IStatus run(IProgressMonitor monitor) { try { project.build(IncrementalProjectBuilder.FULL_BUILD, JavaCore.BUILDER_ID, null, monitor); } catch (CoreException e) { } return Status.OK_STATUS; } }; buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); buildJob.schedule(); }
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. ja v a2s.c om 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:io.sarl.tests.api.WorkspaceTestHelper.java
License:Apache License
/** Create a project in the workspace with the given dependencies. * /*from w w w . j a v a 2 s. co m*/ * @param name - the name of the project. * @param requiredBundles - the bundles required by the project. * @return the project. * @throws CoreException * @see #createProject(String) * @see #DEFAULT_REQUIRED_BUNDLES */ public static IProject createProjectWithDependencies(String name, String... requiredBundles) throws CoreException { Injector injector = getSARLInjector(); JavaProjectFactory projectFactory = injector.getInstance(JavaProjectFactory.class); projectFactory.setProjectName(name); projectFactory.addFolders(Arrays.asList(SOURCE_FOLDER, GENERATED_SOURCE_FOLDER)); IPath srcGenFolder = Path.fromPortableString(GENERATED_SOURCE_FOLDER); projectFactory.addBuilderIds(XtextProjectHelper.BUILDER_ID, JavaCore.BUILDER_ID); projectFactory.addProjectNatures(SARL_NATURE, XtextProjectHelper.NATURE_ID, JavaCore.NATURE_ID); IProject result = projectFactory.createProject(new NullProgressMonitor(), null); IJavaProject javaProject = JavaCore.create(result); JavaProjectSetupUtil.makeJava5Compliant(javaProject); JavaProjectSetupUtil.addJreClasspathEntry(javaProject); assertTrue("Java nature is mandatory", result.hasNature(JavaCore.NATURE_ID)); //$NON-NLS-1$ assertTrue("Xtext nature is mandatoty", result.hasNature(XtextProjectHelper.NATURE_ID)); //$NON-NLS-1$ assertTrue("SARL nature is mandatoty", result.hasNature(SARL_NATURE)); //$NON-NLS-1$ IPath workspaceRoot; IPath platformLocation; try { workspaceRoot = ResourcesPlugin.getWorkspace().getRoot().getLocation(); Location location = Platform.getInstallLocation(); java.net.URI uri = org.eclipse.core.runtime.URIUtil.toURI(location.getURL()); platformLocation = URIUtil.toPath(uri); } catch (Exception e) { throw new RuntimeException(e); } // Retreive the bundles for (String bundleName : requiredBundles) { Bundle bundle = Platform.getBundle(bundleName); if (bundle == null) { throw new RuntimeException("Reference library not found: " + bundleName); //$NON-NLS-1$ } IPath bundlePath = computeBundlePath(bundle, workspaceRoot, platformLocation); if (bundlePath == null) { throw new RuntimeException("Reference library not found: " + bundleName); //$NON-NLS-1$ } IPath binPath = computeBinaryPathForBundle(bundlePath, workspaceRoot); if (binPath == null) { throw new RuntimeException("Reference library not found: " + bundleName); //$NON-NLS-1$ } // Create the classpath entry IClasspathEntry classPathEntry = JavaCore.newLibraryEntry(binPath, null, null); JavaProjectSetupUtil.addToClasspath(javaProject, classPathEntry); } // Configure SARL source folder SARLPreferences.setSpecificSARLConfigurationFor(result, srcGenFolder); return result; }
From source file:net.rim.ejde.internal.util.InternalImportUtils.java
License:Open Source License
/** * Attaches BlackBerry related builders to the <code>project</code>. * * @param project/*from ww w. ja v a 2 s .co m*/ * @throws CoreException */ static public void initiateBuilders(IProject project) throws CoreException { IProjectDescription description = project.getDescription(); ICommand[] projectBuilders = new ICommand[3]; // RIM Resource Builder ICommand rimResourceCommand = description.newCommand(); rimResourceCommand.setBuilderName(ResourceBuilder.BUILDER_ID); projectBuilders[0] = rimResourceCommand; // RIM Preprocessing Builder ICommand rimPreprocessingCommand = description.newCommand(); rimPreprocessingCommand.setBuilderName(PreprocessingBuilder.BUILDER_ID); projectBuilders[1] = rimPreprocessingCommand; // // Java Builder (built into JDT) ICommand javaBuilderCommand = description.newCommand(); javaBuilderCommand.setBuilderName(JavaCore.BUILDER_ID); projectBuilders[2] = javaBuilderCommand; description.setBuildSpec(projectBuilders); project.setDescription(description, new NullProgressMonitor()); }