Search in sources :

Example 11 with ILiferayProject

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());
}
Also used : ILiferayProject(com.liferay.ide.core.ILiferayProject) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 12 with ILiferayProject

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]);
}
Also used : IFile(org.eclipse.core.resources.IFile) ILiferayProject(com.liferay.ide.core.ILiferayProject) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 13 with ILiferayProject

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ILiferayProject(com.liferay.ide.core.ILiferayProject) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 14 with ILiferayProject

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IType(org.eclipse.jdt.core.IType) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) IJavaProject(org.eclipse.jdt.core.IJavaProject) ILiferayProject(com.liferay.ide.core.ILiferayProject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 15 with ILiferayProject

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();
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) ILiferayProject(com.liferay.ide.core.ILiferayProject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SDK(com.liferay.ide.sdk.core.SDK) Job(org.eclipse.core.runtime.jobs.Job) IProject(org.eclipse.core.resources.IProject)

Aggregations

ILiferayProject (com.liferay.ide.core.ILiferayProject)45 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)29 IProject (org.eclipse.core.resources.IProject)21 IPath (org.eclipse.core.runtime.IPath)18 IFile (org.eclipse.core.resources.IFile)17 CoreException (org.eclipse.core.runtime.CoreException)15 ArrayList (java.util.ArrayList)9 IFolder (org.eclipse.core.resources.IFolder)8 Version (org.osgi.framework.Version)8 IOException (java.io.IOException)7 File (java.io.File)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 Test (org.junit.Test)5 IProjectBuilder (com.liferay.ide.project.core.IProjectBuilder)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IStatus (org.eclipse.core.runtime.IStatus)4 Path (org.eclipse.core.runtime.Path)4 IWebProject (com.liferay.ide.core.IWebProject)3 Hook (com.liferay.ide.hook.core.model.Hook)3 IMavenProjectFacade (org.eclipse.m2e.core.project.IMavenProjectFacade)3