All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.smartdeveloperhub.jenkins.crawler.util.GitUtil Maven / Gradle / Ivy

Go to download

The Crawler for the Jenkins integration for the Continuous Integration Harvester of the Smart Developer Hub project

The newest version!
/**
 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
 *   This file is part of the Smart Developer Hub Project:
 *     http://www.smartdeveloperhub.org/
 *
 *   Center for Open Middleware
 *     http://www.centeropenmiddleware.com/
 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
 *   Copyright (C) 2015-2016 Center for Open Middleware.
 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
 *   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.
 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
 *   Artifact    : org.smartdeveloperhub.harvesters.ci.jenkins:ci-jenkins-crawler:0.3.0
 *   Bundle      : ci-jenkins-crawler-0.3.0.jar
 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
 */
package org.smartdeveloperhub.jenkins.crawler.util;

/**
 * Utility class to facilitate the normalization of branch specifier of the
 * Jenkins Git Plugin:
 *
 * 
*

* Specify the branches if you'd like to track a specific branch in a * repository. If left blank, all branches will be examined for changes and * built. *

* *

* The safest way is to use the refs/heads/<branchName> syntax. * This way the expected branch is unambiguous. *

* *

* If your branch name has a / in it make sure to use the full * reference above. When not presented with a full path the plugin will only use * the part of the string right of the last slash. Meaning foo/bar will * actually match bar *

* *

* Possible options: *

*
    *
  • <branchName>
    * Tracks/checks out the specified branch. If ambiguous the first result is * taken, which is not necessarily the expected one. Better use * refs/heads/<branchName>.
    * E.g. master, feature1,...
  • *
  • refs/heads/<branchName>
    * Tracks/checks out the specified branch.
    * E.g. refs/heads/master, refs/heads/feature1/master,...
  • *
  • <remoteRepoName>/<branchName>
    * Tracks/checks out the specified branch. If ambiguous the first result is * taken, which is not necessarily the expected one.
    * Better use refs/heads/<branchName>.
    * E.g. origin/master
  • *
  • remotes/<remoteRepoName>/<branchName>
    * Tracks/checks out the specified branch.
    * E.g. remotes/origin/master
  • *
  • refs/remotes/<remoteRepoName>/<branchName>
    * Tracks/checks out the specified branch.
    * E.g. refs/remotes/origin/master
  • *
  • <tagName>
    * This does not work since the tag will not be recognized as tag.
    * Use refs/tags/<tagName> instead.
    * E.g. git-2.3.0
  • *
  • refs/tags/<tagName>
    * Tracks/checks out the specified tag.
    * E.g. refs/tags/git-2.3.0
  • *
  • <commitId>
    * Checks out the specified commit.
    * E.g. 5062ac843f2b947733e6a3b105977056821bd352, 5062ac84, * ...
  • *
  • ${ENV_VARIABLE}
    * It is also possible to use environment variables. In this case the variables * are evaluated and the result is used as described above.
    * E.g. ${TREEISH}, refs/tags/${TAGNAME},...
  • *
  • <Wildcards>
    * The syntax is of the form: REPOSITORYNAME/BRANCH. In addition, * BRANCH is recognized as a shorthand of */BRANCH, '*' is * recognized as a wildcard, and '**' is recognized as wildcard that includes * the separator '/'. Therefore, origin/branches* would match * origin/branches-foo but not origin/branches/foo, while * origin/branches** would match both origin/branches-foo and * origin/branches/foo.
  • *
  • :<regular expression>
    * The syntax is of the form: :regexp. Regular expression syntax in * branches to build will only build those branches whose names match the * regular expression.
  • *
*

*

*
* * @author Miguel Esteban Gutiérrez * */ public final class GitUtil { private static String[] PREFERRED={"master","develop"}; private static final String REFS_REMOTES = "refs/remotes/"; private static final String REFS_HEADS = "refs/heads/"; private static final String REFS_TAGS = "refs/tags/"; private static final String REMOTES = "remotes/"; private GitUtil() { } public static String normalizeBranchName(final String branchName) { String normalized=branchName; if(normalized!=null) { final String[] parts=normalizeBranchNames(normalized); normalized=selectBranchName(parts); } return normalized; } private static String[] normalizeBranchNames(final String normalized) { final String[] parts=normalized.split("\\s"); for(int i=0;i1) { final int preferred = findPreferred(parts); if(preferred




© 2015 - 2025 Weber Informatics LLC | Privacy Policy