use of org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo in project tycho by eclipse.
the class OsgiCompilerTest method testUseProjectSettingsSetToTrue.
public void testUseProjectSettingsSetToTrue() throws Exception {
// the code in the project does use boxing and the settings file
// turns on warning for auto boxing so we expect here a warning
File basedir = getBasedir("projects/projectSettings/p001");
List<MavenProject> projects = getSortedProjects(basedir, null);
MavenProject project = projects.get(0);
AbstractOsgiCompilerMojo mojo = getMojo(projects, project);
setVariableValueToObject(mojo, "useProjectSettings", Boolean.TRUE);
final List<CharSequence> warnings = new ArrayList<>();
mojo.setLog(new SystemStreamLog() {
@Override
public void warn(CharSequence content) {
warnings.add(content);
}
});
mojo.execute();
assertThat((String) warnings.iterator().next(), containsString("is boxed"));
}
use of org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo 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"));
}
use of org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo in project tycho by eclipse.
the class OsgiCompilerTest method testAccessRulesClasspath.
public void testAccessRulesClasspath() throws Exception {
File basedir = getBasedir("projects/accessrules");
List<MavenProject> projects = getSortedProjects(basedir, null);
getMojo(projects, projects.get(1)).execute();
getMojo(projects, projects.get(2)).execute();
getMojo(projects, projects.get(3)).execute();
MavenProject project = projects.get(4);
AbstractOsgiCompilerMojo mojo = getMojo(projects, project);
List<String> cp = mojo.getClasspathElements();
assertEquals(4, cp.size());
assertEquals(getClasspathElement(project.getBasedir(), "target/classes", ""), cp.get(0));
assertEquals(getClasspathElement(new File(getBasedir()), "target/projects/accessrules/p001/target/classes", "[+p001/*:?**/*]"), cp.get(1));
// note that PDE sorts dependencies coming via imported-package by symbolicName_version
assertEquals(getClasspathElement(new File(getBasedir()), "target/projects/accessrules/p003/target/classes", "[+p003/*:?**/*]"), cp.get(2));
assertEquals(getClasspathElement(new File(getBasedir()), "target/projects/accessrules/p004/target/classes", "[+p004/*:?**/*]"), cp.get(3));
}
use of org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo in project tycho by eclipse.
the class OsgiCompilerTest method testClasspath.
public void testClasspath() throws Exception {
File basedir = getBasedir("projects/classpath");
List<MavenProject> projects = getSortedProjects(basedir, new File(getBasedir(), "src/test/resources/projects/classpath/platform"));
MavenProject project;
List<String> cp;
// simple project
project = projects.get(1);
AbstractOsgiCompilerMojo mojo = getMojo(projects, project);
cp = mojo.getClasspathElements();
assertEquals(1, cp.size());
assertEquals(getClasspathElement(project.getBasedir(), "target/classes", ""), cp.get(0));
// project with nested lib
project = projects.get(2);
mojo = getMojo(projects, project);
cp = mojo.getClasspathElements();
assertEquals(2, cp.size());
assertEquals(getClasspathElement(project.getBasedir(), "target/classes", ""), cp.get(0));
assertEquals(getClasspathElement(project.getBasedir(), "lib/lib.jar", ""), cp.get(1));
// project with external dependency with nested jar
project = projects.get(3);
mojo = getMojo(projects, project);
cp = mojo.getClasspathElements();
assertEquals(3, cp.size());
final String plainJarPath = "src/test/resources/projects/classpath/platform/plugins/p003_0.0.1.jar";
final String nestedJarPath = "target/local-repo/.cache/tycho/p003_0.0.1.jar/lib/lib.jar";
assertEquals(getClasspathElement(project.getBasedir(), "target/classes", ""), cp.get(0));
assertEquals(getClasspathElement(new File(getBasedir()), plainJarPath, "[?**/*]"), cp.get(1));
assertEquals(getClasspathElement(new File(getBasedir()), nestedJarPath, "[?**/*]"), cp.get(2));
// project with a (not yet) existing nested jar that would be copied later during build
// (wrapper scenario with copy-pom-dependencies)
project = projects.get(4);
mojo = getMojo(projects, project);
mojo.execute();
cp = mojo.getClasspathElements();
assertEquals(3, cp.size());
assertEquals(getClasspathElement(project.getBasedir(), "target/classes", ""), cp.get(0));
assertEquals(getClasspathElement(project.getBasedir(), "lib/not_existing_yet.jar", ""), cp.get(1));
assertEquals(getClasspathElement(project.getBasedir(), "lib/not_existing_yet_dir/", ""), cp.get(2));
}
use of org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo in project tycho by eclipse.
the class OsgiCompilerTest method test_TYCHO0400indirectDependencies.
public void test_TYCHO0400indirectDependencies() throws Exception {
File basedir = getBasedir("projects/indirectDependencies");
List<MavenProject> projects = getSortedProjects(basedir, null);
assertEquals("C", projects.get(1).getArtifactId());
getMojo(projects, projects.get(1)).execute();
assertEquals("B", projects.get(2).getArtifactId());
getMojo(projects, projects.get(2)).execute();
assertEquals("A", projects.get(3).getArtifactId());
AbstractOsgiCompilerMojo mojo = getMojo(projects, projects.get(3));
List<String> cp = mojo.getClasspathElements();
assertEquals(getClasspathElement(projects.get(1).getBasedir(), "target/classes", "[?**/*]"), cp.get(2));
mojo.execute();
assertTrue(new File(projects.get(3).getBasedir(), "target/classes/a/A.class").canRead());
}
Aggregations