summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/model/ProjectInfo.java
blob: 119782d98cacb4d66b397e447ef3bd4dc8b8462b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*****************************************************************************
 * Copyright (c) 2013 Ken Gilmer, Intel Corporation
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Ken Gilmer - initial API and implementation
 *     Ioana Grigoropol (Intel) - adapt class for remote support
 *******************************************************************************/
package org.yocto.bc.ui.model;

import java.net.URI;
import java.net.URISyntaxException;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.ptp.remote.core.IRemoteServices;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.services.files.IFileService;
import org.yocto.bc.bitbake.ProjectInfoHelper;
import org.yocto.bc.ui.filesystem.YoctoLocation;
import org.yocto.remote.utils.RemoteHelper;

public class ProjectInfo implements IModelElement {
	private String name;
	private YoctoLocation location;
	private String init;
	private IHost connection;
	private IRemoteServices remoteServices;

	public ProjectInfo() {
	}
	
	public String getInitScriptPath() {
		return init;
	}
	public String getProjectName() {
		return name;
	}
	public URI getOriginalURI() {
		return location.getOriginalURI();
	}

	public URI getOEFSURI() {
		return location.getOEFSURI();
	}

	@Override
	public void initialize() throws Exception {
		name = new String();
		location = new YoctoLocation();
		init = new String();
	}

	public void setInitScriptPath(String init) {
		this.init = init;
	}

	public void setLocationURI(URI location) {
		if (this.location == null)
			this.location = new YoctoLocation();
		if (location.getScheme().equalsIgnoreCase("oefs")) {
			if (this.name ==  null) {
				String path = location.getPath();
				this.name = path.substring(path.lastIndexOf("/") + 1);
			}
			location = RemoteHelper.retrieveURIFromMetaArea(this.name);
		}
		this.location.setOriginalURI(location);
		try {
			this.location.setOEFSURI(new URI(ProjectInfoHelper.OEFS_SCHEME + location.getPath() ));
		} catch (URISyntaxException e) {
			try {
				this.location.setOEFSURI(new URI(""));
			} catch (URISyntaxException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}

	public void setName(String name) {
		this.name = name;
	}

	public IHost getConnection() {
		if (connection == null && RemoteHelper.isInitialized(getOriginalURI())) {
			connection = RemoteHelper.getRemoteConnectionForURI(location.getOriginalURI(), new NullProgressMonitor());
		}
		return connection;
	}

	public void setConnection(IHost connection) {
		this.connection = connection;
	}

	public IRemoteServices getRemoteServices() {
		return remoteServices;
	}

	public void setRemoteServices(IRemoteServices remoteServices) {
		this.remoteServices = remoteServices;
	}

	public IFileService getFileService(IProgressMonitor monitor){
		try {
			if (!RemoteHelper.isInitialized(getOriginalURI()))
				return null;
			return RemoteHelper.getConnectedRemoteFileService(connection, monitor);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}