use of org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy in project liferay-ide by liferay.
the class SDKProjectConvertOperation method convertExistingProject.
protected IProject convertExistingProject(ProjectRecord record, IProgressMonitor monitor) throws CoreException {
String projectName = record.getProjectName();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject project = workspace.getRoot().getProject(projectName);
if (record.description == null) {
// error case
record.description = workspace.newProjectDescription(projectName);
IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());
if (Platform.getLocation().isPrefixOf(locationPath)) {
record.description.setLocation(null);
} else {
record.description.setLocation(locationPath);
}
} else {
record.description.setName(projectName);
}
monitor.beginTask(Msgs.importingProject, 100);
project.open(IResource.FORCE, CoreUtil.newSubMonitor(monitor, 70));
IFacetedProject fProject = ProjectFacetsManager.create(project, true, monitor);
FacetedProjectWorkingCopy fpwc = new FacetedProjectWorkingCopy(fProject);
String sdkLocation = getDataModel().getStringProperty(SDK_LOCATION);
IRuntime runtime = (IRuntime) model.getProperty(IFacetProjectCreationDataModelProperties.FACET_RUNTIME);
String pluginType = ProjectUtil.guessPluginType(fpwc);
SDKPluginFacetUtil.configureProjectAsRuntimeProject(fpwc, runtime, pluginType, sdkLocation, record);
fpwc.commitChanges(monitor);
monitor.done();
return project;
}
use of org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy in project liferay-ide by liferay.
the class ProjectUtil method createExistingProject.
public static IProject createExistingProject(ProjectRecord record, IPath sdkLocation, IProgressMonitor monitor) throws CoreException {
String projectName = record.getProjectName();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject project = workspace.getRoot().getProject(projectName);
if (record.description == null) {
// error case
record.description = workspace.newProjectDescription(projectName);
IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());
if (Platform.getLocation().isPrefixOf(locationPath)) {
record.description.setLocation(null);
} else {
record.description.setLocation(locationPath);
}
} else {
record.description.setName(projectName);
}
project.create(record.description, CoreUtil.newSubMonitor(monitor, 30));
project.open(IResource.FORCE, CoreUtil.newSubMonitor(monitor, 70));
if (project.getName().endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) {
_fixExtProjectClasspathEntries(project);
}
IFacetedProject fProject = ProjectFacetsManager.create(project, true, monitor);
FacetedProjectWorkingCopy fpwc = new FacetedProjectWorkingCopy(fProject);
String pluginType = guessPluginType(fpwc);
SDKPluginFacetUtil.configureProjectAsSDKProject(fpwc, pluginType, sdkLocation.toPortableString(), record);
fpwc.commitChanges(monitor);
IJavaProject javaProject = JavaCore.create(fProject.getProject());
CoreUtil.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
List<IClasspathEntry> rawClasspaths = new ArrayList<>();
IPath containerPath = null;
for (IClasspathEntry entry : javaProject.getRawClasspath()) {
String segment = entry.getPath().segment(0);
if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && segment.equals(SDKClasspathContainer.ID)) {
containerPath = entry.getPath();
break;
}
if (!_isLiferayRuntimePluginClassPath(entry)) {
rawClasspaths.add(entry);
}
}
if (containerPath != null) {
ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(SDKClasspathContainer.ID);
initializer.initialize(containerPath, javaProject);
} else {
javaProject.setRawClasspath(rawClasspaths.toArray(new IClasspathEntry[rawClasspaths.size()]), new NullProgressMonitor());
javaProject.setRawClasspath(rawClasspaths.toArray(new IClasspathEntry[rawClasspaths.size()]), new NullProgressMonitor());
IAccessRule[] accessRules = {};
IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathDependencyConstants.CLASSPATH_COMPONENT_NON_DEPENDENCY, StringPool.EMPTY) };
IPath cpePath = new Path(SDKClasspathContainer.ID);
IClasspathEntry newEntry = JavaCore.newContainerEntry(cpePath, accessRules, attributes, false);
IClasspathEntry[] entries = javaProject.getRawClasspath();
for (IClasspathEntry entry : entries) {
if (entry.getPath().equals(cpePath)) {
return;
}
}
IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
System.arraycopy(entries, 0, newEntries, 0, entries.length);
newEntries[entries.length] = newEntry;
javaProject.setRawClasspath(newEntries, monitor);
}
monitor.done();
SDK sdk = SDKUtil.createSDKFromLocation(sdkLocation);
SDKUtil.openAsProject(sdk);
}
}, monitor);
return project;
}
use of org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy in project liferay-ide by liferay.
the class ProjectUtil method createExistingProject.
public static IProject createExistingProject(ProjectRecord record, IRuntime runtime, String sdkLocation, IProgressMonitor monitor) throws CoreException {
String projectName = record.getProjectName();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject project = workspace.getRoot().getProject(projectName);
if (record.description == null) {
// error case
record.description = workspace.newProjectDescription(projectName);
IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());
if (Platform.getLocation().isPrefixOf(locationPath)) {
record.description.setLocation(null);
} else {
record.description.setLocation(locationPath);
}
} else {
record.description.setName(projectName);
}
monitor.beginTask(Msgs.importingProject, 100);
project.create(record.description, CoreUtil.newSubMonitor(monitor, 30));
project.open(IResource.FORCE, CoreUtil.newSubMonitor(monitor, 70));
if (project.getName().endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) {
_fixExtProjectClasspathEntries(project);
}
IFacetedProject fProject = ProjectFacetsManager.create(project, true, monitor);
FacetedProjectWorkingCopy fpwc = new FacetedProjectWorkingCopy(fProject);
String pluginType = guessPluginType(fpwc);
SDKPluginFacetUtil.configureProjectAsRuntimeProject(fpwc, runtime, pluginType, sdkLocation, record);
fpwc.commitChanges(monitor);
IJavaProject javaProject = JavaCore.create(fProject.getProject());
CoreUtil.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
for (IClasspathEntry entry : javaProject.getRawClasspath()) {
String segment = entry.getPath().segment(0);
if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && segment.equals(PluginClasspathContainerInitializer.ID)) {
ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(PluginClasspathContainerInitializer.ID);
initializer.initialize(entry.getPath(), javaProject);
break;
}
}
monitor.done();
}
}, monitor);
return project;
}
Aggregations