Skip to content
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

Fix blocker issues detected with SonarCloud #7170

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public CommandResult execute(CommandInvocation commandInvocation) throws Command
} else {
try {
BuildFile buildFile = null;
FileProjectWriter writer = null;
if (path != null) {
File projectDirectory = new File(path.getAbsolutePath());
writer = new FileProjectWriter(projectDirectory);
if (new File(projectDirectory, "build.gradle").exists()
|| new File(projectDirectory, "build.gradle.kts").exists()) {
buildFile = new GradleBuildFile(writer);
} else {
buildFile = new MavenBuildFile(writer);
try (FileProjectWriter writer = new FileProjectWriter(projectDirectory)) {
if (new File(projectDirectory, "build.gradle").exists()
|| new File(projectDirectory, "build.gradle.kts").exists()) {
buildFile = new GradleBuildFile(writer);
} else {
buildFile = new MavenBuildFile(writer);
}
}
}
new ListExtensions(buildFile).listExtensions(all, format, searchPattern);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public Job newJob(TriggerFiredBundle bundle, org.quartz.Scheduler scheduler) thr
break;
case CRON4J:
cron = CronMapper.fromCron4jToQuartz().map(cronExpr).asString();
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ public void compile(Set<File> files, Context context) {
.forEach(f -> settings.classpath().append(f));
settings.outputDirs().add(context.getSourceDirectory().getAbsolutePath(),
context.getOutputDirectory().getAbsolutePath());
Global g = new Global(settings);
Global.Run run = g.new Run();
Set<String> fileSet = files.stream()
.map(File::getAbsolutePath)
.collect(Collectors.toSet());
run.compile(JavaConverters.asScalaSet(fileSet).toList());
try (Global g = new Global(settings)) {
Global.Run run = g.new Run();
Set<String> fileSet = files.stream()
.map(File::getAbsolutePath)
.collect(Collectors.toSet());
run.compile(JavaConverters.asScalaSet(fileSet).toList());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ WebMetadataBuildItem createWebMetadata(ApplicationArchivesBuildItem applicationA
Set<String> additionalBeans = new HashSet<>();

final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
inputFactory.setXMLResolver(dtdInfo);
try (InputStream in = Files.newInputStream(webXml)) {
Expand Down Expand Up @@ -113,6 +114,7 @@ private Set<WebFragmentMetaData> parseWebFragments(ApplicationArchivesBuildItem
if (webFragment != null && Files.isRegularFile(webFragment)) {
try (InputStream is = Files.newInputStream(webFragment)) {
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
inputFactory.setXMLResolver(NoopXMLResolver.create());
XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,26 +203,27 @@ private void implementResolve(ClassCreator valueResolver, String clazzName, Clas
if (methodParams.isEmpty()) {

LOGGER.debugf("Method added %s", method);
BytecodeCreator matchScope = createMatchScope(resolve, method.name(), methodParams.size(), name, params,
paramsCount);
try (BytecodeCreator matchScope = createMatchScope(resolve, method.name(), methodParams.size(), name,
params, paramsCount)) {

// Invoke the method - no params
ResultHandle ret;
boolean hasCompletionStage = !skipMemberType(method.returnType())
&& hasCompletionStageInTypeClosure(index.getClassByName(method.returnType().name()), index);
// Invoke the method - no params
ResultHandle ret;
boolean hasCompletionStage = !skipMemberType(method.returnType())
&& hasCompletionStageInTypeClosure(index.getClassByName(method.returnType().name()), index);

ResultHandle invokeRet;
if (Modifier.isInterface(clazz.flags())) {
invokeRet = matchScope.invokeInterfaceMethod(MethodDescriptor.of(method), base);
} else {
invokeRet = matchScope.invokeVirtualMethod(MethodDescriptor.of(method), base);
}
if (hasCompletionStage) {
ret = invokeRet;
} else {
ret = matchScope.invokeStaticMethod(Descriptors.COMPLETED_FUTURE, invokeRet);
ResultHandle invokeRet;
if (Modifier.isInterface(clazz.flags())) {
invokeRet = matchScope.invokeInterfaceMethod(MethodDescriptor.of(method), base);
} else {
invokeRet = matchScope.invokeVirtualMethod(MethodDescriptor.of(method), base);
}
if (hasCompletionStage) {
ret = invokeRet;
} else {
ret = matchScope.invokeStaticMethod(Descriptors.COMPLETED_FUTURE, invokeRet);
}
matchScope.returnValue(ret);
}
matchScope.returnValue(ret);

} else {
// Collect methods with params
Expand Down Expand Up @@ -395,58 +396,60 @@ private void implementResolve(ClassCreator valueResolver, String clazzName, Clas

for (MethodInfo method : entry.getValue()) {
// Try to match parameter types
BytecodeCreator paramMatchScope = success.createScope();
int idx = 0;
for (Type paramType : method.parameters()) {
ResultHandle paramHandleClass = paramMatchScope.readArrayValue(paramClasses, idx++);
ResultHandle testClass = loadParamType(paramMatchScope, paramType);
ResultHandle baseClassTest = paramMatchScope.invokeVirtualMethod(Descriptors.IS_ASSIGNABLE_FROM,
testClass,
paramHandleClass);
paramMatchScope.ifNonZero(baseClassTest).falseBranch().breakScope(paramMatchScope);
}
boolean hasCompletionStage = !skipMemberType(method.returnType())
&& hasCompletionStageInTypeClosure(index.getClassByName(method.returnType().name()), index);

AssignableResultHandle invokeRet = paramMatchScope.createVariable(Object.class);
// try
TryBlock tryCatch = paramMatchScope.tryBlock();
// catch (Throwable e)
CatchBlockCreator exception = tryCatch.addCatch(Throwable.class);
// CompletableFuture.completeExceptionally(Throwable)
exception.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE_EXCEPTIONALLY, whenRet,
exception.getCaughtException());

if (Modifier.isInterface(clazz.flags())) {
tryCatch.assign(invokeRet,
tryCatch.invokeInterfaceMethod(MethodDescriptor.of(method), whenBase, paramsHandle));
} else {
tryCatch.assign(invokeRet,
tryCatch.invokeVirtualMethod(MethodDescriptor.of(method), whenBase, paramsHandle));
}

if (hasCompletionStage) {
FunctionCreator invokeWhenCompleteFun = tryCatch.createFunction(BiConsumer.class);
tryCatch.invokeInterfaceMethod(Descriptors.CF_WHEN_COMPLETE, invokeRet,
invokeWhenCompleteFun.getInstance());
BytecodeCreator invokeWhenComplete = invokeWhenCompleteFun.getBytecode();

// TODO workaround for https://github.com/quarkusio/gizmo/issues/6
AssignableResultHandle invokeWhenRet = invokeWhenComplete.createVariable(CompletableFuture.class);
invokeWhenComplete.assign(invokeWhenRet, whenRet);

BranchResult invokeThrowableIsNull = invokeWhenComplete
.ifNull(invokeWhenComplete.getMethodParam(1));
BytecodeCreator invokeSuccess = invokeThrowableIsNull.trueBranch();
invokeSuccess.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE, invokeWhenRet,
invokeWhenComplete.getMethodParam(0));
BytecodeCreator invokeFailure = invokeThrowableIsNull.falseBranch();
invokeFailure.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE_EXCEPTIONALLY,
invokeWhenRet,
invokeWhenComplete.getMethodParam(1));
invokeWhenComplete.returnValue(null);
} else {
tryCatch.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE, whenRet, invokeRet);
try (BytecodeCreator paramMatchScope = success.createScope()) {
int idx = 0;
for (Type paramType : method.parameters()) {
ResultHandle paramHandleClass = paramMatchScope.readArrayValue(paramClasses, idx++);
ResultHandle testClass = loadParamType(paramMatchScope, paramType);
ResultHandle baseClassTest = paramMatchScope.invokeVirtualMethod(Descriptors.IS_ASSIGNABLE_FROM,
testClass,
paramHandleClass);
paramMatchScope.ifNonZero(baseClassTest).falseBranch().breakScope(paramMatchScope);
}
boolean hasCompletionStage = !skipMemberType(method.returnType())
&& hasCompletionStageInTypeClosure(index.getClassByName(method.returnType().name()), index);

AssignableResultHandle invokeRet = paramMatchScope.createVariable(Object.class);
// try
TryBlock tryCatch = paramMatchScope.tryBlock();
// catch (Throwable e)
CatchBlockCreator exception = tryCatch.addCatch(Throwable.class);
// CompletableFuture.completeExceptionally(Throwable)
exception.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE_EXCEPTIONALLY, whenRet,
exception.getCaughtException());

if (Modifier.isInterface(clazz.flags())) {
tryCatch.assign(invokeRet,
tryCatch.invokeInterfaceMethod(MethodDescriptor.of(method), whenBase, paramsHandle));
} else {
tryCatch.assign(invokeRet,
tryCatch.invokeVirtualMethod(MethodDescriptor.of(method), whenBase, paramsHandle));
}

if (hasCompletionStage) {
FunctionCreator invokeWhenCompleteFun = tryCatch.createFunction(BiConsumer.class);
tryCatch.invokeInterfaceMethod(Descriptors.CF_WHEN_COMPLETE, invokeRet,
invokeWhenCompleteFun.getInstance());
BytecodeCreator invokeWhenComplete = invokeWhenCompleteFun.getBytecode();

// TODO workaround for https://github.com/quarkusio/gizmo/issues/6
AssignableResultHandle invokeWhenRet = invokeWhenComplete
.createVariable(CompletableFuture.class);
invokeWhenComplete.assign(invokeWhenRet, whenRet);

BranchResult invokeThrowableIsNull = invokeWhenComplete
.ifNull(invokeWhenComplete.getMethodParam(1));
BytecodeCreator invokeSuccess = invokeThrowableIsNull.trueBranch();
invokeSuccess.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE, invokeWhenRet,
invokeWhenComplete.getMethodParam(0));
BytecodeCreator invokeFailure = invokeThrowableIsNull.falseBranch();
invokeFailure.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE_EXCEPTIONALLY,
invokeWhenRet,
invokeWhenComplete.getMethodParam(1));
invokeWhenComplete.returnValue(null);
} else {
tryCatch.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE, whenRet, invokeRet);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Map;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.NamespacedKubernetesClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;

Expand All @@ -18,8 +19,9 @@ public Map<String, String> start() {
mockServer.init();

final Map<String, String> systemProps = new HashMap<>();
systemProps.put(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY,
mockServer.createClient().getConfiguration().getMasterUrl());
try (NamespacedKubernetesClient client = mockServer.createClient()) {
systemProps.put(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, client.getConfiguration().getMasterUrl());
}
systemProps.put(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true");
systemProps.put(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false");
systemProps.put(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false");
Expand Down