use of com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon-compiler by ceylon.
the class RecoveryTests method testSyntaxErrorInModule.
@Test
public void testSyntaxErrorInModule() throws IOException {
String subPath = "modules/syntaxErrorInModule";
String srcPath = getPackagePath() + subPath;
List<String> options = new LinkedList<String>();
options.add("-src");
options.add(srcPath);
options.addAll(defaultOptions);
options.add("-continue");
ErrorCollector c = new ErrorCollector();
CeyloncTaskImpl task = getCompilerTask(options, c, Arrays.asList("okmodule"), subPath + "/someok.ceylon");
Boolean ret = task.call();
assertFalse(ret);
TreeSet<CompilerError> actualErrors = c.get(Diagnostic.Kind.ERROR);
compareErrors(actualErrors, new CompilerError(-1, "incorrect syntax: no viable alternative at token end of file"), new CompilerError(20, "incorrect syntax: mismatched token 'ERROR' expecting initial-lowercase identifier"), new CompilerError(20, "incorrect syntax: no viable alternative at token '\"1.0.0\"'"), new CompilerError(20, "incorrect syntax: no viable alternative at token 'okmodule'"));
File carFile = getModuleArchive("default", null);
assertTrue(carFile.exists());
JarFile car = new JarFile(carFile);
ZipEntry moduleClass = car.getEntry("foobar_.class");
assertNotNull(moduleClass);
car.close();
carFile = getModuleArchive("okmodule", "1.0.0");
assertFalse(carFile.exists());
}
use of com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon-compiler by ceylon.
the class RecoveryTests method testTako.
@Ignore("This test largely depends on modules that are now binary-incompatible")
@Test
public void testTako() throws IOException {
String subPath = "modules/bug1411";
String srcPath = getPackagePath() + subPath;
List<String> options = new LinkedList<String>();
options.add("-src");
options.add(srcPath);
options.addAll(defaultOptions);
options.add("-continue");
ErrorCollector c = new ErrorCollector();
CeyloncTaskImpl task = getCompilerTask(options, c, subPath + "/dupdecl.ceylon", subPath + "/moduletest1/module.ceylon", subPath + "/moduletest1/package.ceylon", subPath + "/moduletest1/helloworld.ceylon", subPath + "/hello/hello.ceylon", subPath + "/hello/module.ceylon", subPath + "/hello/package.ceylon", subPath + "/testtest/module.ceylon", subPath + "/testtest/test.ceylon", subPath + "/sub/mod/module.ceylon", subPath + "/sub/mod/run.ceylon", subPath + "/sub/mod/package.ceylon", subPath + "/unknownmodule/module.ceylon", subPath + "/unknownmodule/run.ceylon", subPath + "/unknownmodule/package.ceylon", subPath + "/interop/module.ceylon", subPath + "/interop/interop.ceylon", subPath + "/jsonly/jsonly.ceylon", subPath + "/jsonly/module.ceylon", subPath + "/jsonly/package.ceylon", subPath + "/modulep/module.ceylon", subPath + "/modulep/main.ceylon", subPath + "/browser/dom/main.ceylon", subPath + "/browser/dom/package.ceylon", subPath + "/browser/module.ceylon", subPath + "/browser/main.ceylon", subPath + "/browser/package.ceylon", subPath + "/test/InheritanceAndBoxingTest.ceylon", subPath + "/test/ExceptionTest.ceylon", subPath + "/test/Foo.ceylon", subPath + "/test/GameOfLife.ceylon", subPath + "/test/Bar.ceylon", subPath + "/test/encoding.ceylon", subPath + "/test/helloworld.ceylon", subPath + "/swing/module.ceylon", subPath + "/swing/run.ceylon", subPath + "/swing/package.ceylon", subPath + "/interoprev/module.ceylon", subPath + "/interoprev/run.ceylon", subPath + "/interoprev/package.ceylon", subPath + "/java/hello.ceylon", subPath + "/java/module.ceylon", subPath + "/java/package.ceylon", subPath + "/helloworld.ceylon", subPath + "/wrongversion/module.ceylon", subPath + "/wrongversion/run.ceylon", subPath + "/wrongversion/package.ceylon", subPath + "/importhello/module.ceylon", subPath + "/importhello/helloworld.ceylon", subPath + "/usingimport.ceylon", // subPath + "/javaa/run.ceylon"
subPath + "/gavinprob/module.ceylon", subPath + "/gavinprob/main.ceylon", subPath + "/web_ide_script/module.ceylon", subPath + "/web_ide_script/hello_world.ceylon", subPath + "/timetest/module.ceylon", subPath + "/timetest/test.ceylon");
Boolean ret = task.call();
assertFalse(ret);
TreeSet<CompilerError> actualErrors = c.get(Diagnostic.Kind.ERROR);
compareErrors(actualErrors, new CompilerError(1, "package not found in imported modules: 'java.lang' (define a module and add module import to its module descriptor)"), new CompilerError(2, "source code imports two different versions of module 'ceylon.file': version '0.5' and version '1.1.0'"), new CompilerError(2, "cannot find module artifact fooxhilio.bastardo-77.9(.car|.jar)\n" + " \t- dependency tree: unknownmodule/1.0.0 -> fooxhilio.bastardo/77.9"), new CompilerError(4, "function or value does not exist: 'nanoTime'"), new CompilerError(4, "type does not exist: 'Test'"), new CompilerError(4, "unsupported module name: this namespace is used by Java platform modules"), new CompilerError(5, "duplicate declaration name: 'run'"), new CompilerError(7, "duplicate declaration name: 'run'"), new CompilerError(10, "case must be a toplevel anonymous class: 'alive' is not toplevel"), new CompilerError(10, "case must be a toplevel anonymous class: 'dead' is not toplevel"), new CompilerError(10, "case must be a toplevel anonymous class: 'moribund' is not toplevel"), new CompilerError(10, "case must be a toplevel anonymous class: 'resurrected' is not toplevel"), new CompilerError(12, "imported declaration not found: 'newServer_bogus'"), new CompilerError(30, "function or value does not exist: 'newServer_bogus'"), new CompilerError(135, "function or value does not exist: 'array'"), new CompilerError(138, "could not determine type of function or value reference: 'cells'"), new CompilerError(139, "could not determine type of function or value reference: 'c'"), new CompilerError(140, "could not determine type of function or value reference: 'c'"));
File carFile = getModuleArchive("default", null);
assertTrue(carFile.exists());
String[] modules = new String[] { "swing/1.0.0", "web_ide_script/1.0.0", "browser/1.0.0", "timetest/1.0.0", "interop/1.0.0", "importhello/0.1", "interoprev/1.0.0", "modulep/0.1", "hello/1.0.0", "moduletest1/0.1", "jsonly/1.0.0", "testtest/1.1", "sub.mod/1.0.0" };
for (String module : modules) {
int sep = module.indexOf('/');
String name = module.substring(0, sep);
String version = module.substring(sep + 1);
carFile = getModuleArchive(name, version);
assertTrue("Module created car: " + module, carFile.exists());
}
}
use of com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon-compiler by ceylon.
the class RecoveryTests method testDuplicateInDefault.
@Test
public void testDuplicateInDefault() throws IOException {
String subPath = "modules/duplicateInDefault";
String srcPath = getPackagePath() + subPath;
List<String> options = new LinkedList<String>();
options.add("-src");
options.add(srcPath);
options.addAll(defaultOptions);
options.add("-continue");
ErrorCollector c = new ErrorCollector();
CeyloncTaskImpl task = getCompilerTask(options, c, Arrays.asList("okmodule"), subPath + "/dupdeclerr1.ceylon", subPath + "/dupdeclerr2.ceylon", subPath + "/someok.ceylon");
Boolean ret = task.call();
assertFalse(ret);
TreeSet<CompilerError> actualErrors = c.get(Diagnostic.Kind.ERROR);
compareErrors(actualErrors, // new CompilerError(21, "cannot find module artifact notfound-1(.car|.jar)\n \t- dependency tree: okmodule/1.0.0 -> notfound/1"),
new CompilerError(20, "duplicate declaration name: 'run'"));
File carFile = getModuleArchive("default", null);
assertTrue(carFile.exists());
JarFile car = new JarFile(carFile);
ZipEntry moduleClass = car.getEntry("foobar_.class");
assertNotNull(moduleClass);
car.close();
carFile = getModuleArchive("okmodule", "1.0.0");
assertTrue(carFile.exists());
car = new JarFile(carFile);
moduleClass = car.getEntry("okmodule/$module_.class");
assertNotNull(moduleClass);
car.close();
}
use of com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon-compiler by ceylon.
the class StructureTests2 method testImpImportWildcardSinglePass.
@Test
public void testImpImportWildcardSinglePass() {
List<String> options = new LinkedList<String>();
options.add("-src");
options.add(getPackagePath() + "/importIt/src");
CeyloncTaskImpl task = getCompilerTask(options, "importIt/src/pkg/File.ceylon", "importIt/src/pkg/sub/ConcreteDirectory.ceylon");
Assert.assertTrue(task.call());
task = getCompilerTask(options, "importIt/src/pkg/File.ceylon", "importIt/src/pkg/sub/ConcreteDirectory.ceylon");
Assert.assertTrue(task.call());
}
use of com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon-compiler by ceylon.
the class ModelLoaderTests method verifyCompilerClassLoading.
protected void verifyCompilerClassLoading(String ceylon, final ModelComparison modelCompare) {
// now compile the ceylon decl file
CeyloncTaskImpl task = getCompilerTask(ceylon);
// get the context to grab the phased units
Context context = task.getContext();
if (simpleAnnotationModels) {
CeylonEnter.instance(context);
ExpressionTransformer.getInstance(context).simpleAnnotationModels = true;
CeylonTransformer.getInstance(context).simpleAnnotationModels = true;
StatementTransformer.getInstance(context).simpleAnnotationModels = true;
ClassTransformer.getInstance(context).simpleAnnotationModels = true;
}
Boolean success = task.call();
Assert.assertTrue(success);
PhasedUnits phasedUnits = LanguageCompiler.getPhasedUnitsInstance(context);
// find out what was in that file
Assert.assertEquals(2, phasedUnits.getPhasedUnits().size());
PhasedUnit one = phasedUnits.getPhasedUnits().get(0);
PhasedUnit two = phasedUnits.getPhasedUnits().get(1);
PhasedUnit phasedUnit = one.getUnitFile().getName().endsWith("module.ceylon") ? two : one;
final Map<String, Declaration> decls = new HashMap<String, Declaration>();
for (Declaration decl : phasedUnit.getUnit().getDeclarations()) {
if (decl.isToplevel()) {
decls.put(getQualifiedPrefixedName(decl), decl);
}
}
// now compile the ceylon usage file
// remove the extension, make lowercase and add "test"
String testfile = ceylon.substring(0, ceylon.length() - 7).toLowerCase() + "test.ceylon";
JavacTaskImpl task2 = getCompilerTask(testfile);
// get the context to grab the declarations
final Context context2 = task2.getContext();
// declarations from the jar anymore because we've overridden the jar and the javac jar index is corrupted
class Listener implements TaskListener {
@Override
public void started(TaskEvent e) {
}
@Override
public void finished(TaskEvent e) {
if (e.getKind() == Kind.ENTER) {
AbstractModelLoader modelLoader = CeylonModelLoader.instance(context2);
Modules modules = LanguageCompiler.getCeylonContextInstance(context2).getModules();
// now see if we can find our declarations
compareDeclarations(modelCompare, decls, modelLoader, modules);
}
}
}
Listener listener = new Listener();
task2.setTaskListener(listener);
success = task2.call();
Assert.assertTrue("Compilation failed", success);
// now check with the runtime model loader too
String module = moduleForJavaModelLoading();
String version = "1";
ModuleWithArtifact moduleWithArtifact = new ModuleWithArtifact(module, version);
synchronized (RUN_LOCK) {
// this initialises the metamodel, even if we don't use the resulting ClassLoader
URLClassLoader classLoader;
try {
classLoader = getClassLoader("runtime model loader tests", moduleWithArtifact);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
try {
RuntimeModuleManager moduleManager = Metamodel.getModuleManager();
RuntimeModelLoader modelLoader = moduleManager.getModelLoader();
Modules modules = moduleManager.getModules();
// now see if we can find our declarations
compareDeclarations(modelCompare, decls, modelLoader, modules);
} finally {
try {
classLoader.close();
} catch (IOException e) {
// ignore
e.printStackTrace();
}
}
}
}
Aggregations