private void inferProjectFiles(Project project) { if (!isTypeInferenceEnabled()) return; final ProjectRootManager m = ProjectRootManager.getInstance(project); final PsiManager p = PsiManager.getInstance(project); ApplicationManager.getApplication().runReadAction(new Runnable() { @Override public void run() { final PathsList pathsList = m.orderEntries().withoutSdk().withoutLibraries().sources().getPathsList(); final List<VirtualFile> virtualFiles = pathsList.getVirtualFiles(); for (VirtualFile file : virtualFiles) { log.debug(file.getName()); } } }); }
public void testTestOnlyModuleDependency() throws Exception { Module moduleA = createModule("a.iml", StdModuleTypes.JAVA); Module moduleB = addDependentModule(moduleA, DependencyScope.TEST); VirtualFile classB = myFixture.createFile("b/Test.java", "public class Test { }"); assertTrue(moduleA.getModuleWithDependenciesAndLibrariesScope(true).contains(classB)); assertFalse(moduleA.getModuleWithDependenciesAndLibrariesScope(false).contains(classB)); assertFalse(moduleA.getModuleWithDependenciesAndLibrariesScope(false).isSearchInModuleContent(moduleB)); final VirtualFile[] compilationClasspath = getCompilationClasspath(moduleA); assertEquals(1, compilationClasspath.length); final VirtualFile[] productionCompilationClasspath = getProductionCompileClasspath(moduleA); assertEmpty(productionCompilationClasspath); final PathsList pathsList = OrderEnumerator.orderEntries(moduleA).recursively().getPathsList(); assertEquals(1, pathsList.getPathList().size()); final PathsList pathsListWithoutTests = OrderEnumerator.orderEntries(moduleA).productionOnly().recursively().getPathsList(); assertEquals(0, pathsListWithoutTests.getPathList().size()); }
@Override public void enhanceRemoteProcessing(@NotNull SimpleJavaParameters parameters) throws ExecutionException { final Set<String> additionalEntries = ContainerUtilRt.newHashSet(); for (GradleProjectResolverExtension extension : RESOLVER_EXTENSIONS.getValue()) { ContainerUtilRt.addIfNotNull(additionalEntries, PathUtil.getJarPathForClass(extension.getClass())); for (Class aClass : extension.getExtraProjectModelClasses()) { ContainerUtilRt.addIfNotNull(additionalEntries, PathUtil.getJarPathForClass(aClass)); } extension.enhanceRemoteProcessing(parameters); } final PathsList classPath = parameters.getClassPath(); for (String entry : additionalEntries) { classPath.add(entry); } parameters.getVMParametersList().addProperty( ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY, GradleConstants.SYSTEM_ID.getId()); }
private void assertClasspath(String moduleName, Scope scope, Type type, String... expectedPaths) throws Exception { createOutputDirectories(); PathsList actualPathsList; Module module = getModule(moduleName); if (scope == Scope.RUNTIME) { JavaParameters params = new JavaParameters(); params.configureByModule(module, type == Type.TESTS ? JavaParameters.CLASSES_AND_TESTS : JavaParameters.CLASSES_ONLY); actualPathsList = params.getClassPath(); } else { OrderEnumerator en = OrderEnumerator.orderEntries(module).recursively().withoutSdk().compileOnly(); if (type == Type.PRODUCTION) en.productionOnly(); actualPathsList = en.classes().getPathsList(); } assertPaths(expectedPaths, actualPathsList.getPathList()); }
private PathsList removeFrameworkStuff(Module module, List<VirtualFile> rootFiles) { final List<File> toExclude = getImplicitClasspathRoots(module); if (LOG.isDebugEnabled()) { LOG.debug("Before removing framework stuff: " + rootFiles); LOG.debug("Implicit roots:" + toExclude); } PathsList scriptClassPath = new PathsList(); eachRoot: for (VirtualFile file : rootFiles) { for (final File excluded : toExclude) { if (VfsUtil.isAncestor(excluded, VfsUtil.virtualToIoFile(file), false)) { continue eachRoot; } } scriptClassPath.add(file); } return scriptClassPath; }
/** * The goal of this function is to find classpath for JUnit runner. * <p/> * There are two ways to do so: * 1. If Pants supports `--export-classpath-manifest-jar-only`, then only the manifest jar will be * picked up which contains all the classpath links for a particular test. * 2. If not, this method will collect classpath based on all known target ids from project modules. */ @Override public <T extends RunConfigurationBase> void updateJavaParameters( T configuration, JavaParameters params, RunnerSettings runnerSettings ) throws ExecutionException { final Module module = findPantsModule(configuration); if (module == null) { return; } /** * This enables dynamic classpath for this particular run and prevents argument too long errors caused by long classpaths. */ params.setUseDynamicClasspath(true); final PathsList classpath = params.getClassPath(); VirtualFile manifestJar = PantsUtil.findProjectManifestJar(configuration.getProject()) .orElseThrow(() -> new ExecutionException("Pants supports manifest jar, but it is not found.")); classpath.add(manifestJar.getPath()); PantsExternalMetricsListenerManager.getInstance().logTestRunner(configuration); }
private PathsList collectByOrderEnumerator(ProjectRootsTraversing.RootTraversePolicy policy) { if (policy == ProjectClasspathTraversing.FULL_CLASSPATH) { return OrderEnumerator.orderEntries(myModule).withoutDepModules().getPathsList(); } if (policy == ProjectClasspathTraversing.FULL_CLASS_RECURSIVE_WO_JDK) { return OrderEnumerator.orderEntries(myModule).withoutSdk().recursively().getPathsList(); } if (policy == ProjectClasspathTraversing.FULL_CLASSPATH_RECURSIVE) { return OrderEnumerator.orderEntries(myModule).recursively().getPathsList(); } if (policy == ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_JDK_AND_TESTS) { return OrderEnumerator.orderEntries(myModule).withoutSdk().productionOnly().recursively().getPathsList(); } if (policy == ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_TESTS) { return OrderEnumerator.orderEntries(myModule).productionOnly().recursively().getPathsList(); } throw new AssertionError(policy); }
@Nullable public static PathsList getClassPathFromRootModel(Module module, boolean isTests, JavaParameters params, boolean allowDuplication) throws CantRunException { if (module == null) { return null; } final JavaParameters tmp = new JavaParameters(); tmp.configureByModule(module, isTests ? JavaParameters.CLASSES_AND_TESTS : JavaParameters.CLASSES_ONLY); if (tmp.getClassPath().getVirtualFiles().isEmpty()) { return null; } Set<VirtualFile> core = new HashSet<VirtualFile>(params.getClassPath().getVirtualFiles()); PathsList nonCore = new PathsList(); for (VirtualFile virtualFile : tmp.getClassPath().getVirtualFiles()) { if (allowDuplication || !core.contains(virtualFile)) { nonCore.add(virtualFile); } } return nonCore; }
public static ClassLoader createUsersClassLoader(JavaTestConfigurationBase configuration) { Module module = configuration.getConfigurationModule().getModule(); List<URL> urls = new ArrayList<>(); PathsList pathsList = ReadAction.compute(() -> (module == null || configuration.getTestSearchScope() == TestSearchScope.WHOLE_PROJECT ? OrderEnumerator.orderEntries(configuration.getProject ()) : OrderEnumerator.orderEntries(module)).runtimeOnly().recursively().getPathsList()); //include jdk to avoid NoClassDefFoundError for classes inside tools.jar for(VirtualFile file : pathsList.getVirtualFiles()) { try { urls.add(VfsUtilCore.virtualToIoFile(file).toURI().toURL()); } catch(MalformedURLException ignored) { LOG.info(ignored); } } return UrlClassLoader.build().allowLock().useCache().urls(urls).get(); }
private static void appendParamsEncodingClasspath(OwnSimpleJavaParameters javaParameters, GeneralCommandLine commandLine, ParametersList vmParameters) { commandLine.addParameters(vmParameters.getList()); appendEncoding(javaParameters, commandLine, vmParameters); PathsList classPath = javaParameters.getClassPath(); if(!classPath.isEmpty() && !explicitClassPath(vmParameters)) { commandLine.addParameter("-classpath"); commandLine.addParameter(classPath.getPathsString()); } PathsList modulePath = javaParameters.getModulePath(); if(!modulePath.isEmpty() && !explicitModulePath(vmParameters)) { commandLine.addParameter("-p"); commandLine.addParameter(modulePath.getPathsString()); } }
private void configureJavaLibraryPath(OrderEnumerator enumerator) { PathsList pathsList = new PathsList(); enumerator.runtimeOnly().withoutSdk().roots(NativeLibraryOrderRootType.getInstance()).collectPaths(pathsList); if(!pathsList.getPathList().isEmpty()) { ParametersList vmParameters = getVMParametersList(); if(vmParameters.hasProperty(JAVA_LIBRARY_PATH_PROPERTY)) { LOG.info(JAVA_LIBRARY_PATH_PROPERTY + " property is already specified, " + "native library paths from dependencies (" + pathsList.getPathsString() + ") won't be added"); } else { vmParameters.addProperty(JAVA_LIBRARY_PATH_PROPERTY, pathsList.getPathsString()); } } }
private String maybeGetProcessorPath() { int jdkVersion = findJdkVersion(); if( jdkVersion >= 9 ) { PathsList pathsList = ProjectRootManager.getInstance( _ijProject ).orderEntries().withoutSdk().librariesOnly().getPathsList(); for( VirtualFile path: pathsList.getVirtualFiles() ) { String extension = path.getExtension(); if( extension != null && extension.equals( "jar" ) && path.getNameWithoutExtension().contains( "manifold-" ) ) { try { return " -processorpath " + new File( new URL( path.getUrl() ).getFile() ).getAbsolutePath() ; } catch( MalformedURLException e ) { return ""; } } } } return ""; }
@Override public void updateJavaParameters(RunConfigurationBase configuration, JavaParameters params, RunnerSettings runnerSettings) { PathsList classpath = params.getClassPath(); final Optional<String> allureAdaptor = classpath.getPathList().stream() .filter(e -> e.matches(ALLURE_JAVA_ADAPTORS_REGEX)).findFirst(); final Optional<String> aspectjDependency = classpath.getPathList().stream() .filter(e -> e.contains(ASPECTJ_DEPENCENCY)).findFirst(); if (allureAdaptor.isPresent() && aspectjDependency.isPresent()) { //TODO:extract path to adspectj jar params.getVMParametersList().addParametersString(ASPECTJWEAVER_OPTION_STRING); } }
/** * F�gt die JAR-Dateien zum Classpath des auszuf�hrenden Programms hinzu * * @param profileState Profil, bei dem es hinzugef�gt werden soll * @throws ExecutionException Wenn die JavaParameter nicht geladen werden konnten */ private void _appendSwingExplorerJarsToClassPath(ApplicationConfiguration.JavaApplicationCommandLineState profileState) throws ExecutionException { PathsList classPath = profileState.getJavaParameters().getClassPath(); classPath.add(swagJarFile); classPath.add(swexplJarFile); }
private void configureJavaLibraryPath(OrderEnumerator enumerator) { PathsList pathsList = new PathsList(); enumerator.runtimeOnly().withoutSdk().roots(NativeLibraryOrderRootType.getInstance()).collectPaths(pathsList); if (!pathsList.getPathList().isEmpty()) { ParametersList vmParameters = getVMParametersList(); if (vmParameters.hasProperty(JAVA_LIBRARY_PATH_PROPERTY)) { LOG.info(JAVA_LIBRARY_PATH_PROPERTY + " property is already specified, native library paths from dependencies (" + pathsList.getPathsString() + ") won't be added"); } else { vmParameters.addProperty(JAVA_LIBRARY_PATH_PROPERTY, pathsList.getPathsString()); } } }
public static void addRtJar(PathsList pathsList) { final String ideaRtJarPath = getIdeaRtJarPath(); if (Boolean.getBoolean(IDEA_PREPEND_RTJAR)) { pathsList.addFirst(ideaRtJarPath); } else { pathsList.addTail(ideaRtJarPath); } }
private PathsList collectByOrderEnumerator(OrderRootType type) { final OrderEnumerator base = OrderEnumerator.orderEntries(myModule); if (type == OrderRootType.CLASSES) { return base.withoutModuleSourceEntries().recursively().exportedOnly().getPathsList(); } if (type == OrderRootType.SOURCES) { return base.recursively().exportedOnly().getSourcePathsList(); } throw new AssertionError(type); }
@NotNull @Override public PathsList getPathsList() { final PathsList list = new PathsList(); collectPaths(list); return list; }
@Override public void patchJavaParameters(@Nullable Module module, @NotNull JavaParameters javaParameters) { if (module == null) { return; } AndroidFacet androidFacet = AndroidFacet.getInstance(module); if (androidFacet == null) { return; } IdeaAndroidProject ideaAndroidProject = androidFacet.getIdeaAndroidProject(); if (ideaAndroidProject == null) { return; } BaseArtifact testArtifact = ideaAndroidProject.findSelectedTestArtifactInSelectedVariant(); if (testArtifact == null) { return; } // Modify the class path only if we're dealing with the unit test artifact. if (!AndroidProject.ARTIFACT_UNIT_TEST.equals(testArtifact.getName()) || !(testArtifact instanceof JavaArtifact)) { return; } PathsList classPath = javaParameters.getClassPath(); AndroidPlatform platform = AndroidPlatform.getInstance(module); if (platform == null) { return; } handlePlatformJar(classPath, platform, (JavaArtifact) testArtifact); handleJavaResources(ideaAndroidProject, classPath); }
private static void handleJavaResources(@NotNull IdeaAndroidProject ideaAndroidProject, @NotNull PathsList classPath) { BaseArtifact testArtifact = ideaAndroidProject.findSelectedTestArtifactInSelectedVariant(); if (testArtifact == null) { return; } try { classPath.add(ideaAndroidProject.getSelectedVariant().getMainArtifact().getJavaResourcesFolder()); classPath.add(testArtifact.getJavaResourcesFolder()); } catch (UnsupportedMethodException e) { // Java resources were not in older versions of the gradle plugin. } }
public PathsList getApplicationClassPath(Module module) { final List<VirtualFile> classPath = OrderEnumerator.orderEntries(module).recursively().withoutSdk().getPathsList().getVirtualFiles(); retainOnlyJarsAndDirectories(classPath); removeModuleOutput(module, classPath); final Module pluginsModule = findCommonPluginsModule(module); if (pluginsModule != null) { removeModuleOutput(pluginsModule, classPath); } return removeFrameworkStuff(module, classPath); }
private static JavaParameters createJavaParameters(@NotNull Module module) throws ExecutionException { JavaParameters res = GroovyScriptRunConfiguration.createJavaParametersWithSdk(module); DefaultGroovyScriptRunner .configureGenericGroovyRunner(res, module, "groovy.ui.GroovyMain", !GroovyConsoleUtil.hasGroovyAll(module), true); PathsList list = GroovyScriptRunner.getClassPathFromRootModel(module, true, res, true, res.getClassPath()); if (list != null) { res.getClassPath().addAll(list.getPathList()); } res.getProgramParametersList().addAll("-p", GroovyScriptRunner.getPathInConf("console.txt")); res.setWorkingDirectory(ModuleRootManager.getInstance(module).getContentRoots()[0].getPath()); return res; }
protected static void addClasspathFromRootModel(@Nullable Module module, boolean isTests, JavaParameters params, boolean allowDuplication) throws CantRunException { PathsList nonCore = new PathsList(); getClassPathFromRootModel(module, isTests, params, allowDuplication, nonCore); final String cp = nonCore.getPathsString(); if (!StringUtil.isEmptyOrSpaces(cp)) { params.getProgramParametersList().add("--classpath"); params.getProgramParametersList().add(cp); } }
@Nullable public static PathsList getClassPathFromRootModel(Module module, boolean isTests, JavaParameters params, boolean allowDuplication, PathsList pathList) throws CantRunException { if (module == null) { return null; } pathList.add("."); final JavaParameters tmp = new JavaParameters(); tmp.configureByModule(module, isTests ? JavaParameters.CLASSES_AND_TESTS : JavaParameters.CLASSES_ONLY); if (tmp.getClassPath().getVirtualFiles().isEmpty()) { return null; } Set<VirtualFile> core = new HashSet<VirtualFile>(params.getClassPath().getVirtualFiles()); for (VirtualFile virtualFile : tmp.getClassPath().getVirtualFiles()) { if (allowDuplication || !core.contains(virtualFile)) { pathList.add(virtualFile); } } return pathList; }
private static void addIntellijLibraries(JavaParameters params, Sdk ideaJdk) { @NonNls String libPath = ideaJdk.getHomePath() + File.separator + "lib"; PathsList list = params.getClassPath(); for (String lib : IJ_LIBRARIES) { list.addFirst(libPath + File.separator + lib); } list.addFirst(((JavaSdkType) ideaJdk.getSdkType()).getToolsPath(ideaJdk)); }
private PathsList collectByOrderEnumerator(ProjectRootsTraversing.RootTraversePolicy policy) { if (policy == ProjectRootsTraversing.LIBRARIES_AND_JDK) { return OrderEnumerator.orderEntries(myModule).withoutDepModules().withoutModuleSourceEntries().getPathsList(); } if (policy == ProjectRootsTraversing.PROJECT_SOURCES) { return OrderEnumerator.orderEntries(myModule).withoutSdk().withoutLibraries().withoutDepModules().getSourcePathsList(); } if (policy == ProjectRootsTraversing.PROJECT_LIBRARIES) { return OrderEnumerator.orderEntries(myModule).withoutSdk().withoutModuleSourceEntries().recursively().getPathsList(); } throw new AssertionError(policy); }
/** * Configures given classpath to reference target i18n bundle file(s). * * @param classPath process classpath * @param bundlePath path to the target bundle file * @param contextClass class from the same content root as the target bundle file */ public static void addBundle(@NotNull PathsList classPath, @NotNull String bundlePath, @NotNull Class<?> contextClass) { String pathToUse = bundlePath.replace('.', '/'); if (!pathToUse.endsWith(".properties")) { pathToUse += ".properties"; } if (!pathToUse.startsWith("/")) { pathToUse = '/' + pathToUse; } String root = PathManager.getResourceRoot(contextClass, pathToUse); if (root != null) { classPath.add(root); } }
private static void removeAsmJarFromClasspath(PathsList classPath) { List<String> toRemove = new ArrayList<String>(); for (String filePath : classPath.getPathList()) { if (filePath.endsWith(".jar")) { final VirtualFile root = JarFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(filePath) + JarFileSystem.JAR_SEPARATOR); if (root != null && LibraryUtil.isClassAvailableInLibrary(new VirtualFile[]{root}, "org.objectweb.asm.ClassReader")) { toRemove.add(filePath); } } } for (String path : toRemove) { classPath.remove(path); } }
@NotNull @Override public JavaParameters createJavaParameters(@NotNull Module module) throws ExecutionException { JavaParameters res = GroovyScriptRunConfiguration.createJavaParametersWithSdk(module); DefaultGroovyScriptRunner.configureGenericGroovyRunner(res, module, "groovy.ui.GroovyMain", !hasGroovyAll(module)); PathsList list = GroovyScriptRunner.getClassPathFromRootModel(module, true, res, true); if (list != null) { res.getClassPath().addAll(list.getPathList()); } res.getProgramParametersList().addAll("-p", GroovyScriptRunner.getPathInConf("console.txt")); //res.getVMParametersList().add("-Xdebug"); res.getVMParametersList().add("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5239"); res.setWorkingDirectory(getWorkingDirectory(module)); return res; }