/* * Copyright 2000-2015 JetBrains s.r.o. * * 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 jetbrains.buildServer.runner.rakerunner; import jetbrains.buildServer.rakerunner.RakeRunnerBundle; import jetbrains.buildServer.rakerunner.RakeRunnerConstants; import jetbrains.buildServer.runner.BuildFileRunnerConstants; import jetbrains.buildServer.serverSide.discovery.BreadthFirstRunnerDiscoveryExtension; import jetbrains.buildServer.serverSide.discovery.DiscoveredObject; import jetbrains.buildServer.util.CollectionsUtil; import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.util.browser.Element; import org.jetbrains.annotations.NotNull; import java.util.*; /** * @author Vladislav.Rassokhin * @since 8.1 */ public class RakeRunnerDiscoveryExtension extends BreadthFirstRunnerDiscoveryExtension { private static final Set KNOWN_RAKEFILE_NAMES = CollectionsUtil.setOf("Rakefile", "rakefile", "Rakefile.rb", "rakefile.rb"); @NotNull @Override protected List discoverRunnersInDirectory(@NotNull final Element dir, @NotNull final List files) { final ArrayList discovered = new ArrayList(); final List rakefiles = new LinkedList(); Element gemfile = null; for (Element file : files) { if (KNOWN_RAKEFILE_NAMES.contains(file.getName())) { rakefiles.add(file); } else if (file.getName().equalsIgnoreCase("Gemfile")) { gemfile = file; } } for (Element rakefile : rakefiles) { // For weird case of multiple rakefiles in same directory (with/without .rb, first letter case) final String description = RakeRunnerBundle.RUNNER_DISPLAY_NAME + " (" + rakefile.getFullName() + ")"; final Map params = CollectionsUtil.asMap( BuildFileRunnerConstants.BUILD_FILE_PATH_KEY, FileUtil.toSystemIndependentName(rakefile.getFullName()) ); if (gemfile != null) { params.put(RakeRunnerConstants.SERVER_UI_BUNDLE_EXEC_PROPERTY, Boolean.TRUE.toString()); } discovered.add(new DiscoveredObject(RakeRunnerConstants.RUNNER_TYPE, params)); } return discovered; } }