use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class InconsistentResourceBundleInspection method checkFile.
@Override
public void checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, @NotNull ProblemsHolder problemsHolder, @NotNull GlobalInspectionContext globalContext, @NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) {
Set<ResourceBundle> visitedBundles = globalContext.getUserData(VISITED_BUNDLES_KEY);
if (!(file instanceof PropertiesFile))
return;
final PropertiesFile propertiesFile = (PropertiesFile) file;
ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
assert visitedBundles != null;
if (!visitedBundles.add(resourceBundle))
return;
List<PropertiesFile> files = resourceBundle.getPropertiesFiles();
if (files.size() < 2)
return;
BidirectionalMap<PropertiesFile, PropertiesFile> parents = new BidirectionalMap<>();
for (PropertiesFile f : files) {
PropertiesFile parent = PropertiesUtil.getParent(f, files);
if (parent != null) {
parents.put(f, parent);
}
}
final FactoryMap<PropertiesFile, Map<String, String>> propertiesFilesNamesMaps = new FactoryMap<PropertiesFile, Map<String, String>>() {
@Nullable
@Override
protected Map<String, String> create(PropertiesFile key) {
return key.getNamesMap();
}
};
Map<PropertiesFile, Set<String>> keysUpToParent = new THashMap<>();
for (PropertiesFile f : files) {
Set<String> keys = new THashSet<>(propertiesFilesNamesMaps.get(f).keySet());
PropertiesFile parent = parents.get(f);
while (parent != null) {
keys.addAll(propertiesFilesNamesMaps.get(parent).keySet());
parent = parents.get(parent);
}
keysUpToParent.put(f, keys);
}
for (final InconsistentResourceBundleInspectionProvider provider : myInspectionProviders.getValue()) {
if (isProviderEnabled(provider.getName())) {
provider.check(parents, files, keysUpToParent, propertiesFilesNamesMaps, manager, globalContext.getRefManager(), problemDescriptionsProcessor);
}
}
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class RepositoryAttachHandler method searchArtifacts.
public static void searchArtifacts(final Project project, String coord, final PairProcessor<Collection<Pair<MavenArtifactInfo, MavenRepositoryInfo>>, Boolean> resultProcessor) {
if (coord == null || coord.length() == 0)
return;
final MavenArtifactInfo template;
if (coord.indexOf(':') == -1 && Character.isUpperCase(coord.charAt(0))) {
template = new MavenArtifactInfo(null, null, null, "jar", null, coord, null);
} else {
template = new MavenArtifactInfo(getMavenId(coord), "jar", null);
}
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Maven", false) {
public void run(@NotNull ProgressIndicator indicator) {
String[] urls = MavenRepositoryServicesManager.getServiceUrls();
boolean tooManyResults = false;
final AtomicBoolean proceedFlag = new AtomicBoolean(true);
for (int i = 0, length = urls.length; i < length; i++) {
if (!proceedFlag.get())
break;
final List<Pair<MavenArtifactInfo, MavenRepositoryInfo>> resultList = new ArrayList<>();
try {
String serviceUrl = urls[i];
final List<MavenArtifactInfo> artifacts;
artifacts = MavenRepositoryServicesManager.findArtifacts(template, serviceUrl);
if (!artifacts.isEmpty()) {
if (!proceedFlag.get()) {
break;
}
List<MavenRepositoryInfo> repositories = MavenRepositoryServicesManager.getRepositories(serviceUrl);
Map<String, MavenRepositoryInfo> map = new THashMap<>();
for (MavenRepositoryInfo repository : repositories) {
map.put(repository.getId(), repository);
}
for (MavenArtifactInfo artifact : artifacts) {
if (artifact == null) {
tooManyResults = true;
} else {
MavenRepositoryInfo repository = map.get(artifact.getRepositoryId());
// because it won't be resolved anyway
if (repository == null)
continue;
resultList.add(Pair.create(artifact, repository));
}
}
}
} catch (Exception e) {
MavenLog.LOG.error(e);
} finally {
if (!proceedFlag.get())
break;
final Boolean aBoolean = i == length - 1 ? tooManyResults : null;
ApplicationManager.getApplication().invokeLater(() -> proceedFlag.set(resultProcessor.process(resultList, aBoolean)), o -> !proceedFlag.get());
}
}
}
});
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class JavaFxRedundantPropertyValueInspection method loadDefaultPropertyValues.
/**
* The file format is {@code ClassName#propertyName:type=value} per line, line with leading double dash (--) is commented out
*/
@NotNull
private static Map<String, Map<String, String>> loadDefaultPropertyValues(@NotNull String resourceName) {
final URL resource = JavaFxRedundantPropertyValueInspection.class.getResource(resourceName);
if (resource == null) {
LOG.warn("Resource not found: " + resourceName);
return Collections.emptyMap();
}
final Map<String, Map<String, String>> result = new THashMap<>(200);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.openStream(), CharsetToolkit.UTF8_CHARSET))) {
for (String line : FileUtil.loadLines(reader)) {
if (line.isEmpty() || line.startsWith("--"))
continue;
boolean lineParsed = false;
final int p1 = line.indexOf('#');
if (p1 > 0 && p1 < line.length()) {
final String className = line.substring(0, p1);
final int p2 = line.indexOf('=', p1);
if (p2 > p1 && p2 < line.length()) {
final String propertyName = line.substring(p1 + 1, p2);
final String valueText = line.substring(p2 + 1);
lineParsed = true;
final Map<String, String> properties = result.computeIfAbsent(className, ignored -> new THashMap<>());
if (properties.put(propertyName, valueText) != null) {
LOG.warn("Duplicate default property value " + line);
}
}
}
if (!lineParsed) {
LOG.warn("Can't parse default property value " + line);
}
}
} catch (IOException e) {
LOG.warn("Can't read resource: " + resourceName, e);
return Collections.emptyMap();
}
return result;
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class MavenWebArtifactConfiguration method getRootConfiguration.
@Nullable
public ResourceRootConfiguration getRootConfiguration(@NotNull File root) {
if (myResourceRootsMap == null) {
Map<File, ResourceRootConfiguration> map = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
for (ResourceRootConfiguration resource : webResources) {
map.put(new File(resource.directory), resource);
}
myResourceRootsMap = map;
}
return myResourceRootsMap.get(root);
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class MavenServerManager method createRunProfileState.
private RunProfileState createRunProfileState() {
return new CommandLineState(null) {
private SimpleJavaParameters createJavaParameters() {
final SimpleJavaParameters params = new SimpleJavaParameters();
final Sdk jdk = getJdk();
params.setJdk(jdk);
params.setWorkingDirectory(PathManager.getBinPath());
params.setMainClass(MAIN_CLASS);
Map<String, String> defs = new THashMap<>();
defs.putAll(MavenUtil.getPropertiesFromMavenOpts());
// pass ssl-related options
for (Map.Entry<Object, Object> each : System.getProperties().entrySet()) {
Object key = each.getKey();
Object value = each.getValue();
if (key instanceof String && value instanceof String && ((String) key).startsWith("javax.net.ssl")) {
defs.put((String) key, (String) value);
}
}
if (SystemInfo.isMac) {
String arch = System.getProperty("sun.arch.data.model");
if (arch != null) {
params.getVMParametersList().addParametersString("-d" + arch);
}
}
defs.put("java.awt.headless", "true");
for (Map.Entry<String, String> each : defs.entrySet()) {
params.getVMParametersList().defineProperty(each.getKey(), each.getValue());
}
params.getVMParametersList().addProperty("idea.version=", MavenUtil.getIdeaVersionToPassToMavenProcess());
boolean xmxSet = false;
boolean forceMaven2 = false;
if (myState.vmOptions != null) {
ParametersList mavenOptsList = new ParametersList();
mavenOptsList.addParametersString(myState.vmOptions);
for (String param : mavenOptsList.getParameters()) {
if (param.startsWith("-Xmx")) {
xmxSet = true;
}
if (param.equals(FORCE_MAVEN2_OPTION)) {
forceMaven2 = true;
}
params.getVMParametersList().add(param);
}
}
final File mavenHome;
final String mavenVersion;
final File currentMavenHomeFile = forceMaven2 ? BundledMavenPathHolder.myBundledMaven2Home : getCurrentMavenHomeFile();
if (currentMavenHomeFile == null) {
mavenHome = BundledMavenPathHolder.myBundledMaven3Home;
mavenVersion = getMavenVersion(mavenHome);
Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
final Project project = openProjects.length == 1 ? openProjects[0] : null;
if (project != null) {
new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "", RunnerBundle.message("external.maven.home.invalid.substitution.warning.with.fix", myState.mavenHome, mavenVersion), NotificationType.WARNING, new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
ShowSettingsUtil.getInstance().showSettingsDialog(project, MavenSettings.DISPLAY_NAME);
}
}).notify(null);
} else {
new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "", RunnerBundle.message("external.maven.home.invalid.substitution.warning", myState.mavenHome, mavenVersion), NotificationType.WARNING).notify(null);
}
} else {
mavenHome = currentMavenHomeFile;
mavenVersion = getMavenVersion(mavenHome);
}
assert mavenVersion != null;
params.getVMParametersList().addProperty(MavenServerEmbedder.MAVEN_EMBEDDER_VERSION, mavenVersion);
String sdkConfigLocation = "Settings | Build, Execution, Deployment | Build Tools | Maven | Importing | JDK for Importer";
verifyMavenSdkRequirements(jdk, mavenVersion, sdkConfigLocation);
final List<String> classPath = new ArrayList<>();
classPath.add(PathUtil.getJarPathForClass(org.apache.log4j.Logger.class));
if (StringUtil.compareVersionNumbers(mavenVersion, "3.1") < 0) {
classPath.add(PathUtil.getJarPathForClass(Logger.class));
classPath.add(PathUtil.getJarPathForClass(Log4jLoggerFactory.class));
}
classPath.addAll(PathManager.getUtilClassPath());
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(Query.class));
params.getClassPath().add(PathManager.getResourceRoot(getClass(), "/messages/CommonBundle.properties"));
params.getClassPath().addAll(classPath);
params.getClassPath().addAllFiles(collectClassPathAndLibsFolder(mavenVersion, mavenHome));
String embedderXmx = System.getProperty("idea.maven.embedder.xmx");
if (embedderXmx != null) {
params.getVMParametersList().add("-Xmx" + embedderXmx);
} else {
if (!xmxSet) {
params.getVMParametersList().add("-Xmx768m");
}
}
String mavenEmbedderDebugPort = System.getProperty("idea.maven.embedder.debug.port");
if (mavenEmbedderDebugPort != null) {
params.getVMParametersList().addParametersString("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=" + mavenEmbedderDebugPort);
}
String mavenEmbedderParameters = System.getProperty("idea.maven.embedder.parameters");
if (mavenEmbedderParameters != null) {
params.getProgramParametersList().addParametersString(mavenEmbedderParameters);
}
String mavenEmbedderCliOptions = System.getProperty(MavenServerEmbedder.MAVEN_EMBEDDER_CLI_ADDITIONAL_ARGS);
if (mavenEmbedderCliOptions != null) {
params.getVMParametersList().addProperty(MavenServerEmbedder.MAVEN_EMBEDDER_CLI_ADDITIONAL_ARGS, mavenEmbedderCliOptions);
}
return params;
}
@NotNull
@Override
public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
ProcessHandler processHandler = startProcess();
return new DefaultExecutionResult(processHandler);
}
@Override
@NotNull
protected OSProcessHandler startProcess() throws ExecutionException {
SimpleJavaParameters params = createJavaParameters();
GeneralCommandLine commandLine = params.toCommandLine();
OSProcessHandler processHandler = new OSProcessHandler(commandLine);
processHandler.setShouldDestroyProcessRecursively(false);
return processHandler;
}
};
}
Aggregations