List of usage examples for org.eclipse.jdt.core JavaCore getClasspathVariable
public static IPath getClasspathVariable(final String variableName)
From source file:com.blackducksoftware.integration.eclipseplugin.common.services.DependencyInformationService.java
License:Apache License
public boolean isMavenDependency(final URL filePath) { URL m2Repo;/*from ww w .j a v a 2 s .co m*/ try { m2Repo = JavaCore.getClasspathVariable(ClasspathVariables.MAVEN).toFile().toURI().toURL(); } catch (MalformedURLException e) { e.printStackTrace(); return false; } final String[] m2RepoSegments = m2Repo.getFile().split("/"); final String[] filePathSegments = filePath.getFile().split("/"); if (filePathSegments.length < m2RepoSegments.length) { return false; } for (int i = 0; i < m2RepoSegments.length; i++) { if (!filePathSegments[i].equals(m2RepoSegments[i])) { return false; } } return true; }
From source file:com.blackducksoftware.integration.eclipseplugin.common.services.DependencyInformationServiceTest.java
License:Apache License
@Test public void testIsMavenDependency() { PowerMockito.mockStatic(JavaCore.class); Mockito.when(JavaCore.getClasspathVariable(ClasspathVariables.MAVEN)).thenReturn(mavenPath); Mockito.when(mavenPath.toString()).thenReturn(getSystemSpecificFilepath(fakeMavenClasspathVariable, "/")); for (final URL dependency : MAVEN_DEPENDENCIES_TO_TEST) { assertTrue(dependency.toString() + " is not a maven dependency", service.isMavenDependency(dependency)); }// w ww . ja va2 s . co m }
From source file:com.blackducksoftware.integration.eclipseplugin.common.services.DependencyInformationServiceTest.java
License:Apache License
@Test public void testIsNotMavenDependency() throws MalformedURLException { MAVEN_DEPENDENCIES_TO_TEST = new URL[] { new URL( "com/blackducksoftware/integration/integration-test-common/1.0.0/integration-test-common-1.0.0.jar"), new URL("junit/junit/4.12/junit-4.12.jar"), new URL("org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"), new URL("org/mockito/mockito-all/1.10.19/mockito-all-1.10.19.jar") }; PowerMockito.mockStatic(JavaCore.class); Mockito.when(JavaCore.getClasspathVariable(ClasspathVariables.MAVEN)).thenReturn(mavenPath); Mockito.when(mavenPath.toString()).thenReturn(getSystemSpecificFilepath(fakeMavenClasspathVariable, "/")); for (final URL dependency : MAVEN_DEPENDENCIES_TO_TEST) { assertFalse(dependency + " is a maven dependency", service.isMavenDependency(dependency)); }//from www . j av a 2 s .com }
From source file:com.blackducksoftware.integration.eclipseplugin.common.services.ProjectInformationService.java
License:Apache License
public Gav getGavFromFilepath(URL dependencyFilepath) { if (dependencyInformationService.isMavenDependency(dependencyFilepath)) { URL m2Repo;/*from w w w. j av a2s .c o m*/ try { m2Repo = JavaCore.getClasspathVariable(ClasspathVariables.MAVEN).toFile().toURI().toURL(); } catch (MalformedURLException e) { e.printStackTrace(); return null; } final Gav gav = extractor.getMavenPathGav(dependencyFilepath, m2Repo); // TODO: No hardcoded strings return new Gav("maven", gav.getGroupId(), gav.getArtifactId(), gav.getVersion()); } else if (dependencyInformationService.isGradleDependency(dependencyFilepath)) { final Gav gav = extractor.getGradlePathGav(dependencyFilepath); return new Gav("maven", gav.getGroupId(), gav.getArtifactId(), gav.getVersion()); } else { return null; } }
From source file:com.blackducksoftware.integration.eclipseplugin.common.services.ProjectInformationServiceTest.java
License:Apache License
@Test public void testGettingGavsFromFilepaths() throws MalformedURLException { final ProjectInformationService service = new ProjectInformationService(depService, extractor); prepareExtractor();/*w w w. java 2 s . co m*/ prepareDependencyTypes(); prepareGavElements(); prepareGavsWithType(); PowerMockito.mockStatic(JavaCore.class); Mockito.when(JavaCore.getClasspathVariable(ClasspathVariables.MAVEN)).thenReturn(mavenPath); Mockito.when(mavenPath.toFile().toURI().toURL()).thenReturn(MAVEN_REPO_PATH); prepareExtractor(); final List<URL> dependencies = Arrays.asList(MAVEN_1, MAVEN_2, GRADLE_1, GRADLE_2, NOT_GRAVEN_1, NOT_GRAVEN_2); final List<Gav> gavs = service.getGavsFromFilepaths(dependencies); final List<Gav> expectedGavMessages = Arrays.asList( new Gav("maven", MAVEN_1_GAV.getGroupId(), MAVEN_1_GAV.getArtifactId(), MAVEN_1_GAV.getVersion()), new Gav("maven", MAVEN_2_GAV.getGroupId(), MAVEN_2_GAV.getArtifactId(), MAVEN_2_GAV.getVersion()), new Gav("maven", GRADLE_1_GAV.getGroupId(), GRADLE_1_GAV.getArtifactId(), GRADLE_1_GAV.getVersion()), new Gav("maven", GRADLE_2_GAV.getGroupId(), GRADLE_2_GAV.getArtifactId(), GRADLE_2_GAV.getVersion())); assertEquals("Not getting gavs from filepaths correctly", expectedGavMessages, gavs); }
From source file:com.blackducksoftware.integration.eclipseplugin.common.services.ProjectInformationServiceTest.java
License:Apache License
@Test public void testGettingAllMavenAndGradleDependencyMessages() throws MalformedURLException { final ProjectInformationService service = new ProjectInformationService(depService, extractor); try {//from www . ja v a 2 s . c o m PowerMockito.mockStatic(ResourcesPlugin.class); PowerMockito.mockStatic(JavaCore.class); prepareDependencyTypes(); prepareGavElements(); prepareRootsAndPaths(); prepareExtractor(); prepareGavsWithType(); final IPackageFragmentRoot[] roots = new IPackageFragmentRoot[] { mavenRoot1, mavenRoot2, gradleRoot1, gradleRoot2 }; final List<Gav> expectedGavMessages = Arrays.asList( new Gav("maven", MAVEN_1_GAV.getGroupId(), MAVEN_1_GAV.getArtifactId(), MAVEN_1_GAV.getVersion()), new Gav("maven", MAVEN_2_GAV.getGroupId(), MAVEN_2_GAV.getArtifactId(), MAVEN_2_GAV.getVersion()), new Gav("maven", GRADLE_1_GAV.getGroupId(), GRADLE_1_GAV.getArtifactId(), GRADLE_1_GAV.getVersion()), new Gav("maven", GRADLE_2_GAV.getGroupId(), GRADLE_2_GAV.getArtifactId(), GRADLE_2_GAV.getVersion())); Mockito.when(ResourcesPlugin.getWorkspace()).thenReturn(workspace); Mockito.when(workspace.getRoot()).thenReturn(workspaceRoot); Mockito.when(workspaceRoot.getProject(TEST_PROJECT_NAME)).thenReturn(testProject); Mockito.when(testProject.hasNature(JavaCore.NATURE_ID)).thenReturn(true); Mockito.when(JavaCore.create(testProject)).thenReturn(testJavaProject); Mockito.when(JavaCore.getClasspathVariable(ClasspathVariables.MAVEN)).thenReturn(mavenPath); Mockito.when(mavenPath.toFile().toURI().toURL()).thenReturn(MAVEN_REPO_PATH); Mockito.when(testJavaProject.getPackageFragmentRoots()).thenReturn(roots); final List<Gav> noDeps = service.getGavsFromFilepaths(service.getProjectDependencyFilePaths("")); assertEquals(Arrays.asList(), noDeps); final List<Gav> deps = service .getGavsFromFilepaths(service.getProjectDependencyFilePaths(TEST_PROJECT_NAME)); assertEquals(expectedGavMessages, deps); } catch (final CoreException e) { } }
From source file:com.blackducksoftware.integration.eclipseplugin.internal.listeners.ProjectDependenciesChangedListener.java
License:Apache License
public void removeDependency(final IJavaElement el) throws CoreException, MalformedURLException { final String projName = getProjectNameFromElement(el); if (projName != null) { final URL projectUrl = el.getPath().toFile().toURI().toURL(); if (depService.isGradleDependency(projectUrl)) { final Gav gav = extractor.getGradlePathGav(projectUrl); // TODO: No hardcoded strings. information.removeComponentFromProject(projName, new Gav("maven", gav.getGroupId(), gav.getArtifactId(), gav.getVersion())); } else if (depService.isMavenDependency(projectUrl)) { final URL mavenURL = JavaCore.getClasspathVariable(ClasspathVariables.MAVEN).toFile().toURI() .toURL();//from w w w. j a va2 s . c o m final Gav gav = extractor.getMavenPathGav(projectUrl, mavenURL); information.removeComponentFromProject(projName, new Gav("maven", gav.getGroupId(), gav.getArtifactId(), gav.getVersion())); } } }
From source file:com.blackducksoftware.integration.eclipseplugin.internal.listeners.ProjectDependenciesChangedListener.java
License:Apache License
public void addDependency(final IJavaElement el) throws CoreException, MalformedURLException { final String projName = getProjectNameFromElement(el); if (projName != null) { final URL projectUrl = el.getPath().toFile().toURI().toURL(); if (depService.isGradleDependency(projectUrl)) { final Gav gav = extractor.getGradlePathGav(projectUrl); // TODO: No hardcoded strings. information.addComponentToProject(projName, new Gav("maven", gav.getGroupId(), gav.getArtifactId(), gav.getVersion())); } else if (depService.isMavenDependency(projectUrl)) { final URL mavenURL = JavaCore.getClasspathVariable(ClasspathVariables.MAVEN).toFile().toURI() .toURL();/*from w ww.j ava 2 s .co m*/ final Gav gav = extractor.getMavenPathGav(projectUrl, mavenURL); information.addComponentToProject(projName, new Gav("maven", gav.getGroupId(), gav.getArtifactId(), gav.getVersion())); } } }
From source file:com.blackducksoftware.integration.eclipseplugin.internal.listeners.ProjectDependenciesChangedListenerTest.java
License:Apache License
private void setUpAllStubs() throws CoreException, MalformedURLException { Mockito.when(model.getElementType()).thenReturn(IJavaElement.JAVA_MODEL); Mockito.when(project.getElementType()).thenReturn(IJavaElement.JAVA_PROJECT); Mockito.when(mavenRoot.getElementType()).thenReturn(IJavaElement.PACKAGE_FRAGMENT_ROOT); Mockito.when(gradleRoot.getElementType()).thenReturn(IJavaElement.PACKAGE_FRAGMENT_ROOT); Mockito.when(nonBinaryRoot.getElementType()).thenReturn(IJavaElement.PACKAGE_FRAGMENT_ROOT); Mockito.when(e.getDelta()).thenReturn(modelDelta); Mockito.when(modelDelta.getElement()).thenReturn(model); Mockito.when(projectDelta.getElement()).thenReturn(project); Mockito.when(mavenRootDelta.getElement()).thenReturn(mavenRoot); Mockito.when(gradleRootDelta.getElement()).thenReturn(gradleRoot); Mockito.when(nonBinaryRootDelta.getElement()).thenReturn(nonBinaryRoot); Mockito.when(modelDelta.getAffectedChildren()).thenReturn(new IJavaElementDelta[] { projectDelta }); Mockito.when(projectDelta.getAffectedChildren()) .thenReturn(new IJavaElementDelta[] { mavenRootDelta, gradleRootDelta, nonBinaryRootDelta }); Mockito.when(mavenRoot.getJavaProject()).thenReturn(project); Mockito.when(gradleRoot.getJavaProject()).thenReturn(project); Mockito.when(nonBinaryRoot.getJavaProject()).thenReturn(project); Mockito.when(project.getProject()).thenReturn(parentProject); Mockito.when(parentProject.getDescription()).thenReturn(projectDescription); Mockito.when(projectDescription.getName()).thenReturn(PROJECT_NAME); Mockito.when(gradleRoot.getPath()).thenReturn(gradlePath); Mockito.when(mavenRoot.getPath()).thenReturn(mavenPath); Mockito.when(nonBinaryRoot.getPath()).thenReturn(nonBinaryPath); Mockito.when(gradlePath.toFile().toURI().toURL()).thenReturn(GRADLE_PATH_URL); Mockito.when(mavenPath.toFile().toURI().toURL()).thenReturn(MAVEN_PATH_URL); Mockito.when(nonBinaryPath.toFile().toURI().toURL()).thenReturn(NON_BINARY_PATH_URL); Mockito.when(depService.isMavenDependency(GRADLE_PATH_URL)).thenReturn(false); Mockito.when(depService.isGradleDependency(GRADLE_PATH_URL)).thenReturn(true); Mockito.when(depService.isMavenDependency(MAVEN_PATH_URL)).thenReturn(true); Mockito.when(depService.isGradleDependency(MAVEN_PATH_URL)).thenReturn(false); Mockito.when(depService.isMavenDependency(NON_BINARY_PATH_URL)).thenReturn(false); Mockito.when(depService.isGradleDependency(NON_BINARY_PATH_URL)).thenReturn(false); PowerMockito.mockStatic(JavaCore.class); Mockito.when(JavaCore.getClasspathVariable(ClasspathVariables.MAVEN)).thenReturn(mavenRepoPath); Mockito.when(mavenRepoPath.toFile().toURI().toURL()).thenReturn(MAVEN_REPO_PATH_URL); Mockito.when(extractor.getMavenPathGav(MAVEN_PATH_URL, MAVEN_REPO_PATH_URL)).thenReturn(mavenGav); Mockito.when(extractor.getGradlePathGav(GRADLE_PATH_URL)).thenReturn(gradleGav); Mockito.when(mavenGav.getGroupId()).thenReturn(MAVEN_GROUP_STRING); Mockito.when(mavenGav.getArtifactId()).thenReturn(MAVEN_ARTIFACT_STRING); Mockito.when(mavenGav.getVersion()).thenReturn(MAVEN_VERSION_STRING); Mockito.when(gradleGav.getGroupId()).thenReturn(GRADLE_GROUP_STRING); Mockito.when(gradleGav.getArtifactId()).thenReturn(GRADLE_ARTIFACT_STRING); Mockito.when(gradleGav.getVersion()).thenReturn(GRADLE_VERSION_STRING); }
From source file:com.centurylink.mdw.plugin.codegen.Generator.java
License:Apache License
/** * Sets the MDWCommon.jar file as CLASSPATH variable in Eclipse. Needed so * that the JET Emitter framework can find MDWCommon at runtime. *//* w w w .j a v a 2s . c o m*/ protected void setMdwCommonClasspathVariable() throws JavaModelException { URL url = null; try { url = PluginUtil.getLocalResourceUrl("base/APP-INF/lib/MDWCommon.jar"); } catch (IOException e) { int code = IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST; JavaModelException jme = new JavaModelException(e, code); throw jme; } IPath path = new Path(url.getFile()); if (!path.equals(JavaCore.getClasspathVariable("MDW_COMMON"))) { JavaCore.setClasspathVariable("MDW_COMMON", path, null); } }