imakerplugin/com.nokia.s60tools.imaker/src/com/nokia/s60tools/imaker/internal/managers/ProjectManager.java
author haismail <hussein.ismail@nokia.com>
Wed, 28 Apr 2010 13:50:48 +0300
changeset 11 217e69fc5beb
parent 0 61163b28edca
permissions -rw-r--r--
iMaker 3.1.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     1
/*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     3
* All rights reserved.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     4
* This component and the accompanying materials are made available
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     6
* which accompanies this distribution, and is available
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     8
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     9
* Initial Contributors:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    11
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    12
* Contributors:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    13
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    14
* Description:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    15
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    16
*/
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    17
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    18
package com.nokia.s60tools.imaker.internal.managers;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    19
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    20
import java.io.BufferedWriter;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    21
import java.io.File;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    22
import java.io.FileNotFoundException;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    23
import java.io.FileOutputStream;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    24
import java.io.IOException;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    25
import java.io.OutputStreamWriter;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    26
import java.io.Writer;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    27
import java.util.ArrayList;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    28
import java.util.HashMap;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    29
import java.util.List;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    30
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    31
import org.eclipse.core.resources.IFolder;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    32
import org.eclipse.core.resources.IProject;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    33
import org.eclipse.core.resources.IResource;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    34
import org.eclipse.core.resources.IResourceVisitor;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    35
import org.eclipse.core.runtime.CoreException;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    36
import org.eclipse.core.runtime.IPath;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    37
import org.eclipse.core.runtime.Path;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    38
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    39
import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    40
import com.nokia.carbide.cdt.builder.EpocEngineHelper;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    41
import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    42
import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    43
import com.nokia.s60tools.imaker.IMakerUtils;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    44
import com.nokia.s60tools.imaker.internal.model.iContent.IContentFactory;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    45
import com.nokia.s60tools.imaker.internal.model.iContent.IbyEntry;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    46
import com.nokia.s60tools.imaker.internal.model.iContent.ImageContent;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    47
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    48
public class ProjectManager {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    49
	public static final String NEW_ITEM            = "<New Configuration>";
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    50
	public static final String IBY_FILENAME_PREFIX = "imaker_additional_";
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    51
	public static final String IBY_FOLDER_NAME     = "rombuild";
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    52
	public static final String MAKEFILE_NAME       = "imaker_additions.mk";
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    53
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    54
	private String activeFile = "";
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    55
	private IProject project;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    56
	private ArrayList<IResource> imakerFiles;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    57
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    58
	public ProjectManager(IProject project) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    59
		this.imakerFiles = new ArrayList<IResource>();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    60
		this.project = project;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    61
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    62
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    63
	public String getActiveFile() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    64
		return activeFile;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    65
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    66
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    67
	public void setActiveFile(String newActive) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    68
		activeFile = newActive;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    69
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    70
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    71
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    72
	public IProject getProject() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    73
		return project;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    74
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    75
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    76
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    77
	 * @return The root location of the project
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    78
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    79
	public String getRoot() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    80
		return IMakerUtils.getProjectRootLocation(project);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    81
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    82
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    83
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    84
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    85
	 * Returns the imaker file in the specified location
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    86
	 * @param location
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    87
	 * @return
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    88
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    89
	public IResource getImakerFile(IPath location) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    90
		IResource ret = null;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    91
		for (IResource resource : getImakerFiles()) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    92
			if(resource.getLocation().equals(location)) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    93
				ret = resource;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    94
				break;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    95
			}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    96
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    97
		return ret;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    98
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    99
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   100
//	public IFile getImakerMakeFile() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   101
//		IFolder pfolder = project.getFolder(IBY_FOLDER_NAME);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   102
//		IFile mk = pfolder.getFile(MAKEFILE_NAME);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   103
//		if(mk.exists()) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   104
//			return mk;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   105
//		} else {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   106
//			return null;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   107
//		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   108
//	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   109
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   110
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   111
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   112
	 * Returns all imaker files in the selected project
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   113
	 * @return
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   114
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   115
	public List<IResource> getImakerFiles() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   116
		imakerFiles.clear();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   117
		try {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   118
			project.accept(new ImakerResourceVisitor(imakerFiles));
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   119
		} catch (CoreException e) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   120
			e.printStackTrace();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   121
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   122
		return imakerFiles;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   123
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   124
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   125
	private class ImakerResourceVisitor implements IResourceVisitor {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   126
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   127
		private ArrayList<IResource> list;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   128
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   129
		/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   130
		 * @param imps
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   131
		 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   132
		public ImakerResourceVisitor(ArrayList<IResource> imps) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   133
			this.list = imps;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   134
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   135
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   136
		/* (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   137
		 * @see org.eclipse.core.resources.IResourceVisitor#visit(org.eclipse.core.resources.IResource)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   138
		 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   139
//		@Override
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   140
		public boolean visit(IResource res) throws CoreException {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   141
			String name = res.getName();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   142
			if(name.endsWith(".imp")) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   143
				list.add(res);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   144
			}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   145
			if(res instanceof IFolder) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   146
				if(name.equals("src") || name.equals("inc")) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   147
					return false;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   148
				}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   149
			}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   150
			return true;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   151
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   152
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   153
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   154
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   155
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   156
	 * Creates new iby file to the specified location, with the specified content
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   157
	 * @param basename The name of the iby file, without the extension
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   158
	 * @param content The contents fo iby file
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   159
	 * @param path parent folder of the iby file
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   160
	 * @return The location or path of the newly created file
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   161
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   162
	public IPath createIbyFile(String basename, String content, IPath path) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   163
		File parent = path.toFile();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   164
		createFolder(parent);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   165
		path = path.append(basename+".iby");
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   166
		File file = path.toFile();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   167
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   168
		FileOutputStream fo;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   169
		try {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   170
			if(!file.exists()) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   171
				file.createNewFile();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   172
			}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   173
			fo = new FileOutputStream(file);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   174
			OutputStreamWriter osw = new OutputStreamWriter(fo);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   175
			
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   176
			Writer out = new BufferedWriter(osw);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   177
			out.write(content);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   178
			out.flush();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   179
			out.close();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   180
			return new Path(file.getAbsolutePath());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   181
		} catch (FileNotFoundException e) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   182
			e.printStackTrace();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   183
		} catch (IOException e) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   184
			e.printStackTrace();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   185
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   186
		return null;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   187
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   188
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   189
	private void createFolder(File folder) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   190
		if(folder!=null&&!folder.exists()) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   191
			String parent = folder.getParent();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   192
			File f = new File(parent);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   193
			createFolder(f);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   194
			folder.mkdir();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   195
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   196
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   197
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   198
	public IPath createAdditionsMakefile(List<IPath> files, IPath path) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   199
		createFolder(path.toFile());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   200
		IPath mk = path.append(MAKEFILE_NAME);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   201
		File mkFile = mk.toFile();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   202
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   203
		FileOutputStream fo;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   204
		try {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   205
			StringBuffer sb = new StringBuffer();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   206
			for (IPath p : files) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   207
				File f = p.toFile();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   208
				String name = f.getName();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   209
				int index = name.lastIndexOf('_');
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   210
				String loc = name.substring(index+1, name.length()-4);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   211
				loc = loc.toUpperCase();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   212
				sb.append(loc+"_OBY += " + f.getAbsolutePath()+"\n");
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   213
			}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   214
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   215
			fo = new FileOutputStream(mkFile);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   216
			OutputStreamWriter osw = new OutputStreamWriter(fo);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   217
			
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   218
			Writer out = new BufferedWriter(osw);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   219
			out.write(sb.toString());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   220
			out.flush();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   221
			out.close();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   222
			return new Path(mkFile.getAbsolutePath());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   223
		} catch (FileNotFoundException e) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   224
			e.printStackTrace();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   225
		} catch (IOException e) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   226
			e.printStackTrace();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   227
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   228
		return null;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   229
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   230
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   231
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   232
	 * Populate the model of the dialog with content from the selected project
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   233
	 * @param ic
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   234
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   235
	public void populate(ImageContent ic) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   236
		ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   237
		if (cpi != null) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   238
			ICarbideBuildConfiguration buildConfig = cpi.getDefaultConfiguration();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   239
			String filename = null;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   240
			
11
217e69fc5beb iMaker 3.1.0
haismail <hussein.ismail@nokia.com>
parents: 0
diff changeset
   241
//			boolean debug = "udeb".equalsIgnoreCase(buildConfig.getTargetString());
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   242
			// add the binaries and any resource-type files generated by all mmp files in the project
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   243
			for (IPath mmp : EpocEngineHelper.getMMPFilesForBuildConfiguration(buildConfig)) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   244
				IPath hp = EpocEngineHelper.getHostPathForExecutable(buildConfig, mmp);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   245
				IPath tp = EpocEngineHelper.getTargetPathForExecutable(buildConfig, mmp);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   246
				
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   247
				filename = hp.segment(hp.segmentCount()-1);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   248
				
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   249
				// add component executable
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   250
				if (hp != null) {
11
217e69fc5beb iMaker 3.1.0
haismail <hussein.ismail@nokia.com>
parents: 0
diff changeset
   251
					addEntry(ic, hp.toOSString(), tp.toOSString(), filename);
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   252
				}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   253
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   254
				HashMap<String, String> hostTargetRSRCMap = EpocEngineHelper.getHostAndTargetResources(buildConfig, mmp);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   255
				// Add resource files...
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   256
				for (String key : hostTargetRSRCMap.keySet()) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   257
					filename = new File(key).getName();
11
217e69fc5beb iMaker 3.1.0
haismail <hussein.ismail@nokia.com>
parents: 0
diff changeset
   258
					addEntry(ic, key, hostTargetRSRCMap.get(key),filename);
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   259
				}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   260
			}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   261
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   262
			// check the project for image makefiles
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   263
			HashMap<String, String> hostTargetImagesMap = EpocEngineHelper.getHostAndTargetImages(buildConfig);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   264
			for (String key : hostTargetImagesMap.keySet()) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   265
				filename = new File(key).getName();				
11
217e69fc5beb iMaker 3.1.0
haismail <hussein.ismail@nokia.com>
parents: 0
diff changeset
   266
				addEntry(ic, key, hostTargetImagesMap.get(key), filename);
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   267
			}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   268
		}	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   269
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   270
11
217e69fc5beb iMaker 3.1.0
haismail <hussein.ismail@nokia.com>
parents: 0
diff changeset
   271
	private void addEntry(ImageContent ic,
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   272
			String hp, String tp, String filename) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   273
		IbyEntry entry = IContentFactory.eINSTANCE.createIbyEntry();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   274
		if(hp.length()>2) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   275
			hp = hp.substring(2);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   276
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   277
		entry.setFile(hp);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   278
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   279
		if(tp!=null&&!tp.endsWith(filename)) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   280
			if(tp.endsWith(File.separator)) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   281
				tp = tp + filename;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   282
			} else {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   283
				tp = tp + File.separator + filename;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   284
			}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   285
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   286
		if(tp!=null) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   287
			tp = tp.substring(2);			
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   288
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   289
		entry.setTarget(tp);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   290
		boolean contains = false;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   291
		for (IbyEntry e : ic.getEntries()) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   292
			if(e.equals(entry)) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   293
				contains = true;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   294
				break;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   295
			}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   296
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   297
		if(!contains) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   298
			ic.getEntries().add(entry);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   299
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   300
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   301
}