Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2011 JFrog Ltd.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.jfrog.hudson.release.gradle;
 
 
 import java.util.Map;
A release wrapper for Gradle projects. Allows performing release steps on Gradle. This class is not a direct hudson.tasks.BuildWrapper but is called from the org.jfrog.hudson.gradle.ArtifactoryGradleConfigurator as part of the release procedure.

Author(s):
Tomer Cohen
 
 public class GradleReleaseWrapper {
     private final static Logger debuggingLogger = Logger.getLogger(GradleReleaseWrapper.class.getName());
 
     private String tagPrefix;
     private String releaseBranchPrefix;
     private String alternativeTasks;
     private String releasePropsKeys;
     private String nextIntegPropsKeys;
 
     private transient ScmCoordinator scmCoordinator;
 
     public GradleReleaseWrapper(String releaseBranchPrefixString tagPrefixString alternativeTasks,
             String releasePropsKeysString nextIntegPropsKeys) {
         this. = releaseBranchPrefix;
         this. = tagPrefix;
         this. = alternativeTasks;
         this. = releasePropsKeys;
         this. = nextIntegPropsKeys;
     }
 
     public ScmCoordinator getScmCoordinator() {
         return ;
     }
 
     @SuppressWarnings({"UnusedDeclaration"})
     public String getTagPrefix() {
         return ;
     }
 
     @SuppressWarnings({"UnusedDeclaration"})
     public void setTagPrefix(String tagPrefix) {
         this. = tagPrefix;
     }
 
     public String getReleasePropsKeys() {
         return ;
     }
 
     @SuppressWarnings({"UnusedDeclaration"})
     public void setReleasePropsKeys(String releasePropsKeys) {
         this. = releasePropsKeys;
     }
 
     public String getNextIntegPropsKeys() {
         return ;
     }
 
     @SuppressWarnings({"UnusedDeclaration"})
     public void setNextIntegPropsKeys(String nextIntegPropsKeys) {
         this. = nextIntegPropsKeys;
     }
 
     public String getReleaseBranchPrefix() {
         return ;
     }
 
     @SuppressWarnings({"UnusedDeclaration"})
    public void setReleaseBranchPrefix(String releaseBranchPrefix) {
        this. = releaseBranchPrefix;
    }
    @SuppressWarnings({"UnusedDeclaration"})
    public String getAlternativeTasks() {
        return ;
    }
    @SuppressWarnings({"UnusedDeclaration"})
    public void setAlternativeTasks(String alternativeTasks) {
        this. = alternativeTasks;
    }
    public String[] getReleasePropsKeysList() {
        return stringToArray(getReleasePropsKeys());
    }
    public String[] getNextIntegPropsKeysList() {
        return stringToArray(getNextIntegPropsKeys());
    }
    private String[] stringToArray(String commaSeparatedString) {
        commaSeparatedString = StringUtils.trimToEmpty(commaSeparatedString);
        return StringUtils.split(commaSeparatedString", ");
    }
    public void setUp(AbstractBuild buildLauncher launcherBuildListener listener)
            throws IOExceptionInterruptedException {
        final GradleReleaseAction releaseAction = build.getAction(GradleReleaseAction.class);
        if (releaseAction == null) {
            // this is a normal non release build, continue with normal environment
            return;
        }
        log(listener"Release build triggered");
         = AbstractScmCoordinator.createScmCoordinator(buildlistenerreleaseAction);
        .prepare();
        // TODO: replace the versioning mode with something else
        if (!releaseAction.getVersioning().equals(..)) {
            // change to release properties values
            boolean modified = changeProperties(buildreleaseActiontruelistener);
            .afterReleaseVersionChange(modified);
        }
    }
    public boolean tearDown(AbstractBuild buildBuildListener listener) {
        Result result = build.getResult();
        if (result == null || result.isWorseThan(.)) {
            // revert will happen by the listener
            return true;
        }
        final GradleReleaseAction releaseAction = build.getAction(GradleReleaseAction.class);
        try {
            if (!releaseAction.getVersioning().equals(..)) {
                .beforeDevelopmentVersionChange();
                boolean modified = changeProperties(buildreleaseActionfalselistener);
                .afterDevelopmentVersionChange(modified);
            }
        } catch (Exception e) {
            listener.getLogger().println("Failure in post build SCM action: " + e.getMessage());
            .log(."Failure in post build SCM action: "e);
            return false;
        }
        return true;
    }
    private boolean changeProperties(AbstractBuild buildGradleReleaseAction releaseboolean releaseVersion,
            BuildListener listenerthrows IOExceptionInterruptedException {
        FilePath root = release.getModuleRoot(build.getEnvironment(listener));
        .fine("Root directory is: " + root.getRemote());
        String[] modules = release.getReleaseProperties();
        Map<StringStringmodulesByName = Maps.newHashMap();
        for (String module : modules) {
            String version = releaseVersion ? release.getReleaseVersionFor(module) :
                    release.getCurrentVersionFor(module);
            modulesByName.put(moduleversion);
        }
        String[] additionalModuleProperties = release.getNextIntegProperties();
        for (String property : additionalModuleProperties) {
            String version = releaseVersion ? release.getReleaseVersionFor(property) :
                    release.getNextVersionFor(property);
            modulesByName.put(propertyversion);
        }
        .fine("Changing version of gradle properties");
        FilePath gradlePropertiesFilePath = new FilePath(root"gradle.properties");
        String next = releaseVersion ? "release" : "development";
        log(listener,
                "Changing gradle.properties at " + gradlePropertiesFilePath.getRemote() + " for " + next + " version");
        .edit(gradlePropertiesFilePath);
        return gradlePropertiesFilePath.act(new GradlePropertiesTransformer(modulesByName));
    }
    private void log(BuildListener listenerString message) {
        listener.getLogger().println("[RELEASE] " + message);
    }
New to GrepCode? Check out our FAQ X