Search in sources :

Example 1 with LocationURI

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

the class WorkspaceArtifactsGeneratorVisitor method visitProject.

public void visitProject(final Project entity) {
    // unset the default folder
    env().wUnset("folder");
    env().wEnterScope();
    if (!Matcher.matchImplAndBind(ArtifactsEntityDescriptorEnum.Name, entity.getName(), env(), "projectName"))
        throw new VisitException("No Project name");
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot workspaceRoot = workspace.getRoot();
    String projectName = env().wStringValue("projectName");
    IProject project = workspaceRoot.getProject(projectName);
    try {
        if (!project.exists()) {
            LocationURI locationURI = entity.getLocationURI();
            if (DataTypeUtils.getDataKind(locationURI).isString()) {
                try {
                    IProjectDescription description = workspace.newProjectDescription(projectName);
                    description.setLocationURI(new URI(locationURI.getValue()));
                    project.create(description, progressMonitor());
                } catch (Exception e) {
                    throw new VisitException(e);
                }
            } else
                project.create(progressMonitor());
        }
        project.open(progressMonitor());
        env().wDefValue("project", project);
        entity.getNatures().accept(this);
        entity.getMetadata().accept(this);
        if (project.hasNature(JavaCore.NATURE_ID))
            env().wDefValue("javaProject", JavaCore.create(project));
        entity.getArtifacts().accept(this);
    } catch (CoreException e) {
        throw new VisitException(e);
    }
    env().wExitScope();
}
Also used : LocationURI(org.whole.lang.artifacts.model.LocationURI) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) URI(java.net.URI) LocationURI(org.whole.lang.artifacts.model.LocationURI) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException)

Example 2 with LocationURI

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

the class ResourceArtifactsGeneratorVisitor method visit.

public void visit(Project entity) {
    LocationURI locationURI = entity.getLocationURI();
    if (DataTypeUtils.getDataKind(locationURI).isString() || env().wIsSet("folder") || env().wIsSet("folderLocation")) {
        env().wEnterScope();
        if (!Matcher.matchImplAndBind(ArtifactsEntityDescriptorEnum.Name, entity.getName(), env(), "projectName"))
            throw new VisitException("No project name");
        entity.getMetadata().accept(this);
        File folder;
        if (DataTypeUtils.getDataKind(locationURI).isString()) {
            try {
                folder = new File(new URI(locationURI.getValue()));
            } catch (URISyntaxException e) {
                throw new IllegalArgumentException("Invalid project location URI specified", e);
            }
        } else {
            File parentFolder = getParentFolder();
            String path = parentFolder.getAbsolutePath();
            String projectPath = path + File.separatorChar + env().wStringValue("projectName");
            folder = new File(projectPath);
        }
        if (!folder.exists())
            folder.mkdirs();
        env().wDefValue("folder", folder);
        entity.getNatures().accept(this);
        entity.getArtifacts().accept(this);
        env().wExitScope();
    } else
        throw new IllegalStateException("Project generation not supported yet");
}
Also used : LocationURI(org.whole.lang.artifacts.model.LocationURI) VisitException(org.whole.lang.visitors.VisitException) URISyntaxException(java.net.URISyntaxException) File(java.io.File) LocationURI(org.whole.lang.artifacts.model.LocationURI) URI(java.net.URI)

Aggregations

URI (java.net.URI)2 LocationURI (org.whole.lang.artifacts.model.LocationURI)2 File (java.io.File)1 URISyntaxException (java.net.URISyntaxException)1 IProject (org.eclipse.core.resources.IProject)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1 VisitException (org.whole.lang.visitors.VisitException)1