[DEV] status is OK ==> start integrate init

This commit is contained in:
Edouard DUPIN 2021-06-29 22:02:30 +02:00
parent 19fa1f3983
commit c70d59c918
15 changed files with 309 additions and 162 deletions

View File

@ -2,19 +2,26 @@ package org.atriasoft.island;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.atriasoft.island.internal.Log;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ListBranchCommand.ListMode;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.lib.BranchConfig;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevTag;
public class Commands {
private Commands() {}
@ -98,19 +105,100 @@ public class Commands {
public static List<String> get_tags_current(final Git git) {
List<String> out = new ArrayList<>();
out.add("TODO");
out.add("TODO");
/*
cmd = "git tag --points-at"
Log.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "get_tags_current", error_only=true)
list_tags = []
for elem in return_value[1].split('\n'):
if elem != "":
list_tags.append(elem)
*/
RevCommit latestCommit;
try {
latestCommit = git.log().setMaxCount(1).call().iterator().next();
} catch (GitAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return out;
}
String latestCommitHash = latestCommit.getName();
List<Ref> list;
try {
list = git.tagList().call();
} catch (GitAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return out;
}
ObjectId commitId = ObjectId.fromString(latestCommit.getName());
Collection<ObjectId> commits = new LinkedList<ObjectId>();
for (Ref tag : list) {
ObjectId object = tag.getObjectId();
if (object.equals(commitId)) {
//commits.add(object.getId());
if (tag.getName().startsWith("refs/tags/")) {
out.add(tag.getName().substring(10));
}
}
}
return out;
}
public static void get_diff(Git git) {
try {
Status status = git.status().call();
if (status.getAdded().size() != 0) {
Log.print(" * Added: (" + status.getAdded().size() + ")");
for (String elem : status.getAdded()) {
Log.print(" - " + elem);
}
}
if (status.getChanged().size() != 0) {
Log.print(" * Changed: (" + status.getChanged().size() + ")");
for (String elem : status.getChanged()) {
Log.print(" - " + elem);
}
}
if (status.getConflicting().size() != 0) {
Log.print(" * Conflicting: (" + status.getConflicting().size() + ")");
for (String elem : status.getConflicting()) {
Log.print(" - " + elem);
}
}
/*
if (status.getIgnoredNotInIndex().size() != 0) {
Log.print(" * Ignored not in index: (" + status.getIgnoredNotInIndex().size() + ")");
for (String elem : status.getIgnoredNotInIndex()) {
Log.print(" - " + elem);
}
}
*/
if (status.getMissing().size() != 0) {
Log.print(" * Missing: (" + status.getMissing().size() + ")");
for (String elem : status.getMissing()) {
Log.print(" - " + elem);
}
}
if (status.getModified().size() != 0) {
Log.print(" * Modified: (" + status.getModified().size() + ")");
for (String elem : status.getModified()) {
Log.print(" - " + elem);
}
}
if (status.getRemoved().size() != 0) {
Log.print(" * Removed: (" + status.getRemoved().size() + ")");
for (String elem : status.getRemoved()) {
Log.print(" - " + elem);
}
}
if (status.getUntracked().size() != 0) {
Log.print(" * Untracked: (" + status.getUntracked().size() + ")");
for (String elem : status.getUntracked()) {
Log.print(" - " + elem);
}
}
if (status.getUntrackedFolders().size() != 0) {
Log.print(" * Untracked Folders: (" + status.getUntrackedFolders().size() + ")");
for (String elem : status.getUntrackedFolders()) {
Log.print(" - " + elem);
}
}
} catch (NoWorkTreeException | GitAPIException e) {
Log.error("can not retrive the satus of the repository ... " + e.getMessage());
e.printStackTrace();
}
}
}

View File

@ -4,10 +4,16 @@ import org.atriasoft.island.model.ConfigManifest;
public class Config {
private static ConfigManifest config;
public static ConfigManifest getUniqueConfig() {
public static synchronized ConfigManifest getUniqueConfig() {
if (config == null) {
config = ConfigManifest.load();
}
return config;
}
public static synchronized ConfigManifest createUniqueConfig() {
if (config == null) {
config = new ConfigManifest();
}
return config;
}
}

View File

@ -104,7 +104,9 @@ public class Env {
tmpPath = tmpPath.getParent();
Log.info("test upper path: " + tmpPath);
if (tmpPath == null) {
Log.critical("the root path of " + Env.get_system_base_name() + " must not be upper parent paths of (" + Env.island_root_path.toAbsolutePath() + ")");
Log.info("the root path of " + Env.get_system_base_name() + " must not be upper parent paths of (" + Env.island_root_path.toAbsolutePath() + ")");
tmpPath = Env.island_root_path.toAbsolutePath();
break;
}
}
Env.island_root_path = tmpPath;

View File

@ -10,6 +10,7 @@ import org.atriasoft.death.ArgChoice;
import org.atriasoft.death.ArgElement;
import org.atriasoft.death.Arguments;
import org.atriasoft.island.actions.IslandActionCheckout;
import org.atriasoft.island.actions.IslandActionInit;
import org.atriasoft.island.actions.IslandActionStatus;
import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.ActionException;
@ -157,6 +158,7 @@ public class MainIsland {
// }
}
public MainIsland() {
Actions.addAction("init", IslandActionInit.class);
Actions.addAction("status", IslandActionStatus.class);
Actions.addAction("checkout", IslandActionCheckout.class);
this.my_args.addSection("option", "Can be set one time in all case");

View File

@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.atriasoft.exml.Exml;
import org.atriasoft.exml.exception.ExmlBuilderException;
@ -46,24 +47,10 @@ public class Manifest {
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<>();
OptionRepository defaultWhat = null;
OptionRepository defaultWhat = null;
OptionRepository defaultBase = new OptionRepository();
@Deprecated
List<RemoteConfig> remotes = new ArrayList<>();
@Deprecated
List<IncludeConfig> includes = new ArrayList<>();
@Deprecated
List<Link> links = new ArrayList<>();
OptionRepository defaultBase = new OptionRepository();
public Manifest(final Path manifestXml) throws IOException {
this.manifestXml = manifestXml;
@ -79,7 +66,13 @@ public class Manifest {
}
public List<Link> getLinks() {
return this.links;
List<Link> out = new ArrayList<>();
for (Entry<String, ManifestFile> elem : manifests.entrySet()) {
for (Link link : elem.getValue().getLinks()) {
out.add(link);
}
}
return out;
}
String removeEndSlash(String value) {
while (value.length() > 1
@ -91,7 +84,6 @@ public class Manifest {
}
public void load() throws ExmlParserErrorMulti, ExmlBuilderException, IOException {
Path rootDirectory = this.manifestXml.toAbsolutePath();
this.rootManifest = rootDirectory.getFileName().toString();
rootDirectory = rootDirectory.getParent();
@ -351,10 +343,11 @@ public class Manifest {
// }
public List<ProjectConfig> get_all_configs() {
return get_all_configs(null, new ArrayList<>());
ManifestFile mani = this.manifests.get(this.rootManifest);
return get_all_configs(mani, null, new ArrayList<>());
}
public List<ProjectConfig> get_all_configs(OptionRepository defaultPlouf, final List<RemoteConfig> upper_remotes) {
public List<ProjectConfig> get_all_configs(ManifestFile mani, OptionRepository defaultPlouf, final List<RemoteConfig> upper_remotes) {
List<ProjectConfig> out = new ArrayList<>();
if (defaultPlouf == null) {
if (this.defaultWhat != null) {
@ -365,7 +358,7 @@ public class Manifest {
}
// Log.error(" this.default=" + str(this.default))
// add all local project
for (ProjectConfig elem : this.projects) {
for (ProjectConfig elem : mani.getProjects()) {
Log.verbose("parse element " + elem);
if (!Env.need_process_with_filter(elem.getName())) {
Log.info("Filter repository: " + elem.getName());
@ -374,7 +367,7 @@ public class Manifest {
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) {
for (RemoteConfig remote : mani.getRemotes()) {
Log.verbose(" Local Remote: " + remote);
if (remote.getName().equals(defaultPlouf.getDefaultRemote())) {
conf.getRemotes().add(remote);
@ -383,14 +376,13 @@ public class Manifest {
if (conf.getRemotes().size() == 0) {
for (RemoteConfig remote : upper_remotes) {
Log.verbose(" upper Remote: " + remote);
if (remote.getName().equals(defaultPlouf.getDefaultRemote())) {
if (remote.getName() != null && remote.getName().equals(defaultPlouf.getDefaultRemote())) {
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.getDefaultRemote() + " this remote: " + this.remotes);
Log.error(" No remote detected: " + conf.getRemotes().size() + " for " + conf.getName() + " with default remote name : " + defaultPlouf.getDefaultRemote() + " this remote: " + mani.getRemotes());
}
// select default remote:
Log.debug(" remotes count: " + conf.getRemotes().size());
@ -416,12 +408,13 @@ public class Manifest {
}
// create a temporary variable to transmit the remote to includes
List<RemoteConfig> upper_remotes_forward = new ArrayList<>(upper_remotes);
for (RemoteConfig remote : this.remotes) {
for (RemoteConfig remote : mani.getRemotes()) {
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 (String elemInclude : mani.getIncludes()) {
ManifestFile mani2 = this.manifests.get(elemInclude);
List<ProjectConfig> list_project = get_all_configs(mani2, defaultPlouf, upper_remotes_forward);
for (ProjectConfig elem_proj : list_project) {
out.add(elem_proj);
}

View File

@ -1,5 +1,10 @@
package org.atriasoft.island;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.ProjectConfig;
public class Tools {
@ -11,4 +16,17 @@ public class Tools {
}
return id + "/" + count + " : " + elem.getPath();
}
public static void createDirectory(Path basePath) {
Path absPath = basePath.toAbsolutePath();
if (!Files.exists(absPath)) {
try {
Files.createDirectory(absPath);
} catch (IOException e) {
Log.error("Errro while creating path ... " + e.getMessage());
Log.error("Path ... " + absPath);
e.printStackTrace();
}
}
}
}

View File

@ -23,7 +23,7 @@ public class IslandActionCheckout extends ActionInterface {
}
@Override
public void add_specific_arguments(final Arguments myArgs, final String section) {
public void addSpecificArguments(final Arguments myArgs, final String section) {
myArgs.add("r", "remote", null, "Name of the remote server", true);
myArgs.addArg("branch", false, "Branch to checkout (if '__TAG__' ==> checkout specific repository tags)");
}

View File

@ -0,0 +1,146 @@
package org.atriasoft.island.actions;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import org.atriasoft.death.ArgElement;
import org.atriasoft.death.Arguments;
import org.atriasoft.island.Config;
import org.atriasoft.island.Env;
import org.atriasoft.island.Manifest;
import org.atriasoft.island.Tools;
import org.atriasoft.island.internal.Log;
import org.atriasoft.island.model.ActionException;
import org.atriasoft.island.model.ActionInterface;
import org.atriasoft.island.model.ConfigManifest;
import org.atriasoft.island.model.ProjectConfig;
import org.eclipse.jgit.api.Git;
public class IslandActionInit extends ActionInterface {
@Override
public String help() {
return "Init a island repository (need 'fetch' after)";
}
@Override
public void addSpecificArguments(final Arguments myArgs, final String section) {
myArgs.add("b", "branch", null, "Select branch to display", true);
myArgs.add("m", "manifest", null, "Name of the manifest", true);
}
@Override
public void execute(final List<ArgElement> _arguments) throws ActionException, Exception {
if (_arguments.size() == 0) {
Log.error("Missing argument to execute the current action ...");
return;
}
String branch = "master";
String manifest_name = "default.xml";
String address_manifest = "";
for (ArgElement elem : _arguments) {
if (elem.getOptionName().equals("branch")) {
branch = elem.getArg();
Log.info("Get branch name : " + branch);
} else if (elem.getOptionName().equals("manifest")) {
manifest_name = elem.getArg();
Log.info("Get manifest name : " + manifest_name);
} else if (elem.getOptionName().equals("")) {
if (!address_manifest.isEmpty()) {
Log.critical("Manifest adress already set : '" + address_manifest + "' !!! '" + elem.getArg() + "'");
}
address_manifest = elem.getArg();
Log.info("Get manifest address : " + address_manifest);
} else {
Log.critical("Wrong argument: '" + elem.getOptionName() + "' '" + elem.getArg() + "'");
}
}
if (address_manifest.isEmpty()) {
Log.critical("Init: Missing manifest name");
}
Log.info("Init with: '" + address_manifest + "' branch='" + branch + "' name of manifest='" + manifest_name + "'");
if (Manifest.isInit()) {
Log.critical("System already init: path already exist: '" + Env.get_island_path() + "'");
}
Tools.createDirectory(Env.get_island_path());
// create the file configuration:
ConfigManifest configuration = Config.createUniqueConfig();
configuration.setRepo(address_manifest);
configuration.setBranch(branch);
configuration.setManifestName(manifest_name);
configuration.store();
Tools.createDirectory(Env.get_island_path_manifest());
Log.info("Clone the manifest");
Git git = Git.cloneRepository()
.setURI( address_manifest )
.setDirectory( Env.get_island_path_manifest().toFile() )
.setBranch(branch)
.call();
return;
/*
if ret_values == false:
Log.info("'" + str(ret_values) + "'")
Log.error("Init does not work")
return false
Log.info("Init done correctly ...")
return None
Path file_source_manifest = Env.get_island_path_manifest().resolve(configuration.getManifestName());
if (!Files.exists(file_source_manifest)) {
Log.critical("Missing manifest file : '" + file_source_manifest + "'");
}
Manifest mani = new Manifest(file_source_manifest);
Git git = Git.open(Env.get_island_path_manifest().toFile());
boolean is_modify_manifest = git.status().call().hasUncommittedChanges();
if (is_modify_manifest) {
Log.info("!!!!!!!!!!!! MANIFEST is modify !!!!!!!!");
}
List<ProjectConfig> all_project = mani.get_all_configs();
Log.info("status of: " + all_project.size() + " projects");
int id_element = 0;
boolean is_behind = false;
for (ProjectConfig elem : all_project) {
id_element++;
String base_display = Tools.get_list_base_display(id_element, all_project.size(), elem);
int ret = Status.displayStatus(elem, argument_remote_name, argument_display_tag, id_element, base_display);
if (ret != 0) {
is_behind = true;
}
}
if (is_behind == true) {
//return Env.ret_action_need_updtate;
}
*/
}
@Override
public String helpExample() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -26,7 +26,7 @@ public class IslandActionStatus extends ActionInterface {
}
@Override
public void add_specific_arguments(final Arguments myArgs, final String section) {
public void addSpecificArguments(final Arguments myArgs, final String section) {
myArgs.add("r", "remote", null, "Name of the remote server", true);
myArgs.add("t", "tags", null, "Display if the commit is on a tag (and display it)", false);
}
@ -88,5 +88,6 @@ public class IslandActionStatus extends ActionInterface {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -195,17 +195,9 @@ public class Status {
tags_comment = "\r\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t- - - - -";
}
}
Log.info(base_display + volatileString + "\r\t\t\t\t\t\t\t" + modify_status + "(" + select_branch + " -> " + tracking_remote_branch + ")" + behind_forward_comment + tags_comment);
Log.print(base_display + volatileString + "\r\t\t\t\t\t\t\t" + modify_status + "(" + select_branch + " -> " + tracking_remote_branch + ")" + behind_forward_comment + tags_comment);
if (is_modify) {
/*
cmd = "git status --short"
Log.verbose("execute : " + cmd)
ret_diff = multiprocess.run_command(cmd, cwd=git_repo_path)
tmp_color_red = "\033[31m"
tmp_color_default= "\033[00m"
Log.info(tmp_color_red + ret_diff[1] + tmp_color_default)
*/
Commands.get_diff(git);
}
return in_behind;
}

View File

@ -4,7 +4,7 @@ import io.scenarium.logger.LogLevel;
import io.scenarium.logger.Logger;
public class Log {
private static final boolean FORCE = true;
private static final boolean FORCE = false;
private static final String LIB_NAME = "island";
private static final String LIB_NAME_DRAW = Logger.getDrawableName(Log.LIB_NAME);
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.CRITICAL);

View File

@ -29,12 +29,6 @@ public abstract class ActionInterface {
return false;
}
/**
* Add argument to the specific action
* @param myArgs (death.Arguments) Argument manager
* @param section Name of the current action
*/
public abstract void add_specific_arguments(Arguments myArgs, String section);
/**
* Execute the action required.

View File

@ -9,12 +9,17 @@ public 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 RemoteConfig() {
this.name = "";
this.fetch = "";
this.mirror = new ArrayList<>();
}
@XmlAttribute
public String getName() {

View File

@ -1,100 +0,0 @@
//!/usr/bin/python
// -*- coding: utf-8 -*-
//#
//# @author Edouard DUPIN
//#
//# @copyright 2012, Edouard DUPIN, all right reserved
//#
//# @license MPL v2.0 (see license file)
//#
from realog import Log
from island import tools
from island import env
from island import config
from island import commands
from island import multiprocess
from island import manifest
import os
//#
//# @brief Get the global description of the current action
//# @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
//#
public void help():
return "Init a island repository (need 'fetch' after)"
//#
//# @brief Add argument to the specific action
//# @param[in,out] my_args (death.Arguments) Argument manager
//# @param[in] section Name of the currect action
//#
public void add_specific_arguments(my_args, section):
my_args.add("b", "branch", haveParam=true, desc="Select branch to display")
my_args.add("m", "manifest", haveParam=true, desc="Name of the manifest")
//#
//# @brief Execute the action required.
//#
//# @return error value [0 .. 50] the <0 value is reserved system ==> else, what you want.
//# None : No error (return program out 0)
//# -10 : ACTION is not existing
//# -11 : ACTION execution system error
//# -12 : ACTION Wrong parameters
//#
public void execute(_arguments):
if len(_arguments) == 0:
Log.error("Missing argument to execute the current action ...")
// the configuration availlable:
branch = "master"
manifest_name = "default.xml"
address_manifest = ""
for elem in _arguments:
if elem.getOptionName().equals("branch":
Log.info("find branch name: '" + elem.getArg() + "'")
branch = elem.getArg()
} else if elem.getOptionName().equals("manifest":
Log.info("find mmanifest name: '" + elem.getArg() + "'")
manifest_name = elem.getArg()
} else if elem.getOptionName().equals("":
if address_manifest != "":
Log.error("Manifest adress already set : '" + address_manifest + "' !!! '" + elem.getArg() + "'")
address_manifest = elem.getArg()
else:
Log.error("Wrong argument: '" + elem.getOptionName() + "' '" + elem.getArg() + "'")
if address_manifest.equals("":
Log.error("Init: Missing manifest name")
Log.info("Init with: '" + address_manifest + "' branch='" + branch + "' name of manifest='" + manifest_name + "'")
// check if .XXX exist (create it if needed)
if manifest.is_lutin_init() == true:
Log.error("System already init: path already exist: '" + str(Env.get_island_path()) + "'")
tools.create_directory(Env.get_island_path())
// check if the git of the manifest if availlable
// create the file configuration:
conf = config.get_unique_config()
conf.set_manifest(address_manifest)
conf.set_branch(branch)
conf.set_manifest_name(manifest_name)
conf.store()
Log.info("Clone the manifest")
ret_values = commands.clone(Env.get_island_path_manifest(), address_manifest, branch_name=branch)
if ret_values == false:
Log.info("'" + str(ret_values) + "'")
Log.error("Init does not work")
return false
Log.info("Init done correctly ...")
return None