Skip to content

Commit

Permalink
Fixed upper case issue with emf gen
Browse files Browse the repository at this point in the history
  • Loading branch information
wpiers committed Mar 10, 2016
1 parent 8ab5a41 commit 29f73b0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
Expand Down Expand Up @@ -76,24 +75,49 @@ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
public void run(IAction action) {
IFile occieFile = (IFile) ((IStructuredSelection) selection).getFirstElement();
try {
String extensionName = occieFile.getFullPath().removeFileExtension().lastSegment();
String modelPath = occieFile.getParent().getLocation().toString();
String ecoreLocation = modelPath + '/' + ConverterUtils.toU1Case(extensionName) + ".ecore";
String modelPluginName = new Path(ecoreLocation).removeLastSegments(2).lastSegment().toString();
EPackage.Registry.INSTANCE.put(ECORE_PLATFORM_URI, EcorePackage.eINSTANCE);
resourceSet = new ResourceSetImpl();
Extension ext = (Extension) ConverterUtils.getRootElement(resourceSet,
"file:/" + occieFile.getLocation().toString());

Map<Object, Object> validationContext = LabelUtil.createDefaultContext(Diagnostician.INSTANCE);
BasicDiagnostic diagnostics = Diagnostician.INSTANCE.createDefaultDiagnostic(ext);
if (!Diagnostician.INSTANCE.validate(ext, diagnostics, validationContext)) {
StringBuilder message = null;
for (Diagnostic diagnostic : diagnostics.getChildren()) {
if (message == null) {
message = new StringBuilder();
} else {
message.append("\n");
}
message.append(diagnostic.getMessage());
}
if (message != null) {
MessageDialog.openError(shell, "Invalid Extension", message.toString());
return;
}
}

String genModelPath = modelPath + '/' + ConverterUtils.toU1Case(extensionName) + ".genmodel";
// set a base package if necessary
String basePackage = "";
if (modelPluginName.endsWith(extensionName) && !modelPluginName.equals(extensionName)) {
basePackage = modelPluginName.substring(0, modelPluginName.length() - (extensionName.length() + 1));
String projectName = occieFile.getProject().getName();
String extensionName = ext.getName();
if (projectName.toLowerCase().endsWith(extensionName.toLowerCase())
&& projectName.length() > extensionName.length()) {
basePackage = projectName.substring(0, projectName.length() - (extensionName.length() + 1))
.toLowerCase();
}

try {
generateEMFModels(extensionName, ecoreLocation, basePackage);
generateEMFModels(ext,
occieFile.getLocation().removeFileExtension().addFileExtension("ecore").toString(),
basePackage);
} catch (IllegalArgumentException e) {
MessageDialog.openError(shell, "Invalid Extension", e.getMessage());
return;
}
occieFile.getParent().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
generateEMFCode(genModelPath);
generateEMFCode(occieFile.getLocation().removeFileExtension().addFileExtension("genmodel ").toString());

IFile build = PDEProject.getBuildProperties(occieFile.getProject());
String buildContent = "bin.includes = .,\\\n model/,\\\n META-INF/,\\\n plugin.xml,\\\n plugin.properties\njars.compile.order = .\nsource.. = src-gen/\noutput.. = bin/\n";
Expand All @@ -118,32 +142,10 @@ public void selectionChanged(IAction action, ISelection selection) {
this.selection = selection;
}

private void generateEMFModels(String extensionName, String ecoreLocation, String basePackage) throws IOException {
private void generateEMFModels(Extension ext, String ecoreLocation, String basePackage) throws IOException {
/*
* OCCIE => Ecore conversion
*/
EPackage.Registry.INSTANCE.put(ECORE_PLATFORM_URI, EcorePackage.eINSTANCE);
resourceSet = new ResourceSetImpl();
Extension ext = (Extension) ConverterUtils.getRootElement(resourceSet,
"file:/" + ecoreLocation.substring(0, ecoreLocation.length() - 5) + "occie");

Map<Object, Object> validationContext = LabelUtil.createDefaultContext(Diagnostician.INSTANCE);
BasicDiagnostic diagnostics = Diagnostician.INSTANCE.createDefaultDiagnostic(ext);
if (!Diagnostician.INSTANCE.validate(ext, diagnostics, validationContext)) {
StringBuilder message = null;
for (Diagnostic diagnostic : diagnostics.getChildren()) {
if (message == null) {
message = new StringBuilder();
} else {
message.append("\n");
}
message.append(diagnostic.getMessage());
}
if (message != null) {
throw new IllegalArgumentException(message.toString());
}
}

EPackage ePackage = new OCCIExtension2Ecore().convertExtension(ext);
resourceSet.getPackageRegistry().put(ePackage.getNsURI(), ePackage);
ConverterUtils.persistMetamodel(resourceSet, ePackage, ecoreLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static GenPackage createGenModel(final EPackage rootPackage, final String
genModel.getUsedGenPackages().addAll(usedGenPackages);
genModel.initialize(Collections.singleton(rootPackage));
GenPackage genPackage = genModel.getGenPackages().get(0);
genPackage.setPrefix(rootPackage.getNsPrefix());
genPackage.setPrefix(ConverterUtils.toU1Case(rootPackage.getNsPrefix()));
genPackage.setBasePackage(basePackage);

URI genModelURI = URI
Expand Down

0 comments on commit 29f73b0

Please sign in to comment.