/******************************************************************************* * Copyright (c) 2012, 2016 PDT Extension Group and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * PDT Extension Group - initial API and implementation *******************************************************************************/ package org.eclipse.php.composer.test; import static org.junit.Assert.assertArrayEquals; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.dltk.core.IScriptProject; import org.eclipse.php.composer.core.ComposerPlugin; import org.eclipse.php.composer.core.buildpath.BuildPathParser; import org.eclipse.php.composer.core.facet.FacetManager; import org.eclipse.php.composer.core.resources.IComposerProject; import org.eclipse.php.core.PHPVersion; import org.eclipse.php.core.project.ProjectOptions; import org.eclipse.php.internal.core.facet.PHPFacets; import org.eclipse.php.internal.core.project.PHPNature; import org.junit.Test; public class BuildPathTest extends ComposerModelTests { public BuildPathTest() { super("BuildPath tests"); } @Test public void testBuildpathParser() throws CoreException, IOException, InterruptedException { IScriptProject scriptProject = ensureScriptProject("buildpath"); assertNotNull(scriptProject); IProjectDescription desc = scriptProject.getProject().getDescription(); desc.setNatureIds(new String[] { PHPNature.ID }); scriptProject.getProject().setDescription(desc, null); ProjectOptions.setPHPVersion(PHPVersion.PHP5_3, scriptProject.getProject()); PHPFacets.setFacetedVersion(scriptProject.getProject(), PHPVersion.PHP5_3); FacetManager.installFacets(scriptProject.getProject(), PHPVersion.PHP5_3, new NullProgressMonitor()); scriptProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); scriptProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); ComposerCoreTestPlugin.waitForIndexer(); ComposerCoreTestPlugin.waitForAutoBuild(); IFile file = scriptProject.getProject().getFile("composer.json"); assertNotNull(file); assertTrue(scriptProject.getProject().hasNature(PHPNature.ID)); assertTrue(FacetManager.hasComposerFacet(scriptProject.getProject())); IComposerProject composerProject = ComposerPlugin.getDefault().getComposerProject(scriptProject.getProject()); BuildPathParser parser = new BuildPathParser(composerProject); List<String> paths = parser.getPaths(); List<String> expected = new ArrayList<String>(Arrays.asList("mordor/composer", "mordor/gossi/ldap/src", "mordor/phing/phing/classes/phing", "mordor/propel/propel1/generator/lib", "mordor/propel/propel1/runtime/lib", "mordor/symfony/console", "nother", "src", "test")); assertArrayEquals(paths.toArray(), expected.toArray()); // let indexing threads shutdown to avoid SWT thread access errors Thread.sleep(2000); } }