/** * {@inheritDoc} * * @see * org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator#getPropertiesLoaderService(org.eclipse.acceleo.engine.service.AcceleoService) * @generated NOT */ @Override public AbstractAcceleoPropertiesLoaderService getPropertiesLoaderService( AcceleoService acceleoService) { if (EMFPlugin.IS_ECLIPSE_RUNNING) { Bundle bundle = AcceleoWorkspaceUtil.getBundle(getClass()); return new ObeoNetworkBundlePropertiesLoaderService(acceleoService, bundle); } return new ObeoNetworkPropertiesLoaderService(acceleoService); }
/** * 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); } }
/** * This will be called if the parent {@link URIConverter} didn't know how to convert the given * URI. * * @param uri The uri we are to normalize. * @return The normalized form of <code>uri</code>. */ private URI dynamicNormalize(URI uri) { URI normalized = getURIMap().get(uri); if (normalized == null && EMFPlugin.IS_ECLIPSE_RUNNING) { BundleURLConverter conv = new BundleURLConverter(uri.toString()); if (conv.resolveBundle() != null) { normalized = URI.createURI(conv.resolveAsPlatformPlugin()); } } if (normalized == null && (!IAcceleoConstants.EMTL_FILE_EXTENSION.equals(uri.fileExtension()) || !"file".equals(uri.scheme()))) { // $NON-NLS-1$ normalized = super.normalize(uri); } if (normalized != null) { getURIMap().put(uri, normalized); return normalized; } String moduleName = uri.lastSegment(); moduleName = moduleName.substring(0, moduleName.lastIndexOf('.')); Set<URI> candidateURIs = new CompactLinkedHashSet<URI>(); // Search matching module in the current generation context Set<Module> candidateModules = searchCurrentModuleForCandidateMatches(moduleName); for (Module candidateModule : candidateModules) { if (candidateModule.eResource() != null) { candidateURIs.add(candidateModule.eResource().getURI()); } } // If there were no matching module, search in their ResourceSet(s) if (candidateURIs.size() == 0) { candidateURIs.addAll(searchResourceSetForMatches(moduleName)); } if (candidateURIs.size() == 1) { normalized = candidateURIs.iterator().next(); } else if (candidateURIs.size() > 0) { normalized = findBestMatchFor(uri, candidateURIs); } // There is a chance that our match should itself be normalized if ((normalized == null || "file".equals(normalized.scheme())) // $NON-NLS-1$ && EMFPlugin.IS_ECLIPSE_RUNNING) { BundleURLConverter conv = new BundleURLConverter(uri.toString()); if (conv.resolveBundle() != null) { normalized = URI.createURI(conv.resolveAsPlatformPlugin()); } else { String uriToString = uri.toString(); if (uriToString.indexOf('#') > 0) { uriToString = uriToString.substring(0, uriToString.indexOf('#')); } String resolvedPath = AcceleoWorkspaceUtil.resolveInBundles(uriToString); if (resolvedPath != null) { normalized = URI.createURI(resolvedPath); } } } if (normalized == null) { normalized = super.normalize(uri); } if (!uri.equals(normalized)) { getURIMap().put(uri, normalized); } return normalized; }