public void createDefaultFile(IContainer container, String version, String id, String name) { if (container == null || id == null || name == null) { return; } try { final Path path = new Path("WEB-INF/" + ILiferayConstants.LIFERAY_LOOK_AND_FEEL_XML_FILE); // $NON-NLS-1$ final IFile lookAndFeelFile = container.getFile(path); final String descriptorVersion = getDescriptorVersionFromPortalVersion(version); CoreUtil.prepareFolder((IFolder) lookAndFeelFile.getParent()); String contents = MessageFormat.format( DEFUALT_FILE_TEMPLATE, descriptorVersion, descriptorVersion.replace('.', '_')); contents = contents .replaceAll("__VERSION__", version + "+") .replaceAll("__ID__", id) .replaceAll( //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ "__NAME__", name); // $NON-NLS-1$ lookAndFeelFile.create(new ByteArrayInputStream(contents.getBytes()), true, null); } catch (CoreException e) { ThemeCore.logError("Error creating default descriptor file", e); // $NON-NLS-1$ } }
public static void createEmptyFile(IFile newFile) throws CoreException { if (newFile.getParent() instanceof IFolder) { prepareFolder((IFolder) newFile.getParent()); } newFile.create(new ByteArrayInputStream(new byte[0]), true, null); }
public static void prepareFolder(IFolder folder) throws CoreException { IContainer parent = folder.getParent(); if (parent instanceof IFolder) { prepareFolder((IFolder) parent); } if (!folder.exists()) { folder.create(IResource.FORCE, true, null); } }
private void createServiceXmlFile(String version, boolean useSample) throws Exception { final IProject project = createProject("serviceXmlFiles-" + version + "-" + useSample); final IDataModel model = DataModelFactory.createDataModel(new NewServiceBuilderDataModelProvider()); model.setProperty(NewServiceBuilderDataModelProvider.AUTHOR, "junit"); model.setProperty(NewServiceBuilderDataModelProvider.PACKAGE_PATH, "com.liferay.sample"); model.setProperty(NewServiceBuilderDataModelProvider.NAMESPACE, "SAMPLE"); model.setBooleanProperty(NewServiceBuilderDataModelProvider.USE_SAMPLE_TEMPLATE, useSample); final IFolder folder = project.getFolder("test"); CoreUtil.prepareFolder(folder); final IFile serviceXmlFile = folder.getFile("service.xml"); assertEquals(false, serviceXmlFile.exists()); WizardUtil.createDefaultServiceBuilderFile( serviceXmlFile, version, model.getBooleanProperty(NewServiceBuilderDataModelProvider.USE_SAMPLE_TEMPLATE), model.getStringProperty(NewServiceBuilderDataModelProvider.PACKAGE_PATH), model.getStringProperty(NewServiceBuilderDataModelProvider.NAMESPACE), model.getStringProperty(NewServiceBuilderDataModelProvider.AUTHOR), new NullProgressMonitor()); assertEquals(true, serviceXmlFile.exists()); final String serviceXmlContent = CoreUtil.readStreamToString(serviceXmlFile.getContents()); final String expectedServiceXmlContent = CoreUtil.readStreamToString( this.getClass() .getResourceAsStream("files/service-sample-" + version + "-" + useSample + ".xml")); assertEquals( stripCarriageReturns(expectedServiceXmlContent), stripCarriageReturns(serviceXmlContent)); }