use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class SDKLocationListener method updateLocation.
public static void updateLocation(NewLiferayPluginProjectOp op) {
Path newLocationBase = null;
Path sdkLocation = op.getSdkLocation().content(true);
if (sdkLocation == null) {
return;
}
SDK sdk = SDKUtil.createSDKFromLocation(PathBridge.create(sdkLocation));
op.setImportProjectStatus(false);
if (sdk == null) {
return;
}
switch(op.getPluginType().content(true)) {
case portlet:
case servicebuilder:
newLocationBase = sdkLocation.append("portlets");
break;
case ext:
newLocationBase = sdkLocation.append("ext");
break;
case hook:
newLocationBase = sdkLocation.append("hooks");
break;
case layouttpl:
newLocationBase = sdkLocation.append("layouttpl");
break;
case theme:
newLocationBase = sdkLocation.append("themes");
break;
case web:
newLocationBase = sdkLocation.append("webs");
break;
}
if (newLocationBase != null) {
NewLiferayPluginProjectOpMethods.updateLocation(op, newLocationBase);
}
}
use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class ProjectNameValidationService method compute.
@Override
protected Status compute() {
Status retval = Status.createOkStatus();
NewLiferayPluginProjectOp op = _op();
NewLiferayProjectProvider<NewLiferayPluginProjectOp> provider = op.getProjectProvider().content();
if (provider.getShortName().equals("ant")) {
SDK sdk = null;
try {
sdk = SDKUtil.getWorkspaceSDK();
if (sdk != null) {
IStatus sdkStatus = sdk.validate();
if (!sdkStatus.isOK()) {
retval = Status.createErrorStatus(sdkStatus.getChildren()[0].getMessage());
}
}
} catch (CoreException ce) {
retval = Status.createErrorStatus(ce);
}
}
String currentProjectName = op.getProjectName().content();
if (currentProjectName != null) {
IStatus nameStatus = CoreUtil.getWorkspace().validateName(currentProjectName, IResource.PROJECT);
if (!nameStatus.isOK()) {
retval = StatusBridge.create(nameStatus);
} else if (_isInvalidProjectName(op)) {
Boolean projectImported = op.getImportProjectStatus().content();
if (projectImported == false) {
retval = Status.createErrorStatus("A project with that name already exists.");
}
} else if (_isAntProject(op) && _isSuffixOnly(currentProjectName)) {
retval = Status.createErrorStatus("A project name cannot only be a type suffix.");
} else if (!_hasValidDisplayName(currentProjectName)) {
retval = Status.createErrorStatus("The project name is invalid.");
} else if (_isMavenProject(op) && !_isValidMavenProjectName(currentProjectName)) {
retval = Status.createErrorStatus("The project name is invalid for a maven project");
} else {
Path currentProjectLocation = op.getLocation().content(true);
if ((currentProjectName != null) && (currentProjectLocation != null)) {
String currentPath = currentProjectLocation.toOSString();
IPath osPath = org.eclipse.core.runtime.Path.fromOSString(currentPath);
IStatus projectStatus = provider.validateProjectLocation(currentProjectName, osPath);
if (!projectStatus.isOK()) {
retval = StatusBridge.create(projectStatus);
}
}
}
}
op.getSdkLocation().refresh();
return retval;
}
use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class LiferayProjectPropertyPage method createInfoGroup.
protected void createInfoGroup(final Composite parent) {
new Label(parent, SWT.LEFT).setText(Msgs.liferayPluginTypeLabel);
final Text pluginTypeLabel = new Text(parent, SWT.READ_ONLY | SWT.BORDER);
pluginTypeLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
final IProjectFacet liferayFacet = ProjectUtil.getLiferayFacet(getFacetedProject());
if (liferayFacet != null) {
pluginTypeLabel.setText(liferayFacet.getLabel());
}
final IProject proj = getProject();
if ((proj != null) && ProjectUtil.isLiferayFacetedProject(proj)) {
try {
if (!ProjectUtil.isMavenProject(proj)) {
final SDK projectSdk = SDKUtil.getSDK(getProject());
new Label(parent, SWT.LEFT).setText(Msgs.liferaySdkLabel);
_sdkLabel = new Text(parent, SWT.READ_ONLY | SWT.BORDER);
if (projectSdk != null) {
_sdkLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
_sdkLabel.setText(projectSdk.getName());
} else {
_sdkLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
_sdkLabel.setText("");
final Hyperlink link = new Hyperlink(parent, SWT.NULL);
link.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
link.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
link.setUnderlined(true);
link.setText(Msgs.changeliferaySdk);
link.addHyperlinkListener(new HyperlinkAdapter() {
public void linkActivated(HyperlinkEvent e) {
String dialogId = new String("com.liferay.ide.project.ui.dialog.SelectPluginsSDKDialog");
final LiferayPluginSDKOp op = (LiferayPluginSDKOp) (LiferayPluginSDKOp.TYPE.instantiate().initialize());
DefinitionLoader sdefLoader = DefinitionLoader.context(getClass()).sdef(dialogId);
final Reference<DialogDef> dialogRef = sdefLoader.dialog("ConfigureLiferaySDK");
final SapphireDialog dialog = new SapphireDialog(UIUtil.getActiveShell(), op, dialogRef);
dialog.setBlockOnOpen(true);
final int result = dialog.open();
if (result != SapphireDialog.CANCEL) {
_sdkLabel.setText(op.getPluginsSDKName().content());
}
}
});
}
if (CoreUtil.compareVersions(new Version(projectSdk.getVersion()), ILiferayConstants.V700) < 0) {
new Label(parent, SWT.LEFT).setText(Msgs.liferayRuntimeLabel);
_runtimeCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
_runtimeCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
String currentRuntimeName = null;
try {
ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(getProject());
if (liferayRuntime != null) {
currentRuntimeName = liferayRuntime.getRuntime().getName();
}
} catch (Exception e) {
ProjectUI.logError("Could not determine liferay runtime", e);
}
List<String> runtimeNames = new ArrayList<>();
int selectionIndex = -1;
for (IRuntime runtime : ServerCore.getRuntimes()) {
if (ServerUtil.isLiferayRuntime(runtime) && FileUtil.exists(runtime.getLocation()) && (LiferayServerCore.newPortalBundle(runtime.getLocation()) == null)) {
runtimeNames.add(runtime.getName());
if (runtime.getName().equals(currentRuntimeName)) {
selectionIndex = runtimeNames.size() - 1;
}
}
}
if (ListUtil.isEmpty(runtimeNames)) {
runtimeNames.add("No Liferay runtimes available.");
}
_runtimeCombo.setItems(runtimeNames.toArray(new String[0]));
if (selectionIndex > -1) {
_runtimeCombo.select(selectionIndex);
}
}
}
} catch (Exception e) {
ProjectUI.logError("Could not determine whether its a maven project ", e);
}
}
}
use of com.liferay.ide.sdk.core.SDK 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 com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class SDKCommandAction method run.
@Override
public void run(IAction action) {
if (fSelection instanceof IStructuredSelection) {
Object[] elems = ((IStructuredSelection) fSelection).toArray();
IFile buildXmlFile = null;
IProject project = null;
Object elem = elems[0];
if (elem instanceof IFile) {
buildXmlFile = (IFile) elem;
project = buildXmlFile.getProject();
} else if (elem instanceof IProject) {
project = (IProject) elem;
buildXmlFile = project.getFile("build.xml");
}
if (buildXmlFile.exists()) {
final IProject p = project;
final IFile buildFile = buildXmlFile;
new Job(p.getName() + " : " + getSDKCommand()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
SDK sdk = SDKUtil.getSDK(p);
ILiferayProject liferayProject = LiferayCore.create(p);
if (liferayProject != null) {
sdk.runCommand(p, buildFile, getSDKCommand(), null, monitor);
p.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
} catch (Exception e) {
return ProjectUI.createErrorStatus("Error running SDK command " + getSDKCommand(), e);
}
return Status.OK_STATUS;
}
}.schedule();
}
}
}
Aggregations