From 1b54f1147b4de985ae2254151ab224e6544e68ba Mon Sep 17 00:00:00 2001 From: Jan Belle Date: Sun, 5 May 2019 22:26:00 +0200 Subject: [generator.tests] Migrate tests to new import system Bug 545235 Change-Id: I5f349f7ab6cf12e23cfc68323987e24c998ae263 --- .../eTrice-rt.launch | 2 +- .../etrice/generator/base/args/IntegerOption.java | 30 ---------------------- .../etrice/generator/base/args/PathOption.java | 26 +++++++++++++++++++ .../generator/base/args/StringArrayOption.java | 27 ------------------- .../generator/base/cli/CommandLineParser.java | 21 +++++++-------- .../etrice/generator/base/cli/HelpFormatter.java | 3 +-- .../generator/base/cli/ICommandLineParser.java | 6 ++--- .../etrice/generator/base/cli/IHelpFormatter.java | 4 +-- .../base/setup/GeneratorApplicationOptions.java | 9 ++++--- 9 files changed, 49 insertions(+), 79 deletions(-) delete mode 100644 plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/args/IntegerOption.java create mode 100644 plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/args/PathOption.java delete mode 100644 plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/args/StringArrayOption.java (limited to 'plugins') diff --git a/plugins/org.eclipse.etrice.core.room.ui/eTrice-rt.launch b/plugins/org.eclipse.etrice.core.room.ui/eTrice-rt.launch index 98fc0beb4..6e4b0ece6 100644 --- a/plugins/org.eclipse.etrice.core.room.ui/eTrice-rt.launch +++ b/plugins/org.eclipse.etrice.core.room.ui/eTrice-rt.launch @@ -13,7 +13,7 @@ - + diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/args/IntegerOption.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/args/IntegerOption.java deleted file mode 100644 index b3cec8e30..000000000 --- a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/args/IntegerOption.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2018 protos software gmbh (http://www.protos.de). -* All rights reserved. -* -* This program and the accompanying materials are made -* available under the terms of the Eclipse Public License 2.0 -* which is available at https://www.eclipse.org/legal/epl-2.0/ -* -* SPDX-License-Identifier: EPL-2.0 -* -* CONTRIBUTORS: -* Jan Belle (initial contribution) -* - *******************************************************************************/ - -package org.eclipse.etrice.generator.base.args; - -/** - * Describes an option that takes an {@link Integer} value. - */ -public class IntegerOption extends Option { - - /** - * @see Option#Option - */ - public IntegerOption(String group, String name, String argumentName, String description, int defaultValue) { - super(Integer.class, group, name, argumentName, description, defaultValue); - } - -} diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/args/PathOption.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/args/PathOption.java new file mode 100644 index 000000000..41efa7a70 --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/args/PathOption.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2019 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * CONTRIBUTORS: + * Jan Belle (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.generator.base.args; + +public class PathOption extends Option { + + /** + * @see Option#Option + */ + public PathOption(String group, String name, String argumentName, String description, String[] defaultValue) { + super(String[].class, group, name, argumentName, description, defaultValue); + } + +} diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/args/StringArrayOption.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/args/StringArrayOption.java deleted file mode 100644 index 5e09e4f61..000000000 --- a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/args/StringArrayOption.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2018 protos software gmbh (http://www.protos.de). -* All rights reserved. -* -* This program and the accompanying materials are made -* available under the terms of the Eclipse Public License 2.0 -* which is available at https://www.eclipse.org/legal/epl-2.0/ -* -* SPDX-License-Identifier: EPL-2.0 -* -* CONTRIBUTORS: -* Jan Belle (initial contribution) -* - *******************************************************************************/ - -package org.eclipse.etrice.generator.base.args; - -public class StringArrayOption extends Option { - - /** - * @see Option#Option - */ - public StringArrayOption(String group, String name, String argumentName, String description, String[] defaultValue) { - super(String[].class, group, name, argumentName, description, defaultValue); - } - -} diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/CommandLineParser.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/CommandLineParser.java index 539bfb9f7..9e6e65271 100644 --- a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/CommandLineParser.java +++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/CommandLineParser.java @@ -15,14 +15,18 @@ package org.eclipse.etrice.generator.base.cli; +import java.io.File; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import org.eclipse.etrice.generator.base.args.Arguments; +import org.eclipse.etrice.generator.base.args.BooleanOption; +import org.eclipse.etrice.generator.base.args.EnumOption; import org.eclipse.etrice.generator.base.args.Option; import org.eclipse.etrice.generator.base.args.Options; -import org.eclipse.etrice.generator.base.args.StringArrayOption; +import org.eclipse.etrice.generator.base.args.PathOption; +import org.eclipse.etrice.generator.base.args.StringOption; /** * Simple implementation of a command line parser. @@ -39,7 +43,7 @@ public class CommandLineParser implements ICommandLineParser { } @Override - public Arguments parseArgs(Options options, StringArrayOption defaultOption, List args) throws CommandLineParseException { + public Arguments parseArgs(Options options, Option defaultOption, List args) throws CommandLineParseException { Arguments parsedArgs = new Arguments(options); List nArgs = normalize(args); ListIterator iterator = nArgs.listIterator(); @@ -81,23 +85,20 @@ public class CommandLineParser implements ICommandLineParser { } private Object parseValue(Option opt, ListIterator iterator) throws CommandLineParseException { - Class type = opt.getType(); - - if(type == Boolean.class) { + if(opt instanceof BooleanOption) { return true; } if(iterator.hasNext()) { String str = iterator.next(); - if(type == String.class) { + if(opt instanceof StringOption) { return str; } - else if(type == String[].class) { - String[] strArray = str.split(";"); - return strArray; + else if(opt instanceof PathOption) { + return str.split(File.pathSeparator); } - else if(type.isEnum()) { + else if(opt instanceof EnumOption) { return parseEnum(opt, str); } diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/HelpFormatter.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/HelpFormatter.java index e1aa1fafd..0b578250e 100644 --- a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/HelpFormatter.java +++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/HelpFormatter.java @@ -19,7 +19,6 @@ import java.util.Formatter; import org.eclipse.etrice.generator.base.args.Option; import org.eclipse.etrice.generator.base.args.Options; -import org.eclipse.etrice.generator.base.args.StringArrayOption; /** * Simple implementation for command line help formatting. @@ -30,7 +29,7 @@ public class HelpFormatter implements IHelpFormatter { } @Override - public String getHelp(String name, Options options, StringArrayOption defaultOption) { + public String getHelp(String name, Options options, Option defaultOption) { try(Formatter formatter = new Formatter()) { formatter.format("%s usage: [options] %s...%n", name, defaultOption.getName()); formatter.format("Options:%n"); diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/ICommandLineParser.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/ICommandLineParser.java index f3c3759e4..e17b55af1 100644 --- a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/ICommandLineParser.java +++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/ICommandLineParser.java @@ -19,8 +19,8 @@ import java.util.Arrays; import java.util.List; import org.eclipse.etrice.generator.base.args.Arguments; +import org.eclipse.etrice.generator.base.args.Option; import org.eclipse.etrice.generator.base.args.Options; -import org.eclipse.etrice.generator.base.args.StringArrayOption; import com.google.inject.ImplementedBy; @@ -37,7 +37,7 @@ public interface ICommandLineParser { * @param defaultOption the option for arguments without option identifier * @param args the command line arguments */ - Arguments parseArgs(Options options, StringArrayOption defaultOption, List args) throws CommandLineParseException; + Arguments parseArgs(Options options, Option defaultOption, List args) throws CommandLineParseException; /** @@ -47,7 +47,7 @@ public interface ICommandLineParser { * @param defaultOption the option to store arguments without identifier * @param args the command line arguments */ - default Arguments parseArgs(Options options, StringArrayOption defaultOption, String[] args) throws CommandLineParseException { + default Arguments parseArgs(Options options, Option defaultOption, String[] args) throws CommandLineParseException { return parseArgs(options, defaultOption, Arrays.asList(args)); } } diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/IHelpFormatter.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/IHelpFormatter.java index ac6a5f791..7a8e42bdb 100644 --- a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/IHelpFormatter.java +++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/cli/IHelpFormatter.java @@ -15,8 +15,8 @@ package org.eclipse.etrice.generator.base.cli; +import org.eclipse.etrice.generator.base.args.Option; import org.eclipse.etrice.generator.base.args.Options; -import org.eclipse.etrice.generator.base.args.StringArrayOption; import com.google.inject.ImplementedBy; @@ -34,6 +34,6 @@ public interface IHelpFormatter { * @param defaultOption the option for arguments without option identifier * @return the help message */ - String getHelp(String name, Options options, StringArrayOption defaultOption); + String getHelp(String name, Options options, Option defaultOption); } diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorApplicationOptions.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorApplicationOptions.java index 31e1f0882..4ebb88e0e 100644 --- a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorApplicationOptions.java +++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/setup/GeneratorApplicationOptions.java @@ -21,7 +21,7 @@ import org.eclipse.etrice.generator.base.args.BooleanOption; import org.eclipse.etrice.generator.base.args.EnumOption; import org.eclipse.etrice.generator.base.args.IOptionModule; import org.eclipse.etrice.generator.base.args.Option; -import org.eclipse.etrice.generator.base.args.StringArrayOption; +import org.eclipse.etrice.generator.base.args.PathOption; import org.eclipse.etrice.generator.base.args.StringOption; import org.eclipse.etrice.generator.base.logging.Loglevel; @@ -32,18 +32,19 @@ public class GeneratorApplicationOptions implements IOptionModule { public static final String GROUP_APPLICATION = "application"; - public static final StringArrayOption FILES = new StringArrayOption( + public static final Option FILES = new Option( + String[].class, GROUP_APPLICATION, "files", "input files", "input files for the generator", new String[0]); - public static final StringArrayOption MODELPATH = new StringArrayOption( + public static final PathOption MODELPATH = new PathOption( GROUP_APPLICATION, "modelpath", "paths", - "model imported paths separated by ';'", + "model import paths separated by path separators", new String[0]); public static final BooleanOption HELP = new BooleanOption( -- cgit v1.2.3