Search in sources :

Example 1 with IvyClasspathContainer

use of org.apache.ivyde.eclipse.cp.IvyClasspathContainer in project liferay-ide by liferay.

the class IvyUtil method addIvyLibrary.

public static IvyClasspathContainer addIvyLibrary(IProject project, IProgressMonitor monitor) {
    final String projectName = project.getName();
    final IJavaProject javaProject = JavaCore.create(project);
    final IvyClasspathContainerConfiguration conf = new IvyClasspathContainerConfiguration(javaProject, ISDKConstants.IVY_XML_FILE, true);
    final ClasspathSetup classpathSetup = new ClasspathSetup();
    conf.setAdvancedProjectSpecific(false);
    conf.setClasspathSetup(classpathSetup);
    conf.setClassthProjectSpecific(false);
    conf.setConfs(Collections.singletonList("*"));
    conf.setMappingProjectSpecific(false);
    conf.setSettingsProjectSpecific(true);
    SDK sdk = SDKUtil.getSDK(project);
    final SettingsSetup settingsSetup = new SettingsSetup();
    IPath ivyFilePath = sdk.getLocation().append(ISDKConstants.IVY_SETTINGS_XML_FILE);
    if (ivyFilePath.toFile().exists()) {
        StringBuilder builder = new StringBuilder();
        builder.append("${");
        builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR);
        builder.append(":");
        builder.append(projectName);
        builder.append("}/");
        builder.append(ISDKConstants.IVY_SETTINGS_XML_FILE);
        settingsSetup.setIvySettingsPath(builder.toString());
    }
    StringBuilder builder = new StringBuilder();
    builder.append("${");
    builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR);
    builder.append(":");
    builder.append(projectName);
    builder.append("}/.ivy");
    settingsSetup.setIvyUserDir(builder.toString());
    conf.setIvySettingsSetup(settingsSetup);
    final IPath path = conf.getPath();
    final IClasspathAttribute[] atts = conf.getAttributes();
    final IClasspathEntry ivyEntry = JavaCore.newContainerEntry(path, null, atts, false);
    final IVirtualComponent virtualComponent = ComponentCore.createComponent(project);
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        List<IClasspathEntry> newEntries = new ArrayList<>(Arrays.asList(entries));
        IPath runtimePath = getDefaultRuntimePath(virtualComponent, ivyEntry);
        // add the deployment assembly config to deploy ivy container to /WEB-INF/lib
        final IClasspathEntry cpeTagged = modifyDependencyPath(ivyEntry, runtimePath);
        newEntries.add(cpeTagged);
        entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]);
        javaProject.setRawClasspath(entries, javaProject.getOutputLocation(), monitor);
        IvyClasspathContainer ivycp = IvyClasspathContainerHelper.getContainer(path, javaProject);
        return ivycp;
    } catch (JavaModelException jme) {
        ProjectUI.logError("Unable to add Ivy library container", jme);
    }
    return null;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) ClasspathSetup(org.apache.ivyde.eclipse.cp.ClasspathSetup) IvyClasspathContainer(org.apache.ivyde.eclipse.cp.IvyClasspathContainer) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) SettingsSetup(org.apache.ivyde.eclipse.cp.SettingsSetup) IvyClasspathContainerConfiguration(org.apache.ivyde.eclipse.cp.IvyClasspathContainerConfiguration) SDK(com.liferay.ide.sdk.core.SDK) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent)

Example 2 with IvyClasspathContainer

use of org.apache.ivyde.eclipse.cp.IvyClasspathContainer in project liferay-ide by liferay.

the class IvyUtil method configureIvyProject.

public static IStatus configureIvyProject(final IProject project, IProgressMonitor monitor) throws CoreException {
    SDK sdk = SDKUtil.getSDK(project);
    // check for 6.1.2 and greater but not 6.1.10 which is older EE release
    // and match 6.2.0 and greater
    final Version version = new Version(sdk.getVersion());
    if (((CoreUtil.compareVersions(version, ILiferayConstants.V611) >= 0) && (CoreUtil.compareVersions(version, ILiferayConstants.V6110) < 0)) || (CoreUtil.compareVersions(version, ILiferayConstants.V620) >= 0)) {
        IFile ivyXmlFile = project.getFile(ISDKConstants.IVY_XML_FILE);
        if (ivyXmlFile.exists()) {
            // IDE-1044
            addIvyNature(project, monitor);
            IvyClasspathContainer ivycp = addIvyLibrary(project, monitor);
            if (ivycp != null) {
                IStatus status = ivycp.launchResolve(false, monitor);
                if (status.isOK()) {
                    final IWebProject webproject = LiferayCore.create(IWebProject.class, project);
                    if (webproject != null) {
                        final IFolder webinfFolder = webproject.getDefaultDocrootFolder().getFolder("WEB-INF");
                        if (webinfFolder != null) {
                            ComponentUtil.validateFolder(webinfFolder, monitor);
                        }
                    }
                } else {
                    return status;
                }
            }
        }
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) Version(org.osgi.framework.Version) IWebProject(com.liferay.ide.core.IWebProject) SDK(com.liferay.ide.sdk.core.SDK) IvyClasspathContainer(org.apache.ivyde.eclipse.cp.IvyClasspathContainer) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

SDK (com.liferay.ide.sdk.core.SDK)2 IvyClasspathContainer (org.apache.ivyde.eclipse.cp.IvyClasspathContainer)2 IWebProject (com.liferay.ide.core.IWebProject)1 ArrayList (java.util.ArrayList)1 ClasspathSetup (org.apache.ivyde.eclipse.cp.ClasspathSetup)1 IvyClasspathContainerConfiguration (org.apache.ivyde.eclipse.cp.IvyClasspathContainerConfiguration)1 SettingsSetup (org.apache.ivyde.eclipse.cp.SettingsSetup)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 IVirtualComponent (org.eclipse.wst.common.componentcore.resources.IVirtualComponent)1 Version (org.osgi.framework.Version)1