-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d234e20
commit a8f902f
Showing
16 changed files
with
609 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
plugin-rust-agent/src/main/java/jetbrains/buildServer/rust/logging/CargoCompileLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2000-2016 JetBrains s.r.o. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
|
||
package jetbrains.buildServer.rust.logging; | ||
|
||
import jetbrains.buildServer.agent.BuildProgressLogger; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Compiling logger. | ||
*/ | ||
public class CargoCompileLogger extends CargoDefaultLogger { | ||
private static Pattern PROJECT_NAME_PATTERN = Pattern.compile("([^\\s]+)"); | ||
private static final String COMPILATION_STARTED_FORMAT = "##teamcity[compilationStarted compiler='rustc%s']"; | ||
private static final String COMPILATION_FINISHED_FORMAT = "##teamcity[compilationFinished compiler='rustc%s']"; | ||
private static final String COMPILATION_MESSAGE_FORMAT = "##teamcity[message text='%s']"; | ||
private final BuildProgressLogger myLogger; | ||
private String myProjectName; | ||
|
||
public CargoCompileLogger(@NotNull final BuildProgressLogger logger) { | ||
super(logger); | ||
myLogger = logger; | ||
} | ||
|
||
@Override | ||
public void onEnter(@NotNull final String text) { | ||
final Matcher matcher = PROJECT_NAME_PATTERN.matcher(text); | ||
myProjectName = matcher.find() ? ":" + matcher.group(1) : ""; | ||
myLogger.message(String.format(COMPILATION_STARTED_FORMAT, myProjectName)); | ||
|
||
final String message = String.format("%s %s", CargoState.Compiling, text); | ||
myLogger.message(String.format(COMPILATION_MESSAGE_FORMAT, message)); | ||
} | ||
|
||
@Override | ||
public void processLine(@NotNull final String text) { | ||
myLogger.message(String.format(COMPILATION_MESSAGE_FORMAT, text)); | ||
} | ||
|
||
@Override | ||
public boolean canChangeState(CargoState state, String text) { | ||
return !(state == CargoState.Running && text.startsWith("`rustc")); | ||
} | ||
|
||
@Override | ||
public void onLeave() { | ||
myLogger.message(String.format(COMPILATION_FINISHED_FORMAT, myProjectName)); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
plugin-rust-agent/src/main/java/jetbrains/buildServer/rust/logging/CargoDefaultLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2000-2016 JetBrains s.r.o. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
|
||
package jetbrains.buildServer.rust.logging; | ||
|
||
import jetbrains.buildServer.agent.BuildProgressLogger; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Default logger implementation. | ||
*/ | ||
public class CargoDefaultLogger implements CargoLogger { | ||
|
||
private final BuildProgressLogger myLogger; | ||
|
||
public CargoDefaultLogger(@NotNull final BuildProgressLogger logger){ | ||
myLogger = logger; | ||
} | ||
|
||
@Override | ||
public void onEnter(@NotNull final String text) { | ||
myLogger.message(text); | ||
} | ||
|
||
@Override | ||
public void processLine(@NotNull final String text) { | ||
myLogger.message(text); | ||
} | ||
|
||
@Override | ||
public void processError(@NotNull final String text) { | ||
myLogger.error(text); | ||
} | ||
|
||
@Override | ||
public void onLeave() { | ||
} | ||
|
||
@Override | ||
public boolean canChangeState(CargoState state, String text) { | ||
return true; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
plugin-rust-agent/src/main/java/jetbrains/buildServer/rust/logging/CargoLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2000-2016 JetBrains s.r.o. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
|
||
package jetbrains.buildServer.rust.logging; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Cargo logger. | ||
*/ | ||
public interface CargoLogger { | ||
void onEnter(@NotNull final String text); | ||
void processLine(@NotNull final String text); | ||
void processError(@NotNull final String text); | ||
void onLeave(); | ||
boolean canChangeState(CargoState state, String text); | ||
} |
52 changes: 52 additions & 0 deletions
52
plugin-rust-agent/src/main/java/jetbrains/buildServer/rust/logging/CargoLoggerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2000-2016 JetBrains s.r.o. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
|
||
package jetbrains.buildServer.rust.logging; | ||
|
||
import jetbrains.buildServer.agent.BuildProgressLogger; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Dmitry.Tretyakov | ||
* Date: 25.09.2016 | ||
* Time: 21:49 | ||
*/ | ||
public class CargoLoggerFactory { | ||
private final Map<CargoState, CargoLogger> myLoggers; | ||
|
||
public CargoLoggerFactory(@NotNull final BuildProgressLogger logger){ | ||
myLoggers = new HashMap<CargoState, CargoLogger>(); | ||
myLoggers.put(CargoState.Running, new CargoStateLogger(logger, CargoState.Running)); | ||
myLoggers.put(CargoState.Compiling, new CargoCompileLogger(logger)); | ||
myLoggers.put(CargoState.Error, new CargoStateLogger(logger, CargoState.Error)); | ||
myLoggers.put(CargoState.Warning, new CargoStateLogger(logger, CargoState.Warning)); | ||
myLoggers.put(CargoState.Documenting, new CargoStateLogger(logger, CargoState.Documenting)); | ||
myLoggers.put(CargoState.Fresh, new CargoStateLogger(logger, CargoState.Fresh)); | ||
myLoggers.put(CargoState.Updating, new CargoStateLogger(logger, CargoState.Updating)); | ||
myLoggers.put(CargoState.Adding, new CargoStateLogger(logger, CargoState.Adding)); | ||
myLoggers.put(CargoState.Removing, new CargoStateLogger(logger, CargoState.Removing)); | ||
myLoggers.put(CargoState.DocTests, new CargoStateLogger(logger, CargoState.DocTests)); | ||
myLoggers.put(CargoState.Packaging, new CargoStateLogger(logger, CargoState.Packaging)); | ||
myLoggers.put(CargoState.Downloading, new CargoStateLogger(logger, CargoState.Downloading)); | ||
myLoggers.put(CargoState.Uploading, new CargoStateLogger(logger, CargoState.Uploading)); | ||
myLoggers.put(CargoState.Verifying, new CargoStateLogger(logger, CargoState.Verifying)); | ||
myLoggers.put(CargoState.Archiving, new CargoStateLogger(logger, CargoState.Archiving)); | ||
myLoggers.put(CargoState.Installing, new CargoStateLogger(logger, CargoState.Installing)); | ||
myLoggers.put(CargoState.Replacing, new CargoStateLogger(logger, CargoState.Replacing)); | ||
myLoggers.put(CargoState.Default, new CargoDefaultLogger(logger)); | ||
myLoggers.put(CargoState.Testing, new CargoTestingLogger(logger)); | ||
} | ||
|
||
@NotNull | ||
public CargoLogger getLogger(final CargoState state) { | ||
return myLoggers.get(state); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
plugin-rust-agent/src/main/java/jetbrains/buildServer/rust/logging/CargoLoggingListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright 2000-2016 JetBrains s.r.o. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
|
||
package jetbrains.buildServer.rust.logging; | ||
|
||
import jetbrains.buildServer.agent.runner.ProcessListenerAdapter; | ||
import jetbrains.buildServer.util.StringUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Handles build messages from cargo tool. | ||
*/ | ||
public class CargoLoggingListener extends ProcessListenerAdapter { | ||
private static Pattern myStatement = Pattern.compile("^([\\w][\\w-]+\\:?)\\s+(.*)?$"); | ||
private static Pattern myTestsStart = Pattern.compile("^running \\d+ tests?$"); | ||
private final CargoLoggerFactory myLoggerFactory; | ||
private CargoLogger myLogger; | ||
private String myLastLine; | ||
|
||
public CargoLoggingListener(@NotNull final CargoLoggerFactory loggerFactory) { | ||
myLoggerFactory = loggerFactory; | ||
myLogger = loggerFactory.getLogger(CargoState.Default); | ||
} | ||
|
||
@Override | ||
public void onStandardOutput(@NotNull String text) { | ||
text = text.trim(); | ||
|
||
if (StringUtil.isEmptyOrSpaces(text)) return; | ||
|
||
final String lastLine = myLastLine; | ||
myLastLine = text.trim(); | ||
|
||
final Matcher testsMatcher = myTestsStart.matcher(text); | ||
if (testsMatcher.find()) { | ||
final String testSuiteName = getTestSuiteName(lastLine); | ||
changeState(CargoState.Testing, testSuiteName); | ||
return; | ||
} | ||
|
||
final Matcher stateMatcher = myStatement.matcher(text); | ||
if (stateMatcher.find()) { | ||
final String stateKey = stateMatcher.group(1); | ||
final String stateText = stateMatcher.group(2); | ||
|
||
final CargoState state = CargoState.get(stateKey); | ||
if (state != null && myLogger.canChangeState(state, stateText)) { | ||
changeState(state, stateText); | ||
return; | ||
} | ||
} | ||
|
||
myLogger.processLine(text); | ||
} | ||
|
||
private void changeState(@NotNull final CargoState state, @NotNull final String text) { | ||
final CargoLogger logger = myLoggerFactory.getLogger(state); | ||
|
||
myLogger.onLeave(); | ||
logger.onEnter(text); | ||
myLogger = logger; | ||
} | ||
|
||
@Override | ||
public void onErrorOutput(@NotNull final String text) { | ||
myLogger.processError(text); | ||
} | ||
|
||
@Override | ||
public void processFinished(int exitCode) { | ||
myLogger.onLeave(); | ||
} | ||
|
||
@NotNull | ||
private static String getTestSuiteName(@NotNull final String text) { | ||
if (text.startsWith(CargoState.Running.toString())) { | ||
int slashIndex = text.lastIndexOf("/"); | ||
if (slashIndex < 0) { | ||
slashIndex = text.lastIndexOf("\\"); | ||
} | ||
|
||
if (slashIndex > 0) { | ||
final int dashIndex = text.lastIndexOf("-"); | ||
if (dashIndex > slashIndex) { | ||
return text.substring(slashIndex + 1, dashIndex); | ||
} | ||
} | ||
} else if (text.startsWith(CargoState.DocTests.toString())) { | ||
return text; | ||
} | ||
|
||
return ""; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
plugin-rust-agent/src/main/java/jetbrains/buildServer/rust/logging/CargoState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2000-2016 JetBrains s.r.o. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
|
||
package jetbrains.buildServer.rust.logging; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Cargo states. | ||
* Reference: https://github.com/rust-lang/cargo/blob/master/tests/cargotest/support/mod.rs | ||
*/ | ||
public enum CargoState { | ||
Running("Running"), | ||
Compiling("Compiling"), | ||
Error("error:"), | ||
Warning("warning:"), | ||
Documenting("Documenting"), | ||
Fresh("Fresh"), | ||
Updating("Updating"), | ||
Adding("Adding"), | ||
Removing("Removing"), | ||
DocTests("Doc-tests"), | ||
Packaging("Packaging"), | ||
Downloading("Downloading"), | ||
Uploading("Uploading"), | ||
Verifying("Verifying"), | ||
Archiving("Archiving"), | ||
Installing("Installing"), | ||
Replacing("Replacing"), | ||
|
||
Default("Default"), | ||
Testing("Testing"); | ||
|
||
private String myName; | ||
|
||
CargoState(@NotNull final String name) { | ||
myName = name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return myName; | ||
} | ||
|
||
private static final Map<String, CargoState> STATES = new HashMap<String, CargoState>(); | ||
|
||
static { | ||
for (CargoState state : values()) { | ||
STATES.put(state.myName, state); | ||
} | ||
} | ||
|
||
public static CargoState get(String value) { | ||
return STATES.get(value); | ||
} | ||
} |
Oops, something went wrong.