Search in sources :

Example 1 with FilePersistenceProvider

use of org.whole.lang.codebase.FilePersistenceProvider in project whole by wholeplatform.

the class ReusablesDynamicCompilerVisitor method visit.

@Override
public void visit(FileSystem entity) {
    entity.getPersistence().accept(this);
    IEntityIterator<?> persistenceIterator = getResultIterator();
    entity.getContent().accept(this);
    IEntityIterator<?> contentIterator = getResultIterator();
    setResultIterator(IteratorFactory.composeIterator(IteratorFactory.singleValuedRunnableIterator(new ResourcePersistenceRunnable() {

        protected IPersistenceProvider getPersistenceProvider(String path, IBindingManager bm) {
            return new FilePersistenceProvider(new File(path), bm);
        }
    }, new int[] { 0 }, persistenceIterator).withSourceEntity(entity), contentIterator));
}
Also used : FilePersistenceProvider(org.whole.lang.codebase.FilePersistenceProvider) IBindingManager(org.whole.lang.bindings.IBindingManager) File(java.io.File)

Example 2 with FilePersistenceProvider

use of org.whole.lang.codebase.FilePersistenceProvider in project whole by wholeplatform.

the class ResourceArtifactsGeneratorVisitor method visit.

public void visit(FileArtifact entity) {
    env().wEnterScope();
    entity.getName().accept(this);
    if (!env().wIsSet("name"))
        throw new VisitException("No File name");
    String fileNameWithExtension = env().wStringValue("name");
    env().wDefValue("fileNameWithExtension", fileNameWithExtension);
    env().wDefValue("fileName", StringUtils.stripFileExtension(fileNameWithExtension));
    env().wDefValue("fileExtension", StringUtils.getFileExtension(fileNameWithExtension));
    if (fileNameWithExtension.indexOf(File.separatorChar) != -1 || fileNameWithExtension.indexOf('/') != -1)
        throw new VisitException("Invalid File name");
    entity.getMetadata().accept(this);
    File parentFolder = getParentFolder();
    File file = new File(parentFolder.getAbsolutePath() + File.separatorChar + fileNameWithExtension);
    try {
        if (!file.exists())
            file.createNewFile();
        env().wDefValue("persistenceProvider", new FilePersistenceProvider(file, env()));
        IEntity result = InterpreterOperation.interpret(entity.getContent(), env()).getResult();
        if (result != null)
            writeContents(result);
    } catch (IOException e) {
        throw new VisitException(e);
    }
    if (env().wIsSet("derived"))
        // not implemented yet
        ;
    if (env().wIsSet("readonly") && file.canWrite())
        file.setReadOnly();
    env().wExitScope();
}
Also used : FilePersistenceProvider(org.whole.lang.codebase.FilePersistenceProvider) IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException) IOException(java.io.IOException) File(java.io.File)

Example 3 with FilePersistenceProvider

use of org.whole.lang.codebase.FilePersistenceProvider in project whole by wholeplatform.

the class ModelInputFunction method compute.

@Override
public Object compute(IEclipseContext context) {
    final IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
    bm.wDefValue("eclipse#eclipseContext", context);
    final IEditorPart editorPart = context.get(IEditorPart.class);
    final IEditorInput input = context.get(IEditorInput.class);
    if (input instanceof IFileEditorInput) {
        IFile file = ((IFileEditorInput) input).getFile();
        IFilePersistenceProvider pp = new IFilePersistenceProvider(file, bm);
        ModelInput modelInput = new ModelInput(context, pp, calculateBasePersistenceKitId(file));
        if (editorPart != null) {
            String editorId = editorPart.getSite().getId();
            String overridePersistenceKitId = ReflectionFactory.getPersistenceKitFromEditorId(editorId).getId();
            modelInput.setOverridePersistenceKitId(overridePersistenceKitId);
        }
        return modelInput;
    } else if (input instanceof IURIEditorInput) {
        File file = new File(((IURIEditorInput) input).getURI());
        FilePersistenceProvider pp = new FilePersistenceProvider(file, bm);
        ModelInput modelInput = new ModelInput(context, pp, ReflectionFactory.getDefaultPersistenceKit().getId());
        if (editorPart != null) {
            String editorId = editorPart.getSite().getId();
            String overridePersistenceKitId = ReflectionFactory.getPersistenceKitFromEditorId(editorId).getId();
            modelInput.setOverridePersistenceKitId(overridePersistenceKitId);
        }
        return modelInput;
    } else
        return null;
}
Also used : ModelInput(org.whole.lang.e4.ui.input.ModelInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) IFile(org.eclipse.core.resources.IFile) FilePersistenceProvider(org.whole.lang.codebase.FilePersistenceProvider) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IBindingManager(org.whole.lang.bindings.IBindingManager) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IEditorPart(org.eclipse.ui.IEditorPart) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput)

Example 4 with FilePersistenceProvider

use of org.whole.lang.codebase.FilePersistenceProvider in project whole by wholeplatform.

the class WorkflowsInterpreterVisitorTest method testInvokeOperation.

@Test
public void testInvokeOperation() throws Exception {
    IEntity invokeOperationTest = WorkflowsTestTemplateManager.instance().create("invokeOperationTest");
    IBindingManager args = BindingManagerFactory.instance.createArguments();
    TestDecorationManager dm = new TestDecorationManager();
    args.wDefValue("decorationManager", dm);
    StringWriter writer = new StringWriter();
    args.wDefValue("printWriter", new PrintWriter(writer));
    InterpreterOperation.interpret(invokeOperationTest, args);
    Assert.assertTrue(args.wIsSet("model"));
    Assert.assertTrue(args.wIsSet("modelCopy"));
    // validate assertions
    Assert.assertNotNull(dm.messages);
    Assert.assertFalse(dm.messages.isEmpty());
    Assert.assertEquals(1, dm.messages.size());
    Assert.assertTrue(dm.messages.contains("Reference to the undeclared type: IType"));
    // normalize assertions
    IEntity modelCopy = args.wGet("modelCopy");
    Assert.assertFalse(Matcher.match(args.wGet("model"), modelCopy));
    Assert.assertTrue(Matcher.match(args.wGet("model"), NormalizerOperation.normalize(EntityUtils.clone(modelCopy))));
    // pretty print assertions
    String ls = System.getProperty("line.separator");
    String TEXT_MODEL = "model SampleM" + ls + ls + ls + "entity Type types IType" + ls + "    feature DataStr data" + ls + ls + "entity DataStr" + ls + "    value <String>" + ls + ls + "abstract entity IType" + ls;
    Assert.assertEquals(TEXT_MODEL, writer.toString());
    // pretty print assertions
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit("http://lang.whole.org/SampleM");
    Assert.assertNotNull(languageKit);
    EntityDescriptor<? extends IEntity> ed = languageKit.getEntityDescriptorEnum().valueOf("Type");
    Assert.assertNotNull(ed);
    Assert.assertEquals(1, ed.featureSize());
    // generate assertions
    File file = new File("./data/SampleM.xwl");
    Assert.assertTrue(file.exists());
    IEntity entity = XmlBuilderPersistenceKit.instance().readModel(new FilePersistenceProvider(file));
    Assert.assertTrue(Matcher.match(args.wGet("model"), entity));
    Assert.assertFalse(args.wIsSet("fileArtifact"));
}
Also used : StringWriter(java.io.StringWriter) IEntity(org.whole.lang.model.IEntity) FilePersistenceProvider(org.whole.lang.codebase.FilePersistenceProvider) IBindingManager(org.whole.lang.bindings.IBindingManager) File(java.io.File) ILanguageKit(org.whole.lang.reflect.ILanguageKit) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 5 with FilePersistenceProvider

use of org.whole.lang.codebase.FilePersistenceProvider in project whole by wholeplatform.

the class ModelInput method createPersistenceProvider.

public static IPersistenceProvider createPersistenceProvider(IEclipseContext context, String location) {
    final IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
    bm.wDefValue("eclipse#eclipseContext", context);
    try {
        File file = new File(new URI(location));
        return new FilePersistenceProvider(file, bm);
    } catch (Exception e) {
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.fromPortableString(location));
        return new IFilePersistenceProvider(file, bm);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) FilePersistenceProvider(org.whole.lang.codebase.FilePersistenceProvider) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IBindingManager(org.whole.lang.bindings.IBindingManager) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) File(java.io.File) IFile(org.eclipse.core.resources.IFile) URI(java.net.URI)

Aggregations

File (java.io.File)7 FilePersistenceProvider (org.whole.lang.codebase.FilePersistenceProvider)7 IBindingManager (org.whole.lang.bindings.IBindingManager)5 IFile (org.eclipse.core.resources.IFile)3 IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)3 IEntity (org.whole.lang.model.IEntity)3 Test (org.junit.Test)2 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 EditPart (org.eclipse.gef.EditPart)1 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)1 Shell (org.eclipse.swt.widgets.Shell)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IFileEditorInput (org.eclipse.ui.IFileEditorInput)1