-
Notifications
You must be signed in to change notification settings - Fork 3k
Extracting common devtools from Quarkus core repo #4615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
133 changes: 133 additions & 0 deletions
133
devtools/maven/src/main/java/io/quarkus/maven/BuildFileMojoBase.java
This file contains hidden or 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,133 @@ | ||
| package io.quarkus.maven; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| import org.apache.maven.model.Dependency; | ||
| import org.apache.maven.plugin.AbstractMojo; | ||
| import org.apache.maven.plugin.MojoExecutionException; | ||
| import org.apache.maven.plugins.annotations.Component; | ||
| import org.apache.maven.plugins.annotations.Parameter; | ||
| import org.apache.maven.project.MavenProject; | ||
| import org.eclipse.aether.RepositorySystem; | ||
| import org.eclipse.aether.RepositorySystemSession; | ||
| import org.eclipse.aether.artifact.Artifact; | ||
| import org.eclipse.aether.artifact.DefaultArtifact; | ||
| import org.eclipse.aether.repository.RemoteRepository; | ||
|
|
||
| import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; | ||
| import io.quarkus.cli.commands.file.BuildFile; | ||
| import io.quarkus.cli.commands.file.GradleBuildFile; | ||
| import io.quarkus.cli.commands.file.MavenBuildFile; | ||
| import io.quarkus.cli.commands.writer.FileProjectWriter; | ||
| import io.quarkus.platform.tools.config.QuarkusPlatformConfig; | ||
|
|
||
| public abstract class BuildFileMojoBase extends AbstractMojo { | ||
|
|
||
| @Parameter(defaultValue = "${project}") | ||
| protected MavenProject project; | ||
|
|
||
| @Component | ||
| protected RepositorySystem repoSystem; | ||
|
|
||
| @Parameter(defaultValue = "${repositorySystemSession}", readonly = true) | ||
| protected RepositorySystemSession repoSession; | ||
|
|
||
| @Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true, required = true) | ||
| protected List<RemoteRepository> repos; | ||
|
|
||
| @Override | ||
| public void execute() throws MojoExecutionException { | ||
|
|
||
| validateParameters(); | ||
|
|
||
| final MavenArtifactResolver mvn; | ||
| try { | ||
| mvn = MavenArtifactResolver.builder().setRepositorySystem(repoSystem).setRepositorySystemSession(repoSession) | ||
| .setRemoteRepositories(repos).build(); | ||
| } catch (Exception e) { | ||
| throw new MojoExecutionException("Failed to initialize maven artifact resolver", e); | ||
| } | ||
|
|
||
| BuildFile buildFile = null; | ||
| try { | ||
| if (project.getFile() != null) { | ||
| // Maven project | ||
| @SuppressWarnings("resource") | ||
| final MavenBuildFile mvnBuild = new MavenBuildFile(new FileProjectWriter(project.getBasedir())); | ||
| buildFile = mvnBuild; | ||
|
|
||
| if (QuarkusPlatformConfig.hasGlobalDefault()) { | ||
| getLog().warn("The Quarkus platform default configuration has already been initialized."); | ||
| } else { | ||
| Artifact descrArtifact = null; | ||
| for (Dependency dep : mvnBuild.getManagedDependencies()) { | ||
| if (!dep.getScope().equals("import") && !dep.getType().equals("pom")) { | ||
| continue; | ||
| } | ||
| String bomVersion = dep.getVersion(); | ||
| if (bomVersion.startsWith("${") && bomVersion.endsWith("}")) { | ||
| final String prop = bomVersion.substring(2, bomVersion.length() - 1); | ||
| bomVersion = mvnBuild.getProperty(prop); | ||
| if (bomVersion == null) { | ||
| getLog().debug("Failed to resolve version of " + dep); | ||
| continue; | ||
| } | ||
| } | ||
| Artifact jsonArtifact = new DefaultArtifact(dep.getGroupId(), dep.getArtifactId(), dep.getClassifier(), | ||
| "json", bomVersion); | ||
| try { | ||
| jsonArtifact = mvn.resolve(jsonArtifact).getArtifact(); | ||
| } catch (Exception e) { | ||
| getLog().debug("Failed to resolve JSON descriptor as " + jsonArtifact); | ||
| jsonArtifact = new DefaultArtifact(dep.getGroupId(), dep.getArtifactId() + "-descriptor-json", | ||
| dep.getClassifier(), "json", bomVersion); | ||
| try { | ||
| jsonArtifact = mvn.resolve(jsonArtifact).getArtifact(); | ||
| } catch (Exception e1) { | ||
| getLog().debug("Failed to resolve JSON descriptor as " + jsonArtifact); | ||
| continue; | ||
| } | ||
| } | ||
| descrArtifact = jsonArtifact; | ||
| break; | ||
| } | ||
|
|
||
| if (descrArtifact != null) { | ||
| getLog().debug("Quarkus platform JSON descriptor artifact: " + descrArtifact); | ||
| CreateUtils.setupQuarkusJsonPlatformDescriptor(mvn, descrArtifact, getLog()); | ||
| } | ||
| } | ||
| } else if (new File(project.getBasedir(), "build.gradle").exists() | ||
| || new File(project.getBasedir(), "build.gradle.kts").exists()) { | ||
| // Gradle project | ||
| buildFile = new GradleBuildFile(new FileProjectWriter(project.getBasedir())); | ||
| } | ||
|
|
||
| if (!QuarkusPlatformConfig.hasGlobalDefault()) { | ||
| CreateUtils.setupQuarkusJsonPlatformDescriptor(mvn, | ||
| new DefaultArtifact(CreateUtils.DEFAULT_PLATFORM_GROUP_ID, CreateUtils.DEFAULT_PLATFORM_ARTIFACT_ID, | ||
| null, "json", CreateUtils.resolvePluginInfo(BuildFileMojoBase.class).getVersion()), | ||
| getLog()); | ||
| } | ||
|
|
||
| doExecute(buildFile); | ||
| } catch (IOException e) { | ||
| throw new MojoExecutionException("Failed to initialize project reading tools", e); | ||
| } finally { | ||
| if (buildFile != null) { | ||
| try { | ||
| buildFile.close(); | ||
| } catch (IOException e) { | ||
| getLog().debug("Failed to close " + buildFile, e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected void validateParameters() throws MojoExecutionException { | ||
| } | ||
|
|
||
| protected abstract void doExecute(BuildFile buildFile) throws MojoExecutionException; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aloubyansky this one is too long too bug I think it's copied code right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, I actually type it in :)