List of usage examples for org.eclipse.jdt.core IJavaProject setOutputLocation
void setOutputLocation(IPath path, IProgressMonitor monitor) throws JavaModelException;
From source file:com.buglabs.dragonfly.ui.jobs.CreateBUGProjectJob.java
License:Open Source License
/** * @param proj//from w w w .j a va2 s . co m * @param monitor * @throws CoreException */ private void createBinFolder(IProject proj, IProgressMonitor monitor) throws CoreException { binContainer = proj; // bin.create(true, true, monitor); IJavaProject jproj = JavaCore.create(proj); jproj.setOutputLocation(binContainer.getFullPath(), monitor); }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.JavaUtils.java
License:Open Source License
/** * Makes an Eclipse project a Java project. * <p>/*from w ww . ja v a 2s. c o m*/ * If the project does not exist, or is not accessible, then nothing is done.<br /> * If the project does not have the Java nature, this nature is added. * </p> * <p> * The default output directory is "bin". If this directory does not exist, it is created. * If the creation fails, then no output directory is set. * </p> * <p> * The default source directory is "src/main/java". If this directory does not exist, it is created. * If the creation fails, then no source directory is set. * </p> * * @param project the project to transform into a Java project * @return the created Java project * @throws CoreException if something went wrong */ public static IJavaProject createJavaProject(IProject project) throws CoreException { IJavaProject jp = null; if (project.isAccessible()) { // Add the Java nature? if (!project.hasNature(JavaCore.NATURE_ID)) { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); } // Set the default class path jp = JavaCore.create(project); IProgressMonitor monitor = new NullProgressMonitor(); // // Output location IPath ppath = project.getFullPath(); IPath binPath = ppath.append(PetalsConstants.LOC_BIN_FOLDER); File binFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(binPath).toFile(); if (binFile.exists() && binFile.isDirectory() || !binFile.exists() && binFile.mkdirs()) { jp.setOutputLocation(binPath, monitor); } Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(); entries.addAll(Arrays.asList(jp.getRawClasspath())); entries.add(JavaRuntime.getDefaultJREContainerEntry()); // // Remove the "src" entry IClasspathEntry srcEntry = null; for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcEntry = entry; break; } } // // Specify a new source entry if (srcEntry != null) entries.remove(srcEntry); String[] srcPaths = new String[] { PetalsConstants.LOC_SRC_FOLDER, PetalsConstants.LOC_JAVA_RES_FOLDER }; for (String s : srcPaths) { IPath srcPath = ppath.append(s); File srcFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(srcPath).toFile(); if (srcFile.exists() && srcFile.isDirectory() || !srcFile.exists() && srcFile.mkdirs()) { project.refreshLocal(IResource.DEPTH_INFINITE, monitor); srcEntry = JavaCore.newSourceEntry(srcPath); entries.add(srcEntry); } else { PetalsCommonPlugin.log("Could not set '" + s + "' as a source folder.", IStatus.ERROR); } } jp.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor); } return jp; }
From source file:com.google.gdt.eclipse.core.WebAppUtilities.java
License:Open Source License
/** * Sets the project's default output directory to the WAR output directory's * WEB-INF/classes folder. If the WAR output directory does not have a WEB-INF * directory, this method returns without doing anything. * * @throws CoreException if there's a problem setting the output directory *//* ww w. j av a 2s.c o m*/ public static void setOutputLocationToWebInfClasses(IJavaProject javaProject, IProgressMonitor monitor) throws CoreException { IProject project = javaProject.getProject(); IFolder webInfOut = getWebInfOut(project); if (!webInfOut.exists()) { // If the project has no output <WAR>/WEB-INF directory, don't touch the // output location return; } IPath oldOutputPath = javaProject.getOutputLocation(); IPath outputPath = webInfOut.getFullPath().append("classes"); if (!outputPath.equals(oldOutputPath)) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); // Remove old output location and contents IFolder oldOutputFolder = workspaceRoot.getFolder(oldOutputPath); if (oldOutputFolder.exists()) { try { removeOldClassfiles(oldOutputFolder); } catch (Exception e) { CorePluginLog.logError(e); } } // Create the new output location if necessary IFolder outputFolder = workspaceRoot.getFolder(outputPath); if (!outputFolder.exists()) { // TODO: Could move recreate this in a utilities class CoreUtility.createDerivedFolder(outputFolder, true, true, null); } javaProject.setOutputLocation(outputPath, monitor); } }
From source file:com.google.gdt.eclipse.designer.wizards.model.project.ProjectWizard.java
License:Open Source License
/** * Configures given {@link IJavaProject} as GWT project - adds GWT library and nature. *//*from ww w .j a v a2s .c o m*/ public static final void configureProjectAsGWTProject(IJavaProject javaProject) throws Exception { IProject project = javaProject.getProject(); // add GWT classpath if (!ProjectUtils.hasType(javaProject, "com.google.gwt.core.client.GWT")) { IClasspathEntry entry; if (Utils.hasGPE()) { entry = JavaCore.newContainerEntry(new Path("com.google.gwt.eclipse.core.GWT_CONTAINER")); } else { entry = JavaCore.newVariableEntry(new Path("GWT_HOME/gwt-user.jar"), null, null); } ProjectUtils.addClasspathEntry(javaProject, entry); } // add GWT nature { ProjectUtils.addNature(project, Constants.NATURE_ID); if (Utils.hasGPE()) { ProjectUtils.addNature(project, "com.google.gwt.eclipse.core.gwtNature"); } } // continue { String webFolderName = WebUtils.getWebFolderName(project); // create folders ensureCreateFolder(project, webFolderName); ensureCreateFolder(project, webFolderName + "/WEB-INF"); IFolder classesFolder = ensureCreateFolder(project, webFolderName + "/WEB-INF/classes"); IFolder libFolder = ensureCreateFolder(project, webFolderName + "/WEB-INF/lib"); // set output javaProject.setOutputLocation(classesFolder.getFullPath(), null); // copy gwt-servlet.jar if (!libFolder.getFile("gwt-servlet.jar").exists()) { String servletJarLocation = Utils.getGWTLocation(project) + "/gwt-servlet.jar"; File srcFile = new File(servletJarLocation); File destFile = new File(libFolder.getLocation().toFile(), "gwt-servlet.jar"); FileUtils.copyFile(srcFile, destFile); libFolder.refreshLocal(IResource.DEPTH_INFINITE, null); } } }
From source file:com.google.gdt.eclipse.mobile.android.wizards.helpers.AndroidProjectCreator.java
License:Open Source License
/** * Create the project/* w w w .ja v a 2 s .c o m*/ * * @throws CoreException * @throws IOException * @throws StreamException */ public IProject create(IProgressMonitor monitor) throws CoreException, IOException, StreamException { IWorkspace workspace = ResourcesPlugin.getWorkspace(); androidProject = workspace.getRoot().getProject(projectName); androidProjectDescription = workspace.newProjectDescription(androidProject.getName()); IPath path = (IPath) androidProjectParameters.get(ProjectCreationConstants.PARAM_PROJECT_PATH); IPath defaultLocation = Platform.getLocation(); if (!path.equals(defaultLocation)) { androidProjectDescription.setLocation(path.append(new Path(androidProject.getName()))); } else { androidProjectDescription.setLocation(null); } boolean legacy = sdkTarget.getVersion().getApiLevel() < 4; // Create project and open it androidProject.create(androidProjectDescription, new SubProgressMonitor(monitor, 10)); if (monitor.isCanceled()) throw new OperationCanceledException(); androidProject.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 10)); QualifiedName qualifiedName = new QualifiedName(GdtAndroidPlugin.PLUGIN_ID, androidProject.getName()); // Add the Java and android nature to the project AndroidNature.setupProjectNatures(androidProject, monitor); // Create folders in the project if they don't already exist addDefaultDirectories(androidProject, AdtConstants.WS_ROOT, ProjectCreationConstants.DEFAULT_DIRECTORIES, monitor); String[] sourceFolders = new String[] { SdkConstants.FD_SOURCES, ProjectCreationConstants.GEN_SRC_DIRECTORY }; addDefaultDirectories(androidProject, AdtConstants.WS_ROOT, sourceFolders, monitor); // Create the resource folders in the project if they don't already exist. if (legacy) { addDefaultDirectories(androidProject, ProjectCreationConstants.RES_DIRECTORY, ProjectCreationConstants.RES_DIRECTORIES, monitor); } else { addDefaultDirectories(androidProject, ProjectCreationConstants.RES_DIRECTORY, ProjectCreationConstants.RES_DENSITY_ENABLED_DIRECTORIES, monitor); } // Setup class path: mark folders as source folders IJavaProject javaProject = JavaCore.create(androidProject); String justProjectName = projectName.replace(" ", ""); justProjectName = justProjectName.substring(0, 1).toUpperCase() + justProjectName.substring(1); androidProjectParameters.put("CLASSNAME", justProjectName); //$NON-NLS-N$ // for now, always create new project if (true) { addManifest(androidProject, androidProjectParameters, androidProjectDictionary, monitor); // add the default app icon addIcon(androidProject, legacy, monitor); // Create the default package components Map<String, String> replacements = new HashMap<String, String>(); replacements.put("@PackageName@", //$NON-NLS-N$ (String) androidProjectParameters.get(ProjectCreationConstants.PARAM_PACKAGE)); replacements.put("@EmailId@", //$NON-NLS-N$ (String) androidProjectParameters.get(ProjectCreationConstants.PARAM_C2DM_EMAIL)); replacements.put("@ClassName@", justProjectName); //$NON-NLS-N$ replacements.put("@ClassNameLowercase@", justProjectName.toLowerCase()); //$NON-NLS-N$ addMainActivityClass(androidProject, sourceFolders[0], (String) androidProjectParameters.get(ProjectCreationConstants.PARAM_PACKAGE), "HelloActivity.java", replacements, monitor); //$NON-NLS-N$ addAuthHelperClass(androidProject, sourceFolders[0], (String) androidProjectParameters.get(ProjectCreationConstants.PARAM_PACKAGE), "GoogleAccountCredential.java", replacements, monitor); addIdsClass(androidProject, sourceFolders[0], (String) androidProjectParameters.get(ProjectCreationConstants.PARAM_PACKAGE), "Ids.java", replacements, monitor); // add the string definition file if needed if (androidProjectDictionary.size() > 0) { addStringDictionaryFile(androidProject, androidProjectDictionary, monitor); } // add the main menu resource file addMainMenuFile(androidProject, monitor); addLayoutFile(androidProject, "activity_ping.xml", monitor); // add the default proguard config File libFolder = new File( (String) androidProjectParameters.get(ProjectCreationConstants.PARAM_SDK_TOOLS_DIR), SdkConstants.FD_LIB); addLocalFile(androidProject, new File(libFolder, SdkConstants.FN_PROJECT_PROGUARD_FILE), monitor); addPrefsFile(androidProject, monitor); // Set output location javaProject.setOutputLocation( androidProject.getFolder(ProjectCreationConstants.BIN_DIRECTORY).getFullPath(), monitor); } setupSourceFolders(javaProject, sourceFolders, monitor); Sdk.getCurrent().initProject(androidProject, sdkTarget); // Fix the project to make sure all properties are as expected. // Necessary for existing projects and good for new ones to. ProjectHelper.fixProject(androidProject); return androidProject; }
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(); }// w ww . ja va 2 s . 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.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 www . ja v a 2 s .c o 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.liferay.ide.kaleo.core.WorkflowSupportManager.java
License:Open Source License
public IProject createSupportProject(IProgressMonitor monitor) throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(SUPPORT_PROJECT_NAME); if (project.exists()) { if (!project.isOpen()) { project.open(monitor);//from ww w. j a v a 2s . c o m } return project; } project.create(new SubProgressMonitor(monitor, 1)); project.open(new SubProgressMonitor(monitor, 1)); CoreUtil.makeFolders(project.getFolder("src")); CoreUtil.addNaturesToProject(project, new String[] { JavaCore.NATURE_ID }, new SubProgressMonitor(monitor, 1)); IJavaProject jProject = JavaCore.create(project); jProject.setOutputLocation(project.getFullPath().append("bin"), new SubProgressMonitor(monitor, 1)); computeClasspath(jProject, new SubProgressMonitor(monitor, 1)); return project; }
From source file:com.liferay.ide.project.core.facet.PluginFacetInstall.java
License:Open Source License
@Override public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor) throws CoreException { if (!(config instanceof IDataModel)) { return;/*from ww w .ja v a2 s . c o m*/ } else { this.model = (IDataModel) config; this.masterModel = (IDataModel) this.model.getProperty(FacetInstallDataModelProvider.MASTER_PROJECT_DM); this.project = project; this.monitor = monitor; } // IDE-195 // If the user has the plugins sdk in the workspace, trying to write to the P/foo-portlet/.settings/ will find // the file first in the the plugins-sdk that is in the workspace and will fail to find the file. try { final IFile f = this.project.getProject().getFile(PATH_IN_PROJECT); final File file = f.getLocation().toFile(); final IWorkspace ws = ResourcesPlugin.getWorkspace(); final IWorkspaceRoot wsroot = ws.getRoot(); final IPath path = new Path(file.getAbsolutePath()); final IFile[] wsFiles = wsroot.findFilesForLocationURI(path.toFile().toURI()); if (!CoreUtil.isNullOrEmpty(wsFiles)) { for (IFile wsFile : wsFiles) { wsFile.getParent().getParent().refreshLocal(IResource.DEPTH_INFINITE, null); } } } catch (Exception ex) { // best effort to make sure directories are current } if (shouldInstallPluginLibraryDelegate()) { installPluginLibraryDelegate(); } if (shouldSetupDefaultOutputLocation()) { setupDefaultOutputLocation(); IJavaProject javaProject = JavaCore.create(project); IPath outputLocation = project.getFolder(getDefaultOutputLocation()).getFullPath(); javaProject.setOutputLocation(outputLocation, monitor); } }
From source file:com.liferay.ide.project.core.facet.PluginFacetInstall.java
License:Open Source License
protected void setupDefaultOutputLocation() throws CoreException { IJavaProject jProject = JavaCore.create(this.project); IFolder folder = this.project.getFolder(getDefaultOutputLocation()); if (folder.getParent().exists()) { CoreUtil.prepareFolder(folder);/*from w w w . j a v a 2 s . co m*/ IPath oldOutputLocation = jProject.getOutputLocation(); IFolder oldOutputFolder = CoreUtil.getWorkspaceRoot().getFolder(oldOutputLocation); jProject.setOutputLocation(folder.getFullPath(), null); try { if (!folder.equals(oldOutputFolder) && oldOutputFolder.exists()) { IContainer outputParent = oldOutputFolder.getParent(); oldOutputFolder.delete(true, null); if (outputParent.members().length == 0 && outputParent.getName().equals("build")) //$NON-NLS-1$ { outputParent.delete(true, null); } } } catch (Exception e) { // best effort } } }