r445 - trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin
Author: tchemit Date: 2014-04-16 14:52:01 +0200 (Wed, 16 Apr 2014) New Revision: 445 Url: http://forge.nuiton.org/projects/jredmine/repository/revisions/445 Log: fixes #3157 Removed: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/LoginMojo.java Deleted: 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 2014-04-16 12:51:47 UTC (rev 444) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/LoginMojo.java 2014-04-16 12:52:01 UTC (rev 445) @@ -1,368 +0,0 @@ -/* - * #%L - * JRedmine :: Maven plugin - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, 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.plugin; - -import org.apache.maven.model.IssueManagement; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; -import org.apache.maven.settings.Settings; -import org.nuiton.helper.plugin.ShareServerSecretPlugin; -import org.nuiton.jredmine.client.RedmineClientAuthConfiguration; -import org.nuiton.jredmine.service.RedmineService; -import org.nuiton.jredmine.service.RedmineServiceConfiguration; -import org.nuiton.plugin.AbstractPlugin; -import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; - -import java.net.URL; -import java.util.Properties; - -/** - * Obtain login for the redmine server to use. - * - * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin - * @since 1.2.1 - */ -@Mojo(name = "login", requiresOnline = true, requiresProject = true) -public class LoginMojo extends AbstractPlugin implements RedmineServiceConfiguration { - - /////////////////////////////////////////////////////////////////////////// - /// Mojo parameters - /////////////////////////////////////////////////////////////////////////// - - /** - * The real basedir redmine url. - * <p/> - * If no url is given, will use the issue management url. - * - * @since 1.2.1 - */ - @Parameter(property = "redmine.url") - protected URL url; - - /** - * Flag to activate verbose logging. - * - * @since 1.2.1 - */ - @Parameter(property = "redmine.verbose", defaultValue = "${maven.verbose}") - protected boolean verbose; - - /** - * Flag to check login is ok (will connect to server). - * - * @since 1.2.1 - */ - @Parameter(property = "redmine.checkLogin", defaultValue = "false") - protected boolean checkLogin; - - /** - * Flag to fail build if configuration is not ok. - * - * @since 1.2.1 - */ - @Parameter(property = "redmine.safe", defaultValue = "true") - protected boolean safe; - - /** - * Redmine server id to obtain login and password. - * <p/> - * The server must be defined in your settings.xml file in servers section. - * - * @since 1.2.1 - */ - @Parameter(property = "redmine.serverId", required = true) - protected String serverId; - - /** - * Un flag pour utiliser le clef API pluto que le login/password. - * <p/> - * Il faut alors que le serveur contienne en username le clef API (encrypté ou non). - * - * @since 2.0 - */ - @Parameter(property = "redmine.useApiKey", defaultValue = "false") - private boolean useApiKey; - - /////////////////////////////////////////////////////////////////////////// - /// Mojo components - /////////////////////////////////////////////////////////////////////////// - - /** - * Current project. - * - * @since 1.2.1 - */ - @Component - protected MavenProject project; - - /** - * Settings. - * - * @since 1.2.1 - */ - @Component - protected Settings settings; - - /** - * Password decypher. - * - * @since 1.2.1 - */ - @Component(hint = "helper-maven-plugin") - protected SecDispatcher sec; - - /** - * Redmine service. - * - * @component - * @since 1.2.1 - */ - @Component - protected RedmineService service; - - /////////////////////////////////////////////////////////////////////////// - /// Mojo internal attributes - /////////////////////////////////////////////////////////////////////////// - - /** - * Shared instance of delegate plugin to obtain login - * - * @since 1.2.1 - */ - protected static ShareServerSecretPlugin plugin; - - - private RedmineClientAuthConfiguration authConfiguration; - - private static final String REDMINE_USERNAME = "redmine.username"; - - private static final String REDMINE_PASSWORD = "redmine.password"; - - private static final String REDMINE_API_KEY = "redmine.apiKey"; - - /////////////////////////////////////////////////////////////////////////// - /// Plugin - /////////////////////////////////////////////////////////////////////////// - - @Override - public MavenProject getProject() { - return project; - } - - @Override - public void setProject(MavenProject project) { - this.project = project; - } - - @Override - public boolean isVerbose() { - return verbose; - } - - @Override - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - /////////////////////////////////////////////////////////////////////////// - /// PluginWithEncoding - /////////////////////////////////////////////////////////////////////////// - - @Override - public String getEncoding() { - return null; - } - - @Override - public void setEncoding(String encoding) { - } - - /////////////////////////////////////////////////////////////////////////// - /// RedmineClientConfiguration - /////////////////////////////////////////////////////////////////////////// - - @Override - public boolean isAnonymous() { - return false; - } - - @Override - public void setAnonymous(boolean anonymous) { - } - - @Override - public URL getUrl() { - return url; - } - - @Override - public void setUrl(URL url) { - this.url = url; - } - - @Override - public RedmineClientAuthConfiguration getAuthConfiguration() { - return authConfiguration; - } - - @Override - public void setAuthConfiguration(RedmineClientAuthConfiguration authConfiguration) { - this.authConfiguration = authConfiguration; - } - - /////////////////////////////////////////////////////////////////////////// - /// AbstractPlugin - /////////////////////////////////////////////////////////////////////////// - - @Override - protected void init() throws Exception { - if (plugin == null) { - plugin = new ShareServerSecretPlugin(); - plugin.setServerId(serverId); - if (useApiKey) { - plugin.setUsernameOut(REDMINE_API_KEY); - } else { - plugin.setUsernameOut(REDMINE_USERNAME); - plugin.setPasswordOut(REDMINE_PASSWORD); - } - plugin.setRunOnce(true); - - plugin.setProject(project); - plugin.setLog(getLog()); - plugin.setVerbose(isVerbose()); - plugin.setSettings(settings); - plugin.setSec(sec); - - plugin.init(); - } - - if (!checkLogin) { - // no more thing to do - return; - } - - // check issue management - - IssueManagement issueManagement = project.getIssueManagement(); - - if (issueManagement == null) { - throw new MojoExecutionException("No Issue Management set."); - } 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."); - } - - // prepare Redmine service configuration - - if (url == null || url.toString().isEmpty()) { - - // no redmine url specified, guess it from issueManagement - - url = new URL(issueManagement.getUrl()); - - if (verbose) { - getLog().info("use the url from issue management : " + url); - } - } - - // apply configuration - - setUrl(url); - } - - @Override - protected boolean checkSkip() { - - return plugin.checkSkip(); - } - - @Override - protected void doAction() throws Exception { - - getLog().info("Obtain redmine login for serverId '" + serverId + "'"); - // when plugin is executed, then will repass in method checkSkip and then - // will never execute the plugin :( Should instead open Plugin api to - // pass to public the doAction method - plugin.setRunOnce(false); - plugin.execute(); - plugin.setRunOnce(true); - - if (!checkLogin) { - // no more thing to do - return; - } - - Properties properties = project.getProperties(); - authConfiguration = RedmineClientAuthConfiguration.newConf( - properties.getProperty(REDMINE_API_KEY), - properties.getProperty(REDMINE_USERNAME), - properties.getProperty(REDMINE_PASSWORD) - ); - - // init Redmine service - - try { - - service.init(this); -// if (!((RedmineServiceImplementor) service).isInit()) { -// throw new MojoExecutionException("could not logged to redmine server"); -// } - - } catch (Exception e) { - if (safe) { - throw e; - } -// if (verbose) { - getLog().error("could not init Redmine service [" + getUrl() + "]", e); -// } -// return false; - } - - getLog().info("Connection to redmine server successfull."); - } - - - @Override - protected void afterExecute() { - if (service != null) { - - if (service.isInit()) { - try { - if (verbose) { - getLog().info("<<< Close redmine rest client..."); - } - service.destroy(); - } catch (Exception ex) { - getLog().error("could not close redmine client for reason " + ex.getMessage(), ex); - } - } - } - } - -}
participants (1)
-
tchemit@users.nuiton.org