use of copied.org.apache.maven.plugin.CompilationFailureException in project tycho by eclipse.
the class OsgiCompilerTest method testWarningAndErrorMessages.
public void testWarningAndErrorMessages() throws Exception {
File basedir = getBasedir("projects/compilermessages");
List<MavenProject> projects = getSortedProjects(basedir, null);
MavenProject project = projects.get(0);
AbstractOsgiCompilerMojo mojo = getMojo(projects, project);
final List<CharSequence> warnings = new ArrayList<>();
mojo.setLog(new SystemStreamLog() {
@Override
public void warn(CharSequence content) {
warnings.add(content);
}
});
try {
mojo.execute();
fail("compilation failure expected");
} catch (CompilationFailureException e) {
String message = e.getLongMessage();
assertThat(message, containsString("3 problems (1 error, 2 warnings)"));
// 1 error
assertThat(message, containsString("Test.java:[23"));
assertThat(message, containsString("System.foo();"));
}
// 2 warnings
List<String> expectedWarnings = asList(//
"Test.java:[19", "Test.java:[21");
assertEquals(expectedWarnings.size(), warnings.size());
for (int i = 0; i < warnings.size(); i++) {
String warning = (String) warnings.get(i);
String expectedWarning = expectedWarnings.get(i);
assertThat(warning, containsString(expectedWarning));
}
}
use of copied.org.apache.maven.plugin.CompilationFailureException in project tycho by eclipse.
the class OsgiCompilerTest method testCompilerArgs.
public void testCompilerArgs() throws Exception {
File basedir = getBasedir("projects/compiler-args");
List<MavenProject> projects = getSortedProjects(basedir, null);
MavenProject project = projects.get(0);
AbstractOsgiCompilerMojo mojo = getMojo(projects, project);
final List<CharSequence> warnings = new ArrayList<>();
mojo.setLog(new SystemStreamLog() {
@Override
public void warn(CharSequence content) {
warnings.add(content);
}
});
try {
mojo.execute();
fail("compilation failure expected");
} catch (CompilationFailureException e) {
String message = e.getLongMessage();
assertThat(message, containsString("2 problems (1 error, 1 warning)"));
// 1 error
assertThat(message, containsString("unused"));
}
// 1 warning
assertThat((String) warnings.iterator().next(), containsString("is boxed"));
}
use of copied.org.apache.maven.plugin.CompilationFailureException in project tycho by eclipse.
the class OsgiCompilerTest method testExecutionEnvironment.
public void testExecutionEnvironment() throws Exception {
File basedir = getBasedir("projects/executionEnvironment");
List<MavenProject> projects = getSortedProjects(basedir, null);
MavenProject project;
// project with neither POM nor MANIFEST configuration => must fallback to
// source/target level == 1.6
project = projects.get(1);
getMojo(projects, project).execute();
assertBytecodeMajorLevel(TARGET_1_7, new File(project.getBasedir(), "target/classes/Generic.class"));
// project with multiple execution envs.
// Minimum source and target level must be taken
project = projects.get(2);
AbstractOsgiCompilerMojo mojo = getMojo(projects, project);
assertEquals("OSGi/Minimum-1.0", mojo.getExecutionEnvironment());
try {
mojo.execute();
fail("compilation failure due to assert keyword expected");
} catch (CompilationFailureException e) {
// expected
}
// project with both explicit compiler configuration in pom.xml and Bundle-RequiredExecutionEnvironment.
// explicit compiler configuration in the pom should win. see https://issues.sonatype.org/browse/TYCHO-476
project = projects.get(3);
mojo = getMojo(projects, project);
assertEquals("jsr14", mojo.getTargetLevel());
assertEquals("1.5", mojo.getSourceLevel());
assertEquals("J2SE-1.5", mojo.getExecutionEnvironment());
mojo.execute();
assertBytecodeMajorLevel(TARGET_1_4, new File(project.getBasedir(), "target/classes/Generic.class"));
// project with both explicit EE configuration in pom.xml and Bundle-RequiredExecutionEnvironment.
// explicit configuration in the pom.xml win
project = projects.get(4);
mojo = getMojo(projects, project);
assertEquals("J2SE-1.5", mojo.getExecutionEnvironment());
// project with both explicit compiler configuration in build.properties and Bundle-RequiredExecutionEnvironment.
// build.properties should win.
project = projects.get(5);
mojo = getMojo(projects, project);
assertEquals("jsr14", mojo.getTargetLevel());
assertEquals("1.5", mojo.getSourceLevel());
assertEquals("J2SE-1.5", mojo.getExecutionEnvironment());
mojo.execute();
assertBytecodeMajorLevel(TARGET_1_4, new File(project.getBasedir(), "target/classes/Generic.class"));
}
Aggregations