buildframework/helium/sf/java/scm/src/com/nokia/helium/scm/ant/actions/TagAction.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:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     1
/*
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     2
 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     3
 * All rights reserved.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     8
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     9
 * Initial Contributors:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    11
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    12
 * Contributors:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    13
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    14
 * Description:  
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    15
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    16
 */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    17
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    18
package com.nokia.helium.scm.ant.actions;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    19
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    20
import java.io.File;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    21
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    22
import org.apache.maven.scm.ScmException;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    23
import org.apache.maven.scm.ScmFileSet;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    24
import org.apache.maven.scm.command.tag.TagScmResult;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    25
import org.apache.maven.scm.repository.ScmRepository;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    26
import org.apache.tools.ant.BuildException;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    27
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    28
import com.nokia.maven.scm.manager.ExtendedScmManager;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    29
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    30
/**
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    31
 * This action will tag current repository revision using a specific name.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    32
 * 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    33
 * <pre>
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    34
 * &lt;hlm:scm verbose="true" scmUrl="scm:${repo.type}:${repo.dir}/test1"&gt;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    35
 *     &lt;hlm:tag baseDir="${repo.dir}/test1" name="0.0.1" /&gt;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    36
 * &lt;/hlm:scm&gt;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    37
 * </pre>
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    38
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    39
 * @ant.type name="tag" category="SCM"
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    40
 */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    41
public class TagAction extends BaseDirectoryScmAction {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    42
    private String name;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    43
    private String level = "normal";
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    44
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    45
    /**
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    46
     * String that will be used to tag the current revision.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    47
     * 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    48
     * @param name
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    49
     *            Name of the tag
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    50
     * @ant.required
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    51
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    52
    public void setName(String name) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    53
        this.name = name;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    54
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    55
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    56
    /**
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    57
     * String that will be used to determine tag types, eg. local.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    58
     * 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    59
     * @param level
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    60
     *            Level of the tag eg.local
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    61
     * @ant.not-required
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    62
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    63
    public void setLevel(String level) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    64
        this.level = level;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    65
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    66
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    67
    @Override
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    68
    public void execute(ScmRepository repository) throws ScmException {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    69
        TagScmResult result;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    70
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    71
        if (name == null) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    72
            throw new BuildException("'name' attribute is not defined.");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    73
        }
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    74
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    75
        if (getBasedir() == null) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    76
            throw new BuildException("'basedir' attribute is not defined.");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    77
        }
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    78
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    79
        try {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    80
            ExtendedScmManager scmManager = (ExtendedScmManager) getTask()
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    81
                    .getScmManager();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    82
            if (level.equals(new String("local"))) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    83
                result = scmManager.tag(repository, new ScmFileSet(new File(
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    84
                        getBasedir())), name, level);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    85
            } else {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    86
                result = scmManager.tag(repository, new ScmFileSet(new File(
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    87
                        getBasedir())), name);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    88
            }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    89
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    90
            if (!result.isSuccess()) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    91
                throw new BuildException("SCM tag action error: "
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    92
                        + result.getProviderMessage());
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    93
            }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    94
            getTask().log("Tag '" + name + "' has been created successfully.");
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    95
        } catch (ScmException e) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    96
            throw new BuildException("SCM tag action failed: " + e.toString());
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    97
        }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    98
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    99
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   100
}