package jetbrains.mps.project.foreign;
/*Generated by MPS */
import jetbrains.mps.project.io.DescriptorIO;
import jetbrains.mps.project.structure.modules.SolutionDescriptor;
import jetbrains.mps.vfs.IFile;
import jetbrains.mps.project.io.DescriptorIOException;
import jetbrains.mps.util.MacroHelper;
import jetbrains.mps.baseLanguage.closures.runtime._FunctionTypes;
import jetbrains.mps.project.ModuleId;
import jetbrains.mps.project.structure.model.ModelRootDescriptor;
import org.jetbrains.mps.openapi.persistence.PersistenceFacade;
import org.jetbrains.mps.openapi.persistence.Memento;
import java.io.IOException;
import org.jdom.JDOMException;
import org.jdom.Element;
public class IdeaModuleSolutionDescriptorIO implements DescriptorIO<SolutionDescriptor> {
public IdeaModuleSolutionDescriptorIO() {
}
@Override
public SolutionDescriptor readFromFile(final IFile file) throws DescriptorIOException {
final MPSFacetConfiguration mpsConf = this.readMPSFacetConf(file);
if (mpsConf == null) {
return null;
}
final MacroHelper macroHelper = new ModuleMacroExpander(null, file);
SolutionDescriptor sd;
sd = new _FunctionTypes._return_P0_E0<SolutionDescriptor>() {
public SolutionDescriptor invoke() {
final SolutionDescriptor result_56japk_a0a0e0b = new SolutionDescriptor();
// TODO: namespace
final String result_56japk_a1a0a0e0b = file.getName();
result_56japk_a0a0e0b.setNamespace(result_56japk_a1a0a0e0b);
final ModuleId result_56japk_a3a0a0e0b = ModuleId.fromString(mpsConf.UUID);
result_56japk_a0a0e0b.setId(result_56japk_a3a0a0e0b);
// TODO: pluginKind
final boolean result_56japk_a7a0a0e0b = true;
result_56japk_a0a0e0b.setCompileInMPS(result_56japk_a7a0a0e0b);
final boolean result_56japk_a9a0a0e0b = mpsConf.useTransientOutputFolder;
result_56japk_a0a0e0b.setUseTransientOutput(result_56japk_a9a0a0e0b);
final String result_56japk_a11a0a0e0b = macroHelper.expandPath(mpsConf.generatorOutputPath);
result_56japk_a0a0e0b.setOutputPath(result_56japk_a11a0a0e0b);
if (mpsConf.rootDescriptors != null) {
for (ModelRootDescriptor mrp : mpsConf.rootDescriptors) {
// TODO: model root manager
process(mrp.getMemento(), macroHelper);
result_56japk_a0a0e0b.getModelRootDescriptors().add(mrp);
}
}
// TODO: stub model entries
// TODO: dependencies
if (mpsConf.usedLanguages != null) {
for (String usedLang : mpsConf.usedLanguages) {
result_56japk_a0a0e0b.getUsedLanguages().add(PersistenceFacade.getInstance().createModuleReference(usedLang));
}
}
// TODO: devkits
// TODO : class paths
// TODO: source paths
return result_56japk_a0a0e0b;
}
}.invoke();
sd.setTimestamp(Long.toString(file.lastModified()));
return sd;
}
public void process(Memento memento, MacroHelper helper) {
for (String key : memento.getKeys()) {
if (key.equals("path") || key.endsWith("Path")) {
memento.put(key, helper.expandPath(memento.get(key)));
}
}
for (Memento c : memento.getChildren()) {
process(c, helper);
}
}
private MPSFacetConfiguration readMPSFacetConf(IFile file) throws DescriptorIOException {
try {
IdeaModuleConfiguration imc = IdeaModuleConfiguration.readFile(file);
return imc.getMPSFacetConfiguration();
} catch (FacetConfigurationFormatException e) {
throw new DescriptorIOException(e);
} catch (IOException e) {
throw new DescriptorIOException(e);
} catch (JDOMException e) {
throw new DescriptorIOException(e);
}
}
@Override
public void writeToFile(SolutionDescriptor t, IFile file) {
throw new UnsupportedOperationException();
}
@Override
public SolutionDescriptor readFromXml(Element element, IFile anchorFile) {
throw new UnsupportedOperationException();
}
@Override
public void writeToXml(SolutionDescriptor t, Element element, IFile anchorFile) {
throw new UnsupportedOperationException();
}
}