Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
698 additions
and 533 deletions.
- +257 −260 src/main/java/com/orctom/jenkins/plugin/globalpostscript/GlobalPostScript.java
- +30 −30 src/main/java/com/orctom/jenkins/plugin/globalpostscript/GlobalPostScriptAction.java
- +2 −1 src/main/java/com/orctom/jenkins/plugin/globalpostscript/GlobalPostScriptPlugin.java
- +34 −0 src/main/java/com/orctom/jenkins/plugin/globalpostscript/ScriptContentLoader.java
- +30 −97 src/main/java/com/orctom/jenkins/plugin/globalpostscript/ScriptExecutor.java
- +0 −93 src/main/java/com/orctom/jenkins/plugin/globalpostscript/URL.java
- +32 −0 src/main/java/com/orctom/jenkins/plugin/globalpostscript/model/ScriptContent.java
- +96 −0 src/main/java/com/orctom/jenkins/plugin/globalpostscript/model/URL.java
- +51 −0 src/main/java/com/orctom/jenkins/plugin/globalpostscript/runner/GroovyScriptRunner.java
- +32 −0 src/main/java/com/orctom/jenkins/plugin/globalpostscript/runner/ScriptRunner.java
- +30 −0 src/main/java/com/orctom/jenkins/plugin/globalpostscript/runner/ScriptRunners.java
- +51 −0 src/main/java/com/orctom/jenkins/plugin/globalpostscript/runner/ShellScriptRunner.java
- +50 −48 src/test/java/com/orctom/jenkins/plugin/globalpostscript/ScriptTest.java
- +3 −4 src/test/java/com/orctom/jenkins/plugin/globalpostscript/URLTest.java
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
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
@@ -0,0 +1,34 @@ | ||
package com.orctom.jenkins.plugin.globalpostscript; | ||
|
||
import com.orctom.jenkins.plugin.globalpostscript.model.ScriptContent; | ||
import hudson.Util; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* load script content with cache | ||
* Created by hao on 3/9/16. | ||
*/ | ||
public class ScriptContentLoader { | ||
|
||
private static String scriptFileName; | ||
private static long scriptLastModified; | ||
|
||
private static String scriptContent; | ||
|
||
public static ScriptContent getScriptContent(File script, Map<String, String> variables) throws IOException { | ||
long modified = script.lastModified(); | ||
boolean isChanged = false; | ||
if (!script.getName().equals(scriptFileName) || scriptLastModified < modified) { | ||
scriptFileName = script.getName(); | ||
scriptLastModified = modified; | ||
|
||
String content = Util.loadFile(script); | ||
scriptContent = Util.replaceMacro(content, variables); | ||
isChanged = true; | ||
} | ||
return new ScriptContent(scriptContent, isChanged); | ||
} | ||
} |
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
@@ -1,110 +1,43 @@ | ||
package com.orctom.jenkins.plugin.globalpostscript; | ||
|
||
import com.orctom.jenkins.plugin.globalpostscript.runner.ScriptRunners; | ||
import hudson.model.TaskListener; | ||
import org.codehaus.plexus.util.FileUtils; | ||
|
||
import java.io.File; | ||
import java.util.Map; | ||
|
||
/** | ||
* script executor | ||
* Created by hao on 6/25/2014. | ||
*/ | ||
public class ScriptExecutor { | ||
|
||
private TaskListener listener; | ||
private GlobalPostScript.BadgeManager manager; | ||
|
||
public ScriptExecutor(TaskListener listener, GlobalPostScript.BadgeManager manager) { | ||
this.listener = listener; | ||
this.manager = manager; | ||
} | ||
|
||
public void execute(File scriptFile, Map<String, String> variables) { | ||
println("[INFO]"); | ||
println("[INFO] -----------------------------------------------------"); | ||
println("[INFO] " + GlobalPostScriptPlugin.PLUGIN_NAME); | ||
println("[INFO] -----------------------------------------------------"); | ||
String ext = FileUtils.getExtension(scriptFile.getAbsolutePath()); | ||
if ("groovy".equalsIgnoreCase(ext) || "gvy".equalsIgnoreCase(ext) || "gs".equalsIgnoreCase(ext) || "gsh".equalsIgnoreCase(ext)) { | ||
ScriptRunners.GROOVY.run(scriptFile, variables, manager, listener); | ||
} else if ("sh".equalsIgnoreCase(ext) || "bat".equalsIgnoreCase(ext)) { | ||
ScriptRunners.SHELL.run(scriptFile, variables, manager, listener); | ||
} else { | ||
println("[ERROR] Script type not supported: " + ext + " | " + scriptFile.getName()); | ||
} | ||
println("[INFO] -----------------------------------------------------"); | ||
} | ||
|
||
private void println(String message) { | ||
listener.getLogger().println(message); | ||
} | ||
} |
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
@@ -0,0 +1,32 @@ | ||
package com.orctom.jenkins.plugin.globalpostscript.model; | ||
|
||
/** | ||
* script content model | ||
* Created by hao on 3/13/16. | ||
*/ | ||
public class ScriptContent { | ||
|
||
private String content; | ||
private boolean isChanged; | ||
|
||
public ScriptContent(String content, boolean isChanged) { | ||
this.content = content; | ||
this.isChanged = isChanged; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
|
||
public boolean isChanged() { | ||
return isChanged; | ||
} | ||
|
||
public void setChanged(boolean changed) { | ||
this.isChanged = changed; | ||
} | ||
} |
Oops, something went wrong.