use of com.liferay.ide.core.ILiferayProjectImporter in project liferay-ide by liferay.
the class ImportLiferayModuleProjectOpMethods method getBuildType.
public static IStatus getBuildType(String location) {
IStatus retval = null;
ILiferayProjectImporter[] importers = LiferayCore.getImporters();
for (ILiferayProjectImporter importer : importers) {
IStatus status = importer.canImport(location);
if (status == null) {
retval = ProjectCore.createErrorStatus("Location is not recognized as a valid project type.");
} else if (status.isOK()) {
retval = StatusBridge.create(Status.createStatus(Severity.OK, importer.getBuildType()));
break;
} else if (status.getSeverity() == IStatus.ERROR) {
retval = StatusBridge.create(Status.createStatus(Severity.ERROR, status.getMessage()));
break;
} else if (status.getSeverity() == IStatus.WARNING) {
retval = StatusBridge.create(Status.createStatus(Severity.WARNING, status.getMessage()));
break;
}
}
if (retval == null) {
retval = StatusBridge.create(Status.createStatus(Severity.ERROR, "No project importers found."));
}
return retval;
}
use of com.liferay.ide.core.ILiferayProjectImporter in project liferay-ide by liferay.
the class WorkspaceHelper method openDir.
@Override
public String openDir(String path) {
String retval = null;
File dir = new File(path);
if (!dir.exists() || !dir.isDirectory()) {
retval = "Directory doesn't exist or isn't a directory.";
}
File dotProject = new File(dir, ".project");
if (dotProject.exists()) {
retval = _importExistingProject(dir);
} else {
for (ILiferayProjectImporter importer : LiferayCore.getImporters()) {
try {
IStatus importStatus = importer.canImport(dir.getCanonicalPath());
if ((importStatus != null) && importStatus.isOK()) {
UIUtil.async(new Runnable() {
@Override
public void run() {
try {
new ProgressMonitorDialog(UIUtil.getActiveShell()).run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
try {
importer.importProjects(path, monitor);
} catch (CoreException ce) {
LiferayUIPlugin.logError("Error opening project", ce);
}
}
});
} catch (InterruptedException | InvocationTargetException e) {
}
}
});
return retval;
}
} catch (Exception e) {
}
}
retval = "Directory must have a .project file to open.";
}
return retval;
}
use of com.liferay.ide.core.ILiferayProjectImporter in project liferay-ide by liferay.
the class NewLiferayJSFModuleProjectOpTests method importWorkspaceProject.
private void importWorkspaceProject(String name) throws Exception {
final URL projectZipUrl = Platform.getBundle("com.liferay.ide.maven.core.tests").getEntry("projects/" + name + ".zip");
final File projectZipFile = new File(FileLocator.toFileURL(projectZipUrl).getFile());
IPath wordkspaceProjectLocation = CoreUtil.getWorkspaceRoot().getLocation();
ZipUtil.unzip(projectZipFile, wordkspaceProjectLocation.toFile());
final IPath projectFolder = wordkspaceProjectLocation.append(name);
assertEquals(true, projectFolder.toFile().exists());
ILiferayProjectImporter gradleImporter = LiferayCore.getImporter("gradle");
gradleImporter.importProjects(projectFolder.toOSString(), new NullProgressMonitor());
IProject workspaceProject = CoreUtil.getProject("testWorkspace");
assertNotNull(workspaceProject);
}
use of com.liferay.ide.core.ILiferayProjectImporter in project liferay-ide by liferay.
the class NewGradleJSFModuleProjectProvider method createNewProject.
@Override
public IStatus createNewProject(NewLiferayJSFModuleProjectOp op, IProgressMonitor monitor) throws CoreException {
IStatus retval = Status.OK_STATUS;
try {
IPath projectLocation = createArchetypeProject(op, monitor);
IPath buildGradlePath = projectLocation.append("build.gradle");
if (FileUtil.exists(buildGradlePath)) {
try {
File workspaceDir = LiferayWorkspaceUtil.getWorkspaceDir(buildGradlePath.toFile());
if (FileUtil.exists(workspaceDir)) {
boolean hasLiferayWorkspace = LiferayWorkspaceUtil.isValidWorkspaceLocation(workspaceDir.getAbsolutePath());
if (hasLiferayWorkspace) {
List<String> buildGradleContents = Files.readAllLines(Paths.get(buildGradlePath.toFile().toURI()), StandardCharsets.UTF_8);
List<String> modifyContents = new ArrayList<>();
for (String line : buildGradleContents) {
if (_PATTERN_LIFERAY_WAR_PLUGIN.matcher(line).matches()) {
continue;
}
modifyContents.add(line);
}
Files.write(buildGradlePath.toFile().toPath(), modifyContents, StandardCharsets.UTF_8);
}
}
} catch (Exception e) {
ProjectCore.logError("Failed to check LiferayWorkspace project. ");
}
}
IPath buildPom = projectLocation.append("pom.xml");
if (FileUtil.exists(buildPom)) {
buildPom.toFile().delete();
}
ILiferayProjectImporter importer = LiferayCore.getImporter("gradle");
IStatus canImport = importer.canImport(projectLocation.toOSString());
if (canImport.getCode() != Status.ERROR) {
importer.importProjects(projectLocation.toOSString(), monitor);
}
} catch (Exception e) {
throw new CoreException(LiferayCore.createErrorStatus(e));
}
return retval;
}
Aggregations