Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove maven 2 output parsing, cleanup and some parsing fixes #8265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.queries.SourceForBinaryQuery;
Expand Down Expand Up @@ -78,43 +77,21 @@ public static OutputListener matchStackTraceLine(String line, ClassPath classPat
return sa != null ? new ClassPathStacktraceOutputListener(classPath, sa) : null;
}

/**
*
* @param line
* @param project
* @return
*/
public static OutputListener matchStackTraceLine(String line, Project project) {
StacktraceAttributes sa = matchStackTraceLine(line);
if(sa != null) {
synchronized(projectStacktraceListeners) {
StacktraceOutputListener list = projectStacktraceListeners.get(project);
if(list == null) {
list = new ProjectStacktraceOutputListener(project);
projectStacktraceListeners.put(project, list);
}
return list;
return projectStacktraceListeners.computeIfAbsent(project, k -> new ProjectStacktraceOutputListener(project));
}
}
return null;
}

/**
*
* @param line
* @param fileObject
* @return
*/
public static OutputListener matchStackTraceLine(String line, FileObject fileObject) {
StacktraceAttributes sa = matchStackTraceLine(line);
if(sa != null) {
synchronized(fileStacktraceListeners) {
StacktraceOutputListener list = fileStacktraceListeners.get(fileObject);
if(list == null) {
list = new FileObjectStacktraceOutputListener(fileObject);
fileStacktraceListeners.put(fileObject, list);
}
return list;
return fileStacktraceListeners.computeIfAbsent(fileObject, k -> new FileObjectStacktraceOutputListener(fileObject));
}
}
return null;
Expand Down Expand Up @@ -156,11 +133,6 @@ protected StacktraceAttributes getStacktraceAttributes(String line) {
return matchStackTraceLine(line);
}

@Override
public void outputLineSelected(OutputEvent ev) {
// cookie.getLineSet().getCurrent(line).show(Line.SHOW_SHOW);
}

/** Called when some sort of action is performed on a line.
* @param ev the event describing the line
*/
Expand Down Expand Up @@ -237,18 +209,10 @@ public void outputLineAction(OutputEvent ev) {
StatusDisplayer.getDefault().setStatusText(Bundle.NotFound(sa.file));
}
}

/** Called when a line is cleared from the buffer of known lines.
* @param ev the event describing the line
*/
@Override
public void outputLineCleared(OutputEvent ev) {
}
}

private static ClassPath createProxyClassPath(Stream<ClassPath> paths) {
List<ClassPath> cp = paths.collect(Collectors.toList());
return ClassPathSupport.createProxyClassPath(cp.toArray(new ClassPath[0]));
return ClassPathSupport.createProxyClassPath(paths.toArray(ClassPath[]::new));
}

private static class ProjectStacktraceOutputListener extends StacktraceOutputListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@

package org.netbeans.modules.maven.execute;

import java.awt.Color;
import com.google.common.base.Predicates;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -36,10 +34,8 @@
import org.netbeans.modules.maven.api.output.OutputProcessorFactory;
import org.netbeans.modules.maven.api.output.OutputVisitor;
import org.netbeans.api.project.Project;
import org.netbeans.modules.maven.ActionProviderImpl;
import org.netbeans.modules.maven.api.execute.RunUtils;
import org.netbeans.modules.project.indexingbridge.IndexingBridge;
import org.netbeans.spi.project.ActionProvider;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.RequestProcessor;
Expand All @@ -49,6 +45,8 @@
import org.openide.windows.InputOutput;
import org.openide.windows.OutputWriter;

import static org.netbeans.modules.maven.ActionProviderImpl.*;

/**
*
* @author mkleint
Expand All @@ -71,16 +69,14 @@ public enum Level {DEBUG, INFO, WARNING, ERROR, FATAL}
private static final int SLEEP_DELAY = Integer.getInteger(AbstractOutputHandler.class.getName() + ".SLEEP_DELAY", 15000); // #270005

protected AbstractOutputHandler(Project proj, final ProgressHandle hand, RunConfig config, OutputVisitor visitor) {
processors = new HashMap<String, Set<OutputProcessor>>();
processors = new HashMap<>();
id2count = new HashMap<>();
currentProcessors = new HashSet<OutputProcessor>();
currentProcessors = new HashSet<>();
this.visitor = visitor;
toFinishProcessors = new HashSet<NotifyFinishOutputProcessor>();
sleepTask = new RequestProcessor(AbstractOutputHandler.class).create(new Runnable() {
public @Override void run() {
hand.suspend("");
exitProtectedMode();
}
toFinishProcessors = new HashSet<>();
sleepTask = new RequestProcessor(AbstractOutputHandler.class).create(() -> {
hand.suspend("");
exitProtectedMode();
});
enterProtectedMode(isProtectedWait(proj, config));
}
Expand All @@ -106,17 +102,15 @@ private boolean isProtectedWait(Project proj, RunConfig config) {
if(action == null || proj == null || !RunUtils.isCompileOnSaveEnabled(proj)) {
return false;
}
switch(action) {
case ActionProvider.COMMAND_RUN:
case ActionProvider.COMMAND_RUN_SINGLE:
case ActionProvider.COMMAND_DEBUG:
case ActionProvider.COMMAND_DEBUG_SINGLE:
case ActionProviderImpl.COMMAND_DEBUG_MAIN:
case ActionProviderImpl.COMMAND_RUN_MAIN:
return true;
default:
return false;
}
return switch (action) {
case COMMAND_RUN,
COMMAND_RUN_SINGLE,
COMMAND_DEBUG,
COMMAND_DEBUG_SINGLE,
COMMAND_DEBUG_MAIN,
COMMAND_RUN_MAIN -> true;
default -> false;
};
}

protected abstract InputOutput getIO();
Expand Down Expand Up @@ -152,28 +146,18 @@ protected final String getEventId(String eventName, String target) {
protected final void initProcessorList(Project proj, RunConfig config) {
// get the registered processors.
Lookup.Result<OutputProcessorFactory> result = Lookup.getDefault().lookupResult(OutputProcessorFactory.class);
Iterator<? extends OutputProcessorFactory> it = result.allInstances().iterator();
while (it.hasNext()) {
OutputProcessorFactory factory = it.next();
Set<? extends OutputProcessor> procs = factory.createProcessorsSet(proj);
if (factory instanceof ContextOutputProcessorFactory) {
Set<OutputProcessor> _procs = new HashSet<OutputProcessor>(procs);
_procs.addAll(((ContextOutputProcessorFactory)factory).createProcessorsSet(proj, config));
procs = _procs;
result.allInstances().forEach(factory -> {
Set<OutputProcessor> procs = new HashSet<>(factory.createProcessorsSet(proj));
if (factory instanceof ContextOutputProcessorFactory cof) {
procs.addAll(cof.createProcessorsSet(proj, config));
}
for (OutputProcessor proc : procs) {
String[] regs = proc.getRegisteredOutputSequences();
for (int i = 0; i < regs.length; i++) {
String str = regs[i];
Set<OutputProcessor> set = processors.get(str);
if (set == null) {
set = new HashSet<OutputProcessor>();
processors.put(str, set);
}
set.add(proc);
for (String reg : proc.getRegisteredOutputSequences()) {
processors.computeIfAbsent(reg, k -> new HashSet<>())
.add(proc);
}
}
}
});
}

protected final void processStart(String id, OutputWriter writer) {
Expand Down Expand Up @@ -213,12 +197,10 @@ protected final void processStart(String id, OutputWriter writer) {
protected final void processEnd(String id, OutputWriter writer) {
checkSleepiness();
visitor.resetVisitor();
Iterator<OutputProcessor> it = currentProcessors.iterator();
while (it.hasNext()) {
OutputProcessor proc = it.next();
for (OutputProcessor proc : currentProcessors) {
proc.sequenceEnd(id, visitor);
if (proc instanceof NotifyFinishOutputProcessor) {
toFinishProcessors.add((NotifyFinishOutputProcessor)proc);
if (proc instanceof NotifyFinishOutputProcessor nfop) {
toFinishProcessors.add(nfop);
}
}
if (visitor.getLine() != null) {
Expand All @@ -234,7 +216,7 @@ protected final void processEnd(String id, OutputWriter writer) {
}
AtomicInteger count = id2count.getOrDefault(id, new AtomicInteger(1));
if (count.decrementAndGet() == 0) {
Set set = processors.get(id);
Set<OutputProcessor> set = processors.get(id);
if (set != null) {
//TODO a bulletproof way would be to keep a list of currently started
// sections and compare to the list of getRegisteredOutputSequences fo each of the
Expand All @@ -249,8 +231,8 @@ protected final void processFail(String id, OutputWriter writer) {
checkSleepiness();
visitor.resetVisitor();
for (OutputProcessor proc : currentProcessors) {
if (proc instanceof NotifyFinishOutputProcessor) {
toFinishProcessors.add((NotifyFinishOutputProcessor)proc);
if (proc instanceof NotifyFinishOutputProcessor nfop) {
toFinishProcessors.add(nfop);
}
proc.sequenceFail(id, visitor);
}
Expand All @@ -267,11 +249,9 @@ protected final void processFail(String id, OutputWriter writer) {
}
Set<OutputProcessor> set = processors.get(id);
if (set != null) {
Set<OutputProcessor> retain = new HashSet<OutputProcessor>();
retain.addAll(set);
Set<OutputProcessor> retain = new HashSet<>(set);
retain.retainAll(currentProcessors);
Set<OutputProcessor> remove = new HashSet<OutputProcessor>();
remove.addAll(set);
Set<OutputProcessor> remove = new HashSet<>(set);
remove.removeAll(retain);
currentProcessors.removeAll(remove);
}
Expand Down Expand Up @@ -306,16 +286,9 @@ protected final void processLine(String input, OutputWriter writer, Level level)
String line = visitor.getLine() == null ? input : visitor.getLine();
if (visitor.getColor(getIO()) == null && visitor.getOutputListener() == null) {
switch (level) {
case DEBUG:
visitor.setOutputType(IOColors.OutputType.LOG_DEBUG);
break;
case WARNING:
visitor.setOutputType(IOColors.OutputType.LOG_WARNING);
break;
case ERROR:
case FATAL:
visitor.setOutputType(IOColors.OutputType.LOG_FAILURE);
break;
case DEBUG -> visitor.setOutputType(IOColors.OutputType.LOG_DEBUG);
case WARNING -> visitor.setOutputType(IOColors.OutputType.LOG_WARNING);
case ERROR, FATAL -> visitor.setOutputType(IOColors.OutputType.LOG_FAILURE);
}
}
try {
Expand Down Expand Up @@ -343,13 +316,8 @@ protected final void processLine(String input, OutputWriter writer, Level level)

//MEVENIDE-637
public static List<String> splitMultiLine(String input) {
List<String> list = new ArrayList<String>();
String[] strs = input.split("\\r|\\n"); //NOI18N
for (int i = 0; i < strs.length; i++) {
if(strs[i].length()>0){
list.add(strs[i]);
}
}
return list;
return input.lines()
.filter(Predicates.not(String::isEmpty))
.toList();
}
}
Loading
Loading