Beispiel #1
0
 /**
  * {@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);
    }
  }