Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
rhbz910212 allow push and pull to be properly resumed in multi-module…
… projects
  • Loading branch information
davidmason committed Feb 26, 2013
1 parent 2ec5d98 commit 8e882f9
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 22 deletions.
Expand Up @@ -162,6 +162,12 @@ public String getCurrentModule()
return "";
}

@Override
public String getCurrentModule(boolean canonicalName)
{
return "";
}

@Override
public Set<String> getAllModules()
{
Expand Down
Expand Up @@ -59,5 +59,11 @@ public interface PushPullOptions extends ConfigurableProjectOptions
boolean getEnableModules();
boolean isRootModule();
String getCurrentModule();

/**
* @param canonicalName true if the module name should be in the canonical format used by maven
* @return
*/
String getCurrentModule(boolean canonicalName);
Set<String> getAllModules();
}
Expand Up @@ -154,16 +154,18 @@ public void run() throws Exception
SortedSet<String> docsToPull = docNamesForModule;
if (getOpts().getFromDoc() != null)
{
if (!docNamesForModule.contains(getOpts().getFromDoc()))
if (getOpts().getEnableModules())
{
log.error("Document with id {} not found, unable to start pull from unknown document. Aborting.", getOpts().getFromDoc());
// FIXME should this be throwing an exception to properly abort?
// need to see behaviour with modules
return;
if (belongsToCurrentModule(getOpts().getFromDoc()))
{
docsToPull = getDocsAfterFromDoc(getOpts().getFromDoc(), docsToPull);
}
// else fromDoc does not apply to this module
}
else
{
docsToPull = getDocsAfterFromDoc(getOpts().getFromDoc(), docsToPull);
}
docsToPull = docNamesForModule.tailSet(getOpts().getFromDoc());
int numSkippedDocs = docNamesForModule.size() - docsToPull.size();
log.info("Skipping {} document(s) before {}.", numSkippedDocs, getOpts().getFromDoc());
}

// TODO compare docNamesForModule with localDocNames, offer to delete obsolete translations from filesystem
Expand Down Expand Up @@ -285,13 +287,43 @@ else if(transResponse.getResponseStatus() == Response.Status.NOT_MODIFIED)
}
catch (RuntimeException e)
{
log.error("Operation failed.\n\n To retry from the last document, please add the option: {}\n", getOpts().buildFromDocArgument(qualifiedDocName));
throw e;
String message = "Operation failed.\n\n" +
" To retry from the last document, please set the following option(s):\n\n" +
" ";
if (getOpts().getEnableModules())
{
message += "--resume-from " + getOpts().getCurrentModule(true) + " ";
}
// Note: '.' is included after trailing newlines to prevent them being stripped,
// since stripping newlines can cause extra text to be appended to the options.
message += getOpts().buildFromDocArgument(qualifiedDocName) + "\n\n.";
throw new RuntimeException(message, e);
}
}

}

/**
* Returns a list with all documents before fromDoc removed.
*
* @param fromDoc
* @param docNames
* @return a set with only the documents after fromDoc, inclusive
* @throws RuntimeException if no document with the specified name exists
*/
private SortedSet<String> getDocsAfterFromDoc(String fromDoc, SortedSet<String> docNames)
{
SortedSet<String> docsToPull;
if (!docNames.contains(fromDoc))
{
throw new RuntimeException("Document with id " + fromDoc + " not found, unable to start pull from unknown document. Aborting.");
}
docsToPull = docNames.tailSet(fromDoc);
int numSkippedDocs = docNames.size() - docsToPull.size();
log.info("Skipping {} document(s) before {}.", numSkippedDocs, fromDoc);
return docsToPull;
}

private void writeSrcDoc(PullStrategy strat, Resource doc) throws IOException
{
if (!getOpts().isDryRun())
Expand Down
Expand Up @@ -290,16 +290,18 @@ private void pushCurrentModule() throws IOException, RuntimeException
SortedSet<String> docsToPush = localDocNames;
if (getOpts().getFromDoc() != null)
{
if (!localDocNames.contains(getOpts().getFromDoc()))
if (getOpts().getEnableModules())
{
log.error("Document with id {} not found, unable to start push from unknown document. Aborting.", getOpts().getFromDoc());
// FIXME should this be throwing an exception to properly abort?
// need to see behaviour with modules
return;
if (belongsToCurrentModule(getOpts().getFromDoc()))
{
docsToPush = getDocsAfterFromDoc(unqualifiedDocName(getOpts().getFromDoc()), localDocNames);
}
// else fromDoc does not apply to this module
}
else
{
docsToPush = getDocsAfterFromDoc(getOpts().getFromDoc(), localDocNames);
}
docsToPush = localDocNames.tailSet(getOpts().getFromDoc());
int numSkippedDocs = localDocNames.size() - docsToPush.size();
log.info("Skipping {} document(s) before {}.", numSkippedDocs, getOpts().getFromDoc());
}

if (localDocNames.isEmpty())
Expand Down Expand Up @@ -403,13 +405,43 @@ public void visit(LocaleMapping locale, TranslationsResource targetDoc)
}
catch (RuntimeException e)
{
log.error("Operation failed.\n\n To retry from the last document, please add the option: {}\n", getOpts().buildFromDocArgument(localDocName));
throw e;
String message = "Operation failed.\n\n" +
" To retry from the last document, please set the following option(s):\n\n" +
" ";
if (getOpts().getEnableModules())
{
message += "--resume-from " + getOpts().getCurrentModule(true) + " ";
}
// Note: '.' is included after trailing newlines to prevent them being stripped,
// since stripping newlines can cause extra text to be appended to the options.
message += getOpts().buildFromDocArgument(qualifiedDocName(localDocName)) + "\n\n.";
throw new RuntimeException(message, e);
}
}
deleteSourceDocsFromServer(obsoleteDocs);
}

/**
* Returns a list with all documents before fromDoc removed.
*
* @param fromDoc
* @param docNames
* @return a set with only the documents after fromDoc, inclusive
* @throws RuntimeException if no document with the specified name exists
*/
private SortedSet<String> getDocsAfterFromDoc(String fromDoc, SortedSet<String> docNames)
{
SortedSet<String> docsToPush;
if (!docNames.contains(fromDoc))
{
throw new RuntimeException("Document with id " + fromDoc + " not found, unable to start push from unknown document. Aborting.");
}
docsToPush = docNames.tailSet(fromDoc);
int numSkippedDocs = docNames.size() - docsToPush.size();
log.info("Skipping {} document(s) before {}.", numSkippedDocs, fromDoc);
return docsToPush;
}

/**
* Returns obsolete docs which belong to the current module. Returns any docs
* in the current module from the server, unless they are found in the
Expand Down
Expand Up @@ -23,6 +23,11 @@ public abstract class AbstractPushPullMojo<O extends PushPullOptions> extends Co
*/
private static final char MODULE_SEPARATOR = '/';

/**
* Separator used between components of the module ID for use by maven
*/
private static final char MVN_MODULE_SEPARATOR = ':';

private static final char MODULE_SUFFIX = '/';

@Override
Expand All @@ -44,15 +49,22 @@ public boolean isRootModule()

@Override
public String getCurrentModule()
{
return getCurrentModule(false);
}

@Override
public String getCurrentModule(boolean canonicalName)
{
if (project == null || !getEnableModules())
{
return "";
}
else
if (canonicalName)
{
return toModuleID(project);
return toMavenModuleID(project);
}
return toModuleID(project);
}

@Override
Expand Down Expand Up @@ -84,6 +96,11 @@ private String toModuleID(MavenProject module)
return module.getGroupId() + MODULE_SEPARATOR + module.getArtifactId();
}

private String toMavenModuleID(MavenProject module)
{
return module.getGroupId() + MVN_MODULE_SEPARATOR + module.getArtifactId();
}

/**
* @parameter expression="${project}"
* @readonly
Expand Down

0 comments on commit 8e882f9

Please sign in to comment.