[DEV] continue rework

This commit is contained in:
Edouard DUPIN 2021-06-18 18:32:16 +02:00
parent 1bb1c4638e
commit 5a05e0eb77
6 changed files with 517 additions and 310 deletions

View File

@ -11,14 +11,8 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>

View File

@ -13,15 +13,15 @@ import org.atriasoft.island.model.ActionInterface;
public class Actions {
private static Map<String, Class<ActionInterface>> actions = new HashMap<String,Class<ActionInterface>>();
public static void addAction(String name, Class<ActionInterface> klass) {
actions.put(name, klass);
public static void addAction(final String name, final Class<ActionInterface> klass) {
Actions.actions.put(name, klass);
}
/**
* Get the wall list of action availlable
* @return The list of action name
*/
public static Set<String> getListOfAction() {
return actions.keySet();
return Actions.actions.keySet();
}
@ -51,8 +51,8 @@ public class Actions {
* @return The first line of description
* @throws ActionException
*/
private String getFullActionHelp(String action_name) throws ActionException {
Class<ActionInterface> actionClass = actions.get(action_name);
private String getFullActionHelp(final String action_name) throws ActionException {
Class<ActionInterface> actionClass = Actions.actions.get(action_name);
if (actionClass == null) {
throw new ActionException("Action does not registered");
}
@ -68,8 +68,8 @@ public class Actions {
return action.help();
}
private String getActionHelpExample(String action_name) throws ActionException {
Class<ActionInterface> actionClass = actions.get(action_name);
private String getActionHelpExample(final String action_name) throws ActionException {
Class<ActionInterface> actionClass = Actions.actions.get(action_name);
if (actionClass == null) {
throw new ActionException("Action does not registered");
}
@ -91,11 +91,11 @@ public class Actions {
* @return The first line of description
* @throws ActionException
*/
public String getActionHelp(String action_name) throws ActionException {
public String getActionHelp(final String action_name) throws ActionException {
return getFullActionHelp(action_name).split("\n")[0];
}
public void usage(String action_name, Arguments arguments) throws ActionException {
public void usage(final String action_name, final Arguments arguments) throws ActionException {
String help = getFullActionHelp(action_name);
Log.print("Description:");
Log.print("\t" + help);
@ -110,8 +110,8 @@ public class Actions {
System.exit(0);
}
public void execute(String action_name, List<String> arguments) throws ActionException {
Class<ActionInterface> actionClass = actions.get(action_name);
public void execute(final String action_name, final List<String> arguments) throws ActionException {
Class<ActionInterface> actionClass = Actions.actions.get(action_name);
if (actionClass == null) {
throw new ActionException("Action does not registered");
}

View File

@ -17,7 +17,7 @@ import java.nio.file.Paths;
import org.atriasoft.island.internal.Log;
public class Env {
private Env() {}
public static final int ret_manifest_is_not_existing = -5;
public static final int ret_action_is_not_existing = -10;
public static final int ret_action_executing_system_error = -11;
@ -29,51 +29,51 @@ public class Env {
public static String system_base_name = "island";
public static void set_system_base_name(String val) {
system_base_name = val;
public static void set_system_base_name(final String val) {
Env.system_base_name = val;
}
public static String get_system_base_name() {
return system_base_name;
return Env.system_base_name;
}
public static String get_system_config_name() {
return "." + system_base_name + "Config.json";
return "." + Env.system_base_name + "Config.json";
}
private static boolean fetch_manifest = true;
public static void set_fetch_manifest(boolean val) {
fetch_manifest = val;
public static void set_fetch_manifest(final boolean val) {
Env.fetch_manifest = val;
}
public static boolean get_fetch_manifest() {
return fetch_manifest;
return Env.fetch_manifest;
}
private static int wait_between_sever_command = 0;
public static void set_wait_between_sever_command(int val) {
wait_between_sever_command = val;
public static void set_wait_between_sever_command(final int val) {
Env.wait_between_sever_command = val;
}
public static int get_wait_between_sever_command() {
return wait_between_sever_command;
return Env.wait_between_sever_command;
}
public static String filter_command = "";
public static void set_filter_command(String val) {
filter_command = val;
public static void set_filter_command(final String val) {
Env.filter_command = val;
}
public static String get_filter_command() {
return filter_command;
return Env.filter_command;
}
public static boolean need_process_with_filter(String data) {
if (filter_command.equals("")) {
public static boolean need_process_with_filter(final String data) {
if (Env.filter_command.equals("")) {
return true;
}
if (data.length() < filter_command.length()) {
if (data.length() < Env.filter_command.length()) {
return false;
}
if (data.substring(0,filter_command.length()).equals(filter_command)) {
if (data.substring(0,Env.filter_command.length()).equals(Env.filter_command)) {
return true;
}
return false;
@ -81,11 +81,11 @@ public class Env {
private static boolean display_folder_instead_of_git_name = true;
public static void set_display_folder_instead_of_git_name(boolean val) {
display_folder_instead_of_git_name = val;
public static void set_display_folder_instead_of_git_name(final boolean val) {
Env.display_folder_instead_of_git_name = val;
}
public static boolean get_display_folder_instead_of_git_name() {
return display_folder_instead_of_git_name;
return Env.display_folder_instead_of_git_name;
}
private static Path island_root_path = null;
@ -98,47 +98,47 @@ public class Env {
static {
//String tmp = island_root_path.toAbsolutePath().toString();
//Log.info("Current absolute path is: " + tmp);
island_root_path = Paths.get("");
Path tmpPath = island_root_path;
while (!Files.isDirectory(tmpPath.resolve("." + get_system_base_name()))) {
Env.island_root_path = Paths.get("");
Path tmpPath = Env.island_root_path;
while (!Files.isDirectory(tmpPath.resolve("." + Env.get_system_base_name()))) {
tmpPath = tmpPath.getParent();
if (tmpPath == null) {
Log.critical("the root path of " + get_system_base_name() + " must not be upper parent paths of (" + island_root_path.toAbsolutePath() + ")");
Log.critical("the root path of " + Env.get_system_base_name() + " must not be upper parent paths of (" + Env.island_root_path.toAbsolutePath() + ")");
}
}
island_root_path = tmpPath;
island_path_user_config = island_root_path.resolve(get_system_config_name());
island_path = island_root_path.resolve("." + get_system_base_name());
island_path_config = island_path.resolve("config.xml");
island_path_manifest = island_path.resolve("manifest");
Env.island_root_path = tmpPath;
Env.island_path_user_config = Env.island_root_path.resolve(Env.get_system_config_name());
Env.island_path = Env.island_root_path.resolve("." + Env.get_system_base_name());
Env.island_path_config = Env.island_path.resolve("config.xml");
Env.island_path_manifest = Env.island_path.resolve("manifest");
}
/**
* To use later to know where the ".island" parent path is ...
* @return the parent path of the ".island"
*/
public static Path get_island_root_path() {
return island_root_path;
return Env.island_root_path;
}
public static Path get_island_path() {
return island_path;
return Env.island_path;
}
public static Path get_island_path_config() {
return island_path_config;
return Env.island_path_config;
}
public static Path get_island_path_manifest() {
return island_path_manifest;
return Env.island_path_manifest;
}
public static Path get_island_path_user_config() {
return island_path_user_config;
return Env.island_path_user_config;
}
public static void main(String[] args) {
Log.error("island_root_path = " + island_root_path.toAbsolutePath());
Log.error("island_path_user_config = " + island_path_user_config.toAbsolutePath());
Log.error("island_path = " + island_path.toAbsolutePath());
Log.error("island_path_config = " + island_path_config.toAbsolutePath());
Log.error("island_path_manifest = " + island_path_manifest.toAbsolutePath());
public static void main(final String[] args) {
Log.error("island_root_path = " + Env.island_root_path.toAbsolutePath());
Log.error("island_path_user_config = " + Env.island_path_user_config.toAbsolutePath());
Log.error("island_path = " + Env.island_path.toAbsolutePath());
Log.error("island_path_config = " + Env.island_path_config.toAbsolutePath());
Log.error("island_path_manifest = " + Env.island_path_manifest.toAbsolutePath());
}

View File

@ -1,33 +1,198 @@
package org.atriasoft.island;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.atriasoft.exml.Exml;
import org.atriasoft.exml.exception.ExmlBuilderException;
import org.atriasoft.exml.exception.ExmlParserErrorMulti;
import org.atriasoft.exml.model.XmlAttribute;
import org.atriasoft.exml.model.XmlElement;
import org.atriasoft.exml.model.XmlNode;
import org.atriasoft.exml.model.XmlNodeType;
import org.atriasoft.exml.parser.ParseXml;
import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.Link;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.RemoteListCommand;
class RepositoryCongig {
String remote = "origin";
String revision = "master";
boolean sync = false;
private String remote = "origin";
private String revision = "master";
private boolean sync = false;
public RepositoryCongig(final String remote, final String revision, final boolean sync) {
this.remote = remote;
this.revision = revision;
this.sync = sync;
}
public RepositoryCongig() {
}
public String getRemote() {
return this.remote;
}
public void setRemote(final String remote) {
this.remote = remote;
}
public String getRevision() {
return this.revision;
}
public void setRevision(final String revision) {
this.revision = revision;
}
public boolean isSync() {
return this.sync;
}
public void setSync(final boolean sync) {
this.sync = sync;
}
@Override
protected RepositoryCongig clone() {
// TODO Auto-generated method stub
return new RepositoryCongig(this.remote, this.revision, this.sync);
}
}
record MirrorConfig(String name, String fetch) {
class MirrorConfig {
private String name;
private String fetch;
public MirrorConfig(final String name, final String fetch) {
this.name = name;
this.fetch = fetch;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
public String getFetch() {
return this.fetch;
}
public void setFetch(final String fetch) {
this.fetch = fetch;
}
}
record RemoteConfig(String name, String fetch, List<MirrorConfig> mirror) {
class RemoteConfig {
private String name;
private String fetch;
List<MirrorConfig> mirror;
public RemoteConfig(final String name, final String fetch, final List<MirrorConfig> mirror) {
this.name = name;
this.fetch = fetch;
this.mirror = mirror;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
public String getFetch() {
return this.fetch;
}
public void setFetch(final String fetch) {
this.fetch = fetch;
}
public List<MirrorConfig> getMirror() {
return this.mirror;
}
public void setMirror(final List<MirrorConfig> mirror) {
this.mirror = mirror;
}
@Override
protected RemoteConfig clone() {
// TODO Auto-generated method stub
return new RemoteConfig(this.name, this.fetch, new ArrayList<>(this.mirror));
}
}
record IncludeConfig(String name, String path, Object manifest) {
class IncludeConfig {
private String name;
private Path path;
private Manifest manifest;
public IncludeConfig(final String name, final Path path, final Manifest manifest) {
this.name = name;
this.path = path;
this.manifest = manifest;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
public Path getPath() {
return this.path;
}
public void setPath(final Path path) {
this.path = path;
}
public Manifest getManifest() {
return this.manifest;
}
public void setManifest(final Manifest manifest) {
this.manifest = manifest;
}
}
class ProjectConfig {
private String name;
private String path;
private String tag;
private List<RemoteConfig> remotes = new ArrayList<>();
RemoteConfig selectRemotes = null;
public ProjectConfig(final String name, final String path, final String tag) {
this.name = name;
this.path = path;
this.tag = tag;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
public String getPath() {
return this.path;
}
public void setPath(final String path) {
this.path = path;
}
public String getTag() {
return this.tag;
}
public void setTag(final String tag) {
this.tag = tag;
}
public void setBranch(final String tag) {
this.tag = tag;
}
public List<RemoteConfig> getRemotes() {
return this.remotes;
}
public void setRemotes(final List<RemoteConfig> remotes) {
this.remotes = remotes;
}
public RemoteConfig getSelectRemotes() {
return this.selectRemotes;
}
public void setSelectRemotes(final RemoteConfig selectRemotes) {
this.selectRemotes = selectRemotes;
}
}
public class Manifest {
@ -48,7 +213,7 @@ public class Manifest {
}
public static void checkIsInit() {
// check if .XXX exist (create it if needed)
if (!isInit()) {
if (!Manifest.isInit()) {
Log.error("System not init: missing config: '" + Env.get_island_path() + "'. Call <island init> first");
System.exit(-1);
}
@ -57,34 +222,40 @@ public class Manifest {
private String deliver_master = "master";
private String deliver_develop = "develop";
private String deliver_mode = "merge";
private Path manifestXml;
private final Path manifestXml;
List<Object> projects = new ArrayList<>();
List<ProjectConfig> projects = new ArrayList<>();
RepositoryCongig defaultWhat = null;
RepositoryCongig default_base = new RepositoryCongig();
List<RemoteConfig> remotes = new ArrayList<>();
List<IncludeConfig> includes = new ArrayList<>();
List<Object> links = new ArrayList<>();
public Manifest(Path manifest_xml) {
manifestXml = manifest_xml;
List<Link> links = new ArrayList<>();
public Manifest(final Path manifestXml) throws IOException {
this.manifestXml = manifestXml;
// load the manifest
load();
try {
load();
} catch (ExmlBuilderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// check error in manifest (double path ...)
// TODO checkDoublePath();
}
public List<Object> getLinks() {
public List<Link> getLinks() {
return this.links;
}
String removeEndSlash(String value) {
while (value.length() > 1
&& ( value.charAt(value.length()-1) == '\\'
|| value.charAt(value.length()-1) == '/')) {
|| value.charAt(value.length()-1) == '/') ) {
value = value.substring(0, value.length()-1);
}
return value;
}
public void load() {
public void load() throws ExmlParserErrorMulti, ExmlBuilderException, IOException {
XmlElement rootNode = Exml.parse(this.manifestXml);
Log.debug("manifest : '" + this.manifestXml + "'");
if (!rootNode.getValue().equals("manifest")) {
@ -137,14 +308,14 @@ public class Manifest {
}
fetch = removeEndSlash(fetch);
} else {
Log.error("Parsing the manifest : Unknow '" + child.getName() + "' attibute : '" + attr.getName() + "', availlable:[name,fetch]")
Log.error("Parsing the manifest : Unknow '" + child.getValue() + "' attibute : '" + attr.getName() + "', availlable:[name,fetch]");
}
}
Log.debug(" find '" + child.getName() + "' : name='" + name + "' fetch='" + fetch + "'");
Log.debug(" find '" + child.getValue() + "' : name='" + name + "' fetch='" + fetch + "'");
// parse the sub global mirror list
List<MirrorConfig> mirror_list = new ArrayList<>();
for (XmlNode child_2 : child.toElement().getNodes()) {
if (child_2.getValue().equals("mirror")):
if (child_2.getValue().equals("mirror")) {
// find a new mirror
String mirror_name = "";
String mirror_fetch = "";
@ -167,147 +338,156 @@ public class Manifest {
}
mirror_list.add(new MirrorConfig(mirror_name, mirror_fetch));
} else {
Log.critical("Parsing the manifest : Unknow '" + child_2.getName() + "', availlable:[mirror]");
Log.critical("Parsing the manifest : Unknow '" + child_2.getValue() + "', availlable:[mirror]");
}
}
this.remotes.add(new RemoteConfig(name, fetch, mirror_list));
continue;
}
if (child.getName().equals("include") {
}
if (child.getValue().equals("include")) {
String name = "";
for (XmlAttribute attr : child.toElement.getAttributes()) {
for (XmlAttribute attr : child.toElement().getAttributes()) {
if (attr.getName().equals("name")) {
name = attr.getValue();
} else {
Log.error("Parsing the manifest : Unknow '" + child.getName() + "' attibute : '" + attr + "', availlable:[name]")
Log.error("Parsing the manifest : Unknow '" + child.getValue() + "' attibute : '" + attr + "', availlable:[name]");
}
}
Log.debug(" find '" + child.getName() + "' : name='" + name + "'");
Log.debug(" find '" + child.getValue() + "' : name='" + name + "'");
// check if the file exist ...
Path new_name_xml = this.manifest_xml.resolve(name);
Path new_name_xml = this.manifestXml.resolve(name);
if (!Files.exists(new_name_xml)) {
Log.critical("The file does not exist: " + new_name_xml)
Log.critical("The file does not exist: " + new_name_xml);
}
this.includes.add(new IncludeConfig(name, new_name_xml, null));
continue;
}
if (child.getName().equals("default") {
if (child.getValue().equals("default")) {
String remote = "origin";
String revision = "master";
boolean sync = false;
for (XmlAttribute attr : child.toElement.getAttributes()) {
for (XmlAttribute attr : child.toElement().getAttributes()) {
if (attr.getName().equals("remote")) {
remote = attr.getValue();
} else if (attr.getName().equals("revision")) {
revision = attr.getValue();
} else if (attr.getName().equals("sync-s")) { // synchronize submodule ... automaticaly
sync = attr.getValue();
if (sync.lower().equals("true")
|| sync.equals("1")
|| sync.lower().equals("yes")) {
String syncBase = attr.getValue();
if (syncBase.equalsIgnoreCase("true")
|| syncBase.equals("1")
|| syncBase.toLowerCase().equals("yes")) {
sync = true;
} else if (sync.lower().equals("false")
|| sync.equals("0")
|| sync.lower().equals("no")) {
sync = false
} else {
Log.critical("Parsing the manifest : Unknow '" + child.getName() + "' attibute : '" + attr + "', value:'" + sync + "' availlable:[true,1,yes,false,0,no]");
} else if (syncBase.equalsIgnoreCase("false")
|| syncBase.equals("0")
|| syncBase.equalsIgnoreCase("no")) {
sync = false;
} else {
Log.critical("Parsing the manifest : Unknow '" + child.getValue() + "' attibute : '" + attr + "', value:'" + sync + "' availlable:[true,1,yes,false,0,no]");
}
} else {
Log.error("Parsing the manifest : Unknow '" + child.getName() + "' attibute : '" + attr + "', availlable:[remote,revision,sync-s]");
} else {
Log.error("Parsing the manifest : Unknow '" + child.getValue() + "' attibute : '" + attr + "', availlable:[remote,revision,sync-s]");
}
}
if (this.defaultWhat != null) {
Log.error("Parsing the manifest : Node '" + child.getName() + "' already set")
Log.error("Parsing the manifest : Node '" + child.getValue() + "' already set");
}
this.defaultWhat = new RepositoryCongig(remote, revision, sync));
Log.debug(" find '" + child.getName() + "' : remote='" + remote + "' revision='" + revision + "' sync=" + sync);
this.defaultWhat = new RepositoryCongig(remote, revision, sync);
Log.debug(" find '" + child.getValue() + "' : remote='" + remote + "' revision='" + revision + "' sync=" + sync);
continue;
}
if child.tag == "project":
name = ""
path = ""
tag_sha1 = None
for attr in child.attrib:
if attr == "name":
name = child.attrib[attr]
} else if attr == "path":
path = child.attrib[attr]
} else if attr == "tag":
tag_sha1 = child.attrib[attr]
else:
Log.error("(l:" + str(child.sourceline) + ") Parsing the manifest: Unknow '" + child.tag + "' attibute : '" + attr + "', availlable:[name,tag,sync-s]")
if name == "":
Log.error("(l:" + str(child.sourceline) + ") Parsing the manifest: '" + child.tag + "' missing attribute: 'name' ==> specify the git to clone ...")
this.projects.append({
"name":name,
"path":path,
"tag":tag_sha1,
})
Log.debug("(l:" + str(child.sourceline) + ") find '" + child.tag + "' : name='" + name + "' path='" + path + "' tag='" + str(tag_sha1) + "'");
continue
if child.tag == "option":
if (child.getValue().equals("project")) {
String name = "";
String path = "";
String tag_sha1 = null;
for (XmlAttribute attr : child.toElement().getAttributes()) {
if (attr.getName().equals("name")) {
name = attr.getValue();
} else if (attr.getName().equals("path")) {
path = attr.getValue();
} else if (attr.getName().equals("tag")) {
tag_sha1 = attr.getValue();
} else {
Log.error("Parsing the manifest: Unknow '" + child.getValue() + "' attibute : '" + attr + "', availlable:[name,tag,sync-s]");
}
}
if (name.isEmpty()) {
Log.error("Parsing the manifest: '" + child.getValue() + "' missing attribute: 'name' ==> specify the git to clone ...");
}
this.projects.add(new ProjectConfig(name, path, tag_sha1));
Log.debug(" find '" + child.getValue() + "' : name='" + name + "' path='" + path + "' tag='" + tag_sha1 + "'");
continue;
}
if (child.getValue().equals("option")) {
// not managed ==> future use
type_option = ""
value_option = ""
for attr in child.attrib:
if attr == "type":
type_option = child.attrib[attr]
} else if attr == "value":
value_option = child.attrib[attr]
else:
Log.error("(l:" + str(child.sourceline) + ") Parsing the manifest: Unknow '" + child.tag + "' attibute : '" + attr + "', availlable:[type,value]")
if type_option == "deliver_master":
this.deliver_master = value_option
} else if type_option == "deliver_develop":
this.deliver_develop = value_option
} else if type_option == "deliver_mode":
this.deliver_mode = value_option
if this.deliver_mode not in ["merge","fast_forward"]:
Log.error("(l:" + str(child.sourceline) + ") Parsing the manifest: option 'deliver_mode' value availlable: [merge,fast_forward]")
else:
Log.error("(l:" + str(child.sourceline) + ") Parsing the manifest: Unknow 'type' value availlable: [deliver_master,deliver_develop,deliver_mode]")
continue
if child.tag == "link":
String type_option = "";
String value_option = "";
for (XmlAttribute attr : child.toElement().getAttributes()) {
if (attr.getName().equals("type")) {
type_option = attr.getValue();
} else if (attr.getName().equals("value")) {
value_option = attr.getValue();
} else {
Log.error("Parsing the manifest: Unknow '" + child.getValue() + "' attibute : '" + attr + "', availlable:[type,value]");
}
}
if (type_option.equals("deliver_master")) {
this.deliver_master = value_option;
} else if (type_option.equals("deliver_develop")) {
this.deliver_develop = value_option;
} else if (type_option.equals("deliver_mode")) {
this.deliver_mode = value_option;
if (this.deliver_mode.equals("merge") || this.deliver_mode.equals("fast_forward")) {
Log.critical("Parsing the manifest: option 'deliver_mode' value availlable: [merge,fast_forward]");
}
} else {
Log.critical("Parsing the manifest: Unknow 'type' value availlable: [deliver_master,deliver_develop,deliver_mode]");
}
continue;
}
if (child.getValue().equals("link")) {
// not managed ==> future use
source = ""
destination = ""
for attr in child.attrib:
if attr == "source":
source = child.attrib[attr]
} else if attr == "destination":
destination = child.attrib[attr]
else:
Log.error("(l:" + str(child.sourceline) + ") Parsing the manifest: Unknow '" + child.tag + "' attibute : '" + attr + "', availlable:[source,destination]")
if source == "":
Log.error("(l:" + str(child.sourceline) + ") Parsing the manifest: '" + child.tag + "' missing attribute: 'source' ==> specify the git to clone ...")
if destination == "":
Log.error("(l:" + str(child.sourceline) + ") Parsing the manifest: '" + child.tag + "' missing attribute: 'destination' ==> specify the git to clone ...")
this.links.append({
"source":source,
"destination":destination,
})
Log.debug("Add link: '" + str(destination) + "' ==> '" + str(source) + "'")
continue
Log.info("(l:" + str(child.sourceline) + ") '" + str(child.tag) + "' values=" + str(child.attrib));
Log.error("(l:" + str(child.sourceline) + ") Parsing error Unknow NODE : '" + str(child.tag) + "' availlable:[remote,include,default,project,option,link]")
String source = "";
String destination = "";
for (XmlAttribute attr : child.toElement().getAttributes()) {
if (attr.getName().equals("source")) {
source = attr.getValue();
} else if (attr.getName().equals("destination")) {
destination = attr.getValue();
} else {
Log.critical("Parsing the manifest: Unknow '" + child.getValue() + "' attibute : '" + attr + "', availlable:[source,destination]");
}
}
if (source.isEmpty()) {
Log.error("Parsing the manifest: '" + child.getValue() + "' missing attribute: 'source' ==> specify the git to clone ...");
}
if (destination.isEmpty()) {
Log.error("Parsing the manifest: '" + child.getValue() + "' missing attribute: 'destination' ==> specify the git to clone ...");
}
this.links.add(new Link(source, destination));
Log.debug("Add link: '" + destination + "' ==> '" + source + "'");
continue;
}
Log.info(" '" + child.getValue() + "' values=" + child.toElement().getAttributes());
Log.error("Parsing error Unknow NODE : '" + child.getValue() + "' availlable:[remote,include,default,project,option,link]");
}
// now we parse all sub repo:
for elem in this.includes:
elem["manifest"] = Manifest(elem["path"])
// inside data child.text
for (IncludeConfig elem : this.includes) {
elem.setManifest(new Manifest(elem.getPath()));
}
}
// public void _create_path_with_elem(this, element):
// path = element["path"]
// if path == "":
// path = element["name"]
// if len(path) >= 4 \
// and path[-4:] == ".git":
// path = path[:-4]
// return path
//
// public void checkDoublePath(this, list_path = [], space=""):
public String createPathWithElem(final ProjectConfig element) {
String path = element.getPath();
if (path.isEmpty()) {
path = element.getName();
if (path.endsWith(".git")) {
path = path.substring(0, path.length()-4);
}
}
return path;
}
// public void checkDoublePath(this, list_path = [], space="") {
// Log.debug(space + "check path : '" + this.manifest_xml + "'")
// for elem in this.projects:
// path = this._create_path_with_elem(elem)
@ -317,107 +497,126 @@ public class Manifest {
// list_path.append(path)
// for elem in this.includes:
// elem["manifest"]._check_double_path(list_path, space + " ")
//
// public void get_all_configs(this, default=None, upper_remotes=[]):
// out = []
// if default == None:
// if this.default != None:
// default = copy.deepcopy(this.default)
// else:
// default = copy.deepcopy(this.default_base)
// // Log.error(" this.default=" + str(this.default))
// // add all local project
// for elem in this.projects:
// Log.verbose("parse element " + str(elem))
// if Env.need_process_with_filter(elem["name"]) == false:
// Log.info("Filter repository: " + str(elem["name"]))
// continue
// conf = repo_config.RepoConfig()
// conf.name = elem["name"]
// conf.tag = elem["tag"]
// conf.path = this._create_path_with_elem(elem)
//
// // add default remote for the project (search in herited element)
// for remote in this.remotes:
// Log.verbose(" Local Remote: " + str(remote))
// if remote["name"] == default["remote"]:
// conf.remotes.append(remote)
// if len(conf.remotes) == 0:
// for remote in upper_remotes:
// Log.verbose(" upper Remote: " + str(remote))
// if remote["name"] == default["remote"]:
// conf.remotes.append(remote)
// if len(conf.remotes) == 0:
// Log.error(" No remote detected: " + str(len(conf.remotes)) + " for " + conf.name + " with default remote name : " + default["remote"] + " this remote: " + str(this.remotes))
//
// // select default remote:
// conf.select_remote = None
// Log.debug(" remotes count: " + str(len(conf.remotes)))
// for remote in conf.remotes:
// Log.debug(" remote=" + str(remote))
// Log.debug(" Ckeck remote : " + remote["name"] + " == " + default["remote"])
// Log.verbose(" remote=" + str(remote))
// Log.verbose(" default=" + str(default))
// if remote["name"] == default["remote"]:
// conf.select_remote = copy.deepcopy(remote)
// Log.debug(" copy select=" + str(conf.select_remote))
//
// // copy the submodule synchronisation
// conf.select_remote["sync"] = default["sync"]
// break
// if conf.select_remote == None:
// Log.error("missing remote for project: " + str(conf.name))
//
// conf.branch = default["revision"]
// out.append(conf)
// // create a temporary variable to transmit the remote to includes
// upper_remotes_forward = copy.deepcopy(upper_remotes)
// for remote in this.remotes:
// upper_remotes_forward.append(remote)
// // add all include project
// for elem in this.includes:
// list_project = elem["manifest"].get_all_configs(default, upper_remotes_forward)
// for elem_proj in list_project:
// out.append(elem_proj)
//
// //# -------------------------------------------------------------
// //# -- add Volatile ...
// //# -------------------------------------------------------------
// Log.verbose("include volatile config")
// // TODO: maybe find a better way to do this...
// conf_global = config.get_unique_config()
// for elem in conf_global.get_volatile():
// conf = repo_config.RepoConfig()
// base_volatile, repo_volatile = repo_config.split_repo(elem["git_address"])
// conf.name = repo_volatile
// conf.path = elem["path"]
// conf.branch = "master"
// conf.volatile = true
// conf.remotes = [
// {
// 'name': 'origin',
// 'fetch': base_volatile,
// 'mirror': []
// }
// ]
// conf.select_remote = {
// 'name': 'origin',
// 'fetch': base_volatile,
// 'sync': false,
// 'mirror': []
// }
// out.append(conf)
// //# -------------------------------------------------------------
// if false:
// Log.info("list of all repo:")
// for elem in out:
// Log.info(" '" + elem.name + "'")
// Log.info(" path: " + elem.path)
// Log.info(" remotes: " + str(elem.remotes))
// Log.info(" select_remote: " + str(elem.select_remote))
// Log.info(" branch: " + elem.branch)
// return out
//
// }
public List<ProjectConfig> get_all_configs() {
return get_all_configs(null, new ArrayList<>());
}
public List<ProjectConfig> get_all_configs(RepositoryCongig defaultPlouf, final List<RemoteConfig> upper_remotes) {
List<ProjectConfig> out = new ArrayList<>();
if (defaultPlouf == null) {
if (this.defaultWhat != null) {
defaultPlouf = this.defaultWhat.clone();
} else {
defaultPlouf = this.default_base.clone();
}
}
// Log.error(" this.default=" + str(this.default))
// add all local project
for (ProjectConfig elem : this.projects) {
Log.verbose("parse element " + elem);
if (!Env.need_process_with_filter(elem.getName())) {
Log.info("Filter repository: " + elem.getName());
continue;
}
ProjectConfig conf = new ProjectConfig(elem.getName(), createPathWithElem(elem), elem.getTag());
// add default remote for the project (search in herited element)
for (RemoteConfig remote : this.remotes) {
Log.verbose(" Local Remote: " + remote);
if (remote.getName().equals(defaultPlouf.getRemote())) {
conf.getRemotes().add(remote);
}
}
if (conf.getRemotes().size() == 0) {
for (RemoteConfig remote : upper_remotes) {
Log.verbose(" upper Remote: " + remote);
if (remote.getName().equals(defaultPlouf.getRemote())) {
conf.getRemotes().add(remote);
}
}
}
if (conf.getRemotes().size() == 0) {
Log.error(" No remote detected: " + conf.getRemotes().size() + " for " + conf.getName() + " with default remote name : " + defaultPlouf.getRemote() + " this remote: " + this.remotes);
}
// select default remote:
Log.debug(" remotes count: " + conf.getRemotes().size());
for (RemoteConfig remote : conf.getRemotes()) {
Log.debug(" remote=" + remote);
Log.debug(" Ckeck remote : " + remote.getName() + " == " + defaultPlouf.getRemote());
Log.verbose(" remote=" + remote);
Log.verbose(" default=" + defaultPlouf);
if (remote.getName().equals(defaultPlouf.getRemote())) {
conf.setSelectRemotes(remote.clone());
Log.debug(" copy select=" + conf.getSelectRemotes());
// copy the submodule synchronisation
// TODO: ????? conf.getSelectRemotes().setSync(defaultPlouf.isSync());
break;
}
}
if (conf.getSelectRemotes() == null) {
Log.error("missing remote for project: " + conf.getName());
}
conf.setBranch(defaultPlouf.getRevision());
out.add(conf);
}
// create a temporary variable to transmit the remote to includes
List<RemoteConfig> upper_remotes_forward = new ArrayList<>(upper_remotes);
for (RemoteConfig remote : this.remotes) {
upper_remotes_forward.add(remote);
}
// add all include project
for (IncludeConfig elem : this.includes) {
List<ProjectConfig> list_project = elem.getManifest().get_all_configs(defaultPlouf, upper_remotes_forward);
for (ProjectConfig elem_proj : list_project) {
out.add(elem_proj);
}
}
// DEPRECIATE volatile for a while?.????
//# -------------------------------------------------------------
//# -- add Volatile ...
//# -------------------------------------------------------------
Log.verbose("include volatile config");
// TODO: maybe find a better way to do this...
/*
conf_global = config.get_unique_config()
for elem in conf_global.get_volatile():
conf = repo_config.RepoConfig()
base_volatile, repo_volatile = repo_config.split_repo(elem["git_address"])
conf.name = repo_volatile
conf.path = elem["path"]
conf.branch = "master"
conf.volatile = true
conf.remotes = [
{
'name': 'origin',
'fetch': base_volatile,
'mirror': []
}
]
conf.select_remote = {
'name': 'origin',
'fetch': base_volatile,
'sync': false,
'mirror': []
}
out.append(conf)
//# -------------------------------------------------------------
if false:
Log.info("list of all repo:")
for elem in out:
Log.info(" '" + elem.name + "'")
Log.info(" path: " + elem.path)
Log.info(" remotes: " + str(elem.remotes))
Log.info(" select_remote: " + str(elem.select_remote))
Log.info(" branch: " + elem.branch)
*/
return out;
}
//
//public void tag_manifest(manifest_xml_filename, all_tags):
// tree = etree.parse(manifest_xml_filename)
@ -533,4 +732,6 @@ public class Manifest {
// // now we parse all sub repo:
// for elem in includes:
// tag_clear(elem["path"])
//
//
}

View File

@ -21,35 +21,35 @@ public class ConfigManifest {
}
public String getRepo() {
return repo;
return this.repo;
}
public void setRepo(String repo) {
public void setRepo(final String repo) {
this.repo = repo;
}
public String getBranch() {
return branch;
return this.branch;
}
public void setBranch(String branch) {
public void setBranch(final String branch) {
this.branch = branch;
}
public String getManifestName() {
return manifestName;
return this.manifestName;
}
public void setManifestName(String manifestName) {
public void setManifestName(final String manifestName) {
this.manifestName = manifestName;
}
public List<Volatile> getVolatiles() {
return volatiles;
return this.volatiles;
}
public void setVolatiles(List<Volatile> volatiles) {
public void setVolatiles(final List<Volatile> volatiles) {
this.volatiles = volatiles;
}
public void addVolatile(String gitAddress, String path) {
public void addVolatile(final String gitAddress, final String path) {
rmVolatile(path);
this.volatiles.add(new Volatile(gitAddress, path));
}
private void rmVolatile(String path) {
ListIterator<Volatile> it = volatiles.listIterator();
private void rmVolatile(final String path) {
ListIterator<Volatile> it = this.volatiles.listIterator();
while (it.hasNext()) {
Volatile elem = it.next();
if (elem.path.equals(path)) {
@ -58,29 +58,29 @@ public class ConfigManifest {
}
}
public List<Link> getCurentLink() {
return curentLink;
return this.curentLink;
}
public void setCurentLink(List<Link> curentLink) {
public void setCurentLink(final List<Link> curentLink) {
this.curentLink = curentLink;
}
public void addLink(String source, String destination) {
public void addLink(final String source, final String destination) {
rmLink(destination);
this.curentLink.add(new Link(source, destination));
}
private void rmLink(String destination) {
ListIterator<Link> it = curentLink.listIterator();
private void rmLink(final String destination) {
ListIterator<Link> it = this.curentLink.listIterator();
while (it.hasNext()) {
Link elem = it.next();
if (elem.destination.equals(destination)) {
if (elem.getDestination().equals(destination)) {
it.remove();
}
}
}
public static ConfigManifest load() {
return load(Env.get_island_path_config());
return ConfigManifest.load(Env.get_island_path_config());
}
public static ConfigManifest load(Path path) {
public static ConfigManifest load(final Path path) {
ConfigManifest[] root = null;
try {
root = Exml.parse(path, ConfigManifest.class, "config-island");
@ -96,7 +96,7 @@ public class ConfigManifest {
public void store() {
store(Env.get_island_path_config());
}
public void store(Path path) {
public void store(final Path path) {
Log.todo("unimplemented model...");
}

View File

@ -1,9 +1,9 @@
package org.atriasoft.island.model;
class Link {
public String source;
public String destination;
public Link(String source, String destination) {
public class Link {
private String source;
private String destination;
public Link(final String source, final String destination) {
this.source = source;
this.destination = destination;
}
@ -11,5 +11,17 @@ class Link {
this.source = "";
this.destination = "";
}
public String getSource() {
return this.source;
}
public void setSource(final String source) {
this.source = source;
}
public String getDestination() {
return this.destination;
}
public void setDestination(final String destination) {
this.destination = destination;
}
}