edf35a57634d3a632ad07aee19fef70af93595a7
1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
;
16 import java
.io
.IOException
;
18 import org
.eclipse
.core
.resources
.IResource
;
19 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
20 import org
.eclipse
.core
.runtime
.CoreException
;
21 import org
.eclipse
.core
.runtime
.Path
;
22 import org
.eclipse
.core
.runtime
.URIUtil
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.TmfCommonConstants
;
26 * The "File" implementation of an IFileSystemObject
28 class FileFileSystemObject
implements IFileSystemObject
{
30 private File fFileSystemObject
;
32 FileFileSystemObject(File fileSystemObject
) {
33 fFileSystemObject
= fileSystemObject
;
37 public String
getName() {
38 String name
= fFileSystemObject
.getName();
39 if (name
.length() == 0) {
40 return fFileSystemObject
.getPath();
46 public String
getAbsolutePath() {
47 return fFileSystemObject
.getAbsolutePath();
51 public boolean exists() {
52 return fFileSystemObject
.exists();
56 public String
getSourceLocation() {
57 IResource sourceResource
;
58 String sourceLocation
= null;
59 if (fFileSystemObject
.isDirectory()) {
60 sourceResource
= ResourcesPlugin
.getWorkspace().getRoot().getContainerForLocation(Path
.fromOSString(fFileSystemObject
.getAbsolutePath()));
62 sourceResource
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(Path
.fromOSString(fFileSystemObject
.getAbsolutePath()));
64 if (sourceResource
!= null && sourceResource
.exists()) {
66 sourceLocation
= sourceResource
.getPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
);
67 } catch (CoreException e
) {
68 // Something went wrong with the already existing resource.
69 // This is not a problem, we'll assign a new location below.
72 if (sourceLocation
== null) {
74 sourceLocation
= URIUtil
.toUnencodedString(fFileSystemObject
.getCanonicalFile().toURI());
75 } catch (IOException e
) {
76 // Something went wrong canonicalizing the file. We can still
77 // use the URI but there might be extra ../ in it.
78 sourceLocation
= URIUtil
.toUnencodedString(fFileSystemObject
.toURI());
81 return sourceLocation
;
85 public Object
getRawFileSystemObject() {
86 return fFileSystemObject
;
This page took 0.034067 seconds and 4 git commands to generate.