Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #17 from toericliou/master
[Fixed JENKINS-28722] Integrate Build-Failure-Analyzer Plugin with Cl…
- Loading branch information
Showing
12 changed files
with
909 additions
and
9 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
*.ipr | ||
*.ipr | ||
/bin | ||
/.idea/ | ||
======= |
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
109 changes: 109 additions & 0 deletions
109
src/main/java/hudson/plugins/claim/ClaimBuildFailureAnalyzer.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,109 @@ | ||
package hudson.plugins.claim; | ||
|
||
import com.sonyericsson.jenkins.plugins.bfa.PluginImpl; | ||
import com.sonyericsson.jenkins.plugins.bfa.model.FailureCause; | ||
import com.sonyericsson.jenkins.plugins.bfa.model.FailureCauseBuildAction; | ||
import com.sonyericsson.jenkins.plugins.bfa.model.FoundFailureCause; | ||
import com.sonyericsson.jenkins.plugins.bfa.model.indication.FoundIndication; | ||
import com.sonyericsson.jenkins.plugins.bfa.statistics.StatisticsLogger; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.Run; | ||
import jenkins.model.Jenkins; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
public class ClaimBuildFailureAnalyzer { | ||
|
||
public static String ERROR = "Default"; | ||
private static final String matchingFile = "Claim"; | ||
|
||
public ClaimBuildFailureAnalyzer(String error) throws Exception { | ||
ERROR=error; | ||
} | ||
|
||
public static Collection<FailureCause> getFailureCauses() throws Exception { | ||
return Jenkins.getInstance().getPlugin(PluginImpl.class).getKnowledgeBase().getCauses(); | ||
} | ||
|
||
public static boolean isBFAEnabled(){ | ||
return (Jenkins.getInstance().getPlugin("build-failure-analyzer")!=null && Jenkins.getInstance().getPlugin(PluginImpl.class).isGlobalEnabled()); | ||
} | ||
|
||
public static HashMap<String, String> getFillReasonMap() throws Exception { | ||
HashMap<String, String> map = new HashMap<String, String>(); | ||
for (FailureCause cause : getFailureCauses()) { | ||
map.put(cause.getName(), cause.getDescription()); | ||
} | ||
return map; | ||
} | ||
|
||
public static LinkedList<String> getDropdownList() throws Exception { | ||
LinkedList<String> list = new LinkedList<String>(); | ||
for (FailureCause cause : getFailureCauses()) { | ||
list.add(cause.getName()); | ||
} | ||
return list; | ||
} | ||
|
||
public void createFailAction(Run run) throws Exception { | ||
FoundFailureCause newClaimedFailureCause = null; | ||
List<FoundIndication> indications = new LinkedList<FoundIndication>(); | ||
for(FailureCause cause : getFailureCauses()){ | ||
if(cause.getName().equals(ERROR)) { | ||
indications.add(new ClaimIndication((AbstractBuild) run,"Null",matchingFile,"Null")); | ||
newClaimedFailureCause = new FoundFailureCause(cause, indications); | ||
break; | ||
} | ||
} | ||
try { | ||
Jenkins.getInstance().getPlugin(PluginImpl.class).save(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
List<FailureCauseBuildAction> bfaActionList = run.getActions(FailureCauseBuildAction.class); | ||
FoundFailureCause existingClaimedFoundFailureCause = null; | ||
FailureCauseBuildAction bfaAction = bfaActionList.get(0); | ||
List<FoundFailureCause> foundFailureCauses = bfaAction.getFoundFailureCauses(); | ||
boolean hasFailureCauseFromBFA = false; | ||
for (FoundFailureCause cause : foundFailureCauses) { | ||
// check if it's an indication created by claim | ||
if(cause.getName().equals(newClaimedFailureCause.getName()) && cause.getIndications().get(0).getMatchingFile().equals("log")){ | ||
hasFailureCauseFromBFA = true; | ||
} | ||
if (cause.getIndications().get(0).getMatchingFile()==matchingFile) { | ||
existingClaimedFoundFailureCause = cause; | ||
break; | ||
} | ||
} | ||
if (existingClaimedFoundFailureCause != null) { | ||
foundFailureCauses.remove(existingClaimedFoundFailureCause); | ||
} | ||
if(!hasFailureCauseFromBFA) { | ||
foundFailureCauses.add(newClaimedFailureCause); | ||
} | ||
try { | ||
run.save(); | ||
StatisticsLogger.getInstance().log((AbstractBuild) run, bfaAction.getFoundFailureCauses()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void removeFailAction(Run run){ | ||
List<FailureCauseBuildAction> bfaActionList = run.getActions(FailureCauseBuildAction.class); | ||
if(!bfaActionList.isEmpty()) { | ||
FailureCauseBuildAction bfaAction = bfaActionList.get(0); | ||
List<FoundFailureCause> foundFailureCauses = bfaAction.getFoundFailureCauses(); | ||
for (FoundFailureCause cause : foundFailureCauses) { | ||
if (cause.getIndications().get(0).getMatchingFile() == "Claim") { | ||
foundFailureCauses.remove(cause); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
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,11 @@ | ||
package hudson.plugins.claim; | ||
|
||
import com.sonyericsson.jenkins.plugins.bfa.model.indication.FoundIndication; | ||
import hudson.model.AbstractBuild; | ||
|
||
public class ClaimIndication extends FoundIndication { | ||
|
||
public ClaimIndication(AbstractBuild build, String originalPattern, String matchingFile, String matchingString) { | ||
super(build, originalPattern, matchingFile, matchingString); | ||
} | ||
} |
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
Oops, something went wrong.