Search in sources :

Example 1 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class WorkspaceWizardModelValidator method validateSourceFolder.

private void validateSourceFolder() throws ValidationException {
    this.setSourceFolderValid(false);
    // 1. The source folder property must not be empty
    String sourceFolder = getModel().getSourceFolder().removeTrailingSeparator().toString();
    if (sourceFolder.trim().isEmpty()) {
        throw new ValidationException(ErrorMessages.SOURCE_FOLDER_MUST_NOT_BE_EMPTY, WorkspaceWizardModel.SOURCE_FOLDER_PROPERTY);
    }
    // 2. All segments of the source folder path must be valid folder names
    if (!WorkspaceWizardValidatorUtils.isValidFolderPath(getModel().getSourceFolder())) {
        throw new ValidationException(ErrorMessages.SOURCE_FOLDER_IS_NOT_A_VALID_FOLDER_NAME, WorkspaceWizardModel.SOURCE_FOLDER_PROPERTY);
    }
    // 3. The source folder must be a valid {@link IN4JSSourceContainer}
    // The source container must exist, and not be of type external or library
    URI projectUri = URI.createPlatformResourceURI(getModel().getProject().segment(0), true);
    IN4JSProject project = n4jsCore.findProject(projectUri).orNull();
    if (null == project) {
        throw new ValidationException(ErrorMessages.INVALID_STATE_VALIDATION_ERROR);
    }
    if (project.getSourceContainers().stream().filter(// Filter source type
    src -> (src.isSource() || src.isTest())).filter(// Filter name
    src -> src.getRelativeLocation().equals(sourceFolder)).count() == 0)
        throw new ValidationException(ErrorMessages.SOURCE_FOLDER_DOES_NOT_EXIST, WorkspaceWizardModel.SOURCE_FOLDER_PROPERTY);
    this.setSourceFolderValid(true);
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) URI(org.eclipse.emf.common.util.URI) Optional(com.google.common.base.Optional) Inject(com.google.inject.Inject) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) PropertyChangeSupport(java.beans.PropertyChangeSupport) IN4JSCore(org.eclipse.n4js.projectModel.IN4JSCore) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) URI(org.eclipse.emf.common.util.URI)

Example 2 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class SourceFolderContentProposalProviderFactory method createProviderForProject.

/**
 * Returns a source folder proposal provider for the given project.
 *
 * @param contextProject
 *            The project to look for source folders
 * @return The provider
 */
public IContentProposalProvider createProviderForProject(IProject contextProject) {
    if (null == contextProject) {
        return null;
    }
    IN4JSProject n4Project = StreamSupport.stream(n4jsCore.findAllProjects().spliterator(), false).filter(// Filter for the context
    project -> project.getProjectId().equals(contextProject.getName())).findAny().orElse(null);
    if (n4Project == null) {
        return null;
    }
    SimpleContentProposalProvider provider = new SimpleContentProposalProvider(n4Project.getSourceContainers().stream().map(src -> src.getRelativeLocation()).toArray(String[]::new));
    provider.setFiltering(true);
    return provider;
}
Also used : SimpleContentProposalProvider(org.eclipse.jface.fieldassist.SimpleContentProposalProvider) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Example 3 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class AbstractN4JSCoreTest method testCreateYieldsDifferentInstances.

@SuppressWarnings("javadoc")
@Test
public void testCreateYieldsDifferentInstances() {
    IN4JSProject first = getN4JSCore().create(myProjectURI);
    IN4JSProject second = getN4JSCore().create(myProjectURI);
    assertNotSame(first, second);
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) Test(org.junit.Test)

Example 4 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class AbstractN4JSCoreTest method testProjectId_02.

@SuppressWarnings("javadoc")
@Test
public void testProjectId_02() {
    IN4JSProject project = getN4JSCore().create(myProjectURI);
    assertNotNull(project);
    assertEquals(myProjectId, project.getProjectId());
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) Test(org.junit.Test)

Example 5 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class AbstractN4JSCoreTest method testProjectId_01.

@SuppressWarnings("javadoc")
@Test
public void testProjectId_01() {
    IN4JSProject project = getN4JSCore().create(myProjectURI.trimSegments(1).appendSegment("doesNotExist"));
    assertNotNull(project);
    assertEquals("doesNotExist", project.getProjectId());
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) Test(org.junit.Test)

Aggregations

IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)93 URI (org.eclipse.emf.common.util.URI)32 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)13 List (java.util.List)11 Inject (com.google.inject.Inject)9 Map (java.util.Map)9 IProject (org.eclipse.core.resources.IProject)9 IN4JSCore (org.eclipse.n4js.projectModel.IN4JSCore)9 Optional (com.google.common.base.Optional)7 File (java.io.File)7 Collection (java.util.Collection)7 HashSet (java.util.HashSet)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 IOException (java.io.IOException)5 IN4JSArchive (org.eclipse.n4js.projectModel.IN4JSArchive)5 IN4JSSourceContainer (org.eclipse.n4js.projectModel.IN4JSSourceContainer)5 FluentIterable.from (com.google.common.collect.FluentIterable.from)4