-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42291 from Dilhasha/compiler-plugin-params
Add a data holder to store params between compilations
- Loading branch information
Showing
21 changed files
with
596 additions
and
4 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilerPluginCache.java
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,62 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you 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 io.ballerina.projects; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* A class that acts as the compiler plugin cache for a project. | ||
* | ||
* @since 2201.8.7 | ||
*/ | ||
public class CompilerPluginCache { | ||
|
||
Map<String, Map<String, Object>> pluginMap; | ||
|
||
/** | ||
* Constructor to initialize plugin cache. | ||
*/ | ||
public CompilerPluginCache() { | ||
pluginMap = new HashMap<>(); | ||
} | ||
|
||
/** | ||
* Returns the user data for a particular compiler plugin. | ||
* | ||
* @param key compiler plugin id | ||
* @return data holder map for the plugin | ||
*/ | ||
public Map<String, Object> getData(String key) { | ||
if (!pluginMap.containsKey(key)) { | ||
pluginMap.put(key, new HashMap<>()); | ||
} | ||
return pluginMap.get(key); | ||
} | ||
|
||
/** | ||
* Adds a data holder map for a compiler plugin. | ||
* | ||
* @param key string fully qualified name of the compiler plugin | ||
* @param value user data as a map | ||
*/ | ||
public void putData(String key, Map<String, Object> value) { | ||
this.pluginMap.put(key, value); | ||
} | ||
} |
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
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
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
4 changes: 4 additions & 0 deletions
4
...ources/compiler_plugin_tests/pkg_provided_compiler_plugin_with_shared_data/Ballerina.toml
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,4 @@ | ||
[package] | ||
org = "foo" | ||
name = "test_pkg" | ||
version = "0.1.0" |
5 changes: 5 additions & 0 deletions
5
...s/compiler_plugin_tests/pkg_provided_compiler_plugin_with_shared_data/CompilerPlugin.toml
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,5 @@ | ||
[plugin] | ||
class = "io.context.plugins.CompilerPluginWithSharedData" | ||
|
||
[[dependency]] | ||
path = "../../../../../build/compiler-plugin-jars/pkg-provided-compiler-plugin-with-shared-data-1.0.0.jar" |
24 changes: 24 additions & 0 deletions
24
...st/resources/compiler_plugin_tests/pkg_provided_compiler_plugin_with_shared_data/main.bal
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,24 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you 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. | ||
|
||
public function main() { | ||
} | ||
|
||
function foo() { | ||
} | ||
|
||
function bar() { | ||
} |
4 changes: 4 additions & 0 deletions
4
...oject-api-test/src/test/resources/compiler_plugin_tests/shared_data_plugin/Ballerina.toml
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,4 @@ | ||
[package] | ||
org = "shared_data" | ||
name = "combined_plugin" | ||
version = "0.1.0" |
21 changes: 21 additions & 0 deletions
21
...api/project-api-test/src/test/resources/compiler_plugin_tests/shared_data_plugin/main.bal
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,21 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you 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. | ||
|
||
import foo/test_pkg as _; | ||
|
||
function func1() { | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
project-api/test-artifacts/pkg-provided-compiler-plugin-with-shared-data/build.gradle
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,36 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you 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. | ||
*/ | ||
|
||
apply from: "$rootDir/gradle/javaProject.gradle" | ||
|
||
description = 'Compiler Plugin Tests - Plugin with BuildContext usage' | ||
version = '1.0.0' | ||
|
||
dependencies { | ||
implementation project(':ballerina-lang') | ||
implementation project(':ballerina-parser') | ||
implementation project(':ballerina-tools-api') | ||
} | ||
|
||
ext.moduleName = 'io.context.plugins' | ||
|
||
compileJava { | ||
doFirst { | ||
options.compilerArgs = ['--module-path', classpath.asPath,] | ||
classpath = files() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ect-api/test-artifacts/pkg-provided-compiler-plugin-with-shared-data/spotbugs-exclude.xml
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,27 @@ | ||
<!-- | ||
~ Copyright (c) 2024, WSO2 LLC. (http://wso2.com). | ||
~ | ||
~ WSO2 LLC. licenses this file to you 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. | ||
--> | ||
<FindBugsFilter> | ||
<Match> | ||
<Class name="io.context.plugins.SharedDataTestCodeAnalyzer"/> | ||
<Bug pattern="EI_EXPOSE_REP2"/> | ||
</Match> | ||
<Match> | ||
<Class name="io.context.plugins.SharedDataTestCodeModifier"/> | ||
<Bug pattern="EI_EXPOSE_REP2"/> | ||
</Match> | ||
</FindBugsFilter> |
Oops, something went wrong.