diff --git a/.gitignore b/.gitignore index 59aa692..1767837 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ target *.ipr *.iws work +.idea \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5f71378 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# mantis-plugin + +Forked to add some additional functionality for my daily development. + +Currently implemented: +* Change issue status to RESOVLED. diff --git a/src/main/java/hudson/plugins/mantis/MantisIssueRegister.java b/src/main/java/hudson/plugins/mantis/MantisIssueRegister.java index d5f5c90..3b7f106 100644 --- a/src/main/java/hudson/plugins/mantis/MantisIssueRegister.java +++ b/src/main/java/hudson/plugins/mantis/MantisIssueRegister.java @@ -17,15 +17,16 @@ import hudson.tasks.BuildStepMonitor; import hudson.tasks.Publisher; import hudson.tasks.Recorder; + import java.io.IOException; import java.io.PrintStream; import java.util.logging.Logger; + import org.kohsuke.stapler.DataBoundConstructor; /** - * * @author Seiji Sogabe */ public final class MantisIssueRegister extends Recorder { @@ -108,7 +109,7 @@ private String getIssueURL(MantisSite site, int no) { return site.getIssueLink(no); } - private MantisIssue createIssue(AbstractBuild build, BuildListener listener) + private MantisIssue createIssue(AbstractBuild build, BuildListener listener) throws IOException, InterruptedException { MantisProjectProperty mpp = MantisProjectProperty.get(build); int projectId = mpp.getProjectId(); @@ -128,7 +129,7 @@ private MantisIssue createIssue(AbstractBuild build, BuildListener listene } else { viewState = MantisViewState.PRIVATE; } - return new MantisIssue(project, category, summary, description, viewState); + return new MantisIssue(0, project, category, summary, description, viewState, null, null); } private String summary(AbstractBuild build) { diff --git a/src/main/java/hudson/plugins/mantis/MantisIssueUpdater.java b/src/main/java/hudson/plugins/mantis/MantisIssueUpdater.java index cccba6f..b6ac579 100644 --- a/src/main/java/hudson/plugins/mantis/MantisIssueUpdater.java +++ b/src/main/java/hudson/plugins/mantis/MantisIssueUpdater.java @@ -27,11 +27,14 @@ public final class MantisIssueUpdater extends Recorder { private final boolean keepNotePrivate; private final boolean recordChangelog; - + + private final boolean setStatusResolved; + @DataBoundConstructor - public MantisIssueUpdater(final boolean keepNotePrivate, final boolean recordChangelog) { + public MantisIssueUpdater(final boolean keepNotePrivate, final boolean recordChangelog, final boolean setStatusResolved) { this.keepNotePrivate = keepNotePrivate; this.recordChangelog = recordChangelog; + this.setStatusResolved = setStatusResolved; } public boolean isKeepNotePrivate() { @@ -42,6 +45,10 @@ public boolean isRecordChangelog() { return recordChangelog; } + public boolean isSetStatusResolved() { + return setStatusResolved; + } + @Override public BuildStepMonitor getRequiredMonitorService() { return BuildStepMonitor.NONE; diff --git a/src/main/java/hudson/plugins/mantis/MantisSite.java b/src/main/java/hudson/plugins/mantis/MantisSite.java index bb676f2..2fb2846 100644 --- a/src/main/java/hudson/plugins/mantis/MantisSite.java +++ b/src/main/java/hudson/plugins/mantis/MantisSite.java @@ -155,7 +155,7 @@ public MantisSite(final URL url, final String version, final String userName, public String getIssueLink(int issueNo) { String u = getUrl().toExternalForm(); return String.format("%sview.php?id=%d", u, issueNo); - } + } public boolean isConnect() { final String urlString = url.toExternalForm(); @@ -176,7 +176,7 @@ public MantisIssue getIssue(final int id) throws MantisHandlingException { return session.getIssue(id); } - public void updateIssue(final int id, final String text, final boolean keepNotePrivate) + public void addNote(final int id, final String text, final boolean keepNotePrivate) throws MantisHandlingException { MantisViewState viewState; @@ -205,6 +205,11 @@ public int addIssue(MantisIssue issue) throws MantisHandlingException { final MantisSession session = createSession(); return session.addIssue(issue); } + + public void updateIssue(MantisIssue issue) throws MantisHandlingException { + final MantisSession session = createSession(); + session.updateIssue(issue); + } private MantisSession createSession() throws MantisHandlingException { return MantisSessionFactory.getSession(this); diff --git a/src/main/java/hudson/plugins/mantis/Updater.java b/src/main/java/hudson/plugins/mantis/Updater.java index 0100a5a..1c42401 100644 --- a/src/main/java/hudson/plugins/mantis/Updater.java +++ b/src/main/java/hudson/plugins/mantis/Updater.java @@ -8,6 +8,8 @@ import hudson.plugins.mantis.changeset.ChangeSet; import hudson.plugins.mantis.changeset.ChangeSetFactory; import hudson.plugins.mantis.model.MantisIssue; +import hudson.plugins.mantis.model.MantisIssueResolution; +import hudson.plugins.mantis.model.MantisIssueStatus; import hudson.scm.ChangeLogSet.Entry; import java.io.PrintStream; @@ -69,8 +71,15 @@ 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()); + site.addNote(changeSet.getId(), text, property.isKeepNotePrivate()); + + if (property.isSetStatusResolved() && issue.getStatus() != MantisIssueStatus.RESOLVED) { + MantisIssue resolvedIssue = createResolvedIssue(issue); + site.updateIssue(resolvedIssue); + } + Utility.log(logger, Messages.Updater_Updating(changeSet.getId())); } issues.add(issue); @@ -88,6 +97,11 @@ boolean perform(final AbstractBuild build, final BuildListener listener) { return true; } + private MantisIssue createResolvedIssue(MantisIssue issue) { + return new MantisIssue(issue.getId(), issue.getProject(), issue.getCategory(), issue.getDescription(), + issue.getDescription(), issue.getViewState(), MantisIssueStatus.RESOLVED, MantisIssueResolution.FIXED); + } + private String createUpdateText(final AbstractBuild build, final ChangeSet changeSet, final String rootUrl) { final String prjName = build.getProject().getName(); final int prjNumber = build.getNumber(); diff --git a/src/main/java/hudson/plugins/mantis/model/MantisIssue.java b/src/main/java/hudson/plugins/mantis/model/MantisIssue.java index de35f46..9f715b6 100644 --- a/src/main/java/hudson/plugins/mantis/model/MantisIssue.java +++ b/src/main/java/hudson/plugins/mantis/model/MantisIssue.java @@ -5,6 +5,7 @@ * * @author Seiji Sogabe */ + import java.io.Serializable; public final class MantisIssue implements Serializable { @@ -20,9 +21,13 @@ public final class MantisIssue implements Serializable { private MantisProject project; private MantisCategory category; - + private MantisViewState viewState; + private MantisIssueStatus status; + + private MantisIssueResolution resolution; + public int getId() { return id; } @@ -43,21 +48,29 @@ public MantisProject getProject() { return project; } - public MantisIssue(final int id, final String summary) { - this.id = id; - this.summary = summary; + public MantisIssueStatus getStatus() { + return status; } public MantisViewState getViewState() { return viewState; } - public MantisIssue(MantisProject project, MantisCategory category, String summary, - String description, MantisViewState viewState) { + public MantisIssueResolution getResolution() { + return resolution; + } + + public MantisIssue(final int id, MantisProject project, MantisCategory category, String summary, + String description, MantisViewState viewState, MantisIssueStatus status, MantisIssueResolution resolution) { + this.id = id; this.summary = summary; this.description = description; this.project = project; this.category = category; this.viewState = viewState; + this.status = status; + this.resolution = resolution; } + + } diff --git a/src/main/java/hudson/plugins/mantis/model/MantisIssueResolution.java b/src/main/java/hudson/plugins/mantis/model/MantisIssueResolution.java new file mode 100644 index 0000000..afe91d3 --- /dev/null +++ b/src/main/java/hudson/plugins/mantis/model/MantisIssueResolution.java @@ -0,0 +1,30 @@ +package hudson.plugins.mantis.model; + +/** + * View State for Issue and Note. + * + * @author Seiji Sogabe + */ +public enum MantisIssueResolution { + + FIXED(20); + + private int code; + + MantisIssueResolution(final int code) { + this.code = code; + } + + public static MantisIssueResolution fromCode(int code) { + switch (code) { + case 20: + return FIXED; + default: + return null; + } + } + + public int getCode() { + return code; + } +} diff --git a/src/main/java/hudson/plugins/mantis/model/MantisIssueStatus.java b/src/main/java/hudson/plugins/mantis/model/MantisIssueStatus.java new file mode 100644 index 0000000..ba2f9b1 --- /dev/null +++ b/src/main/java/hudson/plugins/mantis/model/MantisIssueStatus.java @@ -0,0 +1,42 @@ +package hudson.plugins.mantis.model; + +public enum MantisIssueStatus { + + + FEEDBACK(20), + ACKNOWLEDGED(30), + CONFIRMED(40), + ASSIGNED(50), + RESOLVED(80), + CLOSED(90); + + private int code; + + MantisIssueStatus(final int code) { + this.code = code; + } + + + public static MantisIssueStatus fromCode(int code) { + switch (code) { + case 20: + return FEEDBACK; + case 30: + return ACKNOWLEDGED; + case 40: + return CONFIRMED; + case 50: + return ASSIGNED; + case 80: + return RESOLVED; + case 90: + return CLOSED; + default: + return null; + } + } + + public int getCode() { + return code; + } +} diff --git a/src/main/java/hudson/plugins/mantis/model/MantisViewState.java b/src/main/java/hudson/plugins/mantis/model/MantisViewState.java index 7c418a2..ee0eb76 100644 --- a/src/main/java/hudson/plugins/mantis/model/MantisViewState.java +++ b/src/main/java/hudson/plugins/mantis/model/MantisViewState.java @@ -12,10 +12,21 @@ public enum MantisViewState { private int code; - private MantisViewState(final int code) { + MantisViewState(final int code) { this.code = code; } + public static MantisViewState fromCode(int code) { + switch (code) { + case 10: + return PUBLIC; + case 50: + return PRIVATE; + default: + return null; + } + } + public int getCode() { return code; } diff --git a/src/main/java/hudson/plugins/mantis/soap/MantisSession.java b/src/main/java/hudson/plugins/mantis/soap/MantisSession.java index 60f419b..9318064 100644 --- a/src/main/java/hudson/plugins/mantis/soap/MantisSession.java +++ b/src/main/java/hudson/plugins/mantis/soap/MantisSession.java @@ -24,4 +24,6 @@ public interface MantisSession { List getCategories(int projectId) throws MantisHandlingException; int addIssue(MantisIssue issue) throws MantisHandlingException; + + void updateIssue(MantisIssue issue) throws MantisHandlingException; } diff --git a/src/main/java/hudson/plugins/mantis/soap/mantis110/MantisSessionImpl.java b/src/main/java/hudson/plugins/mantis/soap/mantis110/MantisSessionImpl.java index c1c2ffb..e3e4524 100644 --- a/src/main/java/hudson/plugins/mantis/soap/mantis110/MantisSessionImpl.java +++ b/src/main/java/hudson/plugins/mantis/soap/mantis110/MantisSessionImpl.java @@ -2,11 +2,9 @@ import hudson.plugins.mantis.MantisHandlingException; import hudson.plugins.mantis.MantisSite; -import hudson.plugins.mantis.model.MantisCategory; -import hudson.plugins.mantis.model.MantisIssue; -import hudson.plugins.mantis.model.MantisNote; -import hudson.plugins.mantis.model.MantisProject; +import hudson.plugins.mantis.model.*; import hudson.plugins.mantis.soap.AbstractMantisSession; + import java.math.BigInteger; import java.net.MalformedURLException; import java.net.URL; @@ -15,6 +13,7 @@ import java.util.List; import java.util.logging.Logger; import javax.xml.rpc.ServiceException; + import org.apache.axis.AxisProperties; import org.apache.axis.EngineConfiguration; import org.apache.axis.client.AxisClient; @@ -65,7 +64,11 @@ public MantisIssue getIssue(final int id) throws MantisHandlingException { throw new MantisHandlingException(e); } - return new MantisIssue(id, data.getSummary()); + return new MantisIssue(id, new MantisProject(data.getProject().getId().intValue(), data.getProject().getName()), + new MantisCategory(data.getCategory()), data.getSummary(), data.getDescription(), + MantisViewState.fromCode(data.getView_state().getId().intValue()), + MantisIssueStatus.fromCode(data.getStatus().getId().intValue()), + MantisIssueResolution.fromCode(data.getStatus().getId().intValue())); } public void addNote(final int id, final MantisNote note) @@ -164,5 +167,41 @@ public int addIssue(MantisIssue issue) throws MantisHandlingException { return addedIssueNo.intValue(); } + @Override + public void updateIssue(MantisIssue issue) throws MantisHandlingException { + if (issue == null) { + throw new MantisHandlingException("issue should not be null."); + } + IssueData data = new IssueData(); + + MantisProject project = issue.getProject(); + if (project == null) { + throw new MantisHandlingException("project is missing."); + } + MantisCategory category = issue.getCategory(); + if (category == null) { + throw new MantisHandlingException("category is missing."); + } + + data.setId(BigInteger.valueOf(issue.getId())); + ObjectRef pRef = new ObjectRef(BigInteger.valueOf(project.getId()), project.getName()); + data.setProject(pRef); + data.setCategory(category.getName()); + data.setSummary(issue.getSummary()); + data.setDescription(issue.getDescription()); + ObjectRef viewStateRef = new ObjectRef(BigInteger.valueOf(issue.getViewState().getCode()), null); + data.setView_state(viewStateRef); + ObjectRef statusRef = new ObjectRef(BigInteger.valueOf(issue.getStatus().getCode()), null); + data.setStatus(statusRef); + ObjectRef resolutionRef = new ObjectRef(BigInteger.valueOf(issue.getResolution().getCode()), null); + data.setResolution(resolutionRef); + + try { + portType.mc_issue_update(site.getUserName(), site.getPlainPassword(), BigInteger.valueOf(issue.getId()), data); + } catch (RemoteException e) { + throw new MantisHandlingException(e); + } + } + private static final Logger LOGGER = Logger.getLogger(MantisSessionImpl.class.getName()); } diff --git a/src/main/java/hudson/plugins/mantis/soap/mantis120/MantisSessionImpl.java b/src/main/java/hudson/plugins/mantis/soap/mantis120/MantisSessionImpl.java index af7b17a..0c0fd84 100644 --- a/src/main/java/hudson/plugins/mantis/soap/mantis120/MantisSessionImpl.java +++ b/src/main/java/hudson/plugins/mantis/soap/mantis120/MantisSessionImpl.java @@ -2,11 +2,9 @@ import hudson.plugins.mantis.MantisHandlingException; import hudson.plugins.mantis.MantisSite; -import hudson.plugins.mantis.model.MantisCategory; -import hudson.plugins.mantis.model.MantisIssue; -import hudson.plugins.mantis.model.MantisNote; -import hudson.plugins.mantis.model.MantisProject; +import hudson.plugins.mantis.model.*; import hudson.plugins.mantis.soap.AbstractMantisSession; + import java.math.BigInteger; import java.net.MalformedURLException; import java.net.URL; @@ -15,6 +13,7 @@ import java.util.List; import java.util.logging.Logger; import javax.xml.rpc.ServiceException; + import org.apache.axis.AxisProperties; import org.apache.axis.EngineConfiguration; import org.apache.axis.client.AxisClient; @@ -64,7 +63,11 @@ public MantisIssue getIssue(final int id) throws MantisHandlingException { throw new MantisHandlingException(e); } - return new MantisIssue(id, data.getSummary()); + return new MantisIssue(id, new MantisProject(data.getProject().getId().intValue(), data.getProject().getName()), + new MantisCategory(data.getCategory()), data.getSummary(), data.getDescription(), + MantisViewState.fromCode(data.getView_state().getId().intValue()), + MantisIssueStatus.fromCode(data.getStatus().getId().intValue()), + MantisIssueResolution.fromCode(data.getStatus().getId().intValue())); } public void addNote(final int id, final MantisNote note) @@ -163,5 +166,41 @@ public int addIssue(MantisIssue issue) throws MantisHandlingException { return addedIssueNo.intValue(); } + @Override + public void updateIssue(MantisIssue issue) throws MantisHandlingException { + if (issue == null) { + throw new MantisHandlingException("issue should not be null."); + } + IssueData data = new IssueData(); + + MantisProject project = issue.getProject(); + if (project == null) { + throw new MantisHandlingException("project is missing."); + } + MantisCategory category = issue.getCategory(); + if (category == null) { + throw new MantisHandlingException("category is missing."); + } + + data.setId(BigInteger.valueOf(issue.getId())); + ObjectRef pRef = new ObjectRef(BigInteger.valueOf(project.getId()), project.getName()); + data.setProject(pRef); + data.setCategory(category.getName()); + data.setSummary(issue.getSummary()); + data.setDescription(issue.getDescription()); + ObjectRef viewStateRef = new ObjectRef(BigInteger.valueOf(issue.getViewState().getCode()), null); + data.setView_state(viewStateRef); + ObjectRef statusRef = new ObjectRef(BigInteger.valueOf(issue.getStatus().getCode()), null); + data.setStatus(statusRef); + ObjectRef resolutionRef = new ObjectRef(BigInteger.valueOf(issue.getResolution().getCode()), null); + data.setResolution(resolutionRef); + + try { + portType.mc_issue_update(site.getUserName(), site.getPlainPassword(), BigInteger.valueOf(issue.getId()), data); + } catch (RemoteException e) { + throw new MantisHandlingException(e); + } + } + private static final Logger LOGGER = Logger.getLogger(MantisSessionImpl.class.getName()); } diff --git a/src/main/resources/hudson/plugins/mantis/MantisIssueUpdater/config.jelly b/src/main/resources/hudson/plugins/mantis/MantisIssueUpdater/config.jelly index cf38f1e..75a984a 100644 --- a/src/main/resources/hudson/plugins/mantis/MantisIssueUpdater/config.jelly +++ b/src/main/resources/hudson/plugins/mantis/MantisIssueUpdater/config.jelly @@ -1,5 +1,11 @@ + + +