use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class CompilerPathsEx method getOutputPaths.
@NotNull
public static String[] getOutputPaths(@NotNull Module[] modules) {
Set<String> outputPaths = new OrderedSet<>();
for (Module module : modules) {
CompilerModuleExtension compilerModuleExtension = !module.isDisposed() ? CompilerModuleExtension.getInstance(module) : null;
if (compilerModuleExtension == null)
continue;
String outputPathUrl = compilerModuleExtension.getCompilerOutputUrl();
if (outputPathUrl != null) {
outputPaths.add(VirtualFileManager.extractPath(outputPathUrl).replace('/', File.separatorChar));
}
String outputPathForTestsUrl = compilerModuleExtension.getCompilerOutputUrlForTests();
if (outputPathForTestsUrl != null) {
outputPaths.add(VirtualFileManager.extractPath(outputPathForTestsUrl).replace('/', File.separatorChar));
}
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
for (OrderEnumerationHandler.Factory handlerFactory : OrderEnumerationHandler.EP_NAME.getExtensions()) {
if (handlerFactory.isApplicable(module)) {
OrderEnumerationHandler handler = handlerFactory.createHandler(module);
List<String> outputUrls = new SmartList<>();
handler.addCustomModuleRoots(OrderRootType.CLASSES, moduleRootManager, outputUrls, true, true);
for (String outputUrl : outputUrls) {
outputPaths.add(VirtualFileManager.extractPath(outputUrl).replace('/', File.separatorChar));
}
}
}
}
return ArrayUtil.toStringArray(outputPaths);
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class ProjectTaskManagerImpl method run.
@Override
public void run(@NotNull ProjectTaskContext context, @NotNull ProjectTask projectTask, @Nullable ProjectTaskNotification callback) {
List<Pair<ProjectTaskRunner, Collection<? extends ProjectTask>>> toRun = new SmartList<>();
Consumer<Collection<? extends ProjectTask>> taskClassifier = tasks -> {
Map<ProjectTaskRunner, ? extends List<? extends ProjectTask>> toBuild = tasks.stream().collect(Collectors.groupingBy(aTask -> {
for (ProjectTaskRunner runner : getTaskRunners()) {
if (runner.canRun(aTask))
return runner;
}
return myDefaultProjectTaskRunner;
}));
for (Map.Entry<ProjectTaskRunner, ? extends List<? extends ProjectTask>> entry : toBuild.entrySet()) {
toRun.add(Pair.create(entry.getKey(), entry.getValue()));
}
};
visitTasks(projectTask instanceof ProjectTaskList ? (ProjectTaskList) projectTask : Collections.singleton(projectTask), taskClassifier);
if (toRun.isEmpty()) {
sendSuccessNotify(callback);
return;
}
AtomicInteger inProgressCounter = new AtomicInteger(toRun.size());
AtomicInteger errorsCounter = new AtomicInteger();
AtomicInteger warningsCounter = new AtomicInteger();
AtomicBoolean abortedFlag = new AtomicBoolean(false);
ProjectTaskNotification chunkStatusNotification = callback == null ? null : new ProjectTaskNotification() {
@Override
public void finished(@NotNull ProjectTaskResult executionResult) {
int inProgress = inProgressCounter.decrementAndGet();
int allErrors = errorsCounter.addAndGet(executionResult.getErrors());
int allWarnings = warningsCounter.addAndGet(executionResult.getWarnings());
if (executionResult.isAborted()) {
abortedFlag.set(true);
}
if (inProgress == 0) {
callback.finished(new ProjectTaskResult(abortedFlag.get(), allErrors, allWarnings));
}
}
};
toRun.forEach(pair -> {
if (pair.second.isEmpty()) {
sendSuccessNotify(chunkStatusNotification);
} else {
pair.first.run(myProject, context, chunkStatusNotification, pair.second);
}
});
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class CompilerManagerImpl method compileJavaCode.
@Override
public Collection<ClassObject> compileJavaCode(List<String> options, Collection<File> platformCp, Collection<File> classpath, Collection<File> modulePath, Collection<File> sourcePath, Collection<File> files, File outputDir) throws IOException, CompilationException {
final Pair<Sdk, JavaSdkVersion> runtime = BuildManager.getJavacRuntimeSdk(myProject);
final Sdk sdk = runtime.getFirst();
final SdkTypeId type = sdk.getSdkType();
String javaHome = null;
if (type instanceof JavaSdkType) {
javaHome = sdk.getHomePath();
if (!isJdkOrJre(javaHome)) {
// this can be a java-dependent SDK, implementing JavaSdkType
// hack, because there is no direct way to obtain the java sdk, this sdk depends on
final String binPath = ((JavaSdkType) type).getBinPath(sdk);
javaHome = binPath != null ? new File(binPath).getParent() : null;
if (!isJdkOrJre(javaHome)) {
javaHome = null;
}
}
}
if (javaHome == null) {
throw new IOException("Was not able to determine JDK for project " + myProject.getName());
}
final OutputCollector outputCollector = new OutputCollector();
DiagnosticCollector diagnostic = new DiagnosticCollector();
final Set<File> sourceRoots = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
if (!sourcePath.isEmpty()) {
for (File file : sourcePath) {
sourceRoots.add(file);
}
} else {
for (File file : files) {
final File parentFile = file.getParentFile();
if (parentFile != null) {
sourceRoots.add(parentFile);
}
}
}
final Map<File, Set<File>> outs = Collections.singletonMap(outputDir, sourceRoots);
final ExternalJavacManager javacManager = getJavacManager();
boolean compiledOk = javacManager != null && javacManager.forkJavac(javaHome, -1, Collections.emptyList(), options, platformCp, classpath, modulePath, sourcePath, files, outs, diagnostic, outputCollector, new JavacCompilerTool(), CanceledStatus.NULL);
if (!compiledOk) {
final List<CompilationException.Message> messages = new SmartList<>();
for (Diagnostic<? extends JavaFileObject> d : diagnostic.getDiagnostics()) {
final JavaFileObject source = d.getSource();
final URI uri = source != null ? source.toUri() : null;
messages.add(new CompilationException.Message(kindToCategory(d.getKind()), d.getMessage(Locale.US), uri != null ? uri.toURL().toString() : null, (int) d.getLineNumber(), (int) d.getColumnNumber()));
}
throw new CompilationException("Compilation failed", messages);
}
final List<ClassObject> result = new ArrayList<>();
for (OutputFileObject fileObject : outputCollector.getCompiledClasses()) {
final BinaryContent content = fileObject.getContent();
result.add(new CompiledClass(fileObject.getName(), fileObject.getClassName(), content != null ? content.toByteArray() : null));
}
return result;
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class AppletConfiguration method readExternal.
@Override
public void readExternal(final Element parentNode) throws InvalidDataException {
mySerializer.readExternal(this, parentNode);
List<Element> paramList = parentNode.getChildren(PARAMETER_ELEMENT_NAME);
if (paramList.isEmpty()) {
myAppletParameters = null;
} else {
List<AppletParameter> parameters = new SmartList<>();
for (Element element : paramList) {
parameters.add(new AppletParameter(element.getAttributeValue(NAME_ATTR), element.getAttributeValue(VALUE_ATTR)));
}
myAppletParameters = parameters.toArray(new AppletParameter[parameters.size()]);
}
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class PsiSearchHelperImpl method processFilesConcurrentlyDespiteWriteActions.
// Tries to run {@code localProcessor} for each file in {@code files} concurrently on ForkJoinPool.
// When encounters write action request, stops all threads, waits for write action to finish and re-starts all threads again.
// {@localProcessor} must be as idempotent as possible.
public static boolean processFilesConcurrentlyDespiteWriteActions(@NotNull Project project, @NotNull List<VirtualFile> files, @NotNull final ProgressIndicator progress, @NotNull final Processor<VirtualFile> localProcessor) {
ApplicationEx app = (ApplicationEx) ApplicationManager.getApplication();
final AtomicBoolean canceled = new AtomicBoolean(false);
while (true) {
List<VirtualFile> failedList = new SmartList<>();
final List<VirtualFile> failedFiles = Collections.synchronizedList(failedList);
final Processor<VirtualFile> processor = vfile -> {
try {
boolean result = localProcessor.process(vfile);
if (!result) {
canceled.set(true);
}
return result;
} catch (ApplicationUtil.CannotRunReadActionException action) {
failedFiles.add(vfile);
}
return !canceled.get();
};
boolean completed;
if (app.isWriteAccessAllowed() || app.isReadAccessAllowed() && app.isWriteActionPending()) {
// no point in processing in separate threads - they are doomed to fail to obtain read action anyway
completed = ContainerUtil.process(files, processor);
} else if (app.isWriteActionPending()) {
completed = true;
// we don't have read action now so wait for write action to complete
failedFiles.addAll(files);
} else {
// try to run parallel read actions but fail as soon as possible
completed = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(files, progress, false, true, processor);
}
if (!completed) {
return false;
}
if (failedFiles.isEmpty()) {
break;
}
// we failed to run read action in job launcher thread
// run read action in our thread instead to wait for a write action to complete and resume parallel processing
DumbService.getInstance(project).runReadActionInSmartMode(EmptyRunnable.getInstance());
files = failedList;
}
return true;
}
Aggregations