Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.580.3</version>
<version>1.596.2</version>
</parent>

<artifactId>mantis</artifactId>
<version>0.27-SNAPSHOT</version>
<version>0.28-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Jenkins Mantis plugin</name>
<description>Integrates Jenkins to Mantis</description>
Expand All @@ -20,6 +20,11 @@
<name>Seiji Sogabe</name>
<email>s.sogabe@gmail.com</email>
</developer>
<developer>
<id>LFA</id>
<name>Fabre Lucas</name>
<email>l.fabre@amesys.fr</email>
</developer>
</developers>

<properties>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/hudson/plugins/mantis/MantisIssueRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import hudson.model.Result;
import hudson.plugins.mantis.model.MantisCategory;
import hudson.plugins.mantis.model.MantisIssue;
import hudson.plugins.mantis.model.MantisIssueStatus;
import hudson.plugins.mantis.model.MantisProject;
import hudson.plugins.mantis.model.MantisViewState;
import hudson.plugins.mantis.scripts.JellyScriptContent;
Expand Down Expand Up @@ -123,12 +124,13 @@ private MantisIssue createIssue(AbstractBuild<?, ?> build, BuildListener listene
String summary = summary(build);
String description = new JellyScriptContent().getContent(build, build.getResult());
MantisViewState viewState;

if (isKeepTicketPrivate()) {
viewState = MantisViewState.PUBLIC;
} else {
viewState = MantisViewState.PRIVATE;
}
return new MantisIssue(project, category, summary, description, viewState);
return new MantisIssue(project, category, summary, description,viewState,"new");
}

private String summary(AbstractBuild<?, ?> build) {
Expand Down
114 changes: 106 additions & 8 deletions src/main/java/hudson/plugins/mantis/MantisIssueUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;
import java.io.IOException;
import java.util.logging.Level;

import net.sf.json.JSONObject;

Expand All @@ -24,24 +25,117 @@
*/
public final class MantisIssueUpdater extends Recorder {

private final boolean keepNotePrivate;
private final boolean keepNotePrivate;

private final boolean recordChangelog;
private boolean addChangeLog;

private final boolean resolvedFilter;

private boolean NewNoteWithChangeLog;

private boolean InvertSecondStateNote;

private boolean ModeNewChangeLogNote;

private boolean ModeAddChangeLogNote;

private boolean ModeNewChangeLogNoteInvertedStatus;





@DataBoundConstructor
public MantisIssueUpdater(final boolean keepNotePrivate, final boolean recordChangelog) {
public MantisIssueUpdater(
boolean keepNotePrivate,
boolean addChangeLog,
boolean resolvedFilter,
boolean NewNoteWithChangeLog,
boolean InvertSecondStateNote,
boolean ModeNewChangeLogNote,
boolean ModeAddChangeLogNote,
boolean ModeNewChangeLogNoteInvertedStatus

)
{
this.keepNotePrivate = keepNotePrivate;
this.recordChangelog = recordChangelog;
this.resolvedFilter = resolvedFilter;
//----------------------------------------
this.addChangeLog = addChangeLog;
this.NewNoteWithChangeLog = NewNoteWithChangeLog;
this.InvertSecondStateNote = InvertSecondStateNote;
this.ModeNewChangeLogNote = ModeNewChangeLogNote;
this.ModeAddChangeLogNote = ModeAddChangeLogNote;
this.ModeNewChangeLogNoteInvertedStatus = ModeNewChangeLogNoteInvertedStatus;
SetMode();
}


public boolean isModeNewChangeLogNote(){
return ModeNewChangeLogNote;

}
public boolean isModeAddChangeLogNote(){
return ModeAddChangeLogNote;

}
public boolean isModeNewChangeLogNoteInvertedStatus(){
return ModeNewChangeLogNoteInvertedStatus;

}

public boolean isKeepNotePrivate() {
return keepNotePrivate;
}

public boolean isRecordChangelog() {
return recordChangelog;
public boolean isAddChangeLog() {
return addChangeLog;
}
public boolean isResolvedFilter() {
return resolvedFilter;
}

public boolean isNewNoteWithChangeLog() {
return NewNoteWithChangeLog;
}
public boolean isInvertSecondStateNote() {
return InvertSecondStateNote;
}

public void SetMode(){
this.addChangeLog = false;
this.NewNoteWithChangeLog = false;
this.InvertSecondStateNote = false;

// Exclusive Select if Mode 1 & Mode 2 are Selected only M1 be active
if(ModeAddChangeLogNote == true){
//Set other mod to false
this.ModeNewChangeLogNote = false;
this.ModeNewChangeLogNoteInvertedStatus = false;

this.addChangeLog = true;

}
// Exclusive Select if Mode 1 & Mode 2 are Selected only M1 be active
if(ModeNewChangeLogNote == true){
//Set other mod to false
this.ModeAddChangeLogNote = false;
this.ModeNewChangeLogNoteInvertedStatus = false;

this.addChangeLog = true;
this.NewNoteWithChangeLog = true;
}
// Exclusive Select if Mode 2 & Mode 3 are Selected only M2 be active
if(ModeNewChangeLogNoteInvertedStatus == true){
//Set other mod to false
this.ModeAddChangeLogNote = false;
this.ModeNewChangeLogNote = false;

this.addChangeLog = true;
this.NewNoteWithChangeLog = true;
this.InvertSecondStateNote = true;

}
}
@Override
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
Expand All @@ -56,9 +150,10 @@ public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher,

@Extension
public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> {

public DescriptorImpl() {
super(MantisIssueUpdater.class);

}

@Override
Expand All @@ -78,7 +173,10 @@ public boolean isApplicable(Class<? extends AbstractProject> jobType) {

@Override
public Publisher newInstance(final StaplerRequest req, final JSONObject formData) {
req.bindJSON(this, formData.getJSONObject("fruit"));
save();
return req.bindJSON(MantisIssueUpdater.class, formData);
}

}
}
69 changes: 60 additions & 9 deletions src/main/java/hudson/plugins/mantis/MantisSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import hudson.plugins.mantis.model.MantisViewState;
import hudson.plugins.mantis.soap.MantisSession;
import hudson.plugins.mantis.soap.MantisSessionFactory;
import hudson.plugins.mantis.model.MantisIssueStatus;
import hudson.util.Secret;

import java.net.MalformedURLException;
Expand Down Expand Up @@ -173,24 +174,74 @@ public boolean isConnect() {

public MantisIssue getIssue(final int id) throws MantisHandlingException {
final MantisSession session = createSession();

String msglog = "LOG LFA : Appel getIssue : ";
LOGGER.log(Level.INFO,msglog);

return session.getIssue(id);
}

public void updateIssue(final int id, final String text, final boolean keepNotePrivate)
public void updateIssue(final int id, final String text, String textSecondNote, final boolean keepNotePrivate, final boolean resolvedFilter, final boolean addChangeLog, final boolean InvertSecondStateNote, final boolean NewNoteWithChangeLog )
throws MantisHandlingException {

MantisViewState viewState;
if (keepNotePrivate) {
viewState = MantisViewState.PRIVATE;
} else {
viewState = MantisViewState.PUBLIC;
}
MantisNote note = new MantisNote(text, viewState);

viewState = MantisViewState.PUBLIC;

MantisSession session = createSession();
session.addNote(id, note);


if (keepNotePrivate)
{
viewState = MantisViewState.PRIVATE;
}
// Try With two Args text
this.createNote(viewState, addChangeLog, InvertSecondStateNote, NewNoteWithChangeLog ,resolvedFilter, session, id, text, textSecondNote);



}

public void createNote(
MantisViewState viewState,
boolean addChangeLog,
boolean InvertSecondStateNote,
boolean NewNoteWithChangeLog,
boolean Resolved,
MantisSession session,
int id,
String text,
String textSecondNote)
throws MantisHandlingException
{



if(addChangeLog){
if (NewNoteWithChangeLog)
{
MantisViewState newNoteViewState = viewState;
if(InvertSecondStateNote)
{

newNoteViewState = MantisViewState.invertViewState(viewState);
}
//Add note with changelog
MantisNote noteWithChange = new MantisNote(textSecondNote, newNoteViewState);
session.addNote(id, noteWithChange,Resolved);
}
//Add note with changelog
MantisNote noteWithChange = new MantisNote(text, viewState);
session.addNote(id, noteWithChange,Resolved);
}
else
{
//Add note without any changelog
// Modif MantisNote Text if Add Changelog == false
MantisNote noteWithChange = new MantisNote(text, viewState);
session.addNote(id, noteWithChange,Resolved);
}

}
public List<MantisProject> getProjects() throws MantisHandlingException {
final MantisSession session = createSession();
return session.getProjects();
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/hudson/plugins/mantis/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ final class Updater {
private static final String CRLF = System.getProperty("line.separator");

private final MantisIssueUpdater property;

private boolean flag;

Updater(final MantisIssueUpdater property) {
this.property = property;
Expand Down Expand Up @@ -69,8 +71,17 @@ boolean perform(final AbstractBuild<?, ?> build, final BuildListener listener) {
try {
final MantisIssue issue = site.getIssue(changeSet.getId());
if (update) {
final String text = createUpdateText(build, changeSet, rootUrl);
site.updateIssue(changeSet.getId(), text, property.isKeepNotePrivate());
//Add a System flag to control Changelogs on note
flag = false ;
final String text = createUpdateText(build, changeSet, rootUrl);
String text2 = "" ;
if(property.isNewNoteWithChangeLog()){

flag = true;
text2 = createUpdateText(build, changeSet, rootUrl);

}
site.updateIssue(changeSet.getId(), text, text2, property.isKeepNotePrivate(), property.isResolvedFilter(), property.isAddChangeLog(), property.isInvertSecondStateNote(), property.isNewNoteWithChangeLog());
Utility.log(logger, Messages.Updater_Updating(changeSet.getId()));
}
issues.add(issue);
Expand All @@ -92,14 +103,23 @@ private String createUpdateText(final AbstractBuild<?, ?> build, final ChangeSet
final String prjName = build.getProject().getName();
final int prjNumber = build.getNumber();
final String url = rootUrl + build.getUrl();

final StringBuilder text = new StringBuilder();

text.append(Messages.Updater_IssueIntegrated(prjName, prjNumber, url));
text.append(CRLF).append(CRLF);

if (property.isRecordChangelog()) {
if (property.isAddChangeLog() && property.isNewNoteWithChangeLog() == false )
{
text.append(changeSet.createChangeLog());
}

if (property.isAddChangeLog()&& flag == true)
{
text.append(changeSet.createChangeLog());
flag = false;
}

return text.toString();
}

Expand Down
16 changes: 14 additions & 2 deletions src/main/java/hudson/plugins/mantis/model/MantisIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public final class MantisIssue implements Serializable {
private MantisCategory category;

private MantisViewState viewState;

private String status;



public int getId() {
return id;
Expand All @@ -42,22 +46,30 @@ public MantisCategory getCategory() {
public MantisProject getProject() {
return project;
}

public String getStatus() {
return status;
}

public MantisIssue(final int id, final String summary) {
public MantisIssue(final int id, final String summary, final String status) {
this.id = id;
this.summary = summary;
this.status = status;
}

public MantisViewState getViewState() {
return viewState;
}

/* Mantis Issue Constructor */

public MantisIssue(MantisProject project, MantisCategory category, String summary,
String description, MantisViewState viewState) {
String description, MantisViewState viewState, String status) {
this.summary = summary;
this.description = description;
this.project = project;
this.category = category;
this.viewState = viewState;
this.status = status;
}
}
Loading