-
-
Notifications
You must be signed in to change notification settings - Fork 25
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 #78 from jjohannes/generic_imports_resolver
Generalize implementation of ImportsResolver to allow imports from arbitrary npm packages
- Loading branch information
Showing
8 changed files
with
209 additions
and
103 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
62 changes: 62 additions & 0 deletions
62
src/main/groovy/org/web3j/solidity/gradle/plugin/SolidityExtractImports.groovy
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 2024 Web3 Labs Ltd. | ||
* | ||
* Licensed 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 org.web3j.solidity.gradle.plugin | ||
|
||
import groovy.json.JsonBuilder | ||
import groovy.transform.CompileStatic | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.* | ||
|
||
@CacheableTask | ||
@CompileStatic | ||
abstract class SolidityExtractImports extends DefaultTask { | ||
|
||
@Input | ||
abstract Property<String> getProjectName() | ||
|
||
@InputFiles | ||
@PathSensitive(value = PathSensitivity.RELATIVE) | ||
@SkipWhenEmpty | ||
abstract ConfigurableFileCollection getSources() | ||
|
||
@OutputFile | ||
abstract RegularFileProperty getPackageJson() | ||
|
||
SolidityExtractImports() { | ||
projectName.convention(project.name) | ||
} | ||
|
||
@TaskAction | ||
void resolveSolidity() { | ||
final Set<String> packages = new TreeSet<>() | ||
|
||
sources.each { contract -> | ||
packages.addAll(ImportsResolver.extractImports(contract)) | ||
} | ||
|
||
final jsonMap = [ | ||
"name" : projectName.get(), | ||
"description" : "", | ||
"repository" : "", | ||
"license" : "UNLICENSED", | ||
"dependencies": packages.collectEntries { | ||
[(it): "latest"] | ||
} | ||
] | ||
|
||
packageJson.get().asFile.text = new JsonBuilder(jsonMap).toPrettyString() | ||
} | ||
} |
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
Oops, something went wrong.