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 hudson.EnvVars;
 import hudson.Util;
 
 import java.util.List;
 import java.util.Map;

A release action which relates to Maven projects. All relevant information is taken from the gradle.properties file which is related to the Gradle build.

Author(s):
Tomer Cohen
 
 
     private transient Map<StringStringreleaseProps;
     private transient Map<StringStringnextIntegProps;
    
Map of release versions per module. Only used if versioning is per module
 
     private Map<StringStringreleaseVersionPerModule;
    
Map of dev versions per module. Only used if versioning is per module
 
     private Map<StringStringnextVersionPerModule;
 
     public GradleReleaseAction(FreeStyleProject project) {
         super(projectArtifactoryGradleConfigurator.class);
     }
 
     public String[] getReleaseProperties() {
         return getReleaseWrapper().getReleasePropsKeysList();
     }
 
     public String[] getNextIntegProperties() {
         return getReleaseWrapper().getNextIntegPropsKeysList();
     }

    
Initialize the version properties map from the gradle.properties file, and the additional properties from the gradle.properties file.
 
     @Override
     protected void initBuilderSpecific() throws Exception {
         reset();
         FilePath workspace = getModuleRoot(.);
         FilePath gradlePropertiesPath = new FilePath(workspace"gradle.properties");
         if ( == null) {
              = PropertyUtils.getModulesPropertiesFromPropFile(gradlePropertiesPathgetReleaseProperties());
         }
         if ( == null) {
              =
                     PropertyUtils.getModulesPropertiesFromPropFile(gradlePropertiesPathgetNextIntegProperties());
         }
     }

    
Get the root path where the build is located, the project may be checked out to a sub-directory from the root workspace location.

Parameters:
env EnvVars to take the workspace from, if workspace is not found then it is take from project.getSomeWorkspace()
Returns:
The location of the root of the Gradle build.
Throws:
java.io.IOException
java.lang.InterruptedException
        FilePath someWorkspace = .getSomeWorkspace();
        if (someWorkspace == null) {
            throw new IllegalStateException("Couldn't find workspace");
        }
        env.put("WORKSPACE"someWorkspace.getRemote());
        for (Builder builder : .getBuilders()) {
            if (builder instanceof Gradle) {
                Gradle gradleBuilder = (Gradlebuilder;
                String rootBuildScriptDir = gradleBuilder.getRootBuildScriptDir();
                if (rootBuildScriptDir != null && rootBuildScriptDir.trim().length() != 0) {
                    String rootBuildScriptNormalized = Util.replaceMacro(rootBuildScriptDir.trim(), env);
                    rootBuildScriptNormalized = Util.replaceMacro(rootBuildScriptNormalizedenv);
                    return new FilePath(someWorkspacerootBuildScriptNormalized);
                } else {
                    return someWorkspace;
                }
            }
        }
        throw new IllegalArgumentException("Couldn't find Gradle builder in the current builders list");
    }

    
Nullify the version properties map and the additional properties map, should be only called once the build is finished.

Since the GradleReleaseAction is saved in memory and is only build when re-saving a project's config or during startup, therefore a cleanup of the internal maps is needed.

    public void reset() {
         = null;
         = null;
         = null;
    }

    

Returns:
List of target repositories for deployment (release repositories first). Called from the UI.
    @Override
    @SuppressWarnings({"UnusedDeclaration"})
    public List<StringgetRepositoryKeys() {
        ArtifactoryServer server = getArtifactoryServer();
        if (server != null) {
            return getArtifactoryServer().getReleaseRepositoryKeysFirst();
        } else {
            return Collections.emptyList();
        }
    }
    @Override
        ArtifactoryGradleConfigurator configurator = getWrapper();
        if (configurator != null) {
            return configurator.getArtifactoryServer();
        }
        return null;
    }
    @Override
    public String latestVersioningSelection() {
        return ..name();
    }
    @SuppressWarnings({"UnusedDeclaration"})
    public String getValueForProp(String prop) {
        return .get(prop);
    }
    @Override
    public String calculateReleaseVersion(String fromVersion) {
        String version = .get(fromVersion);
        if (StringUtils.isBlank(version)) {
            version = .get(fromVersion);
        }
        if (StringUtils.isNotBlank(version)) {
            return super.calculateReleaseVersion(version);
        }
        return "";
    }
    public String getCurrentVersionFor(String moduleName) {
        return .get(moduleName);
    }
    @Override
    public String getReleaseVersionFor(Object moduleName) {
        switch () {
            case :
                return ;
            case :
                return .get(moduleName.toString());
            default:
                return null;
        }
    }
    @Override
    public String getNextVersionFor(Object moduleName) {
        switch () {
            case :
                return ;
            case :
                return .get(moduleName.toString());
            default:
                return null;
        }
    }
    @Override
        return getWrapper().getDetails().getStagingPlugin();
    }
    @Override
    protected void doPerModuleVersioning(StaplerRequest req) {
         = Maps.newHashMap();
         = Maps.newHashMap();
        Enumeration params = req.getParameterNames();
        while (params.hasMoreElements()) {
            String key = (Stringparams.nextElement();
            if (key.startsWith("release.")) {
                .put(StringUtils.removeStart(key"release."), req.getParameter(key));
            } else if (key.startsWith("next.")) {
                .put(StringUtils.removeStart(key"next."), req.getParameter(key));
            }
        }
    }
    @Override
    protected void prepareBuilderSpecificDefaultGlobalModule() {
    }
    @Override
    protected void prepareBuilderSpecificDefaultModules() {
         = Maps.newHashMap();
        for (String releaseProperties : getReleaseProperties()) {
            .put(releasePropertiesnew VersionedModule(releaseProperties,
                    calculateReleaseVersion(releaseProperties), null));
        }
        for (String nextIntegProperty : getNextIntegProperties()) {
            .put(nextIntegPropertynew VersionedModule(nextIntegProperty,
                    calculateReleaseVersion(nextIntegProperty), calculateNextVersion(nextIntegProperty)));
        }
    }
    @Override
    protected void prepareBuilderSpecificDefaultVcsConfig() {
        String defaultReleaseBranch = getDefaultReleaseBranch();
        String defaultTagUrl = getDefaultTagUrl();
         = new VcsConfig(StringUtils.isNotBlank(defaultReleaseBranch), defaultReleaseBranch,
                StringUtils.isNotBlank(defaultTagUrl), defaultTagUrlgetDefaultTagComment(),
                getDefaultNextDevelCommitMessage());
    }
    @Override
    }
        return getWrapper().getReleaseWrapper();
    }
    private String getDefaultReleaseBranch() {
        String releaseBranchPrefix = getReleaseWrapper().getReleaseBranchPrefix();
        return new StringBuilder(StringUtils.trimToEmpty(releaseBranchPrefix)).append(getFirstReleaseVersion())
                .toString();
    }
    private String getDefaultTagUrl() {
        String baseTagUrl = getReleaseWrapper().getTagPrefix();
    }
    private String getDefaultTagComment() {
        return new StringBuilder(.).append("Release version ")
                .append(getFirstReleaseVersion()).toString();
    }
    private String getFirstReleaseVersion() {
        return super.calculateReleaseVersion(getCurrentVersion());
    }
    private String getCurrentVersion() {
        String version = extractNumericVersion(.values());
        if (StringUtils.isBlank(version)) {
            version = extractNumericVersion(.values());
        }
        if (StringUtils.isBlank(version)) {
            if (!.values().isEmpty()) {
                version = .values().iterator().next();
            } else if (!.values().isEmpty()) {
                version = .values().iterator().next();
            }
        }
        return version;
    }

    
Try to extract a numeric version from a collection of strings.

Parameters:
versionStrings Collection of string properties.
Returns:
The version string if exists in the collection.
    private String extractNumericVersion(Collection<StringversionStrings) {
        if (versionStrings == null) {
            return "";
        }
        for (String value : versionStrings) {
            String releaseValue = calculateReleaseVersion(value);
            if (!releaseValue.equals(value)) {
                return releaseValue;
            }
        }
        return "";
    }

    

Returns:
The release repository configured in Artifactory publisher.
    private String getDefaultStagingRepository() {
        ArtifactoryGradleConfigurator publisher = getWrapper();
        if (publisher == null) {
            return null;
        }
        return publisher.getRepositoryKey();
    }
New to GrepCode? Check out our FAQ X