Search in sources :

Example 6 with ErlProject

use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.

the class IErlProjectTest method getExternalIncludes_includeDirs.

@Test
public void getExternalIncludes_includeDirs() throws Exception {
    File externalFile = null;
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final Collection<IPath> includeDirs = aProject.getProperties().getIncludeDirs();
    try {
        // given
        // an erlang project and an external file not in any project, but on
        // the include-path
        final String externalFileName = "external.hrl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-define(E, hej).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        final List<IPath> newIncludeDirs = Lists.newArrayList(includeDirs);
        aProject.open(null);
        final Collection<IErlModule> otpIncludes = aProject.getExternalIncludes();
        final IPath absoluteDir = new Path(absolutePath).removeLastSegments(1);
        newIncludeDirs.add(absoluteDir);
        ((ErlProject) aProject).setIncludeDirs(newIncludeDirs);
        aProject.open(null);
        // when
        // fetching all external includes
        final Collection<IErlModule> externalIncludes = aProject.getExternalIncludes();
        // then
        // the external file should be returned
        final Set<IErlModule> otpSet = Sets.newHashSet(otpIncludes);
        final Set<IErlModule> externalSet = Sets.newHashSet(externalIncludes);
        final Set<IErlModule> difference = Sets.difference(externalSet, otpSet);
        final IErlModule externalInclude = difference.iterator().next();
        assertNotNull(externalInclude);
        assertEquals(absolutePath, externalInclude.getFilePath());
    } finally {
        if (externalFile != null && externalFile.exists()) {
            externalFile.delete();
        }
        ((ErlProject) aProject).setIncludeDirs(includeDirs);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) File(java.io.File) Test(org.junit.Test)

Example 7 with ErlProject

use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.

the class IErlProjectTest method getExternalModules.

// Collection<IErlModule> getExternalModules() throws ErlModelException;
// void setExternalModulesFile(String absolutePath)
// throws BackingStoreException;
@Test
public void getExternalModules() throws Exception {
    File externalFile = null;
    File externalsFile = null;
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final String externalModulesString = aProject.getProperties().getExternalModules();
    try {
        // given
        // an erlang project and an external file not in any project
        final String externalFileName = "external6.erl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-module(external6).\nf([_ | _]=L ->\n    atom_to_list(L).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        externalsFile = ErlideTestUtils.createTmpFile(IErlProjectTest.XX_ERLIDEX, absolutePath);
        aProject.open(null);
        final Collection<IErlModule> otpModules = aProject.getExternalModules();
        ((ErlProject) aProject).setExternalModulesFile(externalsFile.getAbsolutePath());
        aProject.open(null);
        // when
        // fetching all external modules
        final Collection<IErlModule> externalModules = aProject.getExternalModules();
        // then
        // the external file should be returned
        final Set<IErlModule> otpSet = Sets.newHashSet(otpModules);
        final Set<IErlModule> externalSet = Sets.newHashSet(externalModules);
        final Set<IErlModule> difference = Sets.difference(externalSet, otpSet);
        assertEquals(1, difference.size());
        final IErlModule externalModule = difference.iterator().next();
        assertNotNull(externalModule);
        assertEquals(absolutePath, externalModule.getFilePath());
    } finally {
        if (externalFile != null && externalFile.exists()) {
            externalFile.delete();
        }
        if (externalsFile != null && externalsFile.exists()) {
            externalsFile.delete();
        }
        ((ErlProject) aProject).setExternalModulesFile(externalModulesString);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) File(java.io.File) Test(org.junit.Test)

Example 8 with ErlProject

use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.

the class IErlProjectTest method getExternalIncludesString.

// String getExternalIncludesString();
@Test
public void getExternalIncludesString() throws Exception {
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final String externalIncludesString = aProject.getProperties().getExternalIncludes();
    try {
        final String s = "/tjo";
        ((ErlProject) aProject).setExternalIncludesFile(s);
        assertEquals(s, aProject.getProperties().getExternalIncludes());
    } finally {
        ((ErlProject) aProject).setExternalIncludesFile(externalIncludesString);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) Test(org.junit.Test)

Example 9 with ErlProject

use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.

the class IErlProjectTest method setSourceDirs.

// void setSourceDirs(Collection<IPath> sourceDirs)
// throws BackingStoreException;
@Test
public void setSourceDirs() throws Exception {
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final Collection<IPath> sourceDirs = aProject.getProperties().getSourceDirs();
    try {
        // given
        // an Erlang project and a module
        final IPath srcxPath = new Path("srcx");
        final List<IPath> srcxDirs = Lists.newArrayList(srcxPath);
        aProject.open(null);
        // when
        // setting source dirs so the module is on source path
        final Collection<IErlModule> modules = aProject.getModules();
        ((ErlProject) aProject).setSourceDirs(srcxDirs);
        aProject.open(null);
        final Collection<IErlModule> srcxModules = aProject.getModules();
        ((ErlProject) aProject).setSourceDirs(sourceDirs);
        aProject.open(null);
        final Collection<IErlModule> modulesAgain = aProject.getModules();
        // then
        // the it should be returned, but not otherwise
        assertEquals(0, srcxModules.size());
        assertEquals(1, modules.size());
        assertEquals(module, modules.iterator().next());
        assertEquals(1, modulesAgain.size());
        assertEquals(module, modulesAgain.iterator().next());
    } finally {
        ((ErlProject) aProject).setSourceDirs(sourceDirs);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) Test(org.junit.Test)

Example 10 with ErlProject

use of org.erlide.engine.internal.model.root.ErlProject in project erlide_eclipse by erlang.

the class IErlProjectTest method setIncludeDirs.

// void setIncludeDirs(Collection<IPath> includeDirs)
// throws BackingStoreException;
@Test
public void setIncludeDirs() throws Exception {
    File externalFile = null;
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final Collection<IPath> includeDirs = aProject.getProperties().getIncludeDirs();
    try {
        // given
        // an erlang project and an external file not in any project
        final String externalFileName = "external.hrl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-define(E, hej).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        final List<IPath> newIncludeDirs = Lists.newArrayList(includeDirs);
        aProject.open(null);
        final Collection<IErlModule> otpIncludes = aProject.getExternalIncludes();
        final IPath absoluteDir = new Path(absolutePath).removeLastSegments(1);
        newIncludeDirs.add(absoluteDir);
        ((ErlProject) aProject).setIncludeDirs(newIncludeDirs);
        aProject.open(null);
        // when
        // fetching all external includes
        final Collection<IErlModule> externalIncludes = aProject.getExternalIncludes();
        // then
        // the external file should be returned
        final Set<IErlModule> otpSet = Sets.newHashSet(otpIncludes);
        final Set<IErlModule> externalSet = Sets.newHashSet(externalIncludes);
        final Set<IErlModule> difference = Sets.difference(externalSet, otpSet);
        assertEquals(1, difference.size());
        final IErlModule externalInclude = difference.iterator().next();
        assertNotNull(externalInclude);
        assertEquals(new Path(absolutePath), new Path(externalInclude.getFilePath()));
    } finally {
        if (externalFile != null && externalFile.exists()) {
            externalFile.delete();
        }
        ((ErlProject) aProject).setIncludeDirs(includeDirs);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) File(java.io.File) Test(org.junit.Test)

Aggregations

ErlProject (org.erlide.engine.internal.model.root.ErlProject)28 IErlProject (org.erlide.engine.model.root.IErlProject)27 Test (org.junit.Test)25 IErlModule (org.erlide.engine.model.root.IErlModule)21 File (java.io.File)18 IPath (org.eclipse.core.runtime.IPath)12 Path (org.eclipse.core.runtime.Path)12 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)8 IProject (org.eclipse.core.resources.IProject)6 IFile (org.eclipse.core.resources.IFile)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)5 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)2 IFolder (org.eclipse.core.resources.IFolder)1 ErlModelCache (org.erlide.engine.internal.model.cache.ErlModelCache)1 ErlangProjectProperties (org.erlide.engine.model.root.ErlangProjectProperties)1 IErlExternal (org.erlide.engine.model.root.IErlExternal)1 IErlModel (org.erlide.engine.model.root.IErlModel)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1