mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
Add some Javadoc comments
This commit is contained in:
parent
cc779b4d2f
commit
7d8f94e5e8
@ -7,6 +7,19 @@ import org.eclipse.jgit.lib.ObjectId;
|
|||||||
import io.onedev.commons.launcher.loader.ExtensionPoint;
|
import io.onedev.commons.launcher.loader.ExtensionPoint;
|
||||||
import io.onedev.server.model.Project;
|
import io.onedev.server.model.Project;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This extension point extends OneDev's ability to provide default CI spec for different
|
||||||
|
* kinds of projects
|
||||||
|
* <p>
|
||||||
|
* OneDev has built-in CI support to build projects. The build instructions are defined in <i>onedev-ci.xml</i>
|
||||||
|
* in root of the project (do not worry about writing this xml, OneDev has visual editor to help you doing
|
||||||
|
* that). For some typical projects, it is possible that some default build instructions can be deducted
|
||||||
|
* automatically without existence of <i>onedev-ci.xml</i>. Hence we introduced this extension point to make
|
||||||
|
* OneDev CI more easier to get started.
|
||||||
|
*
|
||||||
|
* @author robin
|
||||||
|
*
|
||||||
|
*/
|
||||||
@ExtensionPoint
|
@ExtensionPoint
|
||||||
public interface DefaultCISpecProvider {
|
public interface DefaultCISpecProvider {
|
||||||
|
|
||||||
@ -22,6 +35,14 @@ public interface DefaultCISpecProvider {
|
|||||||
@Nullable
|
@Nullable
|
||||||
CISpec getDefaultCISpec(Project project, ObjectId commitId);
|
CISpec getDefaultCISpec(Project project, ObjectId commitId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get priority of this provider. If multiple providers can provide default CI specs for
|
||||||
|
* specified project and commit, the provider with higher priority will win
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* a number indicating priority of the provider. The lower the value is, the
|
||||||
|
* higher the priority is
|
||||||
|
*/
|
||||||
int getPriority();
|
int getPriority();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,7 +97,7 @@ public class Job implements Serializable, Validatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Editable(order=120, description="Specify commands to execute in above environment, with one command per line. "
|
@Editable(order=120, description="Specify commands to execute in above environment, with one command per line. "
|
||||||
+ "For Windows based environments, commands will be interpretated by PowerShell, and for Unix/Linux "
|
+ "For Windows based environments, commands will be interpretated by cmd.exe, and for Unix/Linux "
|
||||||
+ "based environments, commands will be interpretated by shell")
|
+ "based environments, commands will be interpretated by shell")
|
||||||
@Script(Script.SHELL)
|
@Script(Script.SHELL)
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
|
|||||||
@ -103,10 +103,11 @@ public class DefaultLogManager implements LogManager {
|
|||||||
|
|
||||||
private void log(LogLevel logLevel, String message) {
|
private void log(LogLevel logLevel, String message) {
|
||||||
for (LogNormalizer logNormalizer: logNormalizers) {
|
for (LogNormalizer logNormalizer: logNormalizers) {
|
||||||
LogNormalizer.Result result = logNormalizer.normalize(message);
|
LogNormalizer.Normalized normalized = logNormalizer.normalize(message);
|
||||||
if (result != null) {
|
if (normalized != null) {
|
||||||
logLevel = result.getLevel();
|
if (normalized.getLevel() != null)
|
||||||
message = result.getMessage();
|
logLevel = normalized.getLevel();
|
||||||
|
message = normalized.getMessage();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,27 +4,56 @@ import javax.annotation.Nullable;
|
|||||||
|
|
||||||
import io.onedev.commons.launcher.loader.ExtensionPoint;
|
import io.onedev.commons.launcher.loader.ExtensionPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sometimes job log message needs to be normalized for better display. For instance Maven command prints something
|
||||||
|
* like below:
|
||||||
|
*
|
||||||
|
* <pre>[INFO] Scanning for projects...</pre>
|
||||||
|
*
|
||||||
|
* In such case, we should extract the log level information to override OneDev's default log level, and the
|
||||||
|
* original message should also be modified to remove the log level information
|
||||||
|
*
|
||||||
|
* @author robin
|
||||||
|
*
|
||||||
|
*/
|
||||||
@ExtensionPoint
|
@ExtensionPoint
|
||||||
public interface LogNormalizer {
|
public interface LogNormalizer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize provided job log message
|
||||||
|
* @param message
|
||||||
|
* message to be normalized
|
||||||
|
* @return
|
||||||
|
* normalized result, or <tt>null</tt> if this normalizer does not handle this message
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
Result normalize(String message);
|
Normalized normalize(String message);
|
||||||
|
|
||||||
public static class Result {
|
public static class Normalized {
|
||||||
|
|
||||||
private final LogLevel level;
|
private final LogLevel level;
|
||||||
|
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
public Result(LogLevel level, String message) {
|
public Normalized(@Nullable LogLevel level, String message) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
* Log level of this message, or <tt>null</tt> if log level information
|
||||||
|
* is not available in this message
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
public LogLevel getLevel() {
|
public LogLevel getLevel() {
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
* normalized message
|
||||||
|
*/
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,6 +63,7 @@ public class DefaultMavenCISpecProvider implements DefaultCISpecProvider {
|
|||||||
Job job = new Job();
|
Job job = new Job();
|
||||||
|
|
||||||
job.setName("ci");
|
job.setName("ci");
|
||||||
|
|
||||||
switch (javaVersion) {
|
switch (javaVersion) {
|
||||||
case "13":
|
case "13":
|
||||||
job.setEnvironment("maven:3.6.1-jdk-13");
|
job.setEnvironment("maven:3.6.1-jdk-13");
|
||||||
@ -76,15 +77,25 @@ public class DefaultMavenCISpecProvider implements DefaultCISpecProvider {
|
|||||||
default:
|
default:
|
||||||
job.setEnvironment("maven:3.6.1-jdk-8");
|
job.setEnvironment("maven:3.6.1-jdk-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Before running maven test, we extract version of the project and use LogInstruction to tell
|
||||||
|
* OneDev using extracted version for current build
|
||||||
|
*/
|
||||||
job.setCommands(""
|
job.setCommands(""
|
||||||
+ "buildVersion=$(mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout)\n"
|
+ "buildVersion=$(mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout)\n"
|
||||||
+ "echo \"##onedev[SetBuildVersion '$buildVersion']\"\n"
|
+ "echo \"##onedev[SetBuildVersion '$buildVersion']\"\n"
|
||||||
+ "echo\n"
|
+ "echo\n"
|
||||||
+ "mvn clean test");
|
+ "mvn clean test");
|
||||||
|
|
||||||
|
// Trigger the job automatically when there is a push to the branch
|
||||||
BranchUpdateTrigger trigger = new BranchUpdateTrigger();
|
BranchUpdateTrigger trigger = new BranchUpdateTrigger();
|
||||||
job.getTriggers().add(trigger);
|
job.getTriggers().add(trigger);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cache Maven local repository in order not to download Maven dependencies all over again for
|
||||||
|
* subsequent builds
|
||||||
|
*/
|
||||||
JobCache cache = new JobCache();
|
JobCache cache = new JobCache();
|
||||||
cache.setKey("maven-local-repository");
|
cache.setKey("maven-local-repository");
|
||||||
cache.setPath("/root/.m2");
|
cache.setPath("/root/.m2");
|
||||||
|
|||||||
@ -9,17 +9,17 @@ import io.onedev.server.ci.job.log.LogNormalizer;
|
|||||||
public class MavenLogNormalizer implements LogNormalizer {
|
public class MavenLogNormalizer implements LogNormalizer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result normalize(String message) {
|
public Normalized normalize(String message) {
|
||||||
if (message.startsWith("[INFO] ")) {
|
if (message.startsWith("[INFO] ")) {
|
||||||
return new Result(LogLevel.INFO, message.substring("[INFO] ".length()));
|
return new Normalized(LogLevel.INFO, message.substring("[INFO] ".length()));
|
||||||
} else if (message.startsWith("[ERROR] ")) {
|
} else if (message.startsWith("[ERROR] ")) {
|
||||||
return new Result(LogLevel.ERROR, message.substring("[ERROR] ".length()));
|
return new Normalized(LogLevel.ERROR, message.substring("[ERROR] ".length()));
|
||||||
} else if (message.startsWith("[WARNING] ")) {
|
} else if (message.startsWith("[WARNING] ")) {
|
||||||
return new Result(LogLevel.WARN, message.substring("[WARNING] ".length()));
|
return new Normalized(LogLevel.WARN, message.substring("[WARNING] ".length()));
|
||||||
} else if (message.startsWith("[DEBUG] ")) {
|
} else if (message.startsWith("[DEBUG] ")) {
|
||||||
return new Result(LogLevel.DEBUG, message.substring("[DEBUG] ".length()));
|
return new Normalized(LogLevel.DEBUG, message.substring("[DEBUG] ".length()));
|
||||||
} else if (message.startsWith("[TRACE] ")) {
|
} else if (message.startsWith("[TRACE] ")) {
|
||||||
return new Result(LogLevel.TRACE, message.substring("[TRACE] ".length()));
|
return new Normalized(LogLevel.TRACE, message.substring("[TRACE] ".length()));
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user