Cleanup (docs; formatting; arrangement)

This commit is contained in:
Roman Shevchenko
2017-11-24 17:16:06 +01:00
parent 338baf7bb0
commit cbbaa81414
2 changed files with 26 additions and 55 deletions
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.configurations;
import com.intellij.openapi.application.Application;
@@ -40,32 +26,25 @@ import java.util.regex.Pattern;
/**
* A list of command-line parameters featuring the following:
* <ul>
* <li>special handling for java properties ({@code -D<name>=<value>})</li>
* <li>special handling for Java properties ({@code -D<name>=<value>})</li>
* <li>macro substitution upon addition for plain parameters, and property values</li>
* <li>named groups for parameters</li>
* <li>parameter strings with quoted parameters</li>
* </ul>
*
*
* @see ParametersList#defineProperty(String, String)
* @see ParametersList#expandMacros(String)
* @see ParametersList#addParamsGroup(String)
* @see ParametersList#addParametersString(String)
* @see ParamsGroup
* @see ParametersList#expandMacros(String)
* @see ParametersList#addParamsGroup(String)
* @see ParametersList#addParametersString(String)
* @see ParamsGroup
*/
public final class ParametersList implements Cloneable {
private static final Pattern PROPERTY_PATTERN = Pattern.compile("-D(\\S+?)(?:=(.+))?");
private static final Pattern MACRO_PATTERN = Pattern.compile("\\$\\{([^}]+)}");
private static Map<String, String> ourTestMacros;
private final List<String> myParameters = new ArrayList<>();
private final List<ParamsGroup> myGroups = new SmartList<>();
private final NotNullLazyValue<Map<String, String>> myMacroMap = NotNullLazyValue.createValue(ParametersList::computeMacroMap);
@TestOnly
public static void setTestMacros(@Nullable Map<String, String> testMacros) {
ourTestMacros = testMacros;
}
public boolean hasParameter(@NotNull String parameter) {
return myParameters.contains(parameter);
@@ -74,7 +53,7 @@ public final class ParametersList implements Cloneable {
public boolean hasProperty(@NotNull String propertyName) {
return getPropertyValue(propertyName) != null;
}
@Nullable
public String getPropertyValue(@NotNull String propertyName) {
String exact = "-D" + propertyName;
@@ -87,7 +66,7 @@ public final class ParametersList implements Cloneable {
@NotNull
public Map<String, String> getProperties() {
LinkedHashMap<String, String> result = new LinkedHashMap<>();
Map<String, String> result = new LinkedHashMap<>();
JBIterable<Matcher> matchers = JBIterable.from(myParameters).map(PROPERTY_PATTERN::matcher).filter(Matcher::matches);
for (Matcher matcher : matchers) {
result.put(matcher.group(1), StringUtil.notNullize(matcher.group(2), ""));
@@ -271,7 +250,7 @@ public final class ParametersList implements Cloneable {
}
private void replaceOrAddAt(@NotNull String replacement,
int position,
int position,
@NotNull Condition<? super String> existingCondition) {
int index = indexOfParameter(existingCondition);
boolean setNewValue = StringUtil.isNotEmpty(replacement);
@@ -377,6 +356,13 @@ public final class ParametersList implements Cloneable {
return sb == null ? text : sb.append(text, start, text.length()).toString();
}
private static Map<String, String> ourTestMacros;
@TestOnly
public static void setTestMacros(@Nullable Map<String, String> testMacros) {
ourTestMacros = testMacros;
}
@NotNull
private static Map<String, String> computeMacroMap() {
// ApplicationManager.getApplication() will return null if executed in ParameterListTest
@@ -402,5 +388,4 @@ public final class ParametersList implements Cloneable {
public String toString() {
return myParameters + (myGroups.isEmpty() ? "" : " and " + myGroups);
}
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.configurations;
import org.jetbrains.annotations.NotNull;
@@ -20,14 +6,14 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author Roman.Chernyatchik
*
* Group of linked params. Sometime it's much more convenient to split cmdline in logical groups.
* In this case it will be easier to patch such grouped argements using custom extentions
* In this case it will be easier to patch such grouped arguments using custom extensions.
*
* E.g.: we want to add Coverage support to all existing Ruby run configurations(ruby applications,
* different kinds of ruby tests, rails configuration, etc). Coverage support require to reorder args
* in cmdline, add rcov runner script, etc. Without groups it would be harder to parse abstract list of arguments
* E.g.: we want to add Coverage support to all existing Ruby run configurations (Ruby applications,
* different kinds of tests, Rails configuration, etc). Adding coverage support requires reordering args
* in command line, adding RCov runner script, etc. Without groups it would be harder to parse abstract list of arguments.
*
* @author Roman.Chernyatchik
*/
public final class ParamsGroup implements Cloneable {
@@ -90,4 +76,4 @@ public final class ParamsGroup implements Cloneable {
public String toString() {
return myGroupId + ":" + myParamList;
}
}
}