analysis.lami: Replace OnDemandAnalysisException with CoreException
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.lami.core.tests / src / org / eclipse / tracecompass / analysis / lami / core / tests / LamiAnalysisStub.java
CommitLineData
ace6413c
MJ
1/*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Michael Jeanson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10package org.eclipse.tracecompass.analysis.lami.core.tests;
11
12import static org.junit.Assert.fail;
13
14import java.io.BufferedReader;
15import java.io.IOException;
16import java.io.InputStream;
17import java.io.InputStreamReader;
18import java.net.URL;
19import java.util.Collections;
20import java.util.List;
21import java.util.stream.Collectors;
22
46f0c09c 23import org.eclipse.core.runtime.CoreException;
ace6413c
MJ
24import org.eclipse.core.runtime.IProgressMonitor;
25import org.eclipse.jdt.annotation.NonNull;
26import org.eclipse.jdt.annotation.Nullable;
27import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis;
28import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiChartModel;
ace6413c
MJ
29import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
30
31import com.google.common.collect.ImmutableMultimap;
32import com.google.common.collect.Multimap;
33
34/**
35 * Extension of {@link LamiAnalysis} used for tests.
36 */
37public class LamiAnalysisStub extends LamiAnalysis {
38
39 private final String fMetaDatafilename;
40 private final String fResultFilename;
41
42 /**
43 * Constructor.
44 *
45 * @param metaDatafilename
46 * Filename of the JSON metadata file.
47 * @param resultFilename
48 * Filename of the JSON results file.
49 */
50 protected LamiAnalysisStub(String metaDatafilename, String resultFilename) {
51 super("Stub Analysis", false, o -> true, Collections.singletonList("StubExecutable"));
52 fMetaDatafilename = metaDatafilename;
53 fResultFilename = resultFilename;
54 }
55
56 @Override
57 public @NonNull String getName() {
58 return "StubName";
59 }
60
61 @Override
62 protected @NonNull Multimap<@NonNull String, @NonNull LamiChartModel> getPredefinedCharts() {
63 return ImmutableMultimap.of();
64 }
65
66 @Override
67 protected String getResultsFromCommand(List<String> command, IProgressMonitor monitor)
46f0c09c 68 throws CoreException {
ace6413c
MJ
69 return readLamiFile(fResultFilename);
70 }
71
72 @Override
73 protected @Nullable String getOutputFromCommand(List<String> command) {
74 return readLamiFile(fMetaDatafilename);
75 }
76
77 @Override
78 public boolean canExecute(ITmfTrace trace) {
79 initialize();
80 return true;
81 }
82
83 @Override
84 protected synchronized void initialize() {
85 checkMetadata();
86 }
87
88 private static String readLamiFile(String filename) {
89 String fileContent = "";
90 try {
91 URL url = new URL("platform:/plugin/org.eclipse.tracecompass.analysis.lami.core.tests/testfiles/" + filename);
92
93 try (InputStream inputStream = url.openConnection().getInputStream()) {
94 BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
95 fileContent = in.lines().collect(Collectors.joining());
96 }
97 } catch (IOException e) {
98 fail(e.getMessage());
99 }
100
101 return fileContent;
102 }
103}
This page took 0.028276 seconds and 5 git commands to generate.