buildframework/helium/sf/java/scm/src/com/nokia/helium/scm/ant/taskdefs/ScmTask.java
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
/*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
 * All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
 * Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
 * Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
 * Description:  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
package com.nokia.helium.scm.ant.taskdefs;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
import java.util.ArrayList;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
import java.util.List;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    22
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    23
import org.apache.maven.scm.ScmException;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import org.apache.maven.scm.manager.NoSuchScmProviderException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import org.apache.maven.scm.manager.ScmManager;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import org.apache.maven.scm.repository.ScmRepository;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import org.apache.maven.scm.repository.ScmRepositoryException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import org.apache.tools.ant.BuildException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import org.apache.tools.ant.Task;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    31
import com.nokia.helium.scm.ant.AntScmLogger;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    32
import com.nokia.helium.scm.ant.actions.AddAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    33
import com.nokia.helium.scm.ant.actions.BranchAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    34
import com.nokia.helium.scm.ant.actions.ChangelogAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    35
import com.nokia.helium.scm.ant.actions.CheckinAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    36
import com.nokia.helium.scm.ant.actions.CheckoutAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    37
import com.nokia.helium.scm.ant.actions.DiffAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    38
import com.nokia.helium.scm.ant.actions.ExportAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    39
import com.nokia.helium.scm.ant.actions.InfoAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    40
import com.nokia.helium.scm.ant.actions.InitAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    41
import com.nokia.helium.scm.ant.actions.PullAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    42
import com.nokia.helium.scm.ant.actions.RemoveAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    43
import com.nokia.helium.scm.ant.actions.ScmAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    44
import com.nokia.helium.scm.ant.actions.StatusAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    45
import com.nokia.helium.scm.ant.actions.TagAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    46
import com.nokia.helium.scm.ant.actions.TagsAction;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    47
import com.nokia.helium.scm.ant.actions.UpdateAction;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
import com.nokia.maven.scm.manager.BasicExtendedScmManager;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
import com.nokia.maven.scm.manager.ExtendedScmManager;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
import com.nokia.maven.scm.provider.hg.HgScmProviderExt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
/**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
 * This provides Ant support for a range of common SCM operations. They should work on 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
 * any Maven based SCM e.g. SVN, Mercurial, synergy.  The
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
 * underlying SCM tool is defined by the URL format.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
 * <pre>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
 * &lt;hlm:scm verbose="true" scmUrl="scm:hg:${pkg_detail.source}"&gt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
 *    &lt;hlm:checkout basedir="${build.drive}${pkg_detail.dst}"/&gt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
 *    &lt;hlm:tags basedir="${build.drive}${pkg_detail.dst}" reference="hg.tags.id${refid}"/&gt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
 *    &lt;hlm:update basedir="${build.drive}${pkg_detail.dst}"&gt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
 *        &lt;hlm:latestTag pattern="${pkg_detail.tag}"&gt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
 *            &lt;hlm:tagSet refid="hg.tags.id${refid}" /&gt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
 *        &lt;/hlm:latestTag&gt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
 *    &lt;/hlm:update&gt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
 * &lt;/hlm:scm&gt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
 * </pre>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
 * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
 * @ant.task name="scm" category="SCM"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
public class ScmTask extends Task {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
    private ExtendedScmManager scmManager;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
    private String username;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
    private String password;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
    private String scmUrl;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
    private List<ScmAction> actions = new ArrayList<ScmAction>();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
    private boolean verbose;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
    private boolean failonerror = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
    public ScmTask() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
        setTaskName("scm");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    91
        BasicExtendedScmManager scmManager = new BasicExtendedScmManager();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    92
        scmManager.addListener(new AntScmLogger(this));
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    93
        this.scmManager = scmManager;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    94
        HgScmProviderExt provider = new HgScmProviderExt();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    95
        
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
        // Add all SCM providers we want to use
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    97
        scmManager.setScmProvider("hg", provider);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
    public ScmManager getScmManager() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
        return scmManager;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
     * Set if the task should use verbose output on Maven SCM framework.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
     * @param value
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
     * @ant.not-required Default is false
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
    public void setVerbose(boolean value) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
        verbose = value;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
     * Set the username, this field is required while user requires to be
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
     * authenticated.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
     * @param username
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
     *            The user login
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
     * @ant.not-required
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
    public void setUsername(String username) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
        this.username = username;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
     * Set the password, this field is required while user requires to be
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
     * authenticated.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
     * @param password
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
     *            The user password
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
     * @ant.not-required
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
    public void setPassword(String password) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
        this.password = password;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
     * Set if the build should keep going while any exception.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
     * @param failonerror
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
     * @ant.not-required Default is true
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
    public void setFailonerror(boolean failonerror) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
        this.failonerror = failonerror;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
    public String getScmUrl() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
        return scmUrl;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
     * Sets the SCM URL so the task knows what repository to use.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
     * @param scmUrl
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
     *            The URL to connect to
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   157
     * @ant.required
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
    public void setScmUrl(String scmUrl) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
        this.scmUrl = scmUrl;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   163
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
     * Add an SCM add action.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
     * @param action
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
     *            The add action.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
     * @ant.optional
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   169
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
    public void addAdd(AddAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   173
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   174
    public void addChangelog(ChangelogAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
    public void addBranch(BranchAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
    public void addCheckin(CheckinAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
    public void addCheckout(CheckoutAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
    public void addDiff(DiffAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
    public void addRemove(RemoveAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
    public void addStatus(StatusAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
    public void addUpdate(UpdateAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
    public ScmAction[] getActions() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
        return (ScmAction[]) actions.toArray(new ScmAction[0]);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
    // Additional actions not supported by the core Maven API
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
    public void addPull(PullAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
    public void addTag(TagAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
    public void addTags(TagsAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
    public void addInfo(InfoAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   226
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   227
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   228
    public void addInit(InitAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   229
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   230
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   231
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   232
    public void addExport(ExportAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   233
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   234
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   235
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   236
    private void addAction(ScmAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   237
        action.setTask(this);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   238
        actions.add(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   239
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   240
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   241
    public void add(ScmAction action) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   242
        addAction(action);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   243
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   244
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   245
    @Override
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   246
    public final void execute() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   247
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   248
            log("scm url: " + scmUrl);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   249
            ScmRepository repository = scmManager.makeScmRepository(scmUrl);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   250
            // Process all scm commands
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   251
            for (ScmAction action : actions) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   252
                action.execute(repository);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   253
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   254
        } catch (NoSuchScmProviderException ex) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   255
            throw new BuildException("Could not find a provider.");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   256
        } catch (ScmRepositoryException ex) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   257
            throw new BuildException(
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   258
                    "Error while connecting to the repository: " + ex.getMessage());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   259
        } catch (BuildException ex) {      //need to do this because the TagAction 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   260
            // execute catches the ScmException and throws a BuildException
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   261
            if ( failonerror ) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   262
                ex.printStackTrace();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   263
                throw new BuildException(ex.getMessage());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   264
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   265
            else {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   266
                ex.printStackTrace();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   267
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   268
        } catch (ScmException ex) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   269
            if ( failonerror ) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   270
                ex.printStackTrace();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   271
                throw new BuildException(ex.getMessage());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   272
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   273
            else {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   274
                ex.printStackTrace();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   275
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   276
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   277
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   278
}