Java源码示例:org.apache.maven.execution.ExecutionEvent

示例1
@Test
public void testCsvEntries() throws Exception {
    ExecutionEvent mojo = mock(ExecutionEvent.class);
    when(mojo.getProject()).thenReturn(createMavenProject());
    when(mojo.getMojoExecution()).thenReturn(createMojoExecution());
    when(mojo.getType()).thenReturn(ExecutionEvent.Type.MojoStarted);
    when(mojo.getType()).thenReturn(ExecutionEvent.Type.MojoSucceeded);

    subject.onEvent(mojo);
    subject.onEvent(mojo);
    subject.onEvent(sessionEndEvent);

    assertTrue(testFile.exists());
    List<String> lines = FileUtils.loadFile(testFile);
    assertEquals("\"Module\";\"Mojo\";\"Time\"", lines.get(0));

    String[] split = lines.get(1).split(";");

    assertEquals(3, split.length);
    assertEquals("\"maven-project-artifact\"", split[0]);
    assertEquals("\"plugin:goal (executionId)\"", split[1]);
    assertTrue(Pattern.matches("\"\\d+\\.\\d+\"", split[2]));

}
 
示例2
public void performReport(Logger logger, ExecutionEvent event, SessionTimer session) {
    if (Boolean.parseBoolean(MavenHelper.getExecutionProperty(event, Constants.BUILDTIME_OUTPUT_CSV_PROPERTY, "false"))) {
        File file = getOutputFile(event);
        if (file != null) {
            PrintWriter printWriter = null;
            try {
                printWriter = new PrintWriter(file);
                writeTo(session, printWriter);
            } catch (FileNotFoundException e) {
                logger.error("Could not write report", e);
            } finally {
                if (printWriter != null) {
                    printWriter.close();
                }
            }
        }
    }
}
 
示例3
@Override
protected void addDetails(@Nonnull ExecutionEvent executionEvent, @Nonnull Xpp3Dom root) {
    super.addDetails(executionEvent, root);
    MavenProject parentProject = executionEvent.getProject().getParent();
    if (parentProject == null) {
        // nothing to do
    } else {
        Xpp3Dom parentProjectElt = new Xpp3Dom("parentProject");
        root.addChild(parentProjectElt);
        parentProjectElt.setAttribute("name", parentProject.getName());
        parentProjectElt.setAttribute("groupId", parentProject.getGroupId());

        parentProjectElt.setAttribute("artifactId", parentProject.getArtifactId());
        parentProjectElt.setAttribute("version", parentProject.getVersion());
    }
}
 
示例4
private ExecutionEventObject createEndForStart(ExecutionEventObject start) {
    ExecutionEventObject toRet;
    if (start instanceof ExecMojo) {
        ExecMojo startEx = (ExecMojo) start;
        toRet = new ExecMojo(startEx.goal, startEx.plugin, startEx.phase, startEx.executionId, ExecutionEvent.Type.MojoFailed);
    } else if (start instanceof ExecProject) {
        ExecProject startPrj = (ExecProject) start;
        toRet = new ExecProject(startPrj.gav, startPrj.currentProjectLocation, ExecutionEvent.Type.ProjectFailed);
    } else if (start instanceof ExecSession) {
        ExecSession ss = (ExecSession) start;
        toRet = new ExecSession(ss.projectCount, ExecutionEvent.Type.SessionEnded);
    } else {
        ExecutionEvent.Type endType;
        if (start.type.equals(ExecutionEvent.Type.ForkStarted)) {
            endType = ExecutionEvent.Type.ForkFailed;
        } else if (start.type.equals(ExecutionEvent.Type.ForkedProjectStarted)) {
            endType = ExecutionEvent.Type.ForkedProjectFailed;
        } else {
            throw new RuntimeException("unknown event type: " + start.type);
        }
        toRet = new ExecutionEventObject(endType);
    }
    return toRet;
}
 
示例5
@Override
protected void addDetails(@Nonnull ExecutionEvent executionEvent, @Nonnull Xpp3Dom root) {
    super.addDetails(executionEvent, root);
    ArtifactRepository artifactRepository = executionEvent.getProject().getDistributionManagementArtifactRepository();
    Xpp3Dom artifactRepositoryElt = new Xpp3Dom("artifactRepository");
    root.addChild(artifactRepositoryElt);
    if (artifactRepository == null) {

    } else {
        Xpp3Dom idElt = new Xpp3Dom("id");
        idElt.setValue(artifactRepository.getId());
        artifactRepositoryElt.addChild(idElt);

        Xpp3Dom urlElt = new Xpp3Dom("url");
        urlElt.setValue(artifactRepository.getUrl());
        artifactRepositoryElt.addChild(urlElt);
    }

}
 
示例6
public void mojoSucceeded(ExecutionEvent event) {
    final MojoExecution execution = event.getMojoExecution();
    next.mojoSucceeded(event);
    if (execution.getGoal().equals(COMPILE_GOAL)) {
        collectConfig(event.getProject(), event.getSession());
    }
}
 
示例7
@Override
public void projectSucceeded(ExecutionEvent executionEvent) {
    if (delegate != null) {
        delegate.projectSucceeded(executionEvent);
    }
    // Cleanup
    request.setExecutionListener(delegate);
}
 
示例8
@Override
public void projectFailed(ExecutionEvent executionEvent) {
    if (delegate != null) {
        delegate.projectFailed(executionEvent);
    }
    // Cleanup
    request.setExecutionListener(delegate);
}
 
示例9
@Override
public void mojoSucceeded(ExecutionEvent executionEvent) {
    // Unlike mojoStarted, this callback has the lifecycle phase set.
    MojoExecution execution = executionEvent.getMojoExecution();
    addExecutionIfNotContainedAlready(execution);
    if (delegate != null) {
        delegate.mojoSucceeded(executionEvent);
    }
}
 
示例10
@Before
public void setUp() throws Exception {
    logReporter = new LogReporter();
    csvReporter = new CsvReporter();
    existingProjects = new ConcurrentHashMap<String, ProjectTimer>();
    SystemClock mockClock = mock(SystemClock.class);
    when(mockClock.currentTimeMillis())
            .thenReturn(100L)
            .thenReturn(200L);

    sessionTimer = new SessionTimer(existingProjects, mockClock);

    mojoTiming = new ConcurrentHashMap<String, MojoTimer>();
    anotherMojoTiming = new ConcurrentHashMap<String, MojoTimer>();
    oneProject = new ProjectTimer("one", mojoTiming, mockClock);
    anotherProject = new ProjectTimer("two", anotherMojoTiming, mockClock);
    mojoExecution = createMojoExecution();
    project = createMavenProject();
    outputStream = new ByteArrayOutputStream();
    printWriter = new PrintWriter(outputStream);

    userProperties.setProperty(Constants.BUILDTIME_OUTPUT_LOG_PROPERTY, "true");
    when(sessionEndEvent.getSession()).thenReturn(session);
    when(session.getSystemProperties()).thenReturn(systemProperties);
    when(session.getUserProperties()).thenReturn(userProperties);
    when(sessionEndEvent.getType()).thenReturn(ExecutionEvent.Type.SessionEnded);
}
 
示例11
ResumeFromFinder createResumeFromFinder() {
    if (contextImpl == null) {
        if (firstFailure != null) {
            return new FindByName(firstFailure);
        }
        return null;
    }
    for (ExecutionEventObject.Tree prj : executionTree.getChildrenNodes()) {
        if (prj.getEndEvent() != null && ExecutionEvent.Type.ProjectFailed.equals(prj.getEndEvent().type)) {
                //our first failure
            return new FindByEvents( (ExecProject) prj.getStartEvent());
        }
    }
    return null;
}
 
示例12
private void checkProgress(ExecutionEventObject eeo) {
    if (ExecutionEvent.Type.ProjectDiscoveryStarted.equals(eeo.type)) {
        handle.switchToIndeterminate();
    } else if (ExecutionEvent.Type.SessionStarted.equals(eeo.type)) {
        reactorSize = ((ExecSession)eeo).projectCount + 1;
        projectCount = 0;
        handle.switchToDeterminate(reactorSize);
    } else if (ExecutionEvent.Type.ProjectStarted.equals(eeo.type)) {
        handle.progress(((ExecProject)eeo).gav.artifactId, Math.min(++projectCount, reactorSize));
    } else if (ExecutionEvent.Type.ProjectSkipped.equals(eeo.type)) {
        handle.progress(((ExecProject)eeo).gav.artifactId + " " + ((ExecProject)eeo).gav.version, Math.min(++projectCount, reactorSize));
    } else if (ExecutionEvent.Type.SessionEnded.equals(eeo.type)) {
        
    }
}
 
示例13
private Children createChildren(final List<ExecutionEventObject.Tree> childrenNodes) {
    if (childrenNodes.isEmpty()) {
        return Children.LEAF;
    }
    return Children.create(new ChildFactory<ExecutionEventObject.Tree>() {
        @Override
        protected boolean createKeys(List<ExecutionEventObject.Tree> toPopulate) {
            if (showOnlyErrors) {
                for (ExecutionEventObject.Tree item : childrenNodes) {
                    ExecutionEventObject end = item.getEndEvent();
                    if (end != null) {
                        if (
                            ExecutionEvent.Type.ProjectFailed.equals(end.type) || 
                            ExecutionEvent.Type.MojoFailed.equals(end.type) ||
                            ExecutionEvent.Type.ForkedProjectFailed.equals(end.type) ||    
                            ExecutionEvent.Type.ForkFailed.equals(end.type))
                        {
                            toPopulate.add(item);
                        }
                    }
                }
            } else {
                toPopulate.addAll(childrenNodes);
            }

            return true;
        }
        
        @Override
        protected Node createNodeForKey(ExecutionEventObject.Tree key) {
            return createNodeForExecutionEventTree(key);
        }
        
    }, false);
}
 
示例14
private Node createPhaseNode(Pair<String, List<ExecutionEventObject.Tree>> key) {
    Children childs;
    if (showOnlyErrors) {
        boolean atLeastOne = false;
        for (ExecutionEventObject.Tree ch : key.second()) {
            ExecutionEventObject end = ch.getEndEvent();
            if (end != null) {
                if (ExecutionEvent.Type.ProjectFailed.equals(end.type)
                        || ExecutionEvent.Type.MojoFailed.equals(end.type)
                        || ExecutionEvent.Type.ForkedProjectFailed.equals(end.type)
                        || ExecutionEvent.Type.ForkFailed.equals(end.type)) {
                    atLeastOne = true;
                    break;
                }
            }
        }
        if (atLeastOne) {
            childs = createChildren(key.second());
        } else {
            childs = Children.LEAF;
        }
    } else {
        childs = createChildren(key.second());
    }
    AbstractNode nd = new AbstractNode(childs, Lookup.EMPTY);
    nd.setName(key.first());
    nd.setDisplayName(key.first());
    nd.setIconBaseWithExtension(ICON_PHASE);
    return nd;
}
 
示例15
@Override
public Image getIcon(int type) {
    Image img =  super.getIcon(type);
    if (ExecutionEvent.Type.ProjectFailed.equals(end.type)) {
        Image ann = ImageUtilities.loadImage(ERROR_ICON); //NOI18N
//        ann = ImageUtilities.addToolTipToImage(ann, "Project build failed");
        return ImageUtilities.mergeImages(img, ann, 8, 0);//NOI18N
    }
    return img;
}
 
示例16
public ExecMojo(String goal, GAV plugin, String phase, String executionId, ExecutionEvent.Type type) {
    super(type);
    this.goal = goal;
    this.plugin = plugin;
    this.phase = phase;
    this.executionId = executionId;
}
 
示例17
public static ExecutionEventObject create(JSONObject obj) {
    String s = (String) obj.get("type");
    ExecutionEvent.Type t = ExecutionEvent.Type.valueOf(s);
    if (mojo_types.contains(t)) {
        return ExecMojo.create(obj, t);
    }
    if (project_types.contains(t)) {
        return ExecProject.create(obj, t);
    }
    if (session_types.contains(t)) {
        return ExecSession.create(obj, t);
    }
    return new ExecutionEventObject(t);
}
 
示例18
@Before
public void setUp() throws IOException {
    subject = new BuildTimeEventSpy(logger, new LogReporter(), new CsvReporter());

    testFile = new File(temporaryFolder.getRoot(), "test.csv");
    userProperties.setProperty(Constants.BUILDTIME_OUTPUT_CSV_FILE_PROPERTY,
            testFile.getAbsolutePath());
    userProperties.setProperty(Constants.BUILDTIME_OUTPUT_CSV_PROPERTY, "true");

    when(sessionEndEvent.getSession()).thenReturn(session);
    when(session.getSystemProperties()).thenReturn(systemProperties);
    when(session.getUserProperties()).thenReturn(userProperties);
    when(sessionEndEvent.getType()).thenReturn(ExecutionEvent.Type.SessionEnded);
}
 
示例19
@Test
public void testExecutionProjectStarted() throws Exception {
    ExecutionEvent executionEvent = new  ExecutionEvent(){
        @Override
        public Type getType() {
            return Type.ProjectStarted;
        }

        @Override
        public MavenSession getSession() {
            return null;
        }

        @Override
        public MavenProject getProject() {
            return project;
        }

        @Override
        public MojoExecution getMojoExecution() {
            return null;
        }

        @Override
        public Exception getException() {
            return null;
        }
    };

    spy.onEvent(executionEvent);

    String actual = writer.toString();
    System.out.println(actual);
    Assert.assertThat(actual, CoreMatchers.containsString("ProjectStarted"));
    Assert.assertThat(actual, CoreMatchers.containsString("petclinic"));
}
 
示例20
@Override
public void mojoSucceeded(ExecutionEvent executionEvent) {
    // Unlike mojoStarted, this callback has the lifecycle phase set.
    MojoExecution execution = executionEvent.getMojoExecution();
    addExecutionIfNotContainedAlready(execution);
    if (delegate != null) {
        delegate.mojoSucceeded(executionEvent);
    }
}
 
示例21
public boolean handle(@Nonnull Object event) {
    if (!(event instanceof ExecutionEvent)) {
        return false;
    }
    ExecutionEvent executionEvent = (ExecutionEvent) event;
    ExecutionEvent.Type supportedType = getSupportedType();

    if (supportedType != null && !(supportedType.equals(executionEvent.getType()))) {
        return false;
    }

    String supportedGoal = getSupportedPluginGoal();
    if (supportedGoal == null) {
        return _handle(executionEvent);
    } else {
        String[] gag = supportedGoal.split(":");
        if (gag.length == 3) {
            MojoExecution execution = executionEvent.getMojoExecution();
            if (execution.getGroupId().equals(gag[0]) && execution.getArtifactId().equals(gag[1]) && execution.getGoal().equals(gag[2])) {
                _handle(executionEvent);
                return true;
            } else {
                return false;
            }
        } else {
            reporter.print(toString() + " - unsupported supportedPluginGoal:" + supportedGoal);
            return false;
        }
    }

}
 
示例22
public void projectDiscoveryStarted(ExecutionEvent event) {
    next.projectDiscoveryStarted(event);
}
 
示例23
public void sessionStarted(ExecutionEvent event) {
    next.sessionStarted(event);
}
 
示例24
public void sessionEnded(ExecutionEvent event) {
    next.sessionEnded(event);
}
 
示例25
public void projectSkipped(ExecutionEvent event) {
    next.projectSkipped(event);
}
 
示例26
@Override
protected List<String> getConfigurationParametersToReport(ExecutionEvent executionEvent) {
    return Collections.emptyList();
}
 
示例27
public void projectSucceeded(ExecutionEvent event) {
    next.projectSucceeded(event);
}
 
示例28
public void projectFailed(ExecutionEvent event) {
    next.projectFailed(event);
}
 
示例29
public void mojoSkipped(ExecutionEvent event) {
    next.mojoSkipped(event);
}
 
示例30
public void mojoStarted(ExecutionEvent event) {
    next.mojoStarted(event);
}