Search in sources :

Example 46 with CompilerError

use of org.eclipse.ceylon.compiler.java.test.CompilerError in project ceylon by eclipse.

the class CMRTests method testMdlAetherMissingDependencies.

@Test
public void testMdlAetherMissingDependencies() throws IOException {
    CompilerError[] expectedErrors = new CompilerError[] { new CompilerError(6, "Error while loading the org.apache.camel:camel-jetty/2.9.4 module:\n" + "   Declaration 'org.apache.camel.component.http.HttpComponent' could not be found in module 'org.apache.camel:camel-jetty' or its imported modules"), new CompilerError(10, "argument must be assignable to parameter 'arg1' of 'addComponent' in 'DefaultCamelContext': 'JettyHttpComponent' is not assignable to 'Component?': Error while loading the org.apache.camel:camel-jetty/2.9.4 module:\n" + "   Declaration 'org.apache.camel.component.http.HttpComponent' could not be found in module 'org.apache.camel:camel-jetty' or its imported modules") };
    ErrorCollector collector = new ErrorCollector();
    // Try to compile the ceylon module
    CeyloncTaskImpl ceylonTask = getCompilerTask(Arrays.asList("-out", destDir, "-rep", "aether"), collector, "modules/bug1100/module.ceylon", "modules/bug1100/test.ceylon");
    assertEquals("Compilation failed", Boolean.FALSE, ceylonTask.call());
    TreeSet<CompilerError> actualErrors = collector.get(Diagnostic.Kind.ERROR);
    compareErrors(actualErrors, expectedErrors);
}
Also used : CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError) ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) Test(org.junit.Test)

Example 47 with CompilerError

use of org.eclipse.ceylon.compiler.java.test.CompilerError in project ceylon by eclipse.

the class CMRTests method testOverridesCeylonModuleInSourceImport.

@Test
public void testOverridesCeylonModuleInSourceImport() {
    setupBinaryModulesForOverridesCeylonModuleTests();
    ErrorCollector collector = new ErrorCollector();
    CeyloncTaskImpl compilerTask = getCompilerTask(Arrays.asList("-continue", "-src", getPackagePath() + "/modules", "-overrides", getPackagePath() + "modules/overridesCeylonModule/overrides-a-version.xml"), collector, "modules/overridesCeylonModule/module.ceylon");
    ModulesRetriever modulesRetriever = new ModulesRetriever(compilerTask.getContext());
    compilerTask.setTaskListener(modulesRetriever);
    Boolean result = compilerTask.call();
    Assert.assertEquals(Boolean.TRUE, result);
    compareErrors(collector.get(Diagnostic.Kind.WARNING), new CompilerError(Kind.WARNING, null, 1, "all-lowercase ASCII module names are recommended"), new CompilerError(Kind.WARNING, null, 2, "project source module import is overridden in module overrides file: 'a/2' overrides 'a/1'"));
    assert (modulesRetriever.modules != null);
    Module a = modulesRetriever.modules.get("a");
    Module b = modulesRetriever.modules.get("b");
    Module c = modulesRetriever.modules.get("c");
    assert (a != null);
    assert (b != null);
    assert (c != null);
    assertEquals("The version override should not be applied to modules imported in source code", "2", a.getVersion());
    assertEquals("The version override should not be applied to modules imported in source code", "2", b.getVersion());
    assertEquals("The version override should not be applied to modules imported in source code", "2", c.getVersion());
}
Also used : ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) Module(org.eclipse.ceylon.model.typechecker.model.Module) Test(org.junit.Test)

Example 48 with CompilerError

use of org.eclipse.ceylon.compiler.java.test.CompilerError in project ceylon by eclipse.

the class CMRTests method testMdlBug1062IncompatibleNonSharedImport.

@Test
public void testMdlBug1062IncompatibleNonSharedImport() throws IOException {
    // compile our java class
    File classesOutputFolder = new File(destDir + "-jar-classes");
    cleanCars(classesOutputFolder.getPath());
    classesOutputFolder.mkdirs();
    File jarOutputFolder = new File(destDir + "-jar");
    cleanCars(jarOutputFolder.getPath());
    jarOutputFolder.mkdirs();
    compileJavaModule(jarOutputFolder, classesOutputFolder, "bug1062.javaA", "1", new File(getPackagePath() + "/modules/bug1062/javaA1-src"), new File[0], "bug1062/javaA/JavaA.java");
    compileJavaModule(jarOutputFolder, classesOutputFolder, "bug1062.javaA", "2", new File(getPackagePath() + "/modules/bug1062/javaA2-src"), new File[0], "bug1062/javaA/JavaA.java");
    compileJavaModule(jarOutputFolder, classesOutputFolder, "bug1062.javaB", "1", new File(getPackagePath() + "/modules/bug1062/javaB-module-src"), new File[] { new File(jarOutputFolder, "bug1062/javaA/1/bug1062.javaA-1.jar") }, "bug1062/javaB/JavaB.java");
    // ceylon module imports JavaA/2 and JavaB/1
    // JavaB/1 imports JavaA/1
    assertErrors("modules/bug1062/ceylon/test", Arrays.asList("-rep", jarOutputFolder.getPath(), "-cp", getClassPathAsPath()), null, new CompilerError(5, "could not determine type of method or attribute reference: 'method' of 'JavaB' is ambiguous - Error while loading the bug1062.javaB/1 module:\n" + "   Declaration 'bug1062.javaA.JavaA' could not be found in module 'bug1062.javaB' or its imported modules but was found in the non-imported module 'bug1062.javaA'"), new CompilerError(5, "parameter type could not be determined: 'arg0' of 'method' in 'JavaB' - Error while loading the bug1062.javaB/1 module:\n" + "   Declaration 'bug1062.javaA.JavaA' could not be found in module 'bug1062.javaB' or its imported modules but was found in the non-imported module 'bug1062.javaA'"));
}
Also used : CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Example 49 with CompilerError

use of org.eclipse.ceylon.compiler.java.test.CompilerError in project ceylon by eclipse.

the class CMRTests method testMdlMultipleVersionsDuringImport.

@Test
public void testMdlMultipleVersionsDuringImport() {
    // Compile module A/1
    Boolean result = getCompilerTask(Arrays.asList("-src", getPackagePath() + "/modules/multiversion/a1"), "modules/multiversion/a1/a/module.ceylon", "modules/multiversion/a1/a/package.ceylon", "modules/multiversion/a1/a/A.ceylon").call();
    Assert.assertEquals(Boolean.TRUE, result);
    // Compile module A/2
    result = getCompilerTask(Arrays.asList("-src", getPackagePath() + "/modules/multiversion/a2"), "modules/multiversion/a2/a/module.ceylon", "modules/multiversion/a2/a/package.ceylon", "modules/multiversion/a2/a/A.ceylon").call();
    Assert.assertEquals(Boolean.TRUE, result);
    ErrorCollector collector = new ErrorCollector();
    // Compile module cImportsATwice which imports both A/1 and A/2
    result = getCompilerTask(Arrays.asList("-src", getPackagePath() + "/modules/multiversion/c"), collector, "modules/multiversion/c/cImportsATwice/module.ceylon", "modules/multiversion/c/cImportsATwice/C.ceylon").call();
    Assert.assertEquals(Boolean.FALSE, result);
    compareErrors(collector.get(Diagnostic.Kind.ERROR), new CompilerError(20, "source code imports two different versions of module 'a': version '1' and version '2'"), new CompilerError(22, "duplicate module import: 'a'"));
}
Also used : ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError) Test(org.junit.Test)

Example 50 with CompilerError

use of org.eclipse.ceylon.compiler.java.test.CompilerError in project ceylon by eclipse.

the class BcTests method testBinaryVersionIncompatibleModule2.

// tests after we renamed module_.class to $module_.class
@Test
public void testBinaryVersionIncompatibleModule2() throws IOException {
    CompilationTask compiler = compileJava("binaryVersionOld2/$module_.java");
    Assert.assertTrue(compiler.call());
    // so now make a jar containing the java module
    File jarFolder = new File(destDir, "org/eclipse/ceylon/compiler/java/test/bc/binaryVersionOld2/1/");
    jarFolder.mkdirs();
    File jarFile = new File(jarFolder, "org.eclipse.ceylon.compiler.java.test.bc.binaryVersionOld2-1.jar");
    // now jar it up
    JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(jarFile));
    ZipEntry entry = new ZipEntry("org/eclipse/ceylon/compiler/java/test/bc/binaryVersionOld2/$module_.class");
    outputStream.putNextEntry(entry);
    File javaClass = new File(destDir, "org/eclipse/ceylon/compiler/java/test/bc/binaryVersionOld2/$module_.class");
    FileInputStream inputStream = new FileInputStream(javaClass);
    Util.copy(inputStream, outputStream);
    inputStream.close();
    outputStream.close();
    assertErrors("binaryVersion2/module", new CompilerError(21, "version '1' of module 'org.eclipse.ceylon.compiler.java.test.bc.binaryVersionOld2' was compiled by" + " an incompatible version of the compiler" + " (binary version 0.0 of module is not compatible with binary version " + Versions.JVM_BINARY_MAJOR_VERSION + "." + Versions.JVM_BINARY_MINOR_VERSION + " of this compiler)"));
}
Also used : FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream) CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError) File(java.io.File) CompilationTask(org.eclipse.ceylon.javax.tools.JavaCompiler.CompilationTask) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

CompilerError (org.eclipse.ceylon.compiler.java.test.CompilerError)55 Test (org.junit.Test)54 ErrorCollector (org.eclipse.ceylon.compiler.java.test.ErrorCollector)19 File (java.io.File)15 CeyloncTaskImpl (org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl)12 JarFile (java.util.jar.JarFile)11 ZipEntry (java.util.zip.ZipEntry)8 LinkedList (java.util.LinkedList)7 ZipFile (java.util.zip.ZipFile)5 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 JarOutputStream (java.util.jar.JarOutputStream)2 ExitState (org.eclipse.ceylon.compiler.java.launcher.Main.ExitState)2 CompilationTask (org.eclipse.ceylon.javax.tools.JavaCompiler.CompilationTask)2 Ignore (org.junit.Ignore)2 HttpServer (com.sun.net.httpserver.HttpServer)1 FileWriter (java.io.FileWriter)1 Writer (java.io.Writer)1 TreeSet (java.util.TreeSet)1 JarEntry (java.util.jar.JarEntry)1