/**
  * Utility method for refreshing the current view on all relevant input and output folders. This
  * makes sure, that methods determining and moving files get the current workspace contents.
  *
  * @param monitor progress monitor
  * @throws CoreException if an error occurs
  */
 private void refreshView(IProgressMonitor monitor) throws CoreException {
   sourceDir.refreshLocal(IProject.DEPTH_INFINITE, monitor);
   if (outputDir != null
       && !sourceDir.getProjectRelativePath().isPrefixOf(outputDir.getProjectRelativePath())) {
     outputDir.refreshLocal(IProject.DEPTH_ONE, monitor);
   }
   if (tempDir != null
       && !sourceDir.getProjectRelativePath().isPrefixOf(tempDir.getProjectRelativePath())) {
     tempDir.refreshLocal(IProject.DEPTH_INFINITE, monitor);
   }
   if (!sourceDir.getLocation().equals(project.getLocation())) {
     project.refreshLocal(IProject.DEPTH_ONE, monitor);
   }
 }
Beispiel #2
0
 protected void refreshOutputFolders(
     IBuildContext ctx,
     Map<String, OutputConfiguration> outputConfigurations,
     IProgressMonitor monitor)
     throws CoreException {
   SubMonitor subMonitor = SubMonitor.convert(monitor, outputConfigurations.size());
   for (OutputConfiguration config : outputConfigurations.values()) {
     SubMonitor child = subMonitor.newChild(1);
     final IProject project = ctx.getBuiltProject();
     for (IContainer container : getOutputs(project, config)) {
       if (monitor.isCanceled()) {
         throw new OperationCanceledException();
       }
       container.refreshLocal(IResource.DEPTH_INFINITE, child);
     }
   }
 }
  private void init(IFile file) throws AmlUIException {
    IProject project = file.getProject();
    File propertiesFile =
        org.eclipse.gmt.weaver.plugin.util.WeaverUtil.getPropertyFilePath(file).toFile();

    // Config file

    try {
      InputStream in = AmlUIResourceManager.getDefault().getAmlFile(project).getContents();
      IModel[] amlAndProblemModels = AmlCompiler.getDefault().injectAMLTextFile(in);
      IModel amlInjected = amlAndProblemModels[0];
      // TODO centralize the logging of aml file problems
      String metametamodel =
          (String) AmlModelUtils.getDefault().getMatchingMetametamodel(amlInjected);

      String resPath = AmlUIResourceManager.getDefault().getPath(file);
      EMFModel equalModel =
          AmlResourceManager.getDefault()
              .loadModel(resPath, AmlResourceManager.getDefault().getEqualMetamodel());
      WeaverXMLMetadata xml = new WeaverXMLMetadata(propertiesFile);
      xml.createXMLConfigFile(
          getModelInfos(equalModel, metametamodel, project.getName()),
          file.getFullPath().toString(),
          weavingPanel,
          EqualModelUtils.wmodel,
          Collections.EMPTY_LIST,
          Collections.EMPTY_LIST,
          ResourceUtils.getPathWithSeparator(
              project.getFullPath().toString(),
              AmlResourceManager.metamodelsFolderName,
              AmlResourceManager.equalMMName));
      IContainer fileContainer = file.getParent();
      fileContainer.refreshLocal(IResource.DEPTH_ONE, null);
    } catch (ATLCoreException e) {
      // TODO Auto-generated catch block
      throw new AmlUIException(IStatus.ERROR, "The equal model cannot be loaded");
    } catch (Exception e) {
      // TODO Auto-generated catch block
      throw new AmlUIException(IStatus.ERROR, e);
    }
  }
Beispiel #4
0
  /**
   * Runs the pub command.
   *
   * @return the result of running the pub command
   */
  public IStatus runSilent(IProgressMonitor monitor) {
    try {
      // Build the process description to run pub
      DartSdk sdk = DartSdkManager.getManager().getSdk();
      File pubFile = sdk.getPubExecutable();

      ProcessBuilder builder = new ProcessBuilder();
      builder.directory(container.getLocation().toFile());
      builder.redirectErrorStream(true);

      List<String> args = new ArrayList<String>();
      if (DartCore.isMac()) {
        args.add("/bin/bash");
        args.add("--login");
        args.add("-c");
        args.add("\"" + pubFile.getAbsolutePath() + "\"" + " " + command);
      } else {
        args.add(pubFile.getAbsolutePath());
        args.add(command);
      }
      builder.command(args);

      // Run the pub command as an external process.
      ProcessRunner runner = newProcessRunner(builder);

      try {
        runner.runSync(monitor);
      } catch (IOException e) {
        String message = NLS.bind(PubMessages.RunPubJob_failed, command, e.toString());
        return new Status(IStatus.CANCEL, DartCore.PLUGIN_ID, message, e);
      }

      StringBuilder stringBuilder = new StringBuilder();

      if (!runner.getStdOut().isEmpty()) {
        stringBuilder.append(runner.getStdOut().trim() + "\n"); // $NON-NLS-1$
      }

      int exitCode = runner.getExitCode();

      if (exitCode != 0) {
        String output = "[" + exitCode + "] " + stringBuilder.toString();
        String message = NLS.bind(PubMessages.RunPubJob_failed, command, output);
        return new Status(IStatus.ERROR, DartCore.PLUGIN_ID, message);
      }

      try {
        // Refresh the Eclipse resources
        container.refreshLocal(IResource.DEPTH_INFINITE, monitor);
      } catch (CoreException e) {
        // Log the exception and move on
        DartCore.logError("Exception refreshing " + container, e);
      }

      return new Status(IStatus.OK, DartCore.PLUGIN_ID, stringBuilder.toString());
    } catch (OperationCanceledException exception) {
      String message = NLS.bind(PubMessages.RunPubJob_canceled, command);
      return new Status(IStatus.CANCEL, DartCore.PLUGIN_ID, message, exception);
    } finally {
      monitor.done();
    }
  }
  private void doFinish(
      String containerName,
      String interfaceMasterFileName,
      String interfaceMasterQuery,
      String interfaceConfigFileName,
      Object[] interfaceConfigQuery,
      IProgressMonitor monitor)
      throws CoreException, IOException, TemplateException {

    // create a sample file
    monitor.beginTask("Creating " + interfaceMasterFileName, 2);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IResource resource = root.findMember(new Path(containerName));
    if (!resource.exists() || !(resource instanceof IContainer)) {
      throwCoreException("Container \"" + containerName + "\" does not exist.");
    }
    IContainer container = (IContainer) resource;

    // Create interface Master script

    try {

      OutputStream os = createInsertScriptFile(interfaceMasterFileName, container);
      byte stringByte[] = interfaceMasterQuery.getBytes();
      os.write(stringByte);
      os.close();
    } catch (IOException e) {
      e.printStackTrace();
    }

    // create interface configuration file.
    try {
      OutputStream os = createInsertScriptFile(interfaceConfigFileName, container);

      for (int i = 0; i < interfaceConfigQuery.length; i++) {
        stringConfigByte = ((String) interfaceConfigQuery[i]).getBytes();
        os.write(stringConfigByte);
      }
      os.close();
    } catch (IOException e) {
      e.printStackTrace();
    }

    // create baseconfiguration.xml

    createBaseConfigurationXML(container);
    createTransformationTemplate(container);

    // Make sure the project is refreshed as the file was created outside
    // the Eclipse API.

    container.refreshLocal(IResource.DEPTH_INFINITE, monitor);

    monitor.worked(1);

    // monitor.setTaskName("Opening file for editing...");
    // getShell().getDisplay().asyncExec(new Runnable() {
    // public void run() {
    // IWorkbenchPage page =
    // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    // try {
    // IDE.openEditor(page, iFile, true);
    // } catch (PartInitException e) {
    // }
    // }
    // });
    // monitor.worked(1);
  }
  @Override
  protected IStatus run(IProgressMonitor monitor) {
    IStatus ret = Status.OK_STATUS;
    SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
    Injector injector =
        TargetPlatformActivator.getInstance()
            .getInjector(TargetPlatformActivator.FR_OBEO_RELENG_TARGETPLATFORM_TARGETPLATFORM);
    Converter converter = new Converter();
    injector.injectMembers(converter);
    Diagnostic diagnostic = null;
    final String path = selectedElement.getLocation().toFile().getAbsolutePath();
    URI targetplatformFileURI = URI.createFileURI(path);

    try {
      diagnostic =
          converter.generateTargetDefinitionFile(targetplatformFileURI, subMonitor.newChild(95));
    } catch (OperationCanceledException cancel) {
      ret =
          new Status(
              IStatus.CANCEL,
              TargetPlatformActivator.FR_OBEO_RELENG_TARGETPLATFORM_TARGETPLATFORM,
              cancel.getMessage(),
              cancel);
    } catch (Exception e) {
      ret =
          new Status(
              IStatus.ERROR,
              TargetPlatformActivator.FR_OBEO_RELENG_TARGETPLATFORM_TARGETPLATFORM,
              e.getMessage(),
              e);
    }
    IContainer container = selectedElement.getParent();
    if (container != null) {
      try {
        container.refreshLocal(IResource.DEPTH_ONE, subMonitor.newChild(5));
      } catch (CoreException e) {
        return new Status(
            IStatus.ERROR,
            TargetPlatformActivator.getInstance().getBundle().getSymbolicName(),
            e.getMessage(),
            e);
      }
    }

    if (setTargetPlatform) {
      PDEIntegration pdeIntegration = new PDEIntegration();

      final URI targetFileURI =
          targetplatformFileURI.trimFileExtension().appendFileExtension("target");
      try {
        pdeIntegration.setTargetPlatform(targetFileURI, monitor);
      } catch (CoreException e) {
        ret =
            new Status(
                IStatus.ERROR,
                TargetPlatformActivator.FR_OBEO_RELENG_TARGETPLATFORM_TARGETPLATFORM,
                e.getMessage(),
                e);
      }
    }

    if (diagnostic != null) {
      return BasicDiagnostic.toIStatus(diagnostic);
    } else {
      return ret;
    }
  }