diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:23:09 +0200 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:24:09 +0200 |
commit | c7da892cb23d50d4d85746c9a0b6b14bf570989d (patch) | |
tree | e7136073f386d6156f51766c498c52c30c8df85f /plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards | |
download | eclipse-poky-kepler-c7da892cb23d50d4d85746c9a0b6b14bf570989d.tar.gz |
initial commit for Enea Linux 4.0daisy
Migrated from the internal git server on the daisy-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards')
14 files changed, 2961 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java new file mode 100644 index 0000000..c8eea71 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/BitbakeRecipeUIElement.java | |||
@@ -0,0 +1,153 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2013 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | * Ioana Grigoropol (Intel) - adapt class for remote support | ||
11 | *******************************************************************************/ | ||
12 | package org.yocto.bc.ui.wizards; | ||
13 | |||
14 | import org.eclipse.jface.viewers.ISelection; | ||
15 | import org.eclipse.swt.widgets.Text; | ||
16 | |||
17 | import java.net.URI; | ||
18 | import java.net.URISyntaxException; | ||
19 | import java.util.ArrayList; | ||
20 | |||
21 | public class BitbakeRecipeUIElement { | ||
22 | |||
23 | private String container; | ||
24 | private String file; | ||
25 | private String description; | ||
26 | private String license; | ||
27 | private String checksum; | ||
28 | private String homepage; | ||
29 | private String author; | ||
30 | private String section; | ||
31 | private String srcuri; | ||
32 | private String md5sum; | ||
33 | private String sha256sum; | ||
34 | private URI metaDir; | ||
35 | private ArrayList inheritance; | ||
36 | |||
37 | public BitbakeRecipeUIElement() | ||
38 | { | ||
39 | this.container = ""; | ||
40 | this.file = ""; | ||
41 | this.description = ""; | ||
42 | this.license = ""; | ||
43 | this.checksum = ""; | ||
44 | this.homepage = ""; | ||
45 | this.author = ""; | ||
46 | this.section = ""; | ||
47 | this.srcuri = ""; | ||
48 | this.md5sum = ""; | ||
49 | this.sha256sum = ""; | ||
50 | this.inheritance = new ArrayList(); | ||
51 | try { | ||
52 | this.metaDir = new URI(""); | ||
53 | } catch (URISyntaxException e) { | ||
54 | e.printStackTrace(); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | public String getContainer() { | ||
59 | return container; | ||
60 | } | ||
61 | public void setContainer(String value) { | ||
62 | this.container = value; | ||
63 | } | ||
64 | public String getFile() { | ||
65 | return file; | ||
66 | } | ||
67 | public void setFile(String value) { | ||
68 | this.file = value; | ||
69 | } | ||
70 | public String getDescription() { | ||
71 | return description; | ||
72 | } | ||
73 | |||
74 | public void setDescription(String value) { | ||
75 | this.description = value; | ||
76 | } | ||
77 | |||
78 | public String getLicense() { | ||
79 | return license; | ||
80 | } | ||
81 | |||
82 | public void setLicense(String value) { | ||
83 | this.license = value; | ||
84 | } | ||
85 | |||
86 | public String getChecksum() { | ||
87 | return checksum; | ||
88 | } | ||
89 | public void setChecksum(String value) { | ||
90 | this.checksum = value; | ||
91 | } | ||
92 | |||
93 | public String getHomePage() { | ||
94 | return homepage; | ||
95 | } | ||
96 | |||
97 | public void setHomePage(String value) { | ||
98 | this.homepage = value; | ||
99 | } | ||
100 | |||
101 | public String getAuthor() { | ||
102 | return author; | ||
103 | } | ||
104 | |||
105 | public void setAuthor(String value) { | ||
106 | this.author = value; | ||
107 | } | ||
108 | |||
109 | public String getSection() { | ||
110 | return section; | ||
111 | } | ||
112 | public void setSection(String value) { | ||
113 | this.section = value; | ||
114 | } | ||
115 | public String getSrcuri() { | ||
116 | return srcuri; | ||
117 | } | ||
118 | public void setSrcuri(String value) { | ||
119 | this.srcuri = value; | ||
120 | } | ||
121 | |||
122 | public String getMd5sum() { | ||
123 | return md5sum; | ||
124 | } | ||
125 | |||
126 | public void setMd5sum(String value) { | ||
127 | this.md5sum = value; | ||
128 | } | ||
129 | |||
130 | public String getsha256sum() { | ||
131 | return sha256sum; | ||
132 | } | ||
133 | |||
134 | public void setSha256sum(String value) { | ||
135 | this.sha256sum = value; | ||
136 | } | ||
137 | |||
138 | public ArrayList<String> getInheritance() { | ||
139 | return inheritance; | ||
140 | } | ||
141 | |||
142 | public void setInheritance(ArrayList<String> value) { | ||
143 | this.inheritance = value; | ||
144 | } | ||
145 | |||
146 | public URI getMetaDir() { | ||
147 | return metaDir; | ||
148 | } | ||
149 | |||
150 | public void setMetaDir(URI value) { | ||
151 | metaDir = value; | ||
152 | } | ||
153 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizard.java new file mode 100644 index 0000000..8b47498 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizard.java | |||
@@ -0,0 +1,56 @@ | |||
1 | package org.yocto.bc.ui.wizards; | ||
2 | import java.util.Map; | ||
3 | |||
4 | import org.eclipse.jface.wizard.Wizard; | ||
5 | import org.eclipse.swt.widgets.Composite; | ||
6 | |||
7 | |||
8 | |||
9 | public abstract class FiniteStateWizard extends Wizard { | ||
10 | private boolean finishable = false; | ||
11 | private boolean canFinish = false; | ||
12 | |||
13 | public FiniteStateWizard() { | ||
14 | } | ||
15 | |||
16 | public abstract boolean performFinish(); | ||
17 | |||
18 | /** | ||
19 | * @return Returns if the wizard is finishable in its current state. | ||
20 | */ | ||
21 | public boolean isFinishable() { | ||
22 | return finishable; | ||
23 | } | ||
24 | /** | ||
25 | * @param finishable Change the finish state of the wizard. | ||
26 | */ | ||
27 | public void setFinishable(boolean finishable) { | ||
28 | this.finishable = finishable; | ||
29 | } | ||
30 | |||
31 | /* (non-Javadoc) | ||
32 | * @see org.eclipse.jface.wizard.IWizard#createPageControls(org.eclipse.swt.widgets.Composite) | ||
33 | */ | ||
34 | public void createPageControls(Composite pageContainer) { | ||
35 | super.createPageControls(pageContainer); | ||
36 | } | ||
37 | |||
38 | /* | ||
39 | * (non-Javadoc) Method declared on IWizard. | ||
40 | */ | ||
41 | public boolean canFinish() { | ||
42 | if (canFinish) | ||
43 | return true; | ||
44 | return super.canFinish(); | ||
45 | } | ||
46 | |||
47 | public void setCanFinish(boolean canFinish) { | ||
48 | this.canFinish = canFinish; | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * Retrive the model object from the wizard. | ||
53 | * @return | ||
54 | */ | ||
55 | public abstract Map getModel(); | ||
56 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java new file mode 100644 index 0000000..a83a389 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/FiniteStateWizardPage.java | |||
@@ -0,0 +1,149 @@ | |||
1 | package org.yocto.bc.ui.wizards; | ||
2 | import java.util.Map; | ||
3 | |||
4 | import org.eclipse.jface.viewers.ISelectionChangedListener; | ||
5 | import org.eclipse.jface.viewers.SelectionChangedEvent; | ||
6 | import org.eclipse.jface.wizard.WizardPage; | ||
7 | import org.eclipse.swt.events.ModifyEvent; | ||
8 | import org.eclipse.swt.events.ModifyListener; | ||
9 | import org.eclipse.swt.events.SelectionEvent; | ||
10 | import org.eclipse.swt.events.SelectionListener; | ||
11 | import org.eclipse.swt.widgets.Composite; | ||
12 | import org.eclipse.swt.widgets.Event; | ||
13 | import org.eclipse.swt.widgets.Listener; | ||
14 | |||
15 | public abstract class FiniteStateWizardPage extends WizardPage { | ||
16 | protected Map model = null; | ||
17 | protected FiniteStateWizard wizard = null; | ||
18 | private static boolean previousState = false; | ||
19 | /** | ||
20 | * @param pageName | ||
21 | */ | ||
22 | protected FiniteStateWizardPage(String name, Map model) { | ||
23 | super(name); | ||
24 | this.model = model; | ||
25 | this.setPageComplete(false); | ||
26 | } | ||
27 | |||
28 | /* | ||
29 | * (non-Javadoc) | ||
30 | * | ||
31 | * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) | ||
32 | */ | ||
33 | public abstract void createControl(Composite parent); | ||
34 | |||
35 | protected void setModelWizard() { | ||
36 | if (wizard == null) { | ||
37 | wizard = (FiniteStateWizard)FiniteStateWizardPage.this.getWizard(); | ||
38 | } | ||
39 | } | ||
40 | |||
41 | /** | ||
42 | * Add page validation logic here. Returning <code>true</code> means that | ||
43 | * the page is complete and the user can go to the next page. | ||
44 | * | ||
45 | * @return | ||
46 | */ | ||
47 | protected abstract boolean validatePage(); | ||
48 | |||
49 | /** | ||
50 | * This method should be implemented by ModelWizardPage classes. This method | ||
51 | * is called after the <code>validatePage()</code> returns successfully. | ||
52 | * Update the model with the contents of the controls on the page. | ||
53 | */ | ||
54 | protected abstract void updateModel(); | ||
55 | |||
56 | /** | ||
57 | * Helper method to see if a field has some sort of text in it. | ||
58 | * @param value | ||
59 | * @return | ||
60 | */ | ||
61 | protected boolean hasContents(String value) { | ||
62 | if (value == null || value.length() == 0) { | ||
63 | return false; | ||
64 | } | ||
65 | |||
66 | return true; | ||
67 | } | ||
68 | |||
69 | /** | ||
70 | * This method is called right before a page is displayed. | ||
71 | * This occurs on user action (Next/Back buttons). | ||
72 | */ | ||
73 | public abstract void pageDisplay(); | ||
74 | |||
75 | /** | ||
76 | * This method is called on the concrete WizardPage after the user has | ||
77 | * gone to the page after. | ||
78 | */ | ||
79 | public abstract void pageCleanup(); | ||
80 | |||
81 | /* (non-Javadoc) | ||
82 | * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean) | ||
83 | */ | ||
84 | public void setVisible(boolean arg0) { | ||
85 | |||
86 | if (!arg0 && previousState) { | ||
87 | pageCleanup(); | ||
88 | } else if (arg0 && !previousState) { | ||
89 | pageDisplay(); | ||
90 | } else if (arg0 && previousState) { | ||
91 | pageDisplay(); | ||
92 | } | ||
93 | |||
94 | previousState = arg0; | ||
95 | |||
96 | super.setVisible(arg0); | ||
97 | } | ||
98 | |||
99 | public class ValidationListener implements SelectionListener, ModifyListener, Listener, ISelectionChangedListener { | ||
100 | |||
101 | /* | ||
102 | * (non-Javadoc) | ||
103 | * | ||
104 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) | ||
105 | */ | ||
106 | public void widgetSelected(SelectionEvent e) { | ||
107 | validate(); | ||
108 | } | ||
109 | |||
110 | /* | ||
111 | * (non-Javadoc) | ||
112 | * | ||
113 | * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) | ||
114 | */ | ||
115 | public void widgetDefaultSelected(SelectionEvent e) { | ||
116 | } | ||
117 | |||
118 | /* | ||
119 | * (non-Javadoc) | ||
120 | * | ||
121 | * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent) | ||
122 | */ | ||
123 | public void modifyText(ModifyEvent e) { | ||
124 | validate(); | ||
125 | } | ||
126 | |||
127 | public void validate() { | ||
128 | if (validatePage()) { | ||
129 | updateModel(); | ||
130 | setPageComplete(true); | ||
131 | return; | ||
132 | } | ||
133 | |||
134 | setPageComplete(false); | ||
135 | } | ||
136 | |||
137 | /* (non-Javadoc) | ||
138 | * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) | ||
139 | */ | ||
140 | public void handleEvent(Event event) { | ||
141 | |||
142 | validate(); | ||
143 | } | ||
144 | |||
145 | public void selectionChanged(SelectionChangedEvent event) { | ||
146 | validate(); | ||
147 | } | ||
148 | } | ||
149 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java new file mode 100644 index 0000000..3a2ac71 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java | |||
@@ -0,0 +1,231 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2013 Ken Gilmer, Intel Corporation | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Ken Gilmer - initial API and implementation | ||
10 | * Jessica Zhang (Intel) - Extend to support auto-fill base on src_uri value | ||
11 | * Ioana Grigoropol (Intel) - adapt class for remote support | ||
12 | *******************************************************************************/ | ||
13 | package org.yocto.bc.ui.wizards; | ||
14 | |||
15 | import java.io.ByteArrayInputStream; | ||
16 | import java.io.IOException; | ||
17 | import java.io.InputStream; | ||
18 | import java.io.File; | ||
19 | import java.lang.reflect.InvocationTargetException; | ||
20 | import java.util.ArrayList; | ||
21 | |||
22 | import org.eclipse.core.resources.IContainer; | ||
23 | import org.eclipse.core.resources.IFile; | ||
24 | import org.eclipse.core.resources.IProject; | ||
25 | import org.eclipse.core.resources.IResource; | ||
26 | import org.eclipse.core.resources.IWorkspaceRoot; | ||
27 | import org.eclipse.core.resources.ResourcesPlugin; | ||
28 | import org.eclipse.core.runtime.CoreException; | ||
29 | import org.eclipse.core.runtime.IProgressMonitor; | ||
30 | import org.eclipse.core.runtime.IStatus; | ||
31 | import org.eclipse.core.runtime.Path; | ||
32 | import org.eclipse.core.runtime.Status; | ||
33 | import org.eclipse.jface.dialogs.MessageDialog; | ||
34 | import org.eclipse.jface.operation.IRunnableWithProgress; | ||
35 | import org.eclipse.jface.viewers.ISelection; | ||
36 | import org.eclipse.jface.viewers.IStructuredSelection; | ||
37 | import org.eclipse.jface.wizard.Wizard; | ||
38 | import org.eclipse.rse.core.model.IHost; | ||
39 | import org.eclipse.ui.INewWizard; | ||
40 | import org.eclipse.ui.IWorkbench; | ||
41 | import org.eclipse.ui.IWorkbenchPage; | ||
42 | import org.eclipse.ui.IWorkbenchWizard; | ||
43 | import org.eclipse.ui.PartInitException; | ||
44 | import org.eclipse.ui.PlatformUI; | ||
45 | import org.eclipse.ui.ide.IDE; | ||
46 | |||
47 | import org.yocto.bc.bitbake.BBLanguageHelper; | ||
48 | import org.yocto.bc.ui.Activator; | ||
49 | import org.yocto.bc.ui.model.ProjectInfo; | ||
50 | import org.yocto.remote.utils.RemoteHelper; | ||
51 | import org.yocto.remote.utils.YoctoCommand; | ||
52 | |||
53 | public class NewBitBakeFileRecipeWizard extends Wizard implements INewWizard { | ||
54 | private NewBitBakeFileRecipeWizardPage page; | ||
55 | private ISelection selection; | ||
56 | private IHost connection; | ||
57 | |||
58 | public NewBitBakeFileRecipeWizard() { | ||
59 | super(); | ||
60 | setNeedsProgressMonitor(true); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | public void addPages() { | ||
65 | page = new NewBitBakeFileRecipeWizardPage(selection, connection); | ||
66 | addPage(page); | ||
67 | } | ||
68 | |||
69 | private void doFinish(BitbakeRecipeUIElement element, IProgressMonitor monitor) throws CoreException { | ||
70 | String fileName = element.getFile(); | ||
71 | monitor.beginTask("Creating " + fileName, 2); | ||
72 | IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); | ||
73 | IResource resource = root.findMember(new Path(element.getContainer())); | ||
74 | if (!resource.exists() || !(resource instanceof IContainer)) { | ||
75 | throwCoreException("Container \"" + element.getContainer() + "\" does not exist."); | ||
76 | } | ||
77 | IContainer container = (IContainer) resource; | ||
78 | |||
79 | // If the extension wasn't specified, assume .bb | ||
80 | if (!fileName.endsWith(".bb") && !fileName.endsWith(".inc") && !fileName.endsWith(".conf")) { | ||
81 | fileName = fileName + ".bb"; | ||
82 | } | ||
83 | |||
84 | final IFile file = container.getFile(new Path(fileName)); | ||
85 | try { | ||
86 | InputStream stream = openContentStream(element); | ||
87 | if (file.exists()) { | ||
88 | file.setContents(stream, true, true, monitor); | ||
89 | } else { | ||
90 | file.create(stream, true, monitor); | ||
91 | } | ||
92 | stream.close(); | ||
93 | } catch (IOException e) { | ||
94 | } | ||
95 | monitor.worked(1); | ||
96 | monitor.setTaskName("Opening file for editing..."); | ||
97 | getShell().getDisplay().asyncExec(new Runnable() { | ||
98 | public void run() { | ||
99 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | ||
100 | try { | ||
101 | IDE.openEditor(page, file, true); | ||
102 | } catch (PartInitException e) { | ||
103 | } | ||
104 | } | ||
105 | }); | ||
106 | monitor.worked(1); | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * We will accept the selection in the workbench to see if we can initialize | ||
111 | * from it. | ||
112 | * | ||
113 | * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection) | ||
114 | */ | ||
115 | public void init(IWorkbench workbench, IStructuredSelection selection) { | ||
116 | this.selection = selection; | ||
117 | if (selection instanceof IStructuredSelection) { | ||
118 | Object element = selection.getFirstElement(); | ||
119 | |||
120 | if (element instanceof IResource) { | ||
121 | IProject p = ((IResource)element).getProject(); | ||
122 | try { | ||
123 | ProjectInfo projInfo = Activator.getProjInfo(p.getLocationURI()); | ||
124 | this.connection = projInfo.getConnection(); | ||
125 | } catch (CoreException e) { | ||
126 | e.printStackTrace(); | ||
127 | } catch (InvocationTargetException e) { | ||
128 | e.printStackTrace(); | ||
129 | } catch (InterruptedException e) { | ||
130 | e.printStackTrace(); | ||
131 | } | ||
132 | |||
133 | } | ||
134 | } | ||
135 | } | ||
136 | |||
137 | /** | ||
138 | * We will initialize file contents with a sample text. | ||
139 | * @param srcuri | ||
140 | * @param author | ||
141 | * @param homepage | ||
142 | * @param license | ||
143 | * @param description | ||
144 | * @param fileName | ||
145 | * @param newPage | ||
146 | */ | ||
147 | |||
148 | private InputStream openContentStream(BitbakeRecipeUIElement element) { | ||
149 | |||
150 | StringBuffer sb = new StringBuffer(); | ||
151 | |||
152 | sb.append("DESCRIPTION = \"" + element.getDescription() + "\"\n"); | ||
153 | |||
154 | if (element.getAuthor().length() > 0) { | ||
155 | sb.append("AUTHOR = \"" + element.getAuthor() + "\"\n"); | ||
156 | } | ||
157 | |||
158 | if (element.getHomePage().length() > 0) { | ||
159 | sb.append("HOMEPAGE = \"" + element.getHomePage() + "\"\n"); | ||
160 | } | ||
161 | |||
162 | if (element.getSection().length() > 0) { | ||
163 | sb.append("SECTION = \"" + element.getSection() + "\"\n"); | ||
164 | } | ||
165 | |||
166 | if (element.getLicense().length() > 0) { | ||
167 | sb.append("LICENSE = \"" + element.getLicense() + "\"\n"); | ||
168 | } | ||
169 | |||
170 | if (element.getChecksum().length() > 0) { | ||
171 | sb.append("LIC_FILES_CHKSUM = \"" + element.getChecksum() + "\"\n"); | ||
172 | } | ||
173 | |||
174 | if (element.getSrcuri().length() > 0) { | ||
175 | sb.append("SRC_URI = \"" + element.getSrcuri() + "\"\n"); | ||
176 | } | ||
177 | |||
178 | if (element.getMd5sum().length() > 0) { | ||
179 | sb.append("SRC_URI[md5sum] = \"" + element.getMd5sum() + "\"\n"); | ||
180 | } | ||
181 | |||
182 | if (element.getsha256sum().length() > 0) { | ||
183 | sb.append("SRC_URI[sha256sum] = \"" + element.getsha256sum() + "\"\n"); | ||
184 | } | ||
185 | |||
186 | ArrayList<String> inheritance = element.getInheritance(); | ||
187 | if (!inheritance.isEmpty()) { | ||
188 | Object ia[] = inheritance.toArray(); | ||
189 | String inheritance_str = "inherit "; | ||
190 | for(int i=0; i<ia.length; i++) | ||
191 | inheritance_str += ((String) ia[i]) + " "; | ||
192 | sb.append(inheritance_str); | ||
193 | } | ||
194 | sb.append("\n"); | ||
195 | |||
196 | return new ByteArrayInputStream(sb.toString().getBytes()); | ||
197 | } | ||
198 | |||
199 | @Override | ||
200 | public boolean performFinish() { | ||
201 | final BitbakeRecipeUIElement element = page.populateUIElement(); | ||
202 | |||
203 | IRunnableWithProgress op = new IRunnableWithProgress() { | ||
204 | public void run(IProgressMonitor monitor) throws InvocationTargetException { | ||
205 | try { | ||
206 | doFinish(element, monitor); | ||
207 | RemoteHelper.handleRunCommandRemote(connection, new YoctoCommand("rm -rf " + element.getMetaDir() + "/temp", "", ""), monitor); | ||
208 | } catch (Exception e) { | ||
209 | throw new InvocationTargetException(e); | ||
210 | } finally { | ||
211 | monitor.done(); | ||
212 | } | ||
213 | } | ||
214 | }; | ||
215 | try { | ||
216 | getContainer().run(true, false, op); | ||
217 | } catch (InterruptedException e) { | ||
218 | return false; | ||
219 | } catch (InvocationTargetException e) { | ||
220 | Throwable realException = e.getTargetException(); | ||
221 | MessageDialog.openError(getShell(), "Error", realException.getMessage()); | ||
222 | return false; | ||
223 | } | ||
224 | return true; | ||
225 | } | ||
226 | |||
227 | private void throwCoreException(String message) throws CoreException { | ||
228 | IStatus status = new Status(IStatus.ERROR, "org.yocto.bc.ui", IStatus.OK, message, null); | ||
229 | throw new CoreException(status); | ||
230 | } | ||
231 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java new file mode 100644 index 0000000..3bdcffd --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java | |||
@@ -0,0 +1,592 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2013 Ken Gilmer, Intel Corporation | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Ken Gilmer - initial API and implementation | ||
10 | * Jessica Zhang (Intel) - Extend to support auto-fill base on src_uri value | ||
11 | * Ioana Grigoropol (Intel) - adapt class for remote support | ||
12 | *******************************************************************************/ | ||
13 | package org.yocto.bc.ui.wizards; | ||
14 | |||
15 | import java.util.List; | ||
16 | import org.eclipse.core.resources.IContainer; | ||
17 | import org.eclipse.core.resources.IProject; | ||
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.IProgressMonitor; | ||
22 | import org.eclipse.core.runtime.NullProgressMonitor; | ||
23 | import org.eclipse.core.runtime.Path; | ||
24 | import org.eclipse.core.runtime.IPath; | ||
25 | import org.eclipse.core.runtime.SubProgressMonitor; | ||
26 | import org.eclipse.jface.operation.IRunnableWithProgress; | ||
27 | import org.eclipse.jface.viewers.ISelection; | ||
28 | import org.eclipse.jface.viewers.IStructuredSelection; | ||
29 | import org.eclipse.jface.window.Window; | ||
30 | import org.eclipse.jface.wizard.WizardPage; | ||
31 | import org.eclipse.rse.core.model.IHost; | ||
32 | import org.eclipse.rse.services.files.IFileService; | ||
33 | import org.eclipse.rse.services.files.IHostFile; | ||
34 | import org.eclipse.swt.SWT; | ||
35 | import org.eclipse.swt.events.ModifyEvent; | ||
36 | import org.eclipse.swt.events.ModifyListener; | ||
37 | import org.eclipse.swt.events.SelectionAdapter; | ||
38 | import org.eclipse.swt.events.SelectionEvent; | ||
39 | import org.eclipse.swt.layout.GridData; | ||
40 | import org.eclipse.swt.layout.GridLayout; | ||
41 | import org.eclipse.swt.widgets.Button; | ||
42 | import org.eclipse.swt.widgets.Composite; | ||
43 | import org.eclipse.swt.widgets.DirectoryDialog; | ||
44 | import org.eclipse.swt.widgets.FileDialog; | ||
45 | import org.eclipse.swt.widgets.Label; | ||
46 | import org.eclipse.swt.widgets.Text; | ||
47 | import org.eclipse.ui.dialogs.ContainerSelectionDialog; | ||
48 | import org.yocto.bc.ui.Activator; | ||
49 | import org.yocto.bc.ui.model.ProjectInfo; | ||
50 | import org.yocto.remote.utils.ProcessStreamBuffer; | ||
51 | import org.yocto.remote.utils.RemoteHelper; | ||
52 | import org.yocto.remote.utils.YoctoCommand; | ||
53 | |||
54 | import java.util.HashMap; | ||
55 | import java.util.Hashtable; | ||
56 | import java.util.Set; | ||
57 | import java.util.ArrayList; | ||
58 | import java.util.Enumeration; | ||
59 | import java.util.Iterator; | ||
60 | import java.util.regex.Pattern; | ||
61 | |||
62 | import java.io.BufferedReader; | ||
63 | import java.io.InputStreamReader; | ||
64 | import java.io.File; | ||
65 | import java.io.FileReader; | ||
66 | import java.io.IOException; | ||
67 | import java.io.FileInputStream; | ||
68 | import java.io.InputStream; | ||
69 | import java.io.FilenameFilter; | ||
70 | import java.security.MessageDigest; | ||
71 | import java.lang.reflect.InvocationTargetException; | ||
72 | import java.math.BigInteger; | ||
73 | import java.net.URI; | ||
74 | import java.net.URISyntaxException; | ||
75 | |||
76 | public class NewBitBakeFileRecipeWizardPage extends WizardPage { | ||
77 | private Text containerText; | ||
78 | private Text fileText; | ||
79 | |||
80 | private Text descriptionText; | ||
81 | private Text licenseText; | ||
82 | private Text checksumText; | ||
83 | private Text homepageText; | ||
84 | private Text authorText; | ||
85 | private Text sectionText; | ||
86 | private Text txtSrcURI; | ||
87 | private Text md5sumText; | ||
88 | private Text sha256sumText; | ||
89 | private Button btnPopulate; | ||
90 | |||
91 | private BitbakeRecipeUIElement element; | ||
92 | |||
93 | private ISelection selection; | ||
94 | private URI metaDirLoc; | ||
95 | private ArrayList inheritance; | ||
96 | private final IHost connection; | ||
97 | |||
98 | private String tempFolderPath; | ||
99 | private String srcFileNameExt; | ||
100 | private String srcFileName; | ||
101 | |||
102 | public static final String TEMP_FOLDER_NAME = "temp"; | ||
103 | public static final String TAR_BZ2_EXT = ".tar.bz2"; | ||
104 | public static final String TAR_GZ_EXT = ".tar.gz"; | ||
105 | public static final String HTTP = "http"; | ||
106 | public static final String FTP ="ftp"; | ||
107 | public static final String BB_RECIPE_EXT =".bb"; | ||
108 | private static final String COPYING_FILE = "COPYING"; | ||
109 | |||
110 | private static final String CMAKE_LIST = "cmakelists.txt"; | ||
111 | private static final String CMAKE = "cmake"; | ||
112 | private static final String SETUP_SCRIPT = "setup.py"; | ||
113 | private static final String DISUTILS = "disutils"; | ||
114 | private static final String CONFIGURE_IN = "configure.in"; | ||
115 | private static final String CONFIGURE_AC = "configure.ac"; | ||
116 | private static final String AUTOTOOLS = "autotools"; | ||
117 | |||
118 | private static final String md5Pattern = "^[0-9a-f]{32}$"; | ||
119 | protected static final String sha256Pattern = "^[0-9a-f]{64}$"; | ||
120 | |||
121 | private static final String MIRRORS_FILE = "mirrors.bbclass"; | ||
122 | private static final String CLASSES_FOLDER = "classes"; | ||
123 | |||
124 | private HashMap<String, String> mirrorTable; | ||
125 | private URI extractDir; | ||
126 | |||
127 | protected ProcessStreamBuffer md5Buffer; | ||
128 | protected ProcessStreamBuffer sha256Buffer; | ||
129 | protected ProcessStreamBuffer md5CopyingBuffer; | ||
130 | |||
131 | public NewBitBakeFileRecipeWizardPage(ISelection selection, IHost connection) { | ||
132 | super("wizardPage"); | ||
133 | setTitle("BitBake Recipe"); | ||
134 | setDescription("Create a new BitBake recipe."); | ||
135 | this.selection = selection; | ||
136 | this.connection = connection; | ||
137 | element = new BitbakeRecipeUIElement(); | ||
138 | inheritance = new ArrayList(); | ||
139 | } | ||
140 | |||
141 | public void createControl(Composite parent) { | ||
142 | final Composite container = new Composite(parent, SWT.NULL); | ||
143 | GridLayout layout = new GridLayout(); | ||
144 | container.setLayout(layout); | ||
145 | layout.numColumns = 3; | ||
146 | layout.verticalSpacing = 9; | ||
147 | |||
148 | Label label = new Label(container, SWT.NULL); | ||
149 | GridData gd = new GridData(); | ||
150 | gd.horizontalSpan = 3; | ||
151 | label.setLayoutData(gd); | ||
152 | |||
153 | label = new Label(container, SWT.NULL); | ||
154 | label.setText("Recipe &Directory:"); | ||
155 | |||
156 | containerText = new Text(container, SWT.BORDER | SWT.SINGLE); | ||
157 | gd = new GridData(GridData.FILL_HORIZONTAL); | ||
158 | containerText.setLayoutData(gd); | ||
159 | containerText.addModifyListener(new ModifyListener() { | ||
160 | public void modifyText(ModifyEvent e) { | ||
161 | dialogChanged(); | ||
162 | } | ||
163 | }); | ||
164 | |||
165 | Button buttonBrowse = new Button(container, SWT.PUSH); | ||
166 | buttonBrowse.setText("Browse..."); | ||
167 | buttonBrowse.addSelectionListener(new SelectionAdapter() { | ||
168 | @Override | ||
169 | public void widgetSelected(SelectionEvent e) { | ||
170 | handleBrowse(container, containerText); | ||
171 | } | ||
172 | }); | ||
173 | |||
174 | label = new Label(container, SWT.NULL); | ||
175 | gd = new GridData(); | ||
176 | gd.horizontalSpan = 3; | ||
177 | label.setLayoutData(gd); | ||
178 | |||
179 | label = new Label(container, SWT.NULL); | ||
180 | label.setText("SRC_&URI:"); | ||
181 | |||
182 | txtSrcURI = new Text(container, SWT.BORDER | SWT.SINGLE); | ||
183 | gd = new GridData(GridData.FILL_HORIZONTAL); | ||
184 | txtSrcURI.setLayoutData(gd); | ||
185 | txtSrcURI.addModifyListener(new ModifyListener() { | ||
186 | public void modifyText(ModifyEvent e) { | ||
187 | if (txtSrcURI.getText().trim().isEmpty()) { | ||
188 | if (btnPopulate != null) | ||
189 | btnPopulate.setEnabled(false); | ||
190 | } else if (btnPopulate != null){ | ||
191 | btnPopulate.setEnabled(true); | ||
192 | } | ||
193 | dialogChanged(); | ||
194 | } | ||
195 | }); | ||
196 | |||
197 | btnPopulate = new Button(container, SWT.PUSH); | ||
198 | btnPopulate.setText("Populate..."); | ||
199 | btnPopulate.setEnabled(false); | ||
200 | btnPopulate.addSelectionListener(new SelectionAdapter() { | ||
201 | @Override | ||
202 | public void widgetSelected(SelectionEvent e) { | ||
203 | handlePopulate(); | ||
204 | } | ||
205 | }); | ||
206 | |||
207 | createField(container, "&Recipe Name:", (fileText = new Text(container, SWT.BORDER | SWT.SINGLE))); | ||
208 | createField(container, "SRC_URI[&md5sum]:", (md5sumText = new Text(container, SWT.BORDER | SWT.SINGLE))); | ||
209 | createField(container, "SRC_URI[&sha256sum]:", (sha256sumText = new Text(container, SWT.BORDER | SWT.SINGLE))); | ||
210 | createField(container, "License File &Checksum:", (checksumText = new Text(container, SWT.BORDER | SWT.SINGLE))); | ||
211 | createField(container, "&Package Description:", (descriptionText = new Text(container, SWT.BORDER | SWT.SINGLE))); | ||
212 | createField(container, "&License:", (licenseText = new Text(container, SWT.BORDER | SWT.SINGLE))); | ||
213 | |||
214 | createField(container, "&Homepage:", (homepageText = new Text(container, SWT.BORDER | SWT.SINGLE))); | ||
215 | createField(container, "Package &Author:", (authorText = new Text(container, SWT.BORDER | SWT.SINGLE))); | ||
216 | createField(container, "&Section:", (sectionText = new Text(container, SWT.BORDER | SWT.SINGLE))); | ||
217 | |||
218 | initialize(); | ||
219 | dialogChanged(); | ||
220 | setControl(container); | ||
221 | } | ||
222 | |||
223 | private void createField(Composite container, String title, Text control) { | ||
224 | Label label = new Label(container, SWT.NONE); | ||
225 | label.setText(title); | ||
226 | label.moveAbove(control); | ||
227 | |||
228 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
229 | gd.horizontalSpan = 2; | ||
230 | control.setLayoutData(gd); | ||
231 | control.addModifyListener(new ModifyListener() { | ||
232 | |||
233 | public void modifyText(ModifyEvent e) { | ||
234 | dialogChanged(); | ||
235 | } | ||
236 | |||
237 | }); | ||
238 | } | ||
239 | |||
240 | private void dialogChanged() { | ||
241 | String containerName = containerText.getText(); | ||
242 | IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(containerName)); | ||
243 | String fileName = fileText.getText(); | ||
244 | |||
245 | if (containerName.length() == 0) { | ||
246 | updateStatus("Directory must be specified"); | ||
247 | return; | ||
248 | } | ||
249 | |||
250 | if (container == null || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) { | ||
251 | updateStatus("File container must exist"); | ||
252 | return; | ||
253 | } | ||
254 | if (!container.isAccessible()) { | ||
255 | updateStatus("Project must be writable"); | ||
256 | return; | ||
257 | } | ||
258 | |||
259 | IProject project = container.getProject(); | ||
260 | ProjectInfo projInfo = null; | ||
261 | try { | ||
262 | projInfo = Activator.getProjInfo(project.getLocationURI()); | ||
263 | } catch (InvocationTargetException e) { | ||
264 | e.printStackTrace(); | ||
265 | } catch (CoreException e) { | ||
266 | e.printStackTrace(); | ||
267 | } catch (InterruptedException e) { | ||
268 | e.printStackTrace(); | ||
269 | } | ||
270 | metaDirLoc = RemoteHelper.createNewURI(projInfo.getOriginalURI(), "meta"); | ||
271 | |||
272 | if (fileName.length() == 0) { | ||
273 | updateStatus("File name must be specified"); | ||
274 | return; | ||
275 | } | ||
276 | if (fileName.contains(" ")) { | ||
277 | updateStatus("File name must be valid with no space in it"); | ||
278 | return; | ||
279 | } | ||
280 | if (fileName.replace('\\', '/').indexOf('/', 1) > 0) { | ||
281 | updateStatus("File name must be valid"); | ||
282 | return; | ||
283 | } | ||
284 | |||
285 | if (descriptionText.getText().length() == 0) { | ||
286 | updateStatus("Recipe must have a description"); | ||
287 | return; | ||
288 | } | ||
289 | |||
290 | if (licenseText.getText().length() == 0) { | ||
291 | updateStatus("Recipe must have a license"); | ||
292 | return; | ||
293 | } | ||
294 | |||
295 | if (txtSrcURI.getText().length() == 0) { | ||
296 | updateStatus("SRC_URI can't be empty"); | ||
297 | } | ||
298 | |||
299 | updateStatus(null); | ||
300 | } | ||
301 | |||
302 | public BitbakeRecipeUIElement populateUIElement() { | ||
303 | element.setAuthor(authorText.getText()); | ||
304 | element.setChecksum(checksumText.getText()); | ||
305 | element.setContainer(containerText.getText()); | ||
306 | element.setDescription(descriptionText.getText()); | ||
307 | element.setFile(fileText.getText()); | ||
308 | element.setHomePage(homepageText.getText()); | ||
309 | element.setLicense(licenseText.getText()); | ||
310 | element.setMd5sum(md5sumText.getText()); | ||
311 | element.setSection(sectionText.getText()); | ||
312 | element.setSha256sum(sha256sumText.getText()); | ||
313 | element.setSrcuri(txtSrcURI.getText()); | ||
314 | element.setInheritance(inheritance); | ||
315 | element.setMetaDir(metaDirLoc); | ||
316 | |||
317 | return element; | ||
318 | } | ||
319 | |||
320 | private void handleBrowse(final Composite parent, final Text text) { | ||
321 | ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false, "Select project directory"); | ||
322 | if (dialog.open() == Window.OK) { | ||
323 | Object[] result = dialog.getResult(); | ||
324 | if (result.length == 1) { | ||
325 | text.setText(((Path) result[0]).toString()); | ||
326 | } | ||
327 | } | ||
328 | } | ||
329 | |||
330 | private void handlePopulate() { | ||
331 | try { | ||
332 | IProgressMonitor monitor = new NullProgressMonitor(); | ||
333 | URI srcURI = new URI(txtSrcURI.getText().trim()); | ||
334 | String scheme = srcURI.getScheme(); | ||
335 | this.srcFileNameExt = getSrcFileName(true); | ||
336 | this.srcFileName = getSrcFileName(false); | ||
337 | if ((scheme.equals(HTTP) || scheme.equals(FTP)) | ||
338 | && (srcFileNameExt.endsWith(TAR_GZ_EXT) || srcFileNameExt.endsWith(TAR_BZ2_EXT))) { | ||
339 | handleRemotePopulate(srcURI, monitor); | ||
340 | } else { | ||
341 | String packageName = srcFileName.replace("-", "_"); | ||
342 | fileText.setText(packageName + BB_RECIPE_EXT); | ||
343 | |||
344 | handleLocalPopulate(srcURI, monitor); | ||
345 | } | ||
346 | } catch (URISyntaxException e) { | ||
347 | e.printStackTrace(); | ||
348 | } catch (InvocationTargetException e) { | ||
349 | e.printStackTrace(); | ||
350 | } catch (InterruptedException e) { | ||
351 | e.printStackTrace(); | ||
352 | } | ||
353 | } | ||
354 | |||
355 | private String getSrcFileName(boolean withExt){ | ||
356 | URI srcURI; | ||
357 | try { | ||
358 | srcURI = new URI(txtSrcURI.getText().trim()); | ||
359 | String path = srcURI.getPath(); | ||
360 | String fileName = path.substring(path.lastIndexOf("/") + 1); | ||
361 | if (withExt) | ||
362 | return fileName; | ||
363 | else { | ||
364 | if (fileName.endsWith(TAR_BZ2_EXT)) { | ||
365 | return fileName.substring(0, fileName.indexOf(TAR_BZ2_EXT)); | ||
366 | } else if(fileName.endsWith(TAR_GZ_EXT)){ | ||
367 | return fileName.substring(0, fileName.indexOf(TAR_GZ_EXT)); | ||
368 | } | ||
369 | } | ||
370 | } catch (URISyntaxException e) { | ||
371 | e.printStackTrace(); | ||
372 | } | ||
373 | return ""; | ||
374 | } | ||
375 | private void handleRemotePopulate(final URI srcURI, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { | ||
376 | populateRecipeName(); | ||
377 | |||
378 | this.getContainer().run(true, true, new IRunnableWithProgress() { | ||
379 | |||
380 | @Override | ||
381 | public void run(IProgressMonitor monitor) throws InvocationTargetException, | ||
382 | InterruptedException { | ||
383 | monitor.beginTask("Populating recipe fields ... ", 100); | ||
384 | try { | ||
385 | String metaDirLocPath = metaDirLoc.getPath(); | ||
386 | monitor.subTask("Cleaning environment"); | ||
387 | YoctoCommand rmYCmd = new YoctoCommand("rm -rf " + TEMP_FOLDER_NAME, metaDirLocPath, ""); | ||
388 | RemoteHelper.handleRunCommandRemote(connection, rmYCmd, new SubProgressMonitor(monitor, 5)); | ||
389 | |||
390 | YoctoCommand mkdirYCmd = new YoctoCommand( "mkdir " + TEMP_FOLDER_NAME, metaDirLocPath, ""); | ||
391 | RemoteHelper.handleRunCommandRemote(connection, mkdirYCmd, new SubProgressMonitor(monitor, 5)); | ||
392 | |||
393 | updateTempFolderPath(); | ||
394 | monitor.worked(10); | ||
395 | |||
396 | monitor.subTask("Downloading package sources"); | ||
397 | |||
398 | updateTempFolderPath(); | ||
399 | |||
400 | YoctoCommand wgetYCmd = new YoctoCommand("wget " + srcURI.toURL(), tempFolderPath, ""); | ||
401 | RemoteHelper.handleRunCommandRemote(connection, wgetYCmd, new SubProgressMonitor(monitor, 40)); | ||
402 | |||
403 | monitor.worked(50); | ||
404 | |||
405 | monitor.subTask("Compute package checksums"); | ||
406 | String md5Cmd = "md5sum " + srcFileNameExt; | ||
407 | YoctoCommand md5YCmd = new YoctoCommand(md5Cmd, tempFolderPath, ""); | ||
408 | |||
409 | RemoteHelper.handleRunCommandRemote(connection, md5YCmd, new SubProgressMonitor(monitor, 10)); | ||
410 | md5Buffer = md5YCmd.getProcessBuffer(); | ||
411 | |||
412 | monitor.worked(60); | ||
413 | |||
414 | String sha256Cmd = "sha256sum " + srcFileNameExt; | ||
415 | YoctoCommand sha256YCmd = new YoctoCommand(sha256Cmd, tempFolderPath, ""); | ||
416 | RemoteHelper.handleRunCommandRemote(connection, sha256YCmd, new SubProgressMonitor(monitor, 10)); | ||
417 | sha256Buffer = sha256YCmd.getProcessBuffer(); | ||
418 | |||
419 | monitor.worked(70); | ||
420 | |||
421 | monitor.subTask("Extracting package"); | ||
422 | extractDir = extractPackage(srcURI, new SubProgressMonitor(monitor, 0)); | ||
423 | monitor.worked(80); | ||
424 | |||
425 | YoctoCommand licenseChecksumCmd = populateLicenseFileChecksum(extractDir, new SubProgressMonitor(monitor, 10)); | ||
426 | md5CopyingBuffer = licenseChecksumCmd.getProcessBuffer(); | ||
427 | |||
428 | monitor.subTask("Creating mirror lookup table"); | ||
429 | mirrorTable = createMirrorLookupTable(new SubProgressMonitor(monitor, 10)); | ||
430 | |||
431 | monitor.worked(90); | ||
432 | monitor.done(); | ||
433 | } catch (Exception e) { | ||
434 | e.printStackTrace(); | ||
435 | } | ||
436 | } | ||
437 | }); | ||
438 | updateSrcUri(mirrorTable, srcURI); | ||
439 | populateInheritance(extractDir, monitor); | ||
440 | |||
441 | String md5Val = md5Buffer.getOutputLineContaining(srcFileNameExt, md5Pattern); | ||
442 | md5sumText.setText(Pattern.matches(md5Pattern, md5Val) ? md5Val : ""); | ||
443 | String sha256Val = sha256Buffer.getOutputLineContaining(srcFileNameExt, sha256Pattern); | ||
444 | sha256sumText.setText(Pattern.matches(sha256Pattern, sha256Val) ? sha256Val : ""); | ||
445 | String checkSumVal = md5CopyingBuffer.getOutputLineContaining(COPYING_FILE, md5Pattern); | ||
446 | checksumText.setText(RemoteHelper.createNewURI(extractDir, COPYING_FILE).toString() + ";md5=" + (Pattern.matches(md5Pattern, checkSumVal) ? checkSumVal : "")); | ||
447 | } | ||
448 | |||
449 | private void updateTempFolderPath(){ | ||
450 | this.tempFolderPath = getMetaFolderPath() + TEMP_FOLDER_NAME + "/"; | ||
451 | } | ||
452 | |||
453 | private String getMetaFolderPath(){ | ||
454 | String sep = metaDirLoc.getPath().endsWith("/")? "" : "/"; | ||
455 | return metaDirLoc.getPath() + sep; | ||
456 | } | ||
457 | |||
458 | private void handleLocalPopulate(URI srcURI, IProgressMonitor monitor) { | ||
459 | populateLicenseFileChecksum(srcURI, monitor); | ||
460 | populateInheritance(srcURI, monitor); | ||
461 | } | ||
462 | |||
463 | private URI extractPackage(URI srcURI, IProgressMonitor monitor) { | ||
464 | try { | ||
465 | String path = srcFileNameExt; | ||
466 | String tarCmd = "tar "; | ||
467 | if (path.endsWith(TAR_BZ2_EXT)) { | ||
468 | tarCmd += "-zxvf "; | ||
469 | } else if(path.endsWith(TAR_GZ_EXT)){ | ||
470 | tarCmd += "-xvf "; | ||
471 | } | ||
472 | |||
473 | RemoteHelper.handleRunCommandRemote(connection, new YoctoCommand(tarCmd + path, tempFolderPath, ""), monitor); | ||
474 | |||
475 | return RemoteHelper.createNewURI(metaDirLoc, TEMP_FOLDER_NAME + "/" + srcFileName); | ||
476 | |||
477 | } catch (Exception e) { | ||
478 | e.printStackTrace(); | ||
479 | } | ||
480 | return null; | ||
481 | } | ||
482 | |||
483 | private void populateInheritance(URI extractDir, IProgressMonitor monitor) { | ||
484 | IHostFile[] hostFiles = RemoteHelper.getRemoteDirContent(connection, metaDirLoc.getPath(), "", IFileService.FILE_TYPE_FILES, monitor); | ||
485 | if (hostFiles == null) | ||
486 | return; | ||
487 | |||
488 | for (IHostFile file: hostFiles) { | ||
489 | String fileName = file.getName(); | ||
490 | if (fileName.equalsIgnoreCase(CMAKE_LIST)){ | ||
491 | inheritance.add(CMAKE); | ||
492 | } else if (fileName.equalsIgnoreCase(SETUP_SCRIPT)) { | ||
493 | inheritance.add(DISUTILS); | ||
494 | } else if (fileName.equalsIgnoreCase(CONFIGURE_AC) || file.getName().equalsIgnoreCase(CONFIGURE_IN)) { | ||
495 | inheritance.add(AUTOTOOLS); | ||
496 | } | ||
497 | } | ||
498 | } | ||
499 | |||
500 | private YoctoCommand populateLicenseFileChecksum(URI extractDir, IProgressMonitor monitor) { | ||
501 | if (extractDir == null) | ||
502 | throw new RuntimeException("Something went wrong during source extraction!"); | ||
503 | |||
504 | try { | ||
505 | YoctoCommand catCmd = new YoctoCommand("md5sum " + COPYING_FILE, extractDir.getPath(), ""); | ||
506 | RemoteHelper.handleRunCommandRemote(connection, catCmd, monitor); | ||
507 | return catCmd; | ||
508 | } catch (Exception e) { | ||
509 | throw new RuntimeException("Unable to process file for MD5 calculation", e); | ||
510 | } | ||
511 | |||
512 | } | ||
513 | |||
514 | private HashMap<String, String> createMirrorLookupTable(IProgressMonitor monitor) throws Exception { | ||
515 | HashMap<String, String> mirrorMap = new HashMap<String, String>(); | ||
516 | |||
517 | YoctoCommand cmd = new YoctoCommand("cat " + MIRRORS_FILE, getMetaFolderPath() + CLASSES_FOLDER, ""); | ||
518 | RemoteHelper.handleRunCommandRemote(connection, cmd, monitor); | ||
519 | |||
520 | if (!cmd.getProcessBuffer().hasErrors()){ | ||
521 | String delims = "[\\t]+"; | ||
522 | List<String> outputLines = cmd.getProcessBuffer().getOutputLines(); | ||
523 | for (String outLine : outputLines) { | ||
524 | String[] tokens = outLine.split(delims); | ||
525 | if (tokens.length < 2) | ||
526 | continue; | ||
527 | String endingStr = " \\n \\"; | ||
528 | int idx = tokens[1].lastIndexOf(endingStr); | ||
529 | String key = tokens[1].substring(0, idx); | ||
530 | mirrorMap.put(key, tokens[0]); | ||
531 | } | ||
532 | } | ||
533 | return mirrorMap; | ||
534 | } | ||
535 | |||
536 | private void populateRecipeName() { | ||
537 | String fileName = fileText.getText(); | ||
538 | if (!fileName.isEmpty()) | ||
539 | return; | ||
540 | |||
541 | String recipeFile = srcFileName.replace("-", "_"); | ||
542 | recipeFile += BB_RECIPE_EXT; | ||
543 | if (recipeFile != null) | ||
544 | fileText.setText(recipeFile); | ||
545 | } | ||
546 | |||
547 | private void updateSrcUri(HashMap<String, String> mirrorsMap, URI srcUri) { | ||
548 | Set<String> mirrors = mirrorsMap.keySet(); | ||
549 | Iterator<String> iter = mirrors.iterator(); | ||
550 | String mirror_key = null; | ||
551 | String srcURL = srcUri.toString(); | ||
552 | |||
553 | while (iter.hasNext()) { | ||
554 | String value = iter.next(); | ||
555 | if (srcURL.startsWith(value)) { | ||
556 | mirror_key = value; | ||
557 | break; | ||
558 | } | ||
559 | } | ||
560 | |||
561 | if (mirror_key != null) { | ||
562 | String replace_string = mirrorsMap.get(mirror_key); | ||
563 | if (replace_string != null) | ||
564 | srcURL = replace_string + srcURL.substring(mirror_key.length()); | ||
565 | } | ||
566 | int idx = srcURL.lastIndexOf("-"); | ||
567 | String new_src_uri = srcURL.substring(0, idx)+"-${PV}" + TAR_GZ_EXT; | ||
568 | txtSrcURI.setText(new_src_uri); | ||
569 | } | ||
570 | |||
571 | private void initialize() { | ||
572 | if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) { | ||
573 | IStructuredSelection ssel = (IStructuredSelection) selection; | ||
574 | if (ssel.size() > 1) | ||
575 | return; | ||
576 | Object obj = ssel.getFirstElement(); | ||
577 | if (obj instanceof IResource) { | ||
578 | IContainer container; | ||
579 | if (obj instanceof IContainer) | ||
580 | container = (IContainer) obj; | ||
581 | else | ||
582 | container = ((IResource) obj).getParent(); | ||
583 | containerText.setText(container.getFullPath().toString()); | ||
584 | } | ||
585 | } | ||
586 | } | ||
587 | |||
588 | private void updateStatus(String message) { | ||
589 | setErrorMessage(message); | ||
590 | setPageComplete(message == null); | ||
591 | } | ||
592 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java new file mode 100644 index 0000000..71ea70c --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/BBCProjectPage.java | |||
@@ -0,0 +1,236 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2009 Ken Gilmer | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Ken Gilmer - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.wizards.importProject; | ||
12 | |||
13 | import java.io.File; | ||
14 | import java.util.Map; | ||
15 | |||
16 | import org.eclipse.core.resources.IProject; | ||
17 | import org.eclipse.core.resources.IResource; | ||
18 | import org.eclipse.core.resources.IWorkspaceRoot; | ||
19 | import org.eclipse.core.resources.ResourcesPlugin; | ||
20 | import org.eclipse.core.runtime.IStatus; | ||
21 | import org.eclipse.swt.SWT; | ||
22 | import org.eclipse.swt.events.SelectionAdapter; | ||
23 | import org.eclipse.swt.events.SelectionEvent; | ||
24 | import org.eclipse.swt.layout.GridData; | ||
25 | import org.eclipse.swt.layout.GridLayout; | ||
26 | import org.eclipse.swt.widgets.Button; | ||
27 | import org.eclipse.swt.widgets.Composite; | ||
28 | import org.eclipse.swt.widgets.DirectoryDialog; | ||
29 | import org.eclipse.swt.widgets.FileDialog; | ||
30 | import org.eclipse.swt.widgets.Label; | ||
31 | import org.eclipse.swt.widgets.Text; | ||
32 | import org.eclipse.ui.PlatformUI; | ||
33 | |||
34 | import org.yocto.bc.ui.wizards.FiniteStateWizardPage; | ||
35 | |||
36 | /** | ||
37 | * Main property page for new project wizard. | ||
38 | * @author kgilmer | ||
39 | * | ||
40 | */ | ||
41 | public class BBCProjectPage extends FiniteStateWizardPage { | ||
42 | |||
43 | private class FileOpenSelectionAdapter extends SelectionAdapter { | ||
44 | @Override | ||
45 | public void widgetSelected(SelectionEvent e) { | ||
46 | FileDialog fd = new FileDialog(PlatformUI.getWorkbench() | ||
47 | .getDisplay().getActiveShell(), SWT.OPEN); | ||
48 | |||
49 | fd.setText("Open Configuration Script"); | ||
50 | fd.setFilterPath(txtProjectLocation.getText()); | ||
51 | |||
52 | String selected = fd.open(); | ||
53 | |||
54 | if (selected != null) { | ||
55 | txtInit.setText(selected); | ||
56 | updateModel(); | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | public static final String PAGE_TITLE = "Yocto Project BitBake Commander Project"; | ||
61 | private Text txtProjectLocation; | ||
62 | |||
63 | private Text txtInit; | ||
64 | private ValidationListener validationListener; | ||
65 | private Text txtProjectName; | ||
66 | |||
67 | public BBCProjectPage(Map model) { | ||
68 | super(PAGE_TITLE, model); | ||
69 | setTitle("Create new Yocto Project BitBake Commander project"); | ||
70 | setMessage("Enter information to create a BitBake Commander project."); | ||
71 | } | ||
72 | |||
73 | public void createControl(Composite parent) { | ||
74 | GridData gdFillH = new GridData(GridData.FILL_HORIZONTAL); | ||
75 | GridData gdVU = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); | ||
76 | |||
77 | Composite top = new Composite(parent, SWT.NONE); | ||
78 | top.setLayoutData(new GridData(GridData.FILL_BOTH)); | ||
79 | top.setLayout(new GridLayout()); | ||
80 | |||
81 | Composite projectNameComp = new Composite(top, SWT.NONE); | ||
82 | GridData gdProjName = new GridData(GridData.FILL_HORIZONTAL); | ||
83 | projectNameComp.setLayoutData(gdProjName); | ||
84 | projectNameComp.setLayout(new GridLayout(2, false)); | ||
85 | Label lblProjectName = new Label(projectNameComp, SWT.NONE); | ||
86 | lblProjectName.setText("N&ame:"); | ||
87 | |||
88 | txtProjectName = new Text(projectNameComp, SWT.BORDER); | ||
89 | txtProjectName.setLayoutData(gdFillH); | ||
90 | txtProjectName.setFocus(); | ||
91 | validationListener = new ValidationListener(); | ||
92 | |||
93 | txtProjectName.addModifyListener(validationListener); | ||
94 | |||
95 | Label lblProjectLocation = new Label(projectNameComp, SWT.None); | ||
96 | lblProjectLocation.setText("&Location:"); | ||
97 | |||
98 | Composite locComposite = new Composite(projectNameComp, SWT.NONE); | ||
99 | GridData gd = new GridData(GridData.VERTICAL_ALIGN_END | ||
100 | | GridData.FILL_HORIZONTAL); | ||
101 | gd.horizontalIndent = 0; | ||
102 | locComposite.setLayoutData(gd); | ||
103 | GridLayout gl = new GridLayout(2, false); | ||
104 | gl.marginWidth = 0; | ||
105 | locComposite.setLayout(gl); | ||
106 | |||
107 | txtProjectLocation = new Text(locComposite, SWT.BORDER); | ||
108 | txtProjectLocation.setLayoutData(gdFillH); | ||
109 | txtProjectLocation.addModifyListener(validationListener); | ||
110 | |||
111 | Button button = new Button(locComposite, SWT.PUSH); | ||
112 | button.setText("Browse..."); | ||
113 | button.addSelectionListener(new SelectionAdapter() { | ||
114 | @Override | ||
115 | public void widgetSelected(SelectionEvent e) { | ||
116 | handleBrowse(); | ||
117 | } | ||
118 | }); | ||
119 | |||
120 | Label lblInit = new Label(projectNameComp, SWT.NONE); | ||
121 | lblInit.setText("Init Script:"); | ||
122 | |||
123 | Composite initComposite = new Composite(projectNameComp, SWT.NONE); | ||
124 | gd = new GridData(GridData.VERTICAL_ALIGN_END | ||
125 | | GridData.FILL_HORIZONTAL); | ||
126 | gd.horizontalIndent = 0; | ||
127 | initComposite.setLayoutData(gd); | ||
128 | gl = new GridLayout(2, false); | ||
129 | gl.marginWidth = 0; | ||
130 | initComposite.setLayout(gl); | ||
131 | |||
132 | txtInit = new Text(initComposite, SWT.BORDER); | ||
133 | GridData gdi = new GridData(GridData.FILL_HORIZONTAL); | ||
134 | txtInit.setLayoutData(gdi); | ||
135 | txtInit.addModifyListener(validationListener); | ||
136 | |||
137 | Button btnLoadInit = new Button(initComposite, SWT.PUSH); | ||
138 | btnLoadInit.setLayoutData(gdVU); | ||
139 | btnLoadInit.setText("Choose..."); | ||
140 | btnLoadInit.addSelectionListener(new FileOpenSelectionAdapter()); | ||
141 | |||
142 | if (System.getenv("OEROOT") != null) { | ||
143 | txtProjectLocation.setText(System.getenv("OEROOT")); | ||
144 | } | ||
145 | |||
146 | setControl(top); | ||
147 | } | ||
148 | |||
149 | private void handleBrowse() { | ||
150 | DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.None); | ||
151 | String dir = dialog.open(); | ||
152 | if (dir != null) { | ||
153 | txtProjectLocation.setText(dir); | ||
154 | } | ||
155 | } | ||
156 | |||
157 | private String getFileSegment(String initScriptPath) { | ||
158 | //return the first segment of " " seperated array, or full string if no " " exists | ||
159 | return initScriptPath.split(" ")[0]; | ||
160 | } | ||
161 | |||
162 | private boolean isValidProjectName(String projectName) { | ||
163 | if (projectName.indexOf('$') > -1) { | ||
164 | return false; | ||
165 | } | ||
166 | |||
167 | return true; | ||
168 | } | ||
169 | |||
170 | |||
171 | @Override | ||
172 | public void pageCleanup() { | ||
173 | // TODO Auto-generated method stub | ||
174 | |||
175 | } | ||
176 | |||
177 | @Override | ||
178 | public void pageDisplay() { | ||
179 | // TODO Auto-generated method stub | ||
180 | |||
181 | } | ||
182 | |||
183 | @Override | ||
184 | protected void updateModel() { | ||
185 | model.put(ImportYoctoProjectWizard.KEY_NAME, txtProjectName.getText()); | ||
186 | model.put(ImportYoctoProjectWizard.KEY_LOCATION, txtProjectLocation.getText()); | ||
187 | model.put(ImportYoctoProjectWizard.KEY_INITPATH, txtInit.getText()); | ||
188 | } | ||
189 | |||
190 | |||
191 | @Override | ||
192 | protected boolean validatePage() { | ||
193 | IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); | ||
194 | |||
195 | IStatus validate = ResourcesPlugin.getWorkspace().validateName(txtProjectName.getText(), IResource.PROJECT); | ||
196 | |||
197 | if (!validate.isOK() || !isValidProjectName(txtProjectName.getText())) { | ||
198 | setErrorMessage("Invalid project name: " + txtProjectName.getText()); | ||
199 | return false; | ||
200 | } | ||
201 | |||
202 | IProject proj = wsroot.getProject(txtProjectName.getText()); | ||
203 | if (proj.exists()) { | ||
204 | setErrorMessage("A project with the name " + txtProjectName.getText() | ||
205 | + " already exists"); | ||
206 | return false; | ||
207 | } | ||
208 | |||
209 | if (txtProjectLocation.getText().trim().length() == 0) { | ||
210 | setErrorMessage("Set directory that contains Poky tree"); | ||
211 | return false; | ||
212 | } | ||
213 | |||
214 | File f = new File(txtProjectLocation.getText()); | ||
215 | if (!f.exists() || !f.isDirectory()) { | ||
216 | setErrorMessage("Invalid Directory"); | ||
217 | return false; | ||
218 | } | ||
219 | |||
220 | if (txtInit.getText().length() == 0) { | ||
221 | setErrorMessage("Set configuration file before BitBake is launched."); | ||
222 | return false; | ||
223 | } | ||
224 | |||
225 | File f2 = new File(getFileSegment(txtInit.getText())); | ||
226 | if (!f2.exists() || f2.isDirectory()) { | ||
227 | setErrorMessage("The configuration file is invalid."); | ||
228 | return false; | ||
229 | } | ||
230 | |||
231 | setErrorMessage(null); | ||
232 | setMessage("All the entries are valid, press \"Finish\" to create the new yocto bitbake project,"+ | ||
233 | "this will take a while. Please don't interrupt till there's output in the Yocto Console window..."); | ||
234 | return true; | ||
235 | } | ||
236 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java new file mode 100644 index 0000000..75f1763 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/importProject/ImportYoctoProjectWizard.java | |||
@@ -0,0 +1,166 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2013 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | * Ioana Grigoropol (Intel) - adapt class for remote support | ||
11 | *******************************************************************************/ | ||
12 | package org.yocto.bc.ui.wizards.importProject; | ||
13 | |||
14 | import java.io.IOException; | ||
15 | import java.io.Writer; | ||
16 | import java.net.URI; | ||
17 | import java.util.Hashtable; | ||
18 | import java.util.Map; | ||
19 | |||
20 | import org.eclipse.core.runtime.IStatus; | ||
21 | import org.eclipse.core.runtime.Status; | ||
22 | import org.eclipse.jface.viewers.IStructuredSelection; | ||
23 | import org.eclipse.ui.IImportWizard; | ||
24 | import org.eclipse.ui.IWorkbench; | ||
25 | import org.eclipse.ui.IWorkbenchPage; | ||
26 | import org.eclipse.ui.IWorkbenchWindow; | ||
27 | import org.eclipse.ui.PlatformUI; | ||
28 | import org.eclipse.ui.console.ConsolePlugin; | ||
29 | import org.eclipse.ui.console.IConsole; | ||
30 | import org.eclipse.ui.console.IConsoleConstants; | ||
31 | import org.eclipse.ui.console.IConsoleManager; | ||
32 | import org.eclipse.ui.console.IConsoleView; | ||
33 | import org.eclipse.ui.console.MessageConsole; | ||
34 | import org.yocto.bc.ui.Activator; | ||
35 | import org.yocto.bc.ui.model.ProjectInfo; | ||
36 | import org.yocto.bc.ui.wizards.FiniteStateWizard; | ||
37 | import org.yocto.bc.ui.wizards.newproject.BBConfigurationInitializeOperation; | ||
38 | import org.yocto.bc.ui.wizards.newproject.CreateBBCProjectOperation; | ||
39 | |||
40 | public class ImportYoctoProjectWizard extends FiniteStateWizard implements IImportWizard { | ||
41 | protected final static String KEY_OEROOT = "OEROOT"; | ||
42 | public static final String KEY_NAME = "NAME"; | ||
43 | public static final String KEY_LOCATION = "LOCATION"; | ||
44 | public static final String KEY_INITPATH = "INITPATH"; | ||
45 | protected static final String KEY_PINFO = "PINFO"; | ||
46 | |||
47 | private Map projectModel; | ||
48 | private IWorkbench workbench; | ||
49 | private IStructuredSelection selection; | ||
50 | |||
51 | private MessageConsole myConsole; | ||
52 | |||
53 | public ImportYoctoProjectWizard() { | ||
54 | projectModel = new Hashtable(); | ||
55 | } | ||
56 | |||
57 | public Map getModel() { | ||
58 | return projectModel; | ||
59 | } | ||
60 | |||
61 | @Override | ||
62 | public void addPages() { | ||
63 | addPage(new BBCProjectPage(projectModel)); | ||
64 | //addPage(new ConsolePage(projectModel)); | ||
65 | } | ||
66 | |||
67 | |||
68 | public boolean performFinish() { | ||
69 | ProjectInfo pinfo = new ProjectInfo(); | ||
70 | pinfo.setInitScriptPath((String) projectModel.get(ImportYoctoProjectWizard.KEY_INITPATH)); | ||
71 | pinfo.setLocationURI((URI) projectModel.get(ImportYoctoProjectWizard.KEY_LOCATION)); | ||
72 | pinfo.setName((String) projectModel.get(ImportYoctoProjectWizard.KEY_NAME)); | ||
73 | |||
74 | try { | ||
75 | ConsoleWriter cw = new ConsoleWriter(); | ||
76 | this.getContainer().run(false, false, new BBConfigurationInitializeOperation(pinfo, cw)); | ||
77 | myConsole.newMessageStream().println(cw.getContents()); | ||
78 | } catch (Exception e) { | ||
79 | Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e)); | ||
80 | this.getContainer().getCurrentPage().setDescription("Failed to create project: " + e.getMessage()); | ||
81 | //valid = false; | ||
82 | //setPageComplete(valid); | ||
83 | return false; | ||
84 | } | ||
85 | |||
86 | //valid = true; | ||
87 | projectModel.put(ImportYoctoProjectWizard.KEY_PINFO, pinfo); | ||
88 | //setPageComplete(valid); | ||
89 | //ProjectInfo pinfo = (ProjectInfo) projectModel.get(KEY_PINFO); | ||
90 | Activator.putProjInfo(pinfo.getOEFSURI(), pinfo); | ||
91 | try { | ||
92 | getContainer().run(false, false, new CreateBBCProjectOperation(pinfo)); | ||
93 | } catch (Exception e) { | ||
94 | Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e)); | ||
95 | this.getContainer().getCurrentPage().setDescription("Failed to create project: " + e.getMessage()); | ||
96 | return false; | ||
97 | } | ||
98 | |||
99 | return true; | ||
100 | } | ||
101 | |||
102 | public void init(IWorkbench workbench, IStructuredSelection selection) { | ||
103 | this.workbench = workbench; | ||
104 | this.selection = selection; | ||
105 | this.setNeedsProgressMonitor(true); | ||
106 | setWindowTitle("BitBake Commander Project"); | ||
107 | |||
108 | myConsole = findConsole("Yocto Console"); | ||
109 | IWorkbench wb = PlatformUI.getWorkbench(); | ||
110 | IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); | ||
111 | IWorkbenchPage page = win.getActivePage(); | ||
112 | String id = IConsoleConstants.ID_CONSOLE_VIEW; | ||
113 | try { | ||
114 | IConsoleView view = (IConsoleView) page.showView(id); | ||
115 | view.display(myConsole); | ||
116 | } catch (Exception e) { | ||
117 | e.printStackTrace(); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | private MessageConsole findConsole(String name) { | ||
122 | ConsolePlugin plugin = ConsolePlugin.getDefault(); | ||
123 | IConsoleManager conMan = plugin.getConsoleManager(); | ||
124 | IConsole[] existing = conMan.getConsoles(); | ||
125 | for (int i = 0; i < existing.length; i++) | ||
126 | if (name.equals(existing[i].getName())) | ||
127 | return (MessageConsole) existing[i]; | ||
128 | // no console found, so create a new one | ||
129 | MessageConsole myConsole = new MessageConsole(name, null); | ||
130 | conMan.addConsoles(new IConsole[] { myConsole }); | ||
131 | return myConsole; | ||
132 | } | ||
133 | |||
134 | private class ConsoleWriter extends Writer { | ||
135 | |||
136 | private StringBuffer sb; | ||
137 | |||
138 | public ConsoleWriter() { | ||
139 | sb = new StringBuffer(); | ||
140 | } | ||
141 | @Override | ||
142 | public void close() throws IOException { | ||
143 | } | ||
144 | |||
145 | public String getContents() { | ||
146 | return sb.toString(); | ||
147 | } | ||
148 | |||
149 | @Override | ||
150 | public void flush() throws IOException { | ||
151 | } | ||
152 | |||
153 | @Override | ||
154 | public void write(char[] cbuf, int off, int len) throws IOException { | ||
155 | //txtConsole.getText().concat(new String(cbuf)); | ||
156 | sb.append(cbuf); | ||
157 | } | ||
158 | |||
159 | @Override | ||
160 | public void write(String str) throws IOException { | ||
161 | sb.append(str); | ||
162 | } | ||
163 | |||
164 | } | ||
165 | |||
166 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java new file mode 100644 index 0000000..6d7c440 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/BBCRemoteProjectContentsLocationArea.java | |||
@@ -0,0 +1,371 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2013 Intel Corporation and others. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - Initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.wizards.install; | ||
12 | |||
13 | import java.net.URI; | ||
14 | |||
15 | import org.eclipse.core.filesystem.URIUtil; | ||
16 | import org.eclipse.core.resources.IProject; | ||
17 | import org.eclipse.core.runtime.Path; | ||
18 | import org.eclipse.core.runtime.Platform; | ||
19 | import org.eclipse.jface.operation.IRunnableContext; | ||
20 | import org.eclipse.ptp.rdt.ui.wizards.RemoteProjectContentsLocationArea; | ||
21 | import org.eclipse.ptp.remote.core.IRemoteFileManager; | ||
22 | import org.eclipse.swt.SWT; | ||
23 | import org.eclipse.swt.events.ModifyEvent; | ||
24 | import org.eclipse.swt.events.ModifyListener; | ||
25 | import org.eclipse.swt.events.SelectionAdapter; | ||
26 | import org.eclipse.swt.events.SelectionEvent; | ||
27 | import org.eclipse.swt.layout.GridData; | ||
28 | import org.eclipse.swt.layout.GridLayout; | ||
29 | import org.eclipse.swt.widgets.Button; | ||
30 | import org.eclipse.swt.widgets.Composite; | ||
31 | import org.eclipse.swt.widgets.Control; | ||
32 | import org.eclipse.swt.widgets.Group; | ||
33 | import org.eclipse.swt.widgets.Label; | ||
34 | import org.eclipse.swt.widgets.Text; | ||
35 | import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; | ||
36 | import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils; | ||
37 | |||
38 | import java.net.URI; | ||
39 | |||
40 | import org.eclipse.core.filesystem.URIUtil; | ||
41 | import org.eclipse.core.resources.IProject; | ||
42 | import org.eclipse.core.runtime.Path; | ||
43 | import org.eclipse.core.runtime.Platform; | ||
44 | import org.eclipse.jface.operation.IRunnableContext; | ||
45 | import org.eclipse.ptp.rdt.ui.messages.Messages; | ||
46 | //import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteBuildServiceProvider; | ||
47 | //import org.eclipse.ptp.rdt.core.serviceproviders. | ||
48 | import org.eclipse.ptp.remote.core.IRemoteConnection; | ||
49 | import org.eclipse.ptp.remote.core.IRemoteFileManager; | ||
50 | import org.eclipse.ptp.remote.core.IRemoteServices; | ||
51 | import org.eclipse.ptp.remote.ui.IRemoteUIConnectionManager; | ||
52 | import org.eclipse.ptp.remote.ui.IRemoteUIConstants; | ||
53 | import org.eclipse.ptp.remote.ui.IRemoteUIFileManager; | ||
54 | import org.eclipse.ptp.remote.ui.IRemoteUIServices; | ||
55 | import org.eclipse.ptp.remote.ui.RemoteUIServices; | ||
56 | import org.eclipse.ptp.remote.ui.widgets.RemoteConnectionWidget; | ||
57 | import org.eclipse.swt.SWT; | ||
58 | import org.eclipse.swt.events.ModifyEvent; | ||
59 | import org.eclipse.swt.events.ModifyListener; | ||
60 | import org.eclipse.swt.events.SelectionAdapter; | ||
61 | import org.eclipse.swt.events.SelectionEvent; | ||
62 | import org.eclipse.swt.layout.GridData; | ||
63 | import org.eclipse.swt.layout.GridLayout; | ||
64 | import org.eclipse.swt.widgets.Button; | ||
65 | import org.eclipse.swt.widgets.Composite; | ||
66 | import org.eclipse.swt.widgets.Control; | ||
67 | import org.eclipse.swt.widgets.Group; | ||
68 | import org.eclipse.swt.widgets.Label; | ||
69 | import org.eclipse.swt.widgets.Text; | ||
70 | import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; | ||
71 | import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils; | ||
72 | |||
73 | |||
74 | public class BBCRemoteProjectContentsLocationArea { | ||
75 | |||
76 | /** | ||
77 | * IErrorMessageReporter is an interface for type that allow message | ||
78 | * reporting. | ||
79 | * | ||
80 | */ | ||
81 | public interface IErrorMessageReporter { | ||
82 | /** | ||
83 | * Report the error message | ||
84 | * | ||
85 | * @param errorMessage | ||
86 | * String or <code>null</code>. If the errorMessage is null | ||
87 | * then clear any error state. | ||
88 | * @param infoOnly | ||
89 | * the message is an informational message, but the dialog | ||
90 | * cannot continue | ||
91 | * | ||
92 | */ | ||
93 | public void reportError(String errorMessage, boolean infoOnly); | ||
94 | } | ||
95 | |||
96 | private static final String FILE_SCHEME = "file"; //$NON-NLS-1$ | ||
97 | |||
98 | private IProject fExistingProject; | ||
99 | |||
100 | private final IErrorMessageReporter fErrorReporter; | ||
101 | |||
102 | private final IRunnableContext fContext; | ||
103 | |||
104 | //private RemoteBuildServiceProvider fProvider; | ||
105 | |||
106 | private IRemoteConnection fSelectedConnection; | ||
107 | |||
108 | private String fProjectName = IDEResourceInfoUtils.EMPTY_STRING; | ||
109 | |||
110 | private Button fBrowseButton; | ||
111 | |||
112 | private Text fLocationText; | ||
113 | |||
114 | private RemoteConnectionWidget fRemoteConnectionWidget; | ||
115 | |||
116 | // public RemoteProjectContentsLocationArea(IServiceProvider provider, | ||
117 | // Composite composite) { | ||
118 | // if(provider instanceof RemoteBuildServiceProvider) | ||
119 | // fProvider = (RemoteBuildServiceProvider) provider; | ||
120 | // else | ||
121 | // throw new IllegalArgumentException(); // should never happen | ||
122 | // createContents(composite); | ||
123 | // } | ||
124 | /** | ||
125 | * @since 3.1 | ||
126 | */ | ||
127 | public BBCRemoteProjectContentsLocationArea(IErrorMessageReporter reporter, Composite composite, IRunnableContext context) { | ||
128 | fErrorReporter = reporter; | ||
129 | fContext = context; | ||
130 | createContents(composite); | ||
131 | } | ||
132 | |||
133 | /** | ||
134 | * Check if the entry in the widget location is valid. If it is valid return | ||
135 | * null. Otherwise return a string that indicates the problem. | ||
136 | * | ||
137 | * @return String | ||
138 | */ | ||
139 | public String checkValidLocation() { | ||
140 | |||
141 | String locationFieldContents = fLocationText.getText(); | ||
142 | if (locationFieldContents.length() == 0) { | ||
143 | return IDEWorkbenchMessages.WizardNewProjectCreationPage_projectLocationEmpty; | ||
144 | } | ||
145 | |||
146 | URI newPath = getProjectLocationURI(); | ||
147 | if (newPath == null) { | ||
148 | return IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationError; | ||
149 | } | ||
150 | |||
151 | if (fExistingProject != null) { | ||
152 | URI projectPath = fExistingProject.getLocationURI(); | ||
153 | if (projectPath != null && URIUtil.equals(projectPath, newPath)) { | ||
154 | return IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationIsSelf; | ||
155 | } | ||
156 | } | ||
157 | |||
158 | return null; | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * Return the browse button. Usually referenced in order to set the layout | ||
163 | * data for a dialog. | ||
164 | * | ||
165 | * @return Button | ||
166 | */ | ||
167 | public Button[] getButtons() { | ||
168 | return new Button[] { fBrowseButton, fRemoteConnectionWidget.getButton() }; | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * Returns the name of the selected connection. | ||
173 | */ | ||
174 | public IRemoteConnection getConnection() { | ||
175 | return fSelectedConnection; | ||
176 | } | ||
177 | |||
178 | /** | ||
179 | * Return the location for the project. | ||
180 | * | ||
181 | * @return String | ||
182 | */ | ||
183 | public String getProjectLocation() { | ||
184 | return fLocationText.getText(); | ||
185 | } | ||
186 | |||
187 | /** | ||
188 | * Get the URI for the location field if possible. | ||
189 | * | ||
190 | * @return URI or <code>null</code> if it is not valid. | ||
191 | */ | ||
192 | public URI getProjectLocationURI() { | ||
193 | if (fSelectedConnection == null) | ||
194 | return null; | ||
195 | return fSelectedConnection.getRemoteServices().getFileManager(fSelectedConnection).toURI(fLocationText.getText()); | ||
196 | } | ||
197 | |||
198 | public IRemoteConnection getRemoteConnection() { | ||
199 | return fSelectedConnection; | ||
200 | } | ||
201 | |||
202 | public IRemoteServices getRemoteServices() { | ||
203 | if (fSelectedConnection != null) | ||
204 | return fSelectedConnection.getRemoteServices(); | ||
205 | return null; | ||
206 | } | ||
207 | |||
208 | /** | ||
209 | * Return whether or not we are currently showing the default location for | ||
210 | * the project. | ||
211 | * | ||
212 | * @return boolean | ||
213 | */ | ||
214 | public boolean isDefault() { | ||
215 | // return useDefaultsButton.getSelection(); | ||
216 | return false; | ||
217 | } | ||
218 | |||
219 | /** | ||
220 | * Set the project to base the contents off of. | ||
221 | * | ||
222 | * @param existingProject | ||
223 | */ | ||
224 | public void setExistingProject(IProject existingProject) { | ||
225 | fProjectName = existingProject.getName(); | ||
226 | fExistingProject = existingProject; | ||
227 | } | ||
228 | |||
229 | /** | ||
230 | * Set the text to the default or clear it if not using the defaults. | ||
231 | * | ||
232 | * @param newName | ||
233 | * the name of the project to use. If <code>null</code> use the | ||
234 | * existing project name. | ||
235 | */ | ||
236 | public void updateProjectName(String newName) { | ||
237 | fProjectName = newName; | ||
238 | if (isDefault()) { | ||
239 | fLocationText.setText(getDefaultPathDisplayString()); | ||
240 | } | ||
241 | |||
242 | } | ||
243 | |||
244 | /** | ||
245 | * Attempt to open a connection. | ||
246 | */ | ||
247 | private void checkConnection() { | ||
248 | IRemoteUIConnectionManager mgr = getUIConnectionManager(); | ||
249 | if (mgr != null) { | ||
250 | mgr.openConnectionWithProgress(fRemoteConnectionWidget.getShell(), fContext, fSelectedConnection); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * Return the path we are going to display. If it is a file URI then remove | ||
256 | * the file prefix. | ||
257 | * | ||
258 | * Only do this if the connection is open. Otherwise we will attempt to | ||
259 | * connect to the first machine in the list, which is annoying. | ||
260 | * | ||
261 | * @return String | ||
262 | */ | ||
263 | private String getDefaultPathDisplayString() { | ||
264 | if (getRemoteConnection() != null && getRemoteConnection().isOpen()) { | ||
265 | IRemoteFileManager fileMgr = fSelectedConnection.getRemoteServices().getFileManager(getRemoteConnection()); | ||
266 | URI defaultURI = fileMgr.toURI(getRemoteConnection().getWorkingDirectory()); | ||
267 | |||
268 | // Handle files specially. Assume a file if there is no project to | ||
269 | // query | ||
270 | if (defaultURI != null && defaultURI.getScheme().equals(FILE_SCHEME)) { | ||
271 | return Platform.getLocation().append(fProjectName).toOSString(); | ||
272 | } | ||
273 | if (defaultURI == null) { | ||
274 | return ""; //$NON-NLS-1$ | ||
275 | } | ||
276 | return new Path(defaultURI.getPath()).append(fProjectName).toOSString(); | ||
277 | } | ||
278 | return ""; //$NON-NLS-1$ | ||
279 | } | ||
280 | |||
281 | /** | ||
282 | * @return | ||
283 | */ | ||
284 | private IRemoteUIConnectionManager getUIConnectionManager() { | ||
285 | IRemoteUIConnectionManager connectionManager = RemoteUIServices.getRemoteUIServices(fSelectedConnection.getRemoteServices()) | ||
286 | .getUIConnectionManager(); | ||
287 | return connectionManager; | ||
288 | } | ||
289 | |||
290 | private void handleConnectionSelected() { | ||
291 | fSelectedConnection = fRemoteConnectionWidget.getConnection(); | ||
292 | fLocationText.setText(getDefaultPathDisplayString()); | ||
293 | } | ||
294 | |||
295 | protected Control createContents(Composite parent) { | ||
296 | Group container = new Group(parent, SWT.SHADOW_ETCHED_IN); | ||
297 | |||
298 | GridLayout layout = new GridLayout(); | ||
299 | layout.numColumns = 3; | ||
300 | container.setLayout(layout); | ||
301 | GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); | ||
302 | container.setLayoutData(gd); | ||
303 | |||
304 | fRemoteConnectionWidget = new RemoteConnectionWidget(container, SWT.NONE, null, RemoteConnectionWidget.FLAG_FORCE_PROVIDER_SELECTION, null); | ||
305 | gd = new GridData(); | ||
306 | gd.horizontalSpan = 3; | ||
307 | fRemoteConnectionWidget.setLayoutData(gd); | ||
308 | fRemoteConnectionWidget.addSelectionListener(new SelectionAdapter() { | ||
309 | @Override | ||
310 | public void widgetSelected(SelectionEvent e) { | ||
311 | handleConnectionSelected(); | ||
312 | } | ||
313 | }); | ||
314 | |||
315 | Label locationLabel = new Label(container, SWT.LEFT); | ||
316 | locationLabel.setText(Messages.getString("RemoteProjectContentsLocationArea.3")); //$NON-NLS-1$ | ||
317 | |||
318 | fLocationText = new Text(container, SWT.SINGLE | SWT.BORDER); | ||
319 | gd = new GridData(GridData.FILL_HORIZONTAL); | ||
320 | gd.horizontalSpan = 1; | ||
321 | gd.grabExcessHorizontalSpace = true; | ||
322 | gd.widthHint = 250; | ||
323 | fLocationText.setLayoutData(gd); | ||
324 | fLocationText.addModifyListener(new ModifyListener() { | ||
325 | public void modifyText(ModifyEvent e) { | ||
326 | fErrorReporter.reportError(checkValidLocation(), false); | ||
327 | } | ||
328 | }); | ||
329 | |||
330 | // new connection button | ||
331 | fBrowseButton = new Button(container, SWT.PUSH); | ||
332 | fBrowseButton.setText(Messages.getString("RemoteProjectContentsLocationArea.4")); //$NON-NLS-1$ | ||
333 | fBrowseButton.addSelectionListener(new SelectionAdapter() { | ||
334 | @Override | ||
335 | public void widgetSelected(SelectionEvent e) { | ||
336 | if (fSelectedConnection != null) { | ||
337 | checkConnection(); | ||
338 | if (fSelectedConnection.isOpen()) { | ||
339 | IRemoteUIServices remoteUIServices = RemoteUIServices.getRemoteUIServices(fSelectedConnection.getRemoteServices()); | ||
340 | if (remoteUIServices != null) { | ||
341 | IRemoteUIFileManager fileMgr = remoteUIServices.getUIFileManager(); | ||
342 | if (fileMgr != null) { | ||
343 | fileMgr.setConnection(fSelectedConnection); | ||
344 | String correctPath = fLocationText.getText(); | ||
345 | String selectedPath = fileMgr.browseDirectory( | ||
346 | fLocationText.getShell(), | ||
347 | Messages.getString("RemoteProjectContentsLocationArea.5", fSelectedConnection.getName()), correctPath, IRemoteUIConstants.NONE); //$NON-NLS-1$ | ||
348 | if (selectedPath != null) { | ||
349 | fLocationText.setText(selectedPath); | ||
350 | } | ||
351 | } | ||
352 | } | ||
353 | } | ||
354 | } | ||
355 | } | ||
356 | }); | ||
357 | |||
358 | return container; | ||
359 | } | ||
360 | |||
361 | /* | ||
362 | * (non-Javadoc) | ||
363 | * | ||
364 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | ||
365 | */ | ||
366 | protected void okPressed() { | ||
367 | // set the connection | ||
368 | //fProvider.setRemoteToolsConnection(fSelectedConnection); | ||
369 | |||
370 | } | ||
371 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java new file mode 100644 index 0000000..f64401c --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java | |||
@@ -0,0 +1,213 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2013 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | * Ioana Grigoropol (Intel) - adapt class for remote support | ||
11 | *******************************************************************************/ | ||
12 | package org.yocto.bc.ui.wizards.install; | ||
13 | |||
14 | import java.io.BufferedReader; | ||
15 | import java.io.File; | ||
16 | import java.io.IOException; | ||
17 | import java.io.InputStreamReader; | ||
18 | import java.io.Writer; | ||
19 | import java.lang.reflect.InvocationTargetException; | ||
20 | import java.net.URI; | ||
21 | import java.util.Hashtable; | ||
22 | import java.util.Map; | ||
23 | import java.util.regex.Matcher; | ||
24 | import java.util.regex.Pattern; | ||
25 | |||
26 | import org.eclipse.core.runtime.IProgressMonitor; | ||
27 | import org.eclipse.core.runtime.IStatus; | ||
28 | import org.eclipse.core.runtime.Status; | ||
29 | import org.eclipse.jface.operation.IRunnableWithProgress; | ||
30 | import org.eclipse.jface.viewers.IStructuredSelection; | ||
31 | import org.eclipse.jface.wizard.IWizardContainer; | ||
32 | import org.eclipse.jface.wizard.WizardPage; | ||
33 | import org.eclipse.ptp.remote.core.IRemoteConnection; | ||
34 | import org.eclipse.ptp.remote.core.IRemoteServices; | ||
35 | import org.eclipse.rse.core.model.IHost; | ||
36 | import org.eclipse.ui.IWorkbench; | ||
37 | import org.eclipse.ui.IWorkbenchPage; | ||
38 | import org.eclipse.ui.IWorkbenchWindow; | ||
39 | import org.eclipse.ui.IWorkbenchWizard; | ||
40 | import org.eclipse.ui.PlatformUI; | ||
41 | import org.eclipse.ui.console.ConsolePlugin; | ||
42 | import org.eclipse.ui.console.IConsole; | ||
43 | import org.eclipse.ui.console.IConsoleConstants; | ||
44 | import org.eclipse.ui.console.IConsoleManager; | ||
45 | import org.eclipse.ui.console.IConsoleView; | ||
46 | import org.eclipse.ui.console.MessageConsole; | ||
47 | import org.eclipse.ui.console.MessageConsoleStream; | ||
48 | import org.yocto.bc.remote.utils.YoctoRunnableWithProgress; | ||
49 | import org.yocto.bc.ui.Activator; | ||
50 | import org.yocto.bc.ui.model.ProjectInfo; | ||
51 | import org.yocto.bc.ui.wizards.FiniteStateWizard; | ||
52 | import org.yocto.bc.ui.wizards.newproject.BBConfigurationInitializeOperation; | ||
53 | import org.yocto.bc.ui.wizards.newproject.CreateBBCProjectOperation; | ||
54 | import org.yocto.remote.utils.CommandResponseHandler; | ||
55 | import org.yocto.remote.utils.ICommandResponseHandler; | ||
56 | import org.yocto.remote.utils.RemoteHelper; | ||
57 | import org.yocto.remote.utils.YoctoCommand; | ||
58 | import org.yocto.bc.remote.utils.ConsoleWriter; | ||
59 | |||
60 | /** | ||
61 | * A wizard for installing a fresh copy of an OE system. | ||
62 | * | ||
63 | * @author kgilmer | ||
64 | * | ||
65 | * A Wizard for creating a fresh Yocto bitbake project and new poky build tree from git | ||
66 | * | ||
67 | * @modified jzhang | ||
68 | * | ||
69 | */ | ||
70 | public class InstallWizard extends FiniteStateWizard implements | ||
71 | IWorkbenchWizard { | ||
72 | |||
73 | static final String KEY_PINFO = "KEY_PINFO"; | ||
74 | protected static final String OPTION_MAP = "OPTION_MAP"; | ||
75 | protected static final String INSTALL_SCRIPT = "INSTALL_SCRIPT"; | ||
76 | protected static final String INSTALL_DIRECTORY = "Install Directory"; | ||
77 | protected static final String INIT_SCRIPT = "Init Script"; | ||
78 | |||
79 | protected static final String SELECTED_CONNECTION = "SEL_CONNECTION"; | ||
80 | protected static final String SELECTED_REMOTE_SERVICE = "SEL_REMOTE_SERVICE"; | ||
81 | |||
82 | protected static final String PROJECT_NAME = "Project Name"; | ||
83 | protected static final String DEFAULT_INIT_SCRIPT = "oe-init-build-env"; | ||
84 | protected static final String DEFAULT_INSTALL_DIR = "~/yocto"; | ||
85 | |||
86 | protected static final String GIT_CLONE = "Git Clone"; | ||
87 | public static final String VALIDATION_FILE = DEFAULT_INIT_SCRIPT; | ||
88 | |||
89 | private Map model; | ||
90 | private MessageConsole myConsole; | ||
91 | private OptionsPage optionsPage; | ||
92 | |||
93 | public InstallWizard() { | ||
94 | this.model = new Hashtable(); | ||
95 | model.put(INSTALL_DIRECTORY, DEFAULT_INSTALL_DIR); | ||
96 | model.put(INIT_SCRIPT, DEFAULT_INIT_SCRIPT); | ||
97 | |||
98 | setWindowTitle("Yocto Project BitBake Commander"); | ||
99 | setNeedsProgressMonitor(true); | ||
100 | } | ||
101 | |||
102 | |||
103 | |||
104 | public InstallWizard(IStructuredSelection selection) { | ||
105 | model = new Hashtable(); | ||
106 | } | ||
107 | |||
108 | /* | ||
109 | * @Override public IWizardPage getNextPage(IWizardPage page) { if (page | ||
110 | * instanceof WelcomePage) { if (model.containsKey(WelcomePage.ACTION_USE)) | ||
111 | * { return bbcProjectPage; } } else if (page instanceof ProgressPage) { | ||
112 | * return bitbakePage; } | ||
113 | * | ||
114 | * if (super.getNextPage(page) != null) { System.out.println("next page: " + | ||
115 | * super.getNextPage(page).getClass().getName()); } else { | ||
116 | * System.out.println("end page"); } | ||
117 | * | ||
118 | * return super.getNextPage(page); } | ||
119 | * | ||
120 | * @Override public boolean canFinish() { System.out.println("can finish: " | ||
121 | * + super.canFinish()); return super.canFinish(); } | ||
122 | */ | ||
123 | @Override | ||
124 | public void addPages() { | ||
125 | optionsPage = new OptionsPage(model); | ||
126 | addPage(optionsPage); | ||
127 | } | ||
128 | |||
129 | @Override | ||
130 | public Map getModel() { | ||
131 | return model; | ||
132 | } | ||
133 | |||
134 | @Override | ||
135 | public boolean performFinish() { | ||
136 | WizardPage page = (WizardPage) getPage("Options"); | ||
137 | page.setPageComplete(true); | ||
138 | Map<String, Object> options = model; | ||
139 | |||
140 | try { | ||
141 | URI uri = new URI(""); | ||
142 | if (options.containsKey(INSTALL_DIRECTORY)) { | ||
143 | uri = (URI) options.get(INSTALL_DIRECTORY); | ||
144 | } | ||
145 | IRemoteConnection remoteConnection = ((IRemoteConnection)model.get(InstallWizard.SELECTED_CONNECTION)); | ||
146 | IRemoteServices remoteServices = ((IRemoteServices)model.get(InstallWizard.SELECTED_REMOTE_SERVICE)); | ||
147 | IHost connection = RemoteHelper.getRemoteConnectionByName(remoteConnection.getName()); | ||
148 | CommandResponseHandler cmdHandler = new CommandResponseHandler(RemoteHelper.getConsole(connection)); | ||
149 | IWizardContainer container = this.getContainer(); | ||
150 | if (((Boolean)options.get(GIT_CLONE)).booleanValue()) { | ||
151 | String cmd = "git clone --progress git://git.yoctoproject.org/poky.git " + uri.getPath(); | ||
152 | String taskName = "Checking out Yocto git repository"; | ||
153 | |||
154 | YoctoRunnableWithProgress adapter = new YoctoRunnableWithProgress(new YoctoCommand(cmd, "", "")); | ||
155 | |||
156 | adapter.setRemoteConnection(remoteConnection); | ||
157 | adapter.setRemoteServices(remoteServices); | ||
158 | adapter.setTaskName(taskName); | ||
159 | try { | ||
160 | container.run(true, true, adapter); | ||
161 | } catch (InvocationTargetException e) { | ||
162 | e.printStackTrace(); | ||
163 | } catch (InterruptedException e) { | ||
164 | e.printStackTrace(); | ||
165 | } | ||
166 | } | ||
167 | if (!cmdHandler.hasError()) { | ||
168 | String initPath = ""; | ||
169 | if (uri.getPath() != null) { | ||
170 | initPath = uri.getPath() + "/" + (String) options.get(INIT_SCRIPT); | ||
171 | } else { | ||
172 | initPath = uri.getFragment() + "/" + (String) options.get(INIT_SCRIPT); | ||
173 | } | ||
174 | String prjName = (String) options.get(PROJECT_NAME); | ||
175 | ProjectInfo pinfo = new ProjectInfo(); | ||
176 | pinfo.setInitScriptPath(initPath); | ||
177 | pinfo.setLocationURI(uri); | ||
178 | pinfo.setName(prjName); | ||
179 | pinfo.setConnection(connection); | ||
180 | pinfo.setRemoteServices(remoteServices); | ||
181 | |||
182 | final ConsoleWriter cw = new ConsoleWriter(); | ||
183 | BBConfigurationInitializeOperation configInitOp = new BBConfigurationInitializeOperation(pinfo, null); | ||
184 | container.run(false, false, configInitOp); | ||
185 | myConsole = RemoteHelper.getConsole(connection); | ||
186 | myConsole.newMessageStream().println(cw.getContents()); | ||
187 | |||
188 | if (configInitOp.hasErrorOccured()) { | ||
189 | optionsPage.setErrorMessage(configInitOp.getErrorMessage()); | ||
190 | return false; | ||
191 | } | ||
192 | |||
193 | model.put(InstallWizard.KEY_PINFO, pinfo); | ||
194 | Activator.putProjInfo(pinfo.getOEFSURI(), pinfo); | ||
195 | |||
196 | container.run(false, false, new CreateBBCProjectOperation(pinfo)); | ||
197 | RemoteHelper.storeURIInMetaArea(pinfo.getProjectName(), uri); | ||
198 | RemoteHelper.storeProjDescrInMetaArea(pinfo.getConnection(), pinfo.getProjectName(), pinfo.getOriginalURI().getPath()); | ||
199 | return true; | ||
200 | } | ||
201 | } catch (Exception e) { | ||
202 | Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, | ||
203 | IStatus.ERROR, e.getMessage(), e)); | ||
204 | this.getContainer().getCurrentPage().setDescription( | ||
205 | "Failed to create project: " + e.getMessage()); | ||
206 | } | ||
207 | return false; | ||
208 | } | ||
209 | |||
210 | public void init(IWorkbench workbench, IStructuredSelection selection) { | ||
211 | } | ||
212 | |||
213 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java new file mode 100644 index 0000000..75d9f99 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/OptionsPage.java | |||
@@ -0,0 +1,327 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2013 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | * Ioana Grigoropol (Intel) - adapt class for remote support | ||
11 | *******************************************************************************/ | ||
12 | package org.yocto.bc.ui.wizards.install; | ||
13 | |||
14 | import java.io.IOException; | ||
15 | import java.io.File; | ||
16 | import java.net.URI; | ||
17 | import java.net.URISyntaxException; | ||
18 | import java.util.ArrayList; | ||
19 | import java.util.Hashtable; | ||
20 | import java.util.Iterator; | ||
21 | import java.util.List; | ||
22 | import java.util.Map; | ||
23 | import java.util.regex.Matcher; | ||
24 | import java.util.regex.Pattern; | ||
25 | |||
26 | import org.eclipse.core.resources.IProject; | ||
27 | import org.eclipse.core.resources.IProjectDescription; | ||
28 | import org.eclipse.core.resources.IResource; | ||
29 | import org.eclipse.core.resources.IWorkspaceRoot; | ||
30 | import org.eclipse.core.resources.ResourcesPlugin; | ||
31 | import org.eclipse.core.runtime.CoreException; | ||
32 | import org.eclipse.core.runtime.IStatus; | ||
33 | import org.eclipse.core.runtime.NullProgressMonitor; | ||
34 | import org.eclipse.ptp.rdt.ui.wizards.RemoteProjectContentsLocationArea; | ||
35 | import org.eclipse.ptp.rdt.ui.wizards.RemoteProjectContentsLocationArea.IErrorMessageReporter; | ||
36 | import org.eclipse.ptp.remote.core.IRemoteConnection; | ||
37 | import org.eclipse.ptp.internal.remote.rse.core.RSEConnection; | ||
38 | import org.eclipse.rse.core.model.IHost; | ||
39 | import org.eclipse.rse.services.files.IFileService; | ||
40 | import org.eclipse.rse.services.files.IHostFile; | ||
41 | import org.eclipse.swt.SWT; | ||
42 | import org.eclipse.swt.events.SelectionAdapter; | ||
43 | import org.eclipse.swt.events.SelectionEvent; | ||
44 | import org.eclipse.swt.layout.GridData; | ||
45 | import org.eclipse.swt.layout.GridLayout; | ||
46 | import org.eclipse.swt.widgets.Button; | ||
47 | import org.eclipse.swt.widgets.Composite; | ||
48 | import org.eclipse.swt.widgets.Control; | ||
49 | import org.eclipse.swt.widgets.DirectoryDialog; | ||
50 | import org.eclipse.swt.widgets.FileDialog; | ||
51 | import org.eclipse.swt.widgets.Label; | ||
52 | import org.eclipse.swt.widgets.Text; | ||
53 | import org.eclipse.ui.PlatformUI; | ||
54 | |||
55 | import org.yocto.bc.ui.wizards.FiniteStateWizard; | ||
56 | import org.yocto.bc.ui.wizards.FiniteStateWizardPage; | ||
57 | import org.yocto.bc.ui.wizards.FiniteStateWizardPage.ValidationListener; | ||
58 | import org.yocto.remote.utils.RemoteHelper; | ||
59 | |||
60 | /** | ||
61 | * Select which flavor of OE is to be installed. | ||
62 | * | ||
63 | * @author kgilmer | ||
64 | * | ||
65 | * Setting up the parameters for creating the new Yocto Bitbake project | ||
66 | * | ||
67 | * @modified jzhang | ||
68 | */ | ||
69 | public class OptionsPage extends FiniteStateWizardPage { | ||
70 | |||
71 | public static final String URI_SEPARATOR = "/"; | ||
72 | public static final String LOCALHOST = "LOCALHOST"; | ||
73 | |||
74 | private Composite top; | ||
75 | |||
76 | private RemoteProjectContentsLocationArea locationArea; | ||
77 | |||
78 | private ValidationListener validationListener; | ||
79 | private Text txtProjectName; | ||
80 | private Button btnGit; | ||
81 | |||
82 | protected OptionsPage(Map model) { | ||
83 | super("Options", model); | ||
84 | //setTitle("Create new yocto bitbake project"); | ||
85 | setMessage("Enter these parameters to create new Yocto Project BitBake commander project"); | ||
86 | } | ||
87 | |||
88 | @Override | ||
89 | public void createControl(Composite parent) { | ||
90 | top = new Composite(parent, SWT.None); | ||
91 | top.setLayout(new GridLayout()); | ||
92 | top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | ||
93 | |||
94 | GridData gdFillH = new GridData(GridData.FILL_HORIZONTAL); | ||
95 | |||
96 | Composite projectNameComp = new Composite(top, SWT.NONE); | ||
97 | GridData gdProjName = new GridData(GridData.FILL_HORIZONTAL); | ||
98 | projectNameComp.setLayoutData(gdProjName); | ||
99 | projectNameComp.setLayout(new GridLayout(2, false)); | ||
100 | Label lblProjectName = new Label(projectNameComp, SWT.NONE); | ||
101 | lblProjectName.setText("Project N&ame:"); | ||
102 | |||
103 | txtProjectName = new Text(projectNameComp, SWT.BORDER); | ||
104 | txtProjectName.setLayoutData(gdFillH); | ||
105 | txtProjectName.setFocus(); | ||
106 | validationListener = new ValidationListener(); | ||
107 | |||
108 | txtProjectName.addModifyListener(validationListener); | ||
109 | |||
110 | IErrorMessageReporter errorReporter = new IErrorMessageReporter() { | ||
111 | |||
112 | @Override | ||
113 | public void reportError(String errorMessage, boolean infoOnly) { | ||
114 | setMessage(errorMessage); | ||
115 | if (validatePage()) { | ||
116 | updateModel(); | ||
117 | setPageComplete(true); | ||
118 | return; | ||
119 | } | ||
120 | |||
121 | setPageComplete(false); | ||
122 | } | ||
123 | }; | ||
124 | |||
125 | locationArea = new RemoteProjectContentsLocationArea(errorReporter, top, null); | ||
126 | |||
127 | btnGit = new Button(top, SWT.CHECK); | ||
128 | btnGit.setText("Clone from Yocto Project &Git Repository into new location"); | ||
129 | btnGit.setEnabled(true); | ||
130 | btnGit.setSelection(true); | ||
131 | btnGit.addSelectionListener(validationListener); | ||
132 | GridData gd = new GridData(GridData.VERTICAL_ALIGN_END | GridData.FILL_HORIZONTAL); | ||
133 | btnGit.setLayoutData(gd); | ||
134 | |||
135 | setControl(top); | ||
136 | } | ||
137 | |||
138 | @Override | ||
139 | public void pageCleanup() { | ||
140 | |||
141 | } | ||
142 | |||
143 | @Override | ||
144 | public void pageDisplay() { | ||
145 | } | ||
146 | |||
147 | @Override | ||
148 | |||
149 | protected void updateModel() { | ||
150 | try { | ||
151 | URI uri = getProjectLocationURI(); | ||
152 | if (uri != null) | ||
153 | model.put(InstallWizard.INSTALL_DIRECTORY, getProjectLocationURI()); | ||
154 | } catch (Exception e){ | ||
155 | e.printStackTrace(); | ||
156 | } | ||
157 | model.put(InstallWizard.PROJECT_NAME, txtProjectName.getText()); | ||
158 | model.put(InstallWizard.GIT_CLONE, new Boolean(btnGit.getSelection())); | ||
159 | model.put(InstallWizard.SELECTED_CONNECTION, locationArea.getRemoteConnection()); | ||
160 | model.put(InstallWizard.SELECTED_REMOTE_SERVICE, locationArea.getRemoteServices()); | ||
161 | } | ||
162 | |||
163 | public URI getProjectLocationURI() throws URISyntaxException { | ||
164 | URI uri = locationArea.getProjectLocationURI(); | ||
165 | |||
166 | if (uri != null) { | ||
167 | String location = locationArea.getProjectLocation(); | ||
168 | if (!uri.getPath().isEmpty()) { | ||
169 | String separator = uri.getPath().endsWith(URI_SEPARATOR) ? "" : URI_SEPARATOR; | ||
170 | |||
171 | return new URI( uri.getScheme(), | ||
172 | uri.getHost(), | ||
173 | uri.getPath() + separator + txtProjectName.getText(), | ||
174 | uri.getFragment()); | ||
175 | } else { | ||
176 | return null; | ||
177 | } | ||
178 | } else { | ||
179 | String location = locationArea.getProjectLocation(); | ||
180 | String separator = location.endsWith(URI_SEPARATOR) ? "" : URI_SEPARATOR; | ||
181 | |||
182 | IRemoteConnection conn = locationArea.getConnection(); | ||
183 | if (conn instanceof RSEConnection) { | ||
184 | RSEConnection rseConn = (RSEConnection)conn; | ||
185 | return new URI("rse", rseConn.getHost().getHostName(), location); | ||
186 | } else { | ||
187 | return new URI( "file", location + separator + txtProjectName.getText(),""); | ||
188 | } | ||
189 | } | ||
190 | } | ||
191 | |||
192 | private boolean isValidProjectName(String projectName) { | ||
193 | if (projectName.indexOf('$') > -1) { | ||
194 | return false; | ||
195 | } | ||
196 | |||
197 | return true; | ||
198 | } | ||
199 | |||
200 | private boolean validateProjectName() { | ||
201 | IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); | ||
202 | |||
203 | IStatus validate = ResourcesPlugin.getWorkspace().validateName(txtProjectName.getText(), IResource.PROJECT); | ||
204 | |||
205 | if (txtProjectName.getText().trim().isEmpty()) { | ||
206 | setErrorMessage("Project name cannot be empty!"); | ||
207 | return false; | ||
208 | } | ||
209 | |||
210 | if (!validate.isOK() || !isValidProjectName(txtProjectName.getText())) { | ||
211 | setErrorMessage("Invalid project name: " + txtProjectName.getText()); | ||
212 | return false; | ||
213 | } | ||
214 | |||
215 | IProject proj = wsroot.getProject(txtProjectName.getText()); | ||
216 | if (proj.exists()) { | ||
217 | setErrorMessage("A project with the name " + txtProjectName.getText() + " already exists"); | ||
218 | return false; | ||
219 | } | ||
220 | return true; | ||
221 | } | ||
222 | private String convertToRealPath(String path) { | ||
223 | String patternStr = File.separator + File.separator; | ||
224 | if (patternStr.equals(URI_SEPARATOR)) | ||
225 | return path; | ||
226 | String replaceStr = URI_SEPARATOR; | ||
227 | String convertedpath; | ||
228 | |||
229 | //Compile regular expression | ||
230 | Pattern pattern = Pattern.compile(patternStr); //pattern to look for | ||
231 | |||
232 | //replace all occurance of percentage character to file separator | ||
233 | Matcher matcher = pattern.matcher(path); | ||
234 | convertedpath = matcher.replaceAll(replaceStr); | ||
235 | |||
236 | return convertedpath; | ||
237 | } | ||
238 | |||
239 | public String getProjectName(){ | ||
240 | return txtProjectName.getText().trim(); | ||
241 | } | ||
242 | |||
243 | protected boolean validateProjectLocation() { | ||
244 | |||
245 | String projectLoc = locationArea.getProjectLocation().trim(); | ||
246 | |||
247 | IRemoteConnection remoteConnection = locationArea.getRemoteConnection(); | ||
248 | if (remoteConnection == null) | ||
249 | return false; | ||
250 | |||
251 | if (projectLoc.isEmpty()) | ||
252 | return true; | ||
253 | |||
254 | IHost connection = RemoteHelper.getRemoteConnectionByName(remoteConnection.getName()); | ||
255 | |||
256 | projectLoc = convertToRealPath(projectLoc); | ||
257 | String separator = projectLoc.endsWith(URI_SEPARATOR) ? "" : URI_SEPARATOR; | ||
258 | String projectPath = projectLoc + separator + getProjectName(); | ||
259 | IHostFile repoDest = RemoteHelper.getRemoteHostFile(connection, projectPath, new NullProgressMonitor()); | ||
260 | |||
261 | if(!btnGit.getSelection()) { | ||
262 | if (repoDest == null || !repoDest.exists()) { | ||
263 | setErrorMessage("Directory " + projectPath + " does not exist, please select git clone."); | ||
264 | return false; | ||
265 | } | ||
266 | |||
267 | IHostFile validationFile = RemoteHelper.getRemoteHostFile(connection, projectPath + URI_SEPARATOR + InstallWizard.VALIDATION_FILE, new NullProgressMonitor()); | ||
268 | if (validationFile == null || !validationFile.exists()) { | ||
269 | setErrorMessage("Directory " + projectPath + " seems invalid, please use other directory or project name."); | ||
270 | return false; | ||
271 | } | ||
272 | } else { //git clone | ||
273 | if (repoDest != null && repoDest.exists() && repoDest.isDirectory()) { | ||
274 | IHostFile[] hostFiles = RemoteHelper.getRemoteDirContent(connection, repoDest.getAbsolutePath(), "", IFileService.FILE_TYPE_FILES_AND_FOLDERS, new NullProgressMonitor()); | ||
275 | if (hostFiles.length != 0) { | ||
276 | setErrorMessage("Directory " + projectPath + " is not empty, please choose another location."); | ||
277 | return false; | ||
278 | } | ||
279 | IHostFile gitDescr = RemoteHelper.getRemoteHostFile(connection, projectPath + "/.git", new NullProgressMonitor()); | ||
280 | if (gitDescr != null && gitDescr.exists()) { | ||
281 | setErrorMessage("Directory " + projectPath + " contains a repository, please choose another location or skip cloning the repository."); | ||
282 | return false; | ||
283 | } | ||
284 | } | ||
285 | } | ||
286 | |||
287 | try { | ||
288 | String projName = txtProjectName.getText(); | ||
289 | if (!projName.trim().isEmpty() && validateProjectName()) { | ||
290 | IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); | ||
291 | IProject proj = wsroot.getProject(); | ||
292 | if (proj != null && proj.exists()) { | ||
293 | setErrorMessage("A project with the name " + projName + " already exists"); | ||
294 | return false; | ||
295 | } | ||
296 | URI location = new URI("file:" + URI_SEPARATOR + URI_SEPARATOR + convertToRealPath(projectLoc) + URI_SEPARATOR + txtProjectName.getText()); | ||
297 | |||
298 | IStatus status = ResourcesPlugin.getWorkspace().validateProjectLocationURI(proj, location); | ||
299 | if (!status.isOK()) { | ||
300 | setErrorMessage(status.getMessage()); | ||
301 | return false; | ||
302 | } | ||
303 | } | ||
304 | } catch (Exception e) { | ||
305 | e.printStackTrace(); | ||
306 | setErrorMessage("Run into error while trying to validate entries!"); | ||
307 | return false; | ||
308 | } | ||
309 | |||
310 | setErrorMessage(null); | ||
311 | return true; | ||
312 | } | ||
313 | @Override | ||
314 | protected boolean validatePage() { | ||
315 | if (!validateProjectName()) | ||
316 | return false; | ||
317 | |||
318 | if (!validateProjectLocation()) | ||
319 | return false; | ||
320 | |||
321 | setErrorMessage(null); | ||
322 | setMessage("All the entries are valid, press \"Finish\" to start the process, "+ | ||
323 | "this will take a while. Please don't interrupt till there's output in the Yocto Console window..."); | ||
324 | return true; | ||
325 | } | ||
326 | |||
327 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java new file mode 100644 index 0000000..c44b7b5 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/BBConfigurationInitializeOperation.java | |||
@@ -0,0 +1,69 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2013 Ken Gilmer, Intel Corporation | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Ken Gilmer - initial API and implementation | ||
10 | * Ioana Grigoropol (Intel) - adapt class for remote support | ||
11 | *******************************************************************************/ | ||
12 | package org.yocto.bc.ui.wizards.newproject; | ||
13 | |||
14 | import java.io.Writer; | ||
15 | import java.lang.reflect.InvocationTargetException; | ||
16 | |||
17 | import org.eclipse.core.runtime.IProgressMonitor; | ||
18 | import org.eclipse.jface.operation.IRunnableWithProgress; | ||
19 | |||
20 | import org.yocto.bc.bitbake.BBSession; | ||
21 | import org.yocto.bc.bitbake.ProjectInfoHelper; | ||
22 | import org.yocto.bc.ui.Activator; | ||
23 | import org.yocto.bc.ui.model.ProjectInfo; | ||
24 | import org.yocto.remote.utils.RemoteHelper; | ||
25 | |||
26 | public class BBConfigurationInitializeOperation implements IRunnableWithProgress { | ||
27 | |||
28 | private final ProjectInfo pinfo; | ||
29 | private final Writer writer; | ||
30 | private boolean errorOccured = false; | ||
31 | private String errorMessage = ""; | ||
32 | |||
33 | public BBConfigurationInitializeOperation(ProjectInfo pinfo) { | ||
34 | this.pinfo = pinfo; | ||
35 | writer = null; | ||
36 | } | ||
37 | public boolean hasErrorOccured() { | ||
38 | return errorOccured; | ||
39 | } | ||
40 | public BBConfigurationInitializeOperation(ProjectInfo pinfo, Writer writer) { | ||
41 | this.pinfo = pinfo; | ||
42 | this.writer = writer; | ||
43 | } | ||
44 | |||
45 | public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { | ||
46 | BBSession session; | ||
47 | try { | ||
48 | System.out.println("Initialize bitbake session ..."); | ||
49 | monitor.beginTask("Initialize bitbake session ...", RemoteHelper.TOTALWORKLOAD); | ||
50 | session = Activator.getBBSession(pinfo, writer, monitor); | ||
51 | session.initialize(); | ||
52 | monitor.worked(90); | ||
53 | monitor.done(); | ||
54 | errorOccured = session.hasErrorOccured(); | ||
55 | errorMessage = session.getErrorLines(); | ||
56 | if (!errorOccured) { | ||
57 | System.out.println("Bitbake session initialized successfully."); | ||
58 | errorMessage = ""; | ||
59 | } else | ||
60 | System.out.println("An error occured and Bitbake session was not initialized."); | ||
61 | } catch (Exception e) { | ||
62 | throw new InvocationTargetException(e); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | public String getErrorMessage() { | ||
67 | return errorMessage; | ||
68 | } | ||
69 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java new file mode 100644 index 0000000..54f16c3 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/newproject/CreateBBCProjectOperation.java | |||
@@ -0,0 +1,93 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2013 Ken Gilmer, Intel Corporation | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Ken Gilmer - initial API and implementation | ||
10 | * Ioana Grigoropol (Intel) - adapt class for remote support | ||
11 | *******************************************************************************/ | ||
12 | package org.yocto.bc.ui.wizards.newproject; | ||
13 | |||
14 | import java.io.IOException; | ||
15 | import java.lang.reflect.InvocationTargetException; | ||
16 | import java.net.URI; | ||
17 | import java.net.URISyntaxException; | ||
18 | import java.util.Arrays; | ||
19 | import java.util.Vector; | ||
20 | |||
21 | import org.eclipse.core.resources.IProject; | ||
22 | import org.eclipse.core.resources.IProjectDescription; | ||
23 | import org.eclipse.core.resources.IWorkspace; | ||
24 | import org.eclipse.core.resources.IWorkspaceRoot; | ||
25 | import org.eclipse.core.resources.ResourcesPlugin; | ||
26 | import org.eclipse.core.runtime.CoreException; | ||
27 | import org.eclipse.core.runtime.IProgressMonitor; | ||
28 | import org.eclipse.core.runtime.IStatus; | ||
29 | import org.eclipse.core.runtime.QualifiedName; | ||
30 | import org.eclipse.core.runtime.Status; | ||
31 | import org.eclipse.ui.actions.WorkspaceModifyOperation; | ||
32 | |||
33 | import org.yocto.bc.bitbake.ProjectInfoHelper; | ||
34 | import org.yocto.bc.ui.Activator; | ||
35 | import org.yocto.bc.ui.builder.BitbakeCommanderNature; | ||
36 | import org.yocto.bc.ui.model.ProjectInfo; | ||
37 | |||
38 | |||
39 | /** | ||
40 | * Creates a bbc project | ||
41 | * @author kgilmer | ||
42 | * | ||
43 | */ | ||
44 | public class CreateBBCProjectOperation extends WorkspaceModifyOperation { | ||
45 | |||
46 | public static final String OEFS_SCHEME = "OEFS://"; | ||
47 | public static final QualifiedName BBC_PROJECT_INIT = new QualifiedName(null, "BBC_PROJECT_INIT"); | ||
48 | public static void addNatureToProject(IProject proj, String nature_id, IProgressMonitor monitor) throws CoreException { | ||
49 | IProjectDescription desc = proj.getDescription(); | ||
50 | Vector natureIds = new Vector(); | ||
51 | |||
52 | natureIds.add(nature_id); | ||
53 | natureIds.addAll(Arrays.asList(desc.getNatureIds())); | ||
54 | desc.setNatureIds((String[]) natureIds.toArray(new String[natureIds.size()])); | ||
55 | |||
56 | proj.setDescription(desc, monitor); | ||
57 | } | ||
58 | |||
59 | private ProjectInfo projInfo; | ||
60 | |||
61 | public CreateBBCProjectOperation(ProjectInfo projInfo) { | ||
62 | this.projInfo = projInfo; | ||
63 | } | ||
64 | |||
65 | protected void addNatures(IProject proj, IProgressMonitor monitor) throws CoreException { | ||
66 | addNatureToProject(proj, BitbakeCommanderNature.NATURE_ID, monitor); | ||
67 | } | ||
68 | |||
69 | private IProjectDescription createProjectDescription(IWorkspace workspace, ProjectInfo projInfo) throws CoreException { | ||
70 | IProjectDescription desc = workspace.newProjectDescription(projInfo.getProjectName()); | ||
71 | |||
72 | desc.setLocationURI(projInfo.getOEFSURI()); | ||
73 | return desc; | ||
74 | } | ||
75 | |||
76 | @Override | ||
77 | protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { | ||
78 | IProjectDescription desc = createProjectDescription(ResourcesPlugin.getWorkspace(), projInfo); | ||
79 | |||
80 | IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); | ||
81 | |||
82 | IProject proj = wsroot.getProject(projInfo.getProjectName()); | ||
83 | proj.create(desc, monitor); | ||
84 | |||
85 | proj.open(monitor); | ||
86 | |||
87 | addNatures(proj, monitor); | ||
88 | } | ||
89 | |||
90 | public ProjectInfo getProjectInfo() { | ||
91 | return projInfo; | ||
92 | } | ||
93 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java new file mode 100644 index 0000000..810a014 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java | |||
@@ -0,0 +1,262 @@ | |||
1 | package org.yocto.bc.ui.wizards.variable; | ||
2 | |||
3 | import java.util.Comparator; | ||
4 | import java.util.Map; | ||
5 | |||
6 | import org.eclipse.jface.viewers.ILabelProviderListener; | ||
7 | import org.eclipse.jface.viewers.IStructuredContentProvider; | ||
8 | import org.eclipse.jface.viewers.ITableLabelProvider; | ||
9 | import org.eclipse.jface.viewers.TableViewer; | ||
10 | import org.eclipse.jface.viewers.Viewer; | ||
11 | import org.eclipse.jface.viewers.ViewerFilter; | ||
12 | import org.eclipse.jface.viewers.ViewerSorter; | ||
13 | import org.eclipse.swt.SWT; | ||
14 | import org.eclipse.swt.events.SelectionAdapter; | ||
15 | import org.eclipse.swt.events.SelectionEvent; | ||
16 | import org.eclipse.swt.graphics.Image; | ||
17 | import org.eclipse.swt.layout.GridData; | ||
18 | import org.eclipse.swt.layout.GridLayout; | ||
19 | import org.eclipse.swt.widgets.Composite; | ||
20 | import org.eclipse.swt.widgets.Table; | ||
21 | import org.eclipse.swt.widgets.TableColumn; | ||
22 | import org.eclipse.swt.widgets.Text; | ||
23 | |||
24 | import org.yocto.bc.ui.wizards.FiniteStateWizardPage; | ||
25 | |||
26 | /** | ||
27 | * The wizard page for the Variable Wizard. | ||
28 | * @author kgilmer | ||
29 | * | ||
30 | */ | ||
31 | public class VariablePage extends FiniteStateWizardPage { | ||
32 | |||
33 | private Text txtName; | ||
34 | private Text txtValue; | ||
35 | private TableViewer viewer; | ||
36 | private TableColumn c1; | ||
37 | private TableColumn c2; | ||
38 | |||
39 | protected VariablePage(Map model) { | ||
40 | super("Yocto Project BitBake Commander", model); | ||
41 | setTitle("Yocto Project BitBake Variable Viewer"); | ||
42 | setDescription("Sort and fitler global BitBake variables by name or value."); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public void createControl(Composite parent) { | ||
47 | Composite top = new Composite(parent, SWT.None); | ||
48 | top.setLayout(new GridLayout(2, true)); | ||
49 | top.setLayoutData(new GridData(GridData.FILL_BOTH)); | ||
50 | |||
51 | ValidationListener listener = new ValidationListener(); | ||
52 | |||
53 | txtName = new Text(top, SWT.BORDER); | ||
54 | txtName.addModifyListener(listener); | ||
55 | txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | ||
56 | |||
57 | txtValue = new Text(top, SWT.BORDER); | ||
58 | txtValue.addModifyListener(listener); | ||
59 | txtValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | ||
60 | |||
61 | viewer = new TableViewer(top); | ||
62 | |||
63 | Table table = viewer.getTable(); | ||
64 | table.setLinesVisible(true); | ||
65 | table.setHeaderVisible(true); | ||
66 | GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); | ||
67 | data.heightHint = 200; | ||
68 | data.horizontalSpan = 2; | ||
69 | table.setLayoutData(data); | ||
70 | c1 = new TableColumn(table, SWT.NONE); | ||
71 | c1.setText("Name"); | ||
72 | c1.setWidth(200); | ||
73 | c1.addSelectionListener(new SelectionAdapter() { | ||
74 | public void widgetSelected(SelectionEvent event) { | ||
75 | ((VariableViewerSorter) viewer.getSorter()).doSort(0); | ||
76 | viewer.refresh(); | ||
77 | } | ||
78 | }); | ||
79 | |||
80 | c2 = new TableColumn(table, SWT.NONE); | ||
81 | c2.setText("Value"); | ||
82 | c2.setWidth(200); | ||
83 | c2.addSelectionListener(new SelectionAdapter() { | ||
84 | public void widgetSelected(SelectionEvent event) { | ||
85 | ((VariableViewerSorter) viewer.getSorter()).doSort(1); | ||
86 | viewer.refresh(); | ||
87 | } | ||
88 | }); | ||
89 | |||
90 | viewer.setContentProvider(new VariableContentProvider()); | ||
91 | viewer.setLabelProvider(new VariableLabelProvider()); | ||
92 | viewer.setSorter(new VariableViewerSorter()); | ||
93 | |||
94 | viewer.setFilters(new ViewerFilter[] {new MapViewerFilter()}); | ||
95 | setControl(top); | ||
96 | } | ||
97 | |||
98 | @Override | ||
99 | public void pageCleanup() { | ||
100 | |||
101 | } | ||
102 | |||
103 | @Override | ||
104 | public void pageDisplay() { | ||
105 | viewer.setInput(model); | ||
106 | } | ||
107 | |||
108 | @Override | ||
109 | protected void updateModel() { | ||
110 | viewer.refresh(); | ||
111 | } | ||
112 | |||
113 | @Override | ||
114 | protected boolean validatePage() { | ||
115 | return true; | ||
116 | } | ||
117 | |||
118 | /** | ||
119 | * A content provider for the variable wizard dialog. | ||
120 | * @author kgilmer | ||
121 | * | ||
122 | */ | ||
123 | private class VariableContentProvider implements IStructuredContentProvider { | ||
124 | |||
125 | public Object[] getElements(Object inputElement) { | ||
126 | return model.keySet().toArray(); | ||
127 | } | ||
128 | |||
129 | public void dispose() { | ||
130 | |||
131 | } | ||
132 | |||
133 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | ||
134 | |||
135 | } | ||
136 | } | ||
137 | |||
138 | /** | ||
139 | * A label provider for variable wizard dialog. | ||
140 | * @author kgilmer | ||
141 | * | ||
142 | */ | ||
143 | private class VariableLabelProvider implements ITableLabelProvider { | ||
144 | |||
145 | public Image getColumnImage(Object element, int columnIndex) { | ||
146 | return null; | ||
147 | } | ||
148 | |||
149 | public String getColumnText(Object element, int columnIndex) { | ||
150 | String val; | ||
151 | |||
152 | switch (columnIndex) { | ||
153 | case 0: | ||
154 | val = element.toString(); | ||
155 | break; | ||
156 | case 1: | ||
157 | val = (String) model.get(element); | ||
158 | break; | ||
159 | default: | ||
160 | val = ""; | ||
161 | break; | ||
162 | } | ||
163 | |||
164 | return val; | ||
165 | } | ||
166 | |||
167 | public void addListener(ILabelProviderListener listener) { | ||
168 | |||
169 | } | ||
170 | |||
171 | public void dispose() { | ||
172 | |||
173 | } | ||
174 | |||
175 | public boolean isLabelProperty(Object element, String property) { | ||
176 | return false; | ||
177 | } | ||
178 | |||
179 | public void removeListener(ILabelProviderListener listener) { | ||
180 | |||
181 | } | ||
182 | |||
183 | } | ||
184 | |||
185 | /** | ||
186 | * | ||
187 | * A tableviewer sorter found on the internet. | ||
188 | * | ||
189 | */ | ||
190 | class VariableViewerSorter extends ViewerSorter { | ||
191 | private static final int ASCENDING = 0; | ||
192 | |||
193 | private static final int DESCENDING = 1; | ||
194 | |||
195 | private int column; | ||
196 | |||
197 | private int direction; | ||
198 | |||
199 | public void doSort(int column) { | ||
200 | if (column == this.column) { | ||
201 | // Same column as last sort; toggle the direction | ||
202 | direction = 1 - direction; | ||
203 | } else { | ||
204 | // New column; do an ascending sort | ||
205 | this.column = column; | ||
206 | direction = ASCENDING; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | public int compare(Viewer viewer, Object e1, Object e2) { | ||
211 | int rc = 0; | ||
212 | Comparator c = this.getComparator(); | ||
213 | // Determine which column and do the appropriate sort | ||
214 | switch (column) { | ||
215 | case 0: | ||
216 | rc = c.compare(e1, e2); | ||
217 | break; | ||
218 | case 1: | ||
219 | rc = c.compare(model.get(e1), model.get(e2)); | ||
220 | break; | ||
221 | } | ||
222 | |||
223 | // If descending order, flip the direction | ||
224 | if (direction == DESCENDING) | ||
225 | rc = -rc; | ||
226 | |||
227 | return rc; | ||
228 | } | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * A filter for the name/value model. | ||
233 | * @author kgilmer | ||
234 | * | ||
235 | */ | ||
236 | private class MapViewerFilter extends ViewerFilter { | ||
237 | |||
238 | public MapViewerFilter() { | ||
239 | } | ||
240 | |||
241 | @Override | ||
242 | public boolean select(Viewer viewer, Object parentElement, Object element) { | ||
243 | String keyFilter = txtName.getText(); | ||
244 | String valFilter = txtValue.getText(); | ||
245 | |||
246 | String elem = (String) element; | ||
247 | String val = (String) model.get(element); | ||
248 | |||
249 | if (keyFilter.length() > 0 && elem.indexOf(keyFilter) == -1 ) { | ||
250 | return false; | ||
251 | } | ||
252 | |||
253 | if (valFilter.length() > 0 && val.indexOf(valFilter) == -1 ) { | ||
254 | return false; | ||
255 | } | ||
256 | |||
257 | return true; | ||
258 | } | ||
259 | |||
260 | } | ||
261 | |||
262 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariableWizard.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariableWizard.java new file mode 100644 index 0000000..d1bee1a --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariableWizard.java | |||
@@ -0,0 +1,43 @@ | |||
1 | package org.yocto.bc.ui.wizards.variable; | ||
2 | |||
3 | import java.util.Hashtable; | ||
4 | import java.util.Map; | ||
5 | |||
6 | import org.eclipse.jface.viewers.IStructuredSelection; | ||
7 | |||
8 | import org.yocto.bc.ui.wizards.FiniteStateWizard; | ||
9 | |||
10 | /** | ||
11 | * This wizard is used to view, filter, and search for BitBake variables and variable contents. | ||
12 | * @author kgilmer | ||
13 | * | ||
14 | */ | ||
15 | public class VariableWizard extends FiniteStateWizard { | ||
16 | |||
17 | private Map model; | ||
18 | |||
19 | public VariableWizard(Map model) { | ||
20 | this.model = model; | ||
21 | setWindowTitle("Yocto Project BitBake Commander"); | ||
22 | } | ||
23 | |||
24 | public VariableWizard(IStructuredSelection selection) { | ||
25 | model = new Hashtable(); | ||
26 | } | ||
27 | |||
28 | @Override | ||
29 | public void addPages() { | ||
30 | addPage(new VariablePage(model)); | ||
31 | } | ||
32 | |||
33 | @Override | ||
34 | public Map getModel() { | ||
35 | return model; | ||
36 | } | ||
37 | |||
38 | @Override | ||
39 | public boolean performFinish() { | ||
40 | return true; | ||
41 | } | ||
42 | |||
43 | } | ||