diff options
author | James Moger <james.moger@gitblit.com> | 2012-01-05 17:08:44 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2012-01-05 17:08:44 -0500 |
commit | 0db5c4710b27969a8e1e49a752c541f5e0bb0a32 (patch) | |
tree | bf9f38f4fd058344bc0db918d2252345341c9ff3 | |
parent | 5e8e7ed191aaf72811334b4ba656405932719766 (diff) | |
download | gitblit-0db5c4710b27969a8e1e49a752c541f5e0bb0a32.tar.gz gitblit-0db5c4710b27969a8e1e49a752c541f5e0bb0a32.zip |
Using ArrayUtils.isEmpty to test arrays and collections
-rw-r--r-- | src/com/gitblit/ConfigUserService.java | 13 | ||||
-rw-r--r-- | src/com/gitblit/FederationPullExecutor.java | 10 | ||||
-rw-r--r-- | src/com/gitblit/FileUserService.java | 49 | ||||
-rw-r--r-- | src/com/gitblit/GitBlit.java | 7 | ||||
-rw-r--r-- | src/com/gitblit/client/EditRepositoryDialog.java | 7 | ||||
-rw-r--r-- | src/com/gitblit/client/GitblitClient.java | 19 | ||||
-rw-r--r-- | src/com/gitblit/wicket/pages/EditRepositoryPage.java | 7 |
7 files changed, 68 insertions, 44 deletions
diff --git a/src/com/gitblit/ConfigUserService.java b/src/com/gitblit/ConfigUserService.java index c3d42df2..5ba49aea 100644 --- a/src/com/gitblit/ConfigUserService.java +++ b/src/com/gitblit/ConfigUserService.java @@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory; import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
+import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.DeepCopier;
import com.gitblit.utils.StringUtils;
@@ -668,7 +669,7 @@ public class ConfigUserService implements IUserService { // repository memberships
// null check on "final" repositories because JSON-sourced UserModel
// can have a null repositories object
- if (model.repositories != null) {
+ if (!ArrayUtils.isEmpty(model.repositories)) {
config.setStringList(USER, model.username, REPOSITORY, new ArrayList<String>(
model.repositories));
}
@@ -678,33 +679,33 @@ public class ConfigUserService implements IUserService { for (TeamModel model : teams.values()) {
// null check on "final" repositories because JSON-sourced TeamModel
// can have a null repositories object
- if (model.repositories != null) {
+ if (!ArrayUtils.isEmpty(model.repositories)) {
config.setStringList(TEAM, model.name, REPOSITORY, new ArrayList<String>(
model.repositories));
}
// null check on "final" users because JSON-sourced TeamModel
// can have a null users object
- if (model.users != null) {
+ if (!ArrayUtils.isEmpty(model.users)) {
config.setStringList(TEAM, model.name, USER, new ArrayList<String>(model.users));
}
// null check on "final" mailing lists because JSON-sourced
// TeamModel can have a null users object
- if (model.mailingLists != null) {
+ if (!ArrayUtils.isEmpty(model.mailingLists)) {
config.setStringList(TEAM, model.name, MAILINGLIST, new ArrayList<String>(
model.mailingLists));
}
// null check on "final" preReceiveScripts because JSON-sourced
// TeamModel can have a null preReceiveScripts object
- if (model.preReceiveScripts != null) {
+ if (!ArrayUtils.isEmpty(model.preReceiveScripts)) {
config.setStringList(TEAM, model.name, PRERECEIVE, model.preReceiveScripts);
}
// null check on "final" postReceiveScripts because JSON-sourced
// TeamModel can have a null postReceiveScripts object
- if (model.postReceiveScripts != null) {
+ if (!ArrayUtils.isEmpty(model.postReceiveScripts)) {
config.setStringList(TEAM, model.name, POSTRECEIVE, model.postReceiveScripts);
}
}
diff --git a/src/com/gitblit/FederationPullExecutor.java b/src/com/gitblit/FederationPullExecutor.java index d54395e4..0fd1355f 100644 --- a/src/com/gitblit/FederationPullExecutor.java +++ b/src/com/gitblit/FederationPullExecutor.java @@ -49,6 +49,7 @@ import com.gitblit.models.FederationModel; import com.gitblit.models.RepositoryModel;
import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
+import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.FederationUtils;
import com.gitblit.utils.FileUtils;
import com.gitblit.utils.JGitUtils;
@@ -339,7 +340,7 @@ public class FederationPullExecutor implements Runnable { // update team repositories
TeamModel remoteTeam = user.getTeam(teamname);
- if (remoteTeam != null && remoteTeam.repositories != null) {
+ if (remoteTeam != null && !ArrayUtils.isEmpty(remoteTeam.repositories)) {
int before = team.repositories.size();
team.addRepositories(remoteTeam.repositories);
int after = team.repositories.size();
@@ -399,7 +400,7 @@ public class FederationPullExecutor implements Runnable { "Failed to retrieve SETTINGS from federated gitblit ({0} @ {1})",
registration.name, registration.url), e);
}
-
+
try {
// Pull SCRIPTS
Map<String, String> scripts = FederationUtils.getScripts(registration);
@@ -407,9 +408,10 @@ public class FederationPullExecutor implements Runnable { for (Map.Entry<String, String> script : scripts.entrySet()) {
String scriptName = script.getKey();
if (scriptName.endsWith(".groovy")) {
- scriptName = scriptName.substring(0, scriptName.indexOf(".groovy"));
+ scriptName = scriptName.substring(0, scriptName.indexOf(".groovy"));
}
- File file = new File(registrationFolderFile, registration.name + "_" + scriptName + ".groovy");
+ File file = new File(registrationFolderFile, registration.name + "_"
+ + scriptName + ".groovy");
FileUtils.writeContent(file, script.getValue());
}
}
diff --git a/src/com/gitblit/FileUserService.java b/src/com/gitblit/FileUserService.java index 9c4e507d..37ca9a70 100644 --- a/src/com/gitblit/FileUserService.java +++ b/src/com/gitblit/FileUserService.java @@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory; import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
+import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.DeepCopier;
import com.gitblit.utils.StringUtils;
@@ -868,29 +869,39 @@ public class FileUserService extends FileSettings implements IUserService { private void updateTeamCache(Properties allUsers, String teamname, TeamModel model) {
StringBuilder sb = new StringBuilder();
- for (String repository : model.repositories) {
- sb.append(repository);
- sb.append(',');
+ if (!ArrayUtils.isEmpty(model.repositories)) {
+ for (String repository : model.repositories) {
+ sb.append(repository);
+ sb.append(',');
+ }
}
- for (String user : model.users) {
- sb.append('!');
- sb.append(user);
- sb.append(',');
+ if (!ArrayUtils.isEmpty(model.users)) {
+ for (String user : model.users) {
+ sb.append('!');
+ sb.append(user);
+ sb.append(',');
+ }
}
- for (String address : model.mailingLists) {
- sb.append('&');
- sb.append(address);
- sb.append(',');
+ if (!ArrayUtils.isEmpty(model.mailingLists)) {
+ for (String address : model.mailingLists) {
+ sb.append('&');
+ sb.append(address);
+ sb.append(',');
+ }
}
- for (String script : model.preReceiveScripts) {
- sb.append('^');
- sb.append(script);
- sb.append(',');
+ if (!ArrayUtils.isEmpty(model.preReceiveScripts)) {
+ for (String script : model.preReceiveScripts) {
+ sb.append('^');
+ sb.append(script);
+ sb.append(',');
+ }
}
- for (String script : model.postReceiveScripts) {
- sb.append('%');
- sb.append(script);
- sb.append(',');
+ if (!ArrayUtils.isEmpty(model.postReceiveScripts)) {
+ for (String script : model.postReceiveScripts) {
+ sb.append('%');
+ sb.append(script);
+ sb.append(',');
+ }
}
// trim trailing comma
sb.setLength(sb.length() - 1);
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 89dcbf1a..d7120569 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -75,6 +75,7 @@ import com.gitblit.models.ServerStatus; import com.gitblit.models.SettingModel;
import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
+import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.ByteFormat;
import com.gitblit.utils.FederationUtils;
import com.gitblit.utils.JGitUtils;
@@ -991,14 +992,14 @@ public class GitBlit implements ServletContextListener { config.setString("gitblit", null, "federationStrategy",
repository.federationStrategy.name());
config.setBoolean("gitblit", null, "isFederated", repository.isFederated);
- if (repository.preReceiveScripts != null) {
+ if (!ArrayUtils.isEmpty(repository.preReceiveScripts)) {
config.setStringList("gitblit", null, "preReceiveScript", repository.preReceiveScripts);
}
- if (repository.postReceiveScripts != null) {
+ if (!ArrayUtils.isEmpty(repository.postReceiveScripts)) {
config.setStringList("gitblit", null, "postReceiveScript",
repository.postReceiveScripts);
}
- if (repository.mailingLists != null) {
+ if (!ArrayUtils.isEmpty(repository.mailingLists)) {
config.setStringList("gitblit", null, "mailingList", repository.mailingLists);
}
try {
diff --git a/src/com/gitblit/client/EditRepositoryDialog.java b/src/com/gitblit/client/EditRepositoryDialog.java index e4a332ab..ebc540f5 100644 --- a/src/com/gitblit/client/EditRepositoryDialog.java +++ b/src/com/gitblit/client/EditRepositoryDialog.java @@ -52,6 +52,7 @@ import javax.swing.ListCellRenderer; import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.Constants.FederationStrategy;
import com.gitblit.models.RepositoryModel;
+import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.StringUtils;
/**
@@ -104,11 +105,11 @@ public class EditRepositoryDialog extends JDialog { private JPalette<String> teamsPalette;
private JPalette<String> preReceivePalette;
-
+
private JLabel preReceiveInherited;
private JPalette<String> postReceivePalette;
-
+
private JLabel postReceiveInherited;
private Set<String> repositoryNames;
@@ -168,7 +169,7 @@ public class EditRepositoryDialog extends JDialog { anRepository.skipSummaryMetrics);
isFrozen = new JCheckBox(Translation.get("gb.isFrozenDescription"), anRepository.isFrozen);
- mailingListsField = new JTextField(anRepository.mailingLists == null ? ""
+ mailingListsField = new JTextField(ArrayUtils.isEmpty(anRepository.mailingLists) ? ""
: StringUtils.flattenStrings(anRepository.mailingLists, " "), 50);
accessRestriction = new JComboBox(AccessRestrictionType.values());
diff --git a/src/com/gitblit/client/GitblitClient.java b/src/com/gitblit/client/GitblitClient.java index d37ee911..09bcaab9 100644 --- a/src/com/gitblit/client/GitblitClient.java +++ b/src/com/gitblit/client/GitblitClient.java @@ -41,6 +41,7 @@ import com.gitblit.models.ServerSettings; import com.gitblit.models.ServerStatus;
import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
+import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.RpcUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.SyndicationUtils;
@@ -208,7 +209,9 @@ public class GitblitClient implements Serializable { if (repository != null) {
for (String teamname : getPermittedTeamnames(repository)) {
TeamModel team = getTeamModel(teamname);
- scripts.addAll(team.preReceiveScripts);
+ if (!ArrayUtils.isEmpty(team.preReceiveScripts)) {
+ scripts.addAll(team.preReceiveScripts);
+ }
}
}
return new ArrayList<String>(scripts);
@@ -258,7 +261,9 @@ public class GitblitClient implements Serializable { if (repository != null) {
for (String teamname : getPermittedTeamnames(repository)) {
TeamModel team = getTeamModel(teamname);
- scripts.addAll(team.postReceiveScripts);
+ if (!ArrayUtils.isEmpty(team.postReceiveScripts)) {
+ scripts.addAll(team.postReceiveScripts);
+ }
}
}
return new ArrayList<String>(scripts);
@@ -278,9 +283,11 @@ public class GitblitClient implements Serializable { // create list of available scripts by excluding inherited scripts
List<String> scripts = new ArrayList<String>();
- for (String script : settings.pushScripts) {
- if (!inherited.contains(script)) {
- scripts.add(script);
+ if (!ArrayUtils.isEmpty(settings.pushScripts)) {
+ for (String script : settings.pushScripts) {
+ if (!inherited.contains(script)) {
+ scripts.add(script);
+ }
}
}
return scripts;
@@ -489,7 +496,7 @@ public class GitblitClient implements Serializable { }
return teamnames;
}
-
+
public TeamModel getTeamModel(String name) {
for (TeamModel team : allTeams) {
if (team.name.equalsIgnoreCase(name)) {
diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/com/gitblit/wicket/pages/EditRepositoryPage.java index 0f3a0bbe..7d2d64c8 100644 --- a/src/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -47,6 +47,7 @@ import com.gitblit.GitBlitException; import com.gitblit.Keys;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
+import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
@@ -116,7 +117,7 @@ public class EditRepositoryPage extends RootSubPage { new ChoiceRenderer<String>("", ""), 5, false);
// pre-receive palette
- if (repositoryModel.preReceiveScripts != null) {
+ if (!ArrayUtils.isEmpty(repositoryModel.preReceiveScripts)) {
preReceiveScripts.addAll(repositoryModel.preReceiveScripts);
}
final Palette<String> preReceivePalette = new Palette<String>("preReceiveScripts",
@@ -125,7 +126,7 @@ public class EditRepositoryPage extends RootSubPage { new ChoiceRenderer<String>("", ""), 12, true);
// post-receive palette
- if (repositoryModel.postReceiveScripts != null) {
+ if (!ArrayUtils.isEmpty(repositoryModel.postReceiveScripts)) {
postReceiveScripts.addAll(repositoryModel.postReceiveScripts);
}
final Palette<String> postReceivePalette = new Palette<String>("postReceiveScripts",
@@ -286,7 +287,7 @@ public class EditRepositoryPage extends RootSubPage { form.add(new CheckBox("showReadme"));
form.add(new CheckBox("skipSizeCalculation"));
form.add(new CheckBox("skipSummaryMetrics"));
- mailingLists = new Model<String>(repositoryModel.mailingLists == null ? ""
+ mailingLists = new Model<String>(ArrayUtils.isEmpty(repositoryModel.mailingLists) ? ""
: StringUtils.flattenStrings(repositoryModel.mailingLists, " "));
form.add(new TextField<String>("mailingLists", mailingLists));
form.add(usersPalette);
|