view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ViaCMDInterceptor.java @ 953:ef995b1ed5ec

update dsl attributes
author Dmitry Neverov <dmitry.neverov@gmail.com>
date Wed, 22 Jun 2016 21:33:59 +0200
parents 64fb4e1e23a2
children 7bf4d943d5bb
line wrap: on
line source
/*
 * Copyright 2000-2014 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.buildTriggers.vcs.mercurial;

import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.TestCommandSettingsFactory;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.VersionCommand;
import org.testng.IMethodInstance;
import org.testng.IMethodInterceptor;
import org.testng.ITestContext;

import java.io.File;
import java.util.Collections;
import java.util.List;

/**
 * Created 03.06.2014 13:22
 *
 * @author Eugene Petrenko (eugene.petrenko@jetbrains.com)
 */
public class ViaCMDInterceptor implements IMethodInterceptor {
  public List<IMethodInstance> intercept(List<IMethodInstance> list, ITestContext iTestContext) {
    if (!"true".equalsIgnoreCase(System.getProperty("teamcity.mercurial.use.commandline.via.file.wrapper"))) {
      return list;
    }

    try {
      final String path = Util.getHgPath();
      final VersionCommand versionCommand = new VersionCommand(new TestCommandSettingsFactory().create(), path, new File(".."));
      final HgVersion version = versionCommand.call();

      if (!version.isEqualsOrGreaterThan(new HgVersion(2,5,0))) {
        System.out.println("!!! Mercurial version is too old: " + version + "  @ " + path);
        return Collections.emptyList();
      }

      return list;
    } catch (Throwable t) {
      System.out.println("Invalid mercurial: " + t.getMessage());
      return Collections.emptyList();
    }
  }
}