package jetbrains.buildServer.eclipse.tests; import java.io.File; import java.util.HashSet; import java.util.List; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.eclipse.EclipseConstants; import jetbrains.buildServer.eclipse.agent.builder.ant.BuildFileCreator; import jetbrains.buildServer.eclipse.java.JDTUtil; import jetbrains.buildServer.eclipse.java.JDTUtil.IWorkspaceRootProvider; import jetbrains.buildServer.eclipse.tests.helper.EclipseBuildDescriptorTestAdapter; import jetbrains.buildServer.eclipse.tests.helper.EclipseBuilderFactoryTestAdapter; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; public class JavaProjectBuilderTest extends AbstractEclipseBuilderTest { private static EclipseBuildDescriptorTestAdapter ourJavaBuildDescriptor; @BeforeClass public static void init() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "project-flat/project-java-project/.project").getPath()); ourJavaBuildDescriptor = new EclipseBuildDescriptorTestAdapter(testAdapter.getBuildDescriptor(ourPlatform, context)); Assert.assertEquals(ourJavaBuildDescriptor.getType(), EclipseConstants.ECLIPSE_BUILD_TYPE_JAVA); final String[] javaProjectTypes = ourJavaBuildDescriptor.getTypeId(); Assert.assertNotNull(javaProjectTypes); Assert.assertEquals(javaProjectTypes.length, 1); Assert.assertEquals(javaProjectTypes[0], "jproject"); //setup root JDTUtil.setWorkspaceRootProvider(new IWorkspaceRootProvider() { public File getWorkspaceRoot() { return new File(getTestDataRoot()).getAbsoluteFile(); } }); } @Test public void create_simple_project() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "project-flat/main/main-java-project/.project").getPath()); final EclipseBuildDescriptorTestAdapter build = new EclipseBuildDescriptorTestAdapter(testAdapter.getBuildDescriptor(ourPlatform, context)); final HashSet unresolvedLibs = new HashSet(); final HashSet unresolvedVars = new HashSet(); final List build_xmls = BuildFileCreator.createBuildFiles(ourPlatform, build, unresolvedLibs, unresolvedVars); Assert.assertNotNull(build_xmls); Assert.assertEquals(1, build_xmls.size()); Assert.assertEquals("[]", unresolvedLibs.toString()); Assert.assertEquals("[]", unresolvedVars.toString()); } @Test public void create_master_slave() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); final File dotProject = new File(getEclipseProjectsHome(), "project-flat/project-java-project/.project"); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, dotProject.getPath()); final EclipseBuildDescriptorTestAdapter build = new EclipseBuildDescriptorTestAdapter(testAdapter.getBuildDescriptor(ourPlatform, context)); final HashSet unresolvedLibs = new HashSet(); final HashSet unresolvedVars = new HashSet(); final List build_xmls = BuildFileCreator.createBuildFiles(ourPlatform, build, unresolvedLibs, unresolvedVars); Assert.assertNotNull(build_xmls); Assert.assertEquals(2, build_xmls.size()); Assert.assertEquals(new File(dotProject.getParentFile().getAbsoluteFile(), "build.xml"), build_xmls.get(0)); Assert.assertEquals("[]", unresolvedLibs.toString()); Assert.assertEquals("[]", unresolvedVars.toString()); } }