public static Dictionary[] getPlatformProperties(String[] profiles, MinimalState state) { if (profiles == null || profiles.length == 0) return new Dictionary[] {getTargetEnvironment(state)}; // add java profiles for those EE's that have a .profile file in the current system bundle ArrayList result = new ArrayList(profiles.length); for (int i = 0; i < profiles.length; i++) { IExecutionEnvironment environment = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(profiles[i]); if (environment != null) { Properties profileProps = environment.getProfileProperties(); if (profileProps != null) { Dictionary props = TargetPlatformHelper.getTargetEnvironment(state); String systemPackages = profileProps.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES); if (systemPackages != null) props.put(Constants.FRAMEWORK_SYSTEMPACKAGES, systemPackages); String ee = profileProps.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT); if (ee != null) props.put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, ee); result.add(props); } } } if (result.size() > 0) return (Dictionary[]) result.toArray(new Dictionary[result.size()]); return new Dictionary[] {TargetPlatformHelper.getTargetEnvironment(state)}; }
/** * Convert the empty project to an Acceleo project. * * @param project The newly created project. * @param selectedJVM The name of the selected JVM (J2SE-1.5 or JavaSE-1.6 recommended). * @param allModules The description of the module that need to be created. * @param shouldGenerateModules Indicates if we should generate the modules in the project or not. * The wizard container to display the progress monitor * @param monitor The monitor. */ public static void convert( IProject project, String selectedJVM, List<AcceleoModule> allModules, boolean shouldGenerateModules, IProgressMonitor monitor) { String generatorName = computeGeneratorName(project.getName()); AcceleoProject acceleoProject = AcceleowizardmodelFactory.eINSTANCE.createAcceleoProject(); acceleoProject.setName(project.getName()); acceleoProject.setGeneratorName(generatorName); // Default JRE value acceleoProject.setJre(selectedJVM); if (acceleoProject.getJre() == null && acceleoProject.getJre().length() == 0) { acceleoProject.setJre("J2SE-1.5"); // $NON-NLS-1$ } if (shouldGenerateModules) { for (AcceleoModule acceleoModule : allModules) { String parentFolder = acceleoModule.getParentFolder(); IProject moduleProject = ResourcesPlugin.getWorkspace().getRoot().getProject(acceleoModule.getProjectName()); if (moduleProject.exists() && moduleProject.isAccessible() && acceleoModule.getModuleElement() != null && acceleoModule.getModuleElement().isIsMain()) { IPath parentFolderPath = new Path(parentFolder); IFolder folder = moduleProject.getFolder(parentFolderPath.removeFirstSegments(1)); acceleoProject .getExportedPackages() .add( folder .getProjectRelativePath() .removeFirstSegments(1) .toString() .replaceAll( "/", //$NON-NLS-1$ "\\.")); //$NON-NLS-1$ } // Calculate project dependencies List<String> metamodelURIs = acceleoModule.getMetamodelURIs(); for (String metamodelURI : metamodelURIs) { // Find the project containing this metamodel and add a dependency to it. EPackage ePackage = AcceleoPackageRegistry.INSTANCE.getEPackage(metamodelURI); if (ePackage != null && !(ePackage instanceof EcorePackage)) { Bundle bundle = AcceleoWorkspaceUtil.getBundle(ePackage.getClass()); acceleoProject.getPluginDependencies().add(bundle.getSymbolicName()); } } } } try { IProjectDescription description = project.getDescription(); description.setNatureIds( new String[] { JavaCore.NATURE_ID, IBundleProjectDescription.PLUGIN_NATURE, IAcceleoConstants.ACCELEO_NATURE_ID, }); project.setDescription(description, monitor); IJavaProject iJavaProject = JavaCore.create(project); // Compute the JRE List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); IExecutionEnvironmentsManager executionEnvironmentsManager = JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment[] executionEnvironments = executionEnvironmentsManager.getExecutionEnvironments(); for (IExecutionEnvironment iExecutionEnvironment : executionEnvironments) { if (acceleoProject.getJre().equals(iExecutionEnvironment.getId())) { entries.add( JavaCore.newContainerEntry(JavaRuntime.newJREContainerPath(iExecutionEnvironment))); break; } } // PDE Entry (will not be generated anymore) entries.add( JavaCore.newContainerEntry( new Path("org.eclipse.pde.core.requiredPlugins"))); // $NON-NLS-1$ // Sets the input / output folders IFolder target = project.getFolder("src"); // $NON-NLS-1$ if (!target.exists()) { target.create(true, true, monitor); } IFolder classes = project.getFolder("bin"); // $NON-NLS-1$ if (!classes.exists()) { classes.create(true, true, monitor); } iJavaProject.setOutputLocation(classes.getFullPath(), monitor); IPackageFragmentRoot packageRoot = iJavaProject.getPackageFragmentRoot(target); entries.add( JavaCore.newSourceEntry( packageRoot.getPath(), new Path[] {}, new Path[] {}, classes.getFullPath())); iJavaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); iJavaProject.open(monitor); AcceleoProjectUtils.generateFiles( acceleoProject, allModules, project, shouldGenerateModules, monitor); // Default settings AcceleoBuilderSettings settings = new AcceleoBuilderSettings(project); settings.setCompilationKind(AcceleoBuilderSettings.COMPILATION_PLATFORM_RESOURCE); settings.setResourceKind(AcceleoBuilderSettings.BUILD_XMI_RESOURCE); settings.save(); } catch (CoreException e) { AcceleoUIActivator.log(e, true); } }