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 yarn execution with Maven proxy defined #797

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -71,15 +71,15 @@ List<String> parse(String args) {
return new ArrayList<>(arguments);
}

private static void addArgument(StringBuilder argumentBuilder, List<String> arguments) {
static void addArgument(StringBuilder argumentBuilder, List<String> arguments) {
if (argumentBuilder.length() > 0) {
String argument = argumentBuilder.toString();
addArgument(argument, arguments);
argumentBuilder.setLength(0);
}
}

private static void addArgument(String argument, List<String> arguments) {
static void addArgument(String argument, List<String> arguments) {
if (!arguments.contains(argument)) {
arguments.add(argument);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

class YarnArgumentsParser {

private final List<String> additionalArguments;

YarnArgumentsParser() {
this(Collections.<String>emptyList());
}

YarnArgumentsParser(List<String> additionalArguments) {
this.additionalArguments = additionalArguments;
}

/**
* Parses a given string of arguments, splitting it by characters that are whitespaces according to {@link Character#isWhitespace(char)}.
* <p>
* This method respects quoted arguments. Meaning that whitespaces appearing phrases that are enclosed by an opening
* single or double quote and a closing single or double quote or the end of the string will not be considered.
* <p>
* All characters excluding whitespaces considered for splitting stay in place.
* <p>
* Examples:
* "foo bar" will be split to ["foo", "bar"]
* "foo \"bar foobar\"" will be split to ["foo", "\"bar foobar\""]
* "foo 'bar" will be split to ["foo", "'bar"]
*
* @param args a string of arguments
* @return an mutable copy of the list of all arguments
*/
List<String> parse(String args) {
if (args == null || "null".equals(args) || args.isEmpty()) {
return Collections.emptyList();
}

final List<String> arguments = new LinkedList<>();

for (String argument : this.additionalArguments) {
ArgumentsParser.addArgument(argument, arguments);
}

final StringBuilder argumentBuilder = new StringBuilder();
Character quote = null;

for (int i = 0, l = args.length(); i < l; i++) {
char c = args.charAt(i);

if (Character.isWhitespace(c) && quote == null) {
ArgumentsParser.addArgument(argumentBuilder, arguments);
continue;
} else if (c == '"' || c == '\'') {
// explicit boxing allows us to use object caching of the Character class
Character currentQuote = Character.valueOf(c);
if (quote == null) {
quote = currentQuote;
} else if (quote.equals(currentQuote)){
quote = null;
} // else
// we ignore the case when a quoted argument contains the other kind of quote
}

argumentBuilder.append(c);
}

ArgumentsParser.addArgument(argumentBuilder, arguments);

return new ArrayList<>(arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class YarnTaskExecutor {

private final String taskName;

private final ArgumentsParser argumentsParser;
private final YarnArgumentsParser argumentsParser;

private final YarnExecutorConfig config;

Expand All @@ -42,7 +42,7 @@ public YarnTaskExecutor(YarnExecutorConfig config, String taskName, String taskL
logger = LoggerFactory.getLogger(getClass());
this.config = config;
this.taskName = taskName;
this.argumentsParser = new ArgumentsParser(additionalArguments);
this.argumentsParser = new YarnArgumentsParser(additionalArguments);
}

private static String getTaskNameFromLocation(String taskLocation) {
Expand Down