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

Task 135 fix sonarqube issues #151

Merged
merged 62 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
58f0a85
81: Mutations.mutation private
LorenzoBettini May 14, 2021
230d23f
135: comment on empty method
LorenzoBettini May 14, 2021
262944f
135: removed overridden methods taken from interface
LorenzoBettini May 14, 2021
7c0db1c
135: removed duplicated code in content provider
LorenzoBettini May 14, 2021
6f4d631
135: reduced cognitive complexity
LorenzoBettini May 14, 2021
e39b5ec
135: removed useless boxing
LorenzoBettini May 14, 2021
da99bcf
135: removed unused parameter 'mode'
LorenzoBettini May 14, 2021
0bb31bf
135: ignore ignored exceptions in launch
LorenzoBettini May 14, 2021
720e9fb
135: ignored returned null array
LorenzoBettini May 14, 2021
4b0d82e
135: Abstract classes should not have public constructors
LorenzoBettini May 14, 2021
3803d01
135: renamed local var not to shadow field
LorenzoBettini May 14, 2021
098be63
135: removed unused parameter
LorenzoBettini May 14, 2021
dc642e5
135: removed unused parameter
LorenzoBettini May 14, 2021
71e7d30
135: ignore constructor with lots of params used by builder
LorenzoBettini May 14, 2021
0773894
135: convert to lambdas and method references
LorenzoBettini May 14, 2021
5c26d8a
135: converted to lambda
LorenzoBettini May 14, 2021
4900e35
135: converted to lambda
LorenzoBettini May 14, 2021
da83e43
135: renamed local var not to shadow field
LorenzoBettini May 14, 2021
cbb4b12
135: fixed use of Optional
LorenzoBettini May 14, 2021
79d475f
135: renamed field coverage -> percentage
LorenzoBettini May 14, 2021
71bab79
135: Guava Optional -> Java Optional
LorenzoBettini May 14, 2021
9cce49c
135: removed launch of CoreException
LorenzoBettini May 14, 2021
194f7a1
135: removed publisher field
LorenzoBettini May 14, 2021
b251116
135: removed throws of PartInitException
LorenzoBettini May 14, 2021
799f038
135: Use java.nio createTempDirectory
LorenzoBettini May 14, 2021
69a0ab1
135: Use java.nio createTempDirectory
LorenzoBettini May 15, 2021
c899c3f
135: fixed createParentDirs
LorenzoBettini May 15, 2021
6ee636a
135: removed code blocks in switch
LorenzoBettini May 15, 2021
d606778
135: ignore security hotspot on temp file
LorenzoBettini May 15, 2021
c861d24
135: removed guava visible for testing annotations
LorenzoBettini May 15, 2021
3a0ce97
135: java.util.Objects instead of Guava
LorenzoBettini May 15, 2021
1e55d03
Merge branch 'task_85-Speed_up_UI_tests' into task_135-Fix_SonarQube_…
LorenzoBettini May 15, 2021
d639a71
135: commons.lang3.source in TP
LorenzoBettini May 15, 2021
24e3535
135: Dont' use Guava MoreObjects
LorenzoBettini May 15, 2021
cfcf6eb
Merge branch 'task_85-Speed_up_UI_tests' into task_135-Fix_SonarQube_…
LorenzoBettini Jul 10, 2021
32f457c
135: increased TP number
LorenzoBettini Jul 10, 2021
8186106
Merge branch 'task_85-Speed_up_UI_tests' into
LorenzoBettini Jul 12, 2021
cccca78
Merge branch 'task_85-Speed_up_UI_tests' into
LorenzoBettini Jul 13, 2021
1c88180
135: Separate PitRunnerMain
LorenzoBettini Jul 14, 2021
ca712a7
135: Private constructor in PitRunner
LorenzoBettini Jul 14, 2021
4d1e450
135: PitFileUtilsTest
LorenzoBettini Jul 14, 2021
f281a16
135: find file in PitFileUtils
LorenzoBettini Jul 14, 2021
c84e3ac
135: Fix file utils test for Windows
LorenzoBettini Jul 14, 2021
cf18ac7
135: Also assert the console contents for multiple projects
LorenzoBettini Jul 14, 2021
c10565d
135: find file without Files.find
LorenzoBettini Jul 14, 2021
af41321
Merge branch 'master' into task_135-Fix_SonarQube_issues
LorenzoBettini Jul 15, 2021
c8451b0
135: another test for PitOptions
LorenzoBettini Jul 15, 2021
da4a9a1
135: removed rethrow
LorenzoBettini Jul 15, 2021
1ab3e5e
135: don't use reflectionToString
LorenzoBettini Jul 15, 2021
856d663
135: excluded a few model classes from coverage
LorenzoBettini Jul 15, 2021
3a7121b
135: other tests for ObjectStreamSocket
LorenzoBettini Jul 15, 2021
1139413
135: SocketProvider returns if interrupted
LorenzoBettini Jul 15, 2021
406ea6c
135: corner case for PitClient.close
LorenzoBettini Jul 15, 2021
1c84c7c
135: fixed doc
LorenzoBettini Jul 15, 2021
98d7ddc
135: removed TODO from PitCommunicator
LorenzoBettini Jul 15, 2021
2ee0657
135: DetectionStatusConverter
LorenzoBettini Jul 15, 2021
9cbd41e
135: printStackTrace in runPit
LorenzoBettini Jul 15, 2021
8067450
135: test corner cases for PitOptions
LorenzoBettini Jul 16, 2021
047669f
135: turned parameter into local variable
LorenzoBettini Jul 21, 2021
e5bc021
135: PitRunner implements Function
LorenzoBettini Jul 21, 2021
1b72790
135: Class and test in default package in test project
LorenzoBettini Jul 21, 2021
235e65d
Merge remote-tracking branch 'origin/HEAD' into
LorenzoBettini Jul 22, 2021
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 @@ -16,26 +16,6 @@

package org.pitest.pitclipse.core;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.framework.BundleContext;
import org.pitest.pitclipse.runner.config.PitConfiguration;
import org.pitest.pitclipse.runner.config.PitExecutionMode;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static com.google.common.io.Files.createParentDirs;
import static com.google.common.io.Files.createTempDir;
import static org.eclipse.core.runtime.FileLocator.getBundleFile;
import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_TO;
import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_CLASSES;
Expand All @@ -46,6 +26,27 @@
import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL;
import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT;
import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT_FACTOR;
import static org.pitest.pitclipse.runner.util.PitFileUtils.createParentDirs;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.framework.BundleContext;
import org.pitest.pitclipse.runner.config.PitConfiguration;
import org.pitest.pitclipse.runner.config.PitExecutionMode;

/**
* The activator class controls the plug-in life cycle
Expand Down Expand Up @@ -118,7 +119,7 @@ public void start(BundleContext context) throws Exception { // NOPMD - Base
// class defines
// signature
super.start(context);
plugin = this;
plugin = this; // NOSONAR typical in Eclipse
setActivator(this);
setupStateDirectories();

Expand Down Expand Up @@ -173,7 +174,7 @@ private void setupHistoryFile() {
} catch (IOException e) {
// Cannot write to workspace.
// Probably shouldn't happen but lets use a temp file instead
historyFile = new File(createTempDir(), STATE_FILE);
historyFile = new File(createTemporaryDirectory(), STATE_FILE);
}
}

Expand All @@ -186,10 +187,17 @@ private void setupResultDir() {
} catch (IOException e) {
// Cannot write to workspace.
// Probably shouldn't happen but lets use a temp dir instead
resultDir = createTempDir();
resultDir = createTemporaryDirectory();
}
}

private File createTemporaryDirectory() {
try {
return Files.createTempDirectory(null).toFile();
} catch (IOException e1) {
throw new IllegalStateException("Cannot create temporary directory", e1);
}
}

private static void setActivator(PitCoreActivator pitActivator) {
plugin = pitActivator;
Expand Down Expand Up @@ -222,19 +230,19 @@ public static PitCoreActivator getDefault() {
}

public static void log(String msg) {
log(Status.INFO, msg, null);
log(IStatus.INFO, msg, null);
}

private static void log(int status, String msg, Throwable t) {
getDefault().getLog().log(new Status(status, PLUGIN_ID, Status.OK, msg, t));
getDefault().getLog().log(new Status(status, PLUGIN_ID, IStatus.OK, msg, t));
}

public static void warn(String msg) {
warn(msg, null);
}

public static void warn(String msg, Throwable t) {
log(Status.WARNING, msg, t);
log(IStatus.WARNING, msg, t);
}

public File emptyResultDir() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ final class LaunchShortcut {

static <T> Optional<T> forEditorInputDo(IEditorInput i, Function<ITypeRoot, Optional<T>> onFound, Supplier<Optional<T>> notFound) {
Optional<ITypeRoot> element = Optional.ofNullable(getEditorInputTypeRoot(i));
if (element.isPresent()) {
return element.map(onFound).get();
} else {
return notFound.get();
}
return element.map(onFound).orElseGet(notFound);
}

static Function<ITypeRoot, Optional<IResource>> getCorrespondingResource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public final class PitArgumentsTab extends AbstractLaunchConfigurationTab {
private Text excludedMethodsText;
private Text avoidCallsTo;

@Override
public void initializeFrom(ILaunchConfiguration config) {
projectText.setText(getAttributeFromConfig(config, ATTR_PROJECT_NAME, ""));
String testClass = getAttributeFromConfig(config, ATTR_MAIN_TYPE_NAME, "");
Expand All @@ -95,14 +96,14 @@ public void initializeFrom(ILaunchConfiguration config) {
private void initialiseWithPreferenceDefaults(ILaunchConfiguration config) {
PitConfiguration preferences = PitCoreActivator.getDefault()
.getConfiguration();
runInParallel.setSelection(Boolean
.valueOf(getBooleanAttributeFromConfig(config,
runInParallel.setSelection(
getBooleanAttributeFromConfig(config,
ATTR_TEST_IN_PARALLEL,
preferences.isParallelExecution())));
incrementalAnalysis.setSelection(Boolean
.valueOf(getBooleanAttributeFromConfig(config,
preferences.isParallelExecution()));
incrementalAnalysis.setSelection(
getBooleanAttributeFromConfig(config,
ATTR_TEST_INCREMENTALLY,
preferences.isIncrementalAnalysis())));
preferences.isIncrementalAnalysis()));
excludedClassesText.setText(getAttributeFromConfig(config,
ATTR_EXCLUDE_CLASSES, preferences.getExcludedClasses()));
excludedMethodsText.setText(getAttributeFromConfig(config,
Expand All @@ -111,6 +112,7 @@ private void initialiseWithPreferenceDefaults(ILaunchConfiguration config) {
ATTR_AVOID_CALLS_TO, preferences.getExcludedMethods()));
}

@Override
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
setControl(comp);
Expand Down Expand Up @@ -234,10 +236,12 @@ private Button createNewCheckBox(Font font, Composite comp, String label) {
return checkBox;
}

@Override
public String getName() {
return "PIT";
}

@Override
public void performApply(ILaunchConfigurationWorkingCopy workingCopy) {
workingCopy.setAttribute(ATTR_PROJECT_NAME, projectText.getText()
.trim());
Expand All @@ -264,6 +268,7 @@ public void performApply(ILaunchConfigurationWorkingCopy workingCopy) {
}
}

@Override
public void setDefaults(ILaunchConfigurationWorkingCopy workingCopy) {
/*
* IJavaElement javaElement = getContext(); if (javaElement != null) {
Expand Down Expand Up @@ -325,6 +330,7 @@ public void widgetSelected(SelectionEvent e) {
}

private final class UpdateOnModifyListener implements ModifyListener {
@Override
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ private void launch(Object[] elements, String mode) {
else {
showNoTestsFoundDialog();
}
} catch (InterruptedException e) {
} catch (InterruptedException e) { // NOSONAR
// OK, silently move on
} catch (CoreException e) {
} catch (CoreException e) { // NOSONAR
// OK, silently move on
}
}
Expand All @@ -134,7 +134,7 @@ private void showNoTestsFoundDialog() {

private void performLaunch(IJavaElement element, String mode) throws InterruptedException, CoreException {
ILaunchConfigurationWorkingCopy tmp = createLaunchConfiguration(element);
Optional<ILaunchConfiguration> existingConfig = findExistingLaunchConfiguration(tmp, mode);
Optional<ILaunchConfiguration> existingConfig = findExistingLaunchConfiguration(tmp);
ILaunchConfiguration config = existingConfig.orElse(tmp.doSave());
DebugUITools.launch(config, mode);
}
Expand All @@ -154,13 +154,11 @@ private ILaunchManager getLaunchManager() {
*
* @param configList
* list of {@link ILaunchConfiguration}s
* @param mode
* launch mode
* @return ILaunchConfiguration
* @throws InterruptedException
* if cancelled by the user
*/
private ILaunchConfiguration chooseConfiguration(List<ILaunchConfiguration> configList, String mode) throws InterruptedException {
private ILaunchConfiguration chooseConfiguration(List<ILaunchConfiguration> configList) throws InterruptedException {
IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
dialog.setElements(configList.toArray());
Expand Down Expand Up @@ -195,31 +193,23 @@ protected ILaunchConfigurationWorkingCopy createLaunchConfiguration(IJavaElement
switch (element.getElementType()) {
case JAVA_PROJECT:
case PACKAGE_FRAGMENT_ROOT:
case PACKAGE_FRAGMENT: {
case PACKAGE_FRAGMENT:
String name = getTextLabel(element, ALL_FULLY_QUALIFIED);
containerHandleId = element.getHandleIdentifier();
mainTypeQualifiedName = EMPTY_STRING;
testName = name.substring(name.lastIndexOf(IPath.SEPARATOR) + 1);
}
break;
case TYPE: {
case TYPE:
containerHandleId = EMPTY_STRING;
mainTypeQualifiedName = ((IType) element).getFullyQualifiedName('.'); // don't
// replace,
// fix
// for
// binary
// inner
// types
// don't replace, fix for binary inner types
mainTypeQualifiedName = ((IType) element).getFullyQualifiedName('.');
testName = element.getElementName();
}
break;
case METHOD: {
case METHOD:
IMethod method = (IMethod) element;
containerHandleId = EMPTY_STRING;
mainTypeQualifiedName = method.getDeclaringType().getFullyQualifiedName('.');
testName = method.getDeclaringType().getElementName() + '.' + method.getElementName();
}
break;
default:
throw new IllegalArgumentException("Invalid element type to create a launch configuration: " + element.getClass().getName()); //$NON-NLS-1$
Expand Down Expand Up @@ -269,7 +259,7 @@ private static boolean hasSameAttributes(ILaunchConfiguration config1, ILaunchCo
return false;
}

private Optional<ILaunchConfiguration> findExistingLaunchConfiguration(ILaunchConfigurationWorkingCopy temporary, String mode) throws InterruptedException,
private Optional<ILaunchConfiguration> findExistingLaunchConfiguration(ILaunchConfigurationWorkingCopy temporary) throws InterruptedException,
CoreException {
List<ILaunchConfiguration> candidateConfigs = findExistingLaunchConfigurations(temporary);

Expand All @@ -287,7 +277,7 @@ private Optional<ILaunchConfiguration> findExistingLaunchConfiguration(ILaunchCo
// cancelled the dialog, in which case this method returns null,
// since cancelling the dialog should also cancel launching
// anything.
ILaunchConfiguration config = chooseConfiguration(candidateConfigs, mode);
ILaunchConfiguration config = chooseConfiguration(candidateConfigs);
if (config != null) {
return Optional.ofNullable(config);
}
Expand Down Expand Up @@ -329,7 +319,7 @@ public ILaunchConfiguration[] getLaunchConfigurations(ISelection selection) {
return toArrayOfILaunchConfiguration(configs);
}
}
return null;
return null; // NOSONAR Eclipse code relies on returned null array
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.jdt.core.IJavaModel;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;

import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME;
import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME;
Expand Down Expand Up @@ -67,14 +68,7 @@ private static IResource getResource(ILaunchConfiguration config)
if (projName != null && Path.ROOT.isValidSegment(projName)) {
IJavaProject javaProject = getJavaModel().getJavaProject(projName);
if (javaProject.exists()) {
if (typeName != null && typeName.length() > 0) {
element = javaProject.findType(typeName);
} else if (container != null && container.length() > 0) {
element = JavaCore.create(container);
}
if (element == null) {
element = javaProject;
}
element = getJavaProject(typeName, container, javaProject);
} else {
IProject project = javaProject.getProject();
if (project.exists() && !project.isOpen()) {
Expand All @@ -89,6 +83,20 @@ private static IResource getResource(ILaunchConfiguration config)
return resource;
}

private static IJavaElement getJavaProject(String typeName, String container,
IJavaProject javaProject) throws JavaModelException {
IJavaElement element = null;
if (typeName != null && typeName.length() > 0) {
element = javaProject.findType(typeName);
} else if (container != null && container.length() > 0) {
element = JavaCore.create(container);
}
if (element == null) {
element = javaProject;
}
return element;
}

/*
* Convenience method to get access to the java model.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.pitest.pitclipse.launch.config.SourceDirFinder;
import org.pitest.pitclipse.runner.PitOptions;
import org.pitest.pitclipse.runner.PitOptions.PitOptionsBuilder;
import org.pitest.pitclipse.runner.PitRunner;
import org.pitest.pitclipse.runner.PitRunnerMain;
import org.pitest.pitclipse.runner.config.PitConfiguration;
import org.pitest.pitclipse.runner.io.SocketProvider;

Expand All @@ -53,20 +53,20 @@
/**
* <p>Abstract launch configuration used to execute PIT in a background VM.</p>
*
* <p>Pitest is executed by calling {@link PitRunner#main(String[])}.</p>
* <p>Pitest is executed by calling {@link PitRunnerMain#main(String[])}.</p>
*
* <p>Right after the VM has been launched, contributions to the {@code results}
* extension points are notified thanks to {@link ExtensionPointHandler}.</p>
*/
public abstract class AbstractPitLaunchDelegate extends JavaLaunchDelegate {

private static final String EXTENSION_POINT_ID = "org.pitest.pitclipse.core.executePit";
private static final String PIT_RUNNER = PitRunner.class.getCanonicalName();
private static final String PIT_RUNNER_MAIN = PitRunnerMain.class.getCanonicalName();
private int portNumber;
private final PitConfiguration pitConfiguration;
private boolean projectUsesJunit5 = false;

public AbstractPitLaunchDelegate(PitConfiguration pitConfiguration) {
protected AbstractPitLaunchDelegate(PitConfiguration pitConfiguration) {
this.pitConfiguration = pitConfiguration;
}

Expand All @@ -76,7 +76,7 @@ protected void generatePortNumber() {

@Override
public String getMainTypeName(ILaunchConfiguration launchConfig) throws CoreException {
return PIT_RUNNER;
return PIT_RUNNER_MAIN;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public IJavaProject getProject() throws CoreException {
return getProject(launchConfig.getAttribute(ATTR_PROJECT_NAME, ""));
}

private IJavaProject getProject(String projectName) throws CoreException {
private IJavaProject getProject(String projectName) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
for (IProject project : root.getProjects()) {
if (projectName.equals(project.getName())) {
Expand Down
Loading