Skip to content

Commit

Permalink
Make CodeServer force next recompile after clearing cache.
Browse files Browse the repository at this point in the history
When navigating to the CodeServer web page (http://localhost:9876/), the
clean button will clear caches, but does not force the next recompile.
If no changes were made to your module, the next compile will say
"skipped compile because no input files have changed."

If you're cleaning the caches, it's presumably because you're having
some issues — in which case serving up the previous compile doesn't make
much sense. This forces you to make some arbitrary change to your module
to force the recompile.

Using the clean button should always force the next recompile.

Closes #9293 on GitHub

Change-Id: I55f599900ea8f2e9752862c00a2bc255dae894c1
  • Loading branch information
dsbecker authored and tbroyer committed Mar 14, 2016
1 parent 21a0b30 commit f187d80
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
12 changes: 8 additions & 4 deletions dev/codeserver/java/com/google/gwt/dev/codeserver/JobRunner.java
Expand Up @@ -48,10 +48,10 @@ public class JobRunner {
/**
* Submits a cleaner job to be executed. (Waits for completion.)
*/
void clean(TreeLogger logger) throws ExecutionException {
void clean(final TreeLogger logger, final OutboxTable outboxTable) throws ExecutionException {
try {
TreeLogger branch = logger.branch(TreeLogger.INFO, "Cleaning disk caches.");
executor.submit(new CleanerJob(branch)).get();
executor.submit(new CleanerJob(branch, outboxTable)).get();
} catch (InterruptedException e) {
// Allow the JVM to shutdown.
}
Expand Down Expand Up @@ -114,24 +114,28 @@ private static void recompile(Job job) {
}

/**
* A callable for clearing both unit and minimalRebuild caches.
* A callable for clearing both unit and minimalRebuild caches. It also forces the next recompile
* even if no input files have changed.
* <p>
* By packaging it as a callable and running it in the ExecutorService any danger of clearing
* caches at the same time as an active compile job is avoided.
*/
private class CleanerJob implements Callable<Void> {

private final OutboxTable outboxTable;
private TreeLogger logger;

public CleanerJob(TreeLogger logger) {
public CleanerJob(final TreeLogger logger, final OutboxTable outboxTable) {
this.logger = logger;
this.outboxTable = outboxTable;
}

@Override
public Void call() throws UnableToCompleteException {
long beforeMs = System.nanoTime() / 1000000L;
minimalRebuildCacheManager.deleteCaches();
UnitCacheSingleton.clearCache();
outboxTable.forceNextRecompileAll();
long afterMs = System.nanoTime() / 1000000L;
logger.log(TreeLogger.INFO, String.format("Cleaned in %sms.", (afterMs - beforeMs)));
return null;
Expand Down
7 changes: 7 additions & 0 deletions dev/codeserver/java/com/google/gwt/dev/codeserver/Outbox.java
Expand Up @@ -65,6 +65,13 @@ private boolean isValidOutboxId(String id) {
return ModuleDef.isValidModuleName(id);
}

/**
* Forces the next recompile even if no input files have changed.
*/
void forceNextRecompile() {
recompiler.forceNextRecompile();
}

/**
* A unique id for this outbox. (This should be treated as an opaque string.)
*/
Expand Down
Expand Up @@ -81,6 +81,12 @@ void defaultCompileAll(TreeLogger logger) throws UnableToCompleteException {
}
}

void forceNextRecompileAll() {
for (Outbox box: outboxes.values()) {
box.forceNextRecompile();
}
}

/**
* Given the name of a policy file, searches all the boxes for a file with that name.
* Returns null if not found.
Expand Down
Expand Up @@ -99,6 +99,13 @@ public class Recompiler {
compilerContext = compilerContextBuilder.build();
}

/**
* Forces the next recompile even if no input files have changed.
*/
void forceNextRecompile() {
previousInputSummary = null;
}

/**
* Compiles the first time, while Super Dev Mode is starting up.
* Either this method or {@link #initWithoutPrecompile} should be called first.
Expand Down Expand Up @@ -336,7 +343,7 @@ private boolean doCompile(TreeLogger compileLogger, CompileDir compileDir, Job j
return true;
}
// Force a recompile if we don't succeed.
previousInputSummary = null;
forceNextRecompile();

job.onProgress("Compiling");

Expand Down
Expand Up @@ -232,7 +232,7 @@ private Response doGet(String target, HttpServletRequest request, TreeLogger log
if (target.startsWith("/clean")) {
JsonObject json = null;
try {
runner.clean(logger);
runner.clean(logger, outboxes);
json = jsonExporter.exportOk("Cleaned disk caches.");
} catch (ExecutionException e) {
json = jsonExporter.exportError(e.getMessage());
Expand Down

0 comments on commit f187d80

Please sign in to comment.