Skip to content

Commit 694fd31

Browse files
committed
tmf: extend api for configuration 4
1 parent 5ad7dd9 commit 694fd31

1 file changed

Lines changed: 94 additions & 9 deletions

File tree

  • analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis

analyses/org.eclipse.tracecompass.incubator.inandout.core/src/org/eclipse/tracecompass/incubator/internal/inandout/core/analysis/InAndOutDataProviderFactory.java

Lines changed: 94 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@
2828
import org.eclipse.jdt.annotation.Nullable;
2929
import org.eclipse.osgi.util.NLS;
3030
import org.eclipse.tracecompass.incubator.internal.inandout.core.Activator;
31+
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
3132
import org.eclipse.tracecompass.tmf.core.config.AbstractTmfDataProviderConfigurator;
3233
import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration;
3334
import org.eclipse.tracecompass.tmf.core.config.ITmfConfigurationSourceType;
34-
import org.eclipse.tracecompass.tmf.core.config.TmfConfiguration;
3535
import org.eclipse.tracecompass.tmf.core.config.TmfConfigurationSourceType;
3636
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor;
3737
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor.ProviderType;
3838
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderFactory;
39+
import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
3940
import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException;
41+
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
4042
import org.eclipse.tracecompass.tmf.core.model.DataProviderCapabilities;
4143
import org.eclipse.tracecompass.tmf.core.model.DataProviderDescriptor;
4244
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel;
@@ -47,9 +49,6 @@
4749
import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
4850
import org.osgi.framework.Bundle;
4951

50-
import com.google.common.collect.HashBasedTable;
51-
import com.google.common.collect.Table;
52-
5352
/**
5453
* Data provider factory for InAndOut analysis. It doesn't have any output but is able
5554
* to create custom InAndOut analyses.
@@ -70,8 +69,6 @@ public class InAndOutDataProviderFactory extends AbstractTmfDataProviderConfigur
7069
private static final String CUSTOM_IN_AND_OUT_ANALYSIS_NAME = "InAndOut Analysis ({0})"; //$NON-NLS-1$
7170
private static final String CUSTOM_IN_AND_OUT_ANALYSIS_DESCRIPTION = "Custom InAndOut analysis configured by \" {0}\""; //$NON-NLS-1$
7271

73-
private Table<String, ITmfTrace, ITmfConfiguration> fTmfConfigurationTable = HashBasedTable.create();
74-
7572
static {
7673
Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
7774
IPath defaultPath = new Path(SegmentSpecifierConfiguration.IN_AND_OUT_CONFIG_SOURCE_SCHEMA);
@@ -115,7 +112,7 @@ public InAndOutDataProviderFactory() {
115112
public Collection<IDataProviderDescriptor> getDescriptors(ITmfTrace trace) {
116113
List<IDataProviderDescriptor> list = new ArrayList<>();
117114
list.add(DESCRIPTOR);
118-
for (ITmfConfiguration config : fTmfConfigurationTable.column(trace).values()) {
115+
for (ITmfConfiguration config : getConfigurationTable().column(trace).values()) {
119116
list.add(getDescriptorFromConfig(config));
120117
}
121118
return list;
@@ -152,7 +149,7 @@ protected void applyConfiguration(ITmfTrace trace, ITmfConfiguration config, boo
152149
}
153150
// Apply configuration to any trace (no need to check trace type here)
154151
try {
155-
TmfConfiguration.create(config, trace, writeConfig, new InAndOutAnalysisModule());
152+
create(config, trace, writeConfig, new InAndOutAnalysisModule());
156153
} catch (TmfConfigurationException e) {
157154
// TODO Auto-generated catch block
158155
e.printStackTrace();
@@ -169,10 +166,98 @@ protected void removeConfiguration(ITmfTrace trace, ITmfConfiguration config) {
169166
return;
170167
}
171168
try {
172-
TmfConfiguration.remove(config, trace, InAndOutAnalysisModule.ID);
169+
remove(config, trace, InAndOutAnalysisModule.ID);
173170
} catch (TmfConfigurationException e) {
174171
// TODO Auto-generated catch block
175172
e.printStackTrace();
176173
}
177174
}
175+
176+
/**
177+
* Removes configuration from trace:
178+
* - delete configuration file
179+
* - remove analysis module from trace object
180+
*
181+
* @param config
182+
* the configuration to remove
183+
* @param trace
184+
* the
185+
* @throws TmfConfigurationException if an error occurs
186+
*/
187+
private void remove(ITmfConfiguration config, @NonNull ITmfTrace trace, String baseAnalysisId) throws TmfConfigurationException {
188+
// IPath traceConfig = getConfigurationRootFolder(trace, config.getSourceTypeId());
189+
IPath traceConfig = getConfigurationRootFolder(trace);
190+
traceConfig = traceConfig.append(File.separator).append(config.getId()).addFileExtension(JSON_EXTENSION);
191+
File configFile = traceConfig.toFile();
192+
if ((!configFile.exists()) || !configFile.delete()) {
193+
throw new TmfConfigurationException("Configuration file can't be deleted from trace: configId=" + config.getId()); //$NON-NLS-1$
194+
}
195+
196+
// Remove and clear persistent data
197+
try {
198+
IAnalysisModule module = trace.removeAnalysisModule(baseAnalysisId + config.getId());
199+
if (module != null) {
200+
module.dispose();
201+
module.clearPersistentData();
202+
}
203+
} catch (TmfTraceException e) {
204+
throw new TmfConfigurationException("Error removing analysis module from trace: analysis ID=" + baseAnalysisId + config.getId(), e); //$NON-NLS-1$
205+
}
206+
}
207+
208+
/**
209+
* Create the InAndOutAnalysisModule for a given configuration and trace
210+
*
211+
* @param config
212+
* the input {@link ITmfConfiguration}
213+
* @param trace
214+
* the trace to apply it to
215+
* @param writeConfig
216+
* write the config (do only once)
217+
* @return InAndOutAnalysisModule
218+
* @throws TmfConfigurationException
219+
* if an error occurs
220+
*/
221+
public void create(@NonNull ITmfConfiguration config, @NonNull ITmfTrace trace, boolean writeConfig, IAnalysisModule module) throws TmfConfigurationException {
222+
/*
223+
* Apply configuration to each trace (no need to check trace type here)
224+
*/
225+
module.setConfiguration(config);
226+
if (writeConfig) {
227+
// IPath traceConfigPath = getConfigurationRootFolder(trace, config.getSourceTypeId());
228+
IPath traceConfigPath = getConfigurationRootFolder(trace);
229+
writeConfiguration(config, traceConfigPath);
230+
}
231+
try {
232+
if (module.setTrace(trace)) {
233+
IAnalysisModule oldModule = trace.addAnalysisModule(module);
234+
if (oldModule != null) {
235+
oldModule.dispose();
236+
oldModule.clearPersistentData();
237+
}
238+
} else {
239+
module.dispose();
240+
throw new TmfConfigurationException("InAndOut analysis module can't be created"); //$NON-NLS-1$
241+
}
242+
} catch (TmfAnalysisException | TmfTraceException e) {
243+
module.dispose();
244+
throw new TmfConfigurationException("Exception when setting trace", e); //$NON-NLS-1$
245+
}
246+
}
247+
248+
// protected IPath getConfigurationRootFolder(ITmfTrace trace, String subFolder) {
249+
// String supplFolder = TmfTraceManager.getSupplementaryFileDir(trace);
250+
// IPath supplPath = new Path(supplFolder);
251+
// supplPath = supplPath.addTrailingSeparator().append(subFolder);
252+
// return supplPath;
253+
// }
254+
255+
@Override
256+
protected IPath getConfigurationRootFolder(ITmfTrace trace) {
257+
String supplFolder = TmfTraceManager.getSupplementaryFileDir(trace);
258+
IPath supplPath = new Path(supplFolder);
259+
supplPath = supplPath.addTrailingSeparator().append(ID);
260+
return supplPath;
261+
}
262+
178263
}

0 commit comments

Comments
 (0)