maven: clean-up

This commit is contained in:
Vladislav.Soroka
2016-08-15 15:22:18 +03:00
parent de83144114
commit eb03498efb
19 changed files with 53 additions and 68 deletions
@@ -18,7 +18,7 @@ import java.util.Map;
*/
public class MavenArtifactIndex {
private static final MavenArtifactIndex EMPTY_INDEX = new MavenArtifactIndex(Collections.<String, Map<String, List<MavenArtifact>>>emptyMap());
private static final MavenArtifactIndex EMPTY_INDEX = new MavenArtifactIndex(Collections.emptyMap());
private final Map<String, Map<String, List<MavenArtifact>>> myData;
@@ -36,7 +36,7 @@ public class MavenArtifactIndex {
if (groupMap == null) return Collections.emptyList();
List<MavenArtifact> res = groupMap.get(artifactId);
return res == null ? Collections.<MavenArtifact>emptyList() : res;
return res == null ? Collections.emptyList() : res;
}
@NotNull
@@ -16,6 +16,7 @@
package org.jetbrains.idea.maven.project;
import com.intellij.openapi.util.Pair;
import com.intellij.ui.JBColor;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -87,7 +88,7 @@ public class MavenDisablePanelCheckbox extends JCheckBox {
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
Color c = enabled ? Color.GRAY : Color.LIGHT_GRAY;
Color c = enabled ? JBColor.GRAY : JBColor.LIGHT_GRAY;
setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, c), BorderFactory.createEmptyBorder(10, 0, 0, 0)));
}
};
@@ -64,41 +64,25 @@ public class MavenGeneralPanel implements PanelWithAnchor {
private void fillOutputLevelCombobox() {
ComboBoxUtil.setModel(outputLevelCombo, outputLevelComboModel,
Arrays.asList(MavenExecutionOptions.LoggingLevel.values()),
new Function<MavenExecutionOptions.LoggingLevel, Pair<String, ?>>() {
public Pair<String, MavenExecutionOptions.LoggingLevel> fun(MavenExecutionOptions.LoggingLevel each) {
return Pair.create(each.getDisplayString(), each);
}
});
each -> Pair.create(each.getDisplayString(), each));
}
private void fillFailureBehaviorCombobox() {
ComboBoxUtil.setModel(failPolicyCombo, failPolicyComboModel,
Arrays.asList(MavenExecutionOptions.FailureMode.values()),
new Function<MavenExecutionOptions.FailureMode, Pair<String, ?>>() {
public Pair<String, MavenExecutionOptions.FailureMode> fun(MavenExecutionOptions.FailureMode each) {
return Pair.create(each.getDisplayString(), each);
}
});
each -> Pair.create(each.getDisplayString(), each));
}
private void fillChecksumPolicyCombobox() {
ComboBoxUtil.setModel(checksumPolicyCombo, checksumPolicyComboModel,
Arrays.asList(MavenExecutionOptions.ChecksumPolicy.values()),
new Function<MavenExecutionOptions.ChecksumPolicy, Pair<String, ?>>() {
public Pair<String, MavenExecutionOptions.ChecksumPolicy> fun(MavenExecutionOptions.ChecksumPolicy each) {
return Pair.create(each.getDisplayString(), each);
}
});
each -> Pair.create(each.getDisplayString(), each));
}
private void fillPluginUpdatePolicyCombobox() {
ComboBoxUtil.setModel(pluginUpdatePolicyCombo, pluginUpdatePolicyComboModel,
Arrays.asList(MavenExecutionOptions.PluginUpdatePolicy.values()),
new Function<MavenExecutionOptions.PluginUpdatePolicy, Pair<String, ?>>() {
public Pair<String, MavenExecutionOptions.PluginUpdatePolicy> fun(MavenExecutionOptions.PluginUpdatePolicy each) {
return Pair.create(each.getDisplayString(), each);
}
});
each -> Pair.create(each.getDisplayString(), each));
}
public JComponent createComponent() {
@@ -41,7 +41,7 @@ public class MavenGeneralSettingsEditor extends SettingsEditor<MavenRunConfigura
}
@Override
protected void resetEditorFrom(MavenRunConfiguration s) {
protected void resetEditorFrom(@NotNull MavenRunConfiguration s) {
myUseProjectSettings.setSelected(s.getGeneralSettings() == null);
if (s.getGeneralSettings() == null) {
@@ -54,7 +54,7 @@ public class MavenGeneralSettingsEditor extends SettingsEditor<MavenRunConfigura
}
@Override
protected void applyEditorTo(MavenRunConfiguration s) throws ConfigurationException {
protected void applyEditorTo(@NotNull MavenRunConfiguration s) throws ConfigurationException {
if (myUseProjectSettings.isSelected()) {
s.setGeneralSettings(null);
}
@@ -20,7 +20,6 @@ import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.module.StdModuleTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream;
@@ -626,7 +626,7 @@ public class MavenProjectsTree {
mavenProject,
isNewModule,
recursive,
recursive ? force : false, // do not force update modules if only this project was requested to be updated
recursive && force, // do not force update modules if only this project was requested to be updated
explicitProfiles,
updateContext,
updateStack,
@@ -1108,7 +1108,7 @@ public class MavenProjectsTree {
try {
List<MavenProject> modules = myAggregatorToModuleMapping.get(aggregator);
return modules == null
? Collections.<MavenProject>emptyList()
? Collections.emptyList()
: new ArrayList<>(modules);
}
finally {
@@ -1164,7 +1164,7 @@ public class MavenProjectsTree {
}
}
return result == null ? Collections.<MavenProject>emptyList() : result;
return result == null ? Collections.emptyList() : result;
}
finally {
readUnlock();
@@ -1214,7 +1214,7 @@ public class MavenProjectsTree {
}
}
return result == null ? Collections.<MavenProject>emptyList() : result;
return result == null ? Collections.emptyList() : result;
}
finally {
readUnlock();
@@ -1501,10 +1501,10 @@ public class MavenProjectsTree {
public void fireUpdatedIfNecessary() {
if (updatedProjectsWithChanges.isEmpty() && deletedProjects.isEmpty()) return;
List<MavenProject> mavenProjects = deletedProjects.isEmpty()
? Collections.<MavenProject>emptyList()
? Collections.emptyList()
: new ArrayList<>(deletedProjects);
List<Pair<MavenProject, MavenProjectChanges>> updated = updatedProjectsWithChanges.isEmpty()
? Collections.<Pair<MavenProject, MavenProjectChanges>>emptyList()
? Collections.emptyList()
: MavenUtil.mapToList(updatedProjectsWithChanges);
fireProjectsUpdated(updated, mavenProjects);
}
@@ -14,10 +14,7 @@ import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.StreamUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.*;
import com.intellij.util.Base64;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.xmlb.XmlSerializer;
@@ -468,7 +465,7 @@ public class MavenResourceCompilerConfigurationGenerator {
? compilerModuleExtension.getCompilerOutputUrlForTests()
: compilerModuleExtension.getCompilerOutputUrl();
cfg.targetPath = VfsUtil.urlToPath(compilerOutputUrl);
cfg.targetPath = VfsUtilCore.urlToPath(compilerOutputUrl);
convertIdeaExcludesToMavenExcludes(cfg, (CompilerConfigurationImpl)compilerConfiguration);
@@ -47,7 +47,7 @@ public class DownloadSelectedSourcesAndDocsAction extends MavenProjectsAction {
private static Collection<MavenArtifact> getDependencies(AnActionEvent e) {
Collection<MavenArtifact> result = e.getData(MavenDataKeys.MAVEN_DEPENDENCIES);
return result == null ? Collections.<MavenArtifact>emptyList() : result;
return result == null ? Collections.emptyList() : result;
}
protected void perform(@NotNull MavenProjectsManager manager, List<MavenProject> mavenProjects, AnActionEvent e) {
@@ -13,7 +13,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
import com.intellij.util.NullableConsumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.project.MavenProject;
@@ -27,9 +27,9 @@ import java.util.List;
public class OpenOrCreateSettingsXmlAction extends MavenOpenOrCreateFilesAction {
protected List<File> getFiles(AnActionEvent e) {
final MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(e.getDataContext());
if(projectsManager == null) return Collections.<File>emptyList();
if(projectsManager == null) return Collections.emptyList();
File file = projectsManager.getGeneralSettings().getEffectiveUserSettingsIoFile();
return file != null ? Collections.singletonList(file) : Collections.<File>emptyList();
return file != null ? Collections.singletonList(file) : Collections.emptyList();
}
@Override
@@ -71,7 +71,7 @@ public class ManifestBuilder {
final Element mavenArchiveConfiguration =
mavenPackagingPluginConfiguration != null ? mavenPackagingPluginConfiguration.getChild("archive") : null;
if (mavenArchiveConfiguration == null) return getDefaultManifest(Collections.<String, String>emptyMap());
if (mavenArchiveConfiguration == null) return getDefaultManifest(Collections.emptyMap());
final Element manifestEntries = mavenArchiveConfiguration.getChild("manifestEntries");
Map<String, String> entries = getManifestEntries(manifestEntries);
@@ -139,7 +139,7 @@ public class ManifestBuilder {
boolean hasManifestEntries = manifestEntries != null && manifestEntries.getContentSize() > 0;
Map<String, String> entries = hasManifestEntries ?
new LinkedHashMap<>(manifestEntries.getContentSize()) :
Collections.<String, String>emptyMap();
Collections.emptyMap();
if (hasManifestEntries) {
for (Element element : manifestEntries.getChildren()) {
entries.put(element.getName(), element.getTextTrim());
@@ -27,7 +27,6 @@ import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.AsyncResult;
import com.intellij.openapi.vfs.LocalFileSystem;
@@ -36,7 +35,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.util.Consumer;
import com.intellij.util.PathUtil;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.maven.importing.MavenRootModelAdapter;
@@ -63,7 +61,7 @@ public class MavenAttachSourcesProvider implements AttachSourcesProvider {
if (projects.isEmpty()) return Collections.emptyList();
if (findArtifacts(projects, orderEntries).isEmpty()) return Collections.emptyList();
return Collections.<AttachSourcesAction>singleton(new AttachSourcesAction() {
return Collections.singleton(new AttachSourcesAction() {
@Override
public String getName() {
return ProjectBundle.message("maven.action.download.sources");
@@ -20,7 +20,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.encoding.EncodingRegistry;
import com.intellij.psi.impl.source.parsing.xml.XmlBuilder;
@@ -42,7 +42,7 @@ public class MavenJDOMUtil {
if (!file.isValid()) return null;
try {
text = VfsUtil.loadText(file);
text = VfsUtilCore.loadText(file);
}
catch (IOException e) {
if (handler != null) handler.onReadError(e);
@@ -16,7 +16,7 @@
package org.jetbrains.idea.maven.utils;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.util.PathUtil;
import org.jetbrains.annotations.NotNull;
@@ -35,7 +35,7 @@ public class Path {
}
public Url toUrl() {
return new Url(VfsUtil.pathToUrl(path));
return new Url(VfsUtilCore.pathToUrl(path));
}
@Override
@@ -27,6 +27,7 @@ import com.intellij.util.containers.Convertor;
import com.intellij.util.ui.AsyncProcessIcon;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.tree.TreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.indices.MavenIndicesManager;
import org.jetbrains.idea.maven.model.MavenArchetype;
@@ -306,7 +307,7 @@ public class MavenArchetypesStep extends ModuleWizardStep implements Disposable
}
private static class MyRenderer extends ColoredTreeCellRenderer {
public void customizeCellRenderer(JTree tree,
public void customizeCellRenderer(@NotNull JTree tree,
Object value,
boolean selected,
boolean expanded,
@@ -106,9 +106,11 @@ public class MavenModuleBuilderHelper {
if (myAggregatorProject != null) {
MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(project, myAggregatorProject.getFile());
model.getPackaging().setStringValue("pom");
MavenDomModule module = model.getModules().addModule();
module.setValue(getPsiFile(project, file));
if (model != null) {
model.getPackaging().setStringValue("pom");
MavenDomModule module = model.getModules().addModule();
module.setValue(getPsiFile(project, file));
}
}
}
}.execute().getResultObject();
@@ -166,8 +168,10 @@ public class MavenModuleBuilderHelper {
pom.putUserData(MavenProjectsManagerWatcher.FORCE_IMPORT_AND_RESOLVE_ON_REFRESH, Boolean.TRUE);
try {
Document doc = FileDocumentManager.getInstance().getDocument(pom);
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(doc);
FileDocumentManager.getInstance().saveDocument(doc);
if (doc != null) {
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(doc);
FileDocumentManager.getInstance().saveDocument(doc);
}
}
finally {
pom.putUserData(MavenProjectsManagerWatcher.FORCE_IMPORT_AND_RESOLVE_ON_REFRESH, null);
@@ -194,7 +198,7 @@ public class MavenModuleBuilderHelper {
MavenRunnerParameters params = new MavenRunnerParameters(
false, workingDir.getPath(),
Collections.singletonList("org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate"),
Collections.<String>emptyList());
Collections.emptyList());
MavenRunner runner = MavenRunner.getInstance(project);
MavenRunnerSettings settings = runner.getState().clone();
@@ -217,7 +221,10 @@ public class MavenModuleBuilderHelper {
private void copyGeneratedFiles(File workingDir, VirtualFile pom, Project project) {
try {
FileUtil.copyDir(new File(workingDir, myProjectId.getArtifactId()), new File(pom.getParent().getPath()));
String artifactId = myProjectId.getArtifactId();
if (artifactId != null) {
FileUtil.copyDir(new File(workingDir, artifactId), new File(pom.getParent().getPath()));
}
}
catch (IOException e) {
showError(project, e);
@@ -134,7 +134,7 @@ public class MavenProjectBuilder extends ProjectImportBuilder<MavenProject> {
: new IdeModifiableModelsProviderImpl(project));
}
private void appendProfilesFromString(Collection<String> selectedProfiles, String profilesList) {
private static void appendProfilesFromString(Collection<String> selectedProfiles, String profilesList) {
if (profilesList == null) return;
for (String profile : StringUtil.split(profilesList, ",")) {
@@ -23,6 +23,7 @@ import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.projectImport.ProjectImportWizardStep;
import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
@@ -69,19 +70,19 @@ public class MavenProjectImportStep extends ProjectImportWizardStep {
c.gridy = 0;
c.weightx = 1;
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(4, 4, 0, 4);
c.insets = JBUI.insets(4, 4, 0, 4);
myPanel.add(myRootPathComponent, c);
c.gridy = 1;
c.insets = new Insets(4, 4, 0, 4);
c.insets = JBUI.insets(4, 4, 0, 4);
myPanel.add(myImportingSettingsForm.createComponent(), c);
c.gridy = 2;
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.NORTHEAST;
c.weighty = 1;
c.insets = new Insets(4 + envSettingsButton.getPreferredSize().height, 4, 4, 4);
c.insets = JBUI.insets(4 + envSettingsButton.getPreferredSize().height, 4, 4, 4);
myPanel.add(envSettingsButton, c);
myRootPathComponent.setNameComponentVisible(false);
@@ -115,10 +116,8 @@ public class MavenProjectImportStep extends ProjectImportWizardStep {
else {
path = getWizardContext().getProjectFileDirectory();
}
if (path != null) {
myRootPathComponent.setPath(FileUtil.toSystemDependentName(path));
myRootPathComponent.getPathComponent().selectAll();
}
myRootPathComponent.setPath(FileUtil.toSystemDependentName(path));
myRootPathComponent.getPathComponent().selectAll();
}
myImportingSettingsForm.setData(getImportingSettings());
}
@@ -29,7 +29,7 @@ import org.jetbrains.idea.maven.model.MavenConstants;
import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
import org.jetbrains.idea.maven.project.MavenProject;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class MavenProjectOpenProcessor extends ProjectOpenProcessorBase<MavenProjectBuilder> {
@@ -43,7 +43,7 @@ public class MavenProjectOpenProcessor extends ProjectOpenProcessorBase<MavenPro
}
public boolean doQuickImport(VirtualFile file, WizardContext wizardContext) {
getBuilder().setFiles(Arrays.asList(file));
getBuilder().setFiles(Collections.singletonList(file));
if (!getBuilder().setSelectedProfiles(MavenExplicitProfiles.NONE)) return false;