SetStaticCCNature.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ///////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2018 Intel Corporation. //
  3. // //
  4. // All rights reserved. This program and the accompanying materials //
  5. // are made available under the terms of the Eclipse Public License v1.0 //
  6. // which accompanies this distribution, and is available at //
  7. // http://www.eclipse.org/legal/epl-v10.html //
  8. // //
  9. // Contributors: //
  10. // Intel Corporation - initial implementation and documentation //
  11. ///////////////////////////////////////////////////////////////////////////
  12. package com.intel.sgx.templates;
  13. import org.eclipse.cdt.core.templateengine.TemplateCore;
  14. import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
  15. import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
  16. import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
  17. import org.eclipse.core.resources.IProject;
  18. import org.eclipse.core.resources.IProjectDescription;
  19. import org.eclipse.core.resources.IWorkspace;
  20. import org.eclipse.core.resources.ResourcesPlugin;
  21. import org.eclipse.core.runtime.CoreException;
  22. import org.eclipse.core.runtime.IProgressMonitor;
  23. import org.eclipse.core.runtime.IStatus;
  24. import com.intel.sgx.Activator;
  25. import com.intel.sgx.natures.SGXStaticCCNature;
  26. public class SetStaticCCNature extends ProcessRunner {
  27. public SetStaticCCNature() {
  28. }
  29. @Override
  30. public void process(TemplateCore template, ProcessArgument[] args,
  31. String processId, IProgressMonitor monitor)
  32. throws ProcessFailureException {
  33. String projectName = null;
  34. IProject project = null;
  35. for(ProcessArgument arg: args){
  36. String argName = arg.getName();
  37. if(argName.equals("projectName")){
  38. projectName = arg.getSimpleValue();
  39. }
  40. }
  41. project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
  42. IWorkspace workspace = project.getWorkspace();
  43. IProjectDescription description;
  44. try {
  45. description = project.getDescription();
  46. String[] natures = description.getNatureIds();
  47. String[] newNatures = new String[natures.length+1];
  48. System.arraycopy(natures,0,newNatures,0,natures.length);
  49. newNatures[natures.length] = SGXStaticCCNature.NATURE_ID;
  50. IStatus status = workspace.validateNatureSet(newNatures);
  51. if(status.getCode() == IStatus.OK)
  52. {
  53. description.setNatureIds(newNatures);
  54. project.setDescription(description, null);
  55. }
  56. else
  57. System.err.println("Incorrect Project Nature. Please check Project Settings.");
  58. } catch (CoreException e) {
  59. Activator.log(e);
  60. e.printStackTrace();
  61. }
  62. }
  63. }