From 104c60cdaf7f29e8065bd0a4ccafbcde5008971d Mon Sep 17 00:00:00 2001 From: "yongsung1.kim" Date: Mon, 31 Mar 2014 16:54:48 +0900 Subject: [PATCH] [INST] Installmanager can support repository history.(max 5) Conflicts: InstallManager_java/src/org/tizen/installmanager/core/InstallManager.java InstallManager_java/src/org/tizen/installmanager/lib/ErrorController.java Change-Id: I332d385112e6f13643f4219c9360f8f46d389a17 Signed-off-by: yongsung1.kim --- .../tizen/installmanager/core/InstallManager.java | 5 +- .../tizen/installmanager/lib/ErrorController.java | 3 +- .../src/org/tizen/installmanager/lib/Registry.java | 79 +++++++++++- .../ui/dialog/ChangeServerDialog.java | 64 ++++++++-- .../ui/dialog/ConfigurationDialog.java | 141 ++++++++++++++++++--- 5 files changed, 256 insertions(+), 36 deletions(-) diff --git a/InstallManager_java/src/org/tizen/installmanager/core/InstallManager.java b/InstallManager_java/src/org/tizen/installmanager/core/InstallManager.java index af88e58..26f17cd 100644 --- a/InstallManager_java/src/org/tizen/installmanager/core/InstallManager.java +++ b/InstallManager_java/src/org/tizen/installmanager/core/InstallManager.java @@ -109,7 +109,8 @@ public class InstallManager { * Load config file */ public void initConfig() { - if (mConfig != null) { + if (mConfig != null) { + Registry.saveRepoInfo(mConfig.getConfigFile().getRepository()); if (Config.isSupportMultiSDK()) { if (!Registry.getInstalledPath().isEmpty()) { mConfig.setTargetDir(Registry.getInstalledPath()); @@ -119,7 +120,7 @@ public class InstallManager { } } else { mConfig = Config.getInstance(); - + Registry.saveRepoInfo(mConfig.getConfigFile().getRepository()); if (Options.doReplaceRepository) { Log.log("Replace repository => " + Options.repository); mConfig.getConfigFile().setRepository(Options.repository); diff --git a/InstallManager_java/src/org/tizen/installmanager/lib/ErrorController.java b/InstallManager_java/src/org/tizen/installmanager/lib/ErrorController.java index 245dc8c..648ffcc 100644 --- a/InstallManager_java/src/org/tizen/installmanager/lib/ErrorController.java +++ b/InstallManager_java/src/org/tizen/installmanager/lib/ErrorController.java @@ -156,7 +156,8 @@ public class ErrorController { SNAPSHOT_PATH_IS_NULL("Snapshot path missing."), FAIL_TO_EXTRACT_SDK_IMAGE_FILE("SDK image file extraction failed."), - //Using add extra repository dialog + //Using add extra repository dialog + INVALID_REPOSITORY_FOR_HISTORY("Invalid repository for history."), SPACE_IN_REPOSITORY_NAME("Name cannot contain spaces."), NOTHING_TO_REPOSITORY_NAME("Name must be more than 1 character long."), HANGUL_IN_REPOSITORY_NAME("Repository name must be in English."), diff --git a/InstallManager_java/src/org/tizen/installmanager/lib/Registry.java b/InstallManager_java/src/org/tizen/installmanager/lib/Registry.java index b0bd66c..1b966f9 100644 --- a/InstallManager_java/src/org/tizen/installmanager/lib/Registry.java +++ b/InstallManager_java/src/org/tizen/installmanager/lib/Registry.java @@ -37,6 +37,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Collections; import org.tizen.installmanager.core.Config; import org.tizen.installmanager.core.IMFatalException; @@ -55,12 +56,15 @@ public class Registry { //installed path. public static final String REGISTRY_FILE_NAME = "tizensdkpath"; public static final String MULTI_SDK_FILE_NAME = "multisdkpath"; + public static final String REPO_HISTORY_FILE_NAME = "repo.history"; public static final String REGISTRY_FILE_PATH = PathUtil.get( Config.INSTALL_MANAGER_CONFIG, REGISTRY_FILE_NAME); private static final String OLD_REGISTRY_FILE_PATH = PathUtil.get( Config.getConfigHome(), REGISTRY_FILE_NAME); public static final String MULTI_SDK_FILE_PATH = PathUtil.get( Config.INSTALL_MANAGER_CONFIG, MULTI_SDK_FILE_NAME); + public static final String REPO_HISTORY_FILE_PATH = PathUtil.get( + Config.INSTALL_MANAGER_CONFIG, REPO_HISTORY_FILE_NAME); private static final String INSTALLED_PATH_KEY = "TIZEN_SDK_INSTALLED_PATH"; private static final String SDK_DATA_PATH_KEY = "TIZEN_SDK_DATA_PATH"; @@ -77,6 +81,8 @@ public class Registry { public static String sdkDataPath = ""; // public static String sdkDataPath = getSDKinfoBySDKPath(Config.getInstance().getTargetDir()); private static ArrayList sdkPathList = getSDKPath(); + private static ArrayList repoHistory = getRepoHistory(); + private final static int REPO_HISTORY_COUNT = 5; /** * Exports target path to the registry file. @@ -337,6 +343,15 @@ public class Registry { return sdkPath; } + public static ArrayList getRepoHistory() { + File repoHistoryFile = new File(REPO_HISTORY_FILE_PATH); + ArrayList repoHistory = new ArrayList(); + if (repoHistoryFile.exists()) { + repoHistory = getPathFromRegistryFile(REPO_HISTORY_FILE_PATH); + } + return repoHistory; + } + private static ArrayList getPathFromRegistryFile(String filePath) { ArrayList sdkPaths = new ArrayList(); InputStream is = null; @@ -449,7 +464,6 @@ public class Registry { if (bw != null) { try { bw.close(); - } catch (IOException e) { Log.ExceptionLog(e); } @@ -510,6 +524,69 @@ public class Registry { } } + public static void saveRepoInfo(String repository) { + if (repository == null || repository.isEmpty()) { + Log.err("Repository is invalid for registering : " + repository); + throw new IMFatalException(ErrorCode.INVALID_REPOSITORY_FOR_HISTORY); + } + + File repoHistoryFile = new File(REPO_HISTORY_FILE_PATH); + if (!repoHistoryFile.exists() || Options.doInstallNoUI || Options.doRemoveNoUI) { + try { + repoHistoryFile = PathUtil.makeNewFile(REPO_HISTORY_FILE_PATH); + } catch (IOException e) { + Log.ExceptionLog(e); + return; + } + } else { + if (repoHistory.contains(repository)) { + return; + } + } + + if (repoHistoryFile == null) { + return; + } + + removeOldHistory(); + + BufferedWriter bw = null; + try { + FileWriter fw = new FileWriter(repoHistoryFile); + bw = new BufferedWriter(fw); + if (!repoHistory.isEmpty()) { + for (String repo : repoHistory) { + if (!repo.equalsIgnoreCase("")) { + bw.write(repo); + bw.newLine(); + } + } + } + bw.write(repository); + bw.newLine(); + bw.flush(); + } catch (IOException e) { + Log.err("Cannot register to file. " + repoHistoryFile.getAbsolutePath()); + throw new IMFatalException(ErrorCode.CANNOT_REGISTER_TARGET_DIR); + } finally { + if (bw != null) { + try { + bw.close(); + repoHistory.add(repository); + Log.log("Package server address history. => " + repoHistory); + } catch (IOException e) { + Log.ExceptionLog(e); + } + } + } + } + + private static void removeOldHistory() { + while (repoHistory.size() >= REPO_HISTORY_COUNT) { + repoHistory.remove(0); + } + } + /** * Get installed version. * @return diff --git a/InstallManager_java/src/org/tizen/installmanager/ui/dialog/ChangeServerDialog.java b/InstallManager_java/src/org/tizen/installmanager/ui/dialog/ChangeServerDialog.java index 9d9565e..c42947c 100644 --- a/InstallManager_java/src/org/tizen/installmanager/ui/dialog/ChangeServerDialog.java +++ b/InstallManager_java/src/org/tizen/installmanager/ui/dialog/ChangeServerDialog.java @@ -1,17 +1,45 @@ +/* + * InstallManager + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Donghee Yang + * Shihyun Kim + * Yongsung kim + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + package org.tizen.installmanager.ui.dialog; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; import org.tizen.installmanager.core.Config; import org.tizen.installmanager.lib.Downloader; import org.tizen.installmanager.lib.ErrorController; @@ -20,10 +48,11 @@ import org.tizen.installmanager.util.PathUtil; public class ChangeServerDialog extends Dialog { private static final String STRING_TITLE = "Change Server"; private Label titleLabel = null; - private Text serverText = null; + private Combo serverCombo = null; private Label errLabel = null; private String serverUrl = ""; + private ArrayList serverUrls = new ArrayList(); public ChangeServerDialog(Shell parentShell) { super(parentShell); @@ -50,7 +79,7 @@ public class ChangeServerDialog extends Dialog { setTitle(); setTitleLabel(container); - setServerUrlText(container); + setServerUrlComboBox(container); setErrLabel(container); return container; @@ -58,9 +87,10 @@ public class ChangeServerDialog extends Dialog { @Override protected void okPressed() { - String changeServerUrl = serverText.getText(); + String changeServerUrl = serverCombo.getText(); - if (serverUrl.equals(changeServerUrl)) { + if (serverUrls.contains(changeServerUrl)) { + serverUrl = changeServerUrl; this.close(); } else { if (isExactFormat(changeServerUrl)) { @@ -84,16 +114,20 @@ public class ChangeServerDialog extends Dialog { titleLabel.setBounds(10, 10, 200, 23); } - private void setServerUrlText(Composite composite) { - serverText = new Text(composite, SWT.BORDER); - serverText.setBounds(10, 33, 360, 23); - serverText.setEnabled(true); + private void setServerUrlComboBox(Composite composite) { + serverCombo = new Combo(composite, SWT.NONE); + serverCombo.setBounds(10, 33, 360, 23); + serverCombo.setEnabled(true); - if (serverUrl.isEmpty()) { - serverText.setText("http://"); + if (serverUrls.isEmpty()) { + serverCombo.setText("http://"); } else { - serverText.setText(serverUrl); - serverText.selectAll(); + serverCombo.setText(serverUrl); + for (String url : serverUrls) { + if (url != null) { + serverCombo.add(url); + } + } } } @@ -143,6 +177,10 @@ public class ChangeServerDialog extends Dialog { serverUrl = url; } + public void setCurrentServer(ArrayList urls) { + serverUrls = urls; + } + public String getServerUrl() { return serverUrl; } diff --git a/InstallManager_java/src/org/tizen/installmanager/ui/dialog/ConfigurationDialog.java b/InstallManager_java/src/org/tizen/installmanager/ui/dialog/ConfigurationDialog.java index 02e913b..cc71b9f 100644 --- a/InstallManager_java/src/org/tizen/installmanager/ui/dialog/ConfigurationDialog.java +++ b/InstallManager_java/src/org/tizen/installmanager/ui/dialog/ConfigurationDialog.java @@ -30,6 +30,7 @@ package org.tizen.installmanager.ui.dialog; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; @@ -46,7 +47,6 @@ import org.eclipse.swt.events.MouseListener; 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.Point; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Button; @@ -60,15 +60,18 @@ 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.tizen.installmanager.core.Config; import org.tizen.installmanager.core.DistributionController; import org.tizen.installmanager.core.InstallManager; +import org.tizen.installmanager.core.InstallManagerConstants; import org.tizen.installmanager.core.Config.ServerType; import org.tizen.installmanager.core.IMFatalException; import org.tizen.installmanager.core.SnapshotLog; import org.tizen.installmanager.lib.Log; import org.tizen.installmanager.lib.ErrorController.ErrorCode; import org.tizen.installmanager.lib.Platform; +import org.tizen.installmanager.lib.Registry; import org.tizen.installmanager.pkg.lib.PackageManager; import org.tizen.installmanager.pkg.model.Snapshot; import org.tizen.installmanager.pkg.model.SnapshotList; @@ -87,6 +90,7 @@ public class ConfigurationDialog extends Dialog { private String snapshotPath = ""; private String currentDistribution = ""; private String repository = ""; + ArrayList repos = new ArrayList(); private ServerType serverType = ServerType.SNAPSHOT; private SnapshotLogDialog snapshotDialog = null; @@ -103,7 +107,6 @@ public class ConfigurationDialog extends Dialog { private Table snapshotTable; - private Label localErrLabel; private Label textPackageServerUrl; private Label textLocalServerUrl; private File imageFile; @@ -111,6 +114,14 @@ public class ConfigurationDialog extends Dialog { private DistributionController controller = null; private boolean noErr = true; // flag check to verify pkg list file path. + //patch support + private Button buttonPatch = null; + private Label labelPatch = null; + private Button buttonPatchSelection = null; + + private static final int IMAGE_FILE = 0; + private static final int PATCH_FILE = 1; + //snapshot table column public static final int TABLE_STATUS = 0; public static final int TABLE_NAME = 1; @@ -154,7 +165,11 @@ public class ConfigurationDialog extends Dialog { setLocalButton(container); setFileDialog(container); setLocalLabel(container); - setLocalErrorlabel(container); + +// setSeparator_02(container); +// setPatchButton(container); +// setPatchDialog(container); +// setPatchLabel(container); return container; } @@ -234,6 +249,14 @@ public class ConfigurationDialog extends Dialog { this.repository = serverUrl; } + public void setRepositories(ArrayList serverUrls) { + if (serverUrls == null || serverUrls.isEmpty()) { + return; + } + + this.repos = serverUrls; + } + /** * Change package server type by install type(normal, snapshot, local). * @param isConfDialog User push 'OK' button in configuration dialog is true, otherwise is false. @@ -342,7 +365,6 @@ public class ConfigurationDialog extends Dialog { buttonSelectImage.setEnabled(false); textLocalServerUrl.setEnabled(false); textLocalServerUrl.setText(""); - localErrLabel.setText(""); setOkEnable(false); } }); @@ -380,12 +402,16 @@ public class ConfigurationDialog extends Dialog { public void widgetSelected(SelectionEvent e) { ChangeServerDialog changeServerDialog = new ChangeServerDialog(composite.getShell()); changeServerDialog.setCurrentServer(repository); + changeServerDialog.setCurrentServer(Registry.getRepoHistory()); int ret = changeServerDialog.open(); if (ret == 0) { String changeServerUrl = changeServerDialog.getServerUrl(); if (!repository.equals(changeServerUrl)) { setPackageServerEnv(changeServerUrl); } + if (!Registry.getRepoHistory().contains(changeServerUrl)) { + Registry.saveRepoInfo(changeServerUrl); + } } else { Log.log("Change server dialog is canceled."); } @@ -559,7 +585,6 @@ public class ConfigurationDialog extends Dialog { buttonLocal.setSelection(false); textLocalServerUrl.setEnabled(false); textLocalServerUrl.setText(""); - localErrLabel.setText(""); buttonSelectImage.setEnabled(false); setOkEnable(true); @@ -736,7 +761,6 @@ public class ConfigurationDialog extends Dialog { public void widgetSelected(SelectionEvent e) { textLocalServerUrl.setEnabled(true); buttonSelectImage.setEnabled(true); - localErrLabel.setEnabled(true); distributionCombo.setEnabled(false); buttonChangeServer.setEnabled(false); @@ -776,10 +800,9 @@ public class ConfigurationDialog extends Dialog { Log.log("SDK image File selection => " + strDir); if (strDir.endsWith(SDK_IMAGE_ZIP_EXTENSION)) { imageFile = new File(strDir); - if (validation(strDir)) { + if (validation(strDir, IMAGE_FILE)) { Log.log("Package list file found in SDK image => " + strDir); textLocalServerUrl.setText(strDir); - localErrLabel.setText(""); UNZIP_RESULT unzipResult = unzipSDKImageFile(imageFile); if (checkUnzip(unzipResult)) { setOkEnable(true); @@ -828,7 +851,7 @@ public class ConfigurationDialog extends Dialog { } @SuppressWarnings("unused") - private boolean validation(String strDir) { + private boolean validation(String strDir, int fileStyle) { ZipFile zipFile = null; ZipEntry entry = null; @@ -841,10 +864,24 @@ public class ConfigurationDialog extends Dialog { } if (zipFile != null) { - String packageList = PackageManager.getInstance().getPackageListFileName(); - Log.log("This platform must have package list file as '" + packageList + "'"); - - entry = zipFile.getEntry(packageList); + if (fileStyle == IMAGE_FILE) { + String packageList = PackageManager.getInstance().getPackageListFileName(); + Log.log("This platform must have package list file as '" + packageList + "'"); + + entry = zipFile.getEntry(packageList); + } else if (fileStyle == PATCH_FILE) { + String scriptFile = InstallManagerConstants.SDK_PATCH_SCRIPT; + Log.log("Patch must have execute script file as '" + scriptFile + "'"); + + entry = zipFile.getEntry(scriptFile); + } else { + try { + zipFile.close(); + } catch (IOException e) { + Log.ExceptionLog(e); + } + return false; + } try { zipFile.close(); @@ -857,12 +894,6 @@ public class ConfigurationDialog extends Dialog { return false; } } - - private void setLocalErrorlabel(Composite composite) { - localErrLabel = new Label(composite, SWT.WRAP); - localErrLabel.setBounds(20, 343, 475, 45); - localErrLabel.setForeground(new Color(null, 255, 0, 0)); - } /** * Show file path dialog when file dialog button is pushed. @@ -881,6 +912,78 @@ public class ConfigurationDialog extends Dialog { return strDir; } + + private void setSeparator_02(Composite composite) { + Label sep = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); + sep.setBounds(10, 348, 560, 1); + } + + private void setPatchButton(Composite composite) { + buttonPatch = new Button(composite, SWT.RADIO); + buttonPatch.setSelection(false); + buttonPatch.setBounds(10, 358, 350, 18); + buttonPatch.setText("SDK patch"); + + buttonPatch.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + textLocalServerUrl.setEnabled(true); + buttonPatchSelection.setEnabled(true); + + distributionCombo.setEnabled(false); + buttonChangeServer.setEnabled(false); + buttonSnapshotFilter.setEnabled(false); + buttonSelectImage.setEnabled(false); + setOkEnable(false); + + snapshotPath = ""; + } + }); + } + + private void setPatchDialog(Composite composite) { + buttonPatchSelection = new Button(composite, SWT.NONE); + buttonPatchSelection.setEnabled(false); + buttonPatchSelection.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + String strDir = showSettingPatchpathDlg(); + if (strDir != null) { + Log.log("Success to open SDK patch selection file dialog."); + Log.log("SDK patch file selection => " + strDir); + if (strDir.endsWith(SDK_IMAGE_ZIP_EXTENSION)) { + + } + } + } + }); + + buttonPatchSelection.setImage(PathUtil.getImageFromResource("/res/icons/icon_directory_open.png")); + if (!Platform.isMacOS()) { + buttonPatchSelection.setBounds(520, 381, 35, 29); + } else { + buttonPatchSelection.setBounds(525, 380, 40, 31); + } + } + + private void setPatchLabel(Composite composite) { + labelPatch = new Label(composite, SWT.BORDER); + labelPatch.setBounds(10, 386, 500, 20); + labelPatch.setEnabled(false); + } + + private String showSettingPatchpathDlg() { + FileDialog dlg = new FileDialog(Display.getCurrent().getShells()[0]); + dlg.setText("Select the SDK patch file."); + String strDir = null; + try { + strDir = dlg.open(); + } catch (SWTException e) { + Log.ExceptionLog(e); + } + + return strDir; + } /** * Unzip SDK ImageFile. -- 2.7.4