forked from eclipse-jdt/eclipse.jdt.core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable compilation progress reporting and cancellation
- Loading branch information
1 parent
f8014fb
commit 7cbf75d
Showing
3 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
...e.jdt.core.javac/src/org/eclipse/jdt/internal/javac/BuildNotifierCompilationProgress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Red Hat, Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.internal.javac; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import org.eclipse.core.runtime.ILog; | ||
import org.eclipse.jdt.core.compiler.CompilationProgress; | ||
import org.eclipse.jdt.internal.compiler.ICompilerRequestor; | ||
import org.eclipse.jdt.internal.core.builder.AbstractImageBuilder; | ||
import org.eclipse.jdt.internal.core.builder.BuildNotifier; | ||
|
||
/******************************************************************************* | ||
* Copyright (c) 2024 Red Hat, Inc. and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
public class BuildNotifierCompilationProgress extends CompilationProgress { | ||
|
||
private BuildNotifier buildNotifier; | ||
|
||
public BuildNotifierCompilationProgress(ICompilerRequestor requestor) { | ||
this.buildNotifier = findBuildNotifier(requestor); | ||
} | ||
|
||
private BuildNotifier findBuildNotifier(ICompilerRequestor requestor) { | ||
if (requestor instanceof AbstractImageBuilder) { | ||
try { | ||
Field notifierField = AbstractImageBuilder.class.getDeclaredField("notifier"); | ||
notifierField.setAccessible(true); | ||
return notifierField.get(requestor) instanceof BuildNotifier notifier ? notifier : null; | ||
} catch (Exception ex) { | ||
ILog.get().warn(ex.getMessage(), ex); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void begin(int remainingWork) { | ||
if (this.buildNotifier != null) { | ||
this.buildNotifier.checkCancelWithinCompiler(); | ||
} | ||
} | ||
|
||
@Override | ||
public void done() { | ||
// do not forward as done() is sent via requestor | ||
} | ||
|
||
@Override | ||
public boolean isCanceled() { | ||
if (this.buildNotifier != null) { | ||
this.buildNotifier.checkCancel(); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void setTaskName(String name) { | ||
if (this.buildNotifier != null) { | ||
this.buildNotifier.subTask(name); | ||
} | ||
} | ||
|
||
@Override | ||
public void worked(int workIncrement, int remainingWork) { | ||
// TODO Auto-generated method stub | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters