Example #1
0
 /**
  * @param project
  * @param javaProject
  * @throws CoreException
  * @throws JavaModelException
  */
 private void createOutputFolder(String path, IProject project, IJavaProject javaProject)
     throws CoreException, JavaModelException {
   try {
     IFolder binFolder = project.getFolder(new Path(path));
     if (!binFolder.exists()) {
       binFolder.create(true, true, null);
       javaProject.setOutputLocation(binFolder.getFullPath(), null);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  public static IJavaProject createJavaProject(final String projectName, String[] projectNatures) {

    IProject project = null;
    IJavaProject javaProject = null;
    try {
      IWorkspace workspace = ResourcesPlugin.getWorkspace();
      project = workspace.getRoot().getProject(projectName);
      deleteProject(project);

      javaProject = JavaCore.create(project);
      IProjectDescription projectDescription =
          ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
      project.create(projectDescription, null);
      List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
      projectDescription.setNatureIds(projectNatures);

      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");

      projectDescription.setBuildSpec(new ICommand[] {java, manifest, schema});

      project.open(null);
      project.setDescription(projectDescription, null);

      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()]), null);

      makeJava5Compliant(javaProject);

      javaProject.setOutputLocation(new Path("/" + projectName + "/bin"), null);
      createManifest(projectName, project);
      //			project.build(IncrementalProjectBuilder.FULL_BUILD, null);
      refreshExternalArchives(javaProject);
      refresh(javaProject);
    } catch (final Exception exception) {
      throw new RuntimeException(exception);
    }
    return javaProject;
  }
 /**
  * Tests that changing the output folder settings for a project cause the class file containers to
  * be updated
  */
 public void testWPUpdateDefaultOutputFolderChanged() throws Exception {
   IJavaProject project = getTestingProject();
   assertNotNull("The testing project must exist", project);
   IContainer container = ProjectUtils.addFolderToProject(project.getProject(), "bin2");
   assertNotNull("the new output folder cannot be null", container);
   IApiComponent component = getWorkspaceBaseline().getApiComponent(project.getElementName());
   assertNotNull("the workspace component must exist", component);
   int before = component.getApiTypeContainers().length;
   project.setOutputLocation(container.getFullPath(), new NullProgressMonitor());
   waitForAutoBuild();
   assertTrue(
       "there must be the same number of containers after the change",
       before == component.getApiTypeContainers().length);
   assertTrue(
       "the new output location should be 'bin2'",
       "bin2".equalsIgnoreCase(project.getOutputLocation().toFile().getName()));
 }
 /**
  * creates a java project with the specified name and additional project natures
  *
  * @param projectName
  * @param additionalNatures
  * @return a new java project
  * @throws CoreException
  */
 public static IJavaProject createJavaProject(String projectName, String[] additionalNatures)
     throws CoreException {
   IProgressMonitor monitor = new NullProgressMonitor();
   IProject project = createProject(projectName, monitor);
   if (!project.hasNature(JavaCore.NATURE_ID)) {
     addNatureToProject(project, JavaCore.NATURE_ID, monitor);
   }
   if (additionalNatures != null) {
     for (int i = 0; i < additionalNatures.length; i++) {
       addNatureToProject(project, additionalNatures[i], monitor);
     }
   }
   IJavaProject jproject = JavaCore.create(project);
   jproject.setOutputLocation(getDefaultProjectOutputLocation(project), monitor);
   jproject.setRawClasspath(new IClasspathEntry[0], monitor);
   addContainerEntry(jproject, JavaRuntime.newDefaultJREContainerPath());
   return jproject;
 }
Example #5
0
 /** Creates specified Java project. */
 public static IJavaProject createJavaProject(String projectName, IProgressMonitor monitor)
     throws CoreException {
   IProject project = SpringCoreUtils.createProject(projectName, null, monitor);
   if (monitor.isCanceled()) {
     throw new OperationCanceledException();
   }
   if (!project.hasNature(JavaCore.NATURE_ID)) {
     SpringCoreUtils.addProjectNature(project, JavaCore.NATURE_ID, monitor);
   }
   IJavaProject jproject = JavaCore.create(project);
   // append JRE entry
   jproject.setRawClasspath(new IClasspathEntry[] {getJreVariableEntry()}, monitor);
   jproject.setOutputLocation(project.getFullPath(), monitor);
   if (monitor.isCanceled()) {
     throw new OperationCanceledException();
   }
   return jproject;
 }
  /** OT: new method: OT specific project creation. Creates a IJavaProject. */
  public static IJavaProject createOTJavaProject(String projectName, String binFolderName)
      throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    if (!project.exists()) {
      project.create(null);
    } else {
      project.refreshLocal(IResource.DEPTH_INFINITE, null);
    }

    if (!project.isOpen()) {
      project.open(null);
    }

    IPath outputLocation;
    if (binFolderName != null && binFolderName.length() > 0) {
      IFolder binFolder = project.getFolder(binFolderName);
      if (!binFolder.exists()) {
        CoreUtility.createFolder(binFolder, false, true, null);
      }
      outputLocation = binFolder.getFullPath();
    } else {
      outputLocation = project.getFullPath();
    }

    if (!project.hasNature(JavaCore.NATURE_ID) && !project.hasNature(JavaCore.OTJ_NATURE_ID)) {
      addNatureToProject(project, JavaCore.NATURE_ID, null);
      // add OT nature to project
      addNatureToProject(project, JavaCore.OTJ_NATURE_ID, null);
    }
    IProjectDescription description = project.getDescription();
    // add OT build spec to project
    description.setBuildSpec(OTDTPlugin.createProjectBuildCommands(description));
    project.setDescription(description, null);

    IJavaProject jproject = JavaCore.create(project);

    jproject.setOutputLocation(outputLocation, null);
    jproject.setRawClasspath(new IClasspathEntry[0], null);

    OTREContainer.initializeOTJProject(project);

    return jproject;
  }
  /**
   * Creates a IJavaProject.
   *
   * @param projectName The name of the project
   * @param binFolderName Name of the output folder
   * @return Returns the Java project handle
   * @throws CoreException Project creation failed
   */
  public static IJavaProject createJavaProject(String projectName, String binFolderName)
      throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    if (!project.exists()) {
      project.create(null);
    } else {
      project.refreshLocal(IResource.DEPTH_INFINITE, null);
    }

    if (!project.isOpen()) {
      project.open(null);
    }

    IPath outputLocation;
    if (binFolderName != null && binFolderName.length() > 0) {
      IFolder binFolder = project.getFolder(binFolderName);
      if (!binFolder.exists()) {
        CoreUtility.createFolder(binFolder, false, true, null);
      }
      outputLocation = binFolder.getFullPath();
    } else {
      outputLocation = project.getFullPath();
    }

    if (!project.hasNature(JavaCore.NATURE_ID)) {
      addNatureToProject(project, JavaCore.NATURE_ID, null);
    }

    IJavaProject jproject = JavaCore.create(project);

    jproject.setOutputLocation(outputLocation, null);
    jproject.setRawClasspath(new IClasspathEntry[0], null);

    return jproject;
  }
Example #8
0
  /**
   * 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);
    }
  }
  private void createOutputLocation(IJavaProject javaProject) throws JavaModelException {

    IPath targetPath = javaProject.getPath().append("target/classes");
    javaProject.setOutputLocation(targetPath, null);
  }
 private void createOutputFolder(IFolder binFolder) throws JavaModelException {
   IPath outputLocation = binFolder.getFullPath();
   javaProject.setOutputLocation(outputLocation, null);
 }