use of org.jetbrains.idea.maven.utils.MavenProcessCanceledException in project intellij-community by JetBrains.
the class MavenProjectImporter method scheduleRefreshResolvedArtifacts.
private void scheduleRefreshResolvedArtifacts(List<MavenProjectsProcessorTask> postTasks) {
// We have to refresh all the resolved artifacts manually in order to
// update all the VirtualFilePointers. It is not enough to call
// VirtualFileManager.refresh() since the newly created files will be only
// picked by FS when FileWatcher finishes its work. And in the case of import
// it doesn't finish in time.
// I couldn't manage to write a test for this since behaviour of VirtualFileManager
// and FileWatcher differs from real-life execution.
List<MavenArtifact> artifacts = new ArrayList<>();
for (MavenProject each : myProjectsToImportWithChanges.keySet()) {
artifacts.addAll(each.getDependencies());
}
final Set<File> files = new THashSet<>();
for (MavenArtifact each : artifacts) {
if (each.isResolved())
files.add(each.getFile());
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
doRefreshFiles(files);
} else {
postTasks.add(new MavenProjectsProcessorTask() {
public void perform(Project project, MavenEmbeddersManager embeddersManager, MavenConsole console, MavenProgressIndicator indicator) throws MavenProcessCanceledException {
indicator.setText("Refreshing files...");
doRefreshFiles(files);
}
});
}
}
use of org.jetbrains.idea.maven.utils.MavenProcessCanceledException in project intellij-community by JetBrains.
the class MavenIndicesStressTest method test1.
public void test1() throws Exception {
MavenCustomRepositoryHelper helper;
helper = new MavenCustomRepositoryHelper(myDir, "plugins", "local1", "local2");
helper.copy("plugins", "local1");
helper.copy("local2", "local1");
//setRepositoryPath(fixture.getTestDataPath("local1"));
final MavenIndexerWrapper indexer = MavenServerManager.getInstance().createIndexer();
File indicesDir = new File(myDir, "indices");
final MavenIndices indices = new MavenIndices(indexer, indicesDir, this);
final MavenIndex index = indices.add("id", getRepositoryPath(), MavenIndex.Kind.LOCAL);
final AtomicBoolean isFinished = new AtomicBoolean(false);
Thread t1 = new Thread(() -> {
try {
for (int i = 0; i < 3; i++) {
System.out.println("INDEXING #" + i);
indices.updateOrRepair(index, true, getMavenGeneralSettings(), EMPTY_MAVEN_PROCESS);
}
} catch (MavenProcessCanceledException e) {
throw new RuntimeException(e);
} finally {
isFinished.set(true);
}
}, "maven index 1");
Thread t2 = new Thread(() -> {
Random random = new Random();
while (!isFinished.get()) {
int i = random.nextInt(100);
System.out.println("Adding artifact #" + i);
//index.addArtifact(new MavenId("group" + i, "artifact" + i, "" + i));
fail();
}
}, "maven index 2");
t1.start();
t2.start();
do {
t1.join(100);
t2.join(100);
} while (!isFinished.get());
t1.join(100);
t2.join(100);
indices.close();
t1.join();
t2.join();
}
use of org.jetbrains.idea.maven.utils.MavenProcessCanceledException in project intellij-community by JetBrains.
the class MavenProjectReader method doReadProjectModel.
private RawModelReadResult doReadProjectModel(VirtualFile file, boolean headerOnly) {
MavenModel result = null;
Collection<MavenProjectProblem> problems = MavenProjectProblem.createProblemsList();
Set<String> alwaysOnProfiles = new THashSet<>();
String fileExtension = file.getExtension();
if (!"pom".equalsIgnoreCase(fileExtension) && !"xml".equalsIgnoreCase(fileExtension)) {
File basedir = getBaseDir(file);
MavenEmbeddersManager manager = MavenProjectsManager.getInstance(myProject).getEmbeddersManager();
MavenEmbedderWrapper embedder = manager.getEmbedder(MavenEmbeddersManager.FOR_MODEL_READ, basedir.getPath(), basedir.getPath());
try {
result = embedder.readModel(VfsUtilCore.virtualToIoFile(file));
} catch (MavenProcessCanceledException ignore) {
} finally {
manager.release(embedder);
}
if (result == null) {
result = new MavenModel();
result.setPackaging(MavenConstants.TYPE_JAR);
return new RawModelReadResult(result, problems, alwaysOnProfiles);
} else {
return new RawModelReadResult(result, problems, alwaysOnProfiles);
}
}
result = new MavenModel();
Element xmlProject = readXml(file, problems, MavenProjectProblem.ProblemType.SYNTAX);
if (xmlProject == null || !"project".equals(xmlProject.getName())) {
result.setPackaging(MavenConstants.TYPE_JAR);
return new RawModelReadResult(result, problems, alwaysOnProfiles);
}
MavenParent parent;
if (MavenJDOMUtil.hasChildByPath(xmlProject, "parent")) {
parent = new MavenParent(new MavenId(MavenJDOMUtil.findChildValueByPath(xmlProject, "parent.groupId", UNKNOWN), MavenJDOMUtil.findChildValueByPath(xmlProject, "parent.artifactId", UNKNOWN), MavenJDOMUtil.findChildValueByPath(xmlProject, "parent.version", UNKNOWN)), MavenJDOMUtil.findChildValueByPath(xmlProject, "parent.relativePath", "../pom.xml"));
result.setParent(parent);
} else {
parent = new MavenParent(new MavenId(UNKNOWN, UNKNOWN, UNKNOWN), "../pom.xml");
}
result.setMavenId(new MavenId(MavenJDOMUtil.findChildValueByPath(xmlProject, "groupId", parent.getMavenId().getGroupId()), MavenJDOMUtil.findChildValueByPath(xmlProject, "artifactId", UNKNOWN), MavenJDOMUtil.findChildValueByPath(xmlProject, "version", parent.getMavenId().getVersion())));
if (headerOnly)
return new RawModelReadResult(result, problems, alwaysOnProfiles);
result.setPackaging(MavenJDOMUtil.findChildValueByPath(xmlProject, "packaging", MavenConstants.TYPE_JAR));
result.setName(MavenJDOMUtil.findChildValueByPath(xmlProject, "name"));
readModelBody(result, result.getBuild(), xmlProject);
result.setProfiles(collectProfiles(file, xmlProject, problems, alwaysOnProfiles));
return new RawModelReadResult(result, problems, alwaysOnProfiles);
}
use of org.jetbrains.idea.maven.utils.MavenProcessCanceledException in project intellij-community by JetBrains.
the class MavenProjectReader method resolveProject.
public Collection<MavenProjectReaderResult> resolveProject(final MavenGeneralSettings generalSettings, MavenEmbedderWrapper embedder, Collection<VirtualFile> files, final MavenExplicitProfiles explicitProfiles, final MavenProjectReaderProjectLocator locator) throws MavenProcessCanceledException {
try {
Collection<MavenServerExecutionResult> executionResults = embedder.resolveProject(files, explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
Collection<MavenProjectReaderResult> readerResults = ContainerUtil.newArrayList();
for (MavenServerExecutionResult result : executionResults) {
MavenServerExecutionResult.ProjectData projectData = result.projectData;
if (projectData == null) {
if (files.size() == 1) {
final VirtualFile file = files.iterator().next();
MavenProjectReaderResult temp = readProject(generalSettings, file, explicitProfiles, locator);
temp.readingProblems.addAll(result.problems);
temp.unresolvedArtifactIds.addAll(result.unresolvedArtifacts);
readerResults.add(temp);
}
} else {
readerResults.add(new MavenProjectReaderResult(projectData.mavenModel, projectData.mavenModelMap, new MavenExplicitProfiles(projectData.activatedProfiles, explicitProfiles.getDisabledProfiles()), projectData.nativeMavenProject, result.problems, result.unresolvedArtifacts));
}
}
return readerResults;
} catch (MavenProcessCanceledException e) {
throw e;
} catch (final Throwable e) {
MavenLog.LOG.info(e);
// print exception since we need to know if something wrong with our logic
MavenLog.printInTests(e);
return ContainerUtil.mapNotNull(files, file -> {
MavenProjectReaderResult result = readProject(generalSettings, file, explicitProfiles, locator);
String message = e.getMessage();
if (message != null) {
result.readingProblems.add(MavenProjectProblem.createStructureProblem(file.getPath(), message));
} else {
result.readingProblems.add(MavenProjectProblem.createSyntaxProblem(file.getPath(), MavenProjectProblem.ProblemType.SYNTAX));
}
return result;
});
}
}
use of org.jetbrains.idea.maven.utils.MavenProcessCanceledException in project android by JetBrains.
the class AndroidFacetImporterBase method importExternalAarDependency.
private static void importExternalAarDependency(@NotNull MavenArtifact artifact, @NotNull MavenProject mavenProject, @NotNull MavenProjectsTree mavenTree, @NotNull MavenRootModelAdapter rootModelAdapter, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull Project project, @NotNull List<MavenProjectsProcessorTask> postTasks) {
final Library aarLibrary = rootModelAdapter.findLibrary(artifact);
if (aarLibrary == null) {
return;
}
final MavenId mavenId = artifact.getMavenId();
Map<MavenId, String> importedAarArtifacts = project.getUserData(IMPORTED_AAR_ARTIFACTS);
if (importedAarArtifacts == null) {
importedAarArtifacts = new HashMap<MavenId, String>();
project.putUserData(IMPORTED_AAR_ARTIFACTS, importedAarArtifacts);
postTasks.add(new MavenProjectsProcessorTask() {
@Override
public void perform(Project project, MavenEmbeddersManager embeddersManager, MavenConsole console, MavenProgressIndicator indicator) throws MavenProcessCanceledException {
project.putUserData(IMPORTED_AAR_ARTIFACTS, null);
}
});
}
final List<MavenProject> allProjects = mavenTree.getProjects();
String aarDirPath = importedAarArtifacts.get(mavenId);
if (aarDirPath == null) {
final String aarDirName = AndroidMavenUtil.getMavenIdStringForFileName(mavenId);
aarDirPath = findExtractedAarDirectory(allProjects, aarDirName);
if (aarDirPath == null) {
final String genDirPath = AndroidMavenUtil.computePathForGenExternalApklibsDir(mavenId, mavenProject, allProjects);
if (genDirPath == null) {
return;
}
aarDirPath = genDirPath + "/" + aarDirName;
}
importedAarArtifacts.put(mavenId, aarDirPath);
extractArtifact(artifact.getPath(), aarDirPath, project, mavenProject.getName());
}
final Library.ModifiableModel aarLibModel = modelsProvider.getModifiableLibraryModel(aarLibrary);
final String classesJarPath = aarDirPath + "/" + SdkConstants.FN_CLASSES_JAR;
final String classesJarUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, classesJarPath) + JarFileSystem.JAR_SEPARATOR;
final String resDirUrl = VfsUtilCore.pathToUrl(aarDirPath + "/" + SdkConstants.FD_RES);
final Set<String> urlsToAdd = new HashSet<String>(Arrays.asList(classesJarUrl, resDirUrl));
collectJarsInAarLibsFolder(aarDirPath, urlsToAdd);
for (String url : aarLibModel.getUrls(OrderRootType.CLASSES)) {
if (!urlsToAdd.remove(url)) {
aarLibModel.removeRoot(url, OrderRootType.CLASSES);
}
}
for (String url : urlsToAdd) {
aarLibModel.addRoot(url, OrderRootType.CLASSES);
}
}
Aggregations