/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/BinaryProjectRecord.java

https://gitlab.com/4615833/liferay-ide · Java · 285 lines · 179 code · 33 blank · 73 comment · 36 complexity · 4e929f9743c2eb29e455039eb6b2a660 MD5 · raw file

  1. /*******************************************************************************
  2. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. *
  14. * Contributors:
  15. * Kamesh Sampath - initial implementation
  16. ******************************************************************************/
  17. package com.liferay.ide.project.core;
  18. import static com.liferay.ide.sdk.core.ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX;
  19. import static com.liferay.ide.sdk.core.ISDKConstants.HOOK_PLUGIN_PROJECT_SUFFIX;
  20. import static com.liferay.ide.sdk.core.ISDKConstants.LAYOUTTPL_PLUGIN_PROJECT_SUFFIX;
  21. import static com.liferay.ide.sdk.core.ISDKConstants.PORTLET_PLUGIN_PROJECT_SUFFIX;
  22. import static com.liferay.ide.sdk.core.ISDKConstants.THEME_PLUGIN_PROJECT_SUFFIX;
  23. import static com.liferay.ide.sdk.core.ISDKConstants.WEB_PLUGIN_PROJECT_SUFFIX;
  24. import java.io.File;
  25. /**
  26. * @author <a href="mailto:kamesh.sampath@hotmail.com">Kamesh Sampath</a>
  27. * @author Terry Jia
  28. */
  29. public class BinaryProjectRecord
  30. {
  31. private String binaryName;
  32. private File binaryFile;
  33. private String displayName;
  34. private String filePath;
  35. private String liferayVersion;
  36. boolean conflicts;
  37. boolean isHook;
  38. boolean isTheme;
  39. boolean isPortlet;
  40. boolean isLayoutTpl;
  41. boolean isExt;
  42. boolean isWeb;
  43. public BinaryProjectRecord( File binaryFile )
  44. {
  45. this.binaryFile = binaryFile;
  46. setNames();
  47. }
  48. private void setNames()
  49. {
  50. if( binaryFile != null )
  51. {
  52. binaryName = binaryFile.getName();
  53. filePath = binaryFile.getAbsolutePath();
  54. setPluginProperties();
  55. }
  56. }
  57. private void setPluginProperties()
  58. {
  59. if( binaryName != null )
  60. {
  61. int index = -1;
  62. if( binaryName.contains( HOOK_PLUGIN_PROJECT_SUFFIX ) )
  63. {
  64. index = binaryName.indexOf( HOOK_PLUGIN_PROJECT_SUFFIX );
  65. isHook = index != -1 ? true : false;
  66. }
  67. else if( binaryName.contains( THEME_PLUGIN_PROJECT_SUFFIX ) )
  68. {
  69. index = binaryName.indexOf( THEME_PLUGIN_PROJECT_SUFFIX );
  70. isTheme = index != -1 ? true : false;
  71. }
  72. else if( binaryName.contains( PORTLET_PLUGIN_PROJECT_SUFFIX ) )
  73. {
  74. index = binaryName.indexOf( PORTLET_PLUGIN_PROJECT_SUFFIX );
  75. isPortlet = index != -1 ? true : false;
  76. }
  77. else if( binaryName.contains( LAYOUTTPL_PLUGIN_PROJECT_SUFFIX ) )
  78. {
  79. index = binaryName.indexOf( LAYOUTTPL_PLUGIN_PROJECT_SUFFIX );
  80. isLayoutTpl = index != -1 ? true : false;
  81. }
  82. else if( binaryName.contains( EXT_PLUGIN_PROJECT_SUFFIX ) )
  83. {
  84. index = binaryName.indexOf( EXT_PLUGIN_PROJECT_SUFFIX );
  85. isExt = index != -1 ? true : false;
  86. }
  87. else if( binaryName.contains( WEB_PLUGIN_PROJECT_SUFFIX ) )
  88. {
  89. index = binaryName.indexOf( WEB_PLUGIN_PROJECT_SUFFIX );
  90. isWeb = index != -1 ? true : false;
  91. }
  92. if( index != -1 )
  93. {
  94. displayName = binaryName.substring( 0, index );
  95. }
  96. index = binaryName.lastIndexOf( "-" ); //$NON-NLS-1$
  97. if( index != -1 )
  98. {
  99. liferayVersion = binaryName.substring( index + 1, binaryName.lastIndexOf( "." ) ); //$NON-NLS-1$
  100. }
  101. }
  102. }
  103. /**
  104. * @return the filePath
  105. */
  106. public String getFilePath()
  107. {
  108. return filePath;
  109. }
  110. /**
  111. * @param filePath
  112. * the filePath to set
  113. */
  114. public void setFilePath( String label )
  115. {
  116. this.filePath = label;
  117. }
  118. /**
  119. * @return the binaryName
  120. */
  121. public String getBinaryName()
  122. {
  123. return binaryName;
  124. }
  125. /**
  126. * @param binaryName
  127. * the binaryName to set
  128. */
  129. public void setBinaryName( String binaryName )
  130. {
  131. this.binaryName = binaryName;
  132. }
  133. /**
  134. * @return the binaryFile
  135. */
  136. public File getBinaryFile()
  137. {
  138. return binaryFile;
  139. }
  140. /**
  141. * @param binaryFile
  142. * the binaryFile to set
  143. */
  144. public void setBinaryFile( File binaryFile )
  145. {
  146. this.binaryFile = binaryFile;
  147. }
  148. /**
  149. * @return the displayName
  150. */
  151. public String getDisplayName()
  152. {
  153. return displayName;
  154. }
  155. /**
  156. * @param displayName
  157. * the displayName to set
  158. */
  159. public void setDisplayName( String liferayPluginName )
  160. {
  161. this.displayName = liferayPluginName;
  162. }
  163. /**
  164. * @return the conflicts
  165. */
  166. public boolean isConflicts()
  167. {
  168. return conflicts;
  169. }
  170. /**
  171. * @param conflicts
  172. * the conflicts to set
  173. */
  174. public void setConflicts( boolean hasConflicts )
  175. {
  176. this.conflicts = hasConflicts;
  177. }
  178. /**
  179. * @return the liferayVersion
  180. */
  181. public String getLiferayVersion()
  182. {
  183. return liferayVersion;
  184. }
  185. /**
  186. * @return the isHook
  187. */
  188. public boolean isHook()
  189. {
  190. return isHook;
  191. }
  192. /**
  193. * @return the isTheme
  194. */
  195. public boolean isTheme()
  196. {
  197. return isTheme;
  198. }
  199. /**
  200. * @return the isPortlet
  201. */
  202. public boolean isPortlet()
  203. {
  204. return isPortlet;
  205. }
  206. /**
  207. * @return the isLayoutTpl
  208. */
  209. public boolean isLayoutTpl()
  210. {
  211. return isLayoutTpl;
  212. }
  213. /**
  214. * @return the isWeb
  215. */
  216. public boolean isWeb()
  217. {
  218. return isWeb;
  219. }
  220. public String getLiferayPluginName()
  221. {
  222. if( isHook )
  223. {
  224. return getDisplayName() + HOOK_PLUGIN_PROJECT_SUFFIX;
  225. }
  226. else if( isLayoutTpl )
  227. {
  228. return getDisplayName() + LAYOUTTPL_PLUGIN_PROJECT_SUFFIX;
  229. }
  230. else if( isPortlet )
  231. {
  232. return getDisplayName() + PORTLET_PLUGIN_PROJECT_SUFFIX;
  233. }
  234. else if( isTheme )
  235. {
  236. return getDisplayName() + THEME_PLUGIN_PROJECT_SUFFIX;
  237. }
  238. else if( isExt )
  239. {
  240. return getDisplayName() + EXT_PLUGIN_PROJECT_SUFFIX;
  241. }
  242. else if( isWeb )
  243. {
  244. return getDisplayName() + WEB_PLUGIN_PROJECT_SUFFIX;
  245. }
  246. return null;
  247. }
  248. public boolean isExt()
  249. {
  250. return isExt;
  251. }
  252. }