package net.certware.hazard.stpa.ui.wizard;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.xtend.type.impl.java.JavaBeansMetaModel;
import org.eclipse.xpand2.XpandExecutionContextImpl;
import org.eclipse.xpand2.XpandFacade;
import org.eclipse.xpand2.output.Outlet;
import org.eclipse.xpand2.output.OutputImpl;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
public class HazardAnalysisProjectCreator extends org.eclipse.xtext.ui.wizard.AbstractPluginProjectCreator {
protected static final String DSL_GENERATOR_PROJECT_NAME = "net.certware.hazard.stpa";
protected static final String SRC_ROOT = "src";
protected static final String SRC_GEN_ROOT = "src-gen";
protected final List<String> SRC_FOLDER_LIST = ImmutableList.of(SRC_ROOT, SRC_GEN_ROOT);
@Override
protected HazardAnalysisProjectInfo getProjectInfo() {
return (HazardAnalysisProjectInfo) super.getProjectInfo();
}
protected String getModelFolderName() {
return SRC_ROOT;
}
@Override
protected List<String> getAllFolders() {
return SRC_FOLDER_LIST;
}
@Override
protected List<String> getRequiredBundles() {
List<String> result = Lists.newArrayList(super.getRequiredBundles());
result.add(DSL_GENERATOR_PROJECT_NAME);
return result;
}
protected void enhanceProject(final IProject project, final IProgressMonitor monitor) throws CoreException {
OutputImpl output = new OutputImpl();
output.addOutlet(new Outlet(false, getEncoding(), null, true, project.getLocation().makeAbsolute().toOSString()));
XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(output, null);
execCtx.getResourceManager().setFileEncoding("US-ASCII");
execCtx.registerMetaModel(new JavaBeansMetaModel());
XpandFacade facade = XpandFacade.create(execCtx);
facade.evaluate("net::certware::hazard::stpa::ui::wizard::HazardAnalysisNewProject::main", getProjectInfo());
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
}