use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class RepositoryAttachHandler method searchArtifacts.
public static void searchArtifacts(final Project project, String coord, final PairProcessor<Collection<Pair<MavenArtifactInfo, MavenRepositoryInfo>>, Boolean> resultProcessor) {
if (coord == null || coord.length() == 0)
return;
final MavenArtifactInfo template;
if (coord.indexOf(':') == -1 && Character.isUpperCase(coord.charAt(0))) {
template = new MavenArtifactInfo(null, null, null, "jar", null, coord, null);
} else {
template = new MavenArtifactInfo(getMavenId(coord), "jar", null);
}
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Maven", false) {
public void run(@NotNull ProgressIndicator indicator) {
String[] urls = MavenRepositoryServicesManager.getServiceUrls();
boolean tooManyResults = false;
final AtomicBoolean proceedFlag = new AtomicBoolean(true);
for (int i = 0, length = urls.length; i < length; i++) {
if (!proceedFlag.get())
break;
final List<Pair<MavenArtifactInfo, MavenRepositoryInfo>> resultList = new ArrayList<>();
try {
String serviceUrl = urls[i];
final List<MavenArtifactInfo> artifacts;
artifacts = MavenRepositoryServicesManager.findArtifacts(template, serviceUrl);
if (!artifacts.isEmpty()) {
if (!proceedFlag.get()) {
break;
}
List<MavenRepositoryInfo> repositories = MavenRepositoryServicesManager.getRepositories(serviceUrl);
Map<String, MavenRepositoryInfo> map = new THashMap<>();
for (MavenRepositoryInfo repository : repositories) {
map.put(repository.getId(), repository);
}
for (MavenArtifactInfo artifact : artifacts) {
if (artifact == null) {
tooManyResults = true;
} else {
MavenRepositoryInfo repository = map.get(artifact.getRepositoryId());
// because it won't be resolved anyway
if (repository == null)
continue;
resultList.add(Pair.create(artifact, repository));
}
}
}
} catch (Exception e) {
MavenLog.LOG.error(e);
} finally {
if (!proceedFlag.get())
break;
final Boolean aBoolean = i == length - 1 ? tooManyResults : null;
ApplicationManager.getApplication().invokeLater(() -> proceedFlag.set(resultProcessor.process(resultList, aBoolean)), o -> !proceedFlag.get());
}
}
}
});
}
use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class MavenProjectImportProvider method createSteps.
public ModuleWizardStep[] createSteps(final WizardContext wizardContext) {
final ProjectWizardStepFactory stepFactory = ProjectWizardStepFactory.getInstance();
return new ModuleWizardStep[] { new MavenProjectImportStep(wizardContext), new SelectProfilesStep(wizardContext), new SelectImportedProjectsStep<MavenProject>(wizardContext) {
@Override
protected String getElementText(final MavenProject project) {
final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(project.getMavenId());
VirtualFile root = ((MavenProjectBuilder) getBuilder()).getRootDirectory();
if (root != null) {
final String relPath = VfsUtilCore.getRelativePath(project.getDirectoryFile(), root, File.separatorChar);
if (StringUtil.isNotEmpty(relPath)) {
stringBuilder.append(" [").append(relPath).append("]");
}
}
if (!isElementEnabled(project)) {
stringBuilder.append(" (project is ignored. See ").append(CommonBundle.settingsActionPath()).append(" | Maven | Ignored Files)");
}
return stringBuilder.toString();
}
@Override
protected boolean isElementEnabled(MavenProject mavenProject) {
Project project = wizardContext.getProject();
if (project == null)
return true;
return !MavenProjectsManager.getInstance(project).isIgnored(mavenProject);
}
@Override
public void updateDataModel() {
super.updateDataModel();
getWizardContext().setProjectName(((MavenProjectBuilder) getBuilder()).getSuggestedProjectName());
}
@Override
public String getHelpId() {
return "reference.dialogs.new.project.import.maven.page3";
}
}, stepFactory.createProjectJdkStep(wizardContext), stepFactory.createNameAndLocationStep(wizardContext) };
}
use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class SelectPropertiesStep method initComponents.
private void initComponents() {
myEnvironmentForm = new MavenEnvironmentForm();
Project project = myProjectOrNull == null ? ProjectManager.getInstance().getDefaultProject() : myProjectOrNull;
myEnvironmentForm.getData(MavenProjectsManager.getInstance(project).getGeneralSettings().clone());
myEnvironmentPanel.add(myEnvironmentForm.createComponent(), BorderLayout.CENTER);
myMavenPropertiesPanel = new MavenPropertiesPanel(myAvailableProperties);
myPropertiesPanel.add(myMavenPropertiesPanel);
}
use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class SvnTestCase method imitUpdate.
protected static void imitUpdate(final Project project) {
ProjectLevelVcsManagerEx.getInstanceEx(project).getOptions(VcsConfiguration.StandardOption.UPDATE).setValue(false);
final CommonUpdateProjectAction action = new CommonUpdateProjectAction();
action.getTemplatePresentation().setText("1");
action.actionPerformed(new AnActionEvent(null, dataId -> {
if (CommonDataKeys.PROJECT.is(dataId)) {
return project;
}
return null;
}, "test", new Presentation(), ActionManager.getInstance(), 0));
final ChangeListManager clManager = ChangeListManager.getInstance(project);
clManager.ensureUpToDate(false);
// wait for after-events like annotations recalculation
clManager.ensureUpToDate(false);
// zipper updater
sleep(100);
}
use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class Form2SourceCompiler method getProcessingItems.
@NotNull
public ProcessingItem[] getProcessingItems(final CompileContext context) {
final Project project = context.getProject();
if (GuiDesignerConfiguration.getInstance(project).INSTRUMENT_CLASSES) {
return ProcessingItem.EMPTY_ARRAY;
}
final ArrayList<ProcessingItem> items = new ArrayList<>();
DumbService.getInstance(project).runReadActionInSmartMode(() -> {
final CompileScope scope = context.getCompileScope();
final CompileScope projectScope = context.getProjectCompileScope();
final VirtualFile[] formFiles = projectScope.getFiles(StdFileTypes.GUI_DESIGNER_FORM, true);
final CompilerManager compilerManager = CompilerManager.getInstance(project);
final BindingsCache bindingsCache = new BindingsCache(project);
try {
final HashMap<String, VirtualFile> class2form = new HashMap<>();
for (final VirtualFile formFile : formFiles) {
if (compilerManager.isExcludedFromCompilation(formFile)) {
continue;
}
final String classToBind;
try {
classToBind = bindingsCache.getBoundClassName(formFile);
} catch (AlienFormFileException e) {
// ignore non-IDEA forms
continue;
} catch (Exception e) {
addError(context, new FormErrorInfo(null, UIDesignerBundle.message("error.cannot.process.form.file", e)), formFile);
continue;
}
if (classToBind == null) {
continue;
}
final VirtualFile sourceFile = findSourceFile(context, formFile, classToBind);
if (sourceFile == null) {
if (scope.belongs(formFile.getUrl())) {
addError(context, new FormErrorInfo(null, UIDesignerBundle.message("error.class.to.bind.does.not.exist", classToBind)), formFile);
}
continue;
}
final boolean inScope = scope.belongs(sourceFile.getUrl()) || scope.belongs(formFile.getUrl());
final VirtualFile alreadyProcessedForm = class2form.get(classToBind);
if (alreadyProcessedForm != null) {
if (inScope) {
addError(context, new FormErrorInfo(null, UIDesignerBundle.message("error.duplicate.bind", classToBind, alreadyProcessedForm.getPresentableUrl())), formFile);
}
continue;
}
class2form.put(classToBind, formFile);
if (!inScope) {
continue;
}
items.add(new MyInstrumentationItem(sourceFile, formFile));
}
} finally {
bindingsCache.close();
}
});
return items.toArray(new ProcessingItem[items.size()]);
}
Aggregations