use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class SDKProjectConvertDataModelProvider method getDefaultProperty.
@Override
public Object getDefaultProperty(String propertyName) {
if (SDK_LOCATION.equals(propertyName)) {
IPath rawLocation = _project.getRawLocation();
if (rawLocation == null) {
URI absoluteUri = _project.getLocationURI();
rawLocation = new Path(absoluteUri.getPath());
}
return rawLocation.removeLastSegments(2).toOSString();
} else if (SDK_VERSION.equals(propertyName)) {
// see if we have a sdk location and extract the version
String sdkLoc = getStringProperty(SDK_LOCATION);
try {
boolean validSDKLocation = SDKUtil.isValidSDKLocation(sdkLoc);
if (validSDKLocation) {
SDK sdk = SDKUtil.createSDKFromLocation(new Path(sdkLoc));
if (sdk != null) {
String sdkVersionValue = sdk.getVersion();
Version v = new Version(sdkVersionValue);
return v.toString();
}
} else {
return StringPool.EMPTY;
}
} catch (Exception e) {
}
} else if (SELECTED_PROJECTS.equals(propertyName)) {
return new ProjectRecord[] { new ProjectRecord(_project) };
}
return super.getDefaultProperty(propertyName);
}
use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class LocationValidationService 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);
}
}
Path currentProjectLocation = op.getLocation().content(true);
String currentProjectName = op.getProjectName().content();
/*
* Location won't be validated if the UseDefaultLocation has an error.
* Get the validation of the property might not work as excepted,
* let's use call the validation service manually.
*/
Value<Boolean> useDefalutLocationValue = op.getUseDefaultLocation();
Status status = useDefalutLocationValue.service(UseDefaultLocationValidationService.class).validation();
if (!useDefalutLocationValue.content(true) && status.ok() && (currentProjectName != null)) {
/*
* IDE-1150, instead of using annotation "@Required",use this service to
* validate the custom project location must be specified, let the wizard
* display the error of project name when project name and location are both
* null.
*/
if (currentProjectLocation == null) {
return Status.createErrorStatus("Location must be specified.");
}
String currentPath = currentProjectLocation.toOSString();
if (!org.eclipse.core.runtime.Path.EMPTY.isValidPath(currentPath)) {
return Status.createErrorStatus("\"" + currentPath + "\" is not a valid path.");
}
IPath osPath = org.eclipse.core.runtime.Path.fromOSString(currentPath);
if (!osPath.toFile().isAbsolute()) {
return Status.createErrorStatus("\"" + currentPath + "\" is not an absolute path.");
}
if (FileUtil.notExists(osPath) && !_canCreate(osPath.toFile())) {
retval = Status.createErrorStatus("Cannot create project content at \"" + currentPath + "\"");
}
IStatus locationStatus = provider.validateProjectLocation(currentProjectName, osPath);
if (!locationStatus.isOK()) {
retval = Status.createErrorStatus(locationStatus.getMessage());
}
}
return retval;
}
use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class NewLiferayPluginProjectOpMethods method supportsTypePlugin.
public static boolean supportsTypePlugin(NewLiferayPluginProjectOp op, String type) {
boolean retval = false;
NewLiferayProjectProvider<NewLiferayPluginProjectOp> provider = op.getProjectProvider().content(true);
if (provider.getShortName().equals("maven") && (type.equals("web") || type.equals("theme"))) {
return true;
} else {
SDK sdk = null;
try {
sdk = SDKUtil.getWorkspaceSDK();
} catch (CoreException ce) {
}
if (sdk == null) {
Path sdkLocation = op.getSdkLocation().content();
if (sdkLocation != null) {
sdk = SDKUtil.createSDKFromLocation(PathBridge.create(sdkLocation));
}
}
if (sdk == null) {
return true;
}
Version version = new Version(sdk.getVersion());
boolean greaterThan700 = false;
if (CoreUtil.compareVersions(version, ILiferayConstants.V700) >= 0) {
greaterThan700 = true;
}
if ((greaterThan700 && "web".equals(type)) || ("theme".equals(type))) {
retval = true;
}
if (greaterThan700 && "ext".equals(type)) {
IPath extFolder = sdk.getLocation().append("ext");
File buildXml = extFolder.append("build.xml").toFile();
if (FileUtil.exists(extFolder) && FileUtil.exists(buildXml)) {
return true;
}
} else if (!greaterThan700 && "ext".equals(type)) {
return true;
}
}
return retval;
}
use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class NewLiferayPluginProjectOpMethods method updateLocation.
public static void updateLocation(NewLiferayPluginProjectOp op) {
String currentProjectName = op.getProjectName().content();
if (currentProjectName == null) {
return;
}
boolean useDefaultLocation = op.getUseDefaultLocation().content(true);
NewLiferayProjectProvider<NewLiferayPluginProjectOp> provider = op.getProjectProvider().content(true);
String providerShortName = provider.getShortName();
if (useDefaultLocation) {
Path newLocationBase = null;
if (providerShortName.equals("ant")) {
SDK sdk = null;
try {
sdk = SDKUtil.getWorkspaceSDK();
if (sdk != null) {
IStatus sdkStatus = sdk.validate();
if (!sdkStatus.isOK()) {
sdk = null;
}
}
} catch (CoreException ce) {
}
if (sdk == null) {
if (op.getSdkLocation() != null) {
Path sdkPath = op.getSdkLocation().content();
if (sdkPath != null) {
IPath sdkLocation = PathBridge.create(sdkPath);
sdk = SDKUtil.createSDKFromLocation(sdkLocation);
}
}
}
if (sdk != null) {
Path sdkLocation = PathBridge.create(sdk.getLocation());
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;
}
} else {
return;
}
} else {
newLocationBase = PathBridge.create(CoreUtil.getWorkspaceRoot().getLocation());
}
if (newLocationBase != null) {
updateLocation(op, newLocationBase);
}
}
}
use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class ParentSDKProjectImportOpMethods method execute.
public static final Status execute(ParentSDKProjectImportOp op, ProgressMonitor pm) {
IProgressMonitor monitor = ProgressMonitorBridge.create(pm);
monitor.beginTask("Importing Liferay parent sdk project...", 100);
Status retval = Status.createOkStatus();
Path sdkLocation = op.getSdkLocation().content();
if ((sdkLocation == null) || sdkLocation.isEmpty()) {
return Status.createErrorStatus("SDK folder cannot be empty");
}
SDK sdk = SDKUtil.createSDKFromLocation(PathBridge.create(sdkLocation));
try {
SDKUtil.openAsProject(sdk, monitor);
} catch (CoreException ce) {
retval = StatusBridge.create(ProjectCore.createErrorStatus(ce));
}
return retval;
}
Aggregations