use of com.intellij.util.Function in project intellij-community by JetBrains.
the class TestObject method addClassesListToJavaParameters.
protected <T> void addClassesListToJavaParameters(Collection<? extends T> elements, Function<T, String> nameFunction, String packageName, boolean createTempFile, JavaParameters javaParameters) throws CantRunException {
try {
if (createTempFile) {
createTempFiles(javaParameters);
}
final Map<Module, List<String>> perModule = forkPerModule() ? new TreeMap<>((o1, o2) -> StringUtil.compare(o1.getName(), o2.getName(), true)) : null;
final List<String> testNames = new ArrayList<>();
for (final T element : elements) {
final String name = nameFunction.fun(element);
if (name == null) {
continue;
}
final PsiElement psiElement = retrievePsiElement(element);
if (perModule != null && psiElement != null) {
final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement);
if (module != null) {
List<String> list = perModule.get(module);
if (list == null) {
list = new ArrayList<>();
perModule.put(module, list);
}
list.add(name);
}
} else {
testNames.add(name);
}
}
final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
if (perModule != null) {
for (List<String> perModuleClasses : perModule.values()) {
Collections.sort(perModuleClasses);
testNames.addAll(perModuleClasses);
}
} else if (JUnitConfiguration.TEST_PACKAGE.equals(data.TEST_OBJECT)) {
//sort tests in FQN order
Collections.sort(testNames);
}
final String category = JUnitConfiguration.TEST_CATEGORY.equals(data.TEST_OBJECT) ? data.getCategory() : "";
JUnitStarter.printClassesList(testNames, packageName, category, myTempFile);
writeClassesPerModule(packageName, javaParameters, perModule);
} catch (IOException e) {
LOG.error(e);
}
}
use of com.intellij.util.Function in project intellij-community by JetBrains.
the class MavenProjectReaderTest method testInheritingParentProfiles.
public void testInheritingParentProfiles() throws Exception {
createProjectPom("<groupId>test</groupId>" + "<artifactId>parent</artifactId>" + "<version>1</version>" + "<profiles>" + " <profile>" + " <id>profileFromParent</id>" + " </profile>" + "</profiles>");
VirtualFile module = createModulePom("module", "<groupId>test</groupId>" + "<artifactId>module</artifactId>" + "<version>1</version>" + "<parent>" + " <groupId>test</groupId>" + " <artifactId>parent</artifactId>" + " <version>1</version>" + "</parent>" + "<profiles>" + " <profile>" + " <id>profileFromChild</id>" + " </profile>" + "</profiles>");
MavenModel p = readProject(module);
assertOrderedElementsAreEqual(ContainerUtil.map(p.getProfiles(), (Function<MavenProfile, Object>) profile -> profile.getId()), "profileFromChild", "profileFromParent");
}
use of com.intellij.util.Function in project intellij-community by JetBrains.
the class ExternalProjectDataCache method getRootExternalProject.
@Nullable
public ExternalProject getRootExternalProject(@NotNull ProjectSystemId systemId, @NotNull File projectRootDir) {
ExternalProject externalProject = myExternalRootProjects.get(Pair.create(systemId, projectRootDir));
if (LOG.isDebugEnabled()) {
LOG.debug("Can not find data for project at: " + projectRootDir);
LOG.debug("Existing imported projects paths: " + ContainerUtil.map(myExternalRootProjects.entrySet(), (Function<Map.Entry<Pair<ProjectSystemId, File>, ExternalProject>, Object>) entry -> {
if (!(entry.getValue() instanceof ExternalProject))
return null;
return Pair.create(entry.getKey(), entry.getValue().getProjectDir());
}));
}
return externalProject;
}
use of com.intellij.util.Function in project intellij-community by JetBrains.
the class GradleTaskManager method executeTasks.
@Override
public void executeTasks(@NotNull final ExternalSystemTaskId id, @NotNull final List<String> taskNames, @NotNull String projectPath, @Nullable GradleExecutionSettings settings, @Nullable final String jvmAgentSetup, @NotNull final ExternalSystemTaskNotificationListener listener) throws ExternalSystemException {
// TODO add support for external process mode
if (ExternalSystemApiUtil.isInProcessMode(GradleConstants.SYSTEM_ID)) {
for (GradleTaskManagerExtension gradleTaskManagerExtension : GradleTaskManagerExtension.EP_NAME.getExtensions()) {
if (gradleTaskManagerExtension.executeTasks(id, taskNames, projectPath, settings, jvmAgentSetup, listener)) {
return;
}
}
}
GradleExecutionSettings effectiveSettings = settings == null ? new GradleExecutionSettings(null, null, DistributionType.BUNDLED, false) : settings;
Function<ProjectConnection, Void> f = connection -> {
final List<String> initScripts = ContainerUtil.newArrayList();
final GradleProjectResolverExtension projectResolverChain = GradleProjectResolver.createProjectResolverChain(effectiveSettings);
for (GradleProjectResolverExtension resolverExtension = projectResolverChain; resolverExtension != null; resolverExtension = resolverExtension.getNext()) {
final String resolverClassName = resolverExtension.getClass().getName();
resolverExtension.enhanceTaskProcessing(taskNames, jvmAgentSetup, script -> {
if (StringUtil.isNotEmpty(script)) {
ContainerUtil.addAllNotNull(initScripts, "//-- Generated by " + resolverClassName, script, "//");
}
});
}
final String initScript = effectiveSettings.getUserData(INIT_SCRIPT_KEY);
if (StringUtil.isNotEmpty(initScript)) {
ContainerUtil.addAll(initScripts, "//-- Additional script", initScript, "//");
}
if (!initScripts.isEmpty()) {
try {
File tempFile = GradleExecutionHelper.writeToFileGradleInitScript(StringUtil.join(initScripts, SystemProperties.getLineSeparator()));
effectiveSettings.withArguments(GradleConstants.INIT_SCRIPT_CMD_OPTION, tempFile.getAbsolutePath());
} catch (IOException e) {
throw new ExternalSystemException(e);
}
}
GradleVersion gradleVersion = GradleExecutionHelper.getGradleVersion(connection);
if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version("2.5")) < 0) {
listener.onStatusChange(new ExternalSystemTaskExecutionEvent(id, new ExternalSystemProgressEventUnsupportedImpl(gradleVersion + " does not support executions view")));
}
for (GradleBuildParticipant buildParticipant : effectiveSettings.getExecutionWorkspace().getBuildParticipants()) {
effectiveSettings.withArguments(GradleConstants.INCLUDE_BUILD_CMD_OPTION, buildParticipant.getProjectPath());
}
BuildLauncher launcher = myHelper.getBuildLauncher(id, connection, effectiveSettings, listener);
launcher.forTasks(ArrayUtil.toStringArray(taskNames));
if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version("2.1")) < 0) {
myCancellationMap.put(id, new UnsupportedCancellationToken());
} else {
final CancellationTokenSource cancellationTokenSource = GradleConnector.newCancellationTokenSource();
launcher.withCancellationToken(cancellationTokenSource.token());
myCancellationMap.put(id, cancellationTokenSource);
}
try {
launcher.run();
} finally {
myCancellationMap.remove(id);
}
return null;
};
myHelper.execute(projectPath, effectiveSettings, f);
}
use of com.intellij.util.Function in project intellij-community by JetBrains.
the class PropertiesCopyHandler method copyPropertyToAnotherBundle.
private static void copyPropertyToAnotherBundle(@NotNull Collection<IProperty> properties, @NotNull final String newName, @NotNull ResourceBundle targetResourceBundle) {
final Map<IProperty, PropertiesFile> propertiesFileMapping = new HashMap<>();
for (IProperty property : properties) {
final PropertiesFile containingFile = property.getPropertiesFile();
final PropertiesFile matched = findWithMatchedSuffix(containingFile, targetResourceBundle);
if (matched != null) {
propertiesFileMapping.put(property, matched);
}
}
final Project project = targetResourceBundle.getProject();
if (properties.size() != propertiesFileMapping.size() && Messages.NO == Messages.showYesNoDialog(project, "Source and target resource bundles properties files are not matched correctly. Copy properties anyway?", "Resource Bundles Are not Matched", null)) {
return;
}
if (!propertiesFileMapping.isEmpty()) {
WriteCommandAction.runWriteCommandAction(project, () -> {
if (!FileModificationService.getInstance().preparePsiElementsForWrite(ContainerUtil.map(propertiesFileMapping.values(), (Function<PropertiesFile, PsiElement>) PropertiesFile::getContainingFile)))
return;
for (Map.Entry<IProperty, PropertiesFile> entry : propertiesFileMapping.entrySet()) {
final String value = entry.getKey().getValue();
final PropertiesFile target = entry.getValue();
target.addProperty(newName, value);
}
});
final IProperty representativeFromSourceBundle = ContainerUtil.getFirstItem(properties);
LOG.assertTrue(representativeFromSourceBundle != null);
final ResourceBundle sourceResourceBundle = representativeFromSourceBundle.getPropertiesFile().getResourceBundle();
if (sourceResourceBundle.equals(targetResourceBundle)) {
DataManager.getInstance().getDataContextFromFocus().doWhenDone((Consumer<DataContext>) context -> {
final FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(context);
if (fileEditor instanceof ResourceBundleEditor) {
final ResourceBundleEditor resourceBundleEditor = (ResourceBundleEditor) fileEditor;
resourceBundleEditor.updateTreeRoot();
resourceBundleEditor.selectProperty(newName);
}
});
} else {
for (FileEditor editor : FileEditorManager.getInstance(project).openFile(new ResourceBundleAsVirtualFile(targetResourceBundle), true)) {
((ResourceBundleEditor) editor).updateTreeRoot();
((ResourceBundleEditor) editor).selectProperty(newName);
}
}
}
}
Aggregations