Search in sources :

Example 1 with AbstractOsgiCompilerMojo

use of org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo in project tycho by eclipse.

the class OsgiCompilerTest method getMojo.

private AbstractOsgiCompilerMojo getMojo(List<MavenProject> projects, MavenProject project) throws Exception {
    AbstractOsgiCompilerMojo mojo = (AbstractOsgiCompilerMojo) lookupMojo("compile", project.getFile());
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "session", newMavenSession(project, projects));
    // setVariableValueToObject(mojo, "fork", fork? Boolean.TRUE: Boolean.FALSE);
    return mojo;
}
Also used : AbstractOsgiCompilerMojo(org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo)

Example 2 with AbstractOsgiCompilerMojo

use of org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo 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));
    }
}
Also used : SystemStreamLog(org.apache.maven.plugin.logging.SystemStreamLog) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CompilationFailureException(copied.org.apache.maven.plugin.CompilationFailureException) MavenProject(org.apache.maven.project.MavenProject) AbstractOsgiCompilerMojo(org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo) File(java.io.File)

Example 3 with AbstractOsgiCompilerMojo

use of org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo 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"));
}
Also used : SystemStreamLog(org.apache.maven.plugin.logging.SystemStreamLog) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) AbstractOsgiCompilerMojo(org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) CompilationFailureException(copied.org.apache.maven.plugin.CompilationFailureException)

Example 4 with AbstractOsgiCompilerMojo

use of org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo in project tycho by eclipse.

the class OsgiCompilerTest method testUseProjectSettingsSetToTrueWithMissingPrefsFile.

public void testUseProjectSettingsSetToTrueWithMissingPrefsFile() throws Exception {
    File basedir = getBasedir("projects/projectSettings/p002");
    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("Parameter 'useProjectSettings' is set to true, but preferences file"));
}
Also used : SystemStreamLog(org.apache.maven.plugin.logging.SystemStreamLog) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) AbstractOsgiCompilerMojo(org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo) File(java.io.File)

Example 5 with AbstractOsgiCompilerMojo

use of org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo in project tycho by eclipse.

the class OsgiCompilerTest method testUseProjectSettingsSetToFalse.

public void testUseProjectSettingsSetToFalse() throws Exception {
    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.FALSE);
    final List<CharSequence> warnings = new ArrayList<>();
    mojo.setLog(new SystemStreamLog() {

        @Override
        public void warn(CharSequence content) {
            warnings.add(content);
        }
    });
    mojo.execute();
    assertTrue(warnings.isEmpty());
}
Also used : SystemStreamLog(org.apache.maven.plugin.logging.SystemStreamLog) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) AbstractOsgiCompilerMojo(org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo) File(java.io.File)

Aggregations

AbstractOsgiCompilerMojo (org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo)10 File (java.io.File)9 MavenProject (org.apache.maven.project.MavenProject)9 ArrayList (java.util.ArrayList)5 SystemStreamLog (org.apache.maven.plugin.logging.SystemStreamLog)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 CompilationFailureException (copied.org.apache.maven.plugin.CompilationFailureException)3