use of com.intellij.openapi.roots.libraries.Library in project android by JetBrains.
the class AndroidRootUtil method fillExternalLibrariesAndModules.
private static void fillExternalLibrariesAndModules(@NotNull final Module module, @NotNull final Set<VirtualFile> outputDirs, @NotNull final Set<Module> visited, @Nullable final Set<VirtualFile> libraries, final boolean exportedLibrariesOnly, final boolean recursive) {
if (!visited.add(module)) {
return;
}
ApplicationManager.getApplication().runReadAction(() -> {
ModuleRootManager manager = ModuleRootManager.getInstance(module);
for (OrderEntry entry : manager.getOrderEntries()) {
if (!(entry instanceof ExportableOrderEntry) || ((ExportableOrderEntry) entry).getScope() != DependencyScope.COMPILE) {
continue;
}
if (libraries != null && entry instanceof LibraryOrderEntry) {
LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
Library library = libraryOrderEntry.getLibrary();
if (library != null && (!exportedLibrariesOnly || libraryOrderEntry.isExported())) {
for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
if (!file.exists()) {
continue;
}
if (file.getFileType() instanceof ArchiveFileType) {
if (file.getFileSystem() instanceof JarFileSystem) {
VirtualFile localFile = JarFileSystem.getInstance().getVirtualFileForJar(file);
if (localFile != null) {
libraries.add(localFile);
}
} else {
libraries.add(file);
}
} else if (file.isDirectory() && !(file.getFileSystem() instanceof JarFileSystem)) {
collectClassFilesAndJars(file, libraries, new HashSet<>());
}
}
}
} else if (entry instanceof ModuleOrderEntry) {
Module depModule = ((ModuleOrderEntry) entry).getModule();
if (depModule == null) {
continue;
}
AndroidFacet facet = AndroidFacet.getInstance(depModule);
boolean libraryProject = facet != null && facet.isLibraryProject();
CompilerModuleExtension extension = CompilerModuleExtension.getInstance(depModule);
if (extension != null) {
VirtualFile classDir = extension.getCompilerOutputPath();
if (libraryProject) {
VirtualFile tmpArtifactsDir = AndroidDexCompiler.getOutputDirectoryForDex(depModule);
if (tmpArtifactsDir != null) {
VirtualFile packedClassesJar = tmpArtifactsDir.findChild(CLASSES_JAR_FILE_NAME);
if (packedClassesJar != null) {
outputDirs.add(packedClassesJar);
}
}
} else // do not support android-app->android-app compile dependencies
if (facet == null && !outputDirs.contains(classDir) && classDir != null && classDir.exists()) {
outputDirs.add(classDir);
}
}
if (recursive) {
fillExternalLibrariesAndModules(depModule, outputDirs, visited, libraries, !libraryProject || exportedLibrariesOnly, true);
}
}
}
});
}
use of com.intellij.openapi.roots.libraries.Library in project android by JetBrains.
the class GradleSyncTest method aarSourceAttachments.
@Test
public void aarSourceAttachments() throws IOException {
guiTest.importSimpleApplication();
IdeFrameFixture ideFrame = guiTest.ideFrame();
Project project = ideFrame.getProject();
Module appModule = ideFrame.getModule("app");
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
runWriteCommandAction(project, () -> {
GradleBuildModel buildModel = GradleBuildModel.get(appModule);
String newDependency = "com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.4@aar";
buildModel.dependencies().addArtifact(COMPILE, newDependency);
buildModel.applyChanges();
});
}
});
ideFrame.requestProjectSync().waitForGradleProjectSyncToFinish();
// Verify that the library has sources.
LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
String libraryName = "mapbox-android-sdk-0.7.4";
Library library = libraryTable.getLibraryByName(libraryName);
VirtualFile[] files = library.getFiles(SOURCES);
assertThat(files).asList().hasSize(1);
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class AppEngineSupportProvider method addSupport.
private void addSupport(final Module module, final ModifiableRootModel rootModel, FrameworkSupportModel frameworkSupportModel, String sdkPath, @Nullable PersistenceApi persistenceApi) {
FacetType<AppEngineFacet, AppEngineFacetConfiguration> facetType = AppEngineFacet.getFacetType();
AppEngineFacet appEngineFacet = FacetManager.getInstance(module).addFacet(facetType, facetType.getDefaultFacetName(), null);
AppEngineWebIntegration webIntegration = AppEngineWebIntegration.getInstance();
webIntegration.registerFrameworkInModel(frameworkSupportModel, appEngineFacet);
final AppEngineFacetConfiguration facetConfiguration = appEngineFacet.getConfiguration();
facetConfiguration.setSdkHomePath(sdkPath);
final AppEngineSdk sdk = appEngineFacet.getSdk();
final Artifact webArtifact = findOrCreateWebArtifact(appEngineFacet);
final VirtualFile webDescriptorDir = webIntegration.suggestParentDirectoryForAppEngineWebXml(module, rootModel);
if (webDescriptorDir != null) {
VirtualFile descriptor = createFileFromTemplate(AppEngineTemplateGroupDescriptorFactory.APP_ENGINE_WEB_XML_TEMPLATE, webDescriptorDir, AppEngineUtil.APP_ENGINE_WEB_XML_NAME);
if (descriptor != null) {
webIntegration.addDescriptor(webArtifact, module.getProject(), descriptor);
}
}
final Project project = module.getProject();
webIntegration.addDevServerToModuleDependencies(rootModel, sdk);
final Library apiJar = addProjectLibrary(module, "AppEngine API", sdk.getUserLibraryPaths(), VirtualFile.EMPTY_ARRAY);
rootModel.addLibraryEntry(apiJar);
webIntegration.addLibraryToArtifact(apiJar, webArtifact, project);
if (persistenceApi != null) {
facetConfiguration.setRunEnhancerOnMake(true);
facetConfiguration.setPersistenceApi(persistenceApi);
facetConfiguration.getFilesToEnhance().addAll(AppEngineUtil.getDefaultSourceRootsToEnhance(rootModel));
try {
final VirtualFile[] sourceRoots = rootModel.getSourceRoots();
final VirtualFile sourceRoot;
if (sourceRoots.length > 0) {
sourceRoot = sourceRoots[0];
} else {
sourceRoot = findOrCreateChildDirectory(rootModel.getContentRoots()[0], "src");
}
VirtualFile metaInf = findOrCreateChildDirectory(sourceRoot, "META-INF");
if (persistenceApi == PersistenceApi.JDO || persistenceApi == PersistenceApi.JDO3) {
createFileFromTemplate(AppEngineTemplateGroupDescriptorFactory.APP_ENGINE_JDO_CONFIG_TEMPLATE, metaInf, AppEngineUtil.JDO_CONFIG_XML_NAME);
} else {
final VirtualFile file = createFileFromTemplate(AppEngineTemplateGroupDescriptorFactory.APP_ENGINE_JPA_CONFIG_TEMPLATE, metaInf, AppEngineUtil.JPA_CONFIG_XML_NAME);
if (file != null) {
webIntegration.setupJpaSupport(module, file);
}
}
} catch (IOException e) {
LOG.error(e);
}
final Library library = addProjectLibrary(module, "AppEngine ORM", Collections.singletonList(sdk.getOrmLibDirectoryPath()), sdk.getOrmLibSources());
rootModel.addLibraryEntry(library);
webIntegration.addLibraryToArtifact(library, webArtifact, project);
}
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class AppEngineSupportProvider method addProjectLibrary.
private static Library addProjectLibrary(final Module module, final String name, final List<String> jarDirectories, final VirtualFile[] sources) {
return new WriteAction<Library>() {
protected void run(@NotNull final Result<Library> result) {
final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(module.getProject());
Library library = libraryTable.getLibraryByName(name);
if (library == null) {
library = libraryTable.createLibrary(name);
final Library.ModifiableModel model = library.getModifiableModel();
for (String path : jarDirectories) {
String url = VfsUtilCore.pathToUrl(path);
VirtualFileManager.getInstance().refreshAndFindFileByUrl(url);
model.addJarDirectory(url, false);
}
for (VirtualFile sourceRoot : sources) {
model.addRoot(sourceRoot, OrderRootType.SOURCES);
}
model.commit();
}
result.setResult(library);
}
}.execute().getResultObject();
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class LibrariesUtil method populateOrderEntries.
private static void populateOrderEntries(@NotNull Module module, Condition<Library> condition, ArrayList<Library> libraries, boolean exportedOnly, Set<Module> visited) {
if (!visited.add(module)) {
return;
}
for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
if (entry instanceof LibraryOrderEntry) {
LibraryOrderEntry libEntry = (LibraryOrderEntry) entry;
if (exportedOnly && !libEntry.isExported()) {
continue;
}
Library library = libEntry.getLibrary();
if (condition.value(library)) {
libraries.add(library);
}
} else if (entry instanceof ModuleOrderEntry) {
final Module dep = ((ModuleOrderEntry) entry).getModule();
if (dep != null) {
populateOrderEntries(dep, condition, libraries, true, visited);
}
}
}
}
Aggregations