Search in sources :

Example 6 with ArtifactsEntityFactory

use of org.whole.lang.artifacts.factories.ArtifactsEntityFactory in project whole by wholeplatform.

the class ArtifactsWorkspaceUtils method createFileName.

protected static FileName createFileName(String nameWithExtension) {
    ArtifactsEntityFactory aef = ArtifactsEntityFactory.instance(RegistryConfigurations.RESOLVER);
    String fileName = StringUtils.stripFileExtension(nameWithExtension);
    String extension = StringUtils.getFileExtension(nameWithExtension);
    if (fileName.length() > 0)
        return aef.createNameWithExtension(aef.createName(fileName), aef.createExtension(extension));
    else
        return aef.createName('.' + extension);
}
Also used : ArtifactsEntityFactory(org.whole.lang.artifacts.factories.ArtifactsEntityFactory)

Example 7 with ArtifactsEntityFactory

use of org.whole.lang.artifacts.factories.ArtifactsEntityFactory 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

ArtifactsEntityFactory (org.whole.lang.artifacts.factories.ArtifactsEntityFactory)7 FileArtifact (org.whole.lang.artifacts.model.FileArtifact)4 FolderArtifact (org.whole.lang.artifacts.model.FolderArtifact)4 IEntity (org.whole.lang.model.IEntity)4 IProject (org.eclipse.core.resources.IProject)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