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

Minor code Improvements #42

Merged
merged 3 commits into from
Aug 15, 2019
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 @@ -198,7 +198,7 @@ public void check() throws CustomToolException {
* @since 0.3
*/
public @Nonnull List<LabelSpecifics> getAppliedSpecifics(@Nonnull Node node) {
List<LabelSpecifics> out = new LinkedList<LabelSpecifics>();
List<LabelSpecifics> out = new LinkedList<>();
if (labelSpecifics != null) {
for (LabelSpecifics spec : labelSpecifics) {
if (spec.appliesTo(node)) {
Expand Down Expand Up @@ -283,7 +283,7 @@ public PathsList invoke(File f, VirtualChannel channel)
throws IOException, InterruptedException {

// Construct output paths
List<String> items = new LinkedList<String>();
List<String> items = new LinkedList<>();
if (exportedPaths != null) {
parseLists(exportedPaths, items);
}
Expand All @@ -295,7 +295,7 @@ public PathsList invoke(File f, VirtualChannel channel)
}

// Resolve exported paths
List<String> outList = new LinkedList<String>();
List<String> outList = new LinkedList<>();
for (String item : items) {
File file = new File(item);
if (!file.isAbsolute()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public Launcher decorateLauncher(AbstractBuild build, final Launcher launcher,
final EnvVars versions = new EnvVars();

final PathsList paths = new PathsList();
final List<EnvVariablesInjector> additionalVarInjectors = new LinkedList<EnvVariablesInjector>();
final List<EnvVariablesInjector> additionalVarInjectors = new LinkedList<>();

// Handle multi-configuration build
if (build instanceof MatrixBuild) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ public void injectVariables(@Nonnull EnvVars target) throws IOException {
//TODO: check overrides
//TODO: check lists
//TODO: substitute, check, etc.
//Substitute current envValue
String replacedValue = target.containsKey(envName) ? target.get(envName) : "";
String newEnvValue=envValue.replace("${"+envName+"}", replacedValue);

// Substitute current envValue
String replacedValue = target.getOrDefault(envName, "");
String newEnvValue = envValue.replace("${" + envName + "}", replacedValue);

target.put(envName, newEnvValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class PathsList implements Serializable {
public @CheckForNull String pathSeparator;
public @CheckForNull String separator;

public static final PathsList EMPTY = new PathsList(new LinkedList<String>(), null);
public static final PathsList EMPTY = new PathsList(new LinkedList<>(), null);

/**
* Constructor. Sets system's default separator and pathSeparator
Expand All @@ -50,13 +50,13 @@ public PathsList(@Nonnull Collection<String> paths, @CheckForNull String homeDir
* Empty constructor. doesn't set pathSeparator and separator
*/
public PathsList() {
this(new LinkedList<String>(), null, null, null);
this(new LinkedList<>(), null, null, null);
}

public PathsList(@Nonnull Collection<String> paths,
@CheckForNull String pathSeparator, @CheckForNull String separator,
@CheckForNull String homeDir) {
this.paths = new ArrayList<String>(paths);
this.paths = new ArrayList<>(paths);
this.pathSeparator = pathSeparator;
this.separator = separator;
this.homeDir = homeDir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static ExtendedChoiceParameterDefinition getVersionDescr(String toolName)
*/
public static @Nonnull List<CustomTool> getAllVersionedTools() {
CustomTool.DescriptorImpl tools = ToolInstallation.all().get(CustomTool.DescriptorImpl.class);
List<CustomTool> res = new LinkedList<CustomTool>();
List<CustomTool> res = new LinkedList<>();
if (tools != null ) {
for (CustomTool tool : tools.getInstallations()) {
if (tool.hasVersions()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public String resolveVariable(@CheckForNull String inputValue, @Nonnull Node nod
*/
private String substituteNodeProperty(@CheckForNull String macroString, @CheckForNull NodeProperty<?> property) {
// Get environment variables
if (property != null && property instanceof EnvironmentVariablesNodeProperty) {
if (property instanceof EnvironmentVariablesNodeProperty) {
EnvironmentVariablesNodeProperty prop = (EnvironmentVariablesNodeProperty)property;
return resolveVariable(macroString, prop.getEnvVars());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class CustomToolInstallWrapperTest {
*/
@Test
public void testNestedWrapper() throws Exception {
List<BuildWrapper> wrappers = new ArrayList<BuildWrapper>(2);
List<BuildWrapper> wrappers = new ArrayList<>(2);
wrappers.add(new StubWrapper());
wrappers.add(setupCustomToolsWrapper());
nestedWrapperTestImpl(wrappers, true);
Expand All @@ -63,7 +63,7 @@ public void testNestedWrapper() throws Exception {
*/
@Test
public void testNestedWrapperReverse() throws Exception {
List<BuildWrapper> wrappers = new ArrayList<BuildWrapper>(2);
List<BuildWrapper> wrappers = new ArrayList<>(2);
wrappers.add(setupCustomToolsWrapper());
wrappers.add(new StubWrapper());
nestedWrapperTestImpl(wrappers, true);
Expand All @@ -79,7 +79,7 @@ public void testNestedWrapperReverse() throws Exception {
@Test
@Issue("JENKINS-19506")
public void testNestedLauncherCalls() throws Exception {
List<BuildWrapper> wrappers = new ArrayList<BuildWrapper>(2);
List<BuildWrapper> wrappers = new ArrayList<>(2);
wrappers.add(new CommandCallerInstaller());
wrappers.add(setupCustomToolsWrapper());
nestedWrapperTestImpl(wrappers, false);
Expand All @@ -88,7 +88,7 @@ public void testNestedLauncherCalls() throws Exception {
@Test
@Issue("JENKINS-20560")
public void testEmptyToolsList() throws Exception {
List<BuildWrapper> wrappers = new ArrayList<BuildWrapper>(0);
List<BuildWrapper> wrappers = new ArrayList<>(0);
wrappers.add(new CommandCallerInstaller());
wrappers.add(new CustomToolInstallWrapper(null, MulticonfigWrapperOptions.DEFAULT, false));
nestedWrapperTestImpl(wrappers, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,22 @@ public void testAdditionalVars() throws Exception {
}

public static CustomTool createTool(String name) throws IOException {
List<ToolInstaller> installers = new ArrayList<ToolInstaller>();
List<ToolInstaller> installers = new ArrayList<>();
installers.add(new CommandInstaller(null, "ln -s `which true` mytrue",
"./"));

List<ToolProperty<ToolInstallation>> properties = new ArrayList<ToolProperty<ToolInstallation>>();
List<ToolProperty<ToolInstallation>> properties = new ArrayList<>();
properties.add(new InstallSourceProperty(installers));

return new CustomTool("MyTrue", null, properties, "./", null, ToolVersionConfig.DEFAULT, null);
}

//TODO: refactor and generalize
private CustomTool createEnvPrinterTool(String name, LabelSpecifics[] specifics, String additionalVars) throws IOException {
List<ToolInstaller> installers = new ArrayList<ToolInstaller>();
List<ToolInstaller> installers = new ArrayList<>();
installers.add(new CommandInstaller(null, "ln -s `which true` mytrue", "./"));

List<ToolProperty<ToolInstallation>> properties = new ArrayList<ToolProperty<ToolInstallation>>();
List<ToolProperty<ToolInstallation>> properties = new ArrayList<>();
properties.add(new InstallSourceProperty(installers));

return new CustomTool(name, null, properties, "./", specifics, ToolVersionConfig.DEFAULT, additionalVars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public class ToolVersionParameterDefinitionTest {

private void setupVersionedTool() throws Exception {
CustomTool.DescriptorImpl tools = j.jenkins.getDescriptorByType(CustomTool.DescriptorImpl.class);
List<ToolInstaller> installers = new ArrayList<ToolInstaller>();
List<ToolInstaller> installers = new ArrayList<>();
installers.add(new CommandInstaller(null, "ln -s `which true` mytrue", "./"));
List<ToolProperty<ToolInstallation>> properties = new ArrayList<ToolProperty<ToolInstallation>>();
List<ToolProperty<ToolInstallation>> properties = new ArrayList<>();
properties.add(new InstallSourceProperty(installers));
CustomTool installation = new CustomTool(TEST_TOOL_NAME, null, properties, "./", null, versionConfig, null);
tools.setInstallations(installation);
Expand Down