use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidLayoutDomTest method doTestTagNameIcons.
private void doTestTagNameIcons(String fileName) throws IOException {
VirtualFile file = copyFileToProject(fileName);
myFixture.configureFromExistingVirtualFile(file);
LookupElement[] elements = myFixture.complete(CompletionType.BASIC);
Set<String> elementsToCheck = new HashSet<>(Arrays.asList("view", "include", "requestFocus", "fragment", "Button"));
for (LookupElement element : elements) {
String s = element.getLookupString();
Object obj = element.getObject();
if (elementsToCheck.contains(s)) {
LookupElementPresentation presentation = new LookupElementPresentation();
element.renderElement(presentation);
assertNotNull("no icon for element: " + element, presentation.getIcon());
if ("Button".equals(s)) {
assertInstanceOf(obj, PsiClass.class);
}
}
}
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidSourceGeneratingBuilder method copyGeneratedSources.
@NotNull
private static MyExitStatus copyGeneratedSources(@NotNull Map<JpsModule, MyModuleData> moduleDataMap, @NotNull BuildDataManager dataManager, @NotNull final CompileContext context) throws IOException {
final Ref<Boolean> didSomething = Ref.create(false);
final Ref<Boolean> success = Ref.create(true);
for (Map.Entry<JpsModule, MyModuleData> entry : moduleDataMap.entrySet()) {
final JpsModule module = entry.getKey();
final MyModuleData data = entry.getValue();
if (!data.getAndroidExtension().isCopyCustomGeneratedSources()) {
continue;
}
final ModuleBuildTarget moduleTarget = new ModuleBuildTarget(module, JavaModuleBuildTargetType.PRODUCTION);
final AndroidGenSourcesCopyingStorage storage = context.getProjectDescriptor().dataManager.getStorage(moduleTarget, AndroidGenSourcesCopyingStorage.PROVIDER);
final Set<String> genDirs = AndroidJpsUtil.getGenDirs(data.getAndroidExtension());
final List<String> filteredGenDirs = filterExcludedByOtherProviders(module, genDirs);
final Set<String> forciblyExcludedDirs = new HashSet<String>(genDirs);
forciblyExcludedDirs.removeAll(filteredGenDirs);
warnUserAboutForciblyExcludedRoots(forciblyExcludedDirs, context);
final AndroidFileSetState savedState = storage.read();
final AndroidFileSetState currentState = new AndroidFileSetState(filteredGenDirs, new Condition<File>() {
@Override
public boolean value(File file) {
try {
return shouldBeCopied(file);
} catch (IOException e) {
return false;
}
}
}, true);
if (currentState.equalsTo(savedState)) {
continue;
}
final File outDir = AndroidJpsUtil.getCopiedSourcesStorage(module, dataManager.getDataPaths());
clearDirectoryIfNotEmpty(outDir, context, ANDROID_GENERATED_SOURCES_PROCESSOR);
final List<Pair<String, String>> copiedFiles = new ArrayList<Pair<String, String>>();
for (String path : filteredGenDirs) {
final File dir = new File(path);
if (dir.isDirectory()) {
FileUtil.processFilesRecursively(dir, new Processor<File>() {
@Override
public boolean process(File file) {
try {
if (!shouldBeCopied(file)) {
return true;
}
final String relPath = FileUtil.getRelativePath(dir, file);
final File dstFile = new File(outDir.getPath() + "/" + relPath);
final File dstDir = dstFile.getParentFile();
if (!dstDir.exists() && !dstDir.mkdirs()) {
context.processMessage(new CompilerMessage(ANDROID_GENERATED_SOURCES_PROCESSOR, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", dstDir.getPath())));
return true;
}
FileUtil.copy(file, dstFile);
copiedFiles.add(Pair.create(file.getPath(), dstFile.getPath()));
didSomething.set(true);
} catch (IOException e) {
AndroidJpsUtil.reportExceptionError(context, null, e, ANDROID_GENERATED_SOURCES_PROCESSOR);
success.set(false);
return true;
}
return true;
}
});
}
}
final File generatedSourcesDir = AndroidJpsUtil.getGeneratedSourcesStorage(module, dataManager.getDataPaths());
final List<String> deletedFiles = new ArrayList<String>();
if (!removeCopiedFilesDuplicatingGeneratedFiles(context, outDir, generatedSourcesDir, deletedFiles)) {
success.set(false);
continue;
}
final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
if (testingManager != null) {
logGeneratedSourcesProcessing(testingManager, copiedFiles, deletedFiles);
}
markDirtyRecursively(outDir, context, ANDROID_GENERATED_SOURCES_PROCESSOR, false);
storage.saveState(currentState);
}
if (didSomething.get()) {
return success.get() ? MyExitStatus.OK : MyExitStatus.FAIL;
} else {
return MyExitStatus.NOTHING_CHANGED;
}
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidSourceGeneratingBuilder method runBuildConfigGeneration.
private static MyExitStatus runBuildConfigGeneration(@NotNull CompileContext context, @NotNull Map<JpsModule, MyModuleData> moduleDataMap) throws IOException {
boolean success = true;
boolean didSomething = false;
for (Map.Entry<JpsModule, MyModuleData> entry : moduleDataMap.entrySet()) {
final JpsModule module = entry.getKey();
final ModuleBuildTarget moduleTarget = new ModuleBuildTarget(module, JavaModuleBuildTargetType.PRODUCTION);
final AndroidBuildConfigStateStorage storage = context.getProjectDescriptor().dataManager.getStorage(moduleTarget, AndroidBuildConfigStateStorage.PROVIDER);
final MyModuleData moduleData = entry.getValue();
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
final File generatedSourcesDir = AndroidJpsUtil.getGeneratedSourcesStorage(module, context.getProjectDescriptor().dataManager);
final File outputDirectory = new File(generatedSourcesDir, AndroidJpsUtil.BUILD_CONFIG_GENERATED_SOURCE_ROOT_NAME);
try {
if (extension == null || isLibraryWithBadCircularDependency(extension)) {
if (!clearDirectoryIfNotEmpty(outputDirectory, context, ANDROID_BUILD_CONFIG_GENERATOR)) {
success = false;
}
continue;
}
final String packageName = moduleData.getPackage();
final boolean debug = !AndroidJpsUtil.isReleaseBuild(context);
final Set<String> libPackages = new HashSet<String>(getDepLibPackages(module).values());
libPackages.remove(packageName);
final AndroidBuildConfigState newState = new AndroidBuildConfigState(packageName, libPackages, debug);
final AndroidBuildConfigState oldState = storage.getState(module.getName());
if (newState.equalsTo(oldState)) {
continue;
}
didSomething = true;
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.build.config", module.getName())));
// clear directory, because it may contain obsolete files (ex. if package name was changed)
if (!clearDirectory(outputDirectory, context, ANDROID_BUILD_CONFIG_GENERATOR)) {
success = false;
continue;
}
if (doBuildConfigGeneration(packageName, libPackages, debug, outputDirectory, context)) {
storage.update(module.getName(), newState);
markDirtyRecursively(outputDirectory, context, ANDROID_BUILD_CONFIG_GENERATOR, true);
} else {
storage.update(module.getName(), null);
success = false;
}
} catch (IOException e) {
AndroidJpsUtil.reportExceptionError(context, null, e, ANDROID_BUILD_CONFIG_GENERATOR);
success = false;
}
}
if (!success) {
return MyExitStatus.FAIL;
} else if (didSomething) {
return MyExitStatus.OK;
}
return MyExitStatus.NOTHING_CHANGED;
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidLibraryPackagingBuilder method doBuild.
private static boolean doBuild(CompileContext context, JpsModule module, BuildOutputConsumer outputConsumer) throws IOException {
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
if (extension == null || !extension.isLibrary()) {
return true;
}
File outputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module);
outputDir = AndroidJpsUtil.createDirIfNotExist(outputDir, context, BUILDER_NAME);
if (outputDir == null) {
return false;
}
final File classesDir = ProjectPaths.getModuleOutputDir(module, false);
if (classesDir == null || !classesDir.isDirectory()) {
return true;
}
final Set<String> subdirs = new HashSet<String>();
AndroidJpsUtil.addSubdirectories(classesDir, subdirs);
if (subdirs.size() > 0) {
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.library.packaging", module.getName())));
final File outputJarFile = new File(outputDir, AndroidCommonUtils.CLASSES_JAR_FILE_NAME);
final List<String> srcFiles;
try {
srcFiles = AndroidCommonUtils.packClassFilesIntoJar(ArrayUtil.EMPTY_STRING_ARRAY, ArrayUtil.toStringArray(subdirs), outputJarFile);
} catch (IOException e) {
AndroidJpsUtil.reportExceptionError(context, null, e, BUILDER_NAME);
return false;
}
final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
if (testingManager != null && outputJarFile.isFile()) {
testingManager.getCommandExecutor().checkJarContent("library_package_jar", outputJarFile.getPath());
}
if (srcFiles.size() > 0) {
outputConsumer.registerOutputFile(outputJarFile, srcFiles);
}
}
return true;
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class SdkUpdaterConfigPanel method getSdkLocations.
@NotNull
private static Collection<File> getSdkLocations() {
File androidHome = IdeSdks.getInstance().getAndroidSdkPath();
if (androidHome != null) {
return ImmutableList.of(androidHome);
}
Set<File> locations = new HashSet<>();
// Gradle project.
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
try {
LocalProperties localProperties = new LocalProperties(project);
File androidSdkPath = localProperties.getAndroidSdkPath();
if (androidSdkPath != null) {
locations.add(androidSdkPath);
continue;
}
} catch (IOException ignored) {
Logger.getInstance(SdkUpdaterConfigPanel.class).info("Unable to read local.properties file from project: " + project.getName(), ignored);
}
List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
for (AndroidFacet facet : facets) {
AndroidSdkData sdkData = facet.getConfiguration().getAndroidSdk();
if (sdkData != null) {
locations.add(sdkData.getLocation());
}
}
}
return locations;
}
Aggregations