Esempio n. 1
0
 @AfterClass
 public static void tearDownProject() throws Exception {
   IResourcesSetupUtil.cleanWorkspace();
   final IWorkspace workspace = ResourcesPlugin.getWorkspace();
   final IWorkspaceDescription description = workspace.getDescription();
   description.setAutoBuilding(BuildAffectionTest.wasAutoBuilding);
   workspace.setDescription(description);
 }
Esempio n. 2
0
 /** Additional Method: Sets autobuilding state for the test workspace. */
 public static boolean setAutoBuilding(boolean state) throws CoreException {
   // disable auto build
   IWorkspace workspace = ResourcesPlugin.getWorkspace();
   IWorkspaceDescription desc = workspace.getDescription();
   boolean result = desc.isAutoBuilding();
   desc.setAutoBuilding(state);
   workspace.setDescription(desc);
   return result;
 }
Esempio n. 3
0
 /**
  * Set the autobuild to the value of the parameter and return the old one.
  *
  * @param state the value to be set for autobuilding.
  * @return the old value of the autobuild state
  */
 public static boolean enableAutoBuild(boolean state) throws CoreException {
   IWorkspace workspace = ResourcesPlugin.getWorkspace();
   IWorkspaceDescription desc = workspace.getDescription();
   boolean isAutoBuilding = desc.isAutoBuilding();
   if (isAutoBuilding != state) {
     desc.setAutoBuilding(state);
     workspace.setDescription(desc);
   }
   return isAutoBuilding;
 }
Esempio n. 4
0
 @BeforeClass
 public static void setUpProject() throws Exception {
   IResourcesSetupUtil.cleanWorkspace();
   final IWorkspace workspace = ResourcesPlugin.getWorkspace();
   final IWorkspaceDescription description = workspace.getDescription();
   boolean _isAutoBuilding = description.isAutoBuilding();
   BuildAffectionTest.wasAutoBuilding = _isAutoBuilding;
   description.setAutoBuilding(false);
   workspace.setDescription(description);
   WorkbenchTestHelper.createPluginProject(WorkbenchTestHelper.TESTPROJECT_NAME);
 }
Esempio n. 5
0
  @BeforeClass
  public static final void prepareWorkspace() throws Exception {
    // Override default location "target/projects-source"
    projectsSource = new File("testdata");
    projectsWorkdir = new File("target/projects-target");

    workspace = ResourcesPlugin.getWorkspace();
    final IWorkspaceDescription description = workspace.getDescription();
    description.setAutoBuilding(false);
    workspace.setDescription(description);

    cleanWorkspace();
  }
  /**
   * @see
   *     org.wtc.eclipse.core.reset.IResetDaemon#resetWorkspace(com.windowtester.runtime.IUIContext,
   *     org.wtc.eclipse.core.reset.IResetDaemon.ResetContext)
   */
  public void resetWorkspace(IUIContext ui, ResetContext context) {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceDescription description = workspace.getDescription();

    if (!description.isAutoBuilding()) {
      description.setAutoBuilding(true);

      try {
        workspace.setDescription(description);
      } catch (CoreException e) {
        ExceptionHandler.handle(e);
      }
    }
  }
  private IProject openProject(final IPath projectPath) throws CoreException {
    final ResourceSet set = ScaResourceFactoryUtil.createResourceSet();
    final IProgressMonitor progressMonitor = new NullProgressMonitor();
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IWorkspaceRoot root = workspace.getRoot();
    final IWorkspaceDescription description = workspace.getDescription();
    final File projectPathFile = projectPath.toFile();
    final IPath projectDescriptionPath = projectPath.append(".project");

    if (!projectPathFile.isDirectory()) {
      throw new IllegalStateException("Provided project path must be a directory");
    }

    if (!projectDescriptionPath.toFile().exists()) {
      throw new IllegalStateException("Provided project path must include .project file");
    }

    final IProjectDescription projDesc = workspace.loadProjectDescription(projectDescriptionPath);
    final IProject project = root.getProject(projDesc.getName());

    if (project.exists()) {
      // If the project exists, make sure that it is the same project the user requested
      // ...this should only happen if the user forced a workspace with -data
      // that already contained a project with the same name but different path
      // from the one provided on the command line
      if (!project.getLocation().equals(projectPath.makeAbsolute())) {
        throw new IllegalStateException(
            "Provided project path conflicts with existing project in workspace");
      }
    } else {
      // If the project doesn't exist in the workspace, create a linked project
      projDesc.setName(projDesc.getName());
      if (Platform.getLocation().isPrefixOf(projectPath)) {
        projDesc.setLocation(null);
      } else {
        projDesc.setLocation(projectPath);
      }

      final WorkspaceModifyOperation operation =
          new WorkspaceModifyOperation() {

            @Override
            protected void execute(final IProgressMonitor monitor)
                throws CoreException, InvocationTargetException, InterruptedException {

              final SubMonitor progressMonitor = SubMonitor.convert(monitor, 1);
              System.out.println(
                  "Loading project " + projDesc.getName() + " " + projDesc.getLocation());
              project.create(projDesc, progressMonitor.newChild(1));
            }
          };

      try {
        operation.run(new NullProgressMonitor());
      } catch (final InvocationTargetException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      } catch (final InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    }

    // Finally open the project
    Assert.isTrue(project.exists());

    final WorkspaceModifyOperation operation =
        new WorkspaceModifyOperation() {
          @Override
          protected void execute(final IProgressMonitor monitor)
              throws CoreException, InvocationTargetException, InterruptedException {
            project.open(monitor);
          }
        };

    try {
      operation.run(new NullProgressMonitor());
    } catch (final InvocationTargetException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (final InterruptedException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    return project;
  }
  public Object start(final String[] args) throws Exception {
    boolean usage = (args.length == 0);

    String[] preserveFiles = new String[0];
    String create_project = null;
    String generate_project = null;
    String lang = null;
    String codegenId = null;
    String templateId = null;
    String project_type = null;

    for (int i = 0; i < args.length; i++) {
      final String arg = args[i];
      if (arg.equals("-create")) {
        create_project = args[++i];
      } else if (arg.equals("-generate")) {
        generate_project = args[++i];
      } else if (arg.startsWith("-Dlang=")) {
        lang = arg.substring(7).toLowerCase();
      } else if (arg.startsWith("-Dcodegen=")) {
        codegenId = arg.substring(10);
      } else if (arg.startsWith("-Dtemplate=")) {
        templateId = arg.substring(11);
      } else if (arg.startsWith("-Dproject-type=")) {
        project_type = arg.substring(15);
      } else if (arg.startsWith("-Dpreserve=")) {
        if (arg.length() > 11) {
          preserveFiles = arg.substring(11).split(",");
        } else {
          preserveFiles = new String[] {"*"};
        }
      } else if (arg.equals("-Dusage")) {
        usage = true;
      }
    }

    // Check various error conditions
    if ((create_project != null) && (generate_project != null)) {
      System.err.println("You cannot combine -create with -generate");
      usage = true;
    }
    if ((create_project == null) && (generate_project == null)) {
      System.err.println("You must provide either -create or -generate");
      usage = true;
    }

    // Show usage and exit if necessary
    if (usage) {
      System.out.println(
          "Usage: eclipse -nosplash -application gov.redhawk.ide.codegen.tests.commandLineGenerator [OPTION]... -create PROJECT_PATH -Dlang=LANG");
      System.out.println(
          "  or:  eclipse -nosplash -application gov.redhawk.ide.codegen.tests.commandLineGenerator [OPTION]... -generate PROJECT_PATH");
      System.out.println("");
      System.out.println("Common Options:");
      System.out.println(
          "\t-Dlang=<lang> specifiy the programming language (C++, Java, or Python).  Required when creating a new project");
      System.out.println(
          "\t-Dproject-type=<id> The type of project to create (resource, device, loadabledevice, executabledevice).  Default: resource.");
      System.out.println("\t-Dcodegen=<id> Optional, the id of the code generator to use.");
      System.out.println("\t-Dtemplate=<id> Optional, the id of the template to use.");
      System.out.println("");
      System.out.println("Less Common Options:");
      System.out.println(
          "\t-Dpreserve=<file1,file2> Optional, the files to keep from being overwritten on generation.");
      System.out.println(
          "\t\t\tIf no files are specified, all files are not overwritten, otherwise everything");
      System.out.println(
          "\t\t\texcept for the comma delimited files will be overwritten on generation.");
      System.out.println("examples:");
      System.out.println("\trhgen -generate /path/to/project");
      System.out.println("\trhgen -create /path/to/project -Dlang=Python");

      // Wait for CDT to finish starting indexers(they get started even though indexing is disabled)
      CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, new NullProgressMonitor());

      return IApplication.EXIT_OK;
    }

    // This was originally put in to try to create temporary workspaces; however
    // that didn't work as intended because when the ResourcesPlugin starts it
    // will create a workspace in the default area before any of this code is called
    // so you still get a plethora of workspace folders...
    //
    // The code is kept here for two reasons:
    //  1. So we can remember how to use the equinox relaunch capability
    //  2. So that if we do need to overrideArgs...the code is already in-place
    final HashMap<String, String> overrideArgs = new HashMap<String, String>();
    // If we have modified any of the command line arguments we need to do a re-launch
    if (!overrideArgs.isEmpty()) {
      final String command_line = buildCommandLine(overrideArgs);
      if (command_line == null) {
        System.out.println("Failed to build command_line");
        return IApplication.EXIT_OK;
      }
      System.setProperty("eclipse.exitcode", Integer.toString(24));
      System.setProperty(IApplicationContext.EXIT_DATA_PROPERTY, command_line);
      return IApplication.EXIT_RELAUNCH;
    }

    final Location workspaceLocation = Platform.getInstanceLocation();
    if (workspaceLocation == null) {
      System.err.println("Error: no workspace setup");
      return IApplication.EXIT_OK;
    }
    System.out.println("CommandLine Generator starting...");
    //		System.out.println("  Workspace: " + workspaceLocation.getURL());

    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IWorkspaceRoot root = workspace.getRoot();
    final IWorkspaceDescription description = workspace.getDescription();

    // Turn off auto building of the workspace
    description.setAutoBuilding(false);

    // Turn off CDT indexer
    disableGlobalCDTIndexer();

    // Attempt to see if PyDev is configured, required for C++ and Python generation
    if (!AutoConfigPydevInterpreterUtil.isPydevConfigured(new NullProgressMonitor(), "")) {
      // Configure PyDev with defaults
      System.out.println("Configuring PyDev");
      AutoConfigPydevInterpreterUtil.configurePydev(new NullProgressMonitor(), false, "");
      System.out.println("Configured PyDev");
    }

    // If we were requested to generate code
    if (create_project != null) {
      create_project(
          create_project, lang, codegenId, templateId, project_type, new NullProgressMonitor());
    } else if (generate_project != null) {
      generate_code(
          generate_project, lang, codegenId, templateId, preserveFiles, new NullProgressMonitor());
    }

    System.out.println("Goodbye");

    return IApplication.EXIT_OK;
  }
Esempio n. 9
0
 @AfterClass
 public static final void end() throws Exception {
   final IWorkspaceDescription description = workspace.getDescription();
   description.setAutoBuilding(true);
   workspace.setDescription(description);
 }