Skip to content

Commit a99d1bb

Browse files
tulinkryVladimir Kotal
authored andcommitted
adding a constructor with name and optional pattern for a group (#1593)
fixes #1555
1 parent 71a04c7 commit a99d1bb

File tree

8 files changed

+30
-37
lines changed

8 files changed

+30
-37
lines changed

src/org/opensolaris/opengrok/configuration/Group.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ public class Group implements Comparable<Group>, Nameable {
6868
private Set<Project> repositories = new TreeSet<>();
6969
private Set<Group> parents;
7070

71+
/**
72+
* No-arg constructor is needed for deserialization.
73+
*/
74+
public Group() {
75+
}
76+
77+
public Group(String name) {
78+
this(name, "");
79+
}
80+
81+
public Group(String name, String pattern) {
82+
this.name = name;
83+
this.setPattern(pattern);
84+
}
85+
7186
public Set<Project> getProjects() {
7287
return projects;
7388
}
@@ -198,7 +213,7 @@ public String getPattern() {
198213
* @param pattern the regexp pattern for this group
199214
* @throws PatternSyntaxException when the pattern is invalid
200215
*/
201-
public void setPattern(String pattern) throws PatternSyntaxException {
216+
public final void setPattern(String pattern) throws PatternSyntaxException {
202217
this.compiledPattern = Pattern.compile("(" + pattern + ")");
203218
this.pattern = pattern;
204219
}

src/org/opensolaris/opengrok/configuration/Groups.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,7 @@ public boolean call(Group g) {
289289
* @return false if parent group was not found, true otherwise
290290
*/
291291
private static boolean modifyGroup(Set<Group> groups, String groupname, String grouppattern, String parent) {
292-
Group g = new Group();
293-
g.setName(groupname);
294-
g.setPattern(grouppattern);
292+
Group g = new Group(groupname, grouppattern);
295293

296294
if (updateGroup(groups, groupname, grouppattern)) {
297295
return true;

test/org/opensolaris/opengrok/authorization/AuthorizationFrameworkTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,12 @@ static private Project createUnallowedProject() {
700700
}
701701

702702
static private Group createAllowedGroup() {
703-
Group g = new Group();
704-
g.setName("allowed" + "_" + "group_" + random.nextInt());
703+
Group g = new Group("allowed" + "_" + "group_" + random.nextInt());
705704
return g;
706705
}
707706

708707
static private Group createUnallowedGroup() {
709-
Group g = new Group();
710-
g.setName("not_allowed" + "_" + "group_" + random.nextInt());
708+
Group g = new Group("not_allowed" + "_" + "group_" + random.nextInt());
711709
return g;
712710
}
713711

test/org/opensolaris/opengrok/authorization/AuthorizationPluginClassLoaderTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ public void testFalsePlugin() {
150150

151151
IAuthorizationPlugin plugin = getNewInstance(clazz);
152152

153-
Group g = new Group();
154-
g.setName("group1");
153+
Group g = new Group("group1");
155154
Project p = new Project("project1");
156155

157156
Assert.assertFalse(
@@ -171,8 +170,7 @@ public void testTruePlugin() {
171170

172171
IAuthorizationPlugin plugin = getNewInstance(clazz);
173172

174-
Group g = new Group();
175-
g.setName("group1");
173+
Group g = new Group("group1");
176174
Project p = new Project("project1");
177175

178176
Assert.assertTrue(

test/org/opensolaris/opengrok/configuration/GroupTest.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ private void testPattern(String pattern, boolean valid) {
114114

115115
@Test
116116
public void basicTest() {
117-
Group g = new Group();
118-
g.setName("Random name");
119-
g.setPattern("abcd");
117+
Group g = new Group("Random name", "abcd");
120118

121119
assertTrue(g.getName().equals("Random name"));
122120
assertTrue(g.getPattern().equals("abcd"));
@@ -154,15 +152,9 @@ public void basicTest() {
154152

155153
@Test
156154
public void subgroupsTest() {
157-
Group g1 = new Group();
158-
g1.setName("Random name");
159-
g1.setPattern("abcd");
160-
Group g2 = new Group();
161-
g2.setName("Random name2");
162-
g2.setPattern("efgh");
163-
Group g3 = new Group();
164-
g3.setName("Random name3");
165-
g3.setPattern("xyz");
155+
Group g1 = new Group("Random name", "abcd");
156+
Group g2 = new Group("Random name2", "efgh");
157+
Group g3 = new Group("Random name3", "xyz");
166158

167159
g1.getSubgroups().add(g2);
168160
g1.getSubgroups().add(g3);
@@ -197,12 +189,8 @@ public void subgroupsTest() {
197189

198190
@Test
199191
public void projectTest() {
200-
Group random1 = new Group();
201-
random1.setName("Random name");
202-
random1.setPattern("abcd");
203-
Group random2 = new Group();
204-
random2.setName("Random name2");
205-
random2.setPattern("efgh");
192+
Group random1 = new Group("Random name", "abcd");
193+
Group random2 = new Group("Random name2", "efgh");
206194

207195
random1.getSubgroups().add(random2);
208196

test/org/opensolaris/opengrok/configuration/RuntimeEnvironmentTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ public void testGroups() throws IOException {
156156
assertNotNull(instance.getGroups());
157157
assertEquals(0, instance.getGroups().size());
158158

159-
Group g = new Group();
160-
g.setName("Random");
161-
g.setPattern("xyz.*");
159+
Group g = new Group("Random", "xyz.*");
162160

163161
instance.getGroups().add(g);
164162
assertEquals(1, instance.getGroups().size());

test/org/opensolaris/opengrok/web/ProjectHelperTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ public void testSynchronization() {
8080
Project p = new Project("some random name not in any group");
8181

8282
// group
83-
Group g = new Group();
84-
g.setName("some random name of a group");
83+
Group g = new Group("some random name of a group");
8584

8685
// repository
8786
Project repo = new Project("some random name not in any other group");

test/org/opensolaris/opengrok/web/ProjectHelperTestBase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ protected static void createGroups(
116116
List<Group> grps) {
117117

118118
for (int i = start; i < start + cnt; i++) {
119-
Group g = new Group();
120-
g.setName((allowed ? "allowed_" : "") + "group_" + i);
119+
Group g = new Group((allowed ? "allowed_" : "") + "group_" + i);
121120
String pattern = "";
122121

123122
pattern += createProject(i, 1, true, false, false, rps, prjs, map).getName() + "|";

0 commit comments

Comments
 (0)