-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for double quoted arrays * Tests for array support * extend documentation for array support in cache * Write arrays as JSON strings to env variables * Adapt workflow and update license * Add check for type array * Unit tests and fixed regex
- Loading branch information
1 parent
7bdaac4
commit fcaa7ce
Showing
7 changed files
with
158 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Apache License, Version 2.0 which is available at | ||
// https://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. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { ProjectCache } from './project-cache'; | ||
|
||
const CACHE_OUTPUT_REGEX: RegExp = | ||
/(\w+)\s*=\s*(\[((\'(\/*\w+)*\'\s*,\s*|(\"(\/*\w+)*\"\s*,\s*)|(\/*\w+)*\s*,\s*|\'(\/*\w+)*\'(?=\])|\"(\/*\w+)*\"(?=\])|(\/*\w+)*(?=\]))*\])|(\'.*?\'|\".*?\"|\w+))\s+\>\>\s+VELOCITAS_CACHE/; | ||
|
||
export function stdOutParser(projectCache: ProjectCache, line: string) { | ||
let lineTrimmed = (line as string).trim(); | ||
|
||
if (lineTrimmed.length === 0) { | ||
return; | ||
} | ||
const match = CACHE_OUTPUT_REGEX.exec(line); | ||
if (match && match.length > 0) { | ||
const [ignored, key, value] = match; | ||
const cleanedValue = value.replace(/['"]/g, ''); | ||
if (cleanedValue.startsWith('[') && cleanedValue.endsWith(']')) { | ||
const arrayPart = cleanedValue.substring(1, cleanedValue.length - 1); | ||
const array = arrayPart.split(','); | ||
const trimmedArray = array.map((str) => str.trim()); | ||
projectCache.set(key, trimmedArray); | ||
} else { | ||
projectCache.set(key, cleanedValue); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Apache License, Version 2.0 which is available at | ||
// https://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. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { expect } from 'chai'; | ||
import { ProjectCache } from '../../src/modules/project-cache'; | ||
import { stdOutParser } from '../../src/modules/stdout-parser'; | ||
import { CliFileSystem, MockFileSystem, MockFileSystemObj } from '../../src/utils/fs-bridge'; | ||
import { getCacheData } from '../helpers/cache'; | ||
|
||
describe('stdOutParser - module', () => { | ||
|
||
before(() => { | ||
const projectCacheDir = ProjectCache.getCacheDir(); | ||
const mockFilesystem: MockFileSystemObj = { | ||
[`${projectCacheDir}/cache.json`]: '{}', | ||
}; | ||
CliFileSystem.setImpl(new MockFileSystem(mockFilesystem)); | ||
}); | ||
|
||
describe('valid inputs', () => { | ||
const matches = new Map<string, any>([ | ||
['test_1 = "/this/is/path/one" >> VELOCITAS_CACHE', '/this/is/path/one'], | ||
["test_2 = '/this/is/path/one' >> VELOCITAS_CACHE", '/this/is/path/one'], | ||
['test_3 = test3 >> VELOCITAS_CACHE', 'test3'], | ||
['test_4 = ["/this/is/path/one", "/this/is/path/two"] >> VELOCITAS_CACHE', ['/this/is/path/one', '/this/is/path/two']], | ||
['test_5 = ["/this/is/path/one","/this/is/path/two"] >> VELOCITAS_CACHE', ['/this/is/path/one', '/this/is/path/two']], | ||
['test_6 = ["/this/is/path/one", "/this/is/path/two"] >> VELOCITAS_CACHE', ['/this/is/path/one', '/this/is/path/two']], | ||
['test_7 =["/this/is/path/one", "/this/is/path/two"] >> VELOCITAS_CACHE', ['/this/is/path/one', '/this/is/path/two']], | ||
['test_8=["/this/is/path/one", "/this/is/path/two"] >> VELOCITAS_CACHE', ['/this/is/path/one', '/this/is/path/two']], | ||
["test_9 = ['/this/is/path/one', /this/is/path/two] >> VELOCITAS_CACHE", ['/this/is/path/one', '/this/is/path/two']], | ||
['test_10 = [/this/is/path/one, "/this/is/path/two"] >> VELOCITAS_CACHE', ['/this/is/path/one', '/this/is/path/two']], | ||
['test_11 = [/this/is/path/one, /this/is/path/two] >> VELOCITAS_CACHE', ['/this/is/path/one', '/this/is/path/two']], | ||
]); | ||
|
||
it('should match and set project cache correct', () => { | ||
matches.forEach((result, element) => { | ||
let id = element.split('=')[0].trim(); | ||
const projectCache = ProjectCache.read(); | ||
stdOutParser(projectCache, element); | ||
expect(JSON.stringify(projectCache.get(id))).to.equal(JSON.stringify(result)); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('invalid inputs', () => { | ||
const noMatches = new Map<string, any>([ | ||
['test_1 = "/this/is/path/one >> VELOCITAS_CACHE', {}], | ||
["test_2 = '/this/is/path/one >> VELOCITAS_CACHE", {}], | ||
['test_3 = /this/is/path/one"this/test >> VELOCITAS_CACHE', {}], | ||
['test_4 = ["/this/is/path/one", /this/is/path/two"]', {}], | ||
['test_5 = ["/this/is/path/one""/this/is/path/two"] >> VELOCITAS_CACHE', {}], | ||
['"test_6" = ["/this/is/path/one", "/this/is/path/two"] >> VELOCITAS_CACHE', {}], | ||
['test_7 = [/this/is/path/one""/this/is/path/two"] >> VELOCITAS_CACHE', {}], | ||
["test_8 = ['/this/is/path/one''/this/is/path/two'] >> VELOCITAS_CACHE", {}], | ||
]); | ||
|
||
it('should not match for wrong inputs', async () => { | ||
noMatches.forEach((result, element) => { | ||
const projectCache = ProjectCache.read(); | ||
stdOutParser(projectCache, element); | ||
expect(JSON.stringify(getCacheData())).to.equal(JSON.stringify(result)); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters