use of com.liferay.ide.core.ILiferayProject in project liferay-ide by liferay.
the class ImportWorkspaceProjectTests method assertSourceFolders.
private void assertSourceFolders(String projectName, String expectedSourceFolderName) {
IProject project = CoreUtil.getProject(projectName);
assertTrue("Project " + projectName + " doesn't exist.", project.exists());
ILiferayProject liferayProject = LiferayCore.create(project);
IFolder[] srcFolders = liferayProject.getSourceFolders();
assertEquals(expectedSourceFolderName, srcFolders[0].getName());
}
use of com.liferay.ide.core.ILiferayProject in project liferay-ide by liferay.
the class PropertiesUtil method getLanguagePropertiesFromLiferayHookXml.
public static IFile[] getLanguagePropertiesFromLiferayHookXml(IFile liferayHookXml) {
List<IFile> retval = new ArrayList<>();
IProject project = CoreUtil.getLiferayProject(liferayHookXml);
if (project == null) {
return new IFile[0];
}
ILiferayProject lrproject = LiferayCore.create(project);
IFolder[] srcFolders = lrproject.getSourceFolders();
if (ListUtil.isEmpty(srcFolders)) {
return new IFile[0];
}
if (FileUtil.notExists(liferayHookXml)) {
return new IFile[0];
}
LanguageFileInfo languageFileInfo = _getLanguageFileInfo(liferayHookXml);
for (String languagePropertiesVal : languageFileInfo.getLanguagePropertyPatterns()) {
for (IFolder srcFolder : srcFolders) {
if (FileUtil.notExists(srcFolder)) {
continue;
}
IFile[] languagePropertiesFiles = visitPropertiesFiles(srcFolder, languagePropertiesVal);
if (ListUtil.isNotEmpty(languagePropertiesFiles)) {
Collections.addAll(retval, languagePropertiesFiles);
}
}
}
return retval.toArray(new IFile[0]);
}
use of com.liferay.ide.core.ILiferayProject in project liferay-ide by liferay.
the class PropertiesUtil method getDefaultLanguagePropertiesFromPortletXml.
public static List<IFile> getDefaultLanguagePropertiesFromPortletXml(IFile portletXml) {
IProject proj = CoreUtil.getLiferayProject(portletXml);
if (proj == null) {
return Collections.emptyList();
}
List<IFile> retvals = new ArrayList<>();
if (FileUtil.notExists(portletXml)) {
return Collections.emptyList();
}
ILiferayProject lrproject = LiferayCore.create(proj);
IFolder[] srcFolders = lrproject.getSourceFolders();
ResourceNodeInfo resourceNodeInfo = _getResourceNodeInfo(portletXml);
Set<String> resourceBundles = resourceNodeInfo.getResourceBundles();
if (ListUtil.isEmpty(resourceBundles)) {
return Collections.emptyList();
}
for (int i = 0; i < resourceBundles.size(); i++) {
String resourceBundleValue = (String) resourceBundles.toArray()[i];
for (IFolder srcFolder : srcFolders) {
IPath path = srcFolder.getFullPath().append(resourceBundleValue + PROPERTIES_FILE_SUFFIX);
IFile languageFile = CoreUtil.getWorkspaceRoot().getFile(path);
if (FileUtil.exists(languageFile)) {
retvals.add(languageFile);
}
}
}
return retvals;
}
use of com.liferay.ide.core.ILiferayProject in project liferay-ide by liferay.
the class PropertiesUtil method getDefaultLanguagePropertiesFromModuleProject.
public static List<IFile> getDefaultLanguagePropertiesFromModuleProject(IProject project) {
IJavaProject javaProject = JavaCore.create(project);
IType portletType = null;
List<IFile> retvals = new ArrayList<>();
try {
portletType = javaProject.findType("javax.portlet.Portlet");
ITypeHierarchy typeHierarchy = portletType.newTypeHierarchy(javaProject, new NullProgressMonitor());
IPackageFragmentRoot[] packageRoots = javaProject.getPackageFragmentRoots();
List<String> packages = new ArrayList<>();
List<IType> srcJavaTypes = new ArrayList<>();
for (IPackageFragmentRoot packageRoot : packageRoots) {
if (packageRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
IJavaElement[] javaElements = packageRoot.getChildren();
for (IJavaElement javaElement : javaElements) {
IPackageFragment packageFragment = (IPackageFragment) javaElement;
packages.add(packageFragment.getElementName());
}
}
}
IType[] subtypes = typeHierarchy.getAllSubtypes(portletType);
for (IType type : subtypes) {
if (_isInPackage(packages, type.getFullyQualifiedName())) {
srcJavaTypes.add(type);
}
}
String resourceBundleValue = null;
for (IType type : srcJavaTypes) {
IPath path = type.getResource().getLocation();
File file = path.toFile();
String content = FileUtil.readContents(file);
String key = "javax.portlet.resource-bundle=";
int i = content.indexOf(key);
if (i == -1) {
continue;
} else {
i += key.length();
StringBuilder strBuilder = new StringBuilder();
for (; i < content.length(); i++) {
char ch = content.charAt(i);
if (ch != '"') {
strBuilder.append(ch);
} else {
break;
}
}
resourceBundleValue = strBuilder.toString();
break;
}
}
String resourceBundle = resourceBundleValue.replaceAll("(^\\s*)|(\\s*$)", StringPool.BLANK);
if (!resourceBundle.endsWith(PROPERTIES_FILE_SUFFIX) && !resourceBundle.contains(IPath.SEPARATOR + "") && !(CoreUtil.isWindows() && resourceBundle.contains("\\"))) {
resourceBundle = new Path(resourceBundle.replace(".", IPath.SEPARATOR + "")).toString();
}
ILiferayProject lrproject = LiferayCore.create(project);
IFolder[] srcFolders = lrproject.getSourceFolders();
for (IFolder srcFolder : srcFolders) {
IPath path = srcFolder.getFullPath().append(resourceBundle + PROPERTIES_FILE_SUFFIX);
IFile languageFile = CoreUtil.getWorkspaceRoot().getFile(path);
if (FileUtil.exists(languageFile)) {
retvals.add(languageFile);
}
}
} catch (Exception e) {
}
return retvals;
}
use of com.liferay.ide.core.ILiferayProject in project liferay-ide by liferay.
the class SDKCommandAction method run.
@Override
public void run(IAction action) {
if (fSelection instanceof IStructuredSelection) {
Object[] elems = ((IStructuredSelection) fSelection).toArray();
IFile buildXmlFile = null;
IProject project = null;
Object elem = elems[0];
if (elem instanceof IFile) {
buildXmlFile = (IFile) elem;
project = buildXmlFile.getProject();
} else if (elem instanceof IProject) {
project = (IProject) elem;
buildXmlFile = project.getFile("build.xml");
}
if (buildXmlFile.exists()) {
final IProject p = project;
final IFile buildFile = buildXmlFile;
new Job(p.getName() + " : " + getSDKCommand()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
SDK sdk = SDKUtil.getSDK(p);
ILiferayProject liferayProject = LiferayCore.create(p);
if (liferayProject != null) {
sdk.runCommand(p, buildFile, getSDKCommand(), null, monitor);
p.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
} catch (Exception e) {
return ProjectUI.createErrorStatus("Error running SDK command " + getSDKCommand(), e);
}
return Status.OK_STATUS;
}
}.schedule();
}
}
}
Aggregations