Search in sources :

Example 1 with ProgressMonitor

use of org.eclipse.sapphire.modeling.ProgressMonitor in project liferay-ide by liferay.

the class ImportMavenLiferayWorkspaceOpTests method testImportMavenLiferayWorkspaceInitBundleSetUrl.

@Test
public void testImportMavenLiferayWorkspaceInitBundleSetUrl() throws Exception {
    ImportLiferayWorkspaceOp op = ImportLiferayWorkspaceOp.TYPE.instantiate();
    URL wsZipUrl = Platform.getBundle("com.liferay.ide.maven.core.tests").getEntry("projects/maven-liferay-workspace-bundleUrl.zip");
    String bundleUrl = "https://cdn.lfrs.sl/releases.liferay.com/portal/7.0.4-ga5/liferay-ce-portal-tomcat-7.0-ga5-20171018150113838.zip";
    String existUrl = "http://www.example.com/";
    String emailConfig = "<emailAddress>example@liferay.com</emailAddress>";
    String projectName = "maven-liferay-workspace";
    File wsZipFile = new File(FileLocator.toFileURL(wsZipUrl).getFile());
    IPath workspaceLocation = CoreUtil.getWorkspaceRoot().getLocation();
    String projectLocation = workspaceLocation.append(projectName).toPortableString();
    ZipUtil.unzip(wsZipFile, workspaceLocation.toFile());
    File wsFolder = new File(workspaceLocation.toFile(), projectName);
    File pomFile = new File(projectLocation, "pom.xml");
    assertTrue(pomFile.exists());
    String content = FileUtil.readContents(pomFile);
    assertTrue(content.contains(existUrl));
    assertTrue(content.contains(emailConfig));
    op.setWorkspaceLocation(wsFolder.getAbsolutePath());
    op.setProvisionLiferayBundle(true);
    op.setBundleUrl(bundleUrl);
    op.execute(new ProgressMonitor());
    content = FileUtil.readContents(pomFile);
    File bundleDir = new File(projectLocation, "bundles");
    assertTrue(bundleDir.exists());
    assertFalse(content.contains(existUrl));
    assertTrue(content.contains(bundleUrl));
    assertTrue(content.contains(emailConfig));
    IProject project = CoreUtil.getProject("maven-liferay-workspace");
    project.delete(true, true, new NullProgressMonitor());
}
Also used : ImportLiferayWorkspaceOp(com.liferay.ide.project.core.workspace.ImportLiferayWorkspaceOp) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProgressMonitor(org.eclipse.sapphire.modeling.ProgressMonitor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) File(java.io.File) URL(java.net.URL) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 2 with ProgressMonitor

use of org.eclipse.sapphire.modeling.ProgressMonitor in project liferay-ide by liferay.

the class LiferayWorkspaceUtilTests method testLiferayWorkspaceUtil.

@Test
public void testLiferayWorkspaceUtil() throws Exception {
    NewLiferayWorkspaceOp op = NewLiferayWorkspaceOp.TYPE.instantiate();
    op.setWorkspaceName("test-liferay-workspace");
    if (op.validation().ok()) {
        op.execute(new ProgressMonitor());
    }
    IProject workspaceProject = CoreUtil.getProject("test-liferay-workspace");
    assertTrue(workspaceProject != null);
    assertTrue(workspaceProject.exists());
    String workspaceLocation = workspaceProject.getLocation().toPortableString();
    String homeValue = LiferayWorkspaceUtil.getHomeDir(workspaceLocation);
    assertTrue(homeValue.equals("bundles"));
    String modulesValue = LiferayWorkspaceUtil.getModulesDir(workspaceProject);
    assertTrue(modulesValue.equals("modules"));
    String pluginSdkValue = LiferayWorkspaceUtil.getPluginsSDKDir(workspaceLocation);
    assertTrue(pluginSdkValue.equals("plugins-sdk"));
    String themesValue = LiferayWorkspaceUtil.getThemesDir(workspaceProject);
    assertTrue(themesValue.equals("themes"));
    String warsValue = LiferayWorkspaceUtil.getWarsDirs(workspaceProject)[0];
    assertTrue(warsValue.equals("wars"));
    File propertiesFile = new File(workspaceLocation + "/gradle.properties");
    Properties prop = PropertiesUtil.loadProperties(propertiesFile);
    prop.setProperty(LiferayWorkspaceUtil.LIFERAY_WORKSPACE_HOME_DIR, "bundles1");
    prop.setProperty(LiferayWorkspaceUtil.LIFERAY_WORKSPACE_MODULES_DIR, "tests,modules");
    prop.setProperty(LiferayWorkspaceUtil.LIFERAY_WORKSPACE_PLUGINS_SDK_DIR, "plugins-sdk1");
    prop.setProperty(LiferayWorkspaceUtil.LIFERAY_WORKSPACE_THEMES_DIR, "themes1");
    prop.setProperty(LiferayWorkspaceUtil.LIFERAY_WORKSPACE_WARS_DIR, "test1,wars1,");
    PropertiesUtil.saveProperties(prop, propertiesFile);
    workspaceProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    homeValue = LiferayWorkspaceUtil.getHomeDir(workspaceLocation);
    assertTrue(homeValue.equals("bundles1"));
    modulesValue = LiferayWorkspaceUtil.getModulesDir(workspaceProject);
    assertTrue(modulesValue.equals("tests"));
    pluginSdkValue = LiferayWorkspaceUtil.getPluginsSDKDir(workspaceLocation);
    assertTrue(pluginSdkValue.equals("plugins-sdk1"));
    themesValue = LiferayWorkspaceUtil.getThemesDir(workspaceProject);
    assertTrue(themesValue.equals("themes1"));
    warsValue = LiferayWorkspaceUtil.getWarsDirs(workspaceProject)[0];
    assertTrue(warsValue.equals("test1"));
    workspaceProject.delete(true, true, new NullProgressMonitor());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProgressMonitor(org.eclipse.sapphire.modeling.ProgressMonitor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) NewLiferayWorkspaceOp(com.liferay.ide.project.core.workspace.NewLiferayWorkspaceOp) Properties(java.util.Properties) File(java.io.File) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 3 with ProgressMonitor

use of org.eclipse.sapphire.modeling.ProgressMonitor in project liferay-ide by liferay.

the class NewLiferayWorkspaceOpTests method testNewLiferayWorkspaceOp.

@Test
public void testNewLiferayWorkspaceOp() throws Exception {
    ILiferayProjectImporter importer = LiferayCore.getImporter("gradle");
    File eclipseWorkspaceLocation = CoreUtil.getWorkspaceRoot().getLocation().toFile();
    URL projectZipUrl = Platform.getBundle("com.liferay.ide.project.core.tests").getEntry("projects/existingProject.zip");
    final File projectZipFile = new File(FileLocator.toFileURL(projectZipUrl).getFile());
    ZipUtil.unzip(projectZipFile, eclipseWorkspaceLocation);
    File projectFolder = new File(eclipseWorkspaceLocation, "existingProject");
    waitForBuildAndValidation();
    importer.importProjects(projectFolder.getAbsolutePath(), new NullProgressMonitor());
    NewLiferayWorkspaceOp op = NewLiferayWorkspaceOp.TYPE.instantiate();
    op.setWorkspaceName("existingProject");
    String message = op.validation().message();
    assertNotNull(message);
    assertEquals("A project with that name(ignore case) already exists.", message);
    op.setWorkspaceName("ExistingProject");
    message = op.validation().message();
    assertTrue(message.equals("A project with that name(ignore case) already exists."));
    String projectName = "test-liferay-workspace";
    IPath workspaceLocation = CoreUtil.getWorkspaceRoot().getLocation();
    op.setWorkspaceName(projectName);
    op.setUseDefaultLocation(false);
    op.setLocation(workspaceLocation.toPortableString());
    op.execute(new ProgressMonitor());
    String wsLocation = workspaceLocation.append(projectName).toPortableString();
    File wsFile = new File(wsLocation);
    assertTrue(wsFile.exists());
    assertTrue(LiferayWorkspaceUtil.isValidWorkspaceLocation(wsLocation));
    File propertiesFile = new File(wsFile, "gradle.properties");
    Properties prop = PropertiesUtil.loadProperties(propertiesFile);
    prop.setProperty(LiferayWorkspaceUtil.LIFERAY_WORKSPACE_WARS_DIR, "wars,wars2");
    PropertiesUtil.saveProperties(prop, propertiesFile);
    NewLiferayModuleProjectOp moduleProjectOp = NewLiferayModuleProjectOp.TYPE.instantiate();
    moduleProjectOp.setProjectName("testThemeWarDefault");
    moduleProjectOp.setProjectTemplateName("theme");
    moduleProjectOp.execute(new ProgressMonitor());
    waitForBuildAndValidation();
    assertTrue(CoreUtil.getProject("testThemeWarDefault").exists());
    moduleProjectOp = NewLiferayModuleProjectOp.TYPE.instantiate();
    moduleProjectOp.setProjectName("testThemeWarNotDefault");
    moduleProjectOp.setProjectTemplateName("theme");
    moduleProjectOp.setUseDefaultLocation(false);
    moduleProjectOp.setLocation(wsLocation + "/wars");
    moduleProjectOp.execute(new ProgressMonitor());
    waitForBuildAndValidation();
    assertTrue(CoreUtil.getProject("testThemeWarNotDefault").exists());
    moduleProjectOp = NewLiferayModuleProjectOp.TYPE.instantiate();
    moduleProjectOp.setProjectName("testThemeWar2");
    moduleProjectOp.setProjectTemplateName("theme");
    moduleProjectOp.setUseDefaultLocation(false);
    moduleProjectOp.setLocation(wsLocation + "/wars2");
    moduleProjectOp.execute(new ProgressMonitor());
    waitForBuildAndValidation();
    assertTrue(CoreUtil.getProject("testThemeWar2").exists());
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProgressMonitor(org.eclipse.sapphire.modeling.ProgressMonitor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) NewLiferayWorkspaceOp(com.liferay.ide.project.core.workspace.NewLiferayWorkspaceOp) ILiferayProjectImporter(com.liferay.ide.core.ILiferayProjectImporter) IPath(org.eclipse.core.runtime.IPath) NewLiferayModuleProjectOp(com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 4 with ProgressMonitor

use of org.eclipse.sapphire.modeling.ProgressMonitor 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());
}
Also used : ProgressMonitor(org.eclipse.sapphire.modeling.ProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) SDK(com.liferay.ide.sdk.core.SDK) Test(org.junit.Test)

Example 5 with ProgressMonitor

use of org.eclipse.sapphire.modeling.ProgressMonitor in project liferay-ide by liferay.

the class NewLiferayPluginProjectOpBase method testSDKLocationValidation.

@Test
public void testSDKLocationValidation() throws Exception {
    if (shouldSkipBundleTests())
        return;
    NewLiferayPluginProjectOp op = newProjectOp("test-sdk");
    op.setProjectProvider("ant");
    Status status = op.execute(new ProgressMonitor());
    if (!status.ok()) {
        throw new Exception(status.exception());
    }
    SDK sdk = SDKUtil.getWorkspaceSDK();
    IPath sdkLocation = sdk.getLocation();
    if (sdk != null) {
        CoreUtil.getWorkspaceRoot().getProject(sdk.getName()).delete(false, false, null);
    }
    // set existed project name
    IProject project = getProject("portlets", "test-sdk-" + getRuntimeVersion() + "-portlet");
    project.delete(false, false, null);
    op.setSdkLocation(sdkLocation.toOSString());
    assertTrue(op.validation().message().contains("is not valid because a project already exists at that location."));
    op = newProjectOp("test2-sdk");
    op.setSdkLocation("");
    assertEquals("This sdk location is empty.", op.validation().message());
    op.setSdkLocation(sdk.getLocation().getDevice() + "/");
    assertEquals("This sdk location is not correct.", op.validation().message());
    // sdk has no build.USERNAME.properties file
    sdkLocation.append("build." + System.getenv().get("USER") + ".properties").toFile().delete();
    sdkLocation.append("build." + System.getenv().get("USERNAME") + ".properties").toFile().delete();
    op.setSdkLocation(sdkLocation.toOSString());
    String expectedMessageRegx = ".*app.server.*";
    assertTrue(op.validation().message().matches(expectedMessageRegx));
    assertEquals(false, op.validation().ok());
}
Also used : Status(org.eclipse.sapphire.modeling.Status) ProgressMonitor(org.eclipse.sapphire.modeling.ProgressMonitor) IPath(org.eclipse.core.runtime.IPath) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) SDK(com.liferay.ide.sdk.core.SDK) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Aggregations

ProgressMonitor (org.eclipse.sapphire.modeling.ProgressMonitor)10 Test (org.junit.Test)10 File (java.io.File)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 IPath (org.eclipse.core.runtime.IPath)7 NewLiferayWorkspaceOp (com.liferay.ide.project.core.workspace.NewLiferayWorkspaceOp)5 IProject (org.eclipse.core.resources.IProject)5 URL (java.net.URL)4 ImportLiferayWorkspaceOp (com.liferay.ide.project.core.workspace.ImportLiferayWorkspaceOp)3 Status (org.eclipse.sapphire.modeling.Status)3 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)2 SDK (com.liferay.ide.sdk.core.SDK)2 Properties (java.util.Properties)2 ILiferayProjectImporter (com.liferay.ide.core.ILiferayProjectImporter)1 NewLiferayModuleProjectOp (com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 IServer (org.eclipse.wst.server.core.IServer)1