Search in sources :

Example 1 with CompilerError

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

the class BcTests method testBinaryVersionIncompatibleModule1.

// tests before we renamed module_.class to $module_.class
@Test
public void testBinaryVersionIncompatibleModule1() throws IOException {
    CompilationTask compiler = compileJava("binaryVersionOld/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/binaryVersionOld/1/");
    jarFolder.mkdirs();
    File jarFile = new File(jarFolder, "org.eclipse.ceylon.compiler.java.test.bc.binaryVersionOld-1.jar");
    // now jar it up
    JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(jarFile));
    ZipEntry entry = new ZipEntry("org/eclipse/ceylon/compiler/java/test/bc/binaryVersionOld/module_.class");
    outputStream.putNextEntry(entry);
    File javaClass = new File(destDir, "org/eclipse/ceylon/compiler/java/test/bc/binaryVersionOld/module_.class");
    FileInputStream inputStream = new FileInputStream(javaClass);
    Util.copy(inputStream, outputStream);
    inputStream.close();
    outputStream.close();
    assertErrors("binaryVersion/module", new CompilerError(21, "version '1' of module 'org.eclipse.ceylon.compiler.java.test.bc.binaryVersionOld' 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)

Example 2 with CompilerError

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

the class BcTests method testBinaryVersionIncompatible.

@Test
public void testBinaryVersionIncompatible() {
    compile("JavaOldVersion.java");
    assertErrors("CeylonNewVersion", new CompilerError(-1, "Ceylon class org.eclipse.ceylon.compiler.java.test.bc.JavaOldVersion was compiled by an incompatible version of the Ceylon compiler\n  The class was compiled using 0.0.\n  This compiler supports " + Versions.JVM_BINARY_MAJOR_VERSION + "." + Versions.JVM_BINARY_MINOR_VERSION + ".\n  Please try to recompile your module using a compatible compiler.\n  Binary compatibility will only be supported after Ceylon 1.2."));
}
Also used : CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError) Test(org.junit.Test)

Example 3 with CompilerError

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

the class CarGenerationTests method testCarMergedManifestComesFirst.

/*
     * Although not in the JAR specification, there are tools and APIs
     * which rely on the MANIFEST.MF being the first file entry in a Jar file.
     * 
     * Test for the case of an existing MANIFEST.MF in resources
     */
@Test
public void testCarMergedManifestComesFirst() throws IOException {
    ErrorCollector ec = new ErrorCollector();
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(getPackagePath() + "meta/mergedmanifest/source");
    options.add("-res");
    options.add(getPackagePath() + "meta/mergedmanifest/resource");
    options.addAll(defaultOptions);
    CeyloncTaskImpl task = getCompilerTask(options, ec, Arrays.asList("test.mergedmanifest"));
    assertTrue(task.call());
    File carFile = getModuleArchive("test.mergedmanifest", "1.0");
    assertTrue(carFile.exists());
    assertTrue(ec.get(Diagnostic.Kind.ERROR).isEmpty());
    // When the compiler value overrides a user value, we expect a warning
    assertTrue(ec.get(Diagnostic.Kind.WARNING).size() == 1);
    assertTrue(ec.get(Diagnostic.Kind.WARNING).iterator().next().equals(new CompilerError(Diagnostic.Kind.WARNING, null, -1, "manifest attribute provided by compiler: ignoring value from 'Bundle-ActivationPolicy' for module 'test.mergedmanifest'")));
    try (JarFile car = new JarFile(carFile)) {
        Manifest manifest = car.getManifest();
        manifest.write(System.err);
        assertTrue(manifest != null);
        assertEquals("test.mergedmanifest", manifest.getMainAttributes().getValue("Bundle-SymbolicName"));
        assertEquals("Baz", manifest.getMainAttributes().getValue("Foo-Bar"));
        assertEquals("whatever", manifest.getMainAttributes().getValue("LastLineWithoutNewline"));
        Enumeration<JarEntry> entries = car.entries();
        assertTrue(entries.hasMoreElements());
        JarEntry entry = entries.nextElement();
        assertEquals("META-INF/", entry.getName());
        assertTrue(entry.isDirectory());
        entry = entries.nextElement();
        assertEquals("META-INF/MANIFEST.MF", entry.getName());
        assertTrue(!entry.isDirectory());
    }
}
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) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 4 with CompilerError

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

the class CMRHTTPTests method testMdlHTTPForbidden.

@Test
public void testMdlHTTPForbidden() throws IOException {
    File repo = makeRepo();
    final int port = allocPortForTest();
    final String repoAURL = getRepoUrl(port);
    HttpServer server = startServer(port, repo, true, null, HttpError.FORBIDDEN);
    try {
        // then try to compile our module by outputting to HTTP
        assertErrors("modules/single/module", Arrays.asList("-out", repoAURL), null, new CompilerError(-1, "Failed to write module to repository: authentication failed on repository " + repoAURL));
    } finally {
        server.stop(1);
    }
}
Also used : HttpServer(com.sun.net.httpserver.HttpServer) CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Example 5 with CompilerError

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

the class CMRTests method testMdlMultipleVersionsOnSameCompilation.

@Test
public void testMdlMultipleVersionsOnSameCompilation() {
    // 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);
    ErrorCollector collector = new ErrorCollector();
    // Compile module A/2 with B importing A/1
    result = getCompilerTask(Arrays.asList("-src", getPackagePath() + "/modules/multiversion/a2" + File.pathSeparator + getPackagePath() + "/modules/multiversion/b"), collector, "modules/multiversion/a2/a/module.ceylon", "modules/multiversion/a2/a/package.ceylon", "modules/multiversion/a2/a/A.ceylon", "modules/multiversion/b/b/module.ceylon", "modules/multiversion/b/b/B.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'"));
}
Also used : ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError) 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