Search in sources :

Example 1 with ErrorCollector

use of org.eclipse.ceylon.compiler.java.test.ErrorCollector 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 2 with ErrorCollector

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

the class CarGenerationTests method testCarWithServicesGreet.

/**
 * Plain module compilation
 */
@Test
public void testCarWithServicesGreet() throws IOException {
    ErrorCollector ec = new ErrorCollector();
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(getPackagePath() + "services/greet1/source");
    options.addAll(defaultOptions);
    CeyloncTaskImpl task = getCompilerTask(options, ec, Arrays.asList("services"));
    assertTrue(task.call());
    File carFile = getModuleArchive("services", "1.0");
    assertTrue(carFile.exists());
    Map<String, Set<String>> services = MetaInfServices.parseAllServices(carFile);
    Set<String> impls = services.get("services.Greeter");
    assertNotNull(impls);
    assertContains(impls, "services.HelloWorld");
    assertContains(impls, "services.Bonjour");
    assertEquals(2, impls.size());
    assertEquals(1, services.size());
}
Also used : Set(java.util.Set) ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) JarFile(java.util.jar.JarFile) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 3 with ErrorCollector

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

the class CarGenerationTests method testCarWithServicesGreetIncremental.

/**
 * Incremental compilation (adding a service implementation)
 */
@Test
public void testCarWithServicesGreetIncremental() throws IOException {
    // first compile the old version
    testCarWithServicesGreet();
    // then recompile
    ErrorCollector ec = new ErrorCollector();
    List<String> options = new LinkedList<String>(defaultOptions);
    options.add("-src");
    options.add(getPackagePath() + "services/greet2/source");
    CeyloncTaskImpl task = getCompilerTask(options, ec, "services/greet2/source/services/Gday.ceylon");
    assertTrue(task.call());
    File carFile = getModuleArchive("services", "1.0");
    assertTrue(carFile.exists());
    Map<String, Set<String>> services = MetaInfServices.parseAllServices(carFile);
    Set<String> impls = services.get("services.Greeter");
    assertNotNull(impls);
    assertContains(impls, "services.HelloWorld");
    assertContains(impls, "services.Bonjour");
    assertContains(impls, "services.Gday");
    assertEquals(3, impls.size());
    assertEquals(1, services.size());
}
Also used : Set(java.util.Set) ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) JarFile(java.util.jar.JarFile) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 4 with ErrorCollector

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

the class CarGenerationTests method testCarGeneratedManifestComesFirst.

/*
     * 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 a compiler-generated MANIFEST.MF
     */
@Test
public void testCarGeneratedManifestComesFirst() throws IOException {
    ErrorCollector ec = new ErrorCollector();
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(getPackagePath() + "meta/generatedmanifest/source");
    options.addAll(defaultOptions);
    CeyloncTaskImpl task = getCompilerTask(options, ec, Arrays.asList("test.generatedmanifest"));
    assertTrue(task.call());
    assertTrue(ec.get(Diagnostic.Kind.ERROR, Diagnostic.Kind.WARNING).isEmpty());
    File carFile = getModuleArchive("test.generatedmanifest", "1.0");
    assertTrue(carFile.exists());
    try (JarFile car = new JarFile(carFile)) {
        Manifest manifest = car.getManifest();
        assertTrue(manifest != null);
        assertEquals("test.generatedmanifest", manifest.getMainAttributes().getValue("Bundle-SymbolicName"));
        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());
    }
    // Now test incremental compilation
    task = getCompilerTask(options, ec, "meta/generatedmanifest/source/test/generatedmanifest/run.ceylon");
    assertTrue(task.call());
    assertTrue(carFile.exists());
    assertTrue(ec.get(Diagnostic.Kind.ERROR, Diagnostic.Kind.WARNING).isEmpty());
    try (JarFile car = new JarFile(carFile)) {
        Manifest manifest = car.getManifest();
        assertTrue(manifest != null);
        assertEquals("test.generatedmanifest", manifest.getMainAttributes().getValue("Bundle-SymbolicName"));
        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) 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 5 with ErrorCollector

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

the class CMRTests method testOverridesCeylonModuleVersionProducesJavaModule.

@Test
public void testOverridesCeylonModuleVersionProducesJavaModule() {
    setupBinaryModulesForOverridesCeylonModuleTests();
    ErrorCollector collector = new ErrorCollector();
    CeyloncTaskImpl compilerTask = getCompilerTask(Arrays.asList("-src", getPackagePath() + "/modules", "-overrides", getPackagePath() + "modules/overridesCeylonModule/overrides-b-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);
    assert (modulesRetriever.modules != null);
    Module b = modulesRetriever.modules.get("b");
    assert (b != null);
    assertEquals("The Ceylon module 'b' is now seen as a Java module when a version override is applied", false, b.isJava());
}
Also used : ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) Module(org.eclipse.ceylon.model.typechecker.model.Module) Test(org.junit.Test)

Aggregations

ErrorCollector (org.eclipse.ceylon.compiler.java.test.ErrorCollector)35 Test (org.junit.Test)31 CeyloncTaskImpl (org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl)23 CompilerError (org.eclipse.ceylon.compiler.java.test.CompilerError)19 File (java.io.File)16 JarFile (java.util.jar.JarFile)12 LinkedList (java.util.LinkedList)11 ZipEntry (java.util.zip.ZipEntry)7 ArrayList (java.util.ArrayList)4 ExitState (org.eclipse.ceylon.compiler.java.launcher.Main.ExitState)4 Set (java.util.Set)3 ZipFile (java.util.zip.ZipFile)3 CeyloncFileManager (org.eclipse.ceylon.compiler.java.tools.CeyloncFileManager)3 CeyloncTool (org.eclipse.ceylon.compiler.java.tools.CeyloncTool)3 Module (org.eclipse.ceylon.model.typechecker.model.Module)3 Ignore (org.junit.Ignore)3 JarEntry (java.util.jar.JarEntry)2 Manifest (java.util.jar.Manifest)2 StringWriter (java.io.StringWriter)1 TreeSet (java.util.TreeSet)1