Search in sources :

Example 1 with ClasspathSetup

use of org.apache.ivyde.eclipse.cp.ClasspathSetup 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)

Aggregations

SDK (com.liferay.ide.sdk.core.SDK)1 ArrayList (java.util.ArrayList)1 ClasspathSetup (org.apache.ivyde.eclipse.cp.ClasspathSetup)1 IvyClasspathContainer (org.apache.ivyde.eclipse.cp.IvyClasspathContainer)1 IvyClasspathContainerConfiguration (org.apache.ivyde.eclipse.cp.IvyClasspathContainerConfiguration)1 SettingsSetup (org.apache.ivyde.eclipse.cp.SettingsSetup)1 IPath (org.eclipse.core.runtime.IPath)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