blob: 8a3745af22d958a0b1dc0c87a43588f4f9eb473d [file] [log] [blame]
IPath ecorePath = new Path(parameter.getModelPath());
URI ecoreURI = URI.createPlatformResourceURI(ecorePath.toString(), false);
String fileName = ecorePath.removeFileExtension().addFileExtension("genmodel").lastSegment();
// look up in the workspace
TextSearchScope fScope = FileTextSearchScope.newWorkspaceScope(new String[] { fileName }, false);
final ObjectHolder<IFile> genModelFile = new ObjectHolder<IFile>();
TextSearchRequestor collector = new TextSearchRequestor() {
@Override
public boolean acceptFile(IFile file) throws CoreException {
genModelFile.object = file;
return super.acceptFile(file);
}
};
Pattern searchPattern = Pattern.compile("");
TextSearchEngine.create().search(fScope, collector, searchPattern, null);
if (genModelFile.object == null) {
ResourceSet resourceSet = new TargetPlatformResourceSet();
Resource resource = null;
IPath genmodelPath = ecorePath.removeFileExtension().addFileExtension("genmodel");
genmodelPath = new Path(parameter.getPluginName()).append(genmodelPath.removeFirstSegments(1));
URI genmodelURI = URI.createPlatformPluginURI(genmodelPath.toString(), false);
try {
// see if a created genmodel exists
resource = resourceSet.getResource(genmodelURI, true);
} catch (Exception e1) {
// create it
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(parameter.getPluginName());
if (!project.exists())
project.create(null);
if (!project.isOpen())
project.open(null);
importer = EcoreImporterHelper.createEcoreImporter(genmodelPath.removeLastSegments(1), ecoreURI, parameter);
}
genmodelURI = URI.createPlatformResourceURI(genmodelPath.toString(), false);
((HashMap<String, URI>) ctx.getValue(FcoreBuilderConstants.GENMODEL_URIS)).put(parameter.getModelPath(), genmodelURI);
} else {
URI uri = URI.createPlatformResourceURI(genModelFile.object.getFullPath().toString(), false);
((HashMap<String, URI>) ctx.getValue(FcoreBuilderConstants.GENMODEL_URIS)).put(parameter.getModelPath(), uri);
}