From d2e2348e06c7a6ef63e3d0865a5e90ff643aa545 Mon Sep 17 00:00:00 2001 From: Jihoon Song Date: Fri, 25 Oct 2013 15:40:51 +0900 Subject: [PATCH] [Title] common-eplugin: refactored project related codes. [Desc.] [Issue] Change-Id: I107a6a7b91cc61194ed90ab119f17480264a32a2 Signed-off-by: Jihoon Song --- .../tizen/common/ui/wizards/TizenCommonWizard.java | 23 +------ .../src/org/tizen/common/util/ProjectUtil.java | 75 ++++++++++++++-------- 2 files changed, 52 insertions(+), 46 deletions(-) diff --git a/org.tizen.common.ui/src/org/tizen/common/ui/wizards/TizenCommonWizard.java b/org.tizen.common.ui/src/org/tizen/common/ui/wizards/TizenCommonWizard.java index cfc0dd0..8d01894 100644 --- a/org.tizen.common.ui/src/org/tizen/common/ui/wizards/TizenCommonWizard.java +++ b/org.tizen.common.ui/src/org/tizen/common/ui/wizards/TizenCommonWizard.java @@ -25,20 +25,15 @@ package org.tizen.common.ui.wizards; -import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExecutableExtension; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.tizen.common.ITizenProject; -import org.tizen.common.core.application.ProfileInfo; -import org.tizen.common.core.application.TizenProjectDescription; +import static org.slf4j.LoggerFactory.*; import org.tizen.common.ui.Activator; import org.tizen.common.util.ImageUtil; -import org.tizen.common.util.ProjectUtil; /** * Base wizard class for Tizen IDE. @@ -47,7 +42,8 @@ import org.tizen.common.util.ProjectUtil; * */ public class TizenCommonWizard extends BasicNewResourceWizard implements IExecutableExtension { - final Logger logger = LoggerFactory.getLogger(TizenCommonWizard.class); + + protected final Logger logger = getLogger( getClass() ); protected IConfigurationElement fConfigElement; @@ -70,17 +66,4 @@ public class TizenCommonWizard extends BasicNewResourceWizard implements IExecut public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { fConfigElement = config; } - - protected void createTizenProjectDescription(IProject project, ProfileInfo platformInfo) { - if (project == null) - throw new IllegalArgumentException("project can not be null"); - if (platformInfo == null) - throw new IllegalArgumentException("platformInfo can not be null"); - ITizenProject tizenPrj = ProjectUtil.getTizenProject(project); - if (tizenPrj != null) { - TizenProjectDescription desc = new TizenProjectDescription(project); - desc.setPlatform(platformInfo); - tizenPrj.setDescription(desc); - } - } } diff --git a/org.tizen.common/src/org/tizen/common/util/ProjectUtil.java b/org.tizen.common/src/org/tizen/common/util/ProjectUtil.java index 22d7824..233958b 100644 --- a/org.tizen.common/src/org/tizen/common/util/ProjectUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/ProjectUtil.java @@ -50,6 +50,7 @@ import org.tizen.common.ITizenProject; import org.tizen.common.ITizenProjectAdapter; import org.tizen.common.ITizenWebProject; import org.tizen.common.TizenProjectType; +import org.tizen.common.core.application.ProfileInfo; import org.tizen.common.core.application.TizenProjectDescription; /** @@ -231,16 +232,18 @@ public class ProjectUtil { /** * Returns {@link ITizenProject} object for the project. * @param project - * @return {@link ITizenProject} + * @return {@link ITizenProject}. If not found, return null. */ - public static ITizenProject getTizenProject(IProject project, Class adapter) { - if (project == null) - throw new IllegalArgumentException("Project can not be null"); - ITizenProject tizenProject = (ITizenProject) AdapterUtil.getAdapter(project, adapter); - if ( tizenProject == null ) { - logger.warn("cannot get adapter of " + project + " (adapterType - " + adapter + ")"); + public static ITizenProject getTizenProject(IProject project, Class adapter) { + Assert.notNull( project, "Project can not be null" ); + + Object tizenProject = AdapterUtil.getAdapter( project, adapter ); + if ( tizenProject instanceof ITizenProject ) { + return (ITizenProject) tizenProject; } - return tizenProject; + + logger.warn("cannot get adapter of " + project + " (adapterType - " + adapter + ")"); + return null; } /** @@ -285,31 +288,54 @@ public class ProjectUtil { /** * Returns {@link TizenProjectDescription} object for the given project. - * @return {@link TizenProjectDescription} + * @return {@link TizenProjectDescription}. If not found, return null. */ public static TizenProjectDescription getTizenProjectDescription(IProject project) { ITizenProject tizenProject = getTizenProject( project ); - if ( tizenProject == null ) { - return null; - } - TizenProjectDescription tizenDesc = tizenProject.getDescription(); - if ( tizenDesc == null ) { - return null; + return ( tizenProject == null ) ? null : tizenProject.getDescription(); + } + + /** + * Create a Tizen project description (.tproject) + * + * @param project current project + * @param platformInfo + * @return If the project is a Tizen project and the creation succeed, return true. + */ + public static boolean createTizenProjectDescription(IProject project, ProfileInfo platformInfo) { + Assert.notNull( project, "project can not be null" ); + Assert.notNull( project, "platformInfo can not be null" ); + + ITizenProject tizenPrj = getTizenProject( project ); + if ( tizenPrj != null ) { + TizenProjectDescription tPrjDesc = new TizenProjectDescription( project ); + tPrjDesc.setPlatform( platformInfo ); + + return tizenPrj.setDescription( tPrjDesc ); } - return tizenDesc; + + return false; } /** + * Returns {@link TizenProjectType} object for the given project. + * @param project + * @param adapter + * @return {@link TizenProjectType}. If not found, return null. + */ + public static TizenProjectType getTizenProjectType(IProject project, Class adapter) { + ITizenProject tProject = getTizenProject( project, adapter ); + return ( tProject == null ) ? null : tProject.getTizenProjectType(); + } + + /** * Checks whether project is for Tizen native or not. * @param project * @return {@code true} if it is Tizen native project */ public static boolean isTizenNativeProject(IProject project) { - ITizenProject adapter = getTizenProject(project, ITizenNativeProject.class); - if ( adapter == null ) { - return false; - } - return (adapter.getTizenProjectType() == null) ? false : adapter.getTizenProjectType().isNativeProject(); + TizenProjectType type = getTizenProjectType( project, ITizenNativeProject.class ); + return ( type == null ) ? false : type.isNativeProject(); } /** @@ -318,11 +344,8 @@ public class ProjectUtil { * @return {@code true} if it is Tizen web project */ public static boolean isTizenWebProject(IProject project) { - ITizenProject adapter = getTizenProject(project, ITizenWebProject.class); - if ( adapter == null ) { - return false; - } - return (adapter.getTizenProjectType() == null) ? false : adapter.getTizenProjectType().isWebProject(); + TizenProjectType type = getTizenProjectType( project, ITizenWebProject.class ); + return ( type == null ) ? false : type.isWebProject(); } /** -- 2.7.4