Skip to content

Commit

Permalink
Code clean-up - formatting. No functional change.
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Nov 22, 2024
1 parent 29285c6 commit 5792736
Show file tree
Hide file tree
Showing 14 changed files with 419 additions and 610 deletions.
67 changes: 30 additions & 37 deletions java/org/apache/jasper/compiler/AntCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ protected Project getProject() {
logger.setOutputPrintStream(System.out);
logger.setErrorPrintStream(System.err);
logger.setMessageOutputLevel(Project.MSG_INFO);
project.addBuildListener( logger);
project.addBuildListener(logger);
if (System.getProperty(Constants.CATALINA_HOME_PROP) != null) {
project.setBasedir(System.getProperty(Constants.CATALINA_HOME_PROP));
}

if( options.getCompiler() != null ) {
if( log.isTraceEnabled() ) {
log.trace("Compiler " + options.getCompiler() );
if (options.getCompiler() != null) {
if (log.isTraceEnabled()) {
log.trace("Compiler " + options.getCompiler());
}
project.setProperty("build.compiler", options.getCompiler() );
project.setProperty("build.compiler", options.getCompiler());
}
project.init();
return project;
Expand All @@ -95,9 +95,7 @@ public static class JasperAntLogger extends DefaultLogger {
protected final StringBuilder reportBuf = new StringBuilder();

@Override
protected void printMessage(final String message,
final PrintStream stream,
final int priority) {
protected void printMessage(final String message, final PrintStream stream, final int priority) {
}

@Override
Expand All @@ -118,7 +116,7 @@ protected String getReport() {

@Override
protected void generateClass(Map<String,SmapStratum> smaps)
throws FileNotFoundException, JasperException, Exception {
throws FileNotFoundException, JasperException, Exception {

long t1 = 0;
if (log.isDebugEnabled()) {
Expand All @@ -131,9 +129,9 @@ protected void generateClass(Map<String,SmapStratum> smaps)

StringBuilder errorReport = new StringBuilder();

StringBuilder info=new StringBuilder();
info.append("Compile: javaFileName=" + javaFileName + "\n" );
info.append(" classpath=" + classpath + "\n" );
StringBuilder info = new StringBuilder();
info.append("Compile: javaFileName=" + javaFileName + "\n");
info.append(" classpath=" + classpath + "\n");

// Start capturing the System.err output for this thread
SystemLogHandler.setThread();
Expand All @@ -155,8 +153,7 @@ protected void generateClass(Map<String,SmapStratum> smaps)
}

if (log.isTraceEnabled()) {
log.trace( "Using classpath: " + System.getProperty("java.class.path") +
File.pathSeparator + classpath);
log.trace("Using classpath: " + System.getProperty("java.class.path") + File.pathSeparator + classpath);
}

// Initializing sourcepath
Expand All @@ -176,15 +173,12 @@ protected void generateClass(Map<String,SmapStratum> smaps)

// Add endorsed directories if any are specified and we're forking
// See Bugzilla 31257
if(ctxt.getOptions().getFork()) {
if (ctxt.getOptions().getFork()) {
String endorsed = System.getProperty("java.endorsed.dirs");
if(endorsed != null) {
Javac.ImplementationSpecificArgument endorsedArg =
javac.createCompilerArg();
endorsedArg.setLine("-J-Djava.endorsed.dirs=" +
quotePathList(endorsed));
info.append(" endorsed dir=" + quotePathList(endorsed) +
"\n");
if (endorsed != null) {
Javac.ImplementationSpecificArgument endorsedArg = javac.createCompilerArg();
endorsedArg.setLine("-J-Djava.endorsed.dirs=" + quotePathList(endorsed));
info.append(" endorsed dir=" + quotePathList(endorsed) + "\n");
} else {
info.append(" no endorsed dirs specified\n");
}
Expand All @@ -197,7 +191,7 @@ protected void generateClass(Map<String,SmapStratum> smaps)
javac.setSrcdir(srcPath);
javac.setTempdir(options.getScratchDir());
javac.setFork(ctxt.getOptions().getFork());
info.append(" srcDir=" + srcPath + "\n" );
info.append(" srcDir=" + srcPath + "\n");

// Set the Java compiler to use
if (options.getCompiler() != null) {
Expand All @@ -219,15 +213,15 @@ protected void generateClass(Map<String,SmapStratum> smaps)
PatternSet.NameEntry includes = javac.createInclude();

includes.setName(ctxt.getJavaPath());
info.append(" include="+ ctxt.getJavaPath() + "\n" );
info.append(" include=" + ctxt.getJavaPath() + "\n");

BuildException be = null;

try {
if (ctxt.getOptions().getFork()) {
javac.execute();
} else {
synchronized(javacLock) {
synchronized (javacLock) {
javac.execute();
}
}
Expand All @@ -249,24 +243,23 @@ protected void generateClass(Map<String,SmapStratum> smaps)
if (!ctxt.keepGenerated()) {
File javaFile = new File(javaFileName);
if (!javaFile.delete()) {
throw new JasperException(Localizer.getMessage(
"jsp.warning.compiler.javafile.delete.fail", javaFile));
throw new JasperException(Localizer.getMessage("jsp.warning.compiler.javafile.delete.fail", javaFile));
}
}

if (be != null) {
String errorReportString = errorReport.toString();
log.error(Localizer.getMessage("jsp.error.compilation", javaFileName, errorReportString));
JavacErrorDetail[] javacErrors = ErrorDispatcher.parseJavacErrors(
errorReportString, javaFileName, pageNodes);
JavacErrorDetail[] javacErrors =
ErrorDispatcher.parseJavacErrors(errorReportString, javaFileName, pageNodes);
if (javacErrors != null) {
errDispatcher.javacError(javacErrors);
} else {
errDispatcher.javacError(errorReportString, be);
}
}

if( log.isDebugEnabled() ) {
if (log.isDebugEnabled()) {
long t2 = System.currentTimeMillis();
log.debug(Localizer.getMessage("jsp.compiled", ctxt.getServletJavaFileName(), Long.valueOf(t2 - t1)));
}
Expand Down Expand Up @@ -312,6 +305,7 @@ protected static class SystemLogHandler extends PrintStream {

/**
* Construct the handler to capture the output of the given steam.
*
* @param wrapped The wrapped stream
*/
public SystemLogHandler(PrintStream wrapped) {
Expand All @@ -332,15 +326,13 @@ public SystemLogHandler(PrintStream wrapped) {
/**
* Thread &lt;-&gt; PrintStream associations.
*/
protected static final ThreadLocal<PrintStream> streams =
new ThreadLocal<>();
protected static final ThreadLocal<PrintStream> streams = new ThreadLocal<>();


/**
* Thread &lt;-&gt; ByteArrayOutputStream associations.
*/
protected static final ThreadLocal<ByteArrayOutputStream> data =
new ThreadLocal<>();
protected static final ThreadLocal<ByteArrayOutputStream> data = new ThreadLocal<>();


// --------------------------------------------------------- Public Methods
Expand All @@ -357,6 +349,7 @@ public static void setThread() {

/**
* Stop capturing thread's output and return captured data as a String.
*
* @return the captured output
*/
public static String unsetThread() {
Expand All @@ -375,6 +368,7 @@ public static String unsetThread() {

/**
* Find PrintStream to which the output must be written to.
*
* @return the current stream
*/
protected PrintStream findStream() {
Expand Down Expand Up @@ -406,7 +400,7 @@ public boolean checkError() {

@Override
protected void setError() {
//findStream().setError();
// findStream().setError();
}

@Override
Expand All @@ -415,8 +409,7 @@ public void write(int b) {
}

@Override
public void write(byte[] b)
throws IOException {
public void write(byte[] b) throws IOException {
findStream().write(b);
}

Expand Down
Loading

0 comments on commit 5792736

Please sign in to comment.