Search in sources :

Example 1 with AbstractLogger

use of org.codehaus.plexus.logging.AbstractLogger in project tycho by eclipse.

the class IncludeValidationHelperTest method testWarning.

@Test
public void testWarning() throws Exception {
    final List<String> warnings = new ArrayList<>();
    Logger log = new AbstractLogger(Logger.LEVEL_DEBUG, null) {

        @Override
        public void warn(String message, Throwable throwable) {
            warnings.add(message);
        }

        @Override
        public void info(String message, Throwable throwable) {
            Assert.fail();
        }

        @Override
        public Logger getChildLogger(String name) {
            return null;
        }

        @Override
        public void fatalError(String message, Throwable throwable) {
            Assert.fail();
        }

        @Override
        public void error(String message, Throwable throwable) {
            Assert.fail();
        }

        @Override
        public void debug(String message, Throwable throwable) {
            Assert.fail();
        }
    };
    IncludeValidationHelper subject = new IncludeValidationHelper(log);
    BuildPropertiesImpl buildProperties = createBuildProperties("src.includes", "foo3, bar3*,**/*.me");
    MavenProject project = createMockProject();
    subject.checkSourceIncludesExist(project, buildProperties, false);
    Assert.assertEquals(1, warnings.size());
    Assert.assertEquals(new File(project.getBasedir(), "build.properties").getAbsolutePath() + ": src.includes value(s) [foo3, bar3*] do not match any files.", warnings.get(0));
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) AbstractLogger(org.codehaus.plexus.logging.AbstractLogger) Logger(org.codehaus.plexus.logging.Logger) BuildPropertiesImpl(org.eclipse.tycho.core.shared.BuildPropertiesImpl) File(java.io.File) AbstractLogger(org.codehaus.plexus.logging.AbstractLogger) Test(org.junit.Test)

Example 2 with AbstractLogger

use of org.codehaus.plexus.logging.AbstractLogger in project build-info by JFrogDev.

the class BuildInfoRecorderLifecycleParticipantTest method testParticipantImplementation.

public void testParticipantImplementation() throws Exception {
    BuildInfoRecorder buildInfoRecorder = new BuildInfoRecorder();
    BuildInfoRecorderLifecycleParticipant participant = new BuildInfoRecorderLifecycleParticipant();
    Class<BuildInfoRecorderLifecycleParticipant> participantClass = BuildInfoRecorderLifecycleParticipant.class;
    Field recorderField = participantClass.getDeclaredField("recorder");
    recorderField.set(participant, buildInfoRecorder);
    Field loggerField = participantClass.getDeclaredField("logger");
    loggerField.setAccessible(true);
    loggerField.set(participant, new AbstractLogger(1, "dummy") {

        public void debug(String message, Throwable throwable) {
            Assert.assertTrue(message.contains("value is true"));
        }

        public void info(String message, Throwable throwable) {
            assert false;
        }

        public void warn(String message, Throwable throwable) {
            assert false;
        }

        public void error(String message, Throwable throwable) {
            assert false;
        }

        public void fatalError(String message, Throwable throwable) {
            assert false;
        }

        public Logger getChildLogger(String name) {
            assert false;
            return null;
        }
    });
    PlexusContainer plexusContainerMock = EasyMock.createMock(PlexusContainer.class);
    RepositorySystemSession repositorySystemSession = EasyMock.createMock(RepositorySystemSession.class);
    MavenExecutionRequest requestMock = EasyMock.createMock(MavenExecutionRequest.class);
    Properties mockSessionProperties = new Properties();
    mockSessionProperties.setProperty(BuildInfoConfigProperties.ACTIVATE_RECORDER, "true");
    EasyMock.expect(requestMock.getSystemProperties()).andReturn(mockSessionProperties).once();
    EasyMock.expect(requestMock.getUserProperties()).andReturn(mockSessionProperties).once();
    AbstractExecutionListener existingListener = new AbstractExecutionListener();
    EasyMock.expect(requestMock.getExecutionListener()).andReturn(existingListener).times(1);
    EasyMock.expect(requestMock.getUserSettingsFile()).andReturn(null).once();
    EasyMock.expect(requestMock.setExecutionListener(buildInfoRecorder)).andReturn(null).once();
    EasyMock.replay(requestMock);
    MavenExecutionResult resultMock = EasyMock.createMock(MavenExecutionResult.class);
    MavenSession session = new MavenSession(plexusContainerMock, repositorySystemSession, requestMock, resultMock);
    // value is true
    participant.afterProjectsRead(session);
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) PlexusContainer(org.codehaus.plexus.PlexusContainer) AbstractExecutionListener(org.apache.maven.execution.AbstractExecutionListener) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) AbstractLogger(org.codehaus.plexus.logging.AbstractLogger) Logger(org.codehaus.plexus.logging.Logger) BuildInfoConfigProperties(org.jfrog.build.api.BuildInfoConfigProperties) Properties(java.util.Properties) Field(java.lang.reflect.Field) MavenSession(org.apache.maven.execution.MavenSession) AbstractLogger(org.codehaus.plexus.logging.AbstractLogger)

Aggregations

AbstractLogger (org.codehaus.plexus.logging.AbstractLogger)2 Logger (org.codehaus.plexus.logging.Logger)2 File (java.io.File)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 AbstractExecutionListener (org.apache.maven.execution.AbstractExecutionListener)1 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)1 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)1 MavenSession (org.apache.maven.execution.MavenSession)1 MavenProject (org.apache.maven.project.MavenProject)1 PlexusContainer (org.codehaus.plexus.PlexusContainer)1 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)1 BuildPropertiesImpl (org.eclipse.tycho.core.shared.BuildPropertiesImpl)1 BuildInfoConfigProperties (org.jfrog.build.api.BuildInfoConfigProperties)1 Test (org.junit.Test)1