Author: tchemit Date: 2012-03-25 17:48:53 +0200 (Sun, 25 Mar 2012) New Revision: 257 Url: http://nuiton.org/repositories/revision/jredmine/257 Log: refs #2030 (introduce the jersey api, and change redmine service api to no more have RestClient api pubic, apply it to mojo) Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousServiceJersey.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementorJersey.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceJersey.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/FakeRedmineServiceConfiguration.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceJerseyTest.java Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/AbstractRedmineServiceTest.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/TestHelper.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojo.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/GenerateChangesMojo.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/IssuesCollector.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/LoginMojo.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/NextVersionMojo.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishAttachmentsMojo.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishNewsMojo.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AbstractAnnouncementMojo.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractIssuesReport.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractRedmineReport.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/IssueReportGenerator.java Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java 2012-03-25 15:48:53 UTC (rev 257) @@ -26,8 +26,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.io.rest.RestClient; -import org.nuiton.io.rest.RestClientConfiguration; import org.nuiton.jredmine.model.Attachment; import org.nuiton.jredmine.model.Issue; import org.nuiton.jredmine.model.IssueCategory; @@ -50,7 +48,7 @@ * * @author tchemit <chemit@codelutin.com> * @plexus.component role="org.nuiton.jredmine.RedmineAnonymousService" role-hint="default" - * @see RestClientConfiguration#isAnonymous() + * @see RedmineServiceConfiguration#isAnonymous() * @since 1.0.3 */ public class DefaultRedmineAnonymousService implements RedmineServiceImplementor, RedmineAnonymousService { @@ -207,7 +205,7 @@ /// RedmineServiceImplementor implementation /////////////////////////////////////////////////////////////////////////// @Override - public RedmineServiceImplementor init(RestClientConfiguration configuration) throws RedmineServiceException { + public RedmineServiceImplementor init(RedmineServiceConfiguration configuration) throws RedmineServiceException { // Force to not be loggued configuration.setAnonymous(true); if (log.isDebugEnabled()) { @@ -217,13 +215,18 @@ return result; } +// @Override +// public RedmineServiceImplementor init(RestClient session) throws RedmineServiceException { +// if (log.isDebugEnabled()) { +// log.debug("init session for " + this); +// } +// checkNotLoggued(session); +// return delegateImplementor.init(session); +// } + @Override - public RedmineServiceImplementor init(RestClient session) throws RedmineServiceException { - if (log.isDebugEnabled()) { - log.debug("init session for " + this); - } - checkNotLoggued(session); - return delegateImplementor.init(session); + public int ping() { + return delegateImplementor.ping(); } @Override @@ -265,8 +268,8 @@ } @Override - public void checkNotLoggued(RestClient session) throws IllegalStateException, RedmineServiceLoginException, NullPointerException { - delegateImplementor.checkNotLoggued(session); + public void checkNotLoggued() throws IllegalStateException, RedmineServiceLoginException, NullPointerException { + delegateImplementor.checkNotLoggued(); } @Override Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java 2012-03-25 15:48:53 UTC (rev 257) @@ -27,7 +27,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.io.rest.RestClient; -import org.nuiton.io.rest.RestClientConfiguration; import org.nuiton.jredmine.model.Attachment; import org.nuiton.jredmine.model.News; import org.nuiton.jredmine.model.Project; @@ -50,15 +49,15 @@ /// RedmineServiceImplementor implementation /////////////////////////////////////////////////////////////////////////// @Override - public RedmineServiceImplementor init(RestClientConfiguration configuration) throws RedmineServiceException { + public RedmineServiceImplementor init(RedmineServiceConfiguration configuration) throws RedmineServiceException { RedmineServiceImplementor result = delegateImplementor.init(configuration); return result; } - @Override - public RedmineServiceImplementor init(RestClient session) throws RedmineServiceException { - return delegateImplementor.init(session); - } +// @Override +// public RedmineServiceImplementor init(RestClient session) throws RedmineServiceException { +// return delegateImplementor.init(session); +// } /////////////////////////////////////////////////////////////////////////// /// RedmineLogguedService implementation Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java 2012-03-25 15:48:53 UTC (rev 257) @@ -27,7 +27,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.io.rest.RestClient; -import org.nuiton.io.rest.RestClientConfiguration; import org.nuiton.io.rest.RestException; import org.nuiton.io.rest.RestRequest; import org.nuiton.jredmine.model.io.xpp3.RedmineXpp3Helper; @@ -82,13 +81,12 @@ } @Override - public RedmineServiceImplementor init(RestClientConfiguration configuration) throws RedmineServiceException { + public RedmineServiceImplementor init(RedmineServiceConfiguration configuration) throws RedmineServiceException { session.setConfiguration(configuration); RedmineServiceImplementor result = init(session); return result; } - @Override public RedmineServiceImplementor init(RestClient session) throws RedmineServiceException { if (init) { throw new IllegalStateException( @@ -110,6 +108,11 @@ } @Override + public int ping() { + return 0; + } + + @Override public void destroy() throws RedmineServiceException { checkInit(); try { @@ -183,7 +186,7 @@ } @Override - public void checkNotLoggued(RestClient session) throws RedmineServiceLoginException, NullPointerException { + public void checkNotLoggued() throws RedmineServiceLoginException, NullPointerException { // checkInit(); checkSessionNotNull(session); checkSessionConfigurationNotNull(session); Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousServiceJersey.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousServiceJersey.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousServiceJersey.java 2012-03-25 15:48:53 UTC (rev 257) @@ -0,0 +1,300 @@ +/* + * #%L + * JRedmine :: Client + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.jredmine; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.io.rest.RestClient; +import org.nuiton.io.rest.RestClientConfiguration; +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.IssueCategory; +import org.nuiton.jredmine.model.IssuePriority; +import org.nuiton.jredmine.model.IssueStatus; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Tracker; +import org.nuiton.jredmine.model.User; +import org.nuiton.jredmine.model.Version; + +import static org.nuiton.jredmine.request.RedmineRequestFactory.DEFAULT_REQUESTS; + +/** + * Implemntation of the {@link RedmineAnonymousService} using Jersey for REST + * query instead of the {@link RestClient} api. + * + * @author tchemit <chemit@codelutin.com> + * @plexus.component role="org.nuiton.jredmine.RedmineAnonymousService" role-hint="jersey" + * @see RestClientConfiguration#isAnonymous() + * @since 1.4 + */ +public class RedmineAnonymousServiceJersey implements RedmineServiceImplementor, RedmineAnonymousService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(RedmineAnonymousServiceJersey.class); + + /** @plexus.requirement role="org.nuiton.jredmine.RedmineServiceImplementor" role-hint="jersey" */ + protected RedmineServiceImplementor delegateImplementor; + + public RedmineAnonymousServiceJersey() { + } + + /////////////////////////////////////////////////////////////////////////// + /// RedmineAnonymousService implementation + /////////////////////////////////////////////////////////////////////////// + + @Override + public IssueStatus[] getIssueStatuses() throws RedmineServiceException { + return getDatas(DEFAULT_REQUESTS.GET_ISSUE_STATUS_LIST.requestName(), + IssueStatus.class + ); + } + + @Override + public IssuePriority[] getIssuePriorities() throws RedmineServiceException { + return getDatas(DEFAULT_REQUESTS.GET_ISSUE_PRIORITY_LIST, + IssuePriority.class + ); + } + + @Override + public Project[] getProjects() throws RedmineServiceException { + return getDatas(DEFAULT_REQUESTS.GET_PROJECT_LIST, Project.class); + } + + @Override + public IssueCategory[] getIssueCategories(String projectName) throws RedmineServiceException { + return getDatas(DEFAULT_REQUESTS.GET_ISSUE_CATEGORY_LIST, + IssueCategory.class, + projectName + ); + } + + @Override + public Project getProject(String projectName) throws RedmineServiceException { + return getData(DEFAULT_REQUESTS.GET_PROJECT, + Project.class, + projectName + ); + } + + @Override + public Tracker[] getTrackers(String projectName) throws RedmineServiceException { + return getDatas(DEFAULT_REQUESTS.GET_TRACKER_LIST, + Tracker.class, + projectName + ); + } + + @Override + public News[] getNews(String projectName) throws RedmineServiceException { + return getDatas(DEFAULT_REQUESTS.GET_NEWS_LIST, + News.class, + projectName + ); + } + + @Override + public User[] getProjectMembers(String projectName) throws RedmineServiceException { + return getDatas(DEFAULT_REQUESTS.GET_USER_LIST, + User.class, + projectName + ); + } + + @Override + public Version[] getVersions(String projectName) throws RedmineServiceException { + return getDatas(DEFAULT_REQUESTS.GET_VERSION_LIST, + Version.class, + projectName + ); + } + + @Override + public Version getVersion(String projectName, + String versionName) throws RedmineServiceException { + return getData(DEFAULT_REQUESTS.GET_VERSION, + Version.class, + projectName, + versionName + ); + } + + @Override + public Attachment[] getAttachments(String projectName, + String versionName) throws RedmineServiceException { + return getDatas(DEFAULT_REQUESTS.GET_ATTACHMENTS_LIST, + Attachment.class, + projectName, + versionName + ); + } + + @Override + public Issue[] getIssues(String projectName, + String versionName) throws RedmineServiceException { + return getDatas(DEFAULT_REQUESTS.GET_ISSUE_LIST, + Issue.class, + projectName, + versionName + ); + } + + @Override + public TimeEntry[] getIssueTimeEntries(String projectName, + String issueId) throws RedmineServiceException { + return getDatas(DEFAULT_REQUESTS.GET_ISSUE_TIME_ENTRY_LIST, + TimeEntry.class, + projectName, + issueId + ); + } + + @Override + public Issue[] getIssues(String projectName) throws RedmineServiceException { + Issue[] result = getDatas(DEFAULT_REQUESTS.GET_PROJECT_ISSUES, + Issue.class, + projectName + ); + return result; + } + + @Override + public Issue[] getOpenedIssues(String projectName) throws RedmineServiceException { + Issue[] result = getDatas(DEFAULT_REQUESTS.GET_PROJECT_OPENED_ISSUES, + Issue.class, + projectName + ); + return result; + } + + @Override + public Issue[] getClosedIssues(String projectName) throws RedmineServiceException { + Issue[] result = getDatas(DEFAULT_REQUESTS.GET_PROJECT_CLOSED_ISSUES, + Issue.class, + projectName + ); + return result; + } + + /////////////////////////////////////////////////////////////////////////// + /// RedmineServiceImplementor implementation + /////////////////////////////////////////////////////////////////////////// + @Override + public RedmineServiceImplementor init(RedmineServiceConfiguration configuration) throws RedmineServiceException { + // Force to not be loggued + configuration.setAnonymous(true); + if (log.isDebugEnabled()) { + log.debug("init configuration for " + this); + } + RedmineServiceImplementor result = delegateImplementor.init(configuration); + return result; + } + + @Override + public int ping() { + int status = delegateImplementor.ping(); + return status; + } + + @Override + public <T> T getData(String requestName, + Class<T> type, + Object... args) throws RedmineServiceException { + return delegateImplementor.getData(requestName, type, args); + } + + @Override + public <T> T[] getDatas(String requestName, + Class<T> type, + Object... args) throws RedmineServiceException { + return delegateImplementor.getDatas(requestName, type, args); + } + + @Override + public <T> T sendData(String requestName, + Class<T> klazz, + Object... args) throws RedmineServiceException { + return delegateImplementor.sendData(requestName, klazz, args); + } + + @Override + public <T> T[] sendDatas(String requestName, + Class<T> klazz, + Object... args) throws RedmineServiceException { + return delegateImplementor.sendDatas(requestName, klazz, args); + } + + @Override + public boolean isInit() { + return delegateImplementor.isInit(); + } + + @Override + public void destroy() throws RedmineServiceException { + delegateImplementor.destroy(); + } + + @Override + public void checkNotLoggued() throws IllegalStateException, RedmineServiceLoginException, NullPointerException { + delegateImplementor.checkNotLoggued(); + } + + @Override + public void checkLoggued() throws IllegalStateException, RedmineServiceLoginException, NullPointerException { + delegateImplementor.checkLoggued(); + } + + /////////////////////////////////////////////////////////////////////////// + /// Internal methods + /////////////////////////////////////////////////////////////////////////// + + protected <T> T getData(DEFAULT_REQUESTS request, + Class<T> type, + Object... args) throws RedmineServiceException { + return delegateImplementor.getData(request.requestName(), type, args); + } + + protected <T> T[] getDatas(DEFAULT_REQUESTS request, + Class<T> type, + Object... args) throws RedmineServiceException { + return delegateImplementor.getDatas(request.requestName(), type, args); + } + + protected <T> T sendData(DEFAULT_REQUESTS request, + Class<T> klazz, + Object... args) throws RedmineServiceException { + return delegateImplementor.sendData(request.requestName(), klazz, args); + } + + protected <T> T[] sendDatas(DEFAULT_REQUESTS request, + Class<T> klazz, + Object... args) throws RedmineServiceException { + return delegateImplementor.sendDatas(request.requestName(), klazz, args); + } + +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousServiceJersey.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java 2012-03-25 15:48:53 UTC (rev 257) @@ -0,0 +1,62 @@ +/* + * #%L + * JRedmine :: Client + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.jredmine; + +import org.nuiton.io.rest.RestClientConfiguration; + +import java.net.URL; + +/** + * Contract of a redmine service configuration. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public interface RedmineServiceConfiguration extends RestClientConfiguration { + + String getEncoding(); + + void setEncoding(String encoding); + + String getRestPassword(); + + void setRestPassword(String restPassword); + + URL getRestUrl(); + + void setRestUrl(URL restUrl); + + String getRestUsername(); + + void setRestUsername(String restUsername); + + boolean isVerbose(); + + void setVerbose(boolean verbose); + + boolean isAnonymous(); + + void setAnonymous(boolean anonymous); +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java 2012-03-25 15:48:53 UTC (rev 257) @@ -24,8 +24,6 @@ */ package org.nuiton.jredmine; -import org.nuiton.io.rest.RestClient; -import org.nuiton.io.rest.RestClientConfiguration; import org.nuiton.jredmine.rest.RedmineRestClient; /** @@ -51,23 +49,13 @@ boolean isInit(); /** - * Initialize the service given a redmine client already initialized. - * - * @param session the redmine client to be used by the service - * @return the initialized service - * @throws RedmineServiceException if any pb - * @see RedmineRestClient - */ - RedmineServiceImplementor init(RestClient session) throws RedmineServiceException; - - /** * Initialize the service given a client configuration. * * @param configuration the configuration to be used to init the internal redmine client * @return the initialized service * @throws RedmineServiceException if any pb */ - RedmineServiceImplementor init(RestClientConfiguration configuration) throws RedmineServiceException; + RedmineServiceImplementor init(RedmineServiceConfiguration configuration) throws RedmineServiceException; /** * Close the service and destroy any connexion to the redmine service. @@ -77,6 +65,14 @@ void destroy() throws RedmineServiceException; /** + * Try to ping the redmine remote service and return his status. + * + * @return status code of the ping request, or {@code -1} if something was + * wrong (unknown host,...). + */ + int ping(); + + /** * Generic method to obtain a single data from a redmine server. * * @param <T> the type of data to obtain @@ -139,9 +135,8 @@ /** * Checks if the current session is anonymous. * - * @param session the session to test * @throws RedmineServiceLoginException if not anonymous * @throws NullPointerException if something is null */ - void checkNotLoggued(RestClient session) throws RedmineServiceLoginException, NullPointerException; + void checkNotLoggued() throws RedmineServiceLoginException, NullPointerException; } Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementorJersey.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementorJersey.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementorJersey.java 2012-03-25 15:48:53 UTC (rev 257) @@ -0,0 +1,355 @@ +/* + * #%L + * JRedmine :: Client + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.jredmine; + +import com.google.common.base.Preconditions; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientHandlerException; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.core.util.MultivaluedMapImpl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.io.rest.RestClientConfiguration; +import org.nuiton.jredmine.model.io.xpp3.RedmineXpp3Helper; +import org.nuiton.jredmine.request.RedmineRequest; +import org.nuiton.jredmine.request.RedmineRequestFactory; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import java.io.File; +import java.io.InputStream; +import java.util.Map; + +/** + * Implementation of {@link RedmineServiceImplementor} using Jersey REST api. + * + * @author tchemit <chemit@codelutin.com> + * @plexus.component role="org.nuiton.jredmine.RedmineServiceImplementor" role-hint="jersey" + * @see RedmineServiceImplementor + * @since 1.4 + */ +public class RedmineServiceImplementorJersey implements RedmineServiceImplementor { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(RedmineServiceImplementorJersey.class); + + protected RestClientConfiguration configuration; + + /** request factory. */ + protected final RedmineRequestFactory requestFactory; + + /** xpp3Helper to transform xml stream to pojo */ + protected final RedmineXpp3Helper xpp3Helper; + + protected Client client; + + /** internal state to known if service was init */ + protected boolean init; + + public RedmineServiceImplementorJersey() { + xpp3Helper = new RedmineXpp3Helper(); + requestFactory = new RedmineRequestFactory(); + requestFactory.addDefaultRequests(); + } + + /////////////////////////////////////////////////////////////////////////// + /// RedmineServiceImplementor implementation + /////////////////////////////////////////////////////////////////////////// + + @Override + public boolean isInit() { + return init; + } + + @Override + public RedmineServiceImplementor init(RedmineServiceConfiguration configuration) throws RedmineServiceException { + Preconditions.checkNotNull(configuration); + this.configuration = configuration; + client = Client.create(); + init = true; + return this; + } + + @Override + public void destroy() throws RedmineServiceException { + checkInit(); + init = false; + configuration = null; + client.destroy(); + client = null; + } + + @Override + public <T> T getData(String requestName, + Class<T> type, + Object... args) throws RedmineServiceException { + checkInit(); + InputStream stream = askDataStream(requestName, args); + T result = getDataFromStream(type, stream); + return result; + } + + @Override + public <T> T[] getDatas(String requestName, + Class<T> type, + Object... args) throws RedmineServiceException { + checkInit(); + InputStream stream = askDataStream(requestName, args); + T[] result = getDatasFromStream(type, stream); + return result; + } + + @Override + public <T> T sendData(String requestName, + Class<T> klazz, + Object... args) throws RedmineServiceException { + checkLoggued(); + InputStream stream = sendDataStream(requestName, args); + T result = getDataFromStream(klazz, stream); + return result; + } + + @Override + public <T> T[] sendDatas(String requestName, + Class<T> klazz, + Object... args) throws RedmineServiceException { + checkLoggued(); + InputStream stream = sendDataStream(requestName, args); + T[] result = getDatasFromStream(klazz, stream); + return result; + } + + @Override + public void checkLoggued() throws IllegalStateException, RedmineServiceLoginException, NullPointerException { + checkInit(); + //TODO + } + + @Override + public void checkNotLoggued() throws RedmineServiceLoginException, NullPointerException { + checkInit(); + //TODO + } + + @Override + public int ping() { + WebResource request = requestToWebResource("ping"); + int status; + try { + ClientResponse clientResponse = request.head(); + status = clientResponse.getStatus(); + } catch (ClientHandlerException e) { + if (log.isErrorEnabled()) { + log.error("Could not ping " + request.toString(), e); + } + status = -1; + } + return status; + } + + protected <T> T getDataFromStream(Class<T> type, + InputStream stream) throws RedmineServiceException { + if (stream == null) { + return null; + } + + try { + T result = xpp3Helper.readObject(type, stream, true); + return result; + } catch (Exception ex) { + throw new RedmineServiceException( + "could not obtain datas of type " + type + " for reason " + + ex.getMessage(), ex); + } + } + + protected <T> T[] getDatasFromStream(Class<T> type, + InputStream stream) throws RedmineServiceException { + if (stream == null) { + return null; + } + try { + T[] result = xpp3Helper.readObjects(type, stream, true); + return result; + } catch (Exception ex) { + throw new RedmineServiceException( + "could not obtain datas of type " + type + " for reason " + + ex.getMessage(), ex); + } + } + + protected InputStream askDataStream(String requestName, + Object... args) throws RedmineServiceException { + + try { + + // get the webresource to grab + WebResource webResource = requestToWebResource(requestName, args); + + // transform it to a input stream + InputStream result = webResource.accept( + MediaType.APPLICATION_XML_TYPE). + get(InputStream.class); + return result; + } catch (Exception e) { + throw new RedmineServiceException( + "could not obtain data stream for request " + requestName + + " for reason " + e.getMessage(), e); + } + } + + protected WebResource requestToWebResource(String requestName, + Object... args) { + + RedmineRequest request = requestFactory.getRequest(requestName, args); + + String url = configuration.getRestUrl().toString(); + for (String path : request.getPath()) { + url += '/' + path; + } + WebResource result = client.resource(url); + String[] parameters = request.getParameters(); + Map<String, File> attachments = request.getAttachments(); + + if (attachments == null) { + + // not a multi-part request + + if (parameters.length > 0) { + + MultivaluedMap<String, String> params = new MultivaluedMapImpl(); + + // add parameters + + int nbParams = parameters.length / 2; + for (int i = 0; i < nbParams; i++) { + String key = parameters[2 * i]; + String value = parameters[2 * i + 1]; + if (value == null) { + if (log.isDebugEnabled()) { + log.debug("skip null parameter " + key); + } + continue; + } + params.add(key, value); + } + result = result.queryParams(params); + } + } else { + + // multi-part request + +// List<Part> paramParts = new ArrayList<Part>(); +// +// if (parameters.length > 0) { +// +// // add parameters as part of multi-part +// +// int nbParams = parameters.length / 2; +// for (int i = 0; i < nbParams; i++) { +// String key = parameters[2 * i]; +// String value = parameters[2 * i + 1]; +// if (value == null) { +// if (log.isDebugEnabled()) { +// log.debug("skip null parameter " + key); +// } +// continue; +// } +// paramParts.add(new StringPart(key, value)); +// if (log.isDebugEnabled()) { +// log.debug("add parameter [" + key + "]=" + value); +// } +// } +// } +// +// // add file parts +// for (Map.Entry<String, File> entry : attachments.entrySet()) { +// String key = entry.getKey(); +// File file = entry.getValue(); +// if (log.isDebugEnabled()) { +// log.debug("add attachment " + key + "=" + file); +// } +// paramParts.add(new FilePart( +// key, +// file.getName(), +// file, +// FilePart.DEFAULT_CONTENT_TYPE, +// configuration.getEncoding()) +// ); +// } +// if (attachments.isEmpty()) { +// log.warn("no attachment in a multi-part request!"); +// } +// +// Part[] parts = paramParts.toArray(new Part[paramParts.size()]); +// +// MultipartRequestEntity entity = +// new MultipartRequestEntity(parts, gm.getParams()); +// if (log.isDebugEnabled()) { +// entity.writeRequest(System.out); +// } +// gm.setRequestEntity(entity); +//// gm.addRequestHeader("content-type", "multipart/form-data"); +// gm.addRequestHeader("content-type", entity.getContentType()); +// gm.addRequestHeader("content-length", entity.getContentLength() + +// ""); +// if (showRequest) { +// log.info("content-type : " + entity.getContentType() + +// ", content-length : " + entity.getContentLength()); +// } + } + if (log.isInfoEnabled()) { + log.info("request = " + result.toString()); + } + return result; + } + + protected InputStream sendDataStream(String requestName, + Object... args) throws RedmineServiceException { + +// RestRequest request = requestFactory.getRequest(requestName, args); + + // obtain data from rest client + try { + +// InputStream stream = session.sendData(r); + InputStream stream = null; + return stream; + } catch (Exception e) { + throw new RedmineServiceException( + "could not send data stream for request " + requestName + + " for reason " + e.getMessage(), e); + } + } + + protected void checkInit() throws IllegalStateException { + if (!init) { + throw new IllegalStateException( + "the client " + this + " is not init!"); + } + } +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementorJersey.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceJersey.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceJersey.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceJersey.java 2012-03-25 15:48:53 UTC (rev 257) @@ -0,0 +1,112 @@ +package org.nuiton.jredmine; + +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Version; + +import static org.nuiton.jredmine.request.RedmineRequestFactory.DEFAULT_REQUESTS; + +/** + * Implementation fo the {@link RedmineService} using Jersey REST layer. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class RedmineServiceJersey extends RedmineAnonymousServiceJersey implements RedmineService { + + /////////////////////////////////////////////////////////////////////////// + /// RedmineLogguedService implementation + /////////////////////////////////////////////////////////////////////////// + + @Override + public Project[] getUserProjects() throws RedmineServiceException { + checkLoggued(); + Project[] result = getDatas(DEFAULT_REQUESTS.GET_USER_PROJECTS, + Project.class); + return result; + } + + @Override + public Version addVersion(String projectName, + Version version) throws RedmineServiceException { + + // send data and obtain created version + Version result = sendData(DEFAULT_REQUESTS.ADD_VERSION, + Version.class, + projectName, + version + ); + return result; + } + + @Override + public Version updateVersion(String projectName, + Version version) throws RedmineServiceException { + + // send data and obtain updated version + Version result = sendData(DEFAULT_REQUESTS.UPDATE_VERSION, + Version.class, + projectName, + version + ); + return result; + } + + @Override + public Version nextVersion(String projectName, + String oldVersionName, + Version newVersion) throws RedmineServiceException { + + // send data and obtain updated or created new version + Version result = sendData(DEFAULT_REQUESTS.NEXT_VERSION, + Version.class, + projectName, + newVersion, + oldVersionName + ); + return result; + } + + @Override + public Attachment addAttachment(String projectName, + String versionName, + Attachment attachement) throws RedmineServiceException { + + // send data and obtain created attachment + Attachment result = sendData(DEFAULT_REQUESTS.ADD_ATTACHMENT, + Attachment.class, + projectName, + versionName, + attachement + ); + return result; + } + + @Override + public News addNews(String projectName, + News news) throws RedmineServiceException { + // send data and obtain created news + News result = sendData(DEFAULT_REQUESTS.ADD_NEWS, + News.class, + projectName, + news + ); + return result; + } + + @Override + public TimeEntry addIssueTimeEntry(String projectName, + String issueId, + TimeEntry entry) throws RedmineServiceException { + // send data and obtain updated version + TimeEntry result = sendData(DEFAULT_REQUESTS.ADD_ISSUE_TIME_ENTRY, + TimeEntry.class, + projectName, + issueId, + entry + ); + return result; + } +} Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/AbstractRedmineServiceTest.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/AbstractRedmineServiceTest.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/AbstractRedmineServiceTest.java 2012-03-25 15:48:53 UTC (rev 257) @@ -123,7 +123,7 @@ } protected final S newService() throws Exception { - return serviceType.newInstance(); + return serviceType.getConstructor().newInstance(); } protected RedmineRestClient newClient(RestClientConfiguration configuration) { @@ -159,7 +159,7 @@ service = newService(); - ((RedmineServiceImplementor) service).init(client); + ((DefaultRedmineServiceImplementor) service).init(client); } @After Added: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/FakeRedmineServiceConfiguration.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/FakeRedmineServiceConfiguration.java (rev 0) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/FakeRedmineServiceConfiguration.java 2012-03-25 15:48:53 UTC (rev 257) @@ -0,0 +1,128 @@ +/* + * #%L + * JRedmine :: Client + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.jredmine; + +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +import java.net.URL; + +/** + * Configuration of a redmine service for test purposes. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class FakeRedmineServiceConfiguration implements RedmineServiceConfiguration { + + URL restUrl; + + String restUsername; + + String restPassword; + + boolean verbose; + + boolean anonymous; + + String encoding; + + @Override + public String getEncoding() { + return encoding; + } + + @Override + public void setEncoding(String encoding) { + this.encoding = encoding; + } + + @Override + public String getRestPassword() { + return restPassword; + } + + @Override + public void setRestPassword(String restPassword) { + this.restPassword = restPassword; + } + + @Override + public URL getRestUrl() { + return restUrl; + } + + @Override + public void setRestUrl(URL restUrl) { + this.restUrl = restUrl; + } + + @Override + public String getRestUsername() { + return restUsername; + } + + @Override + public void setRestUsername(String restUsername) { + this.restUsername = restUsername; + } + + @Override + public boolean isVerbose() { + return verbose; + } + + @Override + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + @Override + public boolean isAnonymous() { + return anonymous; + } + + @Override + public void setAnonymous(boolean anonymous) { + this.anonymous = anonymous; + } + + @Override + public String toString() { + ToStringBuilder b = new ToStringBuilder(this, + ToStringStyle.MULTI_LINE_STYLE + ); + b.append("redmineUrl", restUrl); + if (anonymous) { + b.append("anonymous", true); + } else { + b.append("redmineUsername", restUsername); + b.append("redminePassword", "***"); + } + b.append("encoding", encoding); + b.append("verbose", verbose); + return b.toString(); + } +} Property changes on: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/FakeRedmineServiceConfiguration.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceJerseyTest.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceJerseyTest.java (rev 0) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceJerseyTest.java 2012-03-25 15:48:53 UTC (rev 257) @@ -0,0 +1,222 @@ +/* + * #%L + * JRedmine :: Client + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.jredmine; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.After; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.IssueCategory; +import org.nuiton.jredmine.model.IssuePriority; +import org.nuiton.jredmine.model.IssueStatus; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Tracker; +import org.nuiton.jredmine.model.User; +import org.nuiton.jredmine.model.Version; + +import java.net.URL; + +/** + * To test the {@link RedmineAnonymousServiceJersey}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class RedmineAnonymousServiceJerseyTest { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(RedmineAnonymousServiceJerseyTest.class); + + protected static RedmineServiceConfiguration configuration; + + protected RedmineAnonymousServiceJersey service; + + @BeforeClass + public static void beforeClass() throws Exception { + configuration = new FakeRedmineServiceConfiguration(); + configuration.setAnonymous(true); + configuration.setRestUrl(new URL("http://nuiton.org/jredmine")); + configuration.setVerbose(true); + + // test if can access service + RedmineAnonymousServiceJersey service = + new RedmineAnonymousServiceJersey(); + service.delegateImplementor = new RedmineServiceImplementorJersey(); + service.init(configuration); + + int status = service.ping(); + + if (status != 200) { + + // ping was not ok + if (log.isInfoEnabled()) { + log.info("Will skip test " + + RedmineAnonymousServiceJerseyTest.class.getName() + + ", since ping status is " + status + + " (should be 200 to pass tests...)"); + } + } + Assume.assumeTrue(status == 200); + } + + @Before + public void setUp() throws Exception { + + service = new RedmineAnonymousServiceJersey(); + service.delegateImplementor = new RedmineServiceImplementorJersey(); + service.init(configuration); + } + + @After + public void tearDown() throws Exception { + service.destroy(); + } + + @Test + public void getProjects() throws Exception { + Project[] projects = service.getProjects(); + Assert.assertNotNull(projects); + } + + @Test + public void getIssuePriorities() throws Exception { + IssuePriority[] issuePriorities = service.getIssuePriorities(); + Assert.assertNotNull(issuePriorities); + } + + @Test + public void getIssueStatuses() throws Exception { + + IssueStatus[] issueStatuses = service.getIssueStatuses(); + Assert.assertNotNull(issueStatuses); + } + + public static final String PROJECT_NAME = "jredmine"; + + public static final String VERSION_NAME = "1.4"; + + public static final String ISSUE_ID = "2030"; + + @Test + public void getProject() throws Exception { + Project project = service.getProject(PROJECT_NAME); + Assert.assertNotNull(project); + Assert.assertEquals(PROJECT_NAME, project.getName()); + Assert.assertEquals(PROJECT_NAME, project.getIdentifier()); + Assert.assertEquals(true, project.isIsPublic()); + Assert.assertEquals("http://maven-site.nuiton.org/jredmine", + project.getHomepage()); + Assert.assertEquals("Permet de communiquer en java avec un serveur " + + "redmine qui a installé le plugin rails jredmine", + project.getDescription()); + Assert.assertEquals(36, project.getId()); + Assert.assertEquals(1, project.getStatus()); + } + + @Test + public void getIssueCategories() throws Exception { + IssueCategory[] issueCategories = + service.getIssueCategories(PROJECT_NAME); + Assert.assertNotNull(issueCategories); + } + + @Test + public void getTrackers() throws Exception { + Tracker[] trackers = service.getTrackers(PROJECT_NAME); + Assert.assertNotNull(trackers); + } + + @Test + public void getNews() throws Exception { + News[] news = service.getNews(PROJECT_NAME); + Assert.assertNotNull(news); + } + + @Test + public void getProjectMembers() throws Exception { + User[] projectMembers = service.getProjectMembers(PROJECT_NAME); + Assert.assertNotNull(projectMembers); + } + + @Test + public void getProjectIssues() throws Exception { + Issue[] issues = service.getIssues(PROJECT_NAME); + Assert.assertNotNull(issues); + } + + @Test + public void getVersions() throws Exception { + Version[] versions = service.getVersions(PROJECT_NAME); + Assert.assertNotNull(versions); + } + + @Test + public void getOpenedIssues() throws Exception { + Issue[] issues = service.getOpenedIssues(PROJECT_NAME); + Assert.assertNotNull(issues); + } + + @Test + public void getClosedIssues() throws Exception { + Issue[] issues = service.getClosedIssues(PROJECT_NAME); + Assert.assertNotNull(issues); + } + + @Test + public void getVersion() throws Exception { + Version version = service.getVersion(PROJECT_NAME, VERSION_NAME); + Assert.assertNotNull(version); + } + + @Test + public void getVersionIssues() throws Exception { + Issue[] issues = service.getIssues(PROJECT_NAME, VERSION_NAME); + Assert.assertNotNull(issues); + } + + @Test + public void getIssueTimeEntries() throws Exception { + TimeEntry[] issueTimeEntries = + service.getIssueTimeEntries(PROJECT_NAME, ISSUE_ID); + Assert.assertNotNull(issueTimeEntries); + } + + @Test + public void getAttachments() throws Exception { + Attachment[] attachments = + service.getAttachments(PROJECT_NAME, VERSION_NAME); + Assert.assertNotNull(attachments); + } + +} Property changes on: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceJerseyTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/TestHelper.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/TestHelper.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/TestHelper.java 2012-03-25 15:48:53 UTC (rev 257) @@ -78,10 +78,14 @@ return; } - InputStream stream = TestHelper.class.getResourceAsStream("/test-config.properties"); - defaultConfig = new Properties(); - defaultConfig.load(stream); + InputStream stream = TestHelper.class.getResourceAsStream( + "/test-config.properties"); + try { + defaultConfig.load(stream); + } finally { + stream.close(); + } userConfig = new Properties(defaultConfig); for (String key : System.getenv().keySet()) { @@ -237,6 +241,18 @@ return (List<T>) memoryModel.get(RedmineModelEnum.valueOf(type)); } + public static <T> T getModel(Class<T> type, int pos) { + if (memoryModel == null) { + try { + loadMemoryModel(); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + List<T> ts = (List<T>) memoryModel.get(RedmineModelEnum.valueOf(type)); + return ts.get(pos); + } + public static void tearDownClass() throws Exception { //basedir = null; if (memoryModel != null) { @@ -245,7 +261,7 @@ } } - public static <T> void assertMyListEquals(Class<T> type, List<T> expecteds, T... actuals) throws Exception { + public static <T> void assertMyListEquals(Class<T> type, List<T> expecteds, T[] actuals) throws Exception { Assert.assertNotNull(actuals); Assert.assertEquals(expecteds.size(), actuals.length); Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojo.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojo.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojo.java 2012-03-25 15:48:53 UTC (rev 257) @@ -28,8 +28,8 @@ import org.apache.maven.model.IssueManagement; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; -import org.nuiton.io.rest.RestClientConfiguration; import org.nuiton.jredmine.RedmineService; +import org.nuiton.jredmine.RedmineServiceConfiguration; import org.nuiton.jredmine.RedmineServiceException; import org.nuiton.jredmine.RedmineServiceImplementor; import org.nuiton.jredmine.model.ModelHelper; @@ -50,7 +50,7 @@ * @requiresProject true * @since 1.0.0 */ -public abstract class AbstractRedmineMojo extends AbstractPlugin implements RestClientConfiguration { +public abstract class AbstractRedmineMojo extends AbstractPlugin implements RedmineServiceConfiguration { public static final String REDMINE_SYSTEM = "redmine"; @@ -386,7 +386,7 @@ } /////////////////////////////////////////////////////////////////////////// - /// RestClientConfiguration + /// RedmineServiceConfiguration /////////////////////////////////////////////////////////////////////////// @Override @@ -439,7 +439,8 @@ releaseProject = p; return true; } catch (RedmineServiceException e) { - getLog().warn("could not retreave project '" + projectId + "', for reason " + e.getMessage(), e); + getLog().warn("could not retreave project '" + projectId + + "', for reason " + e.getMessage(), e); return false; } } @@ -462,7 +463,8 @@ releaseVersion = v; return true; } catch (RedmineServiceException e) { - getLog().warn("could not retreave version '" + versionId + "', for reason " + e.getMessage(), e); + getLog().warn("could not retreave version '" + versionId + + "', for reason " + e.getMessage(), e); return false; } } @@ -482,7 +484,8 @@ releaseUser = user; return true; } catch (RedmineServiceException e) { - getLog().warn("could not retreave user '" + username + "', for reason " + e.getMessage(), e); + getLog().warn("could not retreave user '" + username + + "', for reason " + e.getMessage(), e); return false; } } @@ -499,7 +502,9 @@ } i.destroy(); } catch (Exception ex) { - getLog().error("could not close redmine client for reason " + ex.getMessage(), ex); + getLog().error( + "could not close redmine client for reason " + + ex.getMessage(), ex); } } } Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/GenerateChangesMojo.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/GenerateChangesMojo.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/GenerateChangesMojo.java 2012-03-25 15:48:53 UTC (rev 257) @@ -291,7 +291,9 @@ statuses = service.getIssueStatuses(); } catch (RedmineServiceException e) { - throw new MojoExecutionException("could not obtain statuses for reason " + e.getMessage(), e); + throw new MojoExecutionException( + "could not obtain statuses for reason " + e.getMessage(), + e); } // get categories @@ -302,7 +304,9 @@ categories = service.getIssueCategories(projectId); } catch (RedmineServiceException e) { - throw new MojoExecutionException("could not obtain categories for reason " + e.getMessage(), e); + throw new MojoExecutionException( + "could not obtain categories for reason " + e.getMessage(), + e); } // get versions @@ -312,7 +316,9 @@ versions = service.getVersions(projectId); } catch (RedmineServiceException e) { - throw new MojoExecutionException("could not obtain versions for reason " + e.getMessage(), e); + throw new MojoExecutionException( + "could not obtain versions for reason " + e.getMessage(), + e); } filters = new HashMap<String, String>(); @@ -327,14 +333,18 @@ String[] parts = entry.split(":"); if (parts.length != 2) { // error in syntax - throw new MojoExecutionException("the trackerMapping entry " + Arrays.toString(parts) + " is not well formed"); + throw new MojoExecutionException( + "the trackerMapping entry " + Arrays.toString(parts) + + " is not well formed"); } String action = parts[0].trim().toLowerCase(); try { Actions.valueOf(action); } catch (Exception e) { - throw new MojoExecutionException("the action " + action + " is unknown... authorized : " + Arrays.toString(Actions.values())); + throw new MojoExecutionException( + "the action " + action + " is unknown... authorized : " + + Arrays.toString(Actions.values())); } Integer id = Integer.valueOf(parts[1].trim()); @@ -342,7 +352,8 @@ Tracker t = ModelHelper.byId(id, releaseTrackers); if (t == null) { - throw new MojoExecutionException("could not obtain the tracker with id " + id); + throw new MojoExecutionException( + "could not obtain the tracker with id " + id); } trackerToAction.put(id, action); @@ -360,7 +371,8 @@ IssueStatus t = ModelHelper.byId(id, statuses); if (t == null) { - throw new MojoExecutionException("could not obtain the status with id " + id); + throw new MojoExecutionException( + "could not obtain the status with id " + id); } } @@ -378,7 +390,8 @@ IssueCategory t = ModelHelper.byId(id, categories); if (t == null) { - throw new MojoExecutionException("could not obtain the category with id " + id); + throw new MojoExecutionException( + "could not obtain the category with id " + id); } } @@ -397,7 +410,8 @@ versionExist = false; // la version n'existe pas encore sur redmine - getLog().warn("The version " + versionId + " does not exist on redmine"); + getLog().warn("The version " + versionId + + " does not exist on redmine"); releaseVersion = new Version(); releaseVersion.setName(versionId); @@ -454,13 +468,16 @@ if (isRunOnceDone()) { if (!xmlPath.exists()) { - getLog().info("Use already generated " + xmlPath.getName() + " (" + cacheChangesFile + ")"); + getLog().info("Use already generated " + xmlPath.getName() + + " (" + cacheChangesFile + ")"); try { createDirectoryIfNecessary(xmlPath.getParentFile()); copyFile(cacheChangesFile, xmlPath); } catch (IOException e) { - throw new IllegalStateException("could not copy already generated file " + xmlPath + " from " + cacheChangesFile); + throw new IllegalStateException( + "could not copy already generated file " + + xmlPath + " from " + cacheChangesFile); } } } @@ -476,7 +493,9 @@ if (releaseVersion.getEffectiveDate() == null) { - getLog().debug("The version " + versionId + " is not effective on redmine, should update effective-date property to today"); + getLog().debug("The version " + versionId + + " is not effective on redmine, should update " + + "effective-date property to today"); releaseVersion.setEffectiveDate(new Date()); } @@ -484,7 +503,8 @@ getLog().info("release project " + releaseProject.getName()); getLog().info("release version " + releaseVersion.getName()); getLog().info("release date " + releaseVersion.getEffectiveDate()); - getLog().info("release user " + releaseUser.getFirstname() + " " + releaseUser.getLastname()); + getLog().info("release user " + releaseUser.getFirstname() + " " + + releaseUser.getLastname()); // init issues collector @@ -498,12 +518,15 @@ } catch (RedmineServiceException ex) { collector.clearFilters(); - throw new MojoExecutionException("could not obtain issues for reason " + ex.getMessage(), ex); + throw new MojoExecutionException( + "could not obtain issues for reason " + ex.getMessage(), + ex); } //TODO make some logic checks : version must be // build the maven changes.xml as memory model - ChangesDocument doc = buildChangesDocument(releaseVersion, releaseUser, collector); + ChangesDocument doc = buildChangesDocument(releaseVersion, releaseUser, + collector); // store the generated file ChangesXpp3Writer xppWriter = new ChangesXpp3Writer(); @@ -518,7 +541,9 @@ cacheChangesFile = xmlPath; } - protected ChangesDocument buildChangesDocument(Version version, User user, IssuesCollector collector) throws RedmineServiceException { + protected ChangesDocument buildChangesDocument(Version version, + User user, + IssuesCollector collector) throws RedmineServiceException { ChangesDocument doc = new ChangesDocument(); Properties properties = new Properties(); Author author = new Author(); @@ -540,7 +565,8 @@ boolean treateReleaseVersion = v.getId() == version.getId(); - Issue[] issuesForVersion = ModelHelper.byVersionId(v.getId(), issues); + Issue[] issuesForVersion = + ModelHelper.byVersionId(v.getId(), issues); Release release = new Release(); body.addRelease(release); @@ -576,7 +602,8 @@ String type = entry.getValue(); // get issues for the tracker - Issue[] issuesForTracker = ModelHelper.byTrackerId(entry.getKey(), issuesForVersion); + Issue[] issuesForTracker = ModelHelper.byTrackerId( + entry.getKey(), issuesForVersion); for (Issue issue : issuesForTracker) { @@ -591,7 +618,8 @@ action.setDate(dateFormat.format(issue.getDueDate())); } else { if (verbose) { - getLog().warn("issue " + issue.getSubject() + " has no dueDate..."); + getLog().warn("issue " + issue.getSubject() + + " has no dueDate..."); } } @@ -603,7 +631,9 @@ id = issue.getAuthorId(); if (id == 0) { - getLog().warn("issue " + issue.getSubject() + " is not created to any user, this is not normal..."); + getLog().warn("issue " + issue.getSubject() + + " is not created to any user, " + + "this is not normal..."); id = issue.getAuthorId(); } a = ModelHelper.byId(id, users); @@ -617,7 +647,9 @@ id = issue.getAssignedToId(); if (id == 0) { - getLog().warn("issue " + issue.getSubject() + " is not assigned to any user, this is not normal..."); + getLog().warn("issue " + issue.getSubject() + + " is not assigned to any user, " + + "this is not normal..."); id = issue.getAuthorId(); } a = ModelHelper.byId(id, users); Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/IssuesCollector.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/IssuesCollector.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/IssuesCollector.java 2012-03-25 15:48:53 UTC (rev 257) @@ -168,7 +168,7 @@ * clean all internal states. * <p/> * Note : this method is invoked at the begin of each - * {@link #collect(org.nuiton.jredmine.RedmineService, org.nuiton.jredmine.plugin.IssueCollectorConfiguration)} method. + * {@link #collect(RedmineService, IssueCollectorConfiguration)} method. */ public void clearFilters() { maxEntries = null; Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/LoginMojo.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/LoginMojo.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/LoginMojo.java 2012-03-25 15:48:53 UTC (rev 257) @@ -29,8 +29,8 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; import org.nuiton.helper.plugin.ShareServerSecretPlugin; -import org.nuiton.io.rest.RestClientConfiguration; import org.nuiton.jredmine.RedmineService; +import org.nuiton.jredmine.RedmineServiceConfiguration; import org.nuiton.jredmine.RedmineServiceImplementor; import org.nuiton.plugin.AbstractPlugin; import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; @@ -48,7 +48,7 @@ * @goal login * @since 1.2.1 */ -public class LoginMojo extends AbstractPlugin implements RestClientConfiguration { +public class LoginMojo extends AbstractPlugin implements RedmineServiceConfiguration { /** * Dependance du projet. @@ -175,10 +175,15 @@ if (issueManagement == null) { throw new MojoExecutionException("No Issue Management set."); - } else if ((issueManagement.getUrl() == null) || (issueManagement.getUrl().trim().equals(""))) { + } else if (issueManagement.getUrl() == null || + issueManagement.getUrl().trim().equals("")) { throw new MojoExecutionException("No URL set in Issue Management."); - } else if ((issueManagement.getSystem() != null) && !(issueManagement.getSystem().equalsIgnoreCase(AbstractRedmineMojo.REDMINE_SYSTEM))) { - throw new MojoExecutionException("Redmine's Plugin only supports 'redmine' Issue Management system."); + } else if (issueManagement.getSystem() != null && + !issueManagement.getSystem().equalsIgnoreCase( + AbstractRedmineMojo.REDMINE_SYSTEM)) { + throw new MojoExecutionException( + "Redmine's Plugin only supports 'redmine' " + + "Issue Management system."); } // prepare Redmine service configuration @@ -218,7 +223,7 @@ plugin.setRunOnce(false); plugin.execute(); plugin.setRunOnce(true); - + if (!checkLogin) { // no more thing to do return; @@ -230,7 +235,8 @@ ((RedmineServiceImplementor) service).init(this); if (!((RedmineServiceImplementor) service).isInit()) { - throw new MojoExecutionException("could not logged to redmine server"); + throw new MojoExecutionException( + "could not logged to redmine server"); } } catch (Exception e) { @@ -238,7 +244,8 @@ throw e; } // if (verbose) { - getLog().error("could not init Redmine service [" + getRestUrl() + "] with user '" + getRestUsername() + "'", e); + getLog().error("could not init Redmine service [" + getRestUrl() + + "] with user '" + getRestUsername() + "'", e); // } // return false; } @@ -251,7 +258,7 @@ protected void afterExecute() { if (service != null) { RedmineServiceImplementor i; - i = ((RedmineServiceImplementor) service); + i = (RedmineServiceImplementor) service; if (i.isInit()) { try { @@ -260,7 +267,8 @@ } i.destroy(); } catch (Exception ex) { - getLog().error("could not close redmine client for reason " + ex.getMessage(), ex); + getLog().error("could not close redmine client for reason " + + ex.getMessage(), ex); } } } Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/NextVersionMojo.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/NextVersionMojo.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/NextVersionMojo.java 2012-03-25 15:48:53 UTC (rev 257) @@ -167,7 +167,9 @@ try { date = dateFormat.parse(effectiveDate); } catch (ParseException e) { - throw new MojoExecutionException("could not parse effectivate date " + effectiveDate + " for reason " + e.getMessage(), e); + throw new MojoExecutionException( + "could not parse effectivate date " + effectiveDate + + " for reason " + e.getMessage(), e); } } super.init(); @@ -186,11 +188,14 @@ Version v = ModelHelper.byVersionName(versionId, versions); boolean usePreviousVersion = false; - if (previousVersionName != null && !previousVersionName.trim().isEmpty()) { + if (previousVersionName != null && + !previousVersionName.trim().isEmpty()) { // retrieve previous version - Version previousVersion = ModelHelper.byVersionName(previousVersionName, versions); + Version previousVersion = ModelHelper.byVersionName( + previousVersionName, versions); if (previousVersion == null) { - getLog().warn("can not find the previous version " + previousVersionName); + getLog().warn("can not find the previous version " + + previousVersionName); } else { usePreviousVersion = true; } @@ -215,9 +220,13 @@ if (!dryRun) { // create version - getLog().info("next version " + releaseVersion.getName() + (usePreviousVersion ? " from previous version " + previousVersionName : "")); + getLog().info("next version " + releaseVersion.getName() + + (usePreviousVersion ? " from previous version " + + previousVersionName : "")); - service.nextVersion(projectId, usePreviousVersion ? previousVersionName : null, releaseVersion); + service.nextVersion(projectId, + usePreviousVersion ? + previousVersionName : null, releaseVersion); } } Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishAttachmentsMojo.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishAttachmentsMojo.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishAttachmentsMojo.java 2012-03-25 15:48:53 UTC (rev 257) @@ -143,13 +143,15 @@ if (filesFromProperties != null && !filesFromProperties.exists()) { // no file to publish... - getLog().warn("could not find the properties file " + filesFromProperties); + getLog().warn("could not find the properties file " + + filesFromProperties); getLog().warn("will not use this source"); filesFromProperties = null; } if (filesFromProperties != null && files != null && files.length > 0) { - throw new MojoExecutionException("can not use both sources files and filesFromProperties"); + throw new MojoExecutionException( + "can not use both sources files and filesFromProperties"); } if (filesFromProperties != null) { @@ -204,7 +206,8 @@ } if (f.getAbsolutePath().startsWith(basedir)) { - getLog().info("upload " + f.getAbsolutePath().substring(basedirLength)); + getLog().info("upload " + + f.getAbsolutePath().substring(basedirLength)); } else { getLog().info("upload " + f.getAbsolutePath()); } @@ -224,10 +227,14 @@ a.setToUpload(f); // do upload - Attachment result = service.addAttachment(projectId, releaseVersion.getName(), a); + Attachment result = service.addAttachment( + projectId, releaseVersion.getName(), a); long t1 = System.nanoTime(); if (verbose) { - getLog().info("done in " + PluginHelper.convertTime(t1 - t0) + ". attachment id : " + result.getId() + ", size : " + PluginHelper.convertMemory(result.getFilesize())); + getLog().info("done in " + PluginHelper.convertTime(t1 - t0) + + ". attachment id : " + result.getId() + + ", size : " + + PluginHelper.convertMemory(result.getFilesize())); } } } @@ -241,7 +248,8 @@ incoming = new CollectFilesMojo().getFiles(filesFromProperties); getLog().info("Loaded " + filesFromProperties); } catch (IOException ex) { - throw new MojoExecutionException("could not load file " + filesFromProperties, ex); + throw new MojoExecutionException("could not load file " + + filesFromProperties, ex); } // sort attachments by file names Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishNewsMojo.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishNewsMojo.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishNewsMojo.java 2012-03-25 15:48:53 UTC (rev 257) @@ -149,12 +149,14 @@ if (!newsContentFile.exists()) { // no file to publish... - throw new MojoExecutionException("could not find the template " + newsContentFile); + throw new MojoExecutionException("could not find the template " + + newsContentFile); } newsTitle = newsTitle.trim(); if (newsTitle.length() > 60) { - getLog().warn("News title can not be longer than 60 caracters, but was " + newsTitle.length()); + getLog().warn("News title can not be longer than 60 " + + "caracters, but was " + newsTitle.length()); newsTitle = newsTitle.substring(0, 59); getLog().warn("will use the restricted title : " + newsTitle); } @@ -177,7 +179,8 @@ news.setTitle(newsTitle); news.setSummary(newsSummary); - String newsContent = PluginHelper.readAsString(newsContentFile, encoding); + String newsContent = PluginHelper.readAsString(newsContentFile, + encoding); news.setDescription(newsContent); Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AbstractAnnouncementMojo.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AbstractAnnouncementMojo.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AbstractAnnouncementMojo.java 2012-03-25 15:48:53 UTC (rev 257) @@ -309,8 +309,9 @@ if (artifactsFile != null) { if (!artifactsFile.exists()) { - throw new MojoExecutionException("The artifactsFile [" + - artifactsFile + "] does not exists"); + throw new MojoExecutionException( + "The artifactsFile [" + + artifactsFile + "] does not exists"); } @@ -326,7 +327,9 @@ getLog().info("Deploy url = " + url); } - artifactUrls = generator.getArtifactsUrls(url, versionId, isVerbose(), files); + artifactUrls = generator.getArtifactsUrls(url, + versionId, isVerbose(), + files); } super.init(); @@ -350,7 +353,8 @@ for (Map.Entry<Attachment, String> e : attachmentUrls.entrySet()) { Attachment key = e.getKey(); String value = e.getValue(); - getLog().info("attachment file " + key.getFilename() + " --> " + value); + getLog().info("attachment file " + key.getFilename() + + " --> " + value); } } Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractIssuesReport.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractIssuesReport.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractIssuesReport.java 2012-03-25 15:48:53 UTC (rev 257) @@ -135,7 +135,9 @@ issuesCache.put(this, issues); } catch (RedmineServiceException ex) { - throw new MavenReportException("could not obtains issues for reason " + ex.getMessage(), ex); + throw new MavenReportException( + "could not obtains issues for reason " + + ex.getMessage(), ex); } finally { collector.clearFilters(); } @@ -150,21 +152,27 @@ public void executeReport(Locale locale) throws MavenReportException { if (isOnlyCurrentVersion()) { - getLog().info(getBundle(locale).getString("report.message.only.for.current.version") + " " + getVersionId()); + getLog().info(getBundle(locale).getString( + "report.message.only.for.current.version") + " " + + getVersionId()); } String id = getProjectId(); try { if (issues == null || issues.length == 0) { - getLog().warn("no issue to treate, will generate an empty raport."); + getLog().warn("no issue to treate, " + + "will generate an empty raport."); - IssueReportGenerator reportGenerator = new IssueReportGenerator(); + IssueReportGenerator reportGenerator = + new IssueReportGenerator(); - reportGenerator.doGenerateEmptyReport(getBundle(locale), getSink()); + reportGenerator.doGenerateEmptyReport(getBundle(locale), + getSink()); } else { - IssueReportGenerator report = new IssueReportGenerator(getLog(), getColumnNames(), getGroup()); + IssueReportGenerator report = new IssueReportGenerator( + getLog(), getColumnNames(), getGroup()); report.setIssueLinkTemplate(getIssueLinkTemplate()); report.setVersionLinkTemplate(getVersionLinkTemplate()); Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractRedmineReport.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractRedmineReport.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractRedmineReport.java 2012-03-25 15:48:53 UTC (rev 257) @@ -153,7 +153,9 @@ /** @return {@code true} if report should be skip */ protected abstract boolean skipReport(); - public AbstractRedmineReport(boolean requireProject, boolean requireVersion, boolean requireUser) { + public AbstractRedmineReport(boolean requireProject, + boolean requireVersion, + boolean requireUser) { super(requireProject, requireVersion, requireUser); } @@ -179,15 +181,18 @@ Map<String, String> attributes = new HashMap<String, String>(); attributes.put("outputEncoding", encoding); Locale currentLocale = Locale.getDefault(); - SiteRenderingContext siteContext = siteRenderer.createContextForSkin(getSkinArtifactFile(), attributes, - model, getName(currentLocale), currentLocale); + SiteRenderingContext siteContext = + siteRenderer.createContextForSkin( + getSkinArtifactFile(), attributes, + model, getName(currentLocale), currentLocale); createDirectoryIfNecessary(outputDirectory); String filename = getOutputName() + ".html"; File file = new File(outputDirectory, filename); - RenderingContext context = new RenderingContext(outputDirectory, getOutputName() + ".html"); + RenderingContext context = new RenderingContext( + outputDirectory, getOutputName() + ".html"); //SiteRendererSink sink = SinkFactory.createSink(outputDirectory, filename); @@ -205,18 +210,23 @@ writer.close(); } - siteRenderer.copyResources(siteContext, new File(project.getBasedir(), "src/site/resources"), - outputDirectory); + siteRenderer.copyResources( + siteContext, + new File(project.getBasedir(), "src/site/resources"), + outputDirectory); } catch (RendererException e) { throw new MojoExecutionException( - "An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e); + "An error has occurred in " + getName(Locale.ENGLISH) + + " report generation.", e); } catch (IOException e) { throw new MojoExecutionException( - "An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e); + "An error has occurred in " + getName(Locale.ENGLISH) + + " report generation.", e); } catch (MavenReportException e) { throw new MojoExecutionException( - "An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e); + "An error has occurred in " + getName(Locale.ENGLISH) + + " report generation.", e); } finally { closeService(); @@ -234,12 +244,14 @@ getLog().debug("check can use report"); } if (skipReport()) { - getLog().info("User ask to skip report \"" + getName(Locale.ENGLISH) + "\"."); + getLog().info("User ask to skip report \"" + + getName(Locale.ENGLISH) + "\"."); return false; } if (session.getSettings().isOffline()) { // skip when offline - getLog().info("Skipped \"" + getName(Locale.ENGLISH) + "\" report in offline mode."); + getLog().info("Skipped \"" + getName(Locale.ENGLISH) + + "\" report in offline mode."); return false; } try { @@ -247,14 +259,17 @@ init = true; } catch (Exception ex) { if (isVerbose()) { - getLog().error("could not init report goal for reason " + ex.getMessage(), ex); + getLog().error("could not init report goal for reason " + + ex.getMessage(), ex); } else { - getLog().error("could not init report goal for reason " + ex.getMessage()); + getLog().error("could not init report goal for reason " + + ex.getMessage()); } init = false; } if (!init) { - getLog().info("Skipped \"" + getName(Locale.ENGLISH) + "\" report, goal could be initialized."); + getLog().info("Skipped \"" + getName(Locale.ENGLISH) + + "\" report, goal could be initialized."); } if (getLog().isDebugEnabled()) { getLog().debug("check can use report : " + init); @@ -316,7 +331,9 @@ } protected ResourceBundle getBundle(Locale locale) { - return ResourceBundle.getBundle("redmine-report", locale, getClass().getClassLoader()); + return ResourceBundle.getBundle("redmine-report", + locale, + getClass().getClassLoader()); } protected File getSkinArtifactFile() @@ -329,17 +346,28 @@ if (version == null) { version = Artifact.RELEASE_VERSION; } - VersionRange versionSpec = VersionRange.createFromVersionSpec(version); - artifact = factory.createDependencyArtifact(skin.getGroupId(), skin.getArtifactId(), versionSpec, "jar", - null, null); + VersionRange versionSpec = + VersionRange.createFromVersionSpec(version); + artifact = factory.createDependencyArtifact( + skin.getGroupId(), + skin.getArtifactId(), + versionSpec, + "jar", + null, + null); - resolver.resolve(artifact, project.getRemoteArtifactRepositories(), localRepository); + resolver.resolve(artifact, + project.getRemoteArtifactRepositories(), + localRepository); } catch (InvalidVersionSpecificationException e) { - throw new MojoExecutionException("The skin version '" + version + "' is not valid: " + e.getMessage()); + throw new MojoExecutionException( + "The skin version '" + version + + "' is not valid: " + e.getMessage()); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Unable to find skin", e); } catch (ArtifactNotFoundException e) { - throw new MojoExecutionException("The skin does not exist: " + e.getMessage()); + throw new MojoExecutionException("The skin does not exist: " + + e.getMessage()); } return artifact.getFile(); Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/IssueReportGenerator.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/IssueReportGenerator.java 2012-03-25 15:37:26 UTC (rev 256) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/IssueReportGenerator.java 2012-03-25 15:48:53 UTC (rev 257) @@ -77,29 +77,37 @@ key(false, "report.label.key") { @Override - public void sinkInsideCell(Sink sink, IssueReportGenerator generator, Issue issue) { + public void sinkInsideCell(Sink sink, + IssueReportGenerator generator, + Issue issue) { generator.constructIssueLink(issue, sink); } @Override protected Integer getGroupId(Issue issue) { - throw new UnsupportedOperationException(name() + "does not supports grouping"); + throw new UnsupportedOperationException( + name() + "does not supports grouping"); } }, summary(false, "report.label.summary") { @Override - public void sinkInsideCell(Sink sink, IssueReportGenerator generator, Issue issue) { + public void sinkInsideCell(Sink sink, + IssueReportGenerator generator, + Issue issue) { generator.sinkRawText(sink, issue.getDescription()); } @Override protected Integer getGroupId(Issue issue) { - throw new UnsupportedOperationException(name() + "does not supports grouping"); + throw new UnsupportedOperationException( + name() + "does not supports grouping"); } }, status(true, "report.label.status") { @Override - public void sinkInsideCell(Sink sink, IssueReportGenerator generator, Issue issue) { + public void sinkInsideCell(Sink sink, + IssueReportGenerator generator, + Issue issue) { int id = issue.getStatusId(); // String t = id + ""; @@ -120,7 +128,9 @@ }, assignee(true, "report.label.by") { @Override - public void sinkInsideCell(Sink sink, IssueReportGenerator generator, Issue issue) { + public void sinkInsideCell(Sink sink, + IssueReportGenerator generator, + Issue issue) { int id = issue.getAssignedToId(); User u = generator.getUser(id); String t = issue.getAssignedToId() + ""; @@ -141,7 +151,9 @@ }, reporter(true, "report.label.reporter") { @Override - public void sinkInsideCell(Sink sink, IssueReportGenerator generator, Issue issue) { + public void sinkInsideCell(Sink sink, + IssueReportGenerator generator, + Issue issue) { int id = issue.getAuthorId(); User u = generator.getUser(id); String t = issue.getAuthorId() + ""; @@ -162,7 +174,9 @@ }, tracker(true, "report.label.type") { @Override - public void sinkInsideCell(Sink sink, IssueReportGenerator generator, Issue issue) { + public void sinkInsideCell(Sink sink, + IssueReportGenerator generator, + Issue issue) { int id = issue.getTrackerId(); Tracker status = generator.getTracker(id); generator.sinkI18nAble(sink, id, status); @@ -175,7 +189,9 @@ }, priority(true, "report.label.priority") { @Override - public void sinkInsideCell(Sink sink, IssueReportGenerator generator, Issue issue) { + public void sinkInsideCell(Sink sink, + IssueReportGenerator generator, + Issue issue) { int id = issue.getPriorityId(); IssuePriority p = generator.getIssuePriority(id); generator.sinkI18nAble(sink, id, p); @@ -188,7 +204,9 @@ }, version(true, "report.label.version") { @Override - public void sinkInsideCell(Sink sink, IssueReportGenerator generator, Issue issue) { + public void sinkInsideCell(Sink sink, + IssueReportGenerator generator, + Issue issue) { int id = issue.getFixedVersionId(); Version v2 = generator.getVersion(id); generator.sinkI18nAble(sink, id, v2); @@ -201,7 +219,9 @@ }, category(true, "report.label.category") { @Override - public void sinkInsideCell(Sink sink, IssueReportGenerator generator, Issue issue) { + public void sinkInsideCell(Sink sink, + IssueReportGenerator generator, + Issue issue) { int id = issue.getCategoryId(); IssueCategory status = generator.getIssueCategory(id); generator.sinkI18nAble(sink, id, status); @@ -214,26 +234,32 @@ }, createdon(false, "report.label.created") { @Override - public void sinkInsideCell(Sink sink, IssueReportGenerator generator, Issue issue) { + public void sinkInsideCell(Sink sink, + IssueReportGenerator generator, + Issue issue) { Date d = issue.getCreatedOn(); generator.sinkDate(sink, d); } @Override protected Integer getGroupId(Issue issue) { - throw new UnsupportedOperationException(name() + "does not supports grouping"); + throw new UnsupportedOperationException( + name() + "does not supports grouping"); } }, updatedon(false, "report.label.updated") { @Override - public void sinkInsideCell(Sink sink, IssueReportGenerator generator, Issue issue) { + public void sinkInsideCell(Sink sink, + IssueReportGenerator generator, + Issue issue) { Date d = issue.getUpdatedOn(); generator.sinkDate(sink, d); } @Override protected Integer getGroupId(Issue issue) { - throw new UnsupportedOperationException(name() + "does not supports grouping"); + throw new UnsupportedOperationException( + name() + "does not supports grouping"); } }; @@ -254,11 +280,14 @@ return i18nKey; } - public abstract void sinkInsideCell(Sink sink, IssueReportGenerator generator, Issue issue); + public abstract void sinkInsideCell(Sink sink, + IssueReportGenerator generator, + Issue issue); protected abstract Integer getGroupId(Issue issue); - public void collectGroups(Issue[] issues, Map<Integer, List<Issue>> groups) { + public void collectGroups(Issue[] issues, + Map<Integer, List<Issue>> groups) { for (Issue issue : issues) { Integer id = getGroupId(issue); List<Issue> c = groups.get(id); @@ -314,10 +343,12 @@ List<ReportColumn> tmp = new ArrayList<ReportColumn>(nbCols); for (String col : columnNames.split(",")) { try { - ReportColumn valueOf = ReportColumn.valueOf(col.trim().toLowerCase()); + ReportColumn valueOf = + ReportColumn.valueOf(col.trim().toLowerCase()); tmp.add(valueOf); } catch (Exception e) { - log.warn(col + " is an unkown column name, authorized : " + Arrays.toString(ReportColumn.values())); + log.warn(col + " is an unkown column name, authorized : " + + Arrays.toString(ReportColumn.values())); if (log.isDebugEnabled()) { log.debug(e); } @@ -326,14 +357,17 @@ if (tmp.isEmpty()) { // This can happen if the user has configured column names and they are all invalid throw new MavenReportException( - "maven-redmine-plugin: None of the configured columnNames '" + columnNames + "' are valid."); + "maven-redmine-plugin: None of the configured " + + "columnNames '" + columnNames + "' are valid."); } if (groupBy != null && !groupBy.trim().isEmpty()) { try { - groupColumn = ReportColumn.valueOf(groupBy.trim().toLowerCase()); + groupColumn = ReportColumn.valueOf( + groupBy.trim().toLowerCase()); if (!groupColumn.isCanGroup()) { - log.warn(groupColumn + " is not a grouping columne, grouping will be skip."); + log.warn(groupColumn + " is not a grouping columne, " + + "grouping will be skip."); groupColumn = null; } else { // remove the group column from the table @@ -343,7 +377,8 @@ log.info("group by " + groupColumn); } catch (Exception e) { - log.warn(groupBy + " is an unkown group column name, grouping will be skip."); + log.warn(groupBy + " is an unkown group column name, " + + "grouping will be skip."); if (log.isDebugEnabled()) { log.debug(e); } @@ -366,7 +401,8 @@ if (issues != null && issues.length == 0) { throw new MojoExecutionException( - "maven-redmine-plugin: Can not generate report if no issues, use the doGenerateEmptyReport instead"); + "maven-redmine-plugin: Can not generate report if no " + + "issues, use the doGenerateEmptyReport instead"); } String d = bundle.getString("report.date.format"); @@ -399,7 +435,8 @@ sink.sectionTitle2(); - sinkRawText(sink, bundle.getString(groupColumn.getI18nKey()) + " : "); + sinkRawText(sink, bundle.getString( + groupColumn.getI18nKey()) + " : "); groupColumn.sinkInsideCell(sink, this, currentIssues.get(0)); @@ -409,7 +446,8 @@ constructHeaderRow(sink, bundle); - constructDetailRows(sink, currentIssues.toArray(new Issue[currentIssues.size()])); + constructDetailRows(sink, currentIssues.toArray( + new Issue[currentIssues.size()])); sink.table_(); } @@ -425,7 +463,9 @@ * @return {@code true} if issue links can be generated, {@code false} otherwise. */ public boolean canGenerateIssueLinks() { - return !StringUtils.isEmpty(issueLinkTemplate) && (!StringUtils.isBlank(getUrl()) || !issueLinkTemplate.contains(URL_TOKEN)); + return !StringUtils.isEmpty(issueLinkTemplate) && + (!StringUtils.isBlank(getUrl()) || + !issueLinkTemplate.contains(URL_TOKEN)); } /** @@ -434,7 +474,9 @@ * @return {@code true} if issue links can be generated, {@code false} otherwise. */ public boolean canGenerateVersionLinks() { - return !StringUtils.isEmpty(versionLinkTemplate) && (!StringUtils.isBlank(getUrl()) || !versionLinkTemplate.contains(URL_TOKEN)); + return !StringUtils.isEmpty(versionLinkTemplate) && + (!StringUtils.isBlank(getUrl()) || + !versionLinkTemplate.contains(URL_TOKEN)); } public void setUrl(String url) {