Search in sources :

Example 1 with FolderArtifact

use of org.whole.lang.artifacts.model.FolderArtifact in project whole by wholeplatform.

the class ArtifactsWorkspaceUtils method toArtifactsPath.

public static IEntity toArtifactsPath(IResource fromResource, IResource toResource, IEntity child) {
    ArtifactsEntityFactory aef = ArtifactsEntityFactory.instance(RegistryConfigurations.RESOLVER);
    IEntity entity;
    String name = toResource.getName();
    switch(toResource.getType()) {
        case IResource.FILE:
            FileArtifact fileArtifact = aef.createFileArtifact();
            fileArtifact.setName(createFileName(name));
            entity = fileArtifact;
            break;
        case IResource.FOLDER:
            FolderArtifact folderArtifact = aef.createFolderArtifact();
            folderArtifact.setName(aef.createName(name));
            folderArtifact.setArtifacts(aef.createArtifacts(0));
            entity = folderArtifact;
            break;
        case IResource.PROJECT:
            Project project = aef.createProject();
            project.setName(aef.createName(name));
            project.setArtifacts(aef.createArtifacts(0));
            entity = project;
            break;
        default:
        case IResource.ROOT:
            Workspace workspace = aef.createWorkspace();
            workspace.setProjects(aef.createProjects(0));
            entity = workspace;
            break;
    }
    boolean isWorkspace = Matcher.match(ArtifactsEntityDescriptorEnum.Workspace, entity);
    if (!EntityUtils.isNull(child))
        entity.wGet(isWorkspace ? ArtifactsFeatureDescriptorEnum.projects : ArtifactsFeatureDescriptorEnum.artifacts).wAdd(child);
    return fromResource.equals(toResource) ? entity : toArtifactsPath(fromResource, toResource.getParent(), entity);
}
Also used : ArtifactsEntityFactory(org.whole.lang.artifacts.factories.ArtifactsEntityFactory) Project(org.whole.lang.artifacts.model.Project) IProject(org.eclipse.core.resources.IProject) IEntity(org.whole.lang.model.IEntity) FileArtifact(org.whole.lang.artifacts.model.FileArtifact) FolderArtifact(org.whole.lang.artifacts.model.FolderArtifact) Workspace(org.whole.lang.artifacts.model.Workspace)

Example 2 with FolderArtifact

use of org.whole.lang.artifacts.model.FolderArtifact in project whole by wholeplatform.

the class ArtifactsWorkspaceUtils method toArtifactsPath.

public static IEntity toArtifactsPath(IJavaElement fromJavaElement, IResource toResource) {
    ArtifactsEntityFactory aef = ArtifactsEntityFactory.instance(RegistryConfigurations.RESOLVER);
    Artifact child;
    if (toResource.getType() == IResource.FILE) {
        FileArtifact fileArtifact = aef.createFileArtifact();
        fileArtifact.setName(createFileName(toResource.getName()));
        child = fileArtifact;
    } else {
        FolderArtifact folderArtifact = aef.createFolderArtifact();
        folderArtifact.setName(aef.createName(toResource.getName()));
        child = folderArtifact;
    }
    return toArtifactsPath(fromJavaElement, JavaCore.create(toResource.getParent()), child);
}
Also used : ArtifactsEntityFactory(org.whole.lang.artifacts.factories.ArtifactsEntityFactory) FileArtifact(org.whole.lang.artifacts.model.FileArtifact) FolderArtifact(org.whole.lang.artifacts.model.FolderArtifact) FileArtifact(org.whole.lang.artifacts.model.FileArtifact) Artifact(org.whole.lang.artifacts.model.Artifact) PackageArtifact(org.whole.lang.artifacts.model.PackageArtifact) FolderArtifact(org.whole.lang.artifacts.model.FolderArtifact)

Example 3 with FolderArtifact

use of org.whole.lang.artifacts.model.FolderArtifact in project whole by wholeplatform.

the class ArtifactsWorkspaceUtils method getArtifacts.

public static IEntity getArtifacts(IEntity artifact) {
    ArtifactsEntityFactory aef = ArtifactsEntityFactory.instance(RegistryConfigurations.RESOLVER);
    IEntity children = BindingManagerFactory.instance.createTuple();
    if (Matcher.match(ArtifactsEntityDescriptorEnum.Workspace, artifact)) {
        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
        for (IProject project : workspaceRoot.getProjects()) {
            Project projectArtifact = aef.createProject();
            projectArtifact.setName(aef.createName(project.getName()));
            projectArtifact.setArtifacts(aef.createArtifacts(0));
            children.wAdd(projectArtifact);
        }
    } else {
        try {
            IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
            bindPath(artifact, bindings, false);
            IContainer container = (IContainer) (bindings.wIsSet("folder") ? bindings.wGetValue("folder") : bindings.wGetValue("project"));
            IJavaElement javaContainer = JavaCore.create(container);
            if (javaContainer == null || javaContainer.getElementType() == IJavaElement.JAVA_PROJECT) {
                for (IResource resource : container.members()) {
                    if (resource.getType() == IResource.FILE) {
                        appendFileArtifact(((IFile) resource).getName(), children);
                    } else {
                        FolderArtifact folderArtifact = aef.createFolderArtifact();
                        Metadata metadata = aef.createMetadata();
                        metadata.setAttributes(aef.createAttributes(aef.createAttribute(AttributeEnum.source)));
                        folderArtifact.setMetadata(metadata);
                        folderArtifact.setName(aef.createName(StringUtils.getFileName(resource.getName())));
                        folderArtifact.setArtifacts(aef.createArtifacts(0));
                        children.wAdd(folderArtifact);
                    }
                }
            } else {
                if (javaContainer.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) {
                    IPackageFragmentRoot fragmentRoot = (IPackageFragmentRoot) javaContainer;
                    if (fragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
                        for (IJavaElement element : fragmentRoot.getChildren()) {
                            if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
                                if (element.getElementName() == IPackageFragment.DEFAULT_PACKAGE_NAME) {
                                    appendPackageFragmentChildren((IPackageFragment) element, children);
                                } else {
                                    PackageArtifact packageArtifact = aef.createPackageArtifact();
                                    packageArtifact.setName(aef.createName(StringUtils.getFileName(element.getElementName())));
                                    packageArtifact.setArtifacts(aef.createArtifacts(0));
                                    children.wAdd(packageArtifact);
                                }
                            }
                        }
                    }
                } else
                    // IJavaElement.PACKAGE_FRAGMENT
                    appendPackageFragmentChildren((IPackageFragment) javaContainer, children);
            }
        } catch (Exception e) {
        }
    }
    return children;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IEntity(org.whole.lang.model.IEntity) Metadata(org.whole.lang.artifacts.model.Metadata) FolderArtifact(org.whole.lang.artifacts.model.FolderArtifact) IProject(org.eclipse.core.resources.IProject) PackageArtifact(org.whole.lang.artifacts.model.PackageArtifact) CoreException(org.eclipse.core.runtime.CoreException) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) ArtifactsEntityFactory(org.whole.lang.artifacts.factories.ArtifactsEntityFactory) Project(org.whole.lang.artifacts.model.Project) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IBindingManager(org.whole.lang.bindings.IBindingManager) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 4 with FolderArtifact

use of org.whole.lang.artifacts.model.FolderArtifact in project whole by wholeplatform.

the class ResourceTemplateTest method testSubtreeArtifacts.

@Test
public void testSubtreeArtifacts() {
    File testfolder = new File("data/testfolder");
    File testsubfolder = new File("data/testfolder/subfolder");
    ResourceTemplate template = new ResourceTemplate(testfolder);
    ModelBuilderOperation op = new ModelBuilderOperation();
    template.apply(op);
    IEntity testFolder = op.wGetResult();
    template = new ResourceTemplate(testsubfolder);
    op = new ModelBuilderOperation();
    template.apply(op);
    IEntity testSubFolder = op.wGetResult();
    FolderArtifact compareTo = null;
    IEntityIterator<FolderArtifact> iterator = IteratorFactory.<FolderArtifact>childMatcherIterator().withPattern(ArtifactsEntityDescriptorEnum.FolderArtifact);
    iterator.reset(testFolder.wGet(ArtifactsFeatureDescriptorEnum.artifacts));
    while (iterator.hasNext()) {
        FolderArtifact folder = iterator.next();
        if (folder.getName().wEquals(testSubFolder.wGet(ArtifactsFeatureDescriptorEnum.name))) {
            compareTo = folder;
            break;
        }
    }
    assertNotNull(compareTo);
    assertTrue(OrderedMatcher.match(testSubFolder, compareTo, comparatorsMap));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) ResourceTemplate(org.whole.lang.artifacts.templates.ResourceTemplate) FolderArtifact(org.whole.lang.artifacts.model.FolderArtifact) File(java.io.File) Test(org.junit.Test)

Example 5 with FolderArtifact

use of org.whole.lang.artifacts.model.FolderArtifact in project whole by wholeplatform.

the class ArtifactsWorkspaceUtils method toArtifactsPath.

public static IEntity toArtifactsPath(IJavaElement fromJavaElement, IJavaElement toJavaElement, IEntity child) {
    ArtifactsEntityFactory aef = ArtifactsEntityFactory.instance(RegistryConfigurations.RESOLVER);
    IEntity entity;
    String name = toJavaElement.getElementName();
    switch(toJavaElement.getElementType()) {
        case IJavaElement.COMPILATION_UNIT:
            FileArtifact fileArtifact = aef.createFileArtifact();
            fileArtifact.setName(createFileName(name));
            entity = fileArtifact;
            break;
        case IJavaElement.PACKAGE_FRAGMENT:
            if (name == IPackageFragment.DEFAULT_PACKAGE_NAME)
                return fromJavaElement.equals(toJavaElement) ? child : toArtifactsPath(fromJavaElement, toJavaElement.getParent(), child);
            PackageArtifact packageArtifact = aef.createPackageArtifact();
            packageArtifact.setName(aef.createName(name));
            entity = packageArtifact;
            break;
        case IJavaElement.PACKAGE_FRAGMENT_ROOT:
            FolderArtifact folderArtifact = aef.createFolderArtifact();
            Metadata metadata = aef.createMetadata();
            metadata.setAttributes(aef.createAttributes(aef.createAttribute(AttributeEnum.source)));
            folderArtifact.setMetadata(metadata);
            folderArtifact.setName(aef.createName(name));
            entity = folderArtifact;
            break;
        case IJavaElement.JAVA_PROJECT:
            Project project = aef.createProject();
            project.setName(aef.createName(name));
            project.setNatures(aef.createNatures(aef.createNature("org.eclipse.jdt.core.javanature")));
            project.setArtifacts(aef.createArtifacts(0));
            entity = project;
            break;
        default:
        case IJavaElement.JAVA_MODEL:
            Workspace workspace = aef.createWorkspace();
            workspace.setProjects(aef.createProjects(0));
            entity = workspace;
            break;
    }
    boolean isWorkspace = Matcher.match(ArtifactsEntityDescriptorEnum.Workspace, entity);
    if (!EntityUtils.isNull(child))
        entity.wGet(isWorkspace ? ArtifactsFeatureDescriptorEnum.projects : ArtifactsFeatureDescriptorEnum.artifacts).wAdd(child);
    return fromJavaElement.equals(toJavaElement) ? entity : toArtifactsPath(fromJavaElement, toJavaElement.getParent(), entity);
}
Also used : ArtifactsEntityFactory(org.whole.lang.artifacts.factories.ArtifactsEntityFactory) Project(org.whole.lang.artifacts.model.Project) IProject(org.eclipse.core.resources.IProject) IEntity(org.whole.lang.model.IEntity) FileArtifact(org.whole.lang.artifacts.model.FileArtifact) Metadata(org.whole.lang.artifacts.model.Metadata) FolderArtifact(org.whole.lang.artifacts.model.FolderArtifact) PackageArtifact(org.whole.lang.artifacts.model.PackageArtifact) Workspace(org.whole.lang.artifacts.model.Workspace)

Aggregations

FolderArtifact (org.whole.lang.artifacts.model.FolderArtifact)5 ArtifactsEntityFactory (org.whole.lang.artifacts.factories.ArtifactsEntityFactory)4 IEntity (org.whole.lang.model.IEntity)4 IProject (org.eclipse.core.resources.IProject)3 FileArtifact (org.whole.lang.artifacts.model.FileArtifact)3 PackageArtifact (org.whole.lang.artifacts.model.PackageArtifact)3 Project (org.whole.lang.artifacts.model.Project)3 Metadata (org.whole.lang.artifacts.model.Metadata)2 Workspace (org.whole.lang.artifacts.model.Workspace)2 File (java.io.File)1 IContainer (org.eclipse.core.resources.IContainer)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 Test (org.junit.Test)1 Artifact (org.whole.lang.artifacts.model.Artifact)1 ResourceTemplate (org.whole.lang.artifacts.templates.ResourceTemplate)1