use of org.apache.ivyde.eclipse.cp.SettingsSetup 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;
}
Aggregations