|
1 |
| -package io.sloeber.autoBuild.regression; |
2 |
| - |
3 |
| -import java.util.HashMap; |
4 |
| -import java.util.HashSet; |
5 |
| -import java.util.LinkedList; |
6 |
| -import java.util.List; |
7 |
| -import java.util.Map; |
8 |
| -import java.util.Map.Entry; |
9 |
| -import java.util.Set; |
10 |
| -import java.util.stream.Stream; |
11 |
| - |
12 |
| -import org.eclipse.cdt.core.CCProjectNature; |
13 |
| -import org.eclipse.cdt.core.CCorePlugin; |
14 |
| -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; |
15 |
| -import org.eclipse.cdt.core.settings.model.ICProjectDescription; |
16 |
| -import org.eclipse.core.resources.IProject; |
17 |
| -import org.eclipse.core.resources.IWorkspace; |
18 |
| -import org.eclipse.core.resources.IWorkspaceDescription; |
19 |
| -import org.eclipse.core.resources.ResourcesPlugin; |
20 |
| -import org.junit.jupiter.api.BeforeAll; |
21 |
| -import org.junit.jupiter.params.ParameterizedTest; |
22 |
| -import org.junit.jupiter.params.provider.Arguments; |
23 |
| -import org.junit.jupiter.params.provider.MethodSource; |
24 |
| - |
25 |
| -import io.sloeber.autoBuild.api.AutoBuildProject; |
26 |
| -import io.sloeber.autoBuild.api.IAutoBuildConfigurationDescription; |
27 |
| -import io.sloeber.autoBuild.api.ICodeProvider; |
28 |
| -import io.sloeber.autoBuild.extensionPoint.providers.AutoBuildCommon; |
29 |
| -import io.sloeber.autoBuild.helpers.Shared; |
30 |
| -import io.sloeber.autoBuild.helpers.TemplateTestCodeProvider; |
31 |
| -import io.sloeber.autoBuild.integration.AutoBuildManager; |
32 |
| -import io.sloeber.schema.api.IProjectType; |
33 |
| - |
34 |
| -@SuppressWarnings({ "boxing", "nls", "static-method" }) |
35 |
| -public class CreateBasicProjects { |
36 |
| - static int testCounter = 1; |
37 |
| - |
38 |
| - @BeforeAll |
39 |
| - static void beforeAll() { |
40 |
| - Shared.setDeleteProjects(false); |
41 |
| - Shared.setCloseProjects(false); |
42 |
| - // turn off auto building to make sure autobuild does not start a build behind our backs |
43 |
| - final IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
44 |
| - IWorkspaceDescription workspaceDesc = workspace.getDescription(); |
45 |
| - workspaceDesc.setAutoBuilding(false); |
46 |
| - } |
47 |
| - |
48 |
| - static void buildAllConfigsAsActive(String builderName, String projectName, String extensionPointID, |
49 |
| - String extensionID, String projectTypeID, String natureID, ICodeProvider codeProvider, |
50 |
| - Boolean shouldMakefileExists) throws Exception { |
51 |
| - |
52 |
| - IProject testProject = AutoBuildProject.createProject(String.format("%03d", testCounter++) + "_" + projectName, |
53 |
| - extensionPointID, extensionID, projectTypeID, natureID, codeProvider, false, null); |
54 |
| - ICProjectDescription cProjectDesc = CCorePlugin.getDefault().getProjectDescription(testProject, true); |
55 |
| - for (ICConfigurationDescription curConfig : cProjectDesc.getConfigurations()) { |
56 |
| - cProjectDesc.setActiveConfiguration(curConfig); |
57 |
| - CCorePlugin.getDefault().setProjectDescription(testProject, cProjectDesc); |
58 |
| - Shared.BuildAndVerifyActiveConfig(testProject, builderName, shouldMakefileExists); |
59 |
| - } |
60 |
| - } |
61 |
| - |
62 |
| - static void buildAllConfigs(String builderName, String projectName, String extensionPointID, String extensionID, |
63 |
| - String projectTypeID, String natureID, ICodeProvider codeProvider, Boolean shouldMakefileExists) |
64 |
| - throws Exception { |
65 |
| - |
66 |
| - IProject testProject = AutoBuildProject.createProject(String.format("%03d", testCounter++) + "_" + projectName, |
67 |
| - extensionPointID, extensionID, projectTypeID, natureID, codeProvider, false, null); |
68 |
| - ICProjectDescription cProjectDesc = CCorePlugin.getDefault().getProjectDescription(testProject, true); |
69 |
| - Set<String> configs = new HashSet<>(); |
70 |
| - |
71 |
| - for (ICConfigurationDescription curConfig : cProjectDesc.getConfigurations()) { |
72 |
| - configs.add(curConfig.getName()); |
73 |
| - } |
74 |
| - Shared.build(testProject, builderName, AutoBuildProject.encode(configs)); |
75 |
| - for (ICConfigurationDescription curConfig : cProjectDesc.getConfigurations()) { |
76 |
| - |
77 |
| - Shared.verifyConfig(testProject, IAutoBuildConfigurationDescription.getConfig(curConfig), |
78 |
| - shouldMakefileExists); |
79 |
| - } |
80 |
| - } |
81 |
| - |
82 |
| - @ParameterizedTest |
83 |
| - @MethodSource("projectCreationInfoProvider") |
84 |
| - void testDefaultBuilder(String projectName, String extensionPointID, String extensionID, String projectTypeID, |
85 |
| - String natureID, ICodeProvider codeProvider) throws Exception { |
86 |
| - buildAllConfigsAsActive(null, projectName, extensionPointID, extensionID, projectTypeID, natureID, codeProvider, |
87 |
| - null); |
88 |
| - buildAllConfigs(null, "all_" + projectName, extensionPointID, extensionID, projectTypeID, natureID, |
89 |
| - codeProvider, null); |
90 |
| - |
91 |
| - } |
92 |
| - |
93 |
| - @ParameterizedTest |
94 |
| - @MethodSource("projectCreationInfoProvider") |
95 |
| - void testInternaltBuilder(String inProjectName, String extensionPointID, String extensionID, String projectTypeID, |
96 |
| - String natureID, ICodeProvider codeProvider) throws Exception { |
97 |
| - String projectName = "Internal_build_" + inProjectName; |
98 |
| - buildAllConfigsAsActive(AutoBuildProject.ARGS_INTERNAL_BUILDER_KEY, projectName, extensionPointID, extensionID, |
99 |
| - projectTypeID, natureID, codeProvider, Boolean.FALSE); |
100 |
| - buildAllConfigs(AutoBuildProject.ARGS_INTERNAL_BUILDER_KEY, "all_" + projectName, extensionPointID, extensionID, |
101 |
| - projectTypeID, natureID, codeProvider, Boolean.FALSE); |
102 |
| - } |
103 |
| - |
104 |
| - @ParameterizedTest |
105 |
| - @MethodSource("projectCreationInfoProvider") |
106 |
| - void testExternalBuilder(String inProjectName, String extensionPointID, String extensionID, String projectTypeID, |
107 |
| - String natureID, ICodeProvider codeProvider) throws Exception { |
108 |
| - String projectName = "make_build_" + inProjectName; |
109 |
| - buildAllConfigsAsActive(AutoBuildProject.ARGS_MAKE_BUILDER_KEY, projectName, extensionPointID, extensionID, |
110 |
| - projectTypeID, natureID, codeProvider, Boolean.TRUE); |
111 |
| - buildAllConfigs(AutoBuildProject.ARGS_MAKE_BUILDER_KEY, "all_" + projectName, extensionPointID, extensionID, |
112 |
| - projectTypeID, natureID, codeProvider, Boolean.TRUE); |
113 |
| - } |
114 |
| - |
115 |
| - static Stream<Arguments> projectCreationInfoProvider() { |
116 |
| - String extensionPointID = "io.sloeber.autoBuild.buildDefinitions"; |
117 |
| - Map<String, String> testProjectTypeIds = new HashMap<>(); |
118 |
| - testProjectTypeIds.put("io.sloeber.autoBuild.projectType.exe", "io.sloeber.autoBuild"); |
119 |
| - testProjectTypeIds.put("cdt.managedbuild.target.gnu.cross.exe", "cdt.cross.gnu"); |
120 |
| - testProjectTypeIds.put("cdt.managedbuild.target.gnu.cross.so", "cdt.cross.gnu"); |
121 |
| - testProjectTypeIds.put("cdt.managedbuild.target.gnu.cross.lib", "cdt.cross.gnu"); |
122 |
| - |
123 |
| - List<Arguments> ret = new LinkedList<>(); |
124 |
| - for (Entry<String, String> testProjectEntry : testProjectTypeIds.entrySet()) { |
125 |
| - String extensionID = testProjectEntry.getValue(); |
126 |
| - String projectID = testProjectEntry.getKey(); |
127 |
| - IProjectType projectType = AutoBuildManager.getProjectType(extensionPointID, extensionID, projectID, true); |
128 |
| - if (projectType == null || !projectType.isCompatibleWithLocalOS() || projectType.isAbstract()) { |
129 |
| - System.err.println("Skipping " + extensionID + " " + projectID); |
130 |
| - continue; |
131 |
| - } |
132 |
| - String buildArtifactType = projectType.getBuildArtifactType(); |
133 |
| - ICodeProvider codeProvider_cpp = null; |
134 |
| - switch (buildArtifactType) { |
135 |
| - case "org.eclipse.cdt.build.core.buildArtefactType.exe": |
136 |
| - codeProvider_cpp = new TemplateTestCodeProvider("exe"); |
137 |
| - break; |
138 |
| - case "org.eclipse.cdt.build.core.buildArtefactType.staticLib": |
139 |
| - case "org.eclipse.cdt.build.core.buildArtefactType.sharedLib": |
140 |
| - codeProvider_cpp = new TemplateTestCodeProvider("lib"); |
141 |
| - break; |
142 |
| - case "org.eclipse.cdt.build.core.buildArtefactType.compound": |
143 |
| - codeProvider_cpp = new TemplateTestCodeProvider("compound"); |
144 |
| - break; |
145 |
| - default: |
146 |
| - codeProvider_cpp = new TemplateTestCodeProvider("exe"); |
147 |
| - } |
148 |
| - String projectName = AutoBuildCommon.MakeNameCompileSafe(projectType.getName() + "_" + extensionID); |
149 |
| - ret.add(Arguments.of(projectName, extensionPointID, extensionID, projectType.getId(), |
150 |
| - CCProjectNature.CC_NATURE_ID, codeProvider_cpp)); |
151 |
| - } |
152 |
| - return ret.stream(); |
153 |
| - } |
154 |
| -} |
| 1 | +package io.sloeber.autoBuild.regression; |
| 2 | + |
| 3 | +import java.util.HashMap; |
| 4 | +import java.util.HashSet; |
| 5 | +import java.util.LinkedList; |
| 6 | +import java.util.List; |
| 7 | +import java.util.Map; |
| 8 | +import java.util.Map.Entry; |
| 9 | +import java.util.Set; |
| 10 | +import java.util.stream.Stream; |
| 11 | + |
| 12 | +import org.eclipse.cdt.core.CCProjectNature; |
| 13 | +import org.eclipse.cdt.core.CCorePlugin; |
| 14 | +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; |
| 15 | +import org.eclipse.cdt.core.settings.model.ICProjectDescription; |
| 16 | +import org.eclipse.core.resources.IProject; |
| 17 | +import org.eclipse.core.resources.IWorkspace; |
| 18 | +import org.eclipse.core.resources.IWorkspaceDescription; |
| 19 | +import org.eclipse.core.resources.ResourcesPlugin; |
| 20 | +import org.junit.jupiter.api.BeforeAll; |
| 21 | +import org.junit.jupiter.params.ParameterizedTest; |
| 22 | +import org.junit.jupiter.params.provider.Arguments; |
| 23 | +import org.junit.jupiter.params.provider.MethodSource; |
| 24 | + |
| 25 | +import io.sloeber.autoBuild.api.AutoBuildProject; |
| 26 | +import io.sloeber.autoBuild.api.IAutoBuildConfigurationDescription; |
| 27 | +import io.sloeber.autoBuild.api.ICodeProvider; |
| 28 | +import io.sloeber.autoBuild.extensionPoint.providers.AutoBuildCommon; |
| 29 | +import io.sloeber.autoBuild.helpers.Shared; |
| 30 | +import io.sloeber.autoBuild.helpers.TemplateTestCodeProvider; |
| 31 | +import io.sloeber.autoBuild.integration.AutoBuildManager; |
| 32 | +import io.sloeber.schema.api.IProjectType; |
| 33 | + |
| 34 | +@SuppressWarnings({ "boxing", "nls" }) |
| 35 | +public class CreateBasicProjects { |
| 36 | + static int testCounter = 1; |
| 37 | + private boolean buildTypeActiveBuild = false; |
| 38 | + |
| 39 | + @BeforeAll |
| 40 | + static void beforeAll() { |
| 41 | + Shared.setDeleteProjects(false); |
| 42 | + Shared.setCloseProjects(false); |
| 43 | + // turn off auto building to make sure autobuild does not start a build behind our backs |
| 44 | + final IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 45 | + IWorkspaceDescription workspaceDesc = workspace.getDescription(); |
| 46 | + workspaceDesc.setAutoBuilding(false); |
| 47 | + } |
| 48 | + |
| 49 | + static void buildAllConfigsAsActive(String builderName, String projectName, String extensionPointID, |
| 50 | + String extensionID, String projectTypeID, String natureID, ICodeProvider codeProvider, |
| 51 | + Boolean shouldMakefileExists) throws Exception { |
| 52 | + |
| 53 | + IProject testProject = AutoBuildProject.createProject(String.format("%03d", testCounter++) + "_" + projectName, |
| 54 | + extensionPointID, extensionID, projectTypeID, natureID, codeProvider, false, null); |
| 55 | + ICProjectDescription cProjectDesc = CCorePlugin.getDefault().getProjectDescription(testProject, true); |
| 56 | + for (ICConfigurationDescription curConfig : cProjectDesc.getConfigurations()) { |
| 57 | + cProjectDesc.setActiveConfiguration(curConfig); |
| 58 | + CCorePlugin.getDefault().setProjectDescription(testProject, cProjectDesc); |
| 59 | + Shared.BuildAndVerifyActiveConfig(testProject, builderName, shouldMakefileExists); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + static void buildAllConfigs(String builderName, String projectName, String extensionPointID, String extensionID, |
| 64 | + String projectTypeID, String natureID, ICodeProvider codeProvider, Boolean shouldMakefileExists) |
| 65 | + throws Exception { |
| 66 | + |
| 67 | + IProject testProject = AutoBuildProject.createProject(String.format("%03d", testCounter++) + "_" + projectName, |
| 68 | + extensionPointID, extensionID, projectTypeID, natureID, codeProvider, false, null); |
| 69 | + ICProjectDescription cProjectDesc = CCorePlugin.getDefault().getProjectDescription(testProject, true); |
| 70 | + Set<String> configs = new HashSet<>(); |
| 71 | + |
| 72 | + for (ICConfigurationDescription curConfig : cProjectDesc.getConfigurations()) { |
| 73 | + configs.add(curConfig.getName()); |
| 74 | + } |
| 75 | + Shared.build(testProject, builderName, AutoBuildProject.encode(configs)); |
| 76 | + for (ICConfigurationDescription curConfig : cProjectDesc.getConfigurations()) { |
| 77 | + |
| 78 | + Shared.verifyConfig(testProject, IAutoBuildConfigurationDescription.getConfig(curConfig), |
| 79 | + shouldMakefileExists); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + private void doBuilds(String argsInternalBuilderKey, String projectName, String extensionPointID, |
| 84 | + String extensionID, String projectTypeID, String natureID, ICodeProvider codeProvider, |
| 85 | + Boolean shouldMakefileExists) throws Exception { |
| 86 | + if (buildTypeActiveBuild) { |
| 87 | + buildAllConfigsAsActive(argsInternalBuilderKey, projectName, extensionPointID, extensionID, projectTypeID, |
| 88 | + natureID, codeProvider, shouldMakefileExists); |
| 89 | + } |
| 90 | + if (!buildTypeActiveBuild) { |
| 91 | + buildAllConfigs(argsInternalBuilderKey, "all_" + projectName, extensionPointID, extensionID, projectTypeID, |
| 92 | + natureID, codeProvider, shouldMakefileExists); |
| 93 | + } |
| 94 | + |
| 95 | + } |
| 96 | + |
| 97 | + @ParameterizedTest |
| 98 | + @MethodSource("projectCreationInfoProvider") |
| 99 | + void testDefaultBuilder(String projectName, String extensionPointID, String extensionID, String projectTypeID, |
| 100 | + String natureID, ICodeProvider codeProvider) throws Exception { |
| 101 | + |
| 102 | + doBuilds(null, projectName, extensionPointID, extensionID, projectTypeID, natureID, codeProvider, null); |
| 103 | + |
| 104 | + // if(buildTypeActiveBuild) { |
| 105 | + // buildAllConfigsAsActive(null, projectName, extensionPointID, extensionID, projectTypeID, natureID, codeProvider, |
| 106 | + // null); |
| 107 | + // } |
| 108 | + // if(!buildTypeActiveBuild) { |
| 109 | + // buildAllConfigs(null, "all_" + projectName, extensionPointID, extensionID, projectTypeID, natureID, |
| 110 | + // codeProvider, null); |
| 111 | + // } |
| 112 | + |
| 113 | + } |
| 114 | + |
| 115 | + @ParameterizedTest |
| 116 | + @MethodSource("projectCreationInfoProvider") |
| 117 | + void testInternaltBuilder(String inProjectName, String extensionPointID, String extensionID, String projectTypeID, |
| 118 | + String natureID, ICodeProvider codeProvider) throws Exception { |
| 119 | + String projectName = "Internal_build_" + inProjectName; |
| 120 | + |
| 121 | + doBuilds(AutoBuildProject.ARGS_INTERNAL_BUILDER_KEY, projectName, extensionPointID, extensionID, projectTypeID, |
| 122 | + natureID, codeProvider, Boolean.FALSE); |
| 123 | + |
| 124 | + // buildAllConfigsAsActive(AutoBuildProject.ARGS_INTERNAL_BUILDER_KEY, projectName, extensionPointID, extensionID, |
| 125 | + // projectTypeID, natureID, codeProvider, Boolean.FALSE); |
| 126 | + // buildAllConfigs(AutoBuildProject.ARGS_INTERNAL_BUILDER_KEY, "all_" + projectName, extensionPointID, extensionID, |
| 127 | + // projectTypeID, natureID, codeProvider, Boolean.FALSE); |
| 128 | + } |
| 129 | + |
| 130 | + @ParameterizedTest |
| 131 | + @MethodSource("projectCreationInfoProvider") |
| 132 | + void testMakeBuilder(String inProjectName, String extensionPointID, String extensionID, String projectTypeID, |
| 133 | + String natureID, ICodeProvider codeProvider) throws Exception { |
| 134 | + String projectName = "make_build_" + inProjectName; |
| 135 | + doBuilds(AutoBuildProject.ARGS_MAKE_BUILDER_KEY, projectName, extensionPointID, extensionID, projectTypeID, |
| 136 | + natureID, codeProvider, Boolean.TRUE); |
| 137 | + |
| 138 | + // buildAllConfigsAsActive(AutoBuildProject.ARGS_MAKE_BUILDER_KEY, projectName, extensionPointID, extensionID, |
| 139 | + // projectTypeID, natureID, codeProvider, Boolean.TRUE); |
| 140 | + // buildAllConfigs(AutoBuildProject.ARGS_MAKE_BUILDER_KEY, "all_" + projectName, extensionPointID, extensionID, |
| 141 | + // projectTypeID, natureID, codeProvider, Boolean.TRUE); |
| 142 | + } |
| 143 | + |
| 144 | + static Stream<Arguments> projectCreationInfoProvider() { |
| 145 | + String extensionPointID = "io.sloeber.autoBuild.buildDefinitions"; |
| 146 | + Map<String, String> testProjectTypeIds = new HashMap<>(); |
| 147 | + testProjectTypeIds.put("io.sloeber.autoBuild.projectType.exe", "io.sloeber.autoBuild"); |
| 148 | + testProjectTypeIds.put("cdt.managedbuild.target.gnu.cross.exe", "cdt.cross.gnu"); |
| 149 | + testProjectTypeIds.put("cdt.managedbuild.target.gnu.cross.so", "cdt.cross.gnu"); |
| 150 | + testProjectTypeIds.put("cdt.managedbuild.target.gnu.cross.lib", "cdt.cross.gnu"); |
| 151 | + |
| 152 | + List<Arguments> ret = new LinkedList<>(); |
| 153 | + for (Entry<String, String> testProjectEntry : testProjectTypeIds.entrySet()) { |
| 154 | + String extensionID = testProjectEntry.getValue(); |
| 155 | + String projectID = testProjectEntry.getKey(); |
| 156 | + IProjectType projectType = AutoBuildManager.getProjectType(extensionPointID, extensionID, projectID, true); |
| 157 | + if (projectType == null || !projectType.isCompatibleWithLocalOS() || projectType.isAbstract()) { |
| 158 | + System.err.println("Skipping " + extensionID + " " + projectID); |
| 159 | + continue; |
| 160 | + } |
| 161 | + String buildArtifactType = projectType.getBuildArtifactType(); |
| 162 | + ICodeProvider codeProvider_cpp = null; |
| 163 | + switch (buildArtifactType) { |
| 164 | + case "org.eclipse.cdt.build.core.buildArtefactType.exe": |
| 165 | + codeProvider_cpp = new TemplateTestCodeProvider("exe"); |
| 166 | + break; |
| 167 | + case "org.eclipse.cdt.build.core.buildArtefactType.staticLib": |
| 168 | + case "org.eclipse.cdt.build.core.buildArtefactType.sharedLib": |
| 169 | + codeProvider_cpp = new TemplateTestCodeProvider("lib"); |
| 170 | + break; |
| 171 | + case "org.eclipse.cdt.build.core.buildArtefactType.compound": |
| 172 | + codeProvider_cpp = new TemplateTestCodeProvider("compound"); |
| 173 | + break; |
| 174 | + default: |
| 175 | + codeProvider_cpp = new TemplateTestCodeProvider("exe"); |
| 176 | + } |
| 177 | + String projectName = AutoBuildCommon.MakeNameCompileSafe(projectType.getName() + "_" + extensionID); |
| 178 | + ret.add(Arguments.of(projectName, extensionPointID, extensionID, projectType.getId(), |
| 179 | + CCProjectNature.CC_NATURE_ID, codeProvider_cpp)); |
| 180 | + } |
| 181 | + return ret.stream(); |
| 182 | + } |
| 183 | +} |
0 commit comments