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());
}
}
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());
}
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());
}
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());
}
}
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());
}
Aggregations