use of com.intellij.util.containers.HashMap in project android by JetBrains.
the class NonGradleApkProvider method getApks.
@Override
@NotNull
public Collection<ApkInfo> getApks(@NotNull IDevice device) throws ApkProvisionException {
String packageName = myApplicationIdProvider.getPackageName();
// Gather up all the dependency APKs to install, and check that none conflict.
HashMap<AndroidFacet, String> depFacet2PackageName = new HashMap<AndroidFacet, String>();
fillRuntimeAndTestDependencies(myFacet.getModule(), depFacet2PackageName);
checkPackageNames(depFacet2PackageName, myFacet, packageName);
List<ApkInfo> apkList = new ArrayList<ApkInfo>();
addApk(apkList, packageName, myFacet);
for (AndroidFacet depFacet : depFacet2PackageName.keySet()) {
addApk(apkList, depFacet2PackageName.get(depFacet), depFacet);
}
return apkList;
}
use of com.intellij.util.containers.HashMap in project android by JetBrains.
the class AndroidApkBuilder method finalPackage.
private static Map<AndroidCompilerMessageKind, List<String>> finalPackage(@NotNull String dexPath, @NotNull String[] javaResourceRoots, @NotNull String[] externalJars, @NotNull String[] nativeLibsFolders, @NotNull String outputApk, @NotNull String apkPath, @Nullable String customKeystorePath, boolean signed, @NotNull Condition<File> resourceFilter) {
final Map<AndroidCompilerMessageKind, List<String>> result = new HashMap<AndroidCompilerMessageKind, List<String>>();
result.put(ERROR, new ArrayList<String>());
result.put(INFORMATION, new ArrayList<String>());
result.put(WARNING, new ArrayList<String>());
FileOutputStream fos = null;
SignedJarBuilder builder = null;
try {
String keyStoreOsPath = customKeystorePath != null && customKeystorePath.length() > 0 ? customKeystorePath : DebugKeyProvider.getDefaultKeyStoreOsPath();
DebugKeyProvider provider = createDebugKeyProvider(result, keyStoreOsPath);
X509Certificate certificate = signed ? (X509Certificate) provider.getCertificate() : null;
if (certificate != null && certificate.getNotAfter().compareTo(new Date()) < 0) {
// generate a new one
File keyStoreFile = new File(keyStoreOsPath);
if (keyStoreFile.exists()) {
keyStoreFile.delete();
}
provider = createDebugKeyProvider(result, keyStoreOsPath);
certificate = (X509Certificate) provider.getCertificate();
}
if (certificate != null && certificate.getNotAfter().compareTo(new Date()) < 0) {
String date = DateFormatUtil.formatPrettyDateTime(certificate.getNotAfter());
result.get(ERROR).add(("Debug certificate expired on " + date + ". Cannot regenerate it, please delete file \"" + keyStoreOsPath + "\" manually."));
return result;
}
PrivateKey key = provider.getDebugKey();
if (key == null) {
result.get(ERROR).add("Cannot create new key or keystore");
return result;
}
if (!new File(apkPath).exists()) {
result.get(ERROR).add("File " + apkPath + " not found. Try to rebuild project");
return result;
}
File dexEntryFile = new File(dexPath);
if (!dexEntryFile.exists()) {
result.get(ERROR).add("File " + dexEntryFile.getPath() + " not found. Try to rebuild project");
return result;
}
for (String externalJar : externalJars) {
if (new File(externalJar).isDirectory()) {
result.get(ERROR).add(externalJar + " is directory. Directory libraries are not supported");
}
}
if (result.get(ERROR).size() > 0) {
return result;
}
fos = new FileOutputStream(outputApk);
builder = new SafeSignedJarBuilder(fos, key, certificate, outputApk);
FileInputStream fis = new FileInputStream(apkPath);
try {
builder.writeZip(fis, null);
} finally {
fis.close();
}
builder.writeFile(dexEntryFile, AndroidCommonUtils.CLASSES_FILE_NAME);
final HashSet<String> added = new HashSet<String>();
for (String resourceRootPath : javaResourceRoots) {
final HashSet<File> javaResources = new HashSet<File>();
final File resourceRoot = new File(resourceRootPath);
collectStandardJavaResources(resourceRoot, javaResources, resourceFilter);
writeStandardJavaResources(javaResources, resourceRoot, builder, added);
}
Set<String> duplicates = new HashSet<String>();
Set<String> entries = new HashSet<String>();
for (String externalJar : externalJars) {
collectDuplicateEntries(externalJar, entries, duplicates);
}
for (String duplicate : duplicates) {
result.get(WARNING).add("Duplicate entry " + duplicate + ". The file won't be added");
}
MyResourceFilter filter = new MyResourceFilter(duplicates);
for (String externalJar : externalJars) {
fis = new FileInputStream(externalJar);
try {
builder.writeZip(fis, filter);
} finally {
fis.close();
}
}
final HashSet<String> nativeLibs = new HashSet<String>();
for (String nativeLibsFolderPath : nativeLibsFolders) {
final File nativeLibsFolder = new File(nativeLibsFolderPath);
final File[] children = nativeLibsFolder.listFiles();
if (children != null) {
for (File child : children) {
writeNativeLibraries(builder, nativeLibsFolder, child, signed, nativeLibs);
}
}
}
} catch (IOException e) {
return addExceptionMessage(e, result);
} catch (CertificateException e) {
return addExceptionMessage(e, result);
} catch (DebugKeyProvider.KeytoolException e) {
return addExceptionMessage(e, result);
} catch (AndroidLocation.AndroidLocationException e) {
return addExceptionMessage(e, result);
} catch (NoSuchAlgorithmException e) {
return addExceptionMessage(e, result);
} catch (UnrecoverableEntryException e) {
return addExceptionMessage(e, result);
} catch (KeyStoreException e) {
return addExceptionMessage(e, result);
} catch (GeneralSecurityException e) {
return addExceptionMessage(e, result);
} finally {
if (builder != null) {
try {
builder.close();
} catch (IOException e) {
addExceptionMessage(e, result);
} catch (GeneralSecurityException e) {
addExceptionMessage(e, result);
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException ignored) {
}
}
}
return result;
}
use of com.intellij.util.containers.HashMap in project intellij-plugins by JetBrains.
the class ChooseBuildConfigurationDialog method createForApplicableBCs.
/**
* @param project
* @param filter
* @return <code>null</code> if there's no applicable BC configurables according to the filter provided
*/
@Nullable
public static ChooseBuildConfigurationDialog createForApplicableBCs(String title, @Nullable String labelText, Project project, boolean allowEmptySelection, Condition<FlexBCConfigurable> filter) {
Map<Module, List<FlexBCConfigurable>> treeItems = new HashMap<>();
FlexBCConfigurator configurator = FlexBuildConfigurationsExtension.getInstance().getConfigurator();
for (Module module : ModuleStructureConfigurable.getInstance(project).getModules()) {
if (ModuleType.get(module) != FlexModuleType.getInstance()) {
continue;
}
for (CompositeConfigurable configurable : configurator.getBCConfigurables(module)) {
FlexBCConfigurable flexBCConfigurable = FlexBCConfigurable.unwrap(configurable);
if (!filter.value(flexBCConfigurable)) {
continue;
}
List<FlexBCConfigurable> list = treeItems.get(module);
if (list == null) {
list = new ArrayList<>();
treeItems.put(module, list);
}
list.add(flexBCConfigurable);
}
}
if (treeItems.isEmpty()) {
return null;
}
return new ChooseBuildConfigurationDialog(title, labelText, project, allowEmptySelection, treeItems);
}
use of com.intellij.util.containers.HashMap in project intellij-plugins by JetBrains.
the class FlexProjectConfigurationEditor method commit.
public void commit() throws ConfigurationException {
final Map<Pair<String, String>, String> renamedConfigs = new HashMap<>();
for (Module module : myModule2Editors.keySet()) {
ModifiableRootModel modifiableModel = myProvider.getModuleModifiableModel(module);
Collection<String> usedModulesLibrariesIds = new ArrayList<>();
// ---------------- SDK and shared libraries entries ----------------------
// Library -> add_library_entry_flag
Map<Library, Boolean> librariesToAdd = new LinkedHashMap<>();
final Collection<String> sdkNames = new HashSet<>();
for (Editor editor : myModule2Editors.get(module)) {
final SdkEntry sdkEntry = editor.getDependencies().getSdkEntry();
if (sdkEntry != null) {
sdkNames.add(sdkEntry.getName());
}
for (DependencyEntry dependencyEntry : editor.getDependencies().getEntries()) {
if (dependencyEntry instanceof ModuleLibraryEntry) {
ModuleLibraryEntry moduleLibraryEntry = (ModuleLibraryEntry) dependencyEntry;
usedModulesLibrariesIds.add(moduleLibraryEntry.getLibraryId());
}
if (dependencyEntry instanceof SharedLibraryEntry) {
SharedLibraryEntry sharedLibraryEntry = (SharedLibraryEntry) dependencyEntry;
Library library = myProvider.findSourceLibraryForLiveName(sharedLibraryEntry.getLibraryName(), sharedLibraryEntry.getLibraryLevel());
if (library != null) {
librariesToAdd.put(library, true);
}
}
}
String originalName = editor.getOriginalName();
if (originalName != null && !originalName.equals(editor.getName())) {
renamedConfigs.put(Pair.create(module.getName(), originalName), editor.getName());
}
}
final Sdk sdk;
if (sdkNames.isEmpty()) {
sdk = null;
} else if (sdkNames.size() == 1) {
sdk = FlexSdkUtils.findFlexOrFlexmojosSdk(sdkNames.iterator().next());
} else {
sdk = new FlexCompositeSdk(ArrayUtil.toStringArray(sdkNames));
}
modifiableModel.setSdk(sdk);
Collection<OrderEntry> entriesToRemove = new ArrayList<>();
for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
if (orderEntry instanceof LibraryOrderEntry) {
if (((LibraryOrderEntry) orderEntry).isModuleLevel()) {
LibraryEx library = (LibraryEx) ((LibraryOrderEntry) orderEntry).getLibrary();
if (FlexProjectRootsUtil.isFlexLibrary(library) && !usedModulesLibrariesIds.contains(FlexProjectRootsUtil.getLibraryId(library))) {
entriesToRemove.add(orderEntry);
}
} else {
LibraryEx library = (LibraryEx) ((LibraryOrderEntry) orderEntry).getLibrary();
if (librariesToAdd.containsKey(library)) {
// entry already exists for this library
librariesToAdd.put(library, false);
} else if (library != null && FlexProjectRootsUtil.isFlexLibrary(library)) {
entriesToRemove.add(orderEntry);
}
}
}
}
for (OrderEntry e : entriesToRemove) {
modifiableModel.removeOrderEntry(e);
}
for (Library library : librariesToAdd.keySet()) {
if (!((LibraryEx) library).isDisposed() && librariesToAdd.get(library) && myProvider.findSourceLibrary(library.getName(), library.getTable().getTableLevel()) != null) {
modifiableModel.addLibraryEntry(library);
}
}
// ---------------- modules entries ----------------------
final Set<Module> modulesToAdd = new THashSet<>();
for (Editor editor : myModule2Editors.get(module)) {
for (DependencyEntry dependencyEntry : editor.getDependencies().getEntries()) {
if (dependencyEntry instanceof BuildConfigurationEntry) {
final Module dependencyModule = findModuleWithBC((BuildConfigurationEntry) dependencyEntry);
if (dependencyModule != null && dependencyModule != module) {
modulesToAdd.add(dependencyModule);
}
}
}
}
List<OrderEntry> moduleOrderEntriesToRemove = ContainerUtil.filter(modifiableModel.getOrderEntries(), orderEntry -> orderEntry instanceof ModuleOrderEntry && !modulesToAdd.remove(((ModuleOrderEntry) orderEntry).getModule()));
for (OrderEntry orderEntry : moduleOrderEntriesToRemove) {
modifiableModel.removeOrderEntry(orderEntry);
}
for (Module moduleToAdd : modulesToAdd) {
modifiableModel.addModuleOrderEntry(moduleToAdd);
}
for (OrderEntry entry : modifiableModel.getOrderEntries()) {
if (entry instanceof ExportableOrderEntry) {
// transitiveness will be filtered out in FlexOrderEnumeratorHandler if needed
((ExportableOrderEntry) entry).setExported(true);
}
}
}
// ---------------- do commit ----------------------
Collection<Module> modulesWithChangedModifiableModel = ContainerUtil.findAll(myModule2Editors.keySet(), module -> myProvider.getModuleModifiableModel(module).isChanged());
if (!modulesWithChangedModifiableModel.isEmpty()) {
myProvider.commitModifiableModels();
myModulesModelChangeEventDispatcher.getMulticaster().modulesModelsChanged(modulesWithChangedModifiableModel);
}
ApplicationManager.getApplication().runWriteAction(() -> {
for (Module module : myModule2Editors.keySet()) {
Function<Editor, FlexBuildConfigurationImpl> f = editor -> editor.commit();
FlexBuildConfigurationImpl[] current = ContainerUtil.map2Array(myModule2Editors.get(module), FlexBuildConfigurationImpl.class, f);
((FlexBuildConfigurationManagerImpl) FlexBuildConfigurationManager.getInstance(module)).setBuildConfigurations(current);
}
if (myProject != null) {
FlexBuildConfigurationManagerImpl.resetHighlighting(myProject);
if (!renamedConfigs.isEmpty()) {
myProject.getMessageBus().syncPublisher(FlexBuildConfigurationChangeListener.TOPIC).buildConfigurationsRenamed(renamedConfigs);
}
}
});
}
use of com.intellij.util.containers.HashMap in project android by JetBrains.
the class AndroidResourceCachingBuilder method runPngCaching.
private static boolean runPngCaching(AndroidResourceCachingBuildTarget target, CompileContext context, BuildOutputConsumer outputConsumer) throws IOException {
final JpsModule module = target.getModule();
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
assert extension != null;
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.INFO, AndroidJpsBundle.message("android.jps.progress.res.caching", module.getName())));
final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
if (platform == null) {
return false;
}
final File resCacheDir = target.getOutputDir(context);
// todo: probably it may be done automatically
if (context.getScope().isBuildForced(target) && resCacheDir.exists()) {
if (!FileUtil.delete(resCacheDir)) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", resCacheDir.getPath())));
return false;
}
}
if (!resCacheDir.exists()) {
if (!resCacheDir.mkdirs()) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", resCacheDir.getPath())));
return false;
}
}
final IAndroidTarget androidTarget = platform.getTarget();
final List<BuildRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
if (roots.size() == 0) {
return true;
}
final List<String> inputDirs = new ArrayList<String>();
for (BuildRootDescriptor root : roots) {
final File f = root.getRootFile();
if (f.exists()) {
inputDirs.add(f.getPath());
}
}
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidApt.crunch(androidTarget, inputDirs, resCacheDir.getPath());
AndroidJpsUtil.addMessages(context, messages, BUILDER_NAME, module.getName());
final boolean success = messages.get(AndroidCompilerMessageKind.ERROR).isEmpty();
if (success) {
final Map<String, File> outputFiles = new HashMap<String, File>();
FileUtil.processFilesRecursively(resCacheDir, new Processor<File>() {
@Override
public boolean process(File file) {
if (file.isFile()) {
final String relativePath = FileUtil.getRelativePath(resCacheDir, file);
if (relativePath != null) {
outputFiles.put(relativePath, file);
}
}
return true;
}
});
for (Map.Entry<String, File> entry : outputFiles.entrySet()) {
final String relativePath = entry.getKey();
final File outputFile = entry.getValue();
for (String inputDir : inputDirs) {
final File srcFile = new File(inputDir, relativePath);
outputConsumer.registerOutputFile(outputFile, Collections.singletonList(srcFile.getPath()));
}
}
}
return success;
}
Aggregations