Search in sources :

Example 6 with CeyloncTaskImpl

use of org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl 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 7 with CeyloncTaskImpl

use of org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl 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 8 with CeyloncTaskImpl

use of org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon by eclipse.

the class CarGenerationTests method testCarResourceSimple.

@Test
public void testCarResourceSimple() throws IOException {
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(getPackagePath() + "resmodules/simple/source");
    options.add("-res");
    options.add(getPackagePath() + "resmodules/simple/resource");
    options.addAll(defaultOptions);
    CeyloncTaskImpl task = getCompilerTask(options, null, Arrays.asList("test.simple"));
    Boolean ret = task.call();
    assertTrue(ret);
    File carFile = getModuleArchive("test.simple", "1.0");
    assertTrue(carFile.exists());
    JarFile car = new JarFile(carFile);
    ZipEntry moduleClass = car.getEntry("test/simple/README.txt");
    assertNotNull(moduleClass);
    moduleClass = car.getEntry("test/simple/subdir/SUBDIR.txt");
    assertNotNull(moduleClass);
    moduleClass = car.getEntry("test/simple/$module_.class");
    assertNotNull(moduleClass);
    car.close();
}
Also used : ZipEntry(java.util.zip.ZipEntry) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 9 with CeyloncTaskImpl

use of org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon by eclipse.

the class CarGenerationTests method testCarResourceDefault.

@Test
public void testCarResourceDefault() throws IOException {
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(getPackagePath() + "resmodules/default/source");
    options.add("-res");
    options.add(getPackagePath() + "resmodules/default/resource");
    options.addAll(defaultOptions);
    CeyloncTaskImpl task = getCompilerTask(options, "resmodules/default/resource/README.txt", "resmodules/default/resource/subdir/SUBDIR.txt");
    Boolean ret = task.call();
    assertTrue(ret);
    File carFile = getModuleArchive("default", null);
    assertTrue(carFile.exists());
    JarFile car = new JarFile(carFile);
    ZipEntry moduleClass = car.getEntry("README.txt");
    assertNotNull(moduleClass);
    moduleClass = car.getEntry("subdir/SUBDIR.txt");
    assertNotNull(moduleClass);
    car.close();
}
Also used : ZipEntry(java.util.zip.ZipEntry) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 10 with CeyloncTaskImpl

use of org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon by eclipse.

the class CarGenerationTests method testCarResourceAlternativeRoot.

@Test
public void testCarResourceAlternativeRoot() throws IOException {
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(getPackagePath() + "resmodules/altrootdir/source");
    options.add("-res");
    options.add(getPackagePath() + "resmodules/altrootdir/resource");
    options.add("-resroot");
    options.add("ALTROOT");
    options.addAll(defaultOptions);
    CeyloncTaskImpl task = getCompilerTask(options, null, Arrays.asList("test.altrootdir"));
    Boolean ret = task.call();
    assertTrue(ret);
    File carFile = getModuleArchive("test.altrootdir", "1.0");
    assertTrue(carFile.exists());
    JarFile car = new JarFile(carFile);
    ZipEntry carEntry = car.getEntry("test/altrootdir/README.txt");
    assertNotNull(carEntry);
    carEntry = car.getEntry("rootfile");
    assertNotNull(carEntry);
    carEntry = car.getEntry("test/altrootdir/$module_.class");
    assertNotNull(carEntry);
    car.close();
}
Also used : ZipEntry(java.util.zip.ZipEntry) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

CeyloncTaskImpl (org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl)62 Test (org.junit.Test)51 File (java.io.File)34 JarFile (java.util.jar.JarFile)26 LinkedList (java.util.LinkedList)23 ErrorCollector (org.eclipse.ceylon.compiler.java.test.ErrorCollector)23 ZipEntry (java.util.zip.ZipEntry)13 ZipFile (java.util.zip.ZipFile)13 CompilerError (org.eclipse.ceylon.compiler.java.test.CompilerError)12 ExitState (org.eclipse.ceylon.compiler.java.launcher.Main.ExitState)7 CeyloncTool (org.eclipse.ceylon.compiler.java.tools.CeyloncTool)6 ArrayList (java.util.ArrayList)5 CeyloncFileManager (org.eclipse.ceylon.compiler.java.tools.CeyloncFileManager)5 TaskEvent (org.eclipse.ceylon.langtools.source.util.TaskEvent)4 TaskListener (org.eclipse.ceylon.langtools.source.util.TaskListener)4 Set (java.util.Set)3 DiagnosticListener (org.eclipse.ceylon.javax.tools.DiagnosticListener)3 JCCompilationUnit (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit)3 Module (org.eclipse.ceylon.model.typechecker.model.Module)3 Ignore (org.junit.Ignore)3