import org.tizen.nativeplatform.password.SudoPasswdManager;
import org.tizen.nativeplatform.preferences.PreferencesManager;
import org.tizen.nativeplatform.rootstrap.RootstrapManager;
-import org.tizen.nativeplatform.views.model.ICheckTreeItem;
import org.tizen.nativeplatform.views.model.PlatformRootstrap;
String arch = rootstrap.getArch();
String snapshots = "";
- for (ICheckTreeItem s : rootstrap.getChildren()) {
- snapshots = snapshots + " " + s.getText();
+ for (String s : rootstrap.getRepositoryURLs()) {
+ snapshots = snapshots + " " + s;
}
String options = String.format(
+++ /dev/null
-package org.tizen.nativeplatform.rootstrap;
-
-import org.eclipse.cdt.core.CommandLauncher;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.ui.console.MessageConsoleStream;
-import org.tizen.common.ui.view.console.ConsoleManager;
-
-import org.tizen.nativeplatform.views.model.Architecture;
-import org.tizen.nativeplatform.views.model.Snapshot;
-import org.tizen.nativeplatform.views.model.ICheckTreeItem;
-
-public class GenerateRootstrap {
-
- private GenerateRootstrap() {
-
- }
-
- public static boolean generate(String passwd, IPath path, Architecture arch) {
- return generate("noproxy", passwd, path, arch);
- }
-
- public static boolean generate(String proxy, String passwd, IPath path, Architecture arch) {
-
- String snapshots = "";
- for(ICheckTreeItem a : arch.getChildren()) {
- Snapshot s = (Snapshot)a;
- snapshots = snapshots + " " + s.getText();
- }
-
- snapshots = snapshots.trim();
-
- String[] cmd = new String[1];
- cmd[0] = "/tmp/createDummy.sh";
- String[] args = new String[5];
- args[0] = proxy;
- args[1] = arch.getText();
- args[2] = path.toOSString();
- args[3] = passwd;
- args[4] = snapshots;
-
- ConsoleManager cm = new ConsoleManager("Generate Rootstrap [" + args[1] +"]", true);
- cm.clear();
- MessageConsoleStream mcsError = cm.getMessageConsoleStream();
- MessageConsoleStream mcs = cm.getMessageConsoleStream();
-
- return generateTmpProject(cmd, args, mcs, mcsError);
- }
-
-
- private static boolean generateTmpProject(String[] cmd, String[] args, MessageConsoleStream mcs, MessageConsoleStream mcsError) {
-
- CommandLauncher launcher = new CommandLauncher();
- try {
- Process proc = launcher.execute(new Path(cmd[0]), args, null, null, new NullProgressMonitor());
- int illegalCommand = launcher.waitAndRead(mcs, mcsError );
- if (illegalCommand != 0) {
- return false;
- }
- int exitValue = proc.exitValue();
- proc.destroy();
- if ( exitValue == 0) {
- return true;
- } else {
- return false;
- }
- } catch (CoreException e) {
- e.printStackTrace();
- }
-
- return true;
- }
-}
+++ /dev/null
-package org.tizen.nativeplatform.rootstrap;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.tizen.common.core.application.InstallPathConfig;
-import org.tizen.nativecommon.build.SmartBuildInterface;
-import org.tizen.nativeplatform.views.model.PlatformRootstrap;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-public class GenerateRootstrapXml {
-
- private GenerateRootstrapXml() {
-
- }
-
- public static String generate(PlatformRootstrap rootstrap) {
- IPath path = rootstrap.getPath();
- String id = rootstrap.getId();
- String name = rootstrap.getName();
- String arch = rootstrap.getArch();
- String type = rootstrap.getSupportToolchainType();
- return generate(path, id, name, type, arch);
- }
-
- public static String generate(IPath rootstrapBasePath, String id,
- String rootName, String type, String arch) {
-
- String sdkPath = InstallPathConfig.getSDKPath();
- String fileName = id + ".xml";
- String path = rootstrapBasePath.toOSString();
- path = path.replaceAll(sdkPath, "#{SBI_HOME}/../..");
-
- IPath pluginPath = new Path(SmartBuildInterface.getInstance().getPluginPath());
- IPath filePath = pluginPath.append(fileName);
-
- try {
- DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
-
- // root element
- Document doc = docBuilder.newDocument();
- Element rootElement = doc.createElement("extension");
- doc.appendChild(rootElement);
-
- Attr attr = doc.createAttribute("point");
- attr.setValue("rootstrapDefinition");
- rootElement.setAttributeNode(attr);
-
- Element firstnode = doc.createElement("rootstrap");
- rootElement.appendChild(firstnode);
-
- Attr attrId = doc.createAttribute("id");
- attrId.setValue(id);
- Attr attrName = doc.createAttribute("name");
- attrName.setValue(rootName);
- Attr attrArch = doc.createAttribute("architecture");
- attrArch.setValue(arch);
- Attr attrPath = doc.createAttribute("path");
- attrPath.setValue(path);
- Attr attrType = doc.createAttribute("supportToolchainType");
- attrType.setValue(type);
-
- firstnode.setAttributeNode(attrId);
- firstnode.setAttributeNode(attrName);
- firstnode.setAttributeNode(attrArch);
- firstnode.setAttributeNode(attrPath);
- firstnode.setAttributeNode(attrType);
-
- Element secondnode = doc.createElement("property");
- firstnode.appendChild(secondnode);
-
- Attr attrKey = doc.createAttribute("key");
- attrKey.setValue("DEV_PACKAGE_CONFIG_PATH");
- Attr attrValue = doc.createAttribute("value");
- attrValue.setValue("");
-
- secondnode.setAttributeNode(attrKey);
- secondnode.setAttributeNode(attrValue);
-
- TransformerFactory transformerFactory = TransformerFactory.newInstance();
- Transformer transformer = transformerFactory.newTransformer();
-
- transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-
-
- DOMSource source = new DOMSource(doc);
- StreamResult result = new StreamResult(new FileOutputStream(new File(filePath.toOSString())));
-
- transformer.transform(source, result);
-
- } catch (ParserConfigurationException e) {
- e.printStackTrace();
- } catch (TransformerConfigurationException e) {
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (TransformerException e) {
- e.printStackTrace();
- }
-
- return id;
- }
-}
+++ /dev/null
-package org.tizen.nativeplatform.rootstrap;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import org.eclipse.cdt.managedbuilder.core.IConfiguration;
-import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
-import org.eclipse.cdt.managedbuilder.core.IManagedProject;
-import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.tizen.nativecommon.build.SmartBuildInterface;
-import org.tizen.nativeplatform.build.PlatformConfigurationManager;
-import org.tizen.nativeplatform.password.SudoPasswdManager;
-import org.tizen.nativeplatform.views.model.PlatformRootstrap;
-
-public class RemoveRootstrap {
-
- private static ArrayList<String> projectNames = new ArrayList<String>();
- private static HashMap<IProject, String> projectMap = new HashMap<IProject, String>();
- private RemoveRootstrap() {
-
- }
-
- public static boolean remove(PlatformRootstrap rootstrap) {
-
- String passwd = SudoPasswdManager.getSudoPassword();
- String path = rootstrap.getPath().toOSString();
- String command = String.format("sh -c \'echo %s | sudo -S rm -rf %s\'", passwd, path);
- return false;
- }
-
- public static boolean remove(String id) {
- PlatformRootstrap rootstrap = RootstrapManager.getRootstrap(id);
- return remove(rootstrap);
- }
-
- private static void checkRootstrap(String id) {
- IWorkspace works = ResourcesPlugin.getWorkspace();
- IProject[] projs = works.getRoot().getProjects();
- for (IProject p : projs) {
- IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(p);
- if( info == null) {
- continue;
- }
- IConfiguration cfg = info.getDefaultConfiguration();
- if( cfg == null) {
- continue;
- }
- String targetId = PlatformConfigurationManager.getBuildTargetName(cfg);
- String rootstrapId = SmartBuildInterface.getInstance().getRootstrapIDFromTargetID(targetId);
- IManagedProject managedProject = cfg.getManagedProject();
- if( managedProject == null) {
- continue;
- }
- String projectArtifactType = managedProject.getProjectType() != null ? managedProject.getProjectType().getBuildArtefactType().getId() : null;
- if (projectArtifactType != null &&
- projectArtifactType.equals(PlatformConfigurationManager.TIZEN_PLATFORM_ARTIFACT_TYPE) &&
- rootstrapId.equals(id)) {
- String name = p.getName();
- projectNames.add(name);
- }
-
-
- }
- }
-}
package org.tizen.nativeplatform.rootstrap;
-import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileReader;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.tizen.common.core.application.InstallPathConfig;
import org.tizen.nativecommon.build.SmartBuildInterface;
import org.tizen.nativecommon.build.exception.SBIException;
-import org.tizen.nativeplatform.build.PlatformConfigurationManager;
-import org.tizen.nativeplatform.views.model.ICheckTreeItem;
+import org.tizen.nativecommon.build.model.SBIModel;
+import org.tizen.nativecommon.build.model.Target;
+import org.tizen.nativeplatform.password.SudoPasswdManager;
import org.tizen.nativeplatform.views.model.PlatformRootstrap;
-import org.tizen.nativeplatform.views.model.Snapshot;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
public class RootstrapManager {
public static Set<IRootstrapChangedListener> changedListener = new HashSet<IRootstrapChangedListener>();
private static boolean init;
- private static final String EMULATOR_XML_PREFIX = "tizen-emulator-2.0.platform.";
- private static final String DEVICE_XML_PREFIX = "tizen-device-2.0.platform.";
-
- private static final String PLATFORM_TOOLCHAIN_TYPE = "tizen.obs";
private RootstrapManager() {
}
ArrayList<String> lists = sbi.getRootstrapList();
for (String id : lists) {
String type = sbi.getSupportToolchainTypeFromRootstrapID(id);
- if (!PLATFORM_TOOLCHAIN_TYPE.equals(type)) {
+ if (!type.equals(PlatformRootstrap.SUPPORTED_TOOLCHAIN_TYPE)) {
continue;
}
String rootName = sbi.getRootstrapNameFromRootstrapID(id);
String arch = sbi.getArchitectureFromRootstrapID(id);
String path = sbi.getRootstrapPathFromRootstrapID(id);
- addRootstrap(new Path(path), id, rootName, arch);
+ ArrayList<String> reposURLs = new ArrayList<String>();
+ String rootstrapPath = sbi.getRootstrapPropertyValue(id, "REPOSITORY_URLS");
+ if ( rootstrapPath != null && rootstrapPath.split("|").length >= 1 ) {
+ for ( String url : rootstrapPath.split("|") ) {
+ reposURLs.add( url );
+ }
+ }
+ boolean initialized = new File(path).exists() ? true : false;
+ addRootstrap( new PlatformRootstrap(id, rootName, arch, path,
+ reposURLs, initialized) );
}
} catch (SBIException e) {
e.printStackTrace();
init = true;
}
+
- public static PlatformRootstrap addRootstrap(IPath rootstrapPath, String rootName, String arch) {
- String id = getXmlNamePrefix(arch) + rootName;
- return addRootstrap(rootstrapPath, id, rootName, arch);
+ public static PlatformRootstrap addRootstrap(PlatformRootstrap rootstrap ) {
+ rootstraps.add(rootstrap);
+ SBIModel.addRootstrap(rootstrap, false);
+
+ RootstrapManager.notifyChangedRootstrap();
+
+ return rootstrap;
}
- public static PlatformRootstrap addRootstrap(IPath rootstrapPath, String id, String rootName, String arch) {
- ArrayList<ICheckTreeItem> snapshots = new ArrayList<ICheckTreeItem>();
- if (exists(rootName, arch)) {
- return null;
- }
- snapshots = getSnapshotList(rootstrapPath);
- PlatformRootstrap r = new PlatformRootstrap(id, rootName, arch, snapshots, null, rootstrapPath);
- rootstraps.add(r);
- return r;
- }
- private static boolean exists(String rootName, String arch) {
- for (PlatformRootstrap root : rootstraps) {
- if (root.getText().equals(rootName) && root.getArch().equals(arch)) {
- return true;
- }
- }
+ public static boolean removeRootstrap(String id) {
+ PlatformRootstrap rootstrap = getRootstrap( id );
- return false;
+ if ( rootstrap != null ) {
+ rootstraps.remove( rootstrap );
+ removeSBIPluginXML( rootstrap );
+ removeBaseFileSystem( rootstrap.getId() );
+ RootstrapManager.notifyChangedRootstrap();
+ return true;
+ }
+ else {
+ return false;
+ }
}
+
public static ArrayList<PlatformRootstrap> getRootstraps() {
checkInit();
return rootstraps;
}
+
public static PlatformRootstrap getRootstrap(String id) {
checkInit();
return null;
}
+
+ public static PlatformRootstrap getDefaultRootstrap( String arch ) {
+ String baseArch = RootstrapManager.getBaseArchitecture( arch );
+ String defaultRootstrapID = baseArch.equals("arm") ?
+ PlatformRootstrap.DEFAULT_ROOTSTRAP_ARM_ID : PlatformRootstrap.DEFAULT_ROOTSTRAP_I386_ID;
+
+ return RootstrapManager.getRootstrap( defaultRootstrapID );
+ }
+
+
public static void reinitialize() {
init = false;
rootstraps.clear();
initialize();
}
-
- private static ArrayList<ICheckTreeItem> getSnapshotList(IPath rootPath) {
-
- ArrayList<ICheckTreeItem> snapshots = new ArrayList<ICheckTreeItem>();
- IPath zyppPath = rootPath.append("etc").append("zypp").append("repos.d");
- File zyppDir = new File(zyppPath.toOSString());
- if (!zyppDir.exists()) {
- return snapshots;
- }
-
- for (File f : zyppDir.listFiles()) {
- if (f.isFile()) {
- try {
- BufferedReader in = new BufferedReader(new FileReader(f.getPath()));
- String s;
- while ((s = in.readLine()) != null) {
- if (s.startsWith("baseurl=")) {
- snapshots.add(new Snapshot(s.split("=")[1]));
- break;
- }
- }
-
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
-
- return snapshots;
- }
+
public static void setSelectedRootstrap(PlatformRootstrap selected) {
for (PlatformRootstrap r : rootstraps) {
selectedRootstrap = selected;
}
+
public static void setSelectedRootstrap(String id) {
for(PlatformRootstrap r : RootstrapManager.getRootstraps()) {
if (id.equals(r.getId())) {
}
}
+
public static void resetSelectedRootstrap() {
for (PlatformRootstrap r : rootstraps) {
if(r.isChecked()) {
}
}
+
public static PlatformRootstrap getSelectedRootstrap() {
return selectedRootstrap;
}
+
public static synchronized void addListener(IRootstrapChangedListener listener) {
changedListener.add(listener);
}
+
public static synchronized void removeListener(IRootstrapChangedListener listener) {
changedListener.remove(listener);
}
+
public static synchronized void notifyChangedRootstrap() {
Iterator<IRootstrapChangedListener> ite = changedListener.iterator();
}
}
+
public static synchronized void notifyChangedSelectionListener(String rootName) {
Iterator<IRootstrapChangedListener> ite = changedListener.iterator();
}
}
- private static String getXmlNamePrefix(String arch) {
- if (PlatformConfigurationManager.isEmulatorArch(arch)) {
- return EMULATOR_XML_PREFIX;
- } else if (PlatformConfigurationManager.isDeviceArch(arch)) {
- return DEVICE_XML_PREFIX;
- }
-
- return null;
- }
private static void checkInit() {
if (!init) {
initialize();
}
}
+
+
+ public static PlatformRootstrap generate(String name, String arch,
+ ArrayList<String> reposURLs, boolean immediateGen) {
+
+ boolean initialized = false;
+ String id = name;
+ if ( immediateGen ) {
+ if ( generateBaseFileSystem(id, arch, reposURLs) ) {
+ initialized = true;
+ }
+ else {
+ removeBaseFileSystem(id);
+ return null;
+ }
+ }
+
+ // generate SBI plugins
+ if ( generateSBIPluginXML(id, name, arch, reposURLs) ) {
+ return new PlatformRootstrap(id, name, arch, getRootstrapPath(name),
+ reposURLs, initialized);
+ }
+ else {
+ if ( immediateGen ) {
+ removeBaseFileSystem(id);
+ }
+ return null;
+ }
+
+ }
+
+
+ private static boolean generateBaseFileSystem(String id, String arch,
+ ArrayList<String> reposURLs) {
+
+ // remove temp directory if exist
+ if ( !commandWithSudo(String.format("sudo -S rm -rf %s", id), null) ) {
+ // this is for checking sudo password error
+ return false;
+ }
+
+ // use rogen
+ String rogen = InstallPathConfig.getSDKPath()+"/tools/rogen/bin/rogen.rb";
+ String baseArch = getBaseArchitecture(arch);
+ String urlData = "";
+ for( String url: reposURLs ) {
+ urlData += (urlData.isEmpty() ? url : "," + url );
+ }
+ String command = String.format( "%s -n %s -a %s -u %s -p rpm --ctrl GBS -g TizenPlatform", rogen, id, baseArch, urlData );
+ if ( !commandWithSudo( command, "Platform Internal") ) {
+ return false;
+ }
+
+ // copy
+ String rootstrapBasePath = new File(getRootstrapPath(id)).getParent();
+ commandWithSudo(String.format("sudo -S mkdir -p %s", rootstrapBasePath), null);
+ commandWithSudo(String.format("sudo -S mv %s %s/", id, rootstrapBasePath), null);
+
+ return true;
+ }
+
+
+ private static void removeBaseFileSystem( String id ) {
+ String path = getRootstrapPath( id );
+ commandWithSudo( String.format("sudo -S rm -rf %s", path), null );
+ }
+
+
+ public static String getBaseArchitecture( String arch ) {
+ if ( arch.contains("arm") ) {
+ return "arm";
+ }
+ else {
+ return "i386";
+ }
+ }
+
+
+ private static boolean commandWithSudo( String command, String consoleName ) {
+ String passwd = SudoPasswdManager.getSudoPassword();
+ try {
+ // create expect script file
+ File expectScript = new File("/tmp/run_sudo.exp");
+ expectScript.createNewFile();
+ BufferedWriter bw = new BufferedWriter(new FileWriter(expectScript));
+ bw.write("#!/usr/bin/expect --");bw.newLine();
+ bw.write(String.format("spawn sh -c \"%s;echo \\$? > /tmp/exit-status\"",command));bw.newLine();
+ bw.write("while (1) {");bw.newLine();
+ bw.write(" expect {");bw.newLine();
+ bw.write(" \"password for\" {");bw.newLine();
+ bw.write(String.format("send \"%s\\r\"", passwd));bw.newLine();
+ bw.write(" }");bw.newLine();
+ bw.write(" eof {");bw.newLine();
+ bw.write(" return");bw.newLine();
+ bw.write(" }");bw.newLine();
+ bw.write(" }");bw.newLine();
+ bw.write("}");bw.newLine();
+ bw.close();
+ expectScript.setExecutable(true);
+
+ File shellScript = new File("/tmp/run_sudo.sh");
+ shellScript.createNewFile();
+ bw = new BufferedWriter(new FileWriter(shellScript));
+ bw.write("#!/bin/sh -ee");bw.newLine();
+ bw.write("/tmp/run_sudo.exp");bw.newLine();
+ bw.write("EXIT_CODE=`cat /tmp/exit-status`");bw.newLine();
+ bw.write("if [ \"$EXIT_CODE\" != \"0\" ]; then");bw.newLine();
+ bw.write(" echo \"EXIT CODE=${EXIT_CODE}\" >&2");bw.newLine();
+ bw.write(" exit 1");bw.newLine();
+ bw.write("fi");bw.newLine();
+ bw.close();
+ shellScript.setExecutable(true);
+
+ // execute script
+ String scriptCommand = shellScript.getPath();
+ if (consoleName != null && !consoleName.isEmpty() ) {
+ SmartBuildInterface.getInstance().commandConsole(scriptCommand, "/tmp", consoleName);
+ }
+ else {
+ SmartBuildInterface.getInstance().command(scriptCommand, "/tmp");
+ }
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ } catch (SBIException e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ return true;
+ }
+
+
+
+ public static boolean generateSBIPluginXML( String id, String name, String arch, ArrayList<String> reposURLs) {
+
+ IPath pluginPath = new Path(SmartBuildInterface.getInstance().getPluginPath());
+ IPath filePath = pluginPath.append(id + ".xml");
+
+ try {
+ DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
+
+ // root element
+ Document doc = docBuilder.newDocument();
+ Element rootElement = doc.createElement("extension");
+ doc.appendChild(rootElement);
+
+ Attr attr = doc.createAttribute("point");
+ attr.setValue("rootstrapDefinition");
+ rootElement.setAttributeNode(attr);
+
+ Element firstnode = doc.createElement("rootstrap");
+ rootElement.appendChild(firstnode);
+
+ Attr attrId = doc.createAttribute("id");
+ attrId.setValue(id);
+ Attr attrName = doc.createAttribute("name");
+ attrName.setValue(name);
+ Attr attrArch = doc.createAttribute("architecture");
+ attrArch.setValue(arch);
+ Attr attrPath = doc.createAttribute("path");
+ attrPath.setValue( getRootstrapPathOfXml(name) );
+ Attr attrType = doc.createAttribute("supportToolchainType");
+ attrType.setValue("tizen.obs");
+
+ firstnode.setAttributeNode(attrId);
+ firstnode.setAttributeNode(attrName);
+ firstnode.setAttributeNode(attrArch);
+ firstnode.setAttributeNode(attrPath);
+ firstnode.setAttributeNode(attrType);
+
+ String reposURLString = "";
+ for ( String URL: reposURLs ) {
+ if ( !reposURLString.isEmpty() ) {
+ reposURLString += "|";
+ }
+ reposURLString += URL;
+ }
+
+ Element secondnode = doc.createElement("property");
+ firstnode.appendChild(secondnode);
+
+ Attr attrKey = doc.createAttribute("key");
+ attrKey.setValue("REPOSITORY_URLS");
+ Attr attrValue = doc.createAttribute("value");
+ attrValue.setValue(reposURLString);
+
+ secondnode.setAttributeNode(attrKey);
+ secondnode.setAttributeNode(attrValue);
+
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+
+ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+
+
+ DOMSource source = new DOMSource(doc);
+ StreamResult result = new StreamResult(new FileOutputStream(new File(filePath.toOSString())));
+
+ transformer.transform(source, result);
+
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ return false;
+ } catch (TransformerConfigurationException e) {
+ e.printStackTrace();
+ return false;
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ return false;
+ } catch (TransformerException e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ return true;
+ }
+
+
+ public static void removeSBIPluginXML(PlatformRootstrap rootstrap) {
+ // remove related targets
+ ArrayList<Target> targetList = SBIModel.getTargetList();
+ for( Target target : targetList ) {
+ if ( target.getRootstrap().getId().equals(rootstrap.getId()) ) {
+ // remove from model/file
+ SBIModel.removeTarget( target );
+ new File(getPluginXML(target.getId())).delete();
+ }
+ }
+
+ // remove model/file
+ SBIModel.removeRootstrap(rootstrap);
+ new File(getPluginXML(rootstrap.getId())).delete();
+ }
+
+
+ private static String getPluginXML( String id ) {
+ IPath pluginPath = new Path(SmartBuildInterface.getInstance().getPluginPath());
+ return pluginPath.append(id + ".xml").toOSString();
+ }
+
+
+ private static String getRootstrapPath(String id) {
+ return new Path(SmartBuildInterface.getInstance().getBaseRootstrapPath())
+ .append("platform").append(id).toOSString();
+ }
+
+
+ private static String getRootstrapPathOfXml(String id ) {
+ String rootstrapPath = getRootstrapPath(id);
+
+ return rootstrapPath.replaceAll(InstallPathConfig.getSDKPath(), "#{SBI_HOME}/../..");
+ }
}
import java.net.URLConnection;
import java.util.ArrayList;
+import org.tizen.nativeplatform.preferences.PreferencesManager;
import org.tizen.nativeplatform.views.model.Architecture;
import org.tizen.nativeplatform.views.model.ICheckTreeItem;
-import org.tizen.nativeplatform.views.model.PlatformRootstrap;
import org.tizen.nativeplatform.views.model.Snapshot;
public class SnapshotURLParser {
}
- public PlatformRootstrap parse(String rootstrapName, String url)
- throws MalformedURLException, IOException {
- return parse(rootstrapName, url, null, 0);
- }
-
- public PlatformRootstrap parse(String rootstrapName, String url, String proxy, int porxyPort)
+ public ArrayList<ICheckTreeItem> parse(String url)
throws MalformedURLException, IOException {
+
+ String proxyHost = PreferencesManager.getHttpProxyHost();
Proxy p = null;
- if (proxy != null) {
- SocketAddress addr = new InetSocketAddress(proxy, porxyPort);
+ if (proxyHost != null && !proxyHost.isEmpty() ) {
+ int porxyPort = Integer.parseInt(PreferencesManager.getHttpProxyPort());
+ SocketAddress addr = new InetSocketAddress(proxyHost, porxyPort);
p = new Proxy(Proxy.Type.HTTP, addr);
}
if (url.endsWith("/")) {
}
}
- PlatformRootstrap rt = new PlatformRootstrap(rootstrapName, archs);
- return rt;
+ return archs;
}
+
public ArrayList<ICheckTreeItem> parseArch(String path, String name,
ArrayList<ICheckTreeItem> archs, Proxy p)
throws MalformedURLException, IOException {
return archs;
}
+
public boolean checkValidPath(String path, Proxy p) {
try {
URL u = new URL(path);
package org.tizen.nativeplatform.views.model;
import java.util.ArrayList;
-
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.tizen.nativecommon.build.model.Rootstrap;
public class PlatformRootstrap extends Rootstrap implements ICheckTreeItem {
- private ArrayList<ICheckTreeItem> snapshots = new ArrayList<ICheckTreeItem>();
private String http_proxy;
- private boolean checked;
-
- public PlatformRootstrap(String id, String name, String arch,
- ArrayList<ICheckTreeItem> snapshots, String proxy, IPath rootstrapPath) {
-
- super(id, name, "tizen.obs", "1.0", arch, rootstrapPath);
- this.snapshots = snapshots;
- this.http_proxy = proxy;
+ private boolean checked;
+ private boolean initialized;
+ private ArrayList<String> reposURLs;
+ public static final String SUPPORTED_TOOLCHAIN_TYPE = "tizen.obs";
+ public static final String DEFAULT_ROOTSTRAP_ARM_ID = "tizen-device-2.0.platform";
+ public static final String DEFAULT_ROOTSTRAP_I386_ID = "tizen-emulator-2.0.platform";
+ private static final String VERSION = "1.0";
+
+ public PlatformRootstrap(String id, String name, String arch, String rootstrapPath,
+ ArrayList<String> reposURLs, boolean initialized) {
+ super(id, name, SUPPORTED_TOOLCHAIN_TYPE, VERSION, arch, new Path(rootstrapPath));
+ this.reposURLs = reposURLs;
+ this.initialized = initialized;
}
- public PlatformRootstrap(String name, ArrayList<ICheckTreeItem> snapshots) {
-
- super(null, name, null, null, null, new Path(""));
- this.snapshots = snapshots;
- }
public String getText() {
return name;
return http_proxy;
}
- public ArrayList<ICheckTreeItem> getChildren() {
- return snapshots;
- }
-
- public boolean hasChildren() {
- return !snapshots.isEmpty();
- }
-
public boolean isChecked() {
return checked;
}
public void setChecked(boolean isChecked) {
checked = isChecked;
- if (hasChildren()) {
- for (ICheckTreeItem item : getChildren()) {
- item.setChecked(isChecked);
- }
- }
+ }
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ public ArrayList<String> getRepositoryURLs() {
+ return reposURLs;
}
@Override
public boolean isGrayed() {
- // TODO Auto-generated method stub
return false;
}
+ @Override
+ public ArrayList<ICheckTreeItem> getChildren() {
+ return null;
+ }
+
+ @Override
+ public boolean hasChildren() {
+ return false;
+ }
}
package org.tizen.nativeplatform.views.ui;
-import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.ResourceBundle;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.ICheckStateProvider;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.tizen.common.util.DialogUtil;
import org.tizen.common.util.SWTUtil;
-import org.tizen.nativecommon.build.SmartBuildInterface;
-import org.tizen.nativecommon.build.model.SBIModel;
-import org.tizen.nativeplatform.password.SudoPasswdManager;
-import org.tizen.nativeplatform.preferences.PreferencesManager;
-import org.tizen.nativeplatform.rootstrap.GenerateRootstrap;
-import org.tizen.nativeplatform.rootstrap.GenerateRootstrapXml;
import org.tizen.nativeplatform.rootstrap.SnapshotURLParser;
import org.tizen.nativeplatform.rootstrap.RootstrapManager;
-import org.tizen.nativeplatform.views.model.Architecture;
import org.tizen.nativeplatform.views.model.ICheckTreeItem;
import org.tizen.nativeplatform.views.model.PlatformRootstrap;
-import org.tizen.nativeplatform.views.model.Snapshot;
-import org.tizen.nativeplatform.views.provider.RootstrapContentProvider;
-import org.tizen.nativeplatform.views.provider.RootstrapLabelProvider;
public class AddRootstrapDialog extends Dialog {
private Text rootstrapText;
- private Text proxyText;
- private Text portText;
private Text snapshotUrlText;
- private CheckboxTreeViewer treeViewer;
- private Button proxyBt;
- private Button genRootstrapBt;
+ private TableViewer reposURLViewer;
+ private Combo archCombo;
+ private Button generateImmediateBt;
- private String proxyStr = "";
+ ArrayList<ICheckTreeItem> snapshotInfos;
+ private PlatformRootstrap generatedRootstrap;
+ private String rootstrapName;
+ private String architecture;
+ private ArrayList<String> repositoryURLs;
+ boolean isImmediateGenerateChecked;
- private PlatformRootstrap rootstrap;
+ private final static int COL_REPOS_NAME = 0;
+ private final static int COL_REPOS_URL = 1;
private int x = 0;
private int y = 0;
private final int width = 800;
- private final int height = 700;
+ private final int height = 550;
private Shell shell;
private final String BUNDLE_NAME = AddRootstrapDialog.class.getPackage().getName() + ".RootstrapUIMessages";//$NON-NLS-1$
composite.setLayout(new GridLayout(1, false));
createRootstrapNameComposite(composite);
- createSettingRepoComposite(composite);
+ createSelectSnapshotComposite(composite);
+ createSettingRepoComposite(composite);
+
createGenButtonComposite(composite);
return null;
}
rootstrapText.setLayoutData(gridData);
}
+
private void createGenButtonComposite(Composite parent) {
Composite composite = new Composite( parent, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
composite.setLayout(new GridLayout(1, false));
- genRootstrapBt = new Button(composite, SWT.PUSH);
- genRootstrapBt.setText(resources.getString("GenRootDlg.Button.Generate"));
- GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END);
- genRootstrapBt.setLayoutData(gridData);
-
- genRootstrapBt.addMouseListener(new MouseListener() {
-
- @Override
- public void mouseDoubleClick(MouseEvent e) {
- }
-
- @Override
- public void mouseDown(MouseEvent e) {
- ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
-
- final String rootstrapNamePrefix = rootstrapText.getText();
- final boolean selectedProxy = proxyBt.getSelection();
-
- try {
- dialog.run(true, true, new IRunnableWithProgress() {
- @Override
- public void run(IProgressMonitor monitor) throws InvocationTargetException,
- InterruptedException {
- monitor.beginTask(resources.getString("GenRootDlg.Progress.Msg.Generating"), -1);
-
- String password = SudoPasswdManager.getSudoPassword();
-
- ArrayList<ICheckTreeItem> selectedArchs = getSelectedArchs();
-
- for (ICheckTreeItem i : selectedArchs) {
- final Architecture a = (Architecture)i;
- final String arch = a.getText();
- final String rootstrapName = rootstrapNamePrefix + "_" + arch;
- IPath baseRootstrapPath = new Path(SmartBuildInterface.getInstance().getBaseRootstrapPath()).append("platform");
- IPath rootstrapPath = baseRootstrapPath.append(rootstrapName);
- monitor.subTask(resources.getString("GenRootDlg.Progress.Msg.Generating")
- + " [" + arch + "]");
- boolean result = false;
- if (selectedProxy) {
- result = GenerateRootstrap.generate(proxyStr, password, rootstrapPath, a);
- } else {
- result = GenerateRootstrap.generate(password, rootstrapPath, a);
- }
-
- if (result) {
- IPath repoPath = rootstrapPath.append("local");
- if (new File(repoPath.toOSString()).exists()) {
- if (!repoPath.isEmpty()) {
- File repoDir = new File(repoPath.toOSString());
- for (File r : repoDir.listFiles()) {
- if (r.isDirectory() && r.getName().startsWith("scratch")) {
- rootstrapPath = repoPath.append(r.getName());
- }
- }
- }
- }
-
- PlatformRootstrap r = RootstrapManager.addRootstrap(rootstrapPath, rootstrapNamePrefix, arch);
- GenerateRootstrapXml.generate(r);
- SBIModel.addRootstrap(r, false);
- } else {
- SWTUtil.getDisplay().asyncExec( new Runnable() {
- @Override
- public void run() {
- DialogUtil.openErrorDialog(resources.getString("GenRootDlg.Progress.Msg.Generating")
- + " [" + arch +"]");
- }
- });
- }
- }
- }
- });
- } catch (Exception e1) {
- e1.printStackTrace();
- }
-
- RootstrapManager.notifyChangedRootstrap();
- }
-
- @Override
- public void mouseUp(MouseEvent e) {
- }
-
- });
+ generateImmediateBt = new Button(composite, SWT.CHECK);
+ generateImmediateBt.setText(resources.getString("GenRootDlg.Button.GenImmedate"));
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING);
+ generateImmediateBt.setLayoutData(gridData);
}
- private void createHttpProxyComposite(Composite parent) {
- Composite composite = new Composite( parent, SWT.NONE);
- composite.setLayoutData(new GridData(GridData.FILL_BOTH));
- composite.setLayout(new GridLayout(4, false));
-
- proxyBt = new Button(composite, SWT.CHECK);
- proxyBt.setText(resources.getString("GenRootDlg.Label.Httpproxy"));
- GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING);
- gridData.horizontalSpan = 4;
- proxyBt.setLayoutData(gridData);
-
- proxyBt.addSelectionListener(new SelectionListener() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- if (proxyBt.getSelection()) {
- proxyText.setEnabled(true);
- portText.setEnabled(true);
- } else {
- proxyText.setEnabled(false);
- portText.setEnabled(false);
- }
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
- });
-
- Label proxyLabel = new Label(composite, SWT.NONE);
- proxyLabel.setText(resources.getString("GenRootDlg.Label.Httpproxy"));
- proxyText = new Text(composite, SWT.SINGLE | SWT.BORDER | SWT.SEARCH);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- proxyText.setLayoutData(gridData);
- Label portLabel = new Label(composite, SWT.NONE);
- portLabel.setText(resources.getString("GenRootDlg.Label.Port"));
- portText = new Text(composite, SWT.SINGLE | SWT.BORDER | SWT.SEARCH);
-
- proxyBt.setSelection(false);
- proxyText.setEnabled(false);
- portText.setEnabled(false);
-
- String prefProxyHost = PreferencesManager.getHttpProxyHost();
- String prefProxyPort = PreferencesManager.getHttpProxyPort();
+
+ private void createSelectSnapshotComposite(Composite parent) {
- if (!prefProxyHost.isEmpty()) {
- proxyText.setText(prefProxyHost);
- }
+ Group group = new Group(parent, SWT.NONE);
+ group.setLayout(new GridLayout(1, false));
+ group.setText(resources.getString("GenRootDlg.Group.Snapshot"));
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ group.setLayoutData(gridData);
- if (!prefProxyPort.isEmpty()) {
- portText.setText(prefProxyPort);
- }
- }
+ createSnapshotUrlComposite(group);
+ createArchitectureComposite(group);
+ }
+
private void createSettingRepoComposite(Composite parent) {
GridData gridData = new GridData(GridData.FILL_BOTH);
group.setLayoutData(gridData);
- createHttpProxyComposite(group);
- createSnapshotUrlComposite(group);
createTreeViewer(group);
-
}
- private void createTreeViewer(Composite parent) {
-
- Composite composite1 = new Composite(parent, SWT.NONE);
- composite1.setLayout(new GridLayout(1, false));
- GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- gridData.minimumWidth = 300;
- gridData.minimumHeight = 300;
- composite1.setLayoutData(gridData);
-
- Composite composite = new Composite(composite1, SWT.NONE);
- composite.setLayout(new FillLayout());
- gridData = new GridData(GridData.FILL_BOTH);
- composite.setLayoutData(gridData);
-
- treeViewer = new CheckboxTreeViewer(composite, SWT.BORDER | SWT.H_SCROLL);
- Tree tree = treeViewer.getTree();
- tree.setHeaderVisible(true);
- tree.setLinesVisible(true);
- TreeColumn column = new TreeColumn(tree, SWT.LEFT);
- column.setText(resources.getString("GenRootDlg.Tree.Column.0"));
- column.setWidth(300);
-
- treeViewer.setLabelProvider(new RootstrapLabelProvider());
- treeViewer.setContentProvider(new RootstrapContentProvider());
-
- treeViewer.addCheckStateListener(new ICheckStateListener() {
-
- @Override
- public void checkStateChanged(CheckStateChangedEvent event) {
- if (event.getElement() instanceof ICheckTreeItem) {
- ICheckTreeItem changedItem = (ICheckTreeItem) event.getElement();
- if( event.getChecked()) {
- changedItem.setChecked(true);
- } else {
- changedItem.setChecked(false);
- }
- }
- treeViewer.refresh();
- }
- });
-
- treeViewer.setCheckStateProvider( new ICheckStateProvider() {
-
- @Override
- public boolean isChecked(Object element) {
- if (element instanceof ICheckTreeItem) {
- ICheckTreeItem item = (ICheckTreeItem) element;
- return item.isChecked();
- }
- return false;
- }
-
- @Override
- public boolean isGrayed(Object element) {
- if (element instanceof ICheckTreeItem) {
- ICheckTreeItem item = (ICheckTreeItem) element;
- return item.isGrayed();
- }
- return false;
- }
-
- });
- }
private void createSnapshotUrlComposite(Composite parent) {
Composite snapshotComp = new Composite(parent, SWT.NONE);
snapshotComp.setLayoutData(gridData);
Label snapshotLabel = new Label(snapshotComp, SWT.NONE);
+ gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
+ gridData.widthHint = 100;
+ snapshotLabel.setLayoutData(gridData);
+ snapshotLabel.setAlignment(SWT.RIGHT);
snapshotLabel.setText(resources.getString("GenRootDlg.Label.SnapshotURL"));
snapshotUrlText = new Text(snapshotComp, SWT.SINGLE | SWT.BORDER);
public void mouseDown(MouseEvent e) {
final String snapshotUrl = snapshotUrlText.getText().trim();
- final String proxyUrl = proxyText.getText().trim().replaceAll("http://", "");
- final String proxyPort = portText.getText().trim();
- final String rootstrapName = rootstrapText.getText().trim();
- final boolean proxySelected = proxyBt.getSelection();
- int p = 0;
-
- final SnapshotURLParser c = new SnapshotURLParser();
if (snapshotUrl.isEmpty()) {
DialogUtil.openErrorDialog(resources.getString("GenRootDlg.Error.Empty.Snapshot"));
return;
}
- if (rootstrapName.isEmpty()) {
- DialogUtil.openErrorDialog(resources.getString("GenRootDlg.Error.Empty.Rootstrap"));
- return;
- }
- /*
- for (ICheckTreeItem i : RootstrapManager.getRootstraps()) {
- if (i == null) {
- break;
- }
- if (i.getText().equals(rootstrapName)) {
- DialogUtil.openErrorDialog("Rootstrap name ["+rootstrapName+"] exists");
- return;
- }
- }
- */
- if (proxySelected) {
- if (proxyUrl.isEmpty()) {
- DialogUtil.openErrorDialog(resources.getString("GenRootDlg.Error.Empty.Proxy"));
- return;
- }
-
-
- if (!proxyPort.isEmpty()) {
- try {
- p = Integer.parseInt(proxyPort);
- } catch(java.lang.NumberFormatException e1) {
- e1.printStackTrace();
- DialogUtil.openErrorDialog(resources.getString("GenRootDlg.Error.Format.Proxy"));
- return;
- }
- }
- }
-
- final int port = p;
-
- try {
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
-
-
+ try {
dialog.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
- InterruptedException {
- monitor.beginTask(resources.getString("GenRootDlg.Progress.Msg.Searching"), -1);
- try {
- if (proxySelected) {
- rootstrap = c.parse(rootstrapName, snapshotUrl, proxyUrl, port);
- } else {
- rootstrap = c.parse(rootstrapName, snapshotUrl);
- }
- } catch (final MalformedURLException e) {
- e.printStackTrace();
- SWTUtil.getDisplay().asyncExec( new Runnable() {
- @Override
- public void run() {
- DialogUtil.openErrorDialog(e.toString());
- }
- });
- } catch (final FileNotFoundException e) {
- e.printStackTrace();
- SWTUtil.getDisplay().asyncExec( new Runnable() {
- @Override
- public void run() {
- DialogUtil.openErrorDialog(e.toString());
- }
- });
- } catch (final IOException e) {
- e.printStackTrace();
- SWTUtil.getDisplay().asyncExec( new Runnable() {
- @Override
- public void run() {
- DialogUtil.openErrorDialog(e.toString());
- }
- });
- }
+ InterruptedException {
+ monitor.beginTask(resources.getString("GenRootDlg.Progress.Msg.Searching"), -1);
+ try {
+ final SnapshotURLParser c = new SnapshotURLParser();
+ snapshotInfos = c.parse(snapshotUrl);
+ } catch (final IOException e) {
+ e.printStackTrace();
+ SWTUtil.getDisplay().asyncExec( new Runnable() {
+ @Override
+ public void run() {
+ DialogUtil.openErrorDialog(e.toString());
+ }
+ });
+ }
}
});
} catch (Exception e1) {
e1.printStackTrace();
+ DialogUtil.openErrorDialog(e.toString());
+ return;
}
- if (rootstrap == null) {
+ if (snapshotInfos == null || snapshotInfos.size() == 0 ) {
return;
}
- rootstrap.setChecked(true);
- treeViewer.setInput(rootstrap.getChildren());
- treeViewer.expandAll();
- treeViewer.refresh();
+ // add architecture list
+ archCombo.removeAll();
+ for ( ICheckTreeItem item: snapshotInfos ) {
+ archCombo.add(item.getText());
+ }
+ archCombo.setEnabled(true);
+ archCombo.select(0);
+
+ // Update repository table
+ UpdateRepositoryURL();
}
@Override
});
}
+
+
+ private void createArchitectureComposite(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(2, false));
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ composite.setLayoutData(gridData);
- @Override
- protected void okPressed() {
- super.okPressed();
+ Label archLabel = new Label(composite, SWT.NONE);
+ gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
+ gridData.widthHint = 100;
+ archLabel.setLayoutData(gridData);
+ archLabel.setAlignment(SWT.RIGHT);
+ archLabel.setText(resources.getString("GenRootDlg.Label.Architecture"));
+
+ archCombo = new Combo(composite, SWT.READ_ONLY);
+ gridData = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
+ gridData.minimumHeight = 0;
+ archCombo.setLayoutData(gridData);
+ archCombo.addSelectionListener( new SelectionListener(){
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ UpdateRepositoryURL();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ });
+ archCombo.setEnabled(false);
}
+
+ private void UpdateRepositoryURL() {
+ int selectIdx = archCombo.getSelectionIndex();
+ // show repository URLs
+ ArrayList<String> data = new ArrayList<String>();
+ ArrayList<ICheckTreeItem> children = snapshotInfos.get(selectIdx).getChildren();
+ for ( int idx = 0; idx < children.size(); idx++ ) {
+ data.add(String.format("url%d|%s", idx, children.get(idx).getText() ) );
+ }
+ reposURLViewer.setInput(data);
+ }
- private ArrayList<ICheckTreeItem> getSelectedArchs() {
- ArrayList<ICheckTreeItem> selectedArchs = new ArrayList<ICheckTreeItem>();
- for (ICheckTreeItem r : rootstrap.getChildren()) {
- if (r.isChecked()) {
- ArrayList<ICheckTreeItem> selectedSnapshots = new ArrayList<ICheckTreeItem>();
- for (ICheckTreeItem r1 : r.getChildren()) {
- if (r1.isChecked()) {
- selectedSnapshots.add(new Snapshot(r1.getText()));
- }
- }
- selectedArchs.add(new Architecture(r.getText(), selectedSnapshots));
- }
+
+ private void createTreeViewer(Composite parent) {
+
+ reposURLViewer = new TableViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
+ Table table = reposURLViewer.getTable();
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+ reposURLViewer.setLabelProvider(new TableViewerProvider());
+ reposURLViewer.setContentProvider(new ArrayContentProvider());
+
+ TableColumn column = new TableColumn(table, SWT.NONE);
+ column.setResizable(true);
+ column.setText(resources.getString("GenRootDlg.Tree.Column.Name"));
+ column.setWidth(50);
+
+ column = new TableColumn(table, SWT.NONE);
+ column.setResizable(true);
+ column.setText(resources.getString("GenRootDlg.Tree.Column.URL"));
+ column.setWidth(300);
+
+ GridData tableGridData = new GridData(GridData.FILL_HORIZONTAL|GridData.VERTICAL_ALIGN_BEGINNING);
+ tableGridData.heightHint = 200;
+ table.setLayoutData(tableGridData);
+
+ reposURLViewer.setInput(new ArrayList<ICheckTreeItem>());
+ }
+
+
+ @Override
+ protected void okPressed() {
+ rootstrapName = rootstrapText.getText().trim();
+ if (rootstrapName.isEmpty()) {
+ DialogUtil.openErrorDialog(resources.getString("GenRootDlg.Error.Empty.Rootstrap"));
+ return;
}
- return selectedArchs;
+ if ( RootstrapManager.getRootstrap(rootstrapName ) != null ) {
+ DialogUtil.openErrorDialog("Rootstrap name ["+rootstrapName+"] already exists!");
+ return;
+ }
+ architecture = archCombo.getText().trim();
+ repositoryURLs = new ArrayList<String>();
+ for ( TableItem item: reposURLViewer.getTable().getItems() ) {
+ repositoryURLs.add(item.getText(COL_REPOS_URL));
+ }
+ isImmediateGenerateChecked = generateImmediateBt.getSelection();
+ super.okPressed();
+ }
+
+
+ public PlatformRootstrap getGeneratedRootstrap() {
+ return generatedRootstrap;
+ }
+
+
+ public String getRootstrapName() {
+ return rootstrapName;
+ }
+
+
+
+ public String getArchitecture() {
+ return architecture;
}
- protected void createButtonsForButtonBar(Composite parent)
+
+ public ArrayList<String> getRepositoryURLs() {
+ return repositoryURLs;
+ }
+
+ public boolean isImmediateGenerateChecked() {
+ return isImmediateGenerateChecked;
+ }
+
+
+ private class TableViewerProvider extends LabelProvider implements ITableLabelProvider
{
- createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, true);
+ @Override
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ @Override
+ public String getColumnText(Object element, int columnIndex) {
+ String strData = (String)element;
+
+ switch(columnIndex) {
+ case COL_REPOS_NAME:
+ return strData.split("[|]")[COL_REPOS_NAME];
+ case COL_REPOS_URL:
+ return strData.split("[|]")[COL_REPOS_URL];
+ default:
+ return "";
+ }
+ }
}
+
}
View.Contextmenu.Export = Export
GenRootDlg.Title = Generate Rootstrap Dialog
-GenRootDlg.Label.Rootstrapname = Rootstrap Name :
-GenRootDlg.Label.Httpproxy = HTTP Proxy :
-GenRootDlg.Label.Port = Port :
+GenRootDlg.Label.Rootstrapname = Rootstrap Name :
+
+GenRootDlg.Group.Snapshot = Snapshot
GenRootDlg.Label.SnapshotURL = Snapshot URL :
-GenRootDlg.Button.Httpproxy = HTTP Proxy
-GenRootDlg.Button.Generate = Generate
GenRootDlg.Button.Search = Search
-GenRootDlg.Progress.Msg.Generating = Generating rootstraps
+GenRootDlg.Label.Architecture = Architecture :
+
+GenRootDlg.Group.Repos = Repository URL
+GenRootDlg.Tree.Column.Name = Name
+GenRootDlg.Tree.Column.URL = Repository URL
+
+GenRootDlg.Button.GenImmedate = Generate Immediately
+
+GenRootDlg.Progress.Msg.Generating = Generating rootstrap...
GenRootDlg.Progress.Msg.Searching = Seaching repositories
GenRootDlg.Error.Fail.Generate = Failed to generate rootstrap
GenRootDlg.Error.Empty.Snapshot = Snapshot URL is empty
GenRootDlg.Error.Empty.Rootstrap = Rootstrap is empty
-GenRootDlg.Error.Empty.Proxy = HTTP Proxy is empty
-GenRootDlg.Error.Format.Proxy = Proxy port should be number format
-
-GenRootDlg.Group.Repos = Setting architecture and repository for rootstrap
-GenRootDlg.Tree.Column.0 = Select architectures and repositories
SelectRootDlg.Title = Warning
SelectRootDlg.Msg.LastOne = "%s [%s]" rootstrap is the last one. You can not remove it
SelectRootDlg.Label.Desc = Follow projects use "%s" rootstrap.\nYou should set other rootstraps if you want to remove "%s" rootstrap
+
+Action.Msg.Error.RemoveDefault = Cannot remove basic rootstrap!
\ No newline at end of file
package org.tizen.nativeplatform.views.ui;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map.Entry;
import java.util.ResourceBundle;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.tizen.nativeplatform.pkgmgr.ui.RPMPackageDialog;
import org.tizen.nativeplatform.rootstrap.IRootstrapChangedListener;
import org.tizen.nativeplatform.views.model.PlatformRootstrap;
-import org.tizen.nativeplatform.views.provider.RootstrapContentProvider;
-import org.tizen.nativeplatform.views.provider.RootstrapLabelProvider;
import org.tizen.nativeplatform.rootstrap.RootstrapManager;
public class RootstrapView extends ViewPart {
private ToolBar toolBar;
- private TreeViewer treeViewer;
private TableViewer tableViewer;
private Action actionSetDefault;
private Action actionExport;
private MenuManager menuMgr;
+ private PlatformRootstrap generatedRootstrap;
+
private IProject project;
-
private Shell shell;
- private Display display;
private static final String PLATFORM_PERSPECTIVE_ID = "org.tizen.nativeplatform.perspective";
public void createPartControl(Composite parent) {
shell = this.getViewSite().getShell();
- display = this.getViewSite().getShell().getDisplay();
RootstrapManager.addListener(cListener);
CoreModel.getDefault().addCProjectDescriptionListener(prjListner,
bottom.setLayoutData(new GridData(GridData.FILL_BOTH));
bottom.setLayout(new FillLayout());
- //createTreeViewer(bottom);
createRootstrapTableComposite(bottom);
makeActions();
@Override
public void setFocus() {
- // TODO Auto-generated method stub
-
}
private void createToolBar(Composite parent, Object layoutData)
refresh.setEnabled(true);
}
- private void createTreeViewer(Composite parent) {
-
- parent.setLayout(new FillLayout());
- treeViewer = new TreeViewer(parent, SWT.MULTI | SWT.FULL_SELECTION);
- Tree tree = treeViewer.getTree();
- tree.setHeaderVisible(true);
- treeViewer.setLabelProvider(new RootstrapLabelProvider());
- treeViewer.setContentProvider(new RootstrapContentProvider());
-
- TreeColumn column = new TreeColumn(tree, SWT.LEFT);
- column.setText("Rootstraps");
- column.setWidth(300);
-
- treeViewer.setInput(RootstrapManager.getRootstraps());
- }
private void showAddDialog() {
AddRootstrapDialog dlg = new AddRootstrapDialog(shell);
- dlg.open();
+ if ( dlg.open() == AddRootstrapDialog.OK ) {
+ final String rootstrapName = dlg.getRootstrapName();
+ final String arch = dlg.getArchitecture();
+ final ArrayList<String> repositoryURLs = dlg.getRepositoryURLs();
+ final boolean immediateGen = dlg.isImmediateGenerateChecked();
+
+ // generate rootstrap here
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
+ try {
+ dialog.run(true, true, new IRunnableWithProgress() {
+ @Override
+ public void run(IProgressMonitor monitor) throws InvocationTargetException,
+ InterruptedException {
+ monitor.beginTask(resources.getString("GenRootDlg.Progress.Msg.Generating"), -1);
+ generatedRootstrap = null;
+ generatedRootstrap = RootstrapManager.generate(rootstrapName, arch, repositoryURLs, immediateGen);
+ if ( generatedRootstrap == null ) {
+ throw new InterruptedException();
+ }
+ }
+ });
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ DialogUtil.openErrorDialog(resources.getString("GenRootDlg.Progress.Msg.Generating") );
+ return;
+ }
+
+ RootstrapManager.addRootstrap( generatedRootstrap );
+ }
}
+
private void refresh() {
try {
SBIModel.reinitialize();
@Override
public void widgetSelected(SelectionEvent e) {
- Color selectedColor = display.getSystemColor(SWT.COLOR_LIST_SELECTION);
- TableItem item = (TableItem)e.item;
- //item.setBackground(selectedColor);
}
@Override
TableItem[] item = table.getSelection();
PlatformRootstrap selected = (PlatformRootstrap)item[0].getData();
if (project != null) {
- String rootId = selected.getId();
- IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
- IConfiguration config = info.getDefaultConfiguration();
- String targetId = PlatformConfigurationManager.getBuildTargetName(config);
- SmartBuildInterface sbi = SmartBuildInterface.getInstance();
- String toolId = sbi.getToolchainIDFromTargetID(targetId);
- String newTargetId = SmartBuildInterface.makeTargetID(rootId, toolId);
- try {
- if (!sbi.checkTargetID(newTargetId)) {
- sbi.writeTargetCfgFile(newTargetId);
- }
- } catch (SBIException e) {
- e.printStackTrace();
- }
- PlatformConfigurationManager.setBuildTargetName(config, newTargetId);
- RootstrapManager.setSelectedRootstrap(selected);
- RootstrapManager.notifyChangedRootstrap();
-
- ManagedBuildManager.saveBuildInfo( project, true );
+ setActiveRootstrap( project, selected );
}
-
}
@Override
});
}
+
+ private void setActiveRootstrap(IProject project, PlatformRootstrap rootstrap ) {
+ String rootId = rootstrap.getId();
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
+ IConfiguration config = info.getDefaultConfiguration();
+ String targetId = PlatformConfigurationManager.getBuildTargetName(config);
+ SmartBuildInterface sbi = SmartBuildInterface.getInstance();
+ String toolId = sbi.getToolchainIDFromTargetID(targetId);
+ String newTargetId = SmartBuildInterface.makeTargetID(rootId, toolId);
+ try {
+ if (!sbi.checkTargetID(newTargetId)) {
+ sbi.writeTargetCfgFile(newTargetId);
+ }
+ } catch (SBIException e) {
+ e.printStackTrace();
+ }
+ PlatformConfigurationManager.setBuildTargetName(config, newTargetId);
+ RootstrapManager.setSelectedRootstrap(rootstrap);
+ RootstrapManager.notifyChangedRootstrap();
+
+ ManagedBuildManager.saveBuildInfo( project, true );
+ }
+
+
public void selectionPkgMgr()
{
doActionForEntry(new IActionForEntry()
});
}
+
public void removeRootstrap()
{
doActionForEntry(new IActionForEntry()
Table table = tableViewer.getTable();
TableItem[] item = table.getSelection();
PlatformRootstrap selected = (PlatformRootstrap)item[0].getData();
- String rootName = selected.getName();
- String rootArch = selected.getArch();
- HashMap<Integer, HashMap<IProject, IConfiguration>> projectMap = new HashMap<Integer, HashMap<IProject, IConfiguration>>();
+ // default rootstrap cannot be removed!
+ PlatformRootstrap defaultRootstrap = RootstrapManager.getDefaultRootstrap( selected.getArch() );
+ if ( defaultRootstrap.getId().equals(selected.getId()) ) {
+ DialogUtil.openMessageDialog(resources.getString("Action.Msg.Error.RemoveDefault"));
+ return;
+ }
+
IWorkspace works = ResourcesPlugin.getWorkspace();
IProject[] projs = works.getRoot().getProjects();
- int i = 0;
for (final IProject proj : projs) {
- IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(proj);
- if( info == null) {
- continue;
- }
-
- IConfiguration cfg = info.getDefaultConfiguration();
- if( cfg == null) {
- continue;
- }
-
- for( IConfiguration config: cfg.getManagedProject().getConfigurations() ) {
- String targetId = PlatformConfigurationManager.getBuildTargetName(config);
- String rootstrapId = SmartBuildInterface.getInstance().getRootstrapIDFromTargetID(targetId);
- IManagedProject managedProject = config.getManagedProject();
- if( managedProject == null) {
- continue;
- }
- String projectArtifactType = managedProject.getProjectType() != null ? managedProject.getProjectType().getBuildArtefactType().getId() : null;
- if (projectArtifactType != null &&
- projectArtifactType.equals(PlatformConfigurationManager.TIZEN_PLATFORM_ARTIFACT_TYPE) &&
- rootstrapId.equals(selected.getId())) {
- HashMap<IProject, IConfiguration> map = new HashMap<IProject, IConfiguration>();
- map.put(proj, config);
- projectMap.put(new Integer(i), map);
- i++;
- }
- }
+ setActiveRootstrap( proj, defaultRootstrap );
}
- ArrayList<PlatformRootstrap> list = getRootstrapList(rootName, rootArch);
- if (list.isEmpty()) {
-
- DialogUtil.openMessageDialog(String.format(resources.getString("SelectRootDlg.Msg.LastOn"), rootName, rootArch));
- }
- SelectRootstrapMappingDialog dlg = new SelectRootstrapMappingDialog(shell, selected.getName(), projectMap, list);
- dlg.open();
-
- for (Entry<Integer, HashMap<IProject, IConfiguration>> e : projectMap.entrySet()) {
- for (Entry<IProject, IConfiguration> _e : e.getValue().entrySet()) {
- IProject project = _e.getKey();
- ManagedBuildManager.saveBuildInfo( project, true );
- }
- }
-
+ // remove
+ RootstrapManager.removeRootstrap(selected.getId());
}
@Override
});
}
- private ArrayList<PlatformRootstrap> getRootstrapList(String rootName, String arch) {
- ArrayList<PlatformRootstrap> list = new ArrayList<PlatformRootstrap>();
- boolean isEmulatorArch = PlatformConfigurationManager.isEmulatorArch(arch);
- boolean isDeviceArch = PlatformConfigurationManager.isDeviceArch(arch);
-
- for (PlatformRootstrap r : RootstrapManager.getRootstraps()) {
- if (isEmulatorArch && PlatformConfigurationManager.isEmulatorArch(r.getArch()) &&
- !rootName.equals(r.getName())) {
- list.add(r);
- } else if (isDeviceArch && PlatformConfigurationManager.isDeviceArch(r.getArch()) &&
- !rootName.equals(r.getName())) {
- list.add(r);
- }
- }
-
- return list;
- }
public void doActionForEntry(IActionForEntry action)
{