0
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.s60tools.imaker.internal.tests;
|
|
19 |
|
|
20 |
import java.io.ByteArrayInputStream;
|
|
21 |
import java.io.File;
|
|
22 |
import java.io.FilenameFilter;
|
|
23 |
import java.io.InputStream;
|
|
24 |
|
|
25 |
import junit.framework.TestCase;
|
|
26 |
|
|
27 |
import org.eclipse.core.resources.IFile;
|
|
28 |
import org.eclipse.core.resources.IFolder;
|
|
29 |
import org.eclipse.core.resources.IProject;
|
|
30 |
import org.eclipse.core.resources.IWorkspace;
|
|
31 |
import org.eclipse.core.resources.IWorkspaceRoot;
|
|
32 |
import org.eclipse.core.resources.ResourcesPlugin;
|
|
33 |
import org.eclipse.core.runtime.CoreException;
|
|
34 |
|
|
35 |
public class ProjectBuilder extends TestCase {
|
|
36 |
public static final String TESTDATA_DIR = "testdata";
|
|
37 |
public static final String[] imp_file_names = new String[] {"test1.imp","test2.imp"};
|
|
38 |
public static final String[] imp_file_contents = new String[] {
|
|
39 |
"#iMaker properties\n" +
|
|
40 |
"#Fri Sep 18 09:31:17 EEST 2009\n" +
|
|
41 |
"PRODUCT=my_product.mk\n" +
|
|
42 |
"TARGET=all\n" +
|
|
43 |
"HWID=1010\n" +
|
|
44 |
"NAME=FIELD_VALUE\n" +
|
|
45 |
"MAKEFILE=\\\\epoc32\\\\rom\\\\config\\\\ncp70\\\\corolla\\\\corolla12mpix\\\\image_conf_corolla12mpix.mk\n" +
|
|
46 |
"TYPE=rnd\n" +
|
|
47 |
"TARGET_LIST=all\n",
|
|
48 |
"#iMaker properties\n" +
|
|
49 |
"#Fri Sep 18 09:31:17 EEST 2009\n" +
|
|
50 |
"PRODUCT=image_conf_dilbert_ui.mk\n" +
|
|
51 |
"TARGET=core\n" +
|
|
52 |
"HWID=0100\n" +
|
|
53 |
"NAME=FIELD_VALUE\n" +
|
|
54 |
"MAKEFILE=\\\\epoc32\\\\rom\\\\config\\\\ncp70\\\\dilbert\\\\image_conf_dilbert_ui.mk\n" +
|
|
55 |
"TYPE=rnd\n" +
|
|
56 |
"TARGET_LIST=core\n" +
|
|
57 |
"DEBUG_FILES=true;false;\\\\epoc32\\\\data\\\\welcome.gif;\\\\welcome.gif;ROFS3"};
|
|
58 |
private final String PROJECT_NAME = "test";
|
|
59 |
protected IProject project = null;
|
|
60 |
|
|
61 |
protected void createDefaultProject() throws CoreException {
|
|
62 |
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
|
63 |
IWorkspaceRoot root = workspace.getRoot();
|
|
64 |
|
|
65 |
project = root.getProject(PROJECT_NAME);
|
|
66 |
if(!project.exists()) {
|
|
67 |
project.create(null);
|
|
68 |
}
|
|
69 |
if(!project.isOpen()) {
|
|
70 |
project.open(null);
|
|
71 |
}
|
|
72 |
}
|
|
73 |
|
|
74 |
protected void closeAndDeleteDefaultProject() throws CoreException {
|
|
75 |
if(project!=null&&project.exists()) {
|
|
76 |
project.close(null);
|
|
77 |
project.delete(true, null);
|
|
78 |
}
|
|
79 |
}
|
|
80 |
|
|
81 |
protected IFile[] addImakerImpFiles() {
|
|
82 |
IFolder folder = project.getFolder(TESTDATA_DIR);
|
|
83 |
IFile[] ifiles = new IFile[imp_file_names.length];
|
|
84 |
try {
|
|
85 |
if(!folder.exists()) {
|
|
86 |
folder.create(true, true, null);
|
|
87 |
}
|
|
88 |
for (int i = 0; i < imp_file_names.length; i++) {
|
|
89 |
String f_name = imp_file_names[i];
|
|
90 |
IFile file = folder.getFile(f_name);
|
|
91 |
if(!file.exists()) {
|
|
92 |
file.create(getContent(i), true, null);
|
|
93 |
} else {
|
|
94 |
file.setContents(getContent(i), true, false, null);
|
|
95 |
}
|
|
96 |
ifiles[i]=file;
|
|
97 |
}
|
|
98 |
return ifiles;
|
|
99 |
} catch (CoreException e) {
|
|
100 |
e.printStackTrace();
|
|
101 |
}
|
|
102 |
return null;
|
|
103 |
}
|
|
104 |
|
|
105 |
private InputStream getContent(int file) {
|
|
106 |
String contents = imp_file_contents[file];
|
|
107 |
ByteArrayInputStream input = new ByteArrayInputStream(contents.getBytes());
|
|
108 |
return input;
|
|
109 |
}
|
|
110 |
|
|
111 |
public static File[] getTestFiles() {
|
|
112 |
File f = new File(TESTDATA_DIR);
|
|
113 |
File[] files = f.listFiles(new FilenameFilter() {
|
|
114 |
|
|
115 |
// @Override
|
|
116 |
public boolean accept(File dir, String name) {
|
|
117 |
return name.endsWith(".imp");
|
|
118 |
}
|
|
119 |
});
|
|
120 |
return files;
|
|
121 |
}
|
|
122 |
}
|