Search in sources :

Example 1 with CustomModel

use of com.liferay.blade.gradle.model.CustomModel in project liferay-ide by liferay.

the class GradleProjectTests method toolingApiCustomModel.

@Test
public void toolingApiCustomModel() throws Exception {
    LiferayGradleProject gradleProject = Util.fullImportGradleProject("projects/customModel");
    assertNotNull(gradleProject);
    CustomModel customModel = GradleCore.getToolingModel(CustomModel.class, gradleProject.getProject());
    assertNotNull(customModel);
    assertFalse(customModel.hasPlugin("not.a.plugin"));
    assertTrue(customModel.hasPlugin("org.dm.gradle.plugins.bundle.BundlePlugin"));
}
Also used : LiferayGradleProject(com.liferay.ide.gradle.core.LiferayGradleProject) CustomModel(com.liferay.blade.gradle.model.CustomModel) Test(org.junit.Test)

Example 2 with CustomModel

use of com.liferay.blade.gradle.model.CustomModel in project liferay-ide by liferay.

the class GradleProjectCreatedListener method _configureIfLiferayProject.

private void _configureIfLiferayProject(final IProject project) throws CoreException {
    if (GradleProjectNature.isPresentOn(project) && !LiferayNature.hasNature(project)) {
        final boolean[] needAddNature = new boolean[1];
        needAddNature[0] = false;
        IFile bndFile = project.getFile("bnd.bnd");
        if (FileUtil.exists(bndFile)) {
            needAddNature[0] = true;
        } else if (ProjectUtil.isWorkspaceWars(project)) {
            needAddNature[0] = true;
        } else {
            IFile gulpFile = project.getFile("gulpfile.js");
            if (FileUtil.exists(gulpFile)) {
                String gulpFileContent;
                File file = gulpFile.getLocation().toFile();
                try {
                    gulpFileContent = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
                    if (gulpFileContent.contains("require('liferay-theme-tasks')")) {
                        needAddNature[0] = true;
                    }
                } catch (IOException ioe) {
                    GradleCore.logError("read gulpfile.js file fail", ioe);
                }
            }
        }
        Job job = new WorkspaceJob("Checking gradle configuration") {

            @Override
            public boolean belongsTo(Object family) {
                if ((family != null) && family.toString().equals(GradleCore.JobFamilyId)) {
                    return true;
                }
                return false;
            }

            @Override
            public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                try {
                    if (needAddNature[0]) {
                        LiferayNature.addLiferayNature(project, monitor);
                        return Status.OK_STATUS;
                    }
                    final CustomModel customModel = GradleCore.getToolingModel(CustomModel.class, project);
                    if (customModel == null) {
                        throw new CoreException(GradleCore.createErrorStatus("Unable to get read gradle configuration"));
                    }
                    if (customModel.isLiferayModule() || customModel.hasPlugin("org.gradle.api.plugins.WarPlugin") || customModel.hasPlugin("com.liferay.gradle.plugins.theme.builder.ThemeBuilderPlugin")) {
                        LiferayNature.addLiferayNature(project, monitor);
                    }
                } catch (Exception e) {
                    GradleCore.logError("Unable to get tooling model", e);
                }
                return Status.OK_STATUS;
            }
        };
        job.setRule(CoreUtil.getWorkspaceRoot());
        job.schedule();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IOException(java.io.IOException) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) File(java.io.File) IFile(org.eclipse.core.resources.IFile) CustomModel(com.liferay.blade.gradle.model.CustomModel) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException)

Example 3 with CustomModel

use of com.liferay.blade.gradle.model.CustomModel in project liferay-ide by liferay.

the class LiferayGradleProject method getOutputBundlePath.

@Override
public IPath getOutputBundlePath() {
    IProject gradleProject = getProject();
    IPath buildLocation = gradleProject.getLocation().append("build/libs");
    File buildFolder = buildLocation.toFile();
    String[] fileNames = buildFolder.list();
    if ((fileNames != null) && (fileNames.length == 1)) {
        File outputFile = new File(buildFolder, fileNames[0]);
        return new Path(outputFile.getAbsolutePath());
    } else {
        IPath gradleProjectLocation = gradleProject.getLocation();
        File nodeThemeOutput = gradleProjectLocation.append("dist/" + gradleProject.getName() + ".war").toFile();
        if (FileUtil.exists(nodeThemeOutput)) {
            return new Path(nodeThemeOutput.getAbsolutePath());
        } else {
            // using CustomModel if can't find output
            IPath retval = null;
            CustomModel model = GradleCore.getToolingModel(CustomModel.class, gradleProject);
            Set<File> outputFiles = model.getOutputFiles();
            if (ListUtil.isNotEmpty(outputFiles)) {
                // first check to see if there are any outputfiles that are wars, if so use that
                // one.
                File bundleFile = null;
                for (File outputFile : outputFiles) {
                    if (outputFile.getName().endsWith(".war")) {
                        bundleFile = outputFile;
                        break;
                    }
                }
                if (bundleFile == null) {
                    for (File outputFile : outputFiles) {
                        final String name = outputFile.getName();
                        if (name.endsWith("javadoc.jar") || name.endsWith("jspc.jar") || name.endsWith("sources.jar")) {
                            continue;
                        }
                        if (name.endsWith(".jar")) {
                            bundleFile = outputFile;
                            break;
                        }
                    }
                }
                if (bundleFile != null) {
                    retval = new Path(bundleFile.getAbsolutePath());
                }
            } else if (model.hasPlugin("com.liferay.gradle.plugins.gulp.GulpPlugin")) {
                retval = gradleProject.getLocation().append("dist/" + gradleProject.getName() + ".war");
            }
            return retval;
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) CustomModel(com.liferay.blade.gradle.model.CustomModel)

Aggregations

CustomModel (com.liferay.blade.gradle.model.CustomModel)3 File (java.io.File)2 IFile (org.eclipse.core.resources.IFile)2 LiferayGradleProject (com.liferay.ide.gradle.core.LiferayGradleProject)1 IOException (java.io.IOException)1 IProject (org.eclipse.core.resources.IProject)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 Job (org.eclipse.core.runtime.jobs.Job)1 Test (org.junit.Test)1