mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
add support for Build Remove (#17610)
This commit is contained in:
@@ -328,6 +328,7 @@ export const ItemGroup = 'ItemGroup';
|
|||||||
export const Build = 'Build';
|
export const Build = 'Build';
|
||||||
export const Folder = 'Folder';
|
export const Folder = 'Folder';
|
||||||
export const Include = 'Include';
|
export const Include = 'Include';
|
||||||
|
export const Remove = 'Remove';
|
||||||
export const Import = 'Import';
|
export const Import = 'Import';
|
||||||
export const Project = 'Project';
|
export const Project = 'Project';
|
||||||
export const Condition = 'Condition';
|
export const Condition = 'Condition';
|
||||||
|
|||||||
@@ -148,8 +148,12 @@ export class Project implements ISqlProject {
|
|||||||
// find all folders and files to include that are specified in the project file
|
// find all folders and files to include that are specified in the project file
|
||||||
try {
|
try {
|
||||||
const buildElements = itemGroup.getElementsByTagName(constants.Build);
|
const buildElements = itemGroup.getElementsByTagName(constants.Build);
|
||||||
|
|
||||||
|
// <Build Include....>
|
||||||
for (let b = 0; b < buildElements.length; b++) {
|
for (let b = 0; b < buildElements.length; b++) {
|
||||||
const relativePath = buildElements[b].getAttribute(constants.Include)!;
|
const relativePath = buildElements[b].getAttribute(constants.Include)!;
|
||||||
|
|
||||||
|
if (relativePath) {
|
||||||
const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(relativePath));
|
const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(relativePath));
|
||||||
|
|
||||||
// msbuild sdk style projects can handle other globbing patterns like <Build Include="folder1\*.sql" /> and <Build Include="Production*.sql" />
|
// msbuild sdk style projects can handle other globbing patterns like <Build Include="folder1\*.sql" /> and <Build Include="Production*.sql" />
|
||||||
@@ -162,9 +166,6 @@ export class Project implements ISqlProject {
|
|||||||
this._files.push(this.createFileProjectEntry(utils.trimUri(Uri.file(this.projectFilePath), Uri.file(gf)), EntryType.File));
|
this._files.push(this.createFileProjectEntry(utils.trimUri(Uri.file(this.projectFilePath), Uri.file(gf)), EntryType.File));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: add support for <Build Remove="file.sql">
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// only add file if it wasn't already added
|
// only add file if it wasn't already added
|
||||||
if (!this._files.find(f => f.relativePath === relativePath)) {
|
if (!this._files.find(f => f.relativePath === relativePath)) {
|
||||||
@@ -172,6 +173,28 @@ export class Project implements ISqlProject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// <Build Remove....>
|
||||||
|
// after all the files have been included, remove the ones specified in the sqlproj to remove
|
||||||
|
if (this._isMsbuildSdkStyleProject) {
|
||||||
|
for (let b = 0; b < buildElements.length; b++) {
|
||||||
|
const relativePath = buildElements[b].getAttribute(constants.Remove)!;
|
||||||
|
|
||||||
|
if (relativePath) {
|
||||||
|
const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(relativePath));
|
||||||
|
|
||||||
|
const globRemoveFiles = await utils.globWithPattern(fullPath);
|
||||||
|
globRemoveFiles.forEach(gf => {
|
||||||
|
const removeFileRelativePath = utils.convertSlashesForSqlProj(utils.trimUri(Uri.file(this.projectFilePath), Uri.file(gf)));
|
||||||
|
|
||||||
|
if (this._files.find(f => f.relativePath === removeFileRelativePath)) {
|
||||||
|
this._files = this._files.filter(f => f.relativePath !== removeFileRelativePath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
void window.showErrorMessage(constants.errorReadingProject(constants.BuildElements, this.projectFilePath));
|
void window.showErrorMessage(constants.errorReadingProject(constants.BuildElements, this.projectFilePath));
|
||||||
console.error(utils.getErrorMessage(e));
|
console.error(utils.getErrorMessage(e));
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ export let newStyleProjectSdkImportAttributeBaseline: string;
|
|||||||
export let openNewStyleSqlProjectBaseline: string;
|
export let openNewStyleSqlProjectBaseline: string;
|
||||||
export let openNewStyleSqlProjectWithFilesSpecifiedBaseline: string;
|
export let openNewStyleSqlProjectWithFilesSpecifiedBaseline: string;
|
||||||
export let openNewStyleSqlProjectWithGlobsSpecifiedBaseline: string;
|
export let openNewStyleSqlProjectWithGlobsSpecifiedBaseline: string;
|
||||||
|
export let openNewStyleSqlProjectWithBuildRemoveBaseline: string;
|
||||||
|
|
||||||
const baselineFolderPath = __dirname;
|
const baselineFolderPath = __dirname;
|
||||||
|
|
||||||
@@ -63,6 +64,7 @@ export async function loadBaselines() {
|
|||||||
openNewStyleSqlProjectBaseline = await loadBaseline(baselineFolderPath, 'openNewStyleSqlProjectBaseline.xml');
|
openNewStyleSqlProjectBaseline = await loadBaseline(baselineFolderPath, 'openNewStyleSqlProjectBaseline.xml');
|
||||||
openNewStyleSqlProjectWithFilesSpecifiedBaseline = await loadBaseline(baselineFolderPath, 'openNewStyleSqlProjectWithFilesSpecifiedBaseline.xml');
|
openNewStyleSqlProjectWithFilesSpecifiedBaseline = await loadBaseline(baselineFolderPath, 'openNewStyleSqlProjectWithFilesSpecifiedBaseline.xml');
|
||||||
openNewStyleSqlProjectWithGlobsSpecifiedBaseline = await loadBaseline(baselineFolderPath, 'openNewStyleSqlProjectWithGlobsSpecifiedBaseline.xml');
|
openNewStyleSqlProjectWithGlobsSpecifiedBaseline = await loadBaseline(baselineFolderPath, 'openNewStyleSqlProjectWithGlobsSpecifiedBaseline.xml');
|
||||||
|
openNewStyleSqlProjectWithBuildRemoveBaseline = await loadBaseline(baselineFolderPath, 'openNewStyleSqlProjectWithBuildRemoveBaseline.xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadBaseline(baselineFolderPath: string, fileName: string): Promise<string> {
|
async function loadBaseline(baselineFolderPath: string, fileName: string): Promise<string> {
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build">
|
||||||
|
<Sdk Name="Microsoft.Build.Sql" Version="1.0.0" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Name>TestProjectName</Name>
|
||||||
|
<ProjectGuid>{2C283C5D-9E4A-4313-8FF9-4E0CEE20B063}</ProjectGuid>
|
||||||
|
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql150DatabaseSchemaProvider</DSP>
|
||||||
|
<ModelCollation>1033, CI</ModelCollation>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
<Delete Files="$(BaseIntermediateOutputPath)\project.assets.json" />
|
||||||
|
</Target>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Properties" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Build Include="..\other\folder1\file*.sql" />
|
||||||
|
<Build Remove="..\other\folder1\file1.sql" />
|
||||||
|
<Build Remove="folder1\*.sql" />
|
||||||
|
<Build Remove="file1.sql" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ArtifactReference Condition="'$(NetCoreBuild)' == 'true'" Include="$(NETCoreTargetsPath)\SystemDacpacs\150\master.dacpac">
|
||||||
|
<SuppressMissingDependenciesErrors>False</SuppressMissingDependenciesErrors>
|
||||||
|
<DatabaseVariableLiteralValue>master</DatabaseVariableLiteralValue>
|
||||||
|
</ArtifactReference>
|
||||||
|
<ArtifactReference Condition="'$(NetCoreBuild)' != 'true'" Include="$(DacPacRootPath)\Extensions\Microsoft\SQLDB\Extensions\SqlServer\150\SqlSchemas\master.dacpac">
|
||||||
|
<SuppressMissingDependenciesErrors>False</SuppressMissingDependenciesErrors>
|
||||||
|
<DatabaseVariableLiteralValue>master</DatabaseVariableLiteralValue>
|
||||||
|
</ArtifactReference>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -914,6 +914,38 @@ describe('Project: Msbuild sdk style project content operations', function (): v
|
|||||||
// make sure no duplicates from folder1\*.sql
|
// make sure no duplicates from folder1\*.sql
|
||||||
should(project.files.filter(f => f.relativePath === 'folder1\\file1.sql').length).equal(1);
|
should(project.files.filter(f => f.relativePath === 'folder1\\file1.sql').length).equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should handle Build Remove in sqlproj', async function (): Promise<void> {
|
||||||
|
const testFolderPath = await testUtils.generateTestFolderPath();
|
||||||
|
const mainProjectPath = path.join(testFolderPath, 'project');
|
||||||
|
const otherFolderPath = path.join(testFolderPath, 'other');
|
||||||
|
projFilePath = await testUtils.createTestSqlProjFile(baselines.openNewStyleSqlProjectWithBuildRemoveBaseline, mainProjectPath);
|
||||||
|
await testUtils.createDummyFileStructure(false, undefined, path.dirname(projFilePath));
|
||||||
|
|
||||||
|
// create files outside of project folder that are included in the project file
|
||||||
|
await fs.mkdir(otherFolderPath);
|
||||||
|
await testUtils.createOtherDummyFiles(otherFolderPath);
|
||||||
|
|
||||||
|
const project: Project = await Project.openProject(projFilePath);
|
||||||
|
|
||||||
|
should(project.files.filter(f => f.type === EntryType.File).length).equal(6);
|
||||||
|
|
||||||
|
// 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" />
|
||||||
|
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 Remove="folder1\*.sql" />
|
||||||
|
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\\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="file1.sql" />
|
||||||
|
should(project.files.filter(f => f.relativePath === 'file1.sql').length).equal(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Project: add SQLCMD Variables', function (): void {
|
describe('Project: add SQLCMD Variables', function (): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user