SGXCCProjectWizard.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.wizards;
  13. import java.net.URI;
  14. import java.util.Map;
  15. import org.eclipse.cdt.core.templateengine.TemplateCore;
  16. import org.eclipse.cdt.core.templateengine.TemplateEngine;
  17. import org.eclipse.cdt.ui.wizards.CCProjectWizard;
  18. import org.eclipse.core.resources.IProject;
  19. import org.eclipse.core.resources.IProjectDescription;
  20. import org.eclipse.core.resources.IWorkspace;
  21. import org.eclipse.core.resources.ResourcesPlugin;
  22. import org.eclipse.core.runtime.CoreException;
  23. import org.eclipse.core.runtime.IConfigurationElement;
  24. import org.eclipse.core.runtime.IProgressMonitor;
  25. import org.eclipse.core.runtime.IStatus;
  26. import org.eclipse.core.runtime.NullProgressMonitor;
  27. import com.intel.sgx.natures.SGXNature;
  28. public class SGXCCProjectWizard extends CCProjectWizard {
  29. private IProject project;
  30. @Override
  31. protected boolean setCreated() throws CoreException {
  32. boolean result = super.setCreated();
  33. doIt(project, new NullProgressMonitor());
  34. return result;
  35. }
  36. @Override
  37. public boolean performFinish() {
  38. return super.performFinish();
  39. }
  40. @Override
  41. public void setInitializationData(IConfigurationElement config,
  42. String propertyName, Object data) throws CoreException {
  43. // TODO Auto-generated method stub
  44. super.setInitializationData(config, propertyName, data);
  45. }
  46. @Override
  47. public IProject createIProject(String name, URI location)
  48. throws CoreException {
  49. // TODO Auto-generated method stub
  50. return super.createIProject(name, location);
  51. }
  52. @Override
  53. public IProject createIProject(String name, URI location,
  54. IProgressMonitor monitor) throws CoreException {
  55. project = super.createIProject(name, location, monitor);
  56. return project;
  57. }
  58. @Override
  59. public String[] getExtensions() {
  60. // TODO Auto-generated method stub
  61. return super.getExtensions();
  62. }
  63. public SGXCCProjectWizard() {
  64. // TODO Auto-generated constructor stub
  65. }
  66. @Override
  67. public String[] getNatures() {
  68. // TODO Auto-generated method stub
  69. return super.getNatures();
  70. }
  71. @Override
  72. protected IProject continueCreation(IProject prj) {
  73. // TODO Auto-generated method stub
  74. return super.continueCreation(prj);
  75. }
  76. @Override
  77. public String[] getContentTypeIDs() {
  78. // TODO Auto-generated method stub
  79. return super.getContentTypeIDs();
  80. }
  81. @Override
  82. public IProject getProject(boolean defaults) {
  83. // TODO Auto-generated method stub
  84. return super.getProject(defaults);
  85. }
  86. @Override
  87. public String[] getLanguageIDs() {
  88. // TODO Auto-generated method stub
  89. return super.getLanguageIDs();
  90. }
  91. void doIt(IProject project, IProgressMonitor monitor) throws CoreException {
  92. TemplateCore template = TemplateEngine.getDefault().getTemplateById(
  93. "AddSGXNature");
  94. Map<String, String> valueStore = template.getValueStore();
  95. valueStore.put("projectName", project.getName());
  96. valueStore.put("baseName", project.getName());
  97. template.executeTemplateProcesses(monitor, false);
  98. IWorkspace workspace = ResourcesPlugin.getWorkspace();
  99. IProjectDescription description = project.getDescription();
  100. String[] natures = description.getNatureIds();
  101. String[] newNatures = new String[natures.length + 1];
  102. System.arraycopy(natures, 0, newNatures, 0, natures.length);
  103. newNatures[natures.length] = SGXNature.NATURE_ID;
  104. IStatus status = workspace.validateNatureSet(newNatures);
  105. if (status.getCode() == IStatus.OK) {
  106. description.setNatureIds(newNatures);
  107. project.setDescription(description, null);
  108. } else {
  109. System.err
  110. .println("Incorrect Project Nature. Please check Project Settings.");// TODO
  111. // throw
  112. // an
  113. // exception
  114. // here.
  115. System.err.println("Status is: " + status.getCode());
  116. }
  117. // project.refreshLocal(IResource.DEPTH_ONE,null);
  118. }
  119. }