use of org.whole.lang.artifacts.factories.ArtifactsEntityFactory 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);
}
use of org.whole.lang.artifacts.factories.ArtifactsEntityFactory 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);
}
use of org.whole.lang.artifacts.factories.ArtifactsEntityFactory 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;
}
use of org.whole.lang.artifacts.factories.ArtifactsEntityFactory in project whole by wholeplatform.
the class ArtifactsWorkspaceUtils method appendFileArtifact.
protected static void appendFileArtifact(String nameWithExtension, IEntity children) {
ArtifactsEntityFactory aef = ArtifactsEntityFactory.instance(RegistryConfigurations.RESOLVER);
FileArtifact fileArtifact = aef.createFileArtifact();
fileArtifact.setName(createFileName(nameWithExtension));
children.wAdd(fileArtifact);
}
use of org.whole.lang.artifacts.factories.ArtifactsEntityFactory in project whole by wholeplatform.
the class ResourceArtifactsGeneratorTest method test2CompareArtifacts.
@Test
public void test2CompareArtifacts() {
ArtifactsEntityFactory aef = ArtifactsEntityFactory.instance;
File genFolder = new File("data/gen");
ResourceTemplate resourceTemplate = new ResourceTemplate(genFolder);
ModelBuilderOperation mop = new ModelBuilderOperation();
resourceTemplate.apply(mop);
IEntity artifactsRevEng = mop.wGetResult();
IEntity artifactsSubTree = Matcher.find(aef.createFolderArtifact(aef.createName("gen"), CommonsEntityAdapterFactory.createVariable(ArtifactsEntityDescriptorEnum.Metadata, "metadata"), CommonsEntityAdapterFactory.createVariable(ArtifactsEntityDescriptorEnum.Artifacts, "artifacts")), artifacts, false);
assertNotNull(artifactsSubTree);
assertTrue(OrderedMatcher.match(artifactsRevEng, artifactsSubTree, comparatorsMap));
}
Aggregations