Skip to content

Commit

Permalink
Merge pull request #7 from donhui/donhui-0511
Browse files Browse the repository at this point in the history
add a side panel for the build
  • Loading branch information
donhui authored May 11, 2019
2 parents 4a76d98 + 1aa5f94 commit edcd18f
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
public class MavenSnapshotCheck extends Builder implements SimpleBuildStep{
private static final String POM_FILE = "pom.xml,**/pom.xml";
private static final String SNAPSHOT = "SNAPSHOT";
private String CHECKED = "Yes, it was checked.";
private String NOT_CHECKED = "No, it wasn't checked.";

private boolean check;

Expand Down Expand Up @@ -64,7 +66,9 @@ public MavenSnapshotCheck.DescriptorImpl getDescriptor() {
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) {
FilePath workspace = build.getWorkspace();
if (getCheck()) {
listener.getLogger().println("[Maven SNAPSHOT Check]");
build.addAction(new MavenSnapshotCheckAction(CHECKED));
String message = "[Maven SNAPSHOT Check]";
listener.getLogger().println(message);
PrintStream logger = listener.getLogger();
final RemoteOutputStream ros = new RemoteOutputStream(logger);
try {
Expand All @@ -73,10 +77,14 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
return false;
}
} catch (IOException e) {
logger.println("Jenkins Maven SNAPSHOT Check Plugin:" + e.getMessage());
message = "Jenkins Maven SNAPSHOT Check Plugin:" + e.getMessage();
logger.println(message);
} catch (InterruptedException e) {
logger.println("Jenkins Maven SNAPSHOT Check Plugin:" + e.getMessage());
message = "Jenkins Maven SNAPSHOT Check Plugin:" + e.getMessage();
logger.println(message);
}
}else {
build.addAction(new MavenSnapshotCheckAction(NOT_CHECKED));
}
return true;
}
Expand All @@ -93,7 +101,9 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
@Override
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener taskListener) throws InterruptedException, IOException {
if (getCheck()) {
taskListener.getLogger().println("[Maven SNAPSHOT Check]");
run.addAction(new MavenSnapshotCheckAction(CHECKED));
String message = "[Maven SNAPSHOT Check]";
taskListener.getLogger().println(message);
PrintStream logger = taskListener.getLogger();
final RemoteOutputStream ros = new RemoteOutputStream(logger);
try {
Expand All @@ -102,10 +112,14 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnul
run.setResult(Result.FAILURE);
}
} catch (IOException e) {
logger.println("Jenkins Maven SNAPSHOT Check Plugin:" + e.getMessage());
message = "Jenkins Maven SNAPSHOT Check Plugin:" + e.getMessage();
logger.println(message);
} catch (InterruptedException e) {
logger.println("Jenkins Maven SNAPSHOT Check Plugin:" + e.getMessage());
message = "Jenkins Maven SNAPSHOT Check Plugin:" + e.getMessage();
logger.println(message);
}
}else {
run.addAction(new MavenSnapshotCheckAction(NOT_CHECKED));
}
run.setResult(Result.SUCCESS);
}
Expand Down Expand Up @@ -164,15 +178,18 @@ private static boolean checkFile(
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
if (logFilename) {
logger.println(f + ":");
String message = f + ":";
logger.println(message);
logFilename = false;
}
logger.println(line);
String message = line;
logger.println(message);
foundText = true;
}
}
} catch (IOException e) {
logger.println("Jenkins Maven SNAPSHOT Check Plugin: Error reading file '" + f + "' -- ignoring");
String message = "Jenkins Maven SNAPSHOT Check Plugin: Error reading file '" + f + "' -- ignoring";
logger.println(message);
} finally {
IOUtils.closeQuietly(reader);
}
Expand All @@ -192,8 +209,8 @@ private static Pattern compilePattern(PrintStream logger, String regexp) {
try {
pattern = Pattern.compile(regexp);
} catch (PatternSyntaxException e) {
logger.println(
"Jenkins Maven SNAPSHOT Check Plugin: Unable to compile regular expression '" + regexp + "'");
String message = "Jenkins Maven SNAPSHOT Check Plugin: Unable to compile regular expression '" + regexp + "'";
logger.println(message);
}
return pattern;
}
Expand Down Expand Up @@ -235,12 +252,14 @@ public Boolean invoke(File ws, VirtualChannel channel) throws IOException, Inter
File f = new File(ws, file);

if (!f.exists()) {
logger.println("Jenkins Maven SNAPSHOT Check Plugin: Unable to find file '" + f + "'");
String message = "Jenkins Maven SNAPSHOT Check Plugin: Unable to find file '" + f + "'";
logger.println(message);
continue;
}

if (!f.canRead()) {
logger.println("Jenkins Maven SNAPSHOT Check Plugin: Unable to read from file '" + f + "'");
String message = "Jenkins Maven SNAPSHOT Check Plugin: Unable to read from file '" + f + "'";
logger.println(message);
continue;
}
foundText |= checkFile(f, pattern, logger, Charset.defaultCharset());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package jenkins.plugins.mvn_snapshot_check;

import hudson.model.Run;
import jenkins.model.RunAction2;

/**
* @author donghui 2019/5/11.
*/
public class MavenSnapshotCheckAction implements RunAction2{

private transient Run run;

private String message;

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public MavenSnapshotCheckAction(String message){
this.message = message;
}

@Override
public String getIconFileName() {
return "document.png";
}

@Override
public String getDisplayName() {
return "Maven SNAPSHOT Check";
}

@Override
public String getUrlName() {
return "maven-snapshot-check";
}

@Override
public void onAttached(Run<?, ?> run) {
this.run = run;
}

@Override
public void onLoad(Run<?, ?> run) {
this.run = run;
}

public Run getRun() {
return run;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:st="jelly:stapler">
<l:layout title="Maven SNAPSHOT Check">
<l:side-panel>
<st:include page="sidepanel.jelly" it="${it.run}" optional="true" />
</l:side-panel>
<l:main-panel>
<h3>
Is it checked?
</h3>
<h3>
${it.message}
</h3>
</l:main-panel>
</l:layout>
</j:jelly>

0 comments on commit edcd18f

Please sign in to comment.