+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.jetbrains.idea.maven.project;
import com.intellij.execution.filters.Filter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-/**
- * @author Sergey Evdokimov
- */
public class MavenTestConsoleFilter implements Filter {
+ private static final Pattern REPORT_DIR_PATTERN = Pattern
+ .compile("\\s*(?:\\[INFO\\] +Surefire report directory:|\\[ERROR\\] Please refer to) +(.+?)(?: for the individual test results.)?\\s*");
- private static final Pattern REPORT_DIR_PATTERN = Pattern.compile("\\s*(?:\\[INFO\\] +Surefire report directory:|\\[ERROR\\] Please refer to) +(.+?)(?: for the individual test results.)?\\s*");
-// private static final Pattern TEST_PATTERN = Pattern.compile("\\s*(Failed tests:)?\\s*(\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)\\(((?:\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*\\.)*\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)\\)\\s*");
-
- private String myReportFolder;
-
- private boolean myFailedTestsList;
-
- private final Project myProject;
-
- public MavenTestConsoleFilter(Project project) {
- myProject = project;
+ public MavenTestConsoleFilter() {
}
@Nullable
if (matcherReportDir.matches()) {
final String path = matcherReportDir.group(1);
- myReportFolder = path;
return new Result(entireLength - line.length() + matcherReportDir.start(1), entireLength - line.length() + matcherReportDir.end(1),
- new HyperlinkInfo() {
- @Override
- public void navigate(Project project) {
- File f = new File(path);
- if (f.isDirectory()) {
- ShowFilePathAction.openDirectory(f);
- }
- }
- });
+ new HyperlinkInfo() {
+ @Override
+ public void navigate(Project project) {
+ File f = new File(path);
+ if (f.isDirectory()) {
+ ShowFilePathAction.openDirectory(f);
+ }
+ }
+ });
}
-
- //if (myReportFolder != null) {
- // Matcher testMatcher = TEST_PATTERN.matcher(line);
- // if (testMatcher.matches()) {
- // if (testMatcher.group(1) != null) {
- // myFailedTestsList = true;
- // }
- //
- // if (myFailedTestsList) {
- // String className = testMatcher.group(3);
- // String methodName = testMatcher.group(2);
- //
- // PsiMethod method = null;
- //
- // PsiClass[] classes = JavaPsiFacade.getInstance(myProject).findClasses(className, GlobalSearchScope.allScope(myProject));
- // for (PsiClass aClass : classes) {
- // for (PsiMethod m : aClass.findMethodsByName(methodName, true)) {
- // if (JUnitUtil.isTestMethod(new MethodLocation(myProject, m, new PsiLocation<PsiClass>(myProject, aClass)))) {
- // method = m;
- // break;
- // }
- // }
- // }
- //
- // if (method != null) {
- // List<ResultItem> items = new ArrayList<ResultItem>(2);
- //
- // final WeakReference<PsiMethod> methodRef = new WeakReference<PsiMethod>(method);
- //
- // items.add(new ResultItem(entireLength - line.length() + testMatcher.start(2), entireLength - line.length() + testMatcher.end(2),
- // new HyperlinkInfo() {
- // @Override
- // public void navigate(Project project) {
- // PsiMethod method = methodRef.get();
- // if (method != null && method.isValid()) {
- // method.navigate(true);
- // }
- // }
- // }));
- //
- // final File report = new File(myReportFolder, className + ".txt");
- //
- // if (report.exists()) {
- // items.add(new ResultItem(entireLength - line.length() + testMatcher.start(3), entireLength - line.length() + testMatcher.end(3),
- // new IOFileHyperlinkInfo(report)));
- // }
- //
- // return new Result(items);
- //
- // }
- // }
- // }
- // else {
- // myFailedTestsList = false;
- // }
- //}
-
return null;
}
-
- //private class IOFileHyperlinkInfo implements FileHyperlinkInfo {
- // private final File myReport;
- //
- // private OpenFileDescriptor myDescriptor;
- // private boolean myInitialized;
- //
- // public IOFileHyperlinkInfo(File report) {
- // myReport = report;
- // }
- //
- // @Nullable
- // @Override
- // public OpenFileDescriptor getDescriptor() {
- // if (!myInitialized) {
- // VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(myReport);
- // if (virtualFile != null) {
- // myDescriptor = new OpenFileDescriptor(myProject, virtualFile);
- // }
- //
- // myInitialized = true;
- // }
- // return myDescriptor;
- // }
- //
- // @Override
- // public void navigate(Project project) {
- // final OpenFileDescriptor fileDesc = getDescriptor();
- //
- // if (fileDesc != null && fileDesc.getFile().isValid()) {
- // FileEditorManager.getInstance(project).openTextEditor(fileDesc, true);
- // }
- // }
- //}
}
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.jetbrains.idea.maven.tests;
import com.intellij.execution.filters.Filter;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
-import junit.framework.Assert;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.idea.maven.project.MavenTestConsoleFilter;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Override
protected void setUp() throws Exception {
super.setUp();
- myFilter = new MavenTestConsoleFilter(getProject());
+ myFilter = new MavenTestConsoleFilter();
}
private List<String> passLine(String line) {
Filter.Result result = myFilter.applyFilter(line, line.length());
if (result == null) return Collections.emptyList();
- List<String> res = new ArrayList<String>();
+ List<String> res = ContainerUtil.newArrayList();
for (Filter.ResultItem item : result.getResultItems()) {
- res.add(line.substring(item.highlightStartOffset, item.highlightEndOffset));
+ res.add(line.substring(item.getHighlightStartOffset(), item.getHighlightEndOffset()));
}
return res;
String tempDirPath = myFixture.getTempDirPath();
- Assert.assertEquals(passLine("[INFO] Scanning for projects..."), Collections.emptyList());
- Assert.assertEquals(passLine("[INFO] Surefire report directory: " + tempDirPath), Collections.singletonList(tempDirPath));
- Assert.assertEquals(passLine("[ERROR] Please refer to " + tempDirPath + " for the individual test results."), Collections.singletonList(
+ assertEquals(passLine("[INFO] Scanning for projects..."), Collections.emptyList());
+ assertEquals(passLine("[INFO] Surefire report directory: " + tempDirPath), Collections.singletonList(tempDirPath));
+ assertEquals(passLine("[ERROR] Please refer to " + tempDirPath + " for the individual test results."), Collections.singletonList(
tempDirPath));
}
-
}