[DEV] new mode of parsing configs ==> based on introspections...

This commit is contained in:
Edouard DUPIN 2021-06-29 00:03:28 +02:00
parent 1351757c48
commit ea883353e1
17 changed files with 280 additions and 28 deletions

View File

@ -35,6 +35,16 @@
<attribute name="module" value="true"/> <attribute name="module" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="lib/slf4j-api-1.7.31.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/slf4j-simple-1.7.31.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5">
<attributes> <attributes>
<attribute name="test" value="true"/> <attribute name="test" value="true"/>

BIN
lib/log4j-1.2.17.jar Normal file

Binary file not shown.

BIN
lib/slf4j-api-1.7.31.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
lib/slf4j-simple-1.7.31.jar Normal file

Binary file not shown.

View File

@ -2,7 +2,7 @@ package org.atriasoft.island;
import java.nio.file.Path; import java.nio.file.Path;
class IncludeConfig { public class IncludeConfig {
private String name; private String name;
private Path path; private Path path;
private Manifest manifest; private Manifest manifest;

View File

@ -4,24 +4,19 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.atriasoft.exml.Exml; import org.atriasoft.exml.Exml;
import org.atriasoft.exml.exception.ExmlBuilderException; import org.atriasoft.exml.exception.ExmlBuilderException;
import org.atriasoft.exml.exception.ExmlParserErrorMulti; 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.island.internal.Log; import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.Link; import org.atriasoft.island.model.Link;
import org.atriasoft.island.model.MirrorConfig;
import org.atriasoft.island.model.ProjectConfig; import org.atriasoft.island.model.ProjectConfig;
import org.atriasoft.island.model.RemoteConfig; import org.atriasoft.island.model.RemoteConfig;
import org.atriasoft.island.model.RepositoryConfig; import org.atriasoft.island.model.RepositoryConfig;
import org.atriasoft.island.model.manifest.ManifestFile;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.RemoteListCommand;
public class Manifest { public class Manifest {
public static boolean isInit() { public static boolean isInit() {
@ -47,17 +42,29 @@ public class Manifest {
} }
} }
private String deliver_master = "master";
private String deliver_develop = "develop";
private String deliver_mode = "merge";
private final Path manifestXml; private final Path manifestXml;
private String rootManifest;
private final Map<String,ManifestFile> manifests = new HashMap<>();
@Deprecated
private final String deliver_master = "master";
@Deprecated
private final String deliver_develop = "develop";
@Deprecated
private final String deliver_mode = "merge";
@Deprecated
List<ProjectConfig> projects = new ArrayList<>(); List<ProjectConfig> projects = new ArrayList<>();
@Deprecated
RepositoryConfig defaultWhat = null; RepositoryConfig defaultWhat = null;
RepositoryConfig default_base = new RepositoryConfig(); @Deprecated
RepositoryConfig defaultBase = new RepositoryConfig();
@Deprecated
List<RemoteConfig> remotes = new ArrayList<>(); List<RemoteConfig> remotes = new ArrayList<>();
@Deprecated
List<IncludeConfig> includes = new ArrayList<>(); List<IncludeConfig> includes = new ArrayList<>();
@Deprecated
List<Link> links = new ArrayList<>(); List<Link> links = new ArrayList<>();
public Manifest(final Path manifestXml) throws IOException { public Manifest(final Path manifestXml) throws IOException {
this.manifestXml = manifestXml; this.manifestXml = manifestXml;
// load the manifest // load the manifest
@ -84,7 +91,22 @@ public class Manifest {
} }
public void load() throws ExmlParserErrorMulti, ExmlBuilderException, IOException { public void load() throws ExmlParserErrorMulti, ExmlBuilderException, IOException {
XmlElement rootNode = Exml.parse(this.manifestXml);
Path rootDirectory = this.manifestXml.toAbsolutePath();
this.rootManifest = rootDirectory.getFileName().toString();
rootDirectory = rootDirectory.getParent();
ManifestFile parsedElements = Exml.parseOne(this.manifestXml, ManifestFile.class, "manifest");
parsedElements.setFileRealPath(this.manifestXml);
this.manifests.put(this.rootManifest, parsedElements);
for (String includeElem : parsedElements.getIncludes()) {
Path maniPath = rootDirectory.resolve(includeElem);
ManifestFile tmpManifest = Exml.parseOne(maniPath, ManifestFile.class, "manifest");
tmpManifest.setFileRealPath(maniPath);
this.manifests.put(includeElem, tmpManifest);
}
/*
XmlElement rootNode = Exml.parse(this.manifestXml).getNodes().get(0).toElement();
Log.debug("manifest : '" + this.manifestXml + "'"); Log.debug("manifest : '" + this.manifestXml + "'");
if (!rootNode.getValue().equals("manifest")) { if (!rootNode.getValue().equals("manifest")) {
Log.error(" in '" + this.manifestXml + "' have not main xml node='manifest'"); Log.error(" in '" + this.manifestXml + "' have not main xml node='manifest'");
@ -258,17 +280,17 @@ public class Manifest {
Log.error("Parsing the manifest: Unknow '" + child.getValue() + "' attibute : '" + attr + "', availlable:[type,value]"); Log.error("Parsing the manifest: Unknow '" + child.getValue() + "' attibute : '" + attr + "', availlable:[type,value]");
} }
} }
if (type_option.equals("deliver_master")) { if (type_option.equals("deliver-master")) {
this.deliver_master = value_option; this.deliver_master = value_option;
} else if (type_option.equals("deliver_develop")) { } else if (type_option.equals("deliver-develop")) {
this.deliver_develop = value_option; this.deliver_develop = value_option;
} else if (type_option.equals("deliver_mode")) { } else if (type_option.equals("deliver-mode")) {
this.deliver_mode = value_option; this.deliver_mode = value_option;
if (this.deliver_mode.equals("merge") || this.deliver_mode.equals("fast_forward")) { 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]"); Log.critical("Parsing the manifest: option 'deliver-mode' value availlable: [merge,fast-forward]");
} }
} else { } else {
Log.critical("Parsing the manifest: Unknow 'type' value availlable: [deliver_master,deliver_develop,deliver_mode]"); Log.critical("Parsing the manifest: Unknow 'type' value availlable: [deliver-master,deliver-develop,deliver-mode]");
} }
continue; continue;
} }
@ -302,6 +324,7 @@ public class Manifest {
for (IncludeConfig elem : this.includes) { for (IncludeConfig elem : this.includes) {
elem.setManifest(new Manifest(elem.getPath())); elem.setManifest(new Manifest(elem.getPath()));
} }
*/
} }
@ -337,7 +360,7 @@ public class Manifest {
if (this.defaultWhat != null) { if (this.defaultWhat != null) {
defaultPlouf = this.defaultWhat.clone(); defaultPlouf = this.defaultWhat.clone();
} else { } else {
defaultPlouf = this.default_base.clone(); defaultPlouf = this.defaultBase.clone();
} }
} }
// Log.error(" this.default=" + str(this.default)) // Log.error(" this.default=" + str(this.default))

View File

@ -6,6 +6,8 @@ import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import org.atriasoft.exml.Exml; import org.atriasoft.exml.Exml;
import org.atriasoft.exml.annotation.XmlList;
import org.atriasoft.exml.annotation.XmlName;
import org.atriasoft.exml.exception.ExmlBuilderException; import org.atriasoft.exml.exception.ExmlBuilderException;
import org.atriasoft.island.Env; import org.atriasoft.island.Env;
import org.atriasoft.island.internal.Log; import org.atriasoft.island.internal.Log;
@ -15,7 +17,7 @@ public class ConfigManifest {
private String branch = "master"; private String branch = "master";
private String manifestName = "default.xml"; private String manifestName = "default.xml";
private List<Volatile> volatiles = new ArrayList<>(); private List<Volatile> volatiles = new ArrayList<>();
private List<Link> curentLink = new ArrayList<>(); private List<Link> links = new ArrayList<>();
public ConfigManifest() { public ConfigManifest() {
} }
@ -32,12 +34,14 @@ public class ConfigManifest {
public void setBranch(final String branch) { public void setBranch(final String branch) {
this.branch = branch; this.branch = branch;
} }
@XmlName(value="manifest-name")
public String getManifestName() { public String getManifestName() {
return this.manifestName; return this.manifestName;
} }
public void setManifestName(final String manifestName) { public void setManifestName(final String manifestName) {
this.manifestName = manifestName; this.manifestName = manifestName;
} }
@XmlList(value="volatile")
public List<Volatile> getVolatiles() { public List<Volatile> getVolatiles() {
return this.volatiles; return this.volatiles;
} }
@ -57,18 +61,19 @@ public class ConfigManifest {
} }
} }
} }
public List<Link> getCurentLink() { @XmlList(value="link")
return this.curentLink; public List<Link> getLinks() {
return this.links;
} }
public void setCurentLink(final List<Link> curentLink) { public void setLinks(final List<Link> curentLink) {
this.curentLink = curentLink; this.links = curentLink;
} }
public void addLink(final String source, final String destination) { public void addLink(final String source, final String destination) {
rmLink(destination); rmLink(destination);
this.curentLink.add(new Link(source, destination)); this.links.add(new Link(source, destination));
} }
private void rmLink(final String destination) { private void rmLink(final String destination) {
ListIterator<Link> it = this.curentLink.listIterator(); ListIterator<Link> it = this.links.listIterator();
while (it.hasNext()) { while (it.hasNext()) {
Link elem = it.next(); Link elem = it.next();
if (elem.getDestination().equals(destination)) { if (elem.getDestination().equals(destination)) {

View File

@ -1,5 +1,8 @@
package org.atriasoft.island.model; package org.atriasoft.island.model;
import org.atriasoft.exml.annotation.XmlDefaultAttibute;
@XmlDefaultAttibute
public class Link { public class Link {
private String source; private String source;
private String destination; private String destination;

View File

@ -1,5 +1,8 @@
package org.atriasoft.island.model; package org.atriasoft.island.model;
import org.atriasoft.exml.annotation.XmlDefaultAttibute;
@XmlDefaultAttibute
public class MirrorConfig { public class MirrorConfig {
private String name; private String name;
private String fetch; private String fetch;

View File

@ -3,6 +3,9 @@ package org.atriasoft.island.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.atriasoft.exml.annotation.XmlManaged;
import org.atriasoft.exml.annotation.XmlOptional;
public class ProjectConfig { public class ProjectConfig {
private String name; private String name;
private String path; private String path;
@ -10,6 +13,13 @@ public class ProjectConfig {
private boolean volatileElement = false; private boolean volatileElement = false;
private List<RemoteConfig> remotes = new ArrayList<>(); private List<RemoteConfig> remotes = new ArrayList<>();
RemoteConfig selectRemotes = null; RemoteConfig selectRemotes = null;
// TODO remove this when Xml parser is ready ...
public ProjectConfig() {
this.name = null;
this.path = null;
this.tag = null;
}
public ProjectConfig(final String name, final String path, final String tag) { public ProjectConfig(final String name, final String path, final String tag) {
this.name = name; this.name = name;
this.path = path; this.path = path;
@ -27,27 +37,35 @@ public class ProjectConfig {
public void setPath(final String path) { public void setPath(final String path) {
this.path = path; this.path = path;
} }
@XmlOptional
public String getTag() { public String getTag() {
return this.tag; return this.tag;
} }
public void setTag(final String tag) { public void setTag(final String tag) {
this.tag = tag; this.tag = tag;
} }
@XmlManaged(false)
public void setBranch(final String tag) { public void setBranch(final String tag) {
this.tag = tag; this.tag = tag;
} }
@XmlManaged(false)
public List<RemoteConfig> getRemotes() { public List<RemoteConfig> getRemotes() {
return this.remotes; return this.remotes;
} }
public void setRemotes(final List<RemoteConfig> remotes) { public void setRemotes(final List<RemoteConfig> remotes) {
this.remotes = remotes; this.remotes = remotes;
} }
@XmlManaged(false)
public RemoteConfig getSelectRemotes() { public RemoteConfig getSelectRemotes() {
return this.selectRemotes; return this.selectRemotes;
} }
public void setSelectRemotes(final RemoteConfig selectRemotes) { public void setSelectRemotes(final RemoteConfig selectRemotes) {
this.selectRemotes = selectRemotes; this.selectRemotes = selectRemotes;
} }
@XmlManaged(false)
public boolean isVolatile() { public boolean isVolatile() {
return this.volatileElement; return this.volatileElement;
} }

View File

@ -3,6 +3,8 @@ package org.atriasoft.island.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.atriasoft.exml.annotation.XmlAttribute;
public class RemoteConfig { public class RemoteConfig {
private String name; private String name;
private String fetch; private String fetch;
@ -13,18 +15,23 @@ public class RemoteConfig {
this.fetch = fetch; this.fetch = fetch;
this.mirror = mirror; this.mirror = mirror;
} }
@XmlAttribute
public String getName() { public String getName() {
return this.name; return this.name;
} }
public void setName(final String name) { public void setName(final String name) {
this.name = name; this.name = name;
} }
@XmlAttribute
public String getFetch() { public String getFetch() {
return this.fetch; return this.fetch;
} }
public void setFetch(final String fetch) { public void setFetch(final String fetch) {
this.fetch = fetch; this.fetch = fetch;
} }
public List<MirrorConfig> getMirror() { public List<MirrorConfig> getMirror() {
return this.mirror; return this.mirror;
} }

View File

@ -1,5 +1,6 @@
package org.atriasoft.island.model; package org.atriasoft.island.model;
@Deprecated
public class RepositoryConfig { public class RepositoryConfig {
private String remote = "origin"; private String remote = "origin";
private String revision = "master"; private String revision = "master";

View File

@ -0,0 +1,6 @@
package org.atriasoft.island.model.manifest;
public enum DeliverMode {
MERGE,
FAST_FORWARD;
}

View File

@ -0,0 +1,79 @@
package org.atriasoft.island.model.manifest;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.atriasoft.exml.annotation.XmlList;
import org.atriasoft.exml.annotation.XmlManaged;
import org.atriasoft.exml.annotation.XmlName;
import org.atriasoft.island.model.Link;
import org.atriasoft.island.model.ProjectConfig;
import org.atriasoft.island.model.RemoteConfig;
public class ManifestFile {
private Path fileRealPath = null;
private List<ProjectConfig> projects = new ArrayList<>();
private List<RemoteConfig> remotes = new ArrayList<>();
private List<String> includes = new ArrayList<>();
private List<MavenDependency> mavenDependency = new ArrayList<>();
private OptionRepository options = null;
private List<Link> links = new ArrayList<>();
@XmlName(value="project")
public List<ProjectConfig> getProjects() {
return this.projects;
}
public void setProjects(final List<ProjectConfig> projects) {
this.projects = projects;
}
@XmlName(value="remote")
public List<RemoteConfig> getRemotes() {
return this.remotes;
}
public void setRemotes(final List<RemoteConfig> remotes) {
this.remotes = remotes;
}
@XmlName(value="include")
public List<String> getIncludes() {
return this.includes;
}
public void setIncludes(final List<String> includes) {
this.includes = includes;
}
@XmlName(value="maven")
@XmlList(value="dependency")
public List<MavenDependency> getMavenDependency() {
return this.mavenDependency;
}
public void setMavenDependency(final List<MavenDependency> mavenDependency) {
this.mavenDependency = mavenDependency;
}
public OptionRepository getOptions() {
return this.options;
}
public void setOptions(final OptionRepository options) {
this.options = options;
}
@XmlName(value="link")
public List<Link> getLinks() {
return this.links;
}
public void setLinks(final List<Link> links) {
this.links = links;
}
@XmlManaged(false)
public Path getFileRealPath() {
return this.fileRealPath;
}
public void setFileRealPath(final Path fileRealPath) {
this.fileRealPath = fileRealPath;
}
}

View File

@ -0,0 +1,34 @@
package org.atriasoft.island.model.manifest;
import org.atriasoft.exml.annotation.XmlDefaultAttibute;
import org.atriasoft.exml.annotation.XmlName;
@XmlDefaultAttibute
public class MavenDependency {
private String org = null;
private String name = null;
private String revision = null;
public String getOrg() {
return this.org;
}
public void setOrg(final String org) {
this.org = org;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
@XmlName(value="rev")
public String getRevision() {
return this.revision;
}
public void setRevision(final String revision) {
this.revision = revision;
}
}

View File

@ -0,0 +1,63 @@
package org.atriasoft.island.model.manifest;
import org.atriasoft.exml.annotation.XmlName;
public class OptionRepository {
private String branchRelease = "master";
private String branchDevelop = "dev";
private DeliverMode deliverMode = DeliverMode.MERGE;
private String defaultBranch = "master";
private String defaultRemote = "origin";
private boolean synchronizeSubmodule = false;
@XmlName(value="branch-release")
public String getBranchRelease() {
return this.branchRelease;
}
public void setBranchRelease(final String branchRelease) {
this.branchRelease = branchRelease;
}
@XmlName(value="branch-develop")
public String getBranchDevelop() {
return this.branchDevelop;
}
public void setBranchDevelop(final String branchDevelop) {
this.branchDevelop = branchDevelop;
}
@XmlName(value="deliver-mode")
public DeliverMode getDeliverMode() {
return this.deliverMode;
}
public void setDeliverMode(final DeliverMode deliverMode) {
this.deliverMode = deliverMode;
}
@XmlName(value="default-branch")
public String getDefaultBranch() {
return this.defaultBranch;
}
public void setDefaultBranch(final String defaultBranch) {
this.defaultBranch = defaultBranch;
}
@XmlName(value="default-remote")
public String getDefaultRemote() {
return this.defaultRemote;
}
public void setDefaultRemote(final String defaultRemote) {
this.defaultRemote = defaultRemote;
}
@XmlName(value="synchronize-submodule")
public boolean isSynchronizeSubmodule() {
return this.synchronizeSubmodule;
}
public void setSynchronizeSubmodule(final boolean downloadSubmodule) {
this.synchronizeSubmodule = downloadSubmodule;
}
}