diff --git a/sync-git-submodules-branches/.classpath b/sync-git-submodules-branches/.classpath
index 5e8a55f..6d619b3 100644
--- a/sync-git-submodules-branches/.classpath
+++ b/sync-git-submodules-branches/.classpath
@@ -23,5 +23,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sync-git-submodules-branches/.settings/org.eclipse.core.resources.prefs b/sync-git-submodules-branches/.settings/org.eclipse.core.resources.prefs
index e9441bb..abdea9a 100644
--- a/sync-git-submodules-branches/.settings/org.eclipse.core.resources.prefs
+++ b/sync-git-submodules-branches/.settings/org.eclipse.core.resources.prefs
@@ -1,3 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
+encoding//src/main/resources=UTF-8
encoding/=UTF-8
diff --git a/sync-git-submodules-branches/.settings/org.eclipse.jdt.core.prefs b/sync-git-submodules-branches/.settings/org.eclipse.jdt.core.prefs
index 91ca62e..8b5c4dc 100644
--- a/sync-git-submodules-branches/.settings/org.eclipse.jdt.core.prefs
+++ b/sync-git-submodules-branches/.settings/org.eclipse.jdt.core.prefs
@@ -8,7 +8,9 @@ org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
diff --git a/sync-git-submodules-branches/pom.xml b/sync-git-submodules-branches/pom.xml
index db90aac..d219fdc 100644
--- a/sync-git-submodules-branches/pom.xml
+++ b/sync-git-submodules-branches/pom.xml
@@ -5,7 +5,7 @@
org.gemoc.git-sync-tools
sync-git-submodules-branches-plugin
- 1.0.4
+ 1.1.0
maven-plugin
sync-git-submodules-branches Maven Plugin
@@ -107,12 +107,12 @@
descriptor
-
+
diff --git a/sync-git-submodules-branches/src/main/java/org/gemoc/sync_git_submodules_branches/SyncGitSubModulesBranchesCLI.java b/sync-git-submodules-branches/src/main/java/org/gemoc/sync_git_submodules_branches/SyncGitSubModulesBranchesCLI.java
index 4d8647c..0b86744 100644
--- a/sync-git-submodules-branches/src/main/java/org/gemoc/sync_git_submodules_branches/SyncGitSubModulesBranchesCLI.java
+++ b/sync-git-submodules-branches/src/main/java/org/gemoc/sync_git_submodules_branches/SyncGitSubModulesBranchesCLI.java
@@ -1,6 +1,8 @@
package org.gemoc.sync_git_submodules_branches;
import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.Set;
@@ -25,6 +27,8 @@ public static void main(String[] args) throws Exception {
.addOption("g", "gitURL", true, "git URL that will be cloned")
.addOption("c", "committerName", true, "name of the committer who'll sign the commit")
.addOption("e", "committerEmail", true, "email of the committer who'll sign the commit")
+ .addOption("d", "dryRun", false, "dryRun, do not commit and push the update")
+ .addOption("r", "reportFile", true, "file name tha will containt the markdown report")
.addOption("i", "inactivityThreshold", true, "number of days since the last commit of a specific branch before considering the branch as old/unmaintained/inactive (-1 for infinite duration)");
@@ -41,6 +45,8 @@ public static void main(String[] args) throws Exception {
String committerName = cmd.hasOption("c") ? cmd.getOptionValue("c") : "";
String committerEmail = cmd.hasOption("e") ? cmd.getOptionValue("e") : "";
String inactivityThreshold = cmd.hasOption("i") ? cmd.getOptionValue("i") : "90";
+ String reportFilePath = cmd.hasOption("r") ? cmd.getOptionValue("r") : "syncReport.md";
+ boolean dryRun = cmd.hasOption("d");
if(parentGitURL.isEmpty()) {
HelpFormatter formatter = new HelpFormatter();
@@ -66,13 +72,24 @@ public static void main(String[] args) throws Exception {
Set relevantBranches = gitManager.collectAllSubmodulesActiveRemoteBranches(Integer.parseInt(inactivityThreshold));
gitManager.deleteBranchesNotIn(relevantBranches);
gitManager.createMissingParentBranches(relevantBranches);
- gitManager.updateAllBranchesModules();
-
+ StringBuffer sb = new StringBuffer();
+ gitManager.updateAllBranchesModules(sb, dryRun);
+ FileUtils.write(outputDirectory, sb.toString(), Charset.defaultCharset());
+ writeReport(new File(reportFilePath), sb);
if(directoryPath.isEmpty()) {
// must delete the temp dir
System.out.println("Deleting temp directory "+outputDirectory);
FileUtils.deleteDirectory(outputDirectory);
}
}
+
+ protected static void writeReport(File reportFile, StringBuffer content) throws IOException {
+ // Ensure the parent directory exists
+ File parentDir = reportFile.getParentFile();
+ if (parentDir != null && !parentDir.exists()) {
+ parentDir.mkdirs();
+ }
+ FileUtils.write(reportFile, content.toString(), Charset.defaultCharset());
+ }
}
diff --git a/sync-git-submodules-branches/src/main/java/org/gemoc/sync_git_submodules_branches/SyncGitSubmodulesBranchesMojo.java b/sync-git-submodules-branches/src/main/java/org/gemoc/sync_git_submodules_branches/SyncGitSubmodulesBranchesMojo.java
index 3c8d88b..850f4a4 100644
--- a/sync-git-submodules-branches/src/main/java/org/gemoc/sync_git_submodules_branches/SyncGitSubmodulesBranchesMojo.java
+++ b/sync-git-submodules-branches/src/main/java/org/gemoc/sync_git_submodules_branches/SyncGitSubmodulesBranchesMojo.java
@@ -1,8 +1,12 @@
package org.gemoc.sync_git_submodules_branches;
import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
import java.util.Set;
+import org.apache.commons.io.FileUtils;
+
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
@@ -38,11 +42,17 @@ public class SyncGitSubmodulesBranchesMojo
extends AbstractMojo
{
/**
- * Location of the file.
+ * Location of the git repository.
*/
@Parameter( defaultValue = "${project.build.directory}/syncgitsubmodules_repo", property = "outputDir", required = true )
private File outputDirectory;
+ /**
+ * Location of the report file.
+ */
+ @Parameter( defaultValue = "${project.build.directory}/syncReport.md", property = "reportFile", required = true )
+ private File reportFile;
+
@Parameter(property="parentGitURL", required = true)
private String parentGitURL;
@@ -59,6 +69,9 @@ public class SyncGitSubmodulesBranchesMojo
@Parameter(defaultValue = "", property="committerName")
private String committerName;
+ @Parameter(defaultValue = "false", property="dryRun")
+ private boolean dryRun;
+
/**
* number of days since the last commit of a specific branch
* The branch will be considered old/unmaintained /inactive
@@ -91,7 +104,10 @@ public void execute()
Set relevantBranches = gitManager.collectAllSubmodulesActiveRemoteBranches(inactivityThreshold);
gitManager.deleteBranchesNotIn(relevantBranches);
gitManager.createMissingParentBranches(relevantBranches);
- gitManager.updateAllBranchesModules();
+ StringBuffer sb = new StringBuffer();
+ gitManager.updateAllBranchesModules(sb, dryRun);
+ writeReport(sb);
+
} catch (Exception e) {
getLog().error( e);
throw new MojoExecutionException(e.getMessage(), e);
@@ -99,4 +115,17 @@ public void execute()
}
+
+ protected void writeReport(StringBuffer content) throws MojoExecutionException {
+ // Ensure the parent directory exists
+ File parentDir = reportFile.getParentFile();
+ if (parentDir != null && !parentDir.exists()) {
+ parentDir.mkdirs();
+ }
+ try {
+ FileUtils.write(reportFile, content.toString(), Charset.defaultCharset());
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error writing to file", e);
+ }
+ }
}
diff --git a/sync-git-submodules-branches/src/main/java/org/gemoc/sync_git_submodules_branches/gittool/GitModuleManager.java b/sync-git-submodules-branches/src/main/java/org/gemoc/sync_git_submodules_branches/gittool/GitModuleManager.java
index 16b2d2a..e7b53b3 100644
--- a/sync-git-submodules-branches/src/main/java/org/gemoc/sync_git_submodules_branches/gittool/GitModuleManager.java
+++ b/sync-git-submodules-branches/src/main/java/org/gemoc/sync_git_submodules_branches/gittool/GitModuleManager.java
@@ -382,7 +382,15 @@ public void createBranchForModules(Git parentgit, String missingParentBranch)
}
}
- public void updateAllBranchesModules() throws IOException, GitAPIException, GitSyncError, ConfigInvalidException {
+ /**
+ *
+ * @param dryRun report only, do not perform changes
+ * @throws IOException
+ * @throws GitAPIException
+ * @throws GitSyncError
+ * @throws ConfigInvalidException
+ */
+ public void updateAllBranchesModules(StringBuffer reportBuffer, boolean dryRun) throws IOException, GitAPIException, GitSyncError, ConfigInvalidException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
try (Repository parentRepository = builder.setMustExist(true).setGitDir(new File(localGitFolder + "/.git"))
@@ -394,12 +402,15 @@ public void updateAllBranchesModules() throws IOException, GitAPIException, GitS
for (Ref ref : call) {
if (ref.getName().startsWith("refs/remotes/origin/")) {
updateBranchesForModules(parentgit,
- ref.getName().substring("refs/remotes/origin/".length()));
+ ref.getName().substring("refs/remotes/origin/".length()),
+ reportBuffer,
+ dryRun);
}
}
}
}
}
+
/**
*
@@ -411,9 +422,13 @@ public void updateAllBranchesModules() throws IOException, GitAPIException, GitS
* @throws IOException
* @throws ConfigInvalidException
*/
- public void updateBranchesForModules(Git parentgit, String consideredBranch)
+ public void updateBranchesForModules(Git parentgit, String consideredBranch, StringBuffer reportBuffer, boolean dryRun)
throws GitAPIException, GitSyncError, IOException, ConfigInvalidException {
logger.info("updateBranchesForModules branch = " + consideredBranch);
+ reportBuffer.append(String.format("**Branch %s**\n", consideredBranch));
+ reportBuffer.append("\n"
+ + "| Module | Branch |\n"
+ + "|:---------- |:---------- |\n");
// switch parentGit to branch
checkoutBranch(parentgit, consideredBranch);
@@ -442,6 +457,7 @@ public void updateBranchesForModules(Git parentgit, String consideredBranch)
}
}
logger.info(String.format(" tracking module %-32s on branch "+trackedBranchName, walk.getModuleName()));
+
// Make sure the parent repo knows that its submodule now tracks a branch:
FileBasedConfig modulesConfig = new FileBasedConfig(new File(
@@ -475,6 +491,7 @@ public void updateBranchesForModules(Git parentgit, String consideredBranch)
logger.debug("\t\tUntracked: " + status.getUntracked());
logger.debug("\t\tUntrackedFolders: " + status.getUntrackedFolders());
}
+ String branchModifier = "";
if(status.getAdded().size() + status.getChanged().size() +status.getRemoved().size() > 0) {
String msg;
PersonIdent committer;
@@ -493,13 +510,19 @@ public void updateBranchesForModules(Git parentgit, String consideredBranch)
msg = "Updating submodule "+walk.getModuleName()+" to track head of branch "+trackedBranchName;
committer = defaultCommitter;
}
- logger.debug("\t\tgit commit -m \""+msg+"\"");
- parentgit.commit()
- .setMessage(msg)
- .setAllowEmpty(false)
- .setCommitter(committer)
- .call();
+ branchModifier = "🔄";
+ if(! dryRun) {
+ logger.debug("\t\tgit commit -m \""+msg+"\"");
+ parentgit.commit()
+ .setMessage(msg)
+ .setAllowEmpty(false)
+ .setCommitter(committer)
+ .call();
+ } else {
+ logger.info("\t\t[DRYRUN] git commit -m \""+msg+"\"");
+ }
}
+ reportBuffer.append(String.format("| %-32s | %s %-16s |\n", walk.getModuleName(),branchModifier, trackedBranchName));
}
}
@@ -508,22 +531,27 @@ public void updateBranchesForModules(Git parentgit, String consideredBranch)
logger.info(
"\tupdating submodules: " + s);
}*/
- Iterable pushResps = parentgit.push()
- .setCredentialsProvider(credentialProvider)
- .call();
- for (PushResult pushRes : pushResps) {
- for (RemoteRefUpdate pushResult : pushRes.getRemoteUpdates()) {
- if(pushResult.getStatus() == RemoteRefUpdate.Status.OK) {
- logger.info("push branch "+consideredBranch+" => "+RemoteRefUpdate.Status.OK);
- } else if(pushResult.getStatus() == RemoteRefUpdate.Status.UP_TO_DATE) {
- logger.info("nothing to push for branch "+consideredBranch+" => "+RemoteRefUpdate.Status.UP_TO_DATE);
-
- } else {
- logger.error("PB pushing branch "+consideredBranch+" => "+pushRes.getMessages()+"\" "+pushResult);
+ if(!dryRun) {
+ Iterable pushResps = parentgit.push()
+ .setCredentialsProvider(credentialProvider)
+ .call();
+ for (PushResult pushRes : pushResps) {
+ for (RemoteRefUpdate pushResult : pushRes.getRemoteUpdates()) {
+ if(pushResult.getStatus() == RemoteRefUpdate.Status.OK) {
+ logger.info("push branch "+consideredBranch+" => "+RemoteRefUpdate.Status.OK);
+ } else if(pushResult.getStatus() == RemoteRefUpdate.Status.UP_TO_DATE) {
+ logger.info("nothing to push for branch "+consideredBranch+" => "+RemoteRefUpdate.Status.UP_TO_DATE);
+
+ } else {
+ logger.error("PB pushing branch "+consideredBranch+" => "+pushRes.getMessages()+"\" "+pushResult);
+ }
}
+ validateRemoteRefUpdates("push submodule tracking branch", pushRes.getRemoteUpdates());
}
- validateRemoteRefUpdates("push submodule tracking branch", pushRes.getRemoteUpdates());
+ } else {
+ logger.info("\t\t[DRYRUN] not pushing branch "+consideredBranch);
}
+ reportBuffer.append("\n");
}
}