Search in sources :

Example 26 with ILiferayProject

use of com.liferay.ide.core.ILiferayProject in project liferay-ide by liferay.

the class LiferayDependencyQuickFix method _createDepProposal.

private IJavaCompletionProposal _createDepProposal(IInvocationContext context, ServiceContainer bundle) {
    final String bundleGroup = bundle.getBundleGroup();
    final String bundleName = bundle.getBundleName();
    final String bundleVersion = bundle.getBundleVersion();
    return new CUCorrectionProposal("Add module dependency " + bundleName, context.getCompilationUnit(), null, -0) {

        @Override
        public void apply(IDocument document) {
            try {
                IJavaProject javaProject = context.getCompilationUnit().getJavaProject();
                IProject project = javaProject.getProject();
                ILiferayProject liferayProject = LiferayCore.create(project);
                final IProjectBuilder builder = liferayProject.adapt(IProjectBuilder.class);
                if (builder != null) {
                    Version retriveVersion = new Version(bundleVersion);
                    String[] dependency = { bundleGroup, bundleName, retriveVersion.getMajor() + "." + retriveVersion.getMinor() + ".0" };
                    List<String[]> dependencyList = new ArrayList<>();
                    dependencyList.add(dependency);
                    builder.updateProjectDependency(project, dependencyList);
                }
            } catch (Exception e) {
                ProjectUI.logError("Error adding module dependency", e);
            }
        }

        @Override
        public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
            return "Add module dependency";
        }

        @Override
        public Image getImage() {
            return ProjectUI.getPluginImageRegistry().get(ProjectUI.MODULE_DEPENDENCY_IAMGE_ID);
        }
    };
}
Also used : ArrayList(java.util.ArrayList) IProjectBuilder(com.liferay.ide.project.core.IProjectBuilder) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CUCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal) IJavaProject(org.eclipse.jdt.core.IJavaProject) Version(org.osgi.framework.Version) ILiferayProject(com.liferay.ide.core.ILiferayProject) IDocument(org.eclipse.jface.text.IDocument)

Example 27 with ILiferayProject

use of com.liferay.ide.core.ILiferayProject in project liferay-ide by liferay.

the class PortalResourcesProvider method getResources.

@Override
public File[] getResources(IWebResourcesContext context) {
    File[] retval = null;
    IFile htmlFile = context.getHtmlFile();
    ILiferayProject project = LiferayCore.create(htmlFile.getProject());
    if ((htmlFile != null) && (project != null)) {
        ILiferayPortal portal = project.adapt(ILiferayPortal.class);
        if ((portal != null) && ProjectUtil.isPortletProject(htmlFile.getProject())) {
            IPath portalDir = portal.getAppServerPortalDir();
            if (portalDir != null) {
                IPath cssPath = portalDir.append("html/themes/_unstyled/css");
                if (FileUtil.exists(cssPath)) {
                    synchronized (_fileCache) {
                        Collection<File> cachedFiles = _fileCache.get(cssPath);
                        if (cachedFiles != null) {
                            retval = cachedFiles.toArray(new File[0]);
                        } else {
                            String types = new String[] { "css", "scss" };
                            Collection<File> files = FileUtils.listFiles(cssPath.toFile(), types, true);
                            Collection<File> cached = new HashSet<>();
                            for (File file : files) {
                                if (file.getName().endsWith("scss")) {
                                    File cachedFile = new File(file.getParent(), ".sass-cache/" + file.getName().replaceAll("scss$", "css"));
                                    if (FileUtil.exists(cachedFile)) {
                                        cached.add(file);
                                    }
                                }
                            }
                            files.removeAll(cached);
                            if (files != null) {
                                retval = files.toArray(new File[0]);
                            }
                            _fileCache.put(cssPath, files);
                        }
                    }
                }
            }
        } else if ((portal != null) && ProjectUtil.isLayoutTplProject(htmlFile.getProject())) {
            // return the static css resource for layout template names based on the version
            String version = portal.getVersion();
            try {
                if ((version != null) && (version.startsWith("6.0") || version.startsWith("6.1"))) {
                    retval = _createLayoutHelperFiles("resources/layouttpl-6.1.css");
                } else if (version != null) {
                    retval = _createLayoutHelperFiles("resources/layouttpl-6.2.css");
                }
            } catch (IOException ioe) {
                AlloyCore.logError("Unable to load layout template helper css files", ioe);
            }
        }
    }
    return retval;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ILiferayProject(com.liferay.ide.core.ILiferayProject) IOException(java.io.IOException) File(java.io.File) IFile(org.eclipse.core.resources.IFile) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) HashSet(java.util.HashSet)

Example 28 with ILiferayProject

use of com.liferay.ide.core.ILiferayProject in project liferay-ide by liferay.

the class PropertiesUtil method getLanguagePropertiesFromPortletXml.

/**
 *  Search all resource bundle and supported locale files referenced by portlet.xml.
 */
public static IFile[] getLanguagePropertiesFromPortletXml(IFile portletXml) {
    List<IFile> retval = new ArrayList<>();
    IProject project = CoreUtil.getLiferayProject(portletXml);
    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(portletXml)) {
        return new IFile[0];
    }
    for (IFolder srcFolder : srcFolders) {
        if (FileUtil.notExists(srcFolder)) {
            continue;
        }
        ResourceNodeInfo resourceNodeInfo = _getResourceNodeInfo(portletXml);
        for (String resourceBundleValue : resourceNodeInfo.getResourceBundlePatterns()) {
            IFile[] resourceBundleFiles = visitPropertiesFiles(srcFolder, resourceBundleValue);
            if (ListUtil.isNotEmpty(resourceBundleFiles)) {
                Collections.addAll(retval, resourceBundleFiles);
            }
        }
        for (String supportedLocaleValue : resourceNodeInfo.getSupportedLocalePatterns()) {
            IFile[] supportedLocaleFiles = visitPropertiesFiles(srcFolder, supportedLocaleValue);
            if (ListUtil.isNotEmpty(supportedLocaleFiles)) {
                Collections.addAll(retval, supportedLocaleFiles);
            }
        }
    }
    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 29 with ILiferayProject

use of com.liferay.ide.core.ILiferayProject in project liferay-ide by liferay.

the class AddLayoutTplOperation method _isBootstrapStyle.

private boolean _isBootstrapStyle() {
    ILiferayProject lrproject = LiferayCore.create(getTargetProject());
    ILiferayPortal portal = lrproject.adapt(ILiferayPortal.class);
    if (portal != null) {
        Version version = new Version(portal.getVersion());
        if (CoreUtil.compareVersions(version, ILiferayConstants.V620) >= 0) {
            return true;
        }
        return false;
    }
    return true;
}
Also used : Version(org.osgi.framework.Version) ILiferayProject(com.liferay.ide.core.ILiferayProject) ILiferayPortal(com.liferay.ide.core.ILiferayPortal)

Example 30 with ILiferayProject

use of com.liferay.ide.core.ILiferayProject in project liferay-ide by liferay.

the class LayoutTplEditor method _isBootstrapStyle.

private boolean _isBootstrapStyle() {
    boolean retval = true;
    try {
        ILiferayProject lrproject = LiferayCore.create(getFile().getProject());
        ILiferayPortal portal = lrproject.adapt(ILiferayPortal.class);
        Version version = new Version(portal.getVersion());
        if (CoreUtil.compareVersions(version, ILiferayConstants.V620) < 0) {
            retval = false;
        }
    } catch (Exception e) {
    }
    return retval;
}
Also used : Version(org.osgi.framework.Version) ILiferayProject(com.liferay.ide.core.ILiferayProject) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) PartInitException(org.eclipse.ui.PartInitException)

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