use of org.eclipse.wst.common.componentcore.resources.IVirtualComponent 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;
}
use of org.eclipse.wst.common.componentcore.resources.IVirtualComponent in project liferay-ide by liferay.
the class PluginFacetInstall method configureDeploymentAssembly.
protected void configureDeploymentAssembly(String srcPath, String deployPath) {
IVirtualComponent vProject = ComponentCore.createComponent(project);
IVirtualFolder vProjectFolder = vProject.getRootFolder();
IVirtualFolder deployFolder = vProjectFolder.getFolder(new Path(deployPath));
try {
deployFolder.createLink(new Path(srcPath), IResource.FORCE, null);
} catch (CoreException ce) {
ProjectCore.logError("Unable to create link", ce);
}
try {
IPath outputLocation = JavaCore.create(project).getOutputLocation();
vProject.setMetaProperty(IModuleConstants.PROJ_REL_JAVA_OUTPUT_PATH, outputLocation.toPortableString());
} catch (JavaModelException jme) {
ProjectCore.logError("Unable to set java-ouput-path", jme);
}
}
use of org.eclipse.wst.common.componentcore.resources.IVirtualComponent in project liferay-ide by liferay.
the class ComponentUtil method getSources.
private static IPackageFragmentRoot[] getSources(IProject project) {
IJavaProject jProject = JavaCore.create(project);
if (jProject == null) {
return new IPackageFragmentRoot[0];
}
List<IPackageFragmentRoot> list = new ArrayList<IPackageFragmentRoot>();
IVirtualComponent vc = ComponentCore.createComponent(project);
IPackageFragmentRoot[] roots;
try {
roots = jProject.getPackageFragmentRoots();
for (int i = 0; i < roots.length; i++) {
if (roots[i].getKind() != IPackageFragmentRoot.K_SOURCE) {
continue;
}
IResource resource = roots[i].getResource();
if (null != resource) {
IVirtualResource[] vResources = ComponentCore.createResources(resource);
boolean found = false;
for (int j = 0; !found && j < vResources.length; j++) {
if (vResources[j].getComponent().equals(vc)) {
if (!list.contains(roots[i])) {
list.add(roots[i]);
}
found = true;
}
}
}
}
if (list.size() == 0) {
for (IPackageFragmentRoot root : roots) {
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
if (!list.contains(root)) {
list.add(root);
}
}
}
}
} catch (JavaModelException e) {
LiferayServerCore.logError(e);
}
return list.toArray(new IPackageFragmentRoot[list.size()]);
}
use of org.eclipse.wst.common.componentcore.resources.IVirtualComponent in project liferay-ide by liferay.
the class LiferayMavenProjectTests method testNewLiferayPortletProject.
@Test
public void testNewLiferayPortletProject() throws Exception {
if (shouldSkipBundleTests())
return;
NewLiferayPluginProjectOp op = NewLiferayPluginProjectOp.TYPE.instantiate();
op.setProjectName("mvc");
op.setProjectProvider("maven");
op.setPortletFramework("mvc");
createTestBundleProfile(op);
final IProject project = base.createProject(op);
assertNotNull(project);
String pomContents = CoreUtil.readStreamToString(project.getFile("pom.xml").getContents());
assertTrue(pomContents.contains("<liferay.version>"));
assertTrue(pomContents.contains("<artifactId>liferay-maven-plugin</artifactId>"));
assertTrue(pomContents.contains("<artifactId>portal-service</artifactId>"));
waitForJobsToComplete();
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
waitForJobsToComplete();
IVirtualComponent projectComponent = ComponentCore.createComponent(project);
assertEquals("mvc-portlet", projectComponent.getDeployedName());
}
use of org.eclipse.wst.common.componentcore.resources.IVirtualComponent in project liferay-ide by liferay.
the class LiferayMavenProjectTests method testNewLiferayLayouttplProject.
@Test
public void testNewLiferayLayouttplProject() throws Exception {
NewLiferayPluginProjectOp op = NewLiferayPluginProjectOp.TYPE.instantiate();
op.setProjectName("template");
op.setProjectProvider("maven");
op.setPluginType(PluginType.layouttpl);
createTestBundleProfile(op);
final IProject project = base.createProject(op);
assertNotNull(project);
String pomContents = CoreUtil.readStreamToString(project.getFile("pom.xml").getContents());
assertTrue(pomContents.contains("<pluginType>layouttpl</pluginType>"));
assertTrue(pomContents.contains("<artifactId>liferay-maven-plugin</artifactId>"));
waitForJobsToComplete();
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
waitForJobsToComplete();
IVirtualComponent projectComponent = ComponentCore.createComponent(project);
assertEquals("template-layouttpl", projectComponent.getDeployedName());
}
Aggregations