Search in sources :

Example 1 with OverrideFilePath

use of com.liferay.ide.project.core.modules.fragment.OverrideFilePath in project liferay-ide by liferay.

the class AddFilesFromOSGiBundleAction method run.

@Override
protected Object run(Presentation context) {
    Element modelElement = context.part().getModelElement();
    final NewModuleFragmentOp op = modelElement.nearest(NewModuleFragmentOp.class);
    final ElementList<OverrideFilePath> currentFiles = op.getOverrideFiles();
    final String projectName = op.getProjectName().content();
    final OSGiBundleFileSelectionDialog dialog = new OSGiBundleFileSelectionDialog(null, currentFiles, projectName);
    final String runtimeName = op.getLiferayRuntimeName().content();
    final IRuntime runtime = ServerUtil.getRuntime(runtimeName);
    final IPath tempLocation = ProjectCore.getDefault().getStateLocation();
    dialog.setTitle("Add files from OSGi bundle to override");
    String currentOSGiBundle = op.getHostOsgiBundle().content();
    if (!currentOSGiBundle.endsWith("jar")) {
        currentOSGiBundle = currentOSGiBundle + ".jar";
    }
    File module = tempLocation.append(currentOSGiBundle).toFile();
    if (FileUtil.notExists(module)) {
        module = ServerUtil.getModuleFileFrom70Server(runtime, currentOSGiBundle, tempLocation);
    }
    if (FileUtil.exists(module)) {
        dialog.setInput(module);
    }
    if (dialog.open() == Window.OK) {
        Object[] selected = dialog.getResult();
        for (int i = 0; i < selected.length; i++) {
            OverrideFilePath file = op.getOverrideFiles().insert();
            file.setValue(selected[i].toString());
        }
    }
    return Status.createOkStatus();
}
Also used : OverrideFilePath(com.liferay.ide.project.core.modules.fragment.OverrideFilePath) IPath(org.eclipse.core.runtime.IPath) Element(org.eclipse.sapphire.Element) NewModuleFragmentOp(com.liferay.ide.project.core.modules.fragment.NewModuleFragmentOp) File(java.io.File) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 2 with OverrideFilePath

use of com.liferay.ide.project.core.modules.fragment.OverrideFilePath in project liferay-ide by liferay.

the class MavenModuleFragmentProjectTests method testNewModuleFragmentFileProjectValidation.

@Test
public void testNewModuleFragmentFileProjectValidation() throws Exception {
    deleteAllWorkspaceProjects();
    NewModuleFragmentFilesOp fop = NewModuleFragmentFilesOp.TYPE.instantiate();
    Status projectValidationStatus = fop.getProjectName().validation();
    assertEquals("No suitable Liferay fragment project.", projectValidationStatus.message());
    NewModuleFragmentOp op = NewModuleFragmentOp.TYPE.instantiate();
    final String runtimeName = "liferay-portal-7.0";
    final NullProgressMonitor npm = new NullProgressMonitor();
    IRuntime runtime = ServerCore.findRuntime(runtimeName);
    if (runtime == null) {
        final IRuntimeWorkingCopy runtimeWC = ServerCore.findRuntimeType(getRuntimeId()).createRuntime(runtimeName, npm);
        runtimeWC.setName(runtimeName);
        runtimeWC.setLocation(getLiferayRuntimeDir());
        runtime = runtimeWC.save(true, npm);
    }
    assertNotNull(runtime);
    List<String> bundles = ServerUtil.getModuleFileListFrom70Server(runtime);
    assertNotNull(bundles);
    for (String hostOsgiBundle : bundles) {
        if (hostOsgiBundle.contains("com.liferay.asset.display.web")) {
            op.setProjectName("test-project-validation");
            op.setProjectProvider("gradle-module-fragment");
            op.setLiferayRuntimeName(runtimeName);
            op.setHostOsgiBundle(hostOsgiBundle);
            OverrideFilePath overrideFilePath = op.getOverrideFiles().insert();
            overrideFilePath.setValue("META-INF/resources/view.jsp");
            Status gradleExeStatus = NewModuleFragmentOpMethods.execute(op, ProgressMonitorBridge.create(new NullProgressMonitor()));
            assertTrue(gradleExeStatus.ok());
            IProject existedGradleProject = CoreUtil.getProject(op.getProjectName().content());
            assertNotNull(existedGradleProject);
            IFile bndFile = existedGradleProject.getFile("bnd.bnd");
            bndFile.delete(true, true, new NullProgressMonitor());
            fop.setProjectName(op.getProjectName().content());
            projectValidationStatus = fop.getProjectName().validation();
            assertEquals("Can't find bnd.bnd file in the project.", projectValidationStatus.message());
        }
    }
}
Also used : Status(org.eclipse.sapphire.modeling.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) OverrideFilePath(com.liferay.ide.project.core.modules.fragment.OverrideFilePath) NewModuleFragmentOp(com.liferay.ide.project.core.modules.fragment.NewModuleFragmentOp) NewModuleFragmentFilesOp(com.liferay.ide.project.core.modules.fragment.NewModuleFragmentFilesOp) IRuntimeWorkingCopy(org.eclipse.wst.server.core.IRuntimeWorkingCopy) IProject(org.eclipse.core.resources.IProject) IRuntime(org.eclipse.wst.server.core.IRuntime) Test(org.junit.Test)

Example 3 with OverrideFilePath

use of com.liferay.ide.project.core.modules.fragment.OverrideFilePath in project liferay-ide by liferay.

the class MavenModuleFragmentProjectTests method testNewModuleFragmentProjectOpProject.

@Test
public void testNewModuleFragmentProjectOpProject() throws Exception {
    NewModuleFragmentOp op = NewModuleFragmentOp.TYPE.instantiate();
    final String runtimeName = "liferay-portal-7.0";
    final NullProgressMonitor npm = new NullProgressMonitor();
    IRuntime runtime = ServerCore.findRuntime(runtimeName);
    if (runtime == null) {
        final IRuntimeWorkingCopy runtimeWC = ServerCore.findRuntimeType(getRuntimeId()).createRuntime(runtimeName, npm);
        runtimeWC.setName(runtimeName);
        runtimeWC.setLocation(getLiferayRuntimeDir());
        runtime = runtimeWC.save(true, npm);
    }
    assertNotNull(runtime);
    List<String> bundles = ServerUtil.getModuleFileListFrom70Server(runtime);
    assertNotNull(bundles);
    for (String hostOsgiBundle : bundles) {
        if (hostOsgiBundle.contains("com.liferay.asset.display.web")) {
            op.setProjectName("test-gradle-module-fragment");
            op.setProjectProvider("gradle-module-fragment");
            op.setLiferayRuntimeName(runtimeName);
            op.setHostOsgiBundle(hostOsgiBundle);
            OverrideFilePath overrideFilePath = op.getOverrideFiles().insert();
            overrideFilePath.setValue("META-INF/resources/view.jsp");
            Status gradleExeStatus = NewModuleFragmentOpMethods.execute(op, ProgressMonitorBridge.create(new NullProgressMonitor()));
            assertTrue(gradleExeStatus.ok());
            IProject existedGradleProject = CoreUtil.getProject(op.getProjectName().content());
            assertNotNull(existedGradleProject);
            IFile gradleFile = existedGradleProject.getFile("build.gradle");
            assertTrue(gradleFile.exists());
            IFile overrideFile = existedGradleProject.getFile("src/main/resources/META-INF/resources/view.jsp");
            assertTrue(overrideFile.exists());
        }
        if (hostOsgiBundle.contains("com.liferay.login.web")) {
            op.setProjectName("test-maven-module-fragment");
            op.setProjectProvider("maven-module-fragment");
            op.setLiferayRuntimeName(runtimeName);
            op.setHostOsgiBundle(hostOsgiBundle);
            OverrideFilePath file = op.getOverrideFiles().insert();
            file.setValue("META-INF/resources/login.jsp");
            Status mavenExeStatus = NewModuleFragmentOpMethods.execute(op, ProgressMonitorBridge.create(new NullProgressMonitor()));
            assertTrue(mavenExeStatus.ok());
            IProject existedMavenProject = CoreUtil.getProject(op.getProjectName().content());
            assertNotNull(existedMavenProject);
            IFile pomFile = existedMavenProject.getFile("pom.xml");
            assertTrue(pomFile.exists());
            IFile overrideFile1 = existedMavenProject.getFile("src/main/resources/META-INF/resources/login.jsp");
            assertTrue(overrideFile1.exists());
        }
    }
}
Also used : Status(org.eclipse.sapphire.modeling.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) OverrideFilePath(com.liferay.ide.project.core.modules.fragment.OverrideFilePath) NewModuleFragmentOp(com.liferay.ide.project.core.modules.fragment.NewModuleFragmentOp) IRuntimeWorkingCopy(org.eclipse.wst.server.core.IRuntimeWorkingCopy) IProject(org.eclipse.core.resources.IProject) IRuntime(org.eclipse.wst.server.core.IRuntime) Test(org.junit.Test)

Aggregations

NewModuleFragmentOp (com.liferay.ide.project.core.modules.fragment.NewModuleFragmentOp)3 OverrideFilePath (com.liferay.ide.project.core.modules.fragment.OverrideFilePath)3 IRuntime (org.eclipse.wst.server.core.IRuntime)3 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Status (org.eclipse.sapphire.modeling.Status)2 IRuntimeWorkingCopy (org.eclipse.wst.server.core.IRuntimeWorkingCopy)2 Test (org.junit.Test)2 NewModuleFragmentFilesOp (com.liferay.ide.project.core.modules.fragment.NewModuleFragmentFilesOp)1 File (java.io.File)1 IPath (org.eclipse.core.runtime.IPath)1 Element (org.eclipse.sapphire.Element)1