diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index d4188a070243..3a269c4c3245 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -817,9 +817,9 @@ public final class PlatformTestUtil { } public static @NotNull String getCommunityPath() { - final String homePath = IdeaTestExecutionPolicy.getHomePathWithPolicy(); + String homePath = IdeaTestExecutionPolicy.getHomePathWithPolicy(); if (new File(homePath, "community/.idea").isDirectory()) { - return homePath + File.separatorChar + "community"; + homePath = homePath + File.separatorChar + "community"; } return homePath; } diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/IdeaTestExecutionPolicy.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/IdeaTestExecutionPolicy.java index 9f7911cfe4a8..61b6a6dfedfa 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/IdeaTestExecutionPolicy.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/IdeaTestExecutionPolicy.java @@ -17,6 +17,8 @@ import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.InvocationTargetException; + /** * Allows to customize the test execution environment for the entire test execution without modifying the source code * of tests. To specify a test execution policy, set the system property "idea.test.execution.policy" to the FQ name @@ -83,8 +85,9 @@ public abstract class IdeaTestExecutionPolicy implements TestModeFlagListener { if (policyClassName == null) return null; try { Class policyClass = Class.forName(policyClassName); - ourCurrent = (IdeaTestExecutionPolicy) policyClass.newInstance(); - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + ourCurrent = (IdeaTestExecutionPolicy)policyClass.getDeclaredConstructor().newInstance(); + } + catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new RuntimeException(e); } return ourCurrent; diff --git a/platform/util/src/com/intellij/openapi/application/PathManager.java b/platform/util/src/com/intellij/openapi/application/PathManager.java index 0817d32619a7..93cf7706c809 100644 --- a/platform/util/src/com/intellij/openapi/application/PathManager.java +++ b/platform/util/src/com/intellij/openapi/application/PathManager.java @@ -144,9 +144,7 @@ public final class PathManager { if (rootPath == null) return null; Path root = Paths.get(rootPath).toAbsolutePath(); - do { - root = root.getParent(); - } while (root != null && !isIdeaHome(root)); + do root = root.getParent(); while (root != null && !isIdeaHome(root)); return root != null ? root.toString() : null; } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenImporter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenImporter.java index 4a7fa9d181ad..3e6217f5ba11 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenImporter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenImporter.java @@ -1,6 +1,7 @@ // Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.idea.maven.importing; +import com.intellij.ide.util.projectWizard.ModuleBuilder; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider; import com.intellij.openapi.module.Module; @@ -28,6 +29,7 @@ import java.util.*; public abstract class MavenImporter { public static final ExtensionPointName EXTENSION_POINT_NAME = ExtensionPointName.create("org.jetbrains.idea.maven.importer"); + protected final String myPluginGroupID; protected final String myPluginArtifactID; @@ -38,7 +40,7 @@ public abstract class MavenImporter { public static List getSuitableImporters(MavenProject p) { List result = null; - Set moduleTypes = null; + Set> moduleTypes = null; for (MavenImporter importer : EXTENSION_POINT_NAME.getExtensions()) { if (importer.isApplicable(p)) { @@ -63,18 +65,18 @@ public abstract class MavenImporter { // This code is reached when several importers say that they are applicable but they want to have different module types. // Now we select one module type and return only those importers that are ok with it. // If possible - return at least one importer that explicitly supports packaging of the given maven project. - ModuleType moduleType = result.get(0).getModuleType(); - List supportedPackagings = new ArrayList<>(); + ModuleType moduleType = result.get(0).getModuleType(); + List supportedPackagingTypes = new ArrayList<>(); for (MavenImporter importer : result) { - supportedPackagings.clear(); - importer.getSupportedPackagings(supportedPackagings); - if (supportedPackagings.contains(p.getPackaging())) { + supportedPackagingTypes.clear(); + importer.getSupportedPackagings(supportedPackagingTypes); + if (supportedPackagingTypes.contains(p.getPackaging())) { moduleType = importer.getModuleType(); break; } } - final ModuleType finalModuleType = moduleType; + final ModuleType finalModuleType = moduleType; return ContainerUtil.filter(result, importer -> importer.getModuleType() == finalModuleType); } @@ -82,30 +84,25 @@ public abstract class MavenImporter { return mavenProject.findPlugin(myPluginGroupID, myPluginArtifactID) != null; } - @NotNull - public ModuleType getModuleType() { + public @NotNull ModuleType getModuleType() { return StdModuleTypes.JAVA; } - public void getSupportedPackagings(Collection result) { - } + @SuppressWarnings("SpellCheckingInspection") + public void getSupportedPackagings(Collection result) { } - public void getSupportedDependencyTypes(Collection result, SupportedRequestType type) { - } + public void getSupportedDependencyTypes(Collection result, SupportedRequestType type) { } - public void getSupportedDependencyScopes(Collection result) { - } + public void getSupportedDependencyScopes(Collection result) { } - @Nullable - public Pair getExtraArtifactClassifierAndExtension(MavenArtifact artifact, MavenExtraArtifactType type) { + public @Nullable Pair getExtraArtifactClassifierAndExtension(MavenArtifact artifact, MavenExtraArtifactType type) { return null; } - /** - * @deprecated use {@link #resolve(Project, MavenProject, NativeMavenProjectHolder, MavenEmbedderWrapper, ResolveContext)} - */ + /** @deprecated use {@link #resolve(Project, MavenProject, NativeMavenProjectHolder, MavenEmbedderWrapper, ResolveContext)} */ @Deprecated @ApiStatus.ScheduledForRemoval(inVersion = "2021.3") + @SuppressWarnings("unused") public void resolve(Project project, MavenProject mavenProject, NativeMavenProjectHolder nativeMavenProject, @@ -146,6 +143,7 @@ public abstract class MavenImporter { return true; } + @SuppressWarnings("BoundedWildcard") public void collectSourceRoots(MavenProject mavenProject, PairConsumer> result) { List sources = new ArrayList<>(); collectSourceFolders(mavenProject, sources); @@ -159,58 +157,46 @@ public abstract class MavenImporter { } } - /** - * @deprecated override {@link #collectSourceRoots} instead - */ + /** @deprecated override {@link #collectSourceRoots} instead */ @Deprecated @ApiStatus.ScheduledForRemoval(inVersion = "2021.3") - public void collectSourceFolders(MavenProject mavenProject, List result) { - } + @SuppressWarnings("unused") + public void collectSourceFolders(MavenProject mavenProject, List result) { } - /** - * @deprecated override {@link #collectSourceRoots} instead - */ + /** @deprecated override {@link #collectSourceRoots} instead */ @Deprecated @ApiStatus.ScheduledForRemoval(inVersion = "2021.3") - public void collectTestFolders(MavenProject mavenProject, List result) { - } + @SuppressWarnings("unused") + public void collectTestFolders(MavenProject mavenProject, List result) { } - public void collectExcludedFolders(MavenProject mavenProject, List result) { - } + public void collectExcludedFolders(MavenProject mavenProject, List result) { } - @Nullable - protected Element getConfig(MavenProject p) { + protected @Nullable Element getConfig(MavenProject p) { return p.getPluginConfiguration(myPluginGroupID, myPluginArtifactID); } - @Nullable - protected Element getConfig(MavenProject p, @NonNls String path) { + protected @Nullable Element getConfig(MavenProject p, @NonNls String path) { return MavenJDOMUtil.findChildByPath(getConfig(p), path); } - @Nullable - protected String findConfigValue(MavenProject p, @NonNls String path) { + protected @Nullable String findConfigValue(MavenProject p, @NonNls String path) { return MavenJDOMUtil.findChildValueByPath(getConfig(p), path); } - @Nullable - protected String findConfigValue(MavenProject p, @NonNls String path, @NonNls String defaultValue) { + protected @Nullable String findConfigValue(MavenProject p, @NonNls String path, @NonNls String defaultValue) { return MavenJDOMUtil.findChildValueByPath(getConfig(p), path, defaultValue); } - @Nullable - protected Element getGoalConfig(MavenProject p, @NonNls String goal) { + protected @Nullable Element getGoalConfig(MavenProject p, @NonNls String goal) { return p.getPluginGoalConfiguration(myPluginGroupID, myPluginArtifactID, goal); } - @Nullable - protected String findGoalConfigValue(MavenProject p, @NonNls String goal, @NonNls String path) { + protected @Nullable String findGoalConfigValue(MavenProject p, @NonNls String goal, @NonNls String path) { return MavenJDOMUtil.findChildValueByPath(getGoalConfig(p, goal), path); } /** * Override this method if you'd like control over properties used by Maven, e.g. for pom interpolation. */ - public void customizeUserProperties(Project project, MavenProject mavenProject, Properties properties) { - } + public void customizeUserProperties(Project project, MavenProject mavenProject, Properties properties) { } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java index 1084aa444c3e..7a1f397e5aac 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java @@ -2,6 +2,7 @@ package org.jetbrains.idea.maven.project; import com.intellij.execution.configurations.ParametersList; +import com.intellij.ide.util.projectWizard.ModuleBuilder; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.module.ModuleType; @@ -45,8 +46,8 @@ import java.util.concurrent.ConcurrentHashMap; import static com.intellij.openapi.roots.OrderEnumerator.orderEntries; import static org.jetbrains.idea.maven.model.MavenProjectProblem.ProblemType.SYNTAX; +@SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter", "SynchronizeOnNonFinalField"}) public class MavenProject { - private static final Key DEPENDENCIES_CACHE_KEY = Key.create("MavenProject.DEPENDENCIES_CACHE_KEY"); private static final Key> FILTERS_CACHE_KEY = Key.create("MavenProject.FILTERS_CACHE_KEY"); @@ -63,13 +64,12 @@ public class MavenProject { } } - @NotNull private final VirtualFile myFile; - @NotNull private volatile State myState = new State(); + private final @NotNull VirtualFile myFile; + private volatile @NotNull State myState = new State(); public enum ProcMode {BOTH, ONLY, NONE} - @Nullable - public static MavenProject read(DataInputStream in) throws IOException { + public static @Nullable MavenProject read(DataInputStream in) throws IOException { String path = in.readUTF(); int length = in.readInt(); byte[] bytes = new byte[length]; @@ -287,8 +287,7 @@ public class MavenProject { return myState.myLastReadStamp; } - @NotNull - public VirtualFile getFile() { + public @NotNull VirtualFile getFile() { return myFile; } @@ -296,24 +295,19 @@ public class MavenProject { return myFile.getPresentableUrl(); } - @NotNull - @NlsSafe - public String getDirectory() { + public @NotNull @NlsSafe String getDirectory() { return myFile.getParent().getPath(); } - @NotNull - public VirtualFile getDirectoryFile() { + public @NotNull VirtualFile getDirectoryFile() { return myFile.getParent(); } - @Nullable - public VirtualFile getProfilesXmlFile() { + public @Nullable VirtualFile getProfilesXmlFile() { return MavenUtil.findProfilesXmlFile(myFile); } - @Nullable - public File getProfilesXmlIoFile() { + public @Nullable File getProfilesXmlIoFile() { return MavenUtil.getProfilesXmlIoFile(myFile); } @@ -321,15 +315,11 @@ public class MavenProject { return !myState.myReadingProblems.isEmpty(); } - @Nullable - @NlsSafe - public String getName() { + public @Nullable @NlsSafe String getName() { return myState.myName; } - @NotNull - @NlsSafe - public String getDisplayName() { + public @NotNull @NlsSafe String getDisplayName() { State state = myState; if (StringUtil.isEmptyOrSpaces(state.myName)) { return StringUtil.notNullize(state.myMavenId.getArtifactId()); @@ -337,54 +327,39 @@ public class MavenProject { return state.myName; } - @NotNull - public Map getModelMap() { + public @NotNull Map getModelMap() { return myState.myModelMap; } - @NotNull - public MavenId getMavenId() { + public @NotNull MavenId getMavenId() { return myState.myMavenId; } - @Nullable - public MavenId getParentId() { + public @Nullable MavenId getParentId() { return myState.myParentId; } - @NotNull - @NlsSafe - public String getPackaging() { + public @NotNull @NlsSafe String getPackaging() { return myState.myPackaging; } - @NotNull - @NlsSafe - public String getFinalName() { + public @NotNull @NlsSafe String getFinalName() { return myState.myFinalName; } - @Nullable - @NlsSafe - public String getDefaultGoal() { + public @Nullable @NlsSafe String getDefaultGoal() { return myState.myDefaultGoal; } - @NotNull - @NlsSafe - public String getBuildDirectory() { + public @NotNull @NlsSafe String getBuildDirectory() { return myState.myBuildDirectory; } - @NotNull - @NlsSafe - public String getGeneratedSourcesDirectory(boolean testSources) { + public @NotNull @NlsSafe String getGeneratedSourcesDirectory(boolean testSources) { return getBuildDirectory() + (testSources ? "/generated-test-sources" : "/generated-sources"); } - @NotNull - @NlsSafe - public String getAnnotationProcessorDirectory(boolean testSources) { + public @NotNull @NlsSafe String getAnnotationProcessorDirectory(boolean testSources) { if (getProcMode() == ProcMode.NONE) { MavenPlugin bscMavenPlugin = findPlugin("org.bsc.maven", "maven-processor-plugin"); Element cfg = getPluginGoalConfiguration(bscMavenPlugin, testSources ? "process-test" : "process"); @@ -413,8 +388,7 @@ public class MavenProject { getCompilerConfig(), testSources ? "generatedTestSourcesDirectory" : "generatedSourcesDirectory", def); } - @NotNull - public ProcMode getProcMode() { + public @NotNull ProcMode getProcMode() { Element compilerConfiguration = getPluginExecutionConfiguration("org.apache.maven.plugins", "maven-compiler-plugin", "default-compile"); if (compilerConfiguration == null) { compilerConfiguration = getCompilerConfig(); @@ -473,7 +447,7 @@ public class MavenProject { Map res = new LinkedHashMap<>(); String compilerArgument = compilerConfig.getChildText("compilerArgument"); - addAnnotationProcessorOptionFomrParametersString(compilerArgument, res); + addAnnotationProcessorOptionFromParameterString(compilerArgument, res); Element compilerArgs = compilerConfig.getChild("compilerArgs"); if (compilerArgs != null) { @@ -498,7 +472,7 @@ public class MavenProject { return res; } - private static void addAnnotationProcessorOptionFomrParametersString(String compilerArguments, Map res) { + private static void addAnnotationProcessorOptionFromParameterString(String compilerArguments, Map res) { if (!StringUtil.isEmptyOrSpaces(compilerArguments)) { ParametersList parametersList = new ParametersList(); parametersList.addParametersString(compilerArguments); @@ -530,7 +504,7 @@ public class MavenProject { LinkedHashMap res = new LinkedHashMap<>(); if (cfg != null) { String compilerArguments = cfg.getChildText("compilerArguments"); - addAnnotationProcessorOptionFomrParametersString(compilerArguments, res); + addAnnotationProcessorOptionFromParameterString(compilerArguments, res); final Element optionsElement = cfg.getChild("options"); if (optionsElement != null) { @@ -542,8 +516,7 @@ public class MavenProject { return res; } - @Nullable - public List<@NlsSafe String> getDeclaredAnnotationProcessors() { + public @Nullable List<@NlsSafe String> getDeclaredAnnotationProcessors() { Element compilerConfig = getCompilerConfig(); if (compilerConfig == null) { return null; @@ -586,40 +559,31 @@ public class MavenProject { return result; } - @NotNull - @NlsSafe - public String getOutputDirectory() { + public @NotNull @NlsSafe String getOutputDirectory() { return myState.myOutputDirectory; } - @NotNull - @NlsSafe - public String getTestOutputDirectory() { + public @NotNull @NlsSafe String getTestOutputDirectory() { return myState.myTestOutputDirectory; } - @NotNull - public List<@NlsSafe String> getSources() { + public @NotNull List<@NlsSafe String> getSources() { return myState.mySources; } - @NotNull - public List<@NlsSafe String> getTestSources() { + public @NotNull List<@NlsSafe String> getTestSources() { return myState.myTestSources; } - @NotNull - public List getResources() { + public @NotNull List getResources() { return myState.myResources; } - @NotNull - public List getTestResources() { + public @NotNull List getTestResources() { return myState.myTestResources; } - @NotNull - public List<@NlsSafe String> getFilters() { + public @NotNull List<@NlsSafe String> getFilters() { return myState.myFilters; } @@ -663,8 +627,7 @@ public class MavenProject { } } - @Nullable - public String getConfigFileError() { + public @Nullable String getConfigFileError() { return myState .myReadingProblems.stream().filter(p -> p.getPath().endsWith(MavenConstants.MAVEN_CONFIG_RELATIVE_PATH)) .map(p -> p.getDescription()) @@ -672,21 +635,19 @@ public class MavenProject { .orElse(null); } - @NotNull - public MavenProjectChanges read(@NotNull MavenGeneralSettings generalSettings, - @NotNull MavenExplicitProfiles profiles, - @NotNull MavenProjectReader reader, - @NotNull MavenProjectReaderProjectLocator locator) { + public @NotNull MavenProjectChanges read(@NotNull MavenGeneralSettings generalSettings, + @NotNull MavenExplicitProfiles profiles, + @NotNull MavenProjectReader reader, + @NotNull MavenProjectReaderProjectLocator locator) { return set(reader.readProject(generalSettings, myFile, profiles, locator), generalSettings, true, false, true); } - @NotNull - public Pair resolve(@NotNull Project project, - @NotNull MavenGeneralSettings generalSettings, - @NotNull MavenEmbedderWrapper embedder, - @NotNull MavenProjectReader reader, - @NotNull MavenProjectReaderProjectLocator locator, - @NotNull ResolveContext context) + public @NotNull Pair resolve(@NotNull Project project, + @NotNull MavenGeneralSettings generalSettings, + @NotNull MavenEmbedderWrapper embedder, + @NotNull MavenProjectReader reader, + @NotNull MavenProjectReaderProjectLocator locator, + @NotNull ResolveContext context) throws MavenProcessCanceledException { Collection results = reader.resolveProject(generalSettings, embedder, @@ -705,10 +666,9 @@ public class MavenProject { return Pair.create(changes, result.nativeMavenProject); } - @NotNull - public Pair resolveFolders(@NotNull MavenEmbedderWrapper embedder, - @NotNull MavenImportingSettings importingSettings, - @NotNull MavenConsole console) throws MavenProcessCanceledException { + public @NotNull Pair resolveFolders(@NotNull MavenEmbedderWrapper embedder, + @NotNull MavenImportingSettings importingSettings, + @NotNull MavenConsole console) throws MavenProcessCanceledException { MavenProjectReaderResult result = MavenProjectReader.generateSources(embedder, importingSettings, getFile(), @@ -730,8 +690,7 @@ public class MavenProject { return "pom".equals(getPackaging()) || !getModulePaths().isEmpty(); } - @NotNull - public List getProblems() { + public @NotNull List getProblems() { State state = myState; synchronized (state) { if (state.myProblemsCache == null) { @@ -858,8 +817,7 @@ public class MavenProject { } } - @NotNull - public List getExistingModuleFiles() { + public @NotNull List getExistingModuleFiles() { LocalFileSystem fs = LocalFileSystem.getInstance(); List result = new ArrayList<>(); @@ -871,38 +829,31 @@ public class MavenProject { return result; } - @NotNull - public Set getModulePaths() { + public @NotNull Set getModulePaths() { return getModulesPathsAndNames().keySet(); } - @NotNull - public Map getModulesPathsAndNames() { + public @NotNull Map getModulesPathsAndNames() { return myState.myModulesPathsAndNames; } - @NotNull - public Collection getProfilesIds() { + public @NotNull Collection getProfilesIds() { return myState.myProfilesIds; } - @NotNull - public MavenExplicitProfiles getActivatedProfilesIds() { + public @NotNull MavenExplicitProfiles getActivatedProfilesIds() { return myState.myActivatedProfilesIds; } - @NotNull - public List getDependencies() { + public @NotNull List getDependencies() { return myState.myDependencies; } - @NotNull - public List getExternalAnnotationProcessors() { + public @NotNull List getExternalAnnotationProcessors() { return myState.myAnnotationProcessors; } - @NotNull - public String getAnnotationProcessorPath(Project project) { + public @NotNull String getAnnotationProcessorPath(Project project) { StringJoiner annotationProcessorPath = new StringJoiner(File.pathSeparator); Consumer resultAppender = path -> annotationProcessorPath.add(FileUtil.toSystemDependentName(path)); @@ -930,16 +881,14 @@ public class MavenProject { return annotationProcessorPath.toString(); } - @NotNull - public List getDependencyTree() { + public @NotNull List getDependencyTree() { return myState.myDependencyTree; } - @NotNull - public Set getSupportedPackagings() { - Set result = ContainerUtil.newHashSet(MavenConstants.TYPE_POM, - MavenConstants.TYPE_JAR, - "ejb", "ejb-client", "war", "ear", "bundle", "maven-plugin"); + @SuppressWarnings("SpellCheckingInspection") + public @NotNull Set getSupportedPackagings() { + Set result = ContainerUtil.newHashSet( + MavenConstants.TYPE_POM, MavenConstants.TYPE_JAR, "ejb", "ejb-client", "war", "ear", "bundle", "maven-plugin"); for (MavenImporter each : getSuitableImporters()) { each.getSupportedPackagings(result); } @@ -956,8 +905,7 @@ public class MavenProject { return res; } - @NotNull - public Set getSupportedDependencyScopes() { + public @NotNull Set getSupportedDependencyScopes() { Set result = ContainerUtil.set(MavenConstants.SCOPE_COMPILE, MavenConstants.SCOPE_PROVIDED, MavenConstants.SCOPE_RUNTIME, @@ -987,8 +935,7 @@ public class MavenProject { state.myUnresolvedAnnotationProcessors = null; } - @NotNull - public List findDependencies(@NotNull MavenProject depProject) { + public @NotNull List findDependencies(@NotNull MavenProject depProject) { return findDependencies(depProject.getMavenId()); } @@ -996,8 +943,7 @@ public class MavenProject { return getDependencyArtifactIndex().findArtifacts(id); } - @NotNull - public List findDependencies(@NonNls @Nullable String groupId, @NonNls @Nullable String artifactId) { + public @NotNull List findDependencies(@NonNls @Nullable String groupId, @NonNls @Nullable String artifactId) { return getDependencyArtifactIndex().findArtifacts(groupId, artifactId); } @@ -1013,13 +959,11 @@ public class MavenProject { return !getUnresolvedPlugins(myState).isEmpty(); } - @NotNull - public List getPlugins() { + public @NotNull List getPlugins() { return myState.myPlugins; } - @NotNull - public List getDeclaredPlugins() { + public @NotNull List getDeclaredPlugins() { return getDeclaredPlugins(myState); } @@ -1027,18 +971,15 @@ public class MavenProject { return ContainerUtil.findAll(state.myPlugins, mavenPlugin -> !mavenPlugin.isDefault()); } - @Nullable - public Element getPluginConfiguration(@Nullable String groupId, @Nullable String artifactId) { + public @Nullable Element getPluginConfiguration(@Nullable String groupId, @Nullable String artifactId) { return getPluginGoalConfiguration(groupId, artifactId, null); } - @Nullable - public Element getPluginGoalConfiguration(@Nullable String groupId, @Nullable String artifactId, @Nullable String goal) { + public @Nullable Element getPluginGoalConfiguration(@Nullable String groupId, @Nullable String artifactId, @Nullable String goal) { return getPluginGoalConfiguration(findPlugin(groupId, artifactId), goal); } - @Nullable - public Element getPluginGoalConfiguration(@Nullable MavenPlugin plugin, @Nullable String goal) { + public @Nullable Element getPluginGoalConfiguration(@Nullable MavenPlugin plugin, @Nullable String goal) { if (plugin == null) return null; return goal == null ? plugin.getConfigurationElement() : plugin.getGoalConfiguration(goal); } @@ -1049,13 +990,11 @@ public class MavenProject { return plugin.getExecutionConfiguration(executionId); } - @Nullable - public MavenPlugin findPlugin(@Nullable String groupId, @Nullable String artifactId) { + public @Nullable MavenPlugin findPlugin(@Nullable String groupId, @Nullable String artifactId) { return findPlugin(groupId, artifactId, false); } - @Nullable - public MavenPlugin findPlugin(@Nullable String groupId, @Nullable String artifactId, final boolean explicitlyDeclaredOnly) { + public @Nullable MavenPlugin findPlugin(@Nullable String groupId, @Nullable String artifactId, final boolean explicitlyDeclaredOnly) { final List plugins = explicitlyDeclaredOnly ? getDeclaredPlugins() : getPlugins(); for (MavenPlugin each : plugins) { if (each.getMavenId().equals(groupId, artifactId)) return each; @@ -1063,13 +1002,11 @@ public class MavenProject { return null; } - @Nullable - public String getSourceEncoding() { + public @Nullable String getSourceEncoding() { return myState.myProperties.getProperty("project.build.sourceEncoding"); } - @Nullable - public String getResourceEncoding(Project project) { + public @Nullable String getResourceEncoding(Project project) { Element pluginConfiguration = getPluginConfiguration("org.apache.maven.plugins", "maven-resources-plugin"); if (pluginConfiguration != null) { @@ -1095,23 +1032,19 @@ public class MavenProject { return getSourceEncoding(); } - @Nullable - public String getSourceLevel() { + public @Nullable String getSourceLevel() { return getCompilerLevel("source"); } - @Nullable - public String getTargetLevel() { + public @Nullable String getTargetLevel() { return getCompilerLevel("target"); } - @Nullable - public String getReleaseLevel() { + public @Nullable String getReleaseLevel() { return getCompilerLevel("release"); } - @Nullable - private String getCompilerLevel(String level) { + private @Nullable String getCompilerLevel(String level) { String result = MavenJDOMUtil.findChildValueByPath(getCompilerConfig(), level); if (result == null) { @@ -1121,25 +1054,21 @@ public class MavenProject { return result; } - @Nullable - private Element getCompilerConfig() { + private @Nullable Element getCompilerConfig() { Element executionConfiguration = getPluginExecutionConfiguration("org.apache.maven.plugins", "maven-compiler-plugin", "default-compile"); if(executionConfiguration != null) return executionConfiguration; return getPluginConfiguration("org.apache.maven.plugins", "maven-compiler-plugin"); } - @NotNull - public Properties getProperties() { + public @NotNull Properties getProperties() { return myState.myProperties; } - @NotNull - public Map getMavenConfig() { + public @NotNull Map getMavenConfig() { return getPropertiesFromConfig(ConfigFileKind.MAVEN_CONFIG); } - @NotNull - private Map getPropertiesFromConfig(ConfigFileKind kind) { + private @NotNull Map getPropertiesFromConfig(ConfigFileKind kind) { Map mavenConfig = getCachedValue(kind.CACHE_KEY); if (mavenConfig == null) { mavenConfig = readConfigFile(MavenUtil.getBaseDir(getDirectoryFile()), kind); @@ -1149,13 +1078,11 @@ public class MavenProject { return mavenConfig; } - @NotNull - public Map getJvmConfig() { + public @NotNull Map getJvmConfig() { return getPropertiesFromConfig(ConfigFileKind.JVM_CONFIG); } - @NotNull - public static Map readConfigFile(final File baseDir, ConfigFileKind kind) { + public static @NotNull Map readConfigFile(final File baseDir, ConfigFileKind kind) { File configFile = new File(baseDir + FileUtil.toSystemDependentName(kind.myRelativeFilePath)); ParametersList parametersList = new ParametersList(); @@ -1170,30 +1097,25 @@ public class MavenProject { return config.isEmpty() ? Collections.emptyMap() : config; } - @NotNull - public File getLocalRepository() { + public @NotNull File getLocalRepository() { return myState.myLocalRepository; } - @NotNull - public List getRemoteRepositories() { + public @NotNull List getRemoteRepositories() { return myState.myRemoteRepositories; } - @NotNull - public List getSuitableImporters() { + public @NotNull List getSuitableImporters() { return MavenImporter.getSuitableImporters(this); } - @NotNull - public ModuleType getModuleType() { + public @NotNull ModuleType getModuleType() { final List importers = getSuitableImporters(); // getSuitableImporters() guarantees that all returned importers require the same module type return importers.size() > 0 ? importers.get(0).getModuleType() : StdModuleTypes.JAVA; } - @NotNull - public Pair getClassifierAndExtension(@NotNull MavenArtifact artifact, @NotNull MavenExtraArtifactType type) { + public @NotNull Pair getClassifierAndExtension(@NotNull MavenArtifact artifact, @NotNull MavenExtraArtifactType type) { for (MavenImporter each : getSuitableImporters()) { Pair result = each.getExtraArtifactClassifierAndExtension(artifact, type); if (result != null) return result; @@ -1211,20 +1133,17 @@ public class MavenProject { return res; } - @Nullable - public V getCachedValue(Key key) { - //noinspection unchecked - return (V)myState.myCache.get(key); + public @Nullable V getCachedValue(Key key) { + @SuppressWarnings("unchecked") V v = (V)myState.myCache.get(key); + return v; } - @NotNull - public V putCachedValue(Key key, @NotNull V value) { - ConcurrentHashMap map = myState.myCache; - Object oldValue = map.putIfAbsent(key, value); + public @NotNull V putCachedValue(Key key, @NotNull V value) { + Object oldValue = myState.myCache.putIfAbsent(key, value); if (oldValue != null) { - return (V)oldValue; + @SuppressWarnings("unchecked") V v = (V)oldValue; + return v; } - return value; } @@ -1280,7 +1199,7 @@ public class MavenProject { volatile List myUnresolvedExtensionsCache; volatile List myUnresolvedAnnotationProcessors; - transient ConcurrentHashMap myCache = new ConcurrentHashMap<>(); + transient ConcurrentHashMap, Object> myCache = new ConcurrentHashMap<>(); @Override public State clone() {