Skip to content

Commit

Permalink
fix several Java warnings
Browse files Browse the repository at this point in the history
* silence unchecked casts with generics
* replace Maven FileUtils by Apache IO FileUtils (in test)
* silence "discouraged reference" warning in tests
* silence overridden deprecated method warning
* remove unused variables, imports and exception declarations
  • Loading branch information
Bananeweizen authored and HannesWell committed Jan 30, 2023
1 parent 5f79164 commit e379405
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.internal.jobs.MavenJob;

Expand Down
3 changes: 2 additions & 1 deletion org.eclipse.m2e.core.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Require-Bundle: org.eclipse.m2e.tests.common,
org.eclipse.core.resources,
org.eclipse.core.runtime,
org.eclipse.m2e.maven.runtime
Import-Package: javax.annotation;version="1.2.0"
Import-Package: javax.annotation;version="1.2.0",
org.apache.commons.io
Eclipse-BundleShape: dir
Automatic-Module-Name: org.eclipse.m2e.core.tests
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import java.util.Arrays;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.utils.io.FileUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -62,7 +62,7 @@ public void testMNG6530() throws Exception {
FileLocator.toFileURL(getClass().getResource("/resources/projects/testMNG6530")).toURI());
File tempDirectory = Files.createTempDirectory(getClass().getSimpleName()).toFile();
try {
FileUtils.copyDirectoryStructure(sourceDirectory, tempDirectory);
FileUtils.copyDirectory(sourceDirectory, tempDirectory);
List<MavenProjectInfo> toImport = new ArrayList<>(2);
toImport.add(new MavenProjectInfo("", new File(tempDirectory, "pom.xml"), null, null));
toImport.add(new MavenProjectInfo("", new File(tempDirectory, "child/pom.xml"), null, null));
Expand All @@ -75,11 +75,11 @@ public void testMNG6530() throws Exception {
IMavenProjectFacade childFacade = MavenPlugin.getMavenProjectRegistry().getProject(child);
MavenProject mavenProject = childFacade.getMavenProject(new NullProgressMonitor());
assertEquals("bar", mavenProject.getProperties().get("foo"));

IFile pomXml = parent.getFile("pom.xml");
String content = Files.readString(Path.of(pomXml.getLocationURI())).replace("bar", "lol");
pomXml.setContents(new ByteArrayInputStream(content.getBytes()), true, false, null);

MavenPlugin.getProjectConfigurationManager().updateProjectConfiguration(child, monitor);
waitForJobsToComplete();
mavenProject = childFacade.getMavenProject(monitor);
Expand All @@ -100,7 +100,7 @@ public void testMultiModuleProjectDirectoryChild() throws Exception {
IMavenProjectFacade facade = MavenPluginActivator.getDefault().getMavenProjectManagerImpl().create(project.getFile("child/pom.xml"),
true, monitor);
Assert.assertNotNull(facade);
File[] multiModuleDirectory = new File[] { null };
File[] multiModuleDirectory = new File[] { null };
facade.createExecutionContext().execute((context, monitor) -> multiModuleDirectory[0] = context.getExecutionRequest().getMultiModuleProjectDirectory(), null);
assertEquals(project.getLocation().toFile(), multiModuleDirectory[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.NullProgressMonitor;

import org.apache.commons.io.FileUtils;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.utils.io.FileUtils;

import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.internal.IMavenConstants;
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.m2e.core/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=enabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public Server decryptPassword(Server server) throws CoreException {

@Override
public void mavenConfigurationChange(MavenConfigurationChangeEvent event) throws CoreException {
if(MavenConfigurationChangeEvent.P_USER_SETTINGS_FILE.equals(event.key())
if(MavenPreferenceConstants.P_USER_SETTINGS_FILE.equals(event.key())
|| MavenPreferenceConstants.P_GLOBAL_SETTINGS_FILE.equals(event.key())) {
reloadSettings();
}
Expand Down Expand Up @@ -486,7 +486,7 @@ public Map<File, MavenExecutionResult> readMavenProjects(Collection<File> pomFil

@Deprecated
@Override
public void detachFromSession(MavenProject project) throws CoreException {
public void detachFromSession(MavenProject project) {
//noop now
}

Expand Down Expand Up @@ -757,7 +757,7 @@ public <T> T getMojoParameterValue(MavenProject project, MojoExecution mojoExecu
* Resolves a nested configuration parameter from the given {@code mojoExecution}. It coerces from String to the given
* type and considers expressions and default values. Deliberately no public API yet as probably refactored in the
* near future.
*
*
* @param <T>
* @param project the Maven project
* @param mojoExecution the mojo execution from which to retrieve the configuration value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,6 @@ private static boolean isPomMapping(IPluginExecutionMetadata metadata) {
*/
public static List<MappingMetadataSource> getPomMappingMetadataSources(MavenProject mavenProject,
IProgressMonitor monitor) throws CoreException {
IMaven maven = MavenPlugin.getMaven();

List<MappingMetadataSource> sources = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ MutableProjectRegistry newMutableProjectRegistry() {
* @throws StaleMutableProjectRegistryException if primary project registry was modified after mutable registry has
* been created
*/
void applyMutableProjectRegistry(MutableProjectRegistry newState, IProgressMonitor monitor) throws CoreException {
void applyMutableProjectRegistry(MutableProjectRegistry newState, IProgressMonitor monitor) {
List<MavenProjectChangedEvent> events = projectRegistry.apply(newState);
//stateReader.writeWorkspaceState(projectRegistry);
notifyProjectChangeListeners(events, monitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.eclipse.ui.texteditor.ITextEditor;
import org.junit.Test;

@SuppressWarnings("restriction")
public class M2EEditorTest extends AbstractMavenProjectTestCase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ public Object getParent(Object element) {
public Object[] getElements(Object inputElement) {

if(inputElement instanceof LinkedList) {
@SuppressWarnings("unchecked")
LinkedList<MavenProject> projects = (LinkedList<MavenProject>) inputElement;
if(projects.isEmpty()) {
return new Object[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
Expand Down Expand Up @@ -595,15 +594,10 @@ protected IStatus run(IProgressMonitor monitor) {
String versionString = version == null ? null : XmlUtils.getTextValue(version);
if(prj != null && gridString != null && artidString != null
&& (versionString == null || versionString.contains("${"))) { //$NON-NLS-1$
try {
//TODO how do we decide here if the hyperlink is a dependency or a plugin
// hyperlink??
versionString = PomTemplateContext.extractVersion(prj, null, versionString, gridString, artidString,
PomTemplateContext.EXTRACT_STRATEGY_DEPENDENCY);

} catch(CoreException e) {
versionString = null;
}
//TODO how do we decide here if the hyperlink is a dependency or a plugin
// hyperlink??
versionString = PomTemplateContext.extractVersion(prj, null, versionString, gridString, artidString,
PomTemplateContext.EXTRACT_STRATEGY_DEPENDENCY);
}
if(versionString == null) {
return Status.OK_STATUS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ protected void addTemplates(final MavenProject project, IProject eclipseprj, Col
GROUP_ID("groupId") { //$NON-NLS-1$
@Override
public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node,
String prefix) throws CoreException {
String prefix) {
for(String groupId : getSearchEngine(eclipseprj).findGroupIds(prefix, getPackaging(node),
getContainingArtifact(node))) {
checkAndAdd(proposals, prefix, groupId);
Expand All @@ -324,7 +324,7 @@ public void addTemplates(MavenProject project, IProject eclipseprj, Collection<T
ARTIFACT_ID("artifactId") { //$NON-NLS-1$
@Override
public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node,
String prefix) throws CoreException {
String prefix) {
String groupId = getGroupId(node);
//#MNGECLIPSE-1832
if((groupId == null || groupId.trim().length() == 0) && "plugin".equals(node.getParentNode().getNodeName())) {
Expand All @@ -342,7 +342,7 @@ public void addTemplates(MavenProject project, IProject eclipseprj, Collection<T
VERSION("version") { //$NON-NLS-1$
@Override
public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node,
String prefix) throws CoreException {
String prefix) {
String groupId = getGroupId(node);
//#MNGECLIPSE-1832
if((groupId == null || groupId.trim().length() == 0) && "plugin".equals(node.getParentNode().getNodeName())) {
Expand Down Expand Up @@ -412,7 +412,7 @@ public void addTemplates(MavenProject project, IProject eclipseprj, Collection<T
CLASSIFIER("classifier") { //$NON-NLS-1$
@Override
public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node,
String prefix) throws CoreException {
String prefix) {
String groupId = getGroupId(node);
String artifactId = getArtifactId(node);
String version = getVersion(node);
Expand All @@ -428,7 +428,7 @@ public void addTemplates(MavenProject project, IProject eclipseprj, Collection<T
TYPE("type") { //$NON-NLS-1$
@Override
public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node,
String prefix) throws CoreException {
String prefix) {
String groupId = getGroupId(node);
String artifactId = getArtifactId(node);
String version = getVersion(node);
Expand Down Expand Up @@ -523,7 +523,7 @@ public void addTemplates(MavenProject project, IProject eclipseprj, Collection<T
GOAL("goal") { //$NON-NLS-1$
@Override
public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node,
String prefix) throws CoreException {
String prefix) {
if(!"goals".equals(node.getParentNode().getNodeName())) { //$NON-NLS-1$
return;
}
Expand Down Expand Up @@ -977,7 +977,7 @@ public static PomTemplateContext fromNode(Node node) {
return context;
}

protected static SearchEngine getSearchEngine(IProject project) throws CoreException {
protected static SearchEngine getSearchEngine(IProject project) {
if(searchEngineForTests != null) {
return searchEngineForTests;
}
Expand Down Expand Up @@ -1076,7 +1076,7 @@ protected void checkAndAdd(Collection<Template> proposals, String prefix, String
static int EXTRACT_STRATEGY_SEARCH = 4;

static String extractVersion(MavenProject mp, IProject project, String version, String groupId, String artifactId,
int strategy) throws CoreException {
int strategy) {

assert mp != null;
version = simpleInterpolate(mp, version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ private TranslatorAdapter createOrGetChildAdapter(EStructuralFeature feature) {

if(elementType != null
&& elementType.getClassifierID() == PomPackage.Literals.PROPERTY_ELEMENT.getClassifierID()) {
ret = new PropertiesAdapter(resource, element, (List<PropertyElement>) eobject.eGet(feature));
@SuppressWarnings("unchecked")
var adapter = new PropertiesAdapter(resource, element, (List<PropertyElement>) eobject.eGet(feature));
ret = adapter;
} else {
ret = new ListAdapter(resource, element, (List<?>) eobject.eGet(feature), elementType);
}
Expand Down

0 comments on commit e379405

Please sign in to comment.