mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-15 17:22:25 -05:00
Fix ordering of reading sqlproj Build Includes and Removes (#17712)
* evaluate includes and removes in order in sqlproj * fix after merge * fix comment * update comment
This commit is contained in:
@@ -172,16 +172,17 @@ export class Project implements ISqlProject {
|
||||
for (let ig = 0; ig < this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.ItemGroup).length; ig++) {
|
||||
const itemGroup = this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.ItemGroup)[ig];
|
||||
|
||||
// find all files to include that are specified in the project file
|
||||
// find all files to include that are specified to be included and removed (for sdk style projects) in the project file
|
||||
// the build elements are evaluated in the order they are in the sqlproj (same way sdk style csproj handles this)
|
||||
try {
|
||||
const buildElements = itemGroup.getElementsByTagName(constants.Build);
|
||||
|
||||
// <Build Include....>
|
||||
for (let b = 0; b < buildElements.length; b++) {
|
||||
const relativePath = buildElements[b].getAttribute(constants.Include)!;
|
||||
// <Build Include....>
|
||||
const includeRelativePath = buildElements[b].getAttribute(constants.Include)!;
|
||||
|
||||
if (relativePath) {
|
||||
const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(relativePath));
|
||||
if (includeRelativePath) {
|
||||
const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(includeRelativePath));
|
||||
|
||||
// sdk style projects can handle other globbing patterns like <Build Include="folder1\*.sql" /> and <Build Include="Production*.sql" />
|
||||
if (this._isSdkStyleProject && !(await utils.exists(fullPath))) {
|
||||
@@ -192,25 +193,23 @@ export class Project implements ISqlProject {
|
||||
filesSet.add(newFileRelativePath);
|
||||
});
|
||||
} else {
|
||||
filesSet.add(relativePath);
|
||||
filesSet.add(includeRelativePath);
|
||||
|
||||
// Right now only used for external streaming jobs
|
||||
const typeAttribute = buildElements[b].getAttribute(constants.Type)!;
|
||||
if (typeAttribute) {
|
||||
entriesWithType.push({ relativePath, typeAttribute });
|
||||
entriesWithType.push({ relativePath: includeRelativePath, typeAttribute: typeAttribute });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// <Build Remove....>
|
||||
// after all the files have been included, remove the ones specified in the sqlproj to remove
|
||||
if (this._isSdkStyleProject) {
|
||||
for (let b = 0; b < buildElements.length; b++) {
|
||||
const relativePath = buildElements[b].getAttribute(constants.Remove)!;
|
||||
// <Build Remove....>
|
||||
// remove files specified in the sqlproj to remove if this is an sdk style project
|
||||
if (this._isSdkStyleProject) {
|
||||
const removeRelativePath = buildElements[b].getAttribute(constants.Remove)!;
|
||||
|
||||
if (relativePath) {
|
||||
const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(relativePath));
|
||||
if (removeRelativePath) {
|
||||
const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(removeRelativePath));
|
||||
|
||||
const globRemoveFiles = await utils.globWithPattern(fullPath);
|
||||
globRemoveFiles.forEach(gf => {
|
||||
|
||||
@@ -16,7 +16,12 @@
|
||||
<ItemGroup>
|
||||
<Build Include="..\other\folder1\file*.sql" />
|
||||
<Build Remove="..\other\folder1\file1.sql" />
|
||||
<Build Include="..\other\folder2\file2.sql" />
|
||||
<Build Remove="..\other\folder2\**" />
|
||||
<Build Remove="folder1\*.sql" />
|
||||
<Build Include="folder1\file2.sql" />
|
||||
<Build Remove="folder2\file3.sql" />
|
||||
<Build Include="folder2\*.sql" />
|
||||
<Build Remove="file1.sql" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -929,21 +929,40 @@ describe('Project: sdk style project content operations', function (): void {
|
||||
|
||||
const project: Project = await Project.openProject(projFilePath);
|
||||
|
||||
should(project.files.filter(f => f.type === EntryType.File).length).equal(6);
|
||||
should(project.files.filter(f => f.type === EntryType.File).length).equal(7);
|
||||
|
||||
// make sure all the correct files from the globbing patterns were included and removed are evaluated in order
|
||||
|
||||
// make sure all the correct files from the globbing patterns were included and excluded
|
||||
// <Build Include="..\other\folder1\file*.sql" />
|
||||
// <Build Remove="..\other\folder1\file1.sql" />
|
||||
// expected: ..\other\folder1\file1.sql is not included
|
||||
should(project.files.filter(f => f.relativePath === '..\\other\\folder1\\file1.sql').length).equal(0);
|
||||
should(project.files.filter(f => f.relativePath === '..\\other\\folder1\\file2.sql').length).equal(1);
|
||||
|
||||
// <Build Include="..\other\folder2\file2.sql" />
|
||||
// <Build Remove="..\other\folder2\**" />
|
||||
// expected: ..\other\folder2\file2.sql is not included
|
||||
should(project.files.filter(f => f.relativePath === '..\\other\\folder2\\file1.sql').length).equal(0);
|
||||
should(project.files.filter(f => f.relativePath === '..\\other\\folder2\\file2.sql').length).equal(0);
|
||||
|
||||
// <Build Remove="folder1\*.sql" />
|
||||
// <Build Include="folder1\file2.sql" />
|
||||
// expected: folder1\file2.sql is included
|
||||
should(project.files.filter(f => f.relativePath === 'folder1\\file1.sql').length).equal(0);
|
||||
should(project.files.filter(f => f.relativePath === 'folder1\\file2.sql').length).equal(0);
|
||||
should(project.files.filter(f => f.relativePath === 'folder1\\file2.sql').length).equal(1);
|
||||
should(project.files.filter(f => f.relativePath === 'folder1\\file3.sql').length).equal(0);
|
||||
should(project.files.filter(f => f.relativePath === 'folder1\\file4.sql').length).equal(0);
|
||||
should(project.files.filter(f => f.relativePath === 'folder1\\file5.sql').length).equal(0);
|
||||
|
||||
// <Build Remove="folder2\file3.sql" />
|
||||
// <Build Include="folder2\*.sql" />
|
||||
// expected: folder2\file3.sql is included
|
||||
should(project.files.filter(f => f.relativePath === 'folder2\\file1.sql').length).equal(1);
|
||||
should(project.files.filter(f => f.relativePath === 'folder2\\file2.sql').length).equal(1);
|
||||
should(project.files.filter(f => f.relativePath === 'folder2\\file3.sql').length).equal(1);
|
||||
should(project.files.filter(f => f.relativePath === 'folder2\\file4.sql').length).equal(1);
|
||||
should(project.files.filter(f => f.relativePath === 'folder2\\file5.sql').length).equal(1);
|
||||
|
||||
// <Build Remove="file1.sql" />
|
||||
should(project.files.filter(f => f.relativePath === 'file1.sql').length).equal(0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user