Commit | Line | Data |
---|---|---|
f14957a3 MAL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 Ericsson | |
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 | * Contributors: | |
10 | * Marc-Andre Laperle - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model; | |
14 | ||
15 | import java.io.File; | |
16 | import java.io.FileInputStream; | |
17 | ||
18 | import org.eclipse.core.runtime.IProgressMonitor; | |
19 | import org.eclipse.core.runtime.IStatus; | |
20 | import org.eclipse.core.runtime.Status; | |
21 | import org.eclipse.tracecompass.internal.tmf.remote.ui.Activator; | |
22 | import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.AbstractTracePackageOperation; | |
23 | import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement; | |
24 | ||
25 | /** | |
26 | * An operation that extracts profiles information from a file | |
27 | * | |
28 | * @author Marc-Andre Laperle | |
29 | */ | |
30 | public class ExtractRemoteProfilesOperation extends AbstractTracePackageOperation { | |
31 | ||
32 | /** | |
33 | * Constructs a new import operation for reading the profiles | |
34 | * | |
35 | * @param fileName | |
36 | * the output file name | |
37 | */ | |
38 | public ExtractRemoteProfilesOperation(String fileName) { | |
39 | super(fileName); | |
40 | } | |
41 | ||
42 | /** | |
43 | * Run the extract profiles operation. The status (result) of the operation | |
44 | * can be obtained with {@link #getStatus} | |
45 | * | |
46 | * @param progressMonitor | |
47 | * the progress monitor to use to display progress and receive | |
48 | * requests for cancellation | |
49 | */ | |
50 | @Override | |
51 | public void run(IProgressMonitor progressMonitor) { | |
52 | TracePackageElement[] elements = null; | |
53 | try { | |
54 | progressMonitor.worked(1); | |
55 | File file = new File(getFileName()); | |
56 | progressMonitor.worked(1); | |
57 | if (!file.exists()) { | |
58 | setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Invalid format")); //$NON-NLS-1$ | |
59 | return; | |
60 | } | |
61 | ||
62 | // TODO backwards compatibility for location | |
63 | try (FileInputStream inputStream = new FileInputStream(file)) { | |
64 | RemoteImportProfilesReader.validate(inputStream); | |
65 | } | |
66 | ||
67 | try (FileInputStream inputStream = new FileInputStream(file)) { | |
68 | elements = RemoteImportProfilesReader.loadElementsFromProfiles(inputStream); | |
69 | } | |
70 | ||
71 | progressMonitor.worked(1); | |
72 | ||
73 | setResultElements(elements); | |
74 | setStatus(Status.OK_STATUS); | |
75 | } catch (Exception e) { | |
76 | setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error reading profiles", e)); //$NON-NLS-1$ | |
77 | } | |
78 | } | |
79 | } |