use of gnu.trove.TObjectLongHashMap in project intellij-plugins by JetBrains.
the class SwcCatalogXmlUtil method getTimestampFromCatalogXml.
public static long getTimestampFromCatalogXml(@NotNull final PsiElement psiElement) {
final Long cachedTimestamp = psiElement.getUserData(TIMESTAMP_IN_CATALOG_XML);
if (cachedTimestamp != null) {
return cachedTimestamp;
}
if (!(psiElement instanceof JSQualifiedNamedElement)) {
return -1;
}
final String qName = ((JSQualifiedNamedElement) psiElement).getQualifiedName();
if (StringUtil.isEmpty(qName)) {
return -1;
}
final PsiFile psiFile = psiElement.getContainingFile();
if (JavaScriptIndex.ECMASCRIPT_JS2.equals(psiFile.getName()))
return Integer.MIN_VALUE;
final VirtualFile swfFile = psiFile.getVirtualFile();
final VirtualFile dir = swfFile != null && "swf".equalsIgnoreCase(swfFile.getExtension()) ? swfFile.getParent() : null;
final VirtualFile catalogFile = dir == null ? null : dir.findChild("catalog.xml");
if (catalogFile == null) {
return -1;
}
Pair<Long, THashMap<String, TObjectLongHashMap<String>>> modStampAndSwfNameToQnameWithTimestampMap = catalogFile.getUserData(MOD_STAMP_AND_SWF_NAME_TO_QNAME_WITH_TIMESTAMP_MAP);
if (modStampAndSwfNameToQnameWithTimestampMap == null || modStampAndSwfNameToQnameWithTimestampMap.first != catalogFile.getModificationStamp()) {
final THashMap<String, TObjectLongHashMap<String>> swfNameToQnameWithTimestampMap = parseTimestampsFromCatalogXml(catalogFile);
modStampAndSwfNameToQnameWithTimestampMap = Pair.create(catalogFile.getModificationStamp(), swfNameToQnameWithTimestampMap);
catalogFile.putUserData(MOD_STAMP_AND_SWF_NAME_TO_QNAME_WITH_TIMESTAMP_MAP, modStampAndSwfNameToQnameWithTimestampMap);
}
final TObjectLongHashMap<String> qnameWithTimestampMap = modStampAndSwfNameToQnameWithTimestampMap.second.get(swfFile.getName());
final long timestamp = qnameWithTimestampMap == null ? -1 : qnameWithTimestampMap.get(qName);
psiElement.putUserData(TIMESTAMP_IN_CATALOG_XML, timestamp);
return timestamp;
}
use of gnu.trove.TObjectLongHashMap in project intellij-plugins by JetBrains.
the class SwcCatalogXmlUtil method parseTimestampsFromCatalogXml.
@SuppressWarnings({ "unchecked" })
private static THashMap<String, TObjectLongHashMap<String>> parseTimestampsFromCatalogXml(@NotNull final VirtualFile catalogFile) {
// <swc xmlns="http://www.adobe.com/flash/swccatalog/9">
// <libraries>
// <library path="library.swf"> take swf name here
// <script name="flash/sampler/StackFrame" mod="1256700285949" signatureChecksum="121164004" > name attribute is not FQN, take only mod here
// <def id="flash.sampler:Sample" /> multiple defs possible
// <def id="flash.sampler:clearSamples" />
// ...
final THashMap<String, TObjectLongHashMap<String>> swfNameToQnameWithTimestampMap = new THashMap<>(1);
try {
final Element rootElement = JDOMUtil.load(catalogFile.getInputStream());
if (rootElement != null && "swc".equals(rootElement.getName())) {
for (final Element librariesElement : rootElement.getChildren("libraries", rootElement.getNamespace())) {
for (final Element libraryElement : librariesElement.getChildren("library", librariesElement.getNamespace())) {
final String swfName = libraryElement.getAttributeValue("path");
if (StringUtil.isEmpty(swfName)) {
continue;
}
final TObjectLongHashMap<String> qNameWithTimestampMap = new TObjectLongHashMap<>();
swfNameToQnameWithTimestampMap.put(swfName, qNameWithTimestampMap);
for (final Element scriptElement : libraryElement.getChildren("script", libraryElement.getNamespace())) {
final String mod = scriptElement.getAttributeValue("mod");
if (StringUtil.isEmpty(mod)) {
continue;
}
try {
final long timestamp = Long.parseLong(mod);
for (final Element defElement : scriptElement.getChildren("def", scriptElement.getNamespace())) {
final String id = defElement.getAttributeValue("id");
if (!StringUtil.isEmpty(id)) {
final String fqn = id.replace(':', '.');
qNameWithTimestampMap.put(fqn, timestamp);
}
}
} catch (NumberFormatException ignored) {
/*ignore*/
}
}
}
}
}
} catch (JDOMException ignored) {
/*ignore*/
} catch (IOException ignored) {
/*ignore*/
}
return swfNameToQnameWithTimestampMap;
}
use of gnu.trove.TObjectLongHashMap in project android by JetBrains.
the class AndroidSourceGeneratingBuilder method runAaptCompiler.
private static MyExitStatus runAaptCompiler(@NotNull final 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 AndroidAptStateStorage storage = context.getProjectDescriptor().dataManager.getStorage(moduleTarget, AndroidAptStateStorage.PROVIDER);
final MyModuleData moduleData = entry.getValue();
final JpsAndroidModuleExtension extension = moduleData.getAndroidExtension();
final File generatedSourcesDir = AndroidJpsUtil.getGeneratedSourcesStorage(module, context.getProjectDescriptor().dataManager);
final File aptOutputDirectory = new File(generatedSourcesDir, AndroidJpsUtil.AAPT_GENERATED_SOURCE_ROOT_NAME);
final IAndroidTarget target = moduleData.getPlatform().getTarget();
try {
final String[] resPaths = AndroidJpsUtil.collectResourceDirsForCompilation(extension, false, context, true);
if (resPaths.length == 0) {
// there is no resources in the module
if (!clearDirectoryIfNotEmpty(aptOutputDirectory, context, ANDROID_APT_COMPILER)) {
success = false;
}
continue;
}
final String packageName = moduleData.getPackage();
final File manifestFile;
if (extension.isLibrary() || !extension.isManifestMergingEnabled()) {
manifestFile = moduleData.getManifestFileForCompiler();
} else {
manifestFile = new File(AndroidJpsUtil.getPreprocessedManifestDirectory(module, context.getProjectDescriptor().dataManager.getDataPaths()), SdkConstants.FN_ANDROID_MANIFEST_XML);
}
if (isLibraryWithBadCircularDependency(extension)) {
if (!clearDirectoryIfNotEmpty(aptOutputDirectory, context, ANDROID_APT_COMPILER)) {
success = false;
}
continue;
}
final Map<JpsModule, String> packageMap = getDepLibPackages(module);
packageMap.put(module, packageName);
final JpsModule circularDepLibWithSamePackage = findCircularDependencyOnLibraryWithSamePackage(extension, packageMap);
if (circularDepLibWithSamePackage != null && !extension.isLibrary()) {
final String message = "Generated fields in " + packageName + ".R class in module '" + module.getName() + "' won't be final, because of circular dependency on module '" + circularDepLibWithSamePackage.getName() + "'";
context.processMessage(new CompilerMessage(ANDROID_APT_COMPILER, BuildMessage.Kind.WARNING, message));
}
final boolean generateNonFinalFields = extension.isLibrary() || circularDepLibWithSamePackage != null;
AndroidAptValidityState oldState;
try {
oldState = storage.getState(module.getName());
} catch (IOException e) {
LOG.info(e);
oldState = null;
}
final Map<String, ResourceFileData> resources = new HashMap<String, ResourceFileData>();
final TObjectLongHashMap<String> valueResFilesTimestamps = new TObjectLongHashMap<String>();
collectResources(resPaths, resources, valueResFilesTimestamps, oldState);
final List<ResourceEntry> manifestElements = collectManifestElements(manifestFile);
final List<Pair<String, String>> libRTextFilesAndPackages = new ArrayList<Pair<String, String>>(packageMap.size());
for (Map.Entry<JpsModule, String> entry1 : packageMap.entrySet()) {
final String libPackage = entry1.getValue();
if (!packageName.equals(libPackage)) {
final String libRTxtFilePath = new File(new File(AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, entry1.getKey()), R_TXT_OUTPUT_DIR_NAME), SdkConstants.FN_RESOURCE_TEXT).getPath();
libRTextFilesAndPackages.add(Pair.create(libRTxtFilePath, libPackage));
}
}
AndroidJpsUtil.collectRTextFilesFromAarDeps(module, libRTextFilesAndPackages);
final File outputDirForArtifacts = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module);
final String proguardOutputCfgFilePath;
if (AndroidJpsUtil.getProGuardConfigIfShouldRun(context, extension) != null) {
if (AndroidJpsUtil.createDirIfNotExist(outputDirForArtifacts, context, BUILDER_NAME) == null) {
success = false;
continue;
}
proguardOutputCfgFilePath = new File(outputDirForArtifacts, AndroidCommonUtils.PROGUARD_CFG_OUTPUT_FILE_NAME).getPath();
} else {
proguardOutputCfgFilePath = null;
}
String rTxtOutDirOsPath = null;
if (extension.isLibrary() || libRTextFilesAndPackages.size() > 0) {
final File rTxtOutDir = new File(outputDirForArtifacts, R_TXT_OUTPUT_DIR_NAME);
if (AndroidJpsUtil.createDirIfNotExist(rTxtOutDir, context, BUILDER_NAME) == null) {
success = false;
continue;
}
rTxtOutDirOsPath = rTxtOutDir.getPath();
}
final AndroidAptValidityState newState = new AndroidAptValidityState(resources, valueResFilesTimestamps, manifestElements, libRTextFilesAndPackages, packageName, proguardOutputCfgFilePath, rTxtOutDirOsPath, extension.isLibrary());
if (newState.equalsTo(oldState)) {
// we need to update state, because it also contains myValueResFilesTimestamps not taking into account by equalsTo()
storage.update(module.getName(), newState);
continue;
}
didSomething = true;
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.aapt", module.getName())));
File tmpOutputDir = null;
try {
tmpOutputDir = FileUtil.createTempDirectory("android_apt_output", "tmp");
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidApt.compile(target, -1, manifestFile.getPath(), packageName, tmpOutputDir.getPath(), resPaths, libRTextFilesAndPackages, generateNonFinalFields, proguardOutputCfgFilePath, rTxtOutDirOsPath, !extension.isLibrary());
AndroidJpsUtil.addMessages(context, messages, ANDROID_APT_COMPILER, module.getName());
if (messages.get(AndroidCompilerMessageKind.ERROR).size() > 0) {
success = false;
storage.update(module.getName(), null);
} else {
if (!AndroidCommonUtils.directoriesContainSameContent(tmpOutputDir, aptOutputDirectory, JAVA_FILE_FILTER)) {
if (!deleteAndMarkRecursively(aptOutputDirectory, context, ANDROID_APT_COMPILER)) {
success = false;
continue;
}
final File parent = aptOutputDirectory.getParentFile();
if (parent != null && !parent.exists() && !parent.mkdirs()) {
context.processMessage(new CompilerMessage(ANDROID_APT_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", parent.getPath())));
success = false;
continue;
}
// we use copyDir instead of moveDirWithContent here, because tmp directory may be located on other disk and
// moveDirWithContent doesn't work for such case
FileUtil.copyDir(tmpOutputDir, aptOutputDirectory);
markDirtyRecursively(aptOutputDirectory, context, ANDROID_APT_COMPILER, true);
}
storage.update(module.getName(), newState);
}
} finally {
if (tmpOutputDir != null) {
FileUtil.delete(tmpOutputDir);
}
}
} catch (IOException e) {
AndroidJpsUtil.reportExceptionError(context, null, e, ANDROID_APT_COMPILER);
success = false;
}
}
if (!success) {
return MyExitStatus.FAIL;
} else if (didSomething) {
return MyExitStatus.OK;
}
return MyExitStatus.NOTHING_CHANGED;
}
use of gnu.trove.TObjectLongHashMap in project intellij-community by JetBrains.
the class CpuUsageData method measureCpuUsage.
public static <E extends Throwable> CpuUsageData measureCpuUsage(ThrowableRunnable<E> runnable) throws E {
FreeMemorySnapshot memStart = new FreeMemorySnapshot();
TObjectLongHashMap<GarbageCollectorMXBean> gcTimes = new TObjectLongHashMap<>();
for (GarbageCollectorMXBean bean : ourGcBeans) {
gcTimes.put(bean, bean.getCollectionTime());
}
TLongLongHashMap threadTimes = new TLongLongHashMap();
for (long id : ourThreadMXBean.getAllThreadIds()) {
threadTimes.put(id, ourThreadMXBean.getThreadUserTime(id));
}
long compStart = ourCompilationMXBean.getTotalCompilationTime();
long start = System.currentTimeMillis();
runnable.run();
long duration = System.currentTimeMillis() - start;
long compTime = ourCompilationMXBean.getTotalCompilationTime() - compStart;
FreeMemorySnapshot memEnd = new FreeMemorySnapshot();
for (long id : ourThreadMXBean.getAllThreadIds()) {
threadTimes.put(id, ourThreadMXBean.getThreadUserTime(id) - threadTimes.get(id));
}
for (GarbageCollectorMXBean bean : ourGcBeans) {
gcTimes.put(bean, bean.getCollectionTime() - gcTimes.get(bean));
}
return new CpuUsageData(duration, gcTimes, threadTimes, compTime, memStart, memEnd);
}
Aggregations