/* * Copyright 2000-2010 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.eclipse.tests; import java.io.File; import java.util.HashMap; import jetbrains.buildServer.agent.AgentRunningBuild; import jetbrains.buildServer.agent.BuildParametersMap; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.eclipse.EclipseConstants; import jetbrains.buildServer.eclipse.java.PlatformDescriptor; import jetbrains.buildServer.eclipse.tests.helper.EclipseBuilderFactoryTestAdapter; import org.jetbrains.annotations.Nullable; import org.jmock.Expectations; import org.jmock.Mockery; import org.junit.Assert; import org.junit.BeforeClass; public abstract class AbstractEclipseBuilderTest { private static final String TEST_DATA_ECLIPSE_HOME = String.format("%s/%s", getTestDataRoot(), "eclipse-HOME/eclipse"); protected static BuildRunnerContext createRunnerContext() { return createRunnerContext(new File("."), new File(System.getProperty("java.io.tmpdir")), null, null, null); } protected static File getEclipseHome() { return new File(TEST_DATA_ECLIPSE_HOME); } protected static File getEclipseProjectsHome() { return new File(getTestDataRoot()); } protected static String getTestDataRoot() { File testDataRoot = new File("test-data"); if (testDataRoot.exists()) { return "test-data"; } return "eclipse-tests/test-data"; } protected static BuildRunnerContext createRunnerContext(@Nullable String runnerPath, @Nullable String syspropPath, @Nullable String envPath) { return createRunnerContext(new File("."), new File(System.getProperty("java.io.tmpdir")), runnerPath, syspropPath, envPath); } protected static BuildRunnerContext createRunnerContext(@Nullable final File workingDirectory, @Nullable final File buildTempDirectory, @Nullable String runnerPath, @Nullable String syspropPath, @Nullable String envPath) { final Mockery m = new Mockery(); //build final BuildParametersMap bpm = m.mock(BuildParametersMap.class); final HashMap bsp = new HashMap(); final HashMap bev = new HashMap(); m.checking(new Expectations() { { allowing(bpm).getSystemProperties(); will(returnValue(bsp)); allowing(bpm).getEnvironmentVariables(); will(returnValue(bev)); } }); //build final AgentRunningBuild arb = m.mock(AgentRunningBuild.class); m.checking(new Expectations() { { allowing(arb).getBuildTempDirectory(); will(returnValue(buildTempDirectory)); } }); //runner parameters final HashMap brp = new HashMap(); final BuildRunnerContext mrc = m.mock(BuildRunnerContext.class); m.checking(new Expectations() { { allowing(mrc).getBuild(); will(returnValue(arb)); allowing(mrc).getRunnerParameters(); will(returnValue(brp)); allowing(mrc).getBuildParameters(); will(returnValue(bpm)); allowing(mrc).getWorkingDirectory(); will(returnValue(workingDirectory)); } }); if (runnerPath != null) { brp.put(EclipseConstants.SETTINGS_ECLIPSE_BASE, runnerPath); } if (syspropPath != null) { bsp.put(EclipseConstants.ECLIPSE_HOME_PROP_NAME, syspropPath); } if (envPath != null) { bev.put(EclipseConstants.ECLIPSE_HOME_ENV_NAME, envPath); } return mrc; } protected static PlatformDescriptor ourPlatform; @BeforeClass public static void setup() throws Exception { final File eclipseHome = getEclipseHome(); Assert.assertTrue(String.format("Eclipse home directory '%s' does not exist", eclipseHome), eclipseHome.exists()); BuildRunnerContext context = createRunnerContext(null, null, eclipseHome.getAbsolutePath()); final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); ourPlatform = testAdapter.getPlatform(context); } }