/**
  * Tests the {@link
  * BuilderCoreUtils#configureTriggers(org.eclipse.debug.core.ILaunchConfiguration,
  * org.eclipse.core.resources.ICommand)} method <br>
  * <br>
  * Tests that the triggers are configured for a full + incremental build with the targets 'def'
  * and 'inc' specified for after clean targets and manual targets respectively
  *
  * @throws Exception
  */
 public void testConfigureTriggers9() throws Exception {
   Map<String, String> args = new HashMap<>();
   args.put(IAntLaunchConstants.ATTR_ANT_AFTER_CLEAN_TARGETS, "def"); // $NON-NLS-1$
   args.put(IAntLaunchConstants.ATTR_ANT_MANUAL_TARGETS, "inc"); // $NON-NLS-1$
   args.put(
       IExternalToolConstants.ATTR_LOCATION, getBuildFile(EXT_BUILD_FILE_NAME).getAbsolutePath());
   args.put(
       IExternalToolConstants.ATTR_RUN_BUILD_KINDS,
       IExternalToolConstants.BUILD_TYPE_CLEAN
           + ","
           + IExternalToolConstants.BUILD_TYPE_INCREMENTAL); // $NON-NLS-1$
   ILaunchConfiguration config =
       createExternalToolBuilder(getProject(), "testConfigureTriggers9", args); // $NON-NLS-1$
   assertNotNull("the test builder must not be null", config); // $NON-NLS-1$
   ICommand command = createBuildCommand(config);
   assertNotNull("the test build command must not be null", command); // $NON-NLS-1$
   assertTrue(
       "the command must be building CLEAN builds",
       command.isBuilding(IncrementalProjectBuilder.FULL_BUILD)); // $NON-NLS-1$
   assertTrue(
       "the command must be building CLEAN builds",
       command.isBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD)); // $NON-NLS-1$
   String[] names = AntLaunchingUtil.getTargetNames(config);
   assertNull(
       "should be no target names resolved from the config - only available during a build",
       names); //$NON-NLS-1$
 }
Esempio n. 2
0
  public static void addBuilderToProject(IProject project) {
    if (!project.isOpen()) return;

    IProjectDescription description;
    try {
      description = project.getDescription();
    } catch (CoreException e) {
      Log.log(e);
      return;
    }

    ICommand[] cmds = description.getBuildSpec();
    for (int j = 0; j < cmds.length; j++) if (cmds[j].getBuilderName().equals(BUILDER_ID)) return;

    // Associate builder with project.
    ICommand newCmd = description.newCommand();
    newCmd.setBuilderName(BUILDER_ID);
    List<ICommand> newCmds = new ArrayList<ICommand>();
    newCmds.addAll(Arrays.asList(cmds));
    newCmds.add(newCmd);
    description.setBuildSpec((ICommand[]) newCmds.toArray(new ICommand[newCmds.size()]));
    try {
      project.setDescription(description, null);
    } catch (CoreException e) {
      Log.log(e);
    }
  }
Esempio n. 3
0
  public static void addBuilderToBuildSpec(IProject project, String launchId) throws CoreException {

    // Get project description and then the associated build commands
    IProjectDescription desc = project.getDescription();
    ICommand[] commands = desc.getBuildSpec();

    ICommand custCommand = desc.newCommand();
    custCommand.setBuilderName(CUST_BUILDER_ID);
    // Create map with arguments specific to builder in project here
    // custCommand.setArguments(Map args);
    final Map buildsetting;
    buildsetting = new HashMap();
    buildsetting.put(
        "LaunchConfigHandle",
        "<project>/"
            + EXTERNALTOOLBUILDER_FOLDER
            + "/"
            + launchId); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$

    custCommand.setArguments(buildsetting);

    ICommand[] newCommands = new ICommand[commands.length + 1];

    // Add it before other builders.
    System.arraycopy(commands, 0, newCommands, 1, commands.length);

    newCommands[0] = custCommand;
    desc.setBuildSpec(newCommands);
    project.setDescription(desc, null);
  }
Esempio n. 4
0
 @Test
 public void testDeconfigure() throws CoreException {
   ICommand commandMock = mock(ICommand.class);
   when(commandMock.getBuilderName()).thenReturn(JUnitFluxBuilder.BUILDER_ID);
   IProjectDescription projectDescription = initProject(new ICommand[] {commandMock});
   nature.deconfigure();
   verify(projectDescription).setBuildSpec(new ICommand[] {});
 }
 private static IProjectDescription createProjectDescription(IProject project, URI location) {
   IWorkspace workspace = ResourcesPlugin.getWorkspace();
   IProjectDescription description = workspace.newProjectDescription(project.getName());
   description.setLocationURI(location);
   description.setNatureIds(new String[] {DartCore.DART_PROJECT_NATURE});
   ICommand command = description.newCommand();
   command.setBuilderName(DartCore.DART_BUILDER_ID);
   description.setBuildSpec(new ICommand[] {command});
   return description;
 }
 public void configure() throws CoreException {
   IProjectDescription desc = project.getDescription();
   List<ICommand> commands = new ArrayList<ICommand>(Arrays.asList(desc.getBuildSpec()));
   if (!commands.contains(LimyQalabBuilder.BUILDER_ID)) {
     ICommand command = desc.newCommand();
     command.setBuilderName(LimyQalabBuilder.BUILDER_ID);
     commands.add(command);
     desc.setBuildSpec(commands.toArray(new ICommand[commands.size()]));
     project.setDescription(desc, null);
   }
 }
Esempio n. 7
0
 public static void addBuilders(IProject project, String[] builderIds, IProgressMonitor monitor)
     throws CoreException {
   IProjectDescription description = project.getDescription();
   List<ICommand> buildSpec = new ArrayList<ICommand>(Arrays.asList(description.getBuildSpec()));
   for (String id : builderIds) {
     ICommand command = description.newCommand();
     command.setBuilderName(id);
     buildSpec.add(command);
   }
   description.setBuildSpec(buildSpec.toArray(new ICommand[buildSpec.size()]));
   project.setDescription(description, monitor);
 }
Esempio n. 8
0
  @Override
  public void configure() throws CoreException {
    IProjectDescription desc = getDescription();
    List<ICommand> commands = Arrays.asList(desc.getBuildSpec());

    for (ICommand i : commands) if (BigraphBuilder.BUILDER_ID.equals(i.getBuilderName())) return;

    ICommand newCommand = desc.newCommand();
    newCommand.setBuilderName(BigraphBuilder.BUILDER_ID);
    (commands = new ArrayList<ICommand>(commands)).add(newCommand);
    desc.setBuildSpec(commands.toArray(EMPTY));
    project.setDescription(desc, null);
  }
  public void deconfigure() throws CoreException {
    IProjectDescription desc = project.getDescription();
    List<ICommand> commands = new ArrayList<ICommand>(Arrays.asList(desc.getBuildSpec()));
    for (ListIterator<ICommand> it = commands.listIterator(); it.hasNext(); ) {
      ICommand command = it.next();
      if (command.getBuilderName().equals(LimyQalabBuilder.BUILDER_ID)) {
        it.remove();
      }
    }
    desc.setBuildSpec(commands.toArray(new ICommand[commands.size()]));
    project.setDescription(desc, null);

    project.deleteMarkers(LimyQalabMarker.DEFAULT_ID, true, IResource.DEPTH_INFINITE);
  }
Esempio n. 10
0
  @Override
  protected void createProject(IProgressMonitor monitor) throws CoreException {

    if (targetProject.exists()) targetProject.delete(true, monitor);

    // create project with FeatureIDE builder, just in case
    IProjectDescription projDesc =
        targetProject.getWorkspace().newProjectDescription(targetProject.getName());
    ICommand buildcomm = projDesc.newCommand();
    buildcomm.setBuilderName("fos.aheadjakbuilder");
    ICommand[] buildspecs = {buildcomm};
    projDesc.setBuildSpec(buildspecs);

    targetProject.create(projDesc, monitor);

    targetProject.open(monitor);
  }
  private void reorderBuilderEntries(IProject project) throws CoreException {
    IProjectDescription desc = project.getDescription();
    ICommand[] commands = desc.getBuildSpec();

    // Lookup the IncQuery-related command indixii
    int xtextIndex = -1;
    ICommand xtextCommand = null;
    int iqIndex = -1;
    ICommand iqCommand = null;
    int commandListSize = commands.length;
    for (int i = 0; i < commandListSize; i++) {
      String id = commands[i].getBuilderName();
      if (ViatraQueryNature.BUILDER_ID.equals(id)) {
        iqIndex = i;
        iqCommand = commands[i];
      } else if (XtextProjectHelper.BUILDER_ID.equals(id)) {
        xtextIndex = i;
        xtextCommand = commands[i];
      }
    }

    // Preparing reordered array
    if (iqIndex < 0) {
      commandListSize++;
      iqCommand = desc.newCommand();
      iqCommand.setBuilderName(ViatraQueryNature.BUILDER_ID);
    }
    if (xtextIndex < 0) {
      commandListSize++;
      xtextCommand = desc.newCommand();
      xtextCommand.setBuilderName(XtextProjectHelper.BUILDER_ID);
    }
    ICommand[] newCommands = new ICommand[commandListSize];
    newCommands[0] = iqCommand;
    newCommands[1] = xtextCommand;

    int commandIndex = 2;
    for (int i = 0; i < commands.length; i++) {
      if (i != xtextIndex && i != iqIndex) {
        newCommands[commandIndex] = commands[i];
        commandIndex++;
      }
    }
    desc.setBuildSpec(newCommands);
    project.setDescription(desc, null);
  }
Esempio n. 12
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.core.resources.IProjectNature#configure()
   */
  public void configure() throws CoreException {
    IProjectDescription desc = project.getDescription();
    ICommand[] commands = desc.getBuildSpec();

    for (int i = 0; i < commands.length; ++i) {
      if (commands[i].getBuilderName().equals(SampleBuilder.BUILDER_ID)) {
        return;
      }
    }

    ICommand[] newCommands = new ICommand[commands.length + 1];
    System.arraycopy(commands, 0, newCommands, 0, commands.length);
    ICommand command = desc.newCommand();
    command.setBuilderName(SampleBuilder.BUILDER_ID);
    newCommands[newCommands.length - 1] = command;
    desc.setBuildSpec(newCommands);
    project.setDescription(desc, null);
  }
  public static void configureWidgetBuilder(IProject project) throws CoreException {
    IProjectDescription desc = project.getDescription();
    ICommand[] commands = desc.getBuildSpec();
    for (int i = 0; i < commands.length; ++i) {
      System.out.println("builder name -->" + commands[i].getBuilderName());
      if (commands[i].getBuilderName().equals("org.jil.ide.widgetBuilder")) {
        return;
      }
    }

    ICommand[] newCommands = new ICommand[commands.length + 1];
    System.arraycopy(commands, 0, newCommands, 0, commands.length);
    ICommand command = desc.newCommand();
    command.setBuilderName("org.jil.ide.widgetBuilder");
    newCommands[(newCommands.length - 1)] = command;
    desc.setBuildSpec(newCommands);
    project.setDescription(desc, null);
  }
 /**
  * Tests the {@link
  * BuilderCoreUtils#configureTriggers(org.eclipse.debug.core.ILaunchConfiguration,
  * org.eclipse.core.resources.ICommand)} method <br>
  * <br>
  * Tests that the triggers are configured for a clean build
  *
  * @throws Exception
  */
 public void testConfigureTriggers7() throws Exception {
   Map<String, String> args = new HashMap<>();
   args.put(IAntLaunchConstants.ATTR_ANT_CLEAN_TARGETS, null);
   args.put(
       IExternalToolConstants.ATTR_LOCATION, getBuildFile(EXT_BUILD_FILE_NAME).getAbsolutePath());
   args.put(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, IExternalToolConstants.BUILD_TYPE_CLEAN);
   ILaunchConfiguration config =
       createExternalToolBuilder(getProject(), "testConfigureTriggers7", args); // $NON-NLS-1$
   assertNotNull("the test builder must not be null", config); // $NON-NLS-1$
   ICommand command = createBuildCommand(config);
   assertNotNull("the test build command must not be null", command); // $NON-NLS-1$
   assertTrue(
       "the command must be building CLEAN builds",
       command.isBuilding(IncrementalProjectBuilder.CLEAN_BUILD)); // $NON-NLS-1$
   String[] names = AntLaunchingUtil.getTargetNames(config);
   assertNull(
       "should be no target names resolved from the config - null given for target names",
       names); //$NON-NLS-1$
 }
  protected boolean createProject(
      final IProgressMonitor monitor,
      final IPath projectLocation,
      final String projectName,
      final Collection<IPath> includeDirs,
      final Collection<IPath> sourceDirs,
      final IPath outputDir)
      throws InvocationTargetException {
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProject project = workspace.getRoot().getProject(projectName);
    final IProjectDescription description = workspace.newProjectDescription(projectName);
    description.setLocation(projectLocation);

    final ICommand[] old = description.getBuildSpec(), specs = new ICommand[old.length + 1];
    System.arraycopy(old, 0, specs, 0, old.length);
    final ICommand command = description.newCommand();
    command.setBuilderName(ErlangPlugin.BUILDER_ID);
    specs[old.length] = command;
    description.setBuildSpec(specs);
    description.setNatureIds(new String[] {ErlangPlugin.NATURE_ID});

    try {
      monitor.beginTask(WizardMessages.WizardProjectsImportPage_CreateProjectsTask, 1000);
      project.create(description, monitor);
      // final int subTicks = 600 / fileSystemObjects.size();
      // createLinks(theProjectPath, fileSystemObjects, monitor, project,
      // subTicks);
      // project.create(description, IResource.REPLACE,
      // new SubProgressMonitor(monitor, 30));
      project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 300));
      final OldErlangProjectProperties erlangProjectProperties =
          new OldErlangProjectProperties(project);
      erlangProjectProperties.setIncludeDirs(includeDirs);
      erlangProjectProperties.setSourceDirs(sourceDirs);
      erlangProjectProperties.setOutputDir(outputDir);
    } catch (final CoreException e) {
      throw new InvocationTargetException(e);
    } finally {
      monitor.done();
    }
    return true;
  }
  /** Test for Bug #5102. Never reproduced but interesting little test, worth keeping around */
  public void testPR() throws Exception {
    // create a project with a RefreshLocalJavaFileBuilder and a SortBuilder on the classpath
    IProject project = getWorkspace().getRoot().getProject("P1");
    project.create(null);
    project.open(null);
    IProjectDescription desc = project.getDescription();
    ICommand one = desc.newCommand();
    one.setBuilderName(RefreshLocalJavaFileBuilder.BUILDER_NAME);
    ICommand two = desc.newCommand();
    two.setBuilderName(SortBuilder.BUILDER_NAME);
    desc.setBuildSpec(new ICommand[] {one, two});
    project.setDescription(desc, null);

    // do a full build
    project.build(IncrementalProjectBuilder.FULL_BUILD, null);

    // do an incremental build by creating a file
    IFile file = project.getFile("Foo");
    file.create(getRandomContents(), true, getMonitor());
  }
 @Override
 public void configure() throws CoreException {
   IProjectDescription desc = getProject().getDescription();
   ICommand[] commands = desc.getBuildSpec();
   boolean found = false;
   for (ICommand command : commands) {
     if (RadlBuilder.BUILDER_ID.equals(command.getBuilderName())) {
       found = true;
       break;
     }
   }
   if (!found) {
     ICommand[] newCommands = new ICommand[commands.length + 1];
     System.arraycopy(commands, 0, newCommands, 0, commands.length);
     ICommand command = desc.newCommand();
     command.setBuilderName(RadlBuilder.BUILDER_ID);
     newCommands[newCommands.length - 1] = command;
     desc.setBuildSpec(newCommands);
   }
   desc.setNatureIds(ensureNature(desc.getNatureIds()));
   getProject().setDescription(desc, null);
 }
  @Override
  public void configure() throws CoreException {
    IProjectDescription desc = project_.getDescription();
    ICommand[] commands = desc.getBuildSpec();

    boolean wesnothConfigured = false;
    boolean xtextConfigured = false;
    int configured = 0;
    for (int i = 0; i < commands.length; ++i) {
      if (commands[i].getBuilderName().equals(WesnothProjectBuilder.ID_BUIILDER)) {
        wesnothConfigured = true;
        configured++;
      }
      if (commands[i].getBuilderName().equals(XtextProjectHelper.BUILDER_ID)) {
        xtextConfigured = true;
        configured++;
      }
    }
    if (configured == 2) {
      return;
    }

    ICommand[] newCommands = new ICommand[commands.length + (2 - configured)];
    System.arraycopy(commands, 0, newCommands, 0, commands.length);
    if (wesnothConfigured == false) {
      ICommand command = desc.newCommand();
      command.setBuilderName(WesnothProjectBuilder.ID_BUIILDER);
      newCommands[newCommands.length - 1] = command;
    }
    if (xtextConfigured == false) {
      ICommand command = desc.newCommand();
      command.setBuilderName(XtextProjectHelper.BUILDER_ID);
      newCommands[newCommands.length - (2 - configured)] = command;
    }
    desc.setBuildSpec(newCommands);
    project_.setDescription(desc, null);
  }
  @Override
  public boolean performFinish() {
    boolean finish = super.performFinish();
    try {
      IProject project = this.getNewProject();
      IProjectDescription description = project.getDescription();
      String[] natures = description.getNatureIds();
      String[] newNatures = new String[natures.length + 1];

      // add new natures
      System.arraycopy(natures, 0, newNatures, 1, natures.length);
      newNatures[0] = JavaCore.NATURE_ID;
      description.setNatureIds(newNatures);
      project.setDescription(description, null);

      // retrieves the up-to-date description
      description = project.getDescription();

      // filters out the Java builder
      ICommand[] commands = description.getBuildSpec();
      List<ICommand> buildSpec = new ArrayList<ICommand>(commands.length);
      for (ICommand command : commands) {
        if (!JavaCore.BUILDER_ID.equals(command.getBuilderName())) {
          buildSpec.add(command);
        }
      }

      // updates the description and replaces the existing description
      description.setBuildSpec(buildSpec.toArray(new ICommand[0]));
      project.setDescription(description, null);
    } catch (CoreException e) {
      e.printStackTrace();
    }

    return finish;
  }
Esempio n. 20
0
  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;
  }
Esempio n. 21
0
  /**
   * Utility routine to add PythonNature to the project
   *
   * @param projectPythonpath: @see {@link IPythonPathNature#setProjectSourcePath(String)}
   */
  public static synchronized IPythonNature addNature(
      IProject project,
      IProgressMonitor monitor,
      String version,
      String projectPythonpath,
      String externalProjectPythonpath,
      String projectInterpreter,
      Map<String, String> variableSubstitution)
      throws CoreException {

    if (project == null || !project.isOpen()) {
      return null;
    }
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    if (projectInterpreter == null) {
      projectInterpreter = IPythonNature.DEFAULT_INTERPRETER;
    }

    IProjectDescription desc = project.getDescription();

    // only add the nature if it still hasn't been added.
    if (project.hasNature(PYTHON_NATURE_ID) == false) {

      String[] natures = desc.getNatureIds();
      String[] newNatures = new String[natures.length + 1];
      System.arraycopy(natures, 0, newNatures, 0, natures.length);
      newNatures[natures.length] = PYTHON_NATURE_ID;
      desc.setNatureIds(newNatures);
      project.setDescription(desc, monitor);
    } else {
      // Return if it already has the nature configured.
      IProjectNature n = getPythonNature(project);
      if (n instanceof IPythonNature) {
        return (IPythonNature) n;
      }
    }

    // add the builder. It is used for pylint, pychecker, code completion, etc.
    ICommand[] commands = desc.getBuildSpec();

    // now, add the builder if it still hasn't been added.
    if (hasBuilder(commands) == false && PyDevBuilderPrefPage.usePydevBuilders()) {

      ICommand command = desc.newCommand();
      command.setBuilderName(BUILDER_ID);
      ICommand[] newCommands = new ICommand[commands.length + 1];

      System.arraycopy(commands, 0, newCommands, 1, commands.length);
      newCommands[0] = command;
      desc.setBuildSpec(newCommands);
      project.setDescription(desc, monitor);
    }

    IProjectNature n = getPythonNature(project);
    if (n instanceof PythonNature) {
      PythonNature nature = (PythonNature) n;
      // call initialize always - let it do the control.
      nature.init(
          version,
          projectPythonpath,
          externalProjectPythonpath,
          monitor,
          projectInterpreter,
          variableSubstitution);
      return nature;
    }
    return null;
  }