blob: 408e34c28cb207e10d5a445947794400bb42fad1 [file] [log] [blame]
Paul Duffin7fc0b452015-11-10 17:45:15 +00001/*
2 * Copyright (C) 2010 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.caliper;
18
19import com.google.common.collect.ImmutableSet;
20
21import java.util.Arrays;
22import java.util.List;
23
24public final class VmFactory {
25 public static ImmutableSet<String> defaultVms() {
26 String vmName = DalvikVm.isDalvikVm()
27 ? DalvikVm.vmName()
28 : StandardVm.defaultVmName();
29 return ImmutableSet.of(vmName);
30 }
31
32 public Vm createVm(Scenario scenario) {
33 List<String> vmList = Arrays.asList(scenario.getVariables().get(Scenario.VM_KEY).split("\\s+"));
34 Vm vm = null;
35 if (!vmList.isEmpty()) {
36 if (vmList.get(0).endsWith("app_process")) {
37 vm = new DalvikVm();
38 } else if (vmList.get(0).endsWith("java")) {
39 vm = new StandardVm();
40 }
41 }
42 if (vm == null) {
43 vm = new Vm();
44 }
45 return vm;
46 }
47}