Drop "-printArgs"
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-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.
|
||||
*/
|
||||
|
||||
package com.sampullara.cli;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ComparatorUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ArgumentUtils {
|
||||
|
||||
private ArgumentUtils() {}
|
||||
|
||||
@NotNull
|
||||
public static <T> List<String> convertArgumentsToStringList(@NotNull T arguments, @NotNull T defaultArguments) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
convertArgumentsToStringList(arguments, defaultArguments, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> void convertArgumentsToStringList(@NotNull T arguments, @NotNull T defaultArguments, @NotNull List<String> result) {
|
||||
convertArgumentsToStringList(arguments, defaultArguments, arguments.getClass(), result);
|
||||
}
|
||||
|
||||
private static <T> void convertArgumentsToStringList(T arguments, T defaultArguments, Class clazz, List<String> result) {
|
||||
Class superClazz = clazz.getSuperclass();
|
||||
if (superClazz != null) {
|
||||
convertArgumentsToStringList(arguments, defaultArguments, superClazz, result);
|
||||
}
|
||||
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
Argument argument = field.getAnnotation(Argument.class);
|
||||
if (argument == null) continue;
|
||||
|
||||
Object value;
|
||||
Object defaultValue;
|
||||
try {
|
||||
value = field.get(arguments);
|
||||
defaultValue = field.get(defaultArguments);
|
||||
}
|
||||
catch (IllegalAccessException ignored) {
|
||||
// skip this field
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ComparatorUtil.equalsNullable(value, defaultValue)) continue;
|
||||
|
||||
String name = Args.getAlias(argument);
|
||||
if (name == null) {
|
||||
name = Args.getName(argument, field);
|
||||
}
|
||||
|
||||
Class<?> fieldType = field.getType();
|
||||
|
||||
if (fieldType.isArray()) {
|
||||
Object[] values = (Object[]) value;
|
||||
if (values.length == 0) continue;
|
||||
value = StringUtil.join(values, Function.TO_STRING, argument.delimiter());
|
||||
}
|
||||
|
||||
result.add(argument.prefix() + name);
|
||||
|
||||
if (fieldType == boolean.class || fieldType == Boolean.class) continue;
|
||||
|
||||
result.add(value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-3
@@ -41,9 +41,6 @@ public abstract class CommonCompilerArguments {
|
||||
@ValueDescription(SUPPRESS_WARNINGS)
|
||||
public String suppress;
|
||||
|
||||
@Argument(value = "printArgs", description = "Print command line arguments")
|
||||
public boolean printArgs;
|
||||
|
||||
public List<String> freeArgs = new SmartList<String>();
|
||||
|
||||
public boolean suppressAllWarnings() {
|
||||
|
||||
@@ -20,9 +20,7 @@ import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.sampullara.cli.Args;
|
||||
import com.sampullara.cli.ArgumentUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
|
||||
import org.jetbrains.jet.cli.common.messages.*;
|
||||
@@ -112,7 +110,6 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
MessageRenderer messageRenderer = getMessageRenderer(arguments);
|
||||
errStream.print(messageRenderer.renderPreamble());
|
||||
|
||||
printArgumentsIfNeeded(errStream, arguments, messageRenderer);
|
||||
printVersionIfNeeded(errStream, arguments, messageRenderer);
|
||||
|
||||
MessageCollector collector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose);
|
||||
@@ -175,25 +172,6 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
}
|
||||
}
|
||||
|
||||
private void printArgumentsIfNeeded(
|
||||
@NotNull PrintStream errStream,
|
||||
@NotNull A arguments,
|
||||
@NotNull MessageRenderer messageRenderer
|
||||
) {
|
||||
if (arguments.printArgs) {
|
||||
String freeArgs = !arguments.freeArgs.isEmpty() ? " " + StringUtil.join(arguments.freeArgs, " ") : "";
|
||||
|
||||
List<String> argumentsAsList = ArgumentUtils.convertArgumentsToStringList(arguments, createArguments());
|
||||
String argumentsAsString = StringUtil.join(argumentsAsList, " ");
|
||||
|
||||
String printArgsMessage = messageRenderer.render(CompilerMessageSeverity.INFO,
|
||||
"Invoking " + getClass().getSimpleName() +
|
||||
" with arguments " + argumentsAsString + freeArgs,
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
errStream.println(printArgsMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Useful main for derived command line tools
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user