use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class SDKUtilTests method singleWorkSpaceProject.
@Test
public void singleWorkSpaceProject() throws Exception {
if (shouldSkipBundleTests())
return;
final File liferayPluginsSdkDirFile = getLiferayPluginsSdkDir().toFile();
if (!liferayPluginsSdkDirFile.exists()) {
final File liferayPluginsSdkZipFile = getLiferayPluginsSDKZip().toFile();
assertEquals("Expected file to exist: " + liferayPluginsSdkZipFile.getAbsolutePath(), true, liferayPluginsSdkZipFile.exists());
liferayPluginsSdkDirFile.mkdirs();
final String liferayPluginsSdkZipFolder = getLiferayPluginsSdkZipFolder();
if (CoreUtil.isNullOrEmpty(liferayPluginsSdkZipFolder)) {
ZipUtil.unzip(liferayPluginsSdkZipFile, liferayPluginsSdkDirFile);
} else {
ZipUtil.unzip(liferayPluginsSdkZipFile, liferayPluginsSdkZipFolder, liferayPluginsSdkDirFile, new NullProgressMonitor());
}
}
assertEquals(true, liferayPluginsSdkDirFile.exists());
SDK sdk = SDKUtil.createSDKFromLocation(getLiferayPluginsSdkDir());
SDKUtil.openAsProject(sdk);
IProject project = SDKUtil.getWorkspaceSDKProject();
assertNotNull(project);
}
use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class LiferaySDKValidationTests method testSDKLocationValidation.
@Test
public void testSDKLocationValidation() throws Exception {
if (shouldSkipBundleTests())
return;
NewLiferayPluginProjectOp op = newProjectOp("test-sdk");
op.setProjectProvider("ant");
op.execute(new ProgressMonitor());
SDK sdk = SDKUtil.getWorkspaceSDK();
IPath sdkLocation = sdk.getLocation();
if (sdk != null) {
CoreUtil.getWorkspaceRoot().getProject(sdk.getName()).delete(false, true, null);
}
CoreUtil.getWorkspaceRoot().getProject("test-sdk").delete(false, true, null);
// set existed project name
op.setSdkLocation(sdkLocation.toOSString());
assertTrue(op.validation().message().contains("A project with that name already exists."));
op = newProjectOp("test2-sdk");
op.setSdkLocation("");
assertEquals("This sdk location is empty.", op.validation().message());
op.setSdkLocation(sdkLocation.getDevice() + "/");
assertEquals("This sdk location is not correct.", op.validation().message());
// sdk has no build.USERNAME.properties file
sdkLocation.append("build." + System.getProperty("user.name") + ".properties").toFile().delete();
IStatus validateStatus = sdk.validate(true);
assertEquals(false, validateStatus.isOK());
}
use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class InitConfigureProjectPage method importProject.
protected void importProject() throws CoreException {
String layout = dataModel.getLayout().content();
IPath location = PathBridge.create(dataModel.getSdkLocation().content());
if (_isAlreadyImported(location)) {
Stream.of(CoreUtil.getAllProjects()).forEach(this::_checkProjectType);
dataModel.setImportFinished(true);
return;
}
try {
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
progressService.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
try {
String newPath = "";
_backup(monitor);
_clearExistingProjects(location, monitor);
_deleteEclipseConfigFiles(location.toFile());
if (_isMavenProject(location.toPortableString())) {
ILiferayProjectImporter importer = LiferayCore.getImporter("maven");
List<IProject> projects = importer.importProjects(location.toPortableString(), monitor);
for (IProject project : projects) {
_checkProjectType(project);
}
} else {
if (layout.equals("Upgrade to Liferay Workspace")) {
_createLiferayWorkspace(location, monitor);
_removeIvyPrivateSetting(location.append("plugins-sdk"));
newPath = _renameProjectFolder(location);
IPath sdkLocation = new Path(newPath).append("plugins-sdk");
_deleteSDKLegacyProjects(sdkLocation);
ILiferayProjectImporter importer = LiferayCore.getImporter("gradle");
importer.importProjects(newPath, monitor);
if (dataModel.getDownloadBundle().content()) {
_createInitBundle(monitor);
}
_importSDKProject(sdkLocation, monitor);
dataModel.setConvertLiferayWorkspace(true);
} else {
_deleteEclipseConfigFiles(location.toFile());
_copyNewSDK(location, monitor);
_removeIvyPrivateSetting(location);
_deleteSDKLegacyProjects(location);
String serverName = dataModel.getLiferay70ServerName().content();
IServer server = ServerUtil.getServer(serverName);
newPath = _renameProjectFolder(location);
SDK sdk = SDKUtil.createSDKFromLocation(new Path(newPath));
sdk.addOrUpdateServerProperties(ServerUtil.getLiferayRuntime(server).getLiferayHome());
SDKUtil.openAsProject(sdk, monitor);
_importSDKProject(sdk.getLocation(), monitor);
}
}
dataModel.setImportFinished(true);
} catch (Exception e) {
ProjectUI.logError(e);
throw new InvocationTargetException(e, e.getMessage());
}
}
});
} catch (Exception e) {
ProjectUI.logError(e);
throw new CoreException(StatusBridge.create(Status.createErrorStatus(e.getMessage(), e)));
}
}
use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class ProjectLocationValidationService method compute.
@Override
protected Status compute() {
Status retval = Status.createOkStatus();
int countPossibleWorkspaceSDKProjects = SDKUtil.countPossibleWorkspaceSDKProjects();
if (countPossibleWorkspaceSDKProjects > 1) {
return StatusBridge.create(ProjectCore.createErrorStatus("This workspace has more than one SDK."));
}
Value<Path> sdkLocation = _op().getSdkLocation();
final Path location = sdkLocation.content(true);
if ((location == null) || location.isEmpty()) {
return StatusBridge.create(ProjectCore.createErrorStatus("Liferay Plugins SDK or Maven location is empty."));
}
IStatus buildType = ImportLiferayModuleProjectOpMethods.getBuildType(location.removeFileExtension().toPortableString());
SDK sdk = SDKUtil.createSDKFromLocation(PathBridge.create(location));
if (sdk != null) {
String version = sdk.getVersion();
if (version != null) {
Version sdkVersion = new Version(version);
int result = sdkVersion.compareTo(new Version("6.1.0"));
if (result < 0) {
return StatusBridge.create(ProjectCore.createErrorStatus("This tool doesn't support 6.0.x."));
}
}
} else if (!buildType.getMessage().equals("maven")) {
return StatusBridge.create(ProjectCore.createErrorStatus("Plugins SDK or Maven location is not valid."));
}
return retval;
}
use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.
the class SDKCommandHandler method executeSdkCommand.
protected IStatus executeSdkCommand(final IProject project) {
IStatus retval = null;
try {
final IFile 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 {
final SDK sdk = SDKUtil.getSDK(p);
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();
}
} catch (Exception e) {
retval = ProjectCore.createErrorStatus("Unable to execute sdk command", e);
}
return retval;
}
Aggregations