/* * 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.io.FileNotFoundException; import java.util.jar.Manifest; import jetbrains.buildServer.RunBuildException; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.eclipse.EclipseConstants; import jetbrains.buildServer.eclipse.java.BuildDescriptor; import jetbrains.buildServer.eclipse.java.JDTUtil; import jetbrains.buildServer.eclipse.tests.helper.EclipseBuildDescriptorTestAdapter; import jetbrains.buildServer.eclipse.tests.helper.EclipseBuilderFactoryTestAdapter; import org.junit.Assert; import org.junit.Test; public class EclipseBuildDescriptorTest extends AbstractEclipseBuilderTest { @Test(expected = RunBuildException.class) public void getBuildDescriptor_failed() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); testAdapter.getBuildDescriptor(ourPlatform, context); } @Test public void getBuildDescriptor_ok() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-feature-project/features/pfeature/.project").getPath()); final BuildDescriptor descriptor = testAdapter.getBuildDescriptor(ourPlatform, context); Assert.assertNotNull(descriptor); } @Test public void buildDescriptor_site() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-site-project/psite/.project").getPath()); final BuildDescriptor descriptor = testAdapter.getBuildDescriptor(ourPlatform, context); Assert.assertNotNull(descriptor); Assert.assertFalse(descriptor.isJava()); Assert.assertTrue(descriptor.isSite()); Assert.assertFalse(descriptor.isProduct()); Assert.assertFalse(descriptor.isFeature()); Assert.assertFalse(descriptor.isPlugin()); } @Test public void buildDescriptor_feature() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-feature-project/features/pfeature/.project").getPath()); final BuildDescriptor descriptor = testAdapter.getBuildDescriptor(ourPlatform, context); Assert.assertNotNull(descriptor); Assert.assertFalse(descriptor.isJava()); Assert.assertFalse(descriptor.isSite()); Assert.assertFalse(descriptor.isProduct()); Assert.assertTrue(descriptor.isFeature()); Assert.assertFalse(descriptor.isPlugin()); } @Test public void buildDescriptor_plugin() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-plugin-project/plugins/pplugin.ui/.project").getPath()); final BuildDescriptor descriptor = testAdapter.getBuildDescriptor(ourPlatform, context); Assert.assertNotNull(descriptor); Assert.assertTrue(descriptor.isJava()); Assert.assertFalse(descriptor.isSite()); Assert.assertFalse(descriptor.isProduct()); Assert.assertFalse(descriptor.isFeature()); Assert.assertTrue(descriptor.isPlugin()); } @Test public void buildDescriptor_java() 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()); final BuildDescriptor descriptor = testAdapter.getBuildDescriptor(ourPlatform, context); Assert.assertNotNull(descriptor); Assert.assertTrue(descriptor.isJava()); Assert.assertFalse(descriptor.isSite()); Assert.assertFalse(descriptor.isProduct()); Assert.assertFalse(descriptor.isFeature()); Assert.assertFalse(descriptor.isPlugin()); } @Test public void buildDescriptor_getProductTypes() throws Exception { /** @TODO: Assert.assertTrue("TODO: implement it", false); */ } @Test public void buildDescriptor_getPluginTypes_core() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-plugin-project/plugins/pplugin.core/.project").getPath()); final EclipseBuildDescriptorTestAdapter descriptor = new EclipseBuildDescriptorTestAdapter(testAdapter.getBuildDescriptor(ourPlatform, context)); final String[] pluginTypes = descriptor.getTypeId(); Assert.assertNotNull(pluginTypes); Assert.assertEquals(pluginTypes.length, 1); Assert.assertEquals(pluginTypes[0], "pplugin.core"); } @Test public void buildDescriptor_getPluginTypes_ui() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-plugin-project/plugins/pplugin.ui/.project").getPath()); final EclipseBuildDescriptorTestAdapter descriptor = new EclipseBuildDescriptorTestAdapter(testAdapter.getBuildDescriptor(ourPlatform, context)); final String[] pluginTypes = descriptor.getTypeId(); Assert.assertNotNull(pluginTypes); Assert.assertEquals(pluginTypes.length, 1); Assert.assertEquals(pluginTypes[0], "pplugin.ui"); } @Test public void buildDescriptor_getJavaTypes() 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()); final EclipseBuildDescriptorTestAdapter descriptor = new EclipseBuildDescriptorTestAdapter(testAdapter.getBuildDescriptor(ourPlatform, context)); Assert.assertEquals(descriptor.getType(), EclipseConstants.ECLIPSE_BUILD_TYPE_JAVA); final String[] javaProjectTypes = descriptor.getTypeId(); Assert.assertNotNull(javaProjectTypes); Assert.assertEquals(javaProjectTypes.length, 1); Assert.assertEquals(javaProjectTypes[0], "jproject"); } @Test public void buildDescriptor_getFeatureTypes() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-feature-project/features/pfeature/.project").getPath()); final EclipseBuildDescriptorTestAdapter descriptor = new EclipseBuildDescriptorTestAdapter(testAdapter.getBuildDescriptor(ourPlatform, context)); Assert.assertEquals(descriptor.getType(), EclipseConstants.ECLIPSE_BUILD_TYPE_FEATURE); final String[] featureTypes = descriptor.getFeatureTypes(); Assert.assertNotNull(featureTypes); Assert.assertEquals(featureTypes.length, 1); Assert.assertEquals(featureTypes[0], "pfeature"); } @Test public void buildDescriptor_getSiteTypes() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-site-project/psite/.project").getPath()); final EclipseBuildDescriptorTestAdapter descriptor = new EclipseBuildDescriptorTestAdapter(testAdapter.getBuildDescriptor(ourPlatform, context)); Assert.assertEquals(descriptor.getType(), EclipseConstants.ECLIPSE_BUILD_TYPE_FEATURE); final String[] featureTypes = descriptor.getSiteTypes(); Assert.assertNotNull(featureTypes); Assert.assertEquals(featureTypes.length, 2); Assert.assertEquals(featureTypes[0], "pfeature"); Assert.assertEquals(featureTypes[1], "sfeature"); } @Test public void buildDescriptor_findManifest_ok() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-plugin-project/plugins/pplugin.ui/.project").getPath()); final EclipseBuildDescriptorTestAdapter descriptor = new EclipseBuildDescriptorTestAdapter(testAdapter.getBuildDescriptor(ourPlatform, context)); final Manifest manifest = JDTUtil.findManifest(descriptor.getProjectFile().getParentFile()); Assert.assertNotNull(manifest); } public void buildDescriptor_findManifest_fail() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-plugin-project/plugins/pplugin.ui/.project").getPath()); final EclipseBuildDescriptorTestAdapter descriptor = new EclipseBuildDescriptorTestAdapter(testAdapter.getBuildDescriptor(ourPlatform, context)); final Manifest manifest = JDTUtil.findManifest(descriptor.getProjectFile().getParentFile().getParentFile()); Assert.assertNull(manifest); } @Test public void buildDescriptor_wellformed_feature_folder() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-feature-project/features/pfeature/.project").getPath()); final BuildDescriptor descriptor = testAdapter.getBuildDescriptor(ourPlatform, context); Assert.assertNotNull(descriptor); Assert.assertNotNull(descriptor.getFeaturesFolder()); Assert.assertTrue(descriptor.getFeaturesFolder().exists()); Assert.assertEquals("features", descriptor.getFeaturesFolder().getName()); } @Test public void buildDescriptor_wellformed_plugins_folder() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-feature-project/features/pfeature/.project").getPath()); final BuildDescriptor descriptor = testAdapter.getBuildDescriptor(ourPlatform, context); Assert.assertNotNull(descriptor); Assert.assertNotNull(descriptor.getPluginsFolder()); Assert.assertTrue(descriptor.getPluginsFolder().exists()); Assert.assertEquals("plugins", descriptor.getPluginsFolder().getName()); } @Test public void buildDescriptor_feature_version() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-feature-project/features/pfeature/.project").getPath()); final BuildDescriptor descriptor = testAdapter.getBuildDescriptor(ourPlatform, context); Assert.assertNotNull(descriptor); Assert.assertEquals("pfeature", descriptor.getTypeId()[0]); Assert.assertEquals("1.0.0.qualifier", descriptor.getTypeVersion(descriptor.getTypeId()[0])); } @Test public void buildDescriptor_plugin_version() throws Exception { final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final BuildRunnerContext context = createRunnerContext(); context.getRunnerParameters().put(EclipseConstants.SETTINGS_RELATIVE_PATH_TO_PROJECT, new File(getEclipseProjectsHome(), "projects-structured/project-feature-project/plugins/pplugin.core/.project").getPath()); final BuildDescriptor descriptor = testAdapter.getBuildDescriptor(ourPlatform, context); Assert.assertNotNull(descriptor); Assert.assertEquals("pplugin.core", descriptor.getTypeId()[0]); Assert.assertEquals("1.0.0.qualifier", descriptor.getTypeVersion(descriptor.getTypeId()[0])); } }