Skip to content

Commit 9e3bf04

Browse files
committed
Merge remote-tracking branch 'upstream/master' into mavenize
# Conflicts: # opengrok-web/src/main/java/org/opengrok/web/AuthorizationFilter.java
2 parents b2f411e + d14d7a6 commit 9e3bf04

File tree

11 files changed

+191
-30
lines changed

11 files changed

+191
-30
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/Repository.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,16 +540,18 @@ static Boolean checkCmd(String... args) {
540540
* @see #RepoCommand
541541
*/
542542
protected String ensureCommand(String propertyKey, String fallbackCommand) {
543+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
544+
543545
if (RepoCommand != null) {
544546
return RepoCommand;
545547
}
546-
RepoCommand = RuntimeEnvironment.getInstance()
547-
.getRepoCmd(this.getClass().getCanonicalName());
548+
549+
RepoCommand = env.getRepoCmd(this.getClass().getCanonicalName());
548550
if (RepoCommand == null) {
549551
RepoCommand = System.getProperty(propertyKey, fallbackCommand);
550-
RuntimeEnvironment.getInstance()
551-
.setRepoCmd(this.getClass().getCanonicalName(), RepoCommand);
552+
env.setRepoCmd(this.getClass().getCanonicalName(), RepoCommand);
552553
}
554+
553555
return RepoCommand;
554556
}
555557

opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,10 @@ public static void main(String argv[]) {
201201
IndexVersion.check(checkIndexVersionCfg, subFilesList);
202202
} catch (IndexVersionException e) {
203203
System.err.printf("Index version check failed: %s\n", e);
204-
System.err.printf("You might want to remove all data " +
205-
"under the DATA_ROOT and to reindex\n");
204+
System.err.printf("You might want to remove " +
205+
(subFilesList.size() > 0 ?
206+
"data for projects " + String.join(",", subFilesList) : "all data") +
207+
" under the DATA_ROOT and to reindex\n");
206208
status = 1;
207209
System.exit(status);
208210
}

opengrok-indexer/src/main/java/org/opengrok/indexer/search/SearchEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ public IndexSearcher getSearcher() {
290290
*/
291291
public int search(HttpServletRequest req, String... projectNames) {
292292
ProjectHelper pHelper = PageConfig.get(req).getProjectHelper();
293-
Set<Project> projects = pHelper.getAllProjects();
293+
Set<Project> allProjects = pHelper.getAllProjects();
294294
List<Project> filteredProjects = new ArrayList<Project>();
295-
for(Project project: projects) {
295+
for(Project project: allProjects) {
296296
for (String name : projectNames) {
297297
if (project.getName().equalsIgnoreCase(name)) {
298298
filteredProjects.add(project);

opengrok-indexer/src/test/java/org/opengrok/indexer/history/SCCSRepositoryTest.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
package org.opengrok.indexer.history;
2525

2626
import java.io.File;
27+
import java.io.IOException;
28+
import java.nio.file.Files;
2729
import org.junit.After;
2830
import org.junit.AfterClass;
2931
import org.junit.Before;
3032
import org.junit.BeforeClass;
3133
import org.junit.Test;
32-
import static org.junit.Assert.*;
34+
import static org.junit.Assert.assertEquals;
3335

3436
/**
3537
*
@@ -59,16 +61,33 @@ public void tearDown() {
5961
/**
6062
* Test of isRepositoryFor method, of class SCCSRepository.
6163
*/
64+
private void testIsRepositoryFor(final String fileName, boolean shouldPass) throws IOException {
65+
File tdir = Files.createTempDirectory("SCCSrepotest" + fileName).toFile();
66+
File test = new File(tdir, fileName);
67+
test.mkdirs();
68+
tdir.deleteOnExit();
69+
test.deleteOnExit();
70+
SCCSRepository instance = new SCCSRepository();
71+
assertEquals(shouldPass, instance.isRepositoryFor(tdir));
72+
}
73+
6274
@Test
63-
public void testIsRepositoryFor() {
64-
//test bug 15954
65-
File tdir = new File(System.getProperty("java.io.tmpdir")+File.separator+"testogrepo");
66-
File test = new File(tdir,"Codemgr_wsdata");
67-
test.mkdirs();//TODO fix FileUtilities to not leave over dummy directories in tmp and then use them here ;)
68-
SCCSRepository instance = new SCCSRepository();
69-
assertTrue(instance.isRepositoryFor(tdir));
70-
test.delete();
71-
tdir.delete();
75+
public void testIsRepositoryForCodemgr1() throws IOException {
76+
testIsRepositoryFor("Codemgr_wsdata", true);
77+
}
78+
79+
@Test
80+
public void testIsRepositoryForCodemgr2() throws IOException {
81+
testIsRepositoryFor("codemgr_wsdata", true);
82+
}
83+
84+
@Test
85+
public void testIsRepositoryForCodemgr3() throws IOException {
86+
testIsRepositoryFor("SCCS", true);
87+
}
88+
89+
@Test
90+
public void testIsRepositoryForCodemgrNot() throws IOException {
91+
testIsRepositoryFor("NOT", false);
7292
}
73-
7493
}

opengrok-web/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@
110110
<url>${tomcat.url}</url>
111111
</configuration>
112112
</plugin>
113+
<plugin>
114+
<groupId>org.apache.tomcat.maven</groupId>
115+
<artifactId>tomcat7-maven-plugin</artifactId>
116+
<version>2.2</version>
117+
<configuration>
118+
<url>http://localhost:8080/manager/text</url>
119+
<server>OpenGrok</server>
120+
<path>/${project.build.finalName}</path>
121+
</configuration>
122+
</plugin>
113123
</plugins>
114124
</build>
115125

opengrok-web/src/main/java/org/opengrok/web/AuthorizationFilter.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import javax.servlet.http.HttpServletResponse;
3636
import org.opengrok.indexer.configuration.Project;
3737
import org.opengrok.indexer.logger.LoggerFactory;
38-
import org.opengrok.indexer.web.PageConfig;
38+
import org.opengrok.indexer.web.api.v1.RestApp;
3939

4040
public class AuthorizationFilter implements Filter {
4141

@@ -50,6 +50,16 @@ public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc) thr
5050
HttpServletRequest httpReq = (HttpServletRequest) sr;
5151
HttpServletResponse httpRes = (HttpServletResponse) sr1;
5252

53+
// All RESTful API requests are allowed for now (also see LocalhostFilter).
54+
// The /search endpoint will go through authorization via SearchEngine.search()
55+
// so does not have to be exempted here.
56+
if (httpReq.getServletPath().startsWith(RestApp.API_PATH)) {
57+
LOGGER.log(Level.FINER, "Allowing request to {0} in {1}",
58+
new Object[]{ httpReq.getServletPath(), AuthorizationFilter.class.getName() });
59+
fc.doFilter(sr, sr1);
60+
return;
61+
}
62+
5363
PageConfig config = PageConfig.get(httpReq);
5464
long processTime = System.currentTimeMillis();
5565

opengrok-web/src/main/java/org/opengrok/web/api/v1/RestApp.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626

2727
import javax.ws.rs.ApplicationPath;
2828

29-
@ApplicationPath("/api/v1")
29+
@ApplicationPath(RestApp.API_PATH)
3030
public class RestApp extends ResourceConfig {
3131

32+
public static final String API_PATH = "/api/v1";
33+
3234
public RestApp() {
3335
packages("org.opengrok.web.api.v1.controller", "org.opengrok.web.api.v1.filter");
3436
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opensolaris.opengrok.history;
24+
25+
import java.io.File;
26+
import java.lang.reflect.InvocationTargetException;
27+
import org.junit.AfterClass;
28+
import static org.junit.Assert.assertFalse;
29+
import org.junit.BeforeClass;
30+
import org.junit.Test;
31+
import org.opensolaris.opengrok.util.TestRepository;
32+
33+
/**
34+
* Test RepositoryFactory
35+
*
36+
* @author Vladimir Kotal
37+
*/
38+
public class RepositoryFactoryTest {
39+
private static TestRepository repository;
40+
41+
@BeforeClass
42+
public static void setUpClass() throws Exception {
43+
repository = new TestRepository();
44+
repository.create(RepositoryFactory.class.getResourceAsStream("repositories.zip"));
45+
}
46+
47+
@AfterClass
48+
public static void tearDown() {
49+
if (repository != null) {
50+
repository.destroy();
51+
repository = null;
52+
}
53+
}
54+
55+
/*
56+
* There is no conditonal run based on whether given repository is installed because
57+
* this test is not supposed to have working Mercurial anyway.
58+
*/
59+
private void testNotWorkingRepository(String repoPath, String propName)
60+
throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
61+
62+
String origPropValue = System.setProperty(propName, "/foo/bar/nonexistent");
63+
File root = new File(repository.getSourceRoot(), repoPath);
64+
Repository repo = RepositoryFactory.getRepository(root);
65+
if (origPropValue != null) {
66+
System.setProperty(propName, origPropValue);
67+
}
68+
assertFalse(repo.isWorking());
69+
}
70+
71+
@Test
72+
public void testNotWorkingMercurialRepository()
73+
throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
74+
testNotWorkingRepository("mercurial", MercurialRepository.CMD_PROPERTY_KEY);
75+
}
76+
77+
@Test
78+
public void testNotWorkingBitkeeperRepository()
79+
throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
80+
testNotWorkingRepository("bitkeeper", BitKeeperRepository.CMD_PROPERTY_KEY);
81+
}
82+
}

tools/sync/command.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ class Command:
4949
TIMEDOUT = "timed out"
5050

5151
def __init__(self, cmd, args_subst=None, args_append=None, logger=None,
52-
excl_subst=False, work_dir=None, env_vars=None, timeout=None):
52+
excl_subst=False, work_dir=None, env_vars=None, timeout=None,
53+
redirect_stderr=True):
5354
self.cmd = cmd
5455
self.state = "notrun"
5556
self.excl_subst = excl_subst
5657
self.work_dir = work_dir
5758
self.env_vars = env_vars
5859
self.timeout = timeout
5960
self.pid = None
61+
self.redirect_stderr = redirect_stderr
6062

6163
self.logger = logger or logging.getLogger(__name__)
6264
logging.basicConfig()
@@ -167,8 +169,18 @@ def close(self):
167169
return
168170

169171
timeout_thread = None
170-
event = threading.Event()
171-
output_thread = OutputThread(event, self.logger)
172+
output_event = threading.Event()
173+
output_thread = OutputThread(output_event, self.logger)
174+
175+
# If stderr redirection is off, setup a thread that will capture
176+
# stderr data.
177+
if self.redirect_stderr:
178+
stderr_dest = subprocess.STDOUT
179+
else:
180+
stderr_event = threading.Event()
181+
stderr_thread = OutputThread(stderr_event, self.logger)
182+
stderr_dest = stderr_thread
183+
172184
try:
173185
start_time = time.time()
174186
try:
@@ -179,10 +191,10 @@ def close(self):
179191
if self.env_vars:
180192
my_env = os.environ.copy()
181193
my_env.update(self.env_vars)
182-
p = subprocess.Popen(self.cmd, stderr=subprocess.STDOUT,
194+
p = subprocess.Popen(self.cmd, stderr=stderr_dest,
183195
stdout=output_thread, env=my_env)
184196
else:
185-
p = subprocess.Popen(self.cmd, stderr=subprocess.STDOUT,
197+
p = subprocess.Popen(self.cmd, stderr=stderr_dest,
186198
stdout=output_thread)
187199

188200
self.pid = p.pid
@@ -226,9 +238,15 @@ def close(self):
226238
# exit the read loop we have to close it here ourselves.
227239
output_thread.close()
228240
self.logger.debug("Waiting on output thread to finish reading")
229-
event.wait()
230-
241+
output_event.wait()
231242
self.out = output_thread.getoutput()
243+
244+
if not self.redirect_stderr:
245+
stderr_thread.close()
246+
self.logger.debug("Waiting on stderr thread to finish reading")
247+
stderr_event.wait()
248+
self.err = stderr_thread.getoutput()
249+
232250
elapsed_time = time.time() - start_time
233251
self.logger.debug("Command {} took {} seconds".
234252
format(self.cmd, int(elapsed_time)))
@@ -286,6 +304,9 @@ def getoutput(self):
286304
else:
287305
return None
288306

307+
def geterroutput(self):
308+
return self.err
309+
289310
def getstate(self):
290311
return self.state
291312

tools/sync/projadm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ def exec_command(doit, logger, cmd, msg):
5555
Execute given command and return its output.
5656
Exit the program on failure.
5757
"""
58-
cmd = Command(cmd, logger=logger)
58+
cmd = Command(cmd, logger=logger, redirect_stderr=False)
5959
if not doit:
6060
logger.info(cmd)
6161
return
6262
cmd.execute()
6363
if cmd.getstate() is not Command.FINISHED or cmd.getretcode() != 0:
6464
logger.error(msg)
65-
logger.error(cmd.getoutput())
65+
logger.error("Standard output: {}".format(cmd.getoutput()))
66+
logger.error("Error output: {}".format(cmd.geterroutput()))
6667
sys.exit(1)
6768

6869
return cmd.getoutput()

0 commit comments

Comments
 (0)