Skip to content

Commit f816124

Browse files
authored
Merge pull request #2123 from idodeclare/feature/die_w
Fix #431 : option -w should die
2 parents cfa7dbb + c94e44d commit f816124

File tree

14 files changed

+256
-86
lines changed

14 files changed

+256
-86
lines changed

OpenGrok

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ Supported Environment Variables for configuring the default setup:
133133
(by default 3 directories from SRC_ROOT)
134134
- OPENGROK_WEBAPP_CFGADDR Web app address to send configuration to
135135
(use "none" to avoid sending it to web app)
136-
- OPENGROK_WEBAPP_CONTEXT Context URL of the OpenGrok webapp
137-
(by default /source). FULL reindex is needed
138-
once this is used (old already indexed files
139-
won't be refreshed)
140136
- OPENGROK_WPREFIX Disable wildcard prefix search query support (*)
141137
- OPENGROK_TAG Enable parsing of revision tags into the History
142138
view
@@ -388,13 +384,6 @@ DefaultInstanceConfiguration()
388384
WEBAPP_CONFIG="-U ${WEBAPP_CONFIG_ADDRESS}"
389385
fi
390386

391-
# OPTIONAL: Context URL of the OpenGrok webapp
392-
# (default is /source)
393-
WEBAPP_CONTEXT=""
394-
if [ -n "${OPENGROK_WEBAPP_CONTEXT}" ]; then
395-
WEBAPP_CONTEXT="-w ${OPENGROK_WEBAPP_CONTEXT}"
396-
fi
397-
398387
# OPTIONAL: JVM Options
399388
JAVA_OPTS="${JAVA_OPTS:--Xmx2048m}"
400389

@@ -912,7 +901,6 @@ CommonInvocation()
912901
${ASSIGNMENTS} \
913902
${READ_XML_CONF} \
914903
${WEBAPP_CONFIG} \
915-
${WEBAPP_CONTEXT} \
916904
${OPENGROK_PROFILER:+--profiler} \
917905
"${@}"
918906
}

build.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
371371
<property name="gen.context.dir" value="/org/opensolaris/opengrok/search/context"/>
372372
<run-jflex dir="${gen.context.dir}" name="HistoryLineTokenizer"/>
373373
<run-jflex dir="${gen.context.dir}" name="PlainLineTokenizer"/>
374+
375+
<property name="gen.web.dir" value="/org/opensolaris/opengrok/web"/>
376+
<run-jflex dir="${gen.web.dir}" name="XrefSourceTransformer"/>
374377
</target>
375378

376379
<property name="git" value="git"/>

src/org/opensolaris/opengrok/analysis/AnalyzerGuru.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.io.BufferedReader;
2727
import java.io.File;
28+
import java.io.FileWriter;
2829
import java.io.IOException;
2930
import java.io.InputStream;
3031
import java.io.InputStreamReader;
@@ -631,6 +632,35 @@ public static void writeXref(FileAnalyzerFactory factory, Reader in,
631632
analyzer.writeXref(args);
632633
}
633634

635+
/**
636+
* Writes a browse-able version of the file transformed for immediate
637+
* serving to a web client.
638+
* @param contextPath the web context path for
639+
* {@link Util#dumpXref(java.io.Writer, java.io.Reader, java.lang.String)}
640+
* @param factory the analyzer factory for this file type
641+
* @param in the input stream containing the data
642+
* @param out a defined instance to write
643+
* @param defs definitions for the source file, if available
644+
* @param annotation annotation information for the file
645+
* @param project project the file belongs to
646+
* @throws java.io.IOException if an error occurs while creating the output
647+
*/
648+
public static void writeDumpedXref(String contextPath,
649+
FileAnalyzerFactory factory, Reader in, Writer out,
650+
Definitions defs, Annotation annotation, Project project)
651+
throws IOException {
652+
653+
File xrefTemp = File.createTempFile("ogxref", ".html");
654+
try {
655+
try (FileWriter tmpout = new FileWriter(xrefTemp)) {
656+
writeXref(factory, in, tmpout, defs, annotation, project);
657+
}
658+
Util.dumpXref(out, xrefTemp, false, contextPath);
659+
} finally {
660+
xrefTemp.delete();
661+
}
662+
}
663+
634664
/**
635665
* Get the genre of a file
636666
*

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ public final class Configuration {
144144
private String sourceRoot;
145145
private String dataRoot;
146146
private List<RepositoryInfo> repositories;
147+
/**
148+
* @deprecated This is kept around so not to break object deserialization
149+
* but it is ignored and cannot be truly set. This should mean that the
150+
* configuration is written leaving out this deprecated property; so after
151+
* some time it can be retired with the expectation that zero or a
152+
* miniscule number of production configurations still have this deprecated
153+
* property.
154+
*/
147155
private String urlPrefix;
148156
private boolean generateHtml;
149157
/**
@@ -461,8 +469,7 @@ public Configuration() {
461469
setStatisticsFilePath(null);
462470
//setTabSize(4);
463471
setTagsEnabled(false);
464-
setUrlPrefix("/source/s?");
465-
//setUrlPrefix("../s?"); // TODO generate relative search paths, get rid of -w <webapp> option to indexer !
472+
//urlPrefix's constant value is moved to RuntimeEnvironment.
466473
//setUserPage("http://www.myserver.org/viewProfile.jspa?username=");
467474
// Set to empty string so we can append it to the URL
468475
// unconditionally later.
@@ -812,15 +819,16 @@ public String getUrlPrefix() {
812819
}
813820

814821
/**
815-
* Set the URL prefix to be used by the {@link
816-
* org.opensolaris.opengrok.analysis.executables.JavaClassAnalyzer} as well
817-
* as lexers (see {@link org.opensolaris.opengrok.analysis.JFlexXref}) when
818-
* they create output with html links.
819-
*
820-
* @param urlPrefix prefix to use.
822+
* Formerly this allowed setting the URL prefix to be used for the Java
823+
* class analyzer and for language cross-referencing (xref) when they
824+
* created HTML links. Now, a static value is used and transformed as
825+
* necessary to the servlet {@code contextPath} so that users can deploy
826+
* OpenGrok as they like.
827+
* @param urlPrefix ignored
821828
*/
829+
@Deprecated
822830
public void setUrlPrefix(String urlPrefix) {
823-
this.urlPrefix = urlPrefix;
831+
// ignore the value
824832
}
825833

826834
public void setGenerateHtml(boolean generateHtml) {

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
import static org.opensolaris.opengrok.configuration.Configuration.makeXMLStringAsConfiguration;
104104
import org.opensolaris.opengrok.util.ForbiddenSymlinkException;
105105
import org.opensolaris.opengrok.util.PathUtils;
106+
import org.opensolaris.opengrok.web.Prefix;
106107

107108
/**
108109
* The RuntimeEnvironment class is used as a placeholder for the current
@@ -112,6 +113,9 @@ public final class RuntimeEnvironment {
112113

113114
private static final Logger LOGGER = LoggerFactory.getLogger(RuntimeEnvironment.class);
114115

116+
/** {@code "/source"} + {@link Prefix#SEARCH_R} + {@code "?"} */
117+
private static final String URL_PREFIX = "/source" + Prefix.SEARCH_R + "?";
118+
115119
private Configuration configuration;
116120
private final ThreadLocal<Configuration> threadConfig;
117121
private static final RuntimeEnvironment instance = new RuntimeEnvironment();
@@ -556,21 +560,12 @@ public Map<Project, List<RepositoryInfo>> getProjectRepositoriesMap() {
556560
}
557561

558562
/**
559-
* Get the context name of the web application
560-
*
561-
* @return the web applications context name
563+
* Gets a static placeholder for the web application context name that is
564+
* translated to the true servlet {@code contextPath} on demand.
565+
* @return {@code "/source"} + {@link Prefix#SEARCH_R} + {@code "?"}
562566
*/
563567
public String getUrlPrefix() {
564-
return threadConfig.get().getUrlPrefix();
565-
}
566-
567-
/**
568-
* Set the web context name
569-
*
570-
* @param urlPrefix the web applications context name
571-
*/
572-
public void setUrlPrefix(String urlPrefix) {
573-
threadConfig.get().setUrlPrefix(urlPrefix);
568+
return URL_PREFIX;
574569
}
575570

576571
/**

src/org/opensolaris/opengrok/index/Indexer.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -771,22 +771,6 @@ public static String[] parseOptions(String[] argv) throws ParseException {
771771
"(so that the web application can use the same configuration)").Do( configFile -> {
772772
configFilename = (String)configFile;
773773
});
774-
775-
parser.on("-w", "--web", "=webapp-context",
776-
"Context of webapp. Default is /source. If you specify a different",
777-
"name, make sure to rename source.war to that name. Also FULL reindex",
778-
"is needed if this is changed.").
779-
Do( webContext -> {
780-
String webapp = (String)webContext;
781-
if (webapp.charAt(0) != '/' && !webapp.startsWith("http")) {
782-
webapp = "/" + webapp;
783-
}
784-
if (!webapp.endsWith("/")) {
785-
webapp += "/";
786-
}
787-
cfg.setUrlPrefix(webapp + "s?");
788-
}
789-
);
790774
});
791775

792776
// Need to read the configuration file first

src/org/opensolaris/opengrok/web/Util.java

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525

2626
package org.opensolaris.opengrok.web;
2727

28+
import java.io.BufferedInputStream;
2829
import java.io.File;
2930
import java.io.FileInputStream;
30-
import java.io.FileReader;
3131
import java.io.IOException;
32+
import java.io.InputStream;
3233
import java.io.InputStreamReader;
3334
import java.io.Reader;
3435
import java.io.UnsupportedEncodingException;
@@ -1169,10 +1170,10 @@ public static boolean dump(Writer out, File file, boolean compressed) {
11691170
* For backward compatibility, read the OpenGrok-produced document
11701171
* using the system default charset.
11711172
*/
1172-
try (Reader in = compressed
1173-
? new InputStreamReader(new GZIPInputStream(
1174-
new FileInputStream(file)))
1175-
: new FileReader(file)) {
1173+
try (InputStream iss = new BufferedInputStream(
1174+
new FileInputStream(file))) {
1175+
Reader in = compressed ? new InputStreamReader(new GZIPInputStream(
1176+
iss)) : new InputStreamReader(iss);
11761177
dump(out, in);
11771178
return true;
11781179
} catch (IOException e) {
@@ -1182,6 +1183,61 @@ public static boolean dump(Writer out, File file, boolean compressed) {
11821183
return false;
11831184
}
11841185

1186+
/**
1187+
* Silently dump an xref file to the given destination. All
1188+
* {@link IOException}s get caught and logged, but not re-thrown.
1189+
* @param out dump destination
1190+
* @param file file to dump
1191+
* @param compressed if {@code true} the denoted file is assumed to be
1192+
* gzipped
1193+
* @param contextPath an optional override of "/source/" as the context path
1194+
* @return {@code true} on success (everything read and written)
1195+
* @throws NullPointerException if a parameter is {@code null}.
1196+
*/
1197+
public static boolean dumpXref(Writer out, File file, boolean compressed,
1198+
String contextPath) {
1199+
if (!file.exists()) {
1200+
return false;
1201+
}
1202+
/**
1203+
* For backward compatibility, read the OpenGrok-produced document
1204+
* using the system default charset.
1205+
*/
1206+
try (InputStream iss = new BufferedInputStream(
1207+
new FileInputStream(file))) {
1208+
Reader in = compressed ? new InputStreamReader(new GZIPInputStream(
1209+
iss)) : new InputStreamReader(iss);
1210+
dumpXref(out, in, contextPath);
1211+
return true;
1212+
} catch (IOException e) {
1213+
LOGGER.log(Level.WARNING, "An error occured while piping file " +
1214+
file, e);
1215+
}
1216+
return false;
1217+
}
1218+
1219+
/**
1220+
* Silently dump an xref file to the given destination. All
1221+
* {@link IOException}s get caught and logged, but not re-thrown.
1222+
* @param out dump destination
1223+
* @param in source to read
1224+
* @param contextPath an optional override of "/source/" as the context path
1225+
* @throws IOException as defined by the given reader/writer
1226+
* @throws NullPointerException if a parameter is {@code null}.
1227+
*/
1228+
public static void dumpXref(Writer out, Reader in, String contextPath)
1229+
throws IOException {
1230+
if (in == null || out == null) {
1231+
return;
1232+
}
1233+
XrefSourceTransformer xform = new XrefSourceTransformer(in);
1234+
xform.setWriter(out);
1235+
xform.setContextPath(contextPath);
1236+
while (xform.yylex()) {
1237+
// Nothing else to do.
1238+
}
1239+
}
1240+
11851241
/**
11861242
* Print list of messages into output
11871243
*

0 commit comments

Comments
 (0)