11.08., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

Commit 709c683d authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

add project migration to vadere console

parent d84565f3
......@@ -197,6 +197,14 @@ public class VadereConsole {
.help("If PATH contains a directory instead of a scenario file recursively search " +
"the directory tree for scenario files and apply the command.");
migrationAssistant.addArgument("--consider-projects-only")
.required(false)
.dest("consider-projects-only")
.action(Arguments.storeTrue())
.setDefault(false)
.help("If set only directories containing a vadere project will be migrated. " +
"The migraion will use the legacy folder in the project.");
migrationAssistant.addArgument("--create-new-version")
.required(false)
.type(String.class)
......
......@@ -6,41 +6,57 @@ import net.sourceforge.argparse4j.inf.Namespace;
import org.apache.log4j.Logger;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.entrypoints.cmd.SubCommandRunner;
import org.vadere.simulator.projects.migration.JoltMigrationAssistant;
import org.vadere.simulator.projects.migration.MigrationAssistant;
import org.vadere.simulator.projects.migration.MigrationException;
import org.vadere.simulator.projects.migration.MigrationFactory;
import org.vadere.simulator.projects.migration.MigrationOptions;
import org.vadere.simulator.projects.migration.helper.MigrationUtil;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import static org.vadere.util.io.IOUtils.VADERE_PROJECT_FILENAME;
public class MigrationSubCommand implements SubCommandRunner {
private final static Logger logger = Logger.getLogger(MigrationSubCommand.class);
private String outputPathString;
private Version targetVersion;
private boolean revertMode;
private boolean recursive;
private boolean projectOnly;
private List<String> paths;
private String newVersion;
ArrayList<Path> files = new ArrayList<>();
ArrayList<Path> dirs = new ArrayList<>();
ArrayList<Path> err = new ArrayList<>();
@Override
public void run(Namespace ns, ArgumentParser parser) throws Exception {
String outputPathString = ns.getString("output-file");
Version targetVersion = Version.fromString(ns.getString("target-version"));
boolean revertMode = ns.getBoolean("revert-migration");
boolean recursive = ns.getBoolean("recursive");
List<String> paths = ns.getList("paths");
String newVersion = ns.getString("create-new-version");
outputPathString = ns.getString("output-file");
targetVersion = Version.fromString(ns.getString("target-version"));
revertMode = ns.getBoolean("revert-migration");
recursive = ns.getBoolean("recursive");
projectOnly = ns.getBoolean("consider-projects-only");
paths = ns.getList("paths");
newVersion = ns.getString("create-new-version");
ArrayList<Path> files = new ArrayList<>();
ArrayList<Path> dirs = new ArrayList<>();
ArrayList<Path> err = new ArrayList<>();
for (String path : paths) {
Path tmp = Paths.get(path);
if (tmp.toFile().exists()) {
if (tmp.toFile().isFile()) {
files.add(tmp);
} else if (tmp.toFile().isDirectory()) {
dirs.add(tmp);
testDirAndAdd(dirs, tmp);
} else {
err.add(tmp);
}
......@@ -78,12 +94,28 @@ public class MigrationSubCommand implements SubCommandRunner {
MigrationUtil migrationUtil = new MigrationUtil();
for (Path dir : dirs) {
logger.info("migrate directory to version(" + targetVersion.label() + "): " + dir.toAbsolutePath().toString());
migrationUtil.migrateDirectoryTree(dir, targetVersion, recursive);
if (projectOnly){
JoltMigrationAssistant migrationAssistant = new JoltMigrationAssistant();
migrationAssistant.analyzeProject(dir.toString());
} else {
migrationUtil.migrateDirectoryTree(dir, targetVersion, recursive);
}
}
}
}
private void testDirAndAdd(ArrayList<Path> dirs, Path dir){
if(projectOnly){
if (Files.exists(dir.resolve(VADERE_PROJECT_FILENAME))){
dirs.add(dir);
}
} else {
dirs.add(dir);
}
}
private void createNewTransformFiles(Path dest, String versionLabel) throws MigrationException {
MigrationUtil migrationUtil = new MigrationUtil();
try {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment