Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Taal2013-06-03 05:56:10 -0400
committerMartin Taal2013-06-03 05:56:10 -0400
commit958b3536300299b477d5c063cf9a96ffc0c7a693 (patch)
tree8af758a1a7e92fe072f106bc6c46322a01348e0f /generator/org.eclipse.emf.texo.orm
parentca7fd5e27ccdd05a6a14ae5add4d027eaca350c5 (diff)
downloadorg.eclipse.emf.texo-958b3536300299b477d5c063cf9a96ffc0c7a693.tar.gz
org.eclipse.emf.texo-958b3536300299b477d5c063cf9a96ffc0c7a693.tar.xz
org.eclipse.emf.texo-958b3536300299b477d5c063cf9a96ffc0c7a693.zip
Resolve NPE and other issues related to storing files
Diffstat (limited to 'generator/org.eclipse.emf.texo.orm')
-rw-r--r--generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPACode.java6
-rw-r--r--generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPADaoCode.java6
-rwxr-xr-xgenerator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMGenerator.java28
-rwxr-xr-xgenerator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/StandardORMGenerator.java3
4 files changed, 30 insertions, 13 deletions
diff --git a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPACode.java b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPACode.java
index ee474ad6..e2326fe5 100644
--- a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPACode.java
+++ b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPACode.java
@@ -16,9 +16,9 @@
*/
package org.eclipse.emf.texo.orm.annotator;
-import java.net.URI;
import java.util.List;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.texo.eclipse.popup.actions.GenerateCode;
@@ -31,11 +31,11 @@ import org.eclipse.emf.texo.eclipse.popup.actions.GenerateCode;
public class GenerateModelJPACode extends GenerateCode {
@Override
- protected void generateFromUris(IProgressMonitor monitor, IProject project, List<URI> uris) {
+ protected void generateFromModelFiles(IProgressMonitor monitor, IProject project, List<IFile> modelFiles) {
try {
setDoJpa(true);
ORMUtils.setORMMappingOptionsFromProjectProperties(project);
- super.generateFromUris(monitor, project, uris);
+ super.generateFromModelFiles(monitor, project, modelFiles);
} finally {
setDoJpa(false);
ORMMappingOptions.setDefaultOptions(null);
diff --git a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPADaoCode.java b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPADaoCode.java
index 0973e997..93957085 100644
--- a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPADaoCode.java
+++ b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/GenerateModelJPADaoCode.java
@@ -16,9 +16,9 @@
*/
package org.eclipse.emf.texo.orm.annotator;
-import java.net.URI;
import java.util.List;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -30,12 +30,12 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class GenerateModelJPADaoCode extends GenerateModelJPACode {
@Override
- protected void generateFromUris(IProgressMonitor monitor, IProject project, List<URI> uris) {
+ protected void generateFromModelFiles(IProgressMonitor monitor, IProject project, List<IFile> modelFiles) {
try {
setDoJpa(true);
setDoDao(true);
ORMUtils.setORMMappingOptionsFromProjectProperties(project);
- super.generateFromUris(monitor, project, uris);
+ super.generateFromModelFiles(monitor, project, modelFiles);
} finally {
setDoJpa(false);
setDoDao(false);
diff --git a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMGenerator.java b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMGenerator.java
index 8ebbfec3..abb8e086 100755
--- a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMGenerator.java
+++ b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMGenerator.java
@@ -18,12 +18,14 @@
package org.eclipse.emf.texo.orm.annotator;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.URI;
@@ -170,24 +172,27 @@ public class ORMGenerator extends BaseGenerateAction {
}
@Override
- protected void generateFromUris(IProgressMonitor monitor, IProject project, List<java.net.URI> uris) {
- for (java.net.URI uri : uris) {
- generateFromURI(monitor, project, uri);
+ protected void generateFromModelFiles(IProgressMonitor monitor, IProject project, List<IFile> modelFiles) {
+ for (IFile modelFile : modelFiles) {
+ generateFromModelFile(monitor, project, modelFile);
}
}
- protected void generateFromURI(IProgressMonitor monitor, IProject project, java.net.URI uri) {
+ protected void generateFromModelFile(IProgressMonitor monitor, IProject project, IFile modelFile) {
ORMUtils.setORMMappingOptionsFromProjectProperties(project);
try {
// always start with a fresh epackage registry
+ final java.net.URI uri = new java.net.URI(modelFile.getFullPath().toString());
final List<EPackage> ePackages = GeneratorUtils.readEPackages(Collections.singletonList(uri),
GeneratorUtils.createEPackageRegistry(), true);
- final URI parentUri = URI.createURI(uri.toString()).trimSegments(1);
+ final URI parentUri = URI.createURI(modelFile.getLocation().toString()).trimSegments(1);
final URI ormUri = parentUri.appendSegment(ORM_FILE_NAME);
generateStoreORM(ePackages, ormUri);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
} finally {
ORMMappingOptions.setDefaultOptions(null);
}
@@ -211,18 +216,29 @@ public class ORMGenerator extends BaseGenerateAction {
EntityMappingsType entityMappings) {
final Resource ormResource = new OrmannotationsResourceFactoryImpl().createResource(fileUri);
+ FileOutputStream fos = null;
try {
final File file = new File(fileUri.toFileString());
if (file.exists()) {
file.delete();
}
+ file.createNewFile();
+ fos = new FileOutputStream(file);
ormResource.getContents().clear();
final DocumentRoot docRoot = OrmFactory.eINSTANCE.createDocumentRoot();
docRoot.setEntityMappings(entityMappings);
ormResource.getContents().add(docRoot);
- ormResource.save(Collections.emptyMap());
+ ormResource.save(fos, Collections.emptyMap());
} catch (IOException e) {
throw new IllegalStateException(e);
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (Exception ignore) {
+
+ }
+ }
}
}
diff --git a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/StandardORMGenerator.java b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/StandardORMGenerator.java
index 3a2ab2d4..7ee7d0ca 100755
--- a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/StandardORMGenerator.java
+++ b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/StandardORMGenerator.java
@@ -83,7 +83,8 @@ public class StandardORMGenerator extends ORMGenerator {
final OrmannotationsResourceImpl ormResource = (OrmannotationsResourceImpl) new OrmannotationsResourceFactoryImpl()
.createResource(fileUri);
try {
- final File file = new File(fileUri.toFileString());
+ String fileUriStr = fileUri.toFileString();
+ final File file = new File(fileUriStr);
if (file.exists()) {
file.delete();
}

Back to the top