Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Willink2016-05-05 14:11:31 -0400
committerEd Willink2016-05-05 14:11:31 -0400
commit06339afe1d23f93e1e24fa3049678aee594d3dc3 (patch)
tree2ff156c2ce0275225145de0a30c1057e74cc0f67
parent05eee7d13e06f3a7a984bec968b201668e129ec6 (diff)
downloadorg.eclipse.qvtd-06339afe1d23f93e1e24fa3049678aee594d3dc3.tar.gz
org.eclipse.qvtd-06339afe1d23f93e1e24fa3049678aee594d3dc3.tar.xz
org.eclipse.qvtd-06339afe1d23f93e1e24fa3049678aee594d3dc3.zip
[492869] Compile generated models explicitly
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/QVTrCompilerChain.java12
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/QVTrToQVTc.java27
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/utilities/JavaSourceFileObject.java (renamed from tests/org.eclipse.qvtd.xtext.qvtbase.tests/src/org/eclipse/qvtd/xtext/qvtbase/tests/utilities/JavaSourceFileObject.java)21
-rw-r--r--plugins/org.eclipse.qvtd.pivot.qvtbase/annotations/java/io/File.eea4
-rw-r--r--tests/org.eclipse.qvtd.xtext.qvtrelation.tests/.classpath2
-rw-r--r--tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java2
6 files changed, 44 insertions, 24 deletions
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/QVTrCompilerChain.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/QVTrCompilerChain.java
index 0516b9f2a..20beb729c 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/QVTrCompilerChain.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/QVTrCompilerChain.java
@@ -15,6 +15,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
@@ -26,6 +27,7 @@ import org.eclipse.ocl.pivot.internal.utilities.PivotUtilInternal;
import org.eclipse.ocl.pivot.utilities.XMIUtil;
import org.eclipse.qvtd.compiler.internal.qvtc2qvtu.QVTuConfiguration;
import org.eclipse.qvtd.compiler.internal.qvtr2qvtc.QVTrToQVTc;
+import org.eclipse.qvtd.compiler.internal.utilities.JavaSourceFileObject;
import org.eclipse.qvtd.pivot.qvtbase.Transformation;
import org.eclipse.qvtd.pivot.qvtbase.utilities.QVTbaseUtil;
import org.eclipse.qvtd.pivot.qvtimperative.evaluation.QVTiEnvironmentFactory;
@@ -96,7 +98,15 @@ public class QVTrCompilerChain extends AbstractCompilerChain
}
saveOptions.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
Collection<@NonNull ? extends GenPackage> usedGenPackages = getOption(GENMODEL_STEP, GENMODEL_USED_GENPACKAGES_KEY);
- t.saveGenModel(traceResource, traceURI, genModelURI, getOption(GENMODEL_STEP, GENMODEL_OPTIONS_KEY), saveOptions, usedGenPackages);
+ GenModel genModel = t.saveGenModel(traceResource, traceURI, genModelURI, getOption(GENMODEL_STEP, GENMODEL_OPTIONS_KEY), saveOptions, usedGenPackages);
+ t.generateModels(genModel);
+ String sourcePathPrefix = ".." + genModel.getModelDirectory() + "/";
+ String projectName = t.getProjectName(traceURI);
+ String objectPath = "../" + projectName + "/bin"; // FIXME deduce/parameterize bin
+ for (GenPackage genPackage : genModel.getGenPackages()) {
+ String sourcePath = sourcePathPrefix + genPackage.getBasePackage().replace(".", "/");
+ JavaSourceFileObject.compileClasses(sourcePath, objectPath);
+ }
compiled(GENMODEL_STEP, cResource);
// }
return cResource;
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/QVTrToQVTc.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/QVTrToQVTc.java
index cd3871d57..b467ea452 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/QVTrToQVTc.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/QVTrToQVTc.java
@@ -331,6 +331,16 @@ public class QVTrToQVTc
// TODO Auto-generated method stub
return null;
}
+
+ public @NonNull String getProjectName(@NonNull URI traceURI) {
+ URI trimFileExtension = traceURI.trimFileExtension();
+ if (trimFileExtension.isPlatform()) {
+ return trimFileExtension.segment(1);
+ }
+ else {
+ return trimFileExtension.segment(0);
+ }
+ }
/**
* @return the qvtcSource
@@ -494,17 +504,11 @@ public class QVTrToQVTc
asResource.save(options);
}
- public @NonNull Resource saveGenModel(@NonNull Resource asResource, @NonNull URI traceURI, @NonNull URI genModelURI, @Nullable Map<@NonNull String, @Nullable String> genModelOptions, @NonNull Map<Object, Object> saveOptions2, @Nullable Collection<@NonNull ? extends GenPackage> usedGenPackages) throws IOException {
+ public @NonNull GenModel saveGenModel(@NonNull Resource asResource, @NonNull URI traceURI, @NonNull URI genModelURI, @Nullable Map<@NonNull String, @Nullable String> genModelOptions, @NonNull Map<Object, Object> saveOptions2, @Nullable Collection<@NonNull ? extends GenPackage> usedGenPackages) throws IOException {
URI trimFileExtension = traceURI.trimFileExtension();
- String projectName;
- if (trimFileExtension.isPlatform()) {
- projectName = trimFileExtension.segment(1);
- }
- else {
- projectName = trimFileExtension.segment(0);
- }
+ String projectName = getProjectName(traceURI);
Resource genmodelResource = environmentFactory.getResourceSet().createResource(genModelURI);
- GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
+ @SuppressWarnings("null")@NonNull GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
genModel.getForeignModel().add(traceURI.lastSegment());
String copyrightText = genModelOptions != null ? genModelOptions.get(CompilerChain.GENMODEL_COPYRIGHT_TEXT) : null;
if (copyrightText != null) {
@@ -599,11 +603,10 @@ public class QVTrToQVTc
saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
saveOptions.put(Resource.OPTION_LINE_DELIMITER, Resource.OPTION_LINE_DELIMITER_UNSPECIFIED);
genmodelResource.save(saveOptions);
- generateModels(genModel);
- return genmodelResource;
+ return genModel;
}
- private void generateModels(@NonNull GenModel genModel) {
+ public void generateModels(@NonNull GenModel genModel) {
Registry generatorAdapterDescriptorRegistry = GeneratorAdapterFactory.Descriptor.Registry.INSTANCE;
if (!generatorAdapterDescriptorRegistry.getDescriptors(GenModelPackage.eNS_URI).contains(GenModelGeneratorAdapterFactory.DESCRIPTOR)) {
generatorAdapterDescriptorRegistry.addDescriptor(GenModelPackage.eNS_URI, GenModelGeneratorAdapterFactory.DESCRIPTOR);
diff --git a/tests/org.eclipse.qvtd.xtext.qvtbase.tests/src/org/eclipse/qvtd/xtext/qvtbase/tests/utilities/JavaSourceFileObject.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/utilities/JavaSourceFileObject.java
index cec4960fe..731372160 100644
--- a/tests/org.eclipse.qvtd.xtext.qvtbase.tests/src/org/eclipse/qvtd/xtext/qvtbase/tests/utilities/JavaSourceFileObject.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/utilities/JavaSourceFileObject.java
@@ -8,7 +8,7 @@
* Contributors:
* E.D.Willink - initial API and implementation
*******************************************************************************/
-package org.eclipse.qvtd.xtext.qvtbase.tests.utilities;
+package org.eclipse.qvtd.compiler.internal.utilities;
import java.io.File;
import java.io.FileReader;
@@ -33,7 +33,7 @@ import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
/**
- * JavaSourceFileObject supporets use of a File as a Java compilation unit.
+ * JavaSourceFileObject supports use of a File as a Java compilation unit.
*
* The compileClasses utility method support compilation of a source package and subpackages.
*/
@@ -89,13 +89,16 @@ public final class JavaSourceFileObject extends SimpleJavaFileObject
if (compilationUnits == null) {
compilationUnits = new ArrayList<@NonNull JavaFileObject>();
}
- for (File file : folder.listFiles()) {
- if (file.isDirectory()) {
- gatherCompilationUnits(file, compilationUnits);
- }
- else if (file.isFile() && file.getName().endsWith(".java")) {
- URI uri = file.getCanonicalFile().toURI();
- compilationUnits.add(new JavaSourceFileObject(uri));
+ File[] listFiles = folder.listFiles();
+ if (listFiles != null) {
+ for (File file : listFiles) {
+ if (file.isDirectory()) {
+ gatherCompilationUnits(file, compilationUnits);
+ }
+ else if (file.isFile() && file.getName().endsWith(".java")) {
+ URI uri = file.getCanonicalFile().toURI();
+ compilationUnits.add(new JavaSourceFileObject(uri));
+ }
}
}
return compilationUnits;
diff --git a/plugins/org.eclipse.qvtd.pivot.qvtbase/annotations/java/io/File.eea b/plugins/org.eclipse.qvtd.pivot.qvtbase/annotations/java/io/File.eea
new file mode 100644
index 000000000..aac44762d
--- /dev/null
+++ b/plugins/org.eclipse.qvtd.pivot.qvtbase/annotations/java/io/File.eea
@@ -0,0 +1,4 @@
+class java/io/File
+toURI
+ ()Ljava/net/URI;
+ ()L1java/net/URI;
diff --git a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/.classpath b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/.classpath
index 00c4e19d2..12a154e5a 100644
--- a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/.classpath
+++ b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/.classpath
@@ -11,6 +11,6 @@
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="test-gen"/>
+ <!--classpathentry kind="src" path="test-gen"/-->
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java
index e65655e9c..e19884150 100644
--- a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java
+++ b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java
@@ -43,6 +43,7 @@ import org.eclipse.qvtd.compiler.AbstractCompilerChain;
import org.eclipse.qvtd.compiler.CompilerChain;
import org.eclipse.qvtd.compiler.QVTrCompilerChain;
import org.eclipse.qvtd.compiler.internal.qvtp2qvts.Scheduler;
+import org.eclipse.qvtd.compiler.internal.utilities.JavaSourceFileObject;
import org.eclipse.qvtd.pivot.qvtbase.Transformation;
import org.eclipse.qvtd.pivot.qvtimperative.evaluation.BasicQVTiExecutor;
import org.eclipse.qvtd.pivot.qvtimperative.evaluation.QVTiEnvironmentFactory;
@@ -53,7 +54,6 @@ import org.eclipse.qvtd.pivot.qvtimperative.utilities.QVTimperativeUtil;
import org.eclipse.qvtd.runtime.evaluation.AbstractTransformer;
import org.eclipse.qvtd.runtime.evaluation.Transformer;
import org.eclipse.qvtd.xtext.qvtbase.tests.LoadTestCase;
-import org.eclipse.qvtd.xtext.qvtbase.tests.utilities.JavaSourceFileObject;
import org.eclipse.qvtd.xtext.qvtbase.tests.utilities.TestsXMLUtil;
import org.eclipse.qvtd.xtext.qvtcore.tests.QVTcTestUtil;
import org.eclipse.qvtd.xtext.qvtimperative.tests.ModelNormalizer;

Back to the top