Skip to content

Commit

Permalink
Fixed init from config not copying branches
Browse files Browse the repository at this point in the history
See #106
  • Loading branch information
lptr committed Sep 22, 2014
1 parent 3651c23 commit 217713e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
31 changes: 28 additions & 3 deletions pride/src/main/java/com/prezi/gradle/pride/cli/ModuleAdder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.prezi.gradle.pride.cli;

import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.prezi.gradle.pride.Pride;
import com.prezi.gradle.pride.PrideException;
Expand Down Expand Up @@ -28,12 +29,12 @@
public class ModuleAdder {
private static final Logger logger = LoggerFactory.getLogger(ModuleAdder.class);

public static List<String> addModules(Pride pride, Collection<String> modules, VcsManager vcsManager) throws ConfigurationException {
public static List<String> addModules(Pride pride, Collection<ModuleToAdd> modules, VcsManager vcsManager) throws ConfigurationException {
RuntimeConfiguration config = pride.getConfiguration();
boolean useRepoCache = config.getBoolean(REPO_CACHE_ALWAYS);
String repoBaseUrl = config.getString(REPO_BASE_URL);
boolean recursive = config.getBoolean(REPO_RECURSIVE);
String branch = config.getString(REPO_BRANCH);
String defaultBranch = config.getString(REPO_BRANCH);
String repoType = config.getString(REPO_TYPE_DEFAULT);

// Get some support for our VCS
Expand All @@ -48,7 +49,13 @@ public static List<String> addModules(Pride pride, Collection<String> modules, V

List<String> failedModules = Lists.newArrayList();
RepoCache repoCache = null;
for (String module : modules) {
for (ModuleToAdd moduleEntry : modules) {
String module = moduleEntry.getModule();
String branch = moduleEntry.getBranch();
if (Strings.isNullOrEmpty(branch)) {
branch = defaultBranch;
}

try {
String moduleName = vcsSupport.resolveRepositoryName(module);
String repoUrl;
Expand Down Expand Up @@ -99,4 +106,22 @@ private static String getRepoUrl(String repoBaseUrl, String moduleName) {

return repoBaseUrl + moduleName;
}

public static class ModuleToAdd {
private final String module;
private final String branch;

public ModuleToAdd(String module, String branch) {
this.module = module;
this.branch = branch;
}

public String getModule() {
return module;
}

public String getBranch() {
return branch;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.prezi.gradle.pride.cli.commands;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.prezi.gradle.pride.Pride;
import com.prezi.gradle.pride.PrideException;
import com.prezi.gradle.pride.RuntimeConfiguration;
Expand Down Expand Up @@ -68,7 +70,7 @@ public void executeInPride(final Pride pride) throws Exception {
config.override(REPO_TYPE_DEFAULT, explicitRepoType);
config.override(REPO_CACHE_ALWAYS, explicitUseRepoCache, explicitNoRepoCache);
config.override(REPO_RECURSIVE, explicitRecursive);
config.override(REPO_BRANCH, explicitBranch);
final String branch = config.override(REPO_BRANCH, explicitBranch);

// Check if anything exists already
if (!overwrite) {
Expand All @@ -92,8 +94,15 @@ public boolean apply(String it) {
}
}

Collection<ModuleAdder.ModuleToAdd> modulesToAdd = Collections2.transform(modules, new Function<String, ModuleAdder.ModuleToAdd>() {
@Override
public ModuleAdder.ModuleToAdd apply(String module) {
return new ModuleAdder.ModuleToAdd(module, branch);
}
});

// Clone repositories
ModuleAdder.addModules(pride, modules, getVcsManager());
ModuleAdder.addModules(pride, modulesToAdd, getVcsManager());

pride.save();
new PrideInitializer(new GradleConnectorManager(config), isVerbose()).reinitialize(pride);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ protected int initPride(PrideInitializer prideInitializer, Pride pride) throws E
return 0;
}

Collection<String> modules = Collections2.transform(modulesFromConfiguration, new Function<Module, String>() {
Collection<ModuleAdder.ModuleToAdd> modules = Collections2.transform(modulesFromConfiguration, new Function<Module, ModuleAdder.ModuleToAdd>() {
@Override
public String apply(Module module) {
return module.getRemote();
public ModuleAdder.ModuleToAdd apply(Module module) {
return new ModuleAdder.ModuleToAdd(module.getRemote(), module.getBranch());
}
});
List<String> failedModules = ModuleAdder.addModules(pride, modules, vcsManager);
Expand Down

0 comments on commit 217713e

Please sign in to comment.