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"));
}
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();
}
}
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;
}
}
}
Aggregations