mirror of
https://github.com/jlengrand/quarkus.git
synced 2026-03-10 08:41:22 +00:00
Minor cleanup in Gradle plugin
Using constants and avoiding casts
This commit is contained in:
@@ -27,6 +27,7 @@ import org.gradle.api.file.RegularFile;
|
||||
import org.gradle.api.internal.artifacts.DefaultModuleIdentifier;
|
||||
import org.gradle.api.internal.artifacts.dependencies.DefaultDependencyArtifact;
|
||||
import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.provider.Provider;
|
||||
import org.gradle.jvm.tasks.Jar;
|
||||
|
||||
@@ -40,6 +41,7 @@ import io.quarkus.bootstrap.resolver.AppModelResolverException;
|
||||
public class AppModelGradleResolver implements AppModelResolver {
|
||||
|
||||
private AppModel appModel;
|
||||
|
||||
private final Project project;
|
||||
|
||||
public AppModelGradleResolver(Project project) {
|
||||
@@ -47,7 +49,8 @@ public class AppModelGradleResolver implements AppModelResolver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLatestVersion(AppArtifact arg0, String arg1, boolean arg2) throws AppModelResolverException {
|
||||
public String getLatestVersion(AppArtifact appArtifact, String upToVersion, boolean inclusive)
|
||||
throws AppModelResolverException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -57,18 +60,20 @@ public class AppModelGradleResolver implements AppModelResolver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNextVersion(AppArtifact arg0, String fromVersion, boolean fromVersionIncluded, String arg1, boolean arg2)
|
||||
public String getNextVersion(AppArtifact appArtifact, String fromVersion, boolean fromVersionIncluded, String upToVersion,
|
||||
boolean upToVersionIncluded)
|
||||
throws AppModelResolverException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listLaterVersions(AppArtifact arg0, String arg1, boolean arg2) throws AppModelResolverException {
|
||||
public List<String> listLaterVersions(AppArtifact appArtifact, String upToVersion, boolean inclusive)
|
||||
throws AppModelResolverException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void relink(AppArtifact arg0, Path arg1) throws AppModelResolverException {
|
||||
public void relink(AppArtifact appArtifact, Path localPath) throws AppModelResolverException {
|
||||
|
||||
}
|
||||
|
||||
@@ -105,8 +110,7 @@ public class AppModelGradleResolver implements AppModelResolver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AppDependency> resolveUserDependencies(AppArtifact appArtifact, List<AppDependency> directDeps)
|
||||
throws AppModelResolverException {
|
||||
public List<AppDependency> resolveUserDependencies(AppArtifact appArtifact, List<AppDependency> directDeps) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -115,7 +119,7 @@ public class AppModelGradleResolver implements AppModelResolver {
|
||||
if (appModel != null && appModel.getAppArtifact().equals(appArtifact)) {
|
||||
return appModel;
|
||||
}
|
||||
final Configuration compileCp = project.getConfigurations().getByName("compileClasspath");
|
||||
final Configuration compileCp = project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
|
||||
final List<Dependency> extensionDeps = new ArrayList<>();
|
||||
final List<AppDependency> userDeps = new ArrayList<>();
|
||||
Map<ModuleIdentifier, ModuleVersionIdentifier> userModules = new HashMap<>();
|
||||
@@ -160,7 +164,7 @@ public class AppModelGradleResolver implements AppModelResolver {
|
||||
// In the case of quarkusBuild (which is the primary user of this),
|
||||
// it's not necessary to actually resolve the original application JAR
|
||||
if (!appArtifact.isResolved()) {
|
||||
final Jar jarTask = (Jar) project.getTasks().findByName("jar");
|
||||
final Jar jarTask = (Jar) project.getTasks().findByName(JavaPlugin.JAR_TASK_NAME);
|
||||
if (jarTask == null) {
|
||||
throw new AppModelResolverException("Failed to locate task 'jar' in the project.");
|
||||
}
|
||||
@@ -176,7 +180,7 @@ public class AppModelGradleResolver implements AppModelResolver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppModel resolveModel(AppArtifact arg0, List<AppDependency> arg1) throws AppModelResolverException {
|
||||
public AppModel resolveModel(AppArtifact root, List<AppDependency> deps) throws AppModelResolverException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import io.quarkus.gradle.tasks.QuarkusTestNative;
|
||||
|
||||
public class QuarkusPlugin implements Plugin<Project> {
|
||||
|
||||
public static final String EXTENSION_NAME = "quarkus";
|
||||
public static final String LIST_EXTENSIONS_TASK_NAME = "listExtensions";
|
||||
public static final String ADD_EXTENSION_TASK_NAME = "addExtension";
|
||||
public static final String QUARKUS_BUILD_TASK_NAME = "quarkusBuild";
|
||||
@@ -46,7 +47,7 @@ public class QuarkusPlugin implements Plugin<Project> {
|
||||
public void apply(Project project) {
|
||||
verifyGradleVersion();
|
||||
// register extension
|
||||
project.getExtensions().create("quarkus", QuarkusPluginExtension.class, project);
|
||||
project.getExtensions().create(EXTENSION_NAME, QuarkusPluginExtension.class, project);
|
||||
|
||||
registerTasks(project);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Set;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
import io.quarkus.bootstrap.model.AppArtifact;
|
||||
import io.quarkus.bootstrap.resolver.AppModelResolver;
|
||||
@@ -30,7 +31,7 @@ public class QuarkusPluginExtension {
|
||||
public File outputDirectory() {
|
||||
if (outputDirectory == null)
|
||||
outputDirectory = project.getConvention().getPlugin(JavaPluginConvention.class)
|
||||
.getSourceSets().getByName("main").getOutput().getClassesDirs().getAsPath();
|
||||
.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput().getClassesDirs().getAsPath();
|
||||
|
||||
return new File(outputDirectory);
|
||||
}
|
||||
@@ -38,7 +39,7 @@ public class QuarkusPluginExtension {
|
||||
public File outputConfigDirectory() {
|
||||
if (outputConfigDirectory == null) {
|
||||
outputConfigDirectory = project.getConvention().getPlugin(JavaPluginConvention.class)
|
||||
.getSourceSets().getByName("main").getOutput().getResourcesDir().getAbsolutePath();
|
||||
.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput().getResourcesDir().getAbsolutePath();
|
||||
}
|
||||
return new File(outputConfigDirectory);
|
||||
}
|
||||
@@ -46,7 +47,7 @@ public class QuarkusPluginExtension {
|
||||
public File sourceDir() {
|
||||
if (sourceDir == null) {
|
||||
sourceDir = project.getConvention().getPlugin(JavaPluginConvention.class)
|
||||
.getSourceSets().getByName("main").getAllJava().getSourceDirectories().getAsPath();
|
||||
.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getAllJava().getSourceDirectories().getAsPath();
|
||||
}
|
||||
return new File(sourceDir);
|
||||
}
|
||||
@@ -61,14 +62,14 @@ public class QuarkusPluginExtension {
|
||||
|
||||
public String finalName() {
|
||||
if (finalName == null || finalName.length() == 0) {
|
||||
this.finalName = project.getName() + "-" + project.getVersion();
|
||||
this.finalName = String.format("%s-%s", project.getName(), project.getVersion());
|
||||
}
|
||||
return finalName;
|
||||
}
|
||||
|
||||
public Set<File> resourcesDir() {
|
||||
return project.getConvention().getPlugin(JavaPluginConvention.class)
|
||||
.getSourceSets().getByName("main").getResources().getSrcDirs();
|
||||
.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getResources().getSrcDirs();
|
||||
}
|
||||
|
||||
public AppArtifact getAppArtifact() {
|
||||
|
||||
@@ -13,18 +13,18 @@ public class GradleMessageWriter implements MessageWriter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String arg0) {
|
||||
logger.debug(arg0);
|
||||
public void debug(String msg) {
|
||||
logger.debug(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String arg0) {
|
||||
logger.error(arg0);
|
||||
public void error(String msg) {
|
||||
logger.error(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String arg0) {
|
||||
logger.info(arg0);
|
||||
public void info(String msg) {
|
||||
logger.info(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,7 +33,7 @@ public class GradleMessageWriter implements MessageWriter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String arg0) {
|
||||
logger.warn(arg0);
|
||||
public void warn(String msg) {
|
||||
logger.warn(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +271,8 @@ public class QuarkusDev extends QuarkusTask {
|
||||
res = file.getAbsolutePath();
|
||||
}
|
||||
|
||||
final Configuration compileCp = project.getConfigurations().getByName("compileClasspath");
|
||||
final Configuration compileCp = project.getConfigurations()
|
||||
.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
|
||||
final DependencySet compileCpDependencies = compileCp.getAllDependencies();
|
||||
|
||||
for (Dependency dependency : compileCpDependencies) {
|
||||
|
||||
@@ -16,8 +16,9 @@ public abstract class QuarkusTask extends DefaultTask {
|
||||
}
|
||||
|
||||
QuarkusPluginExtension extension() {
|
||||
if (extension == null)
|
||||
extension = (QuarkusPluginExtension) getProject().getExtensions().findByName("quarkus");
|
||||
if (extension == null) {
|
||||
extension = getProject().getExtensions().findByType(QuarkusPluginExtension.class);
|
||||
}
|
||||
return extension;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user