Skip to content

Commit

Permalink
Replace Arrays by suitable Collections in m2e.core APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Jul 5, 2022
1 parent 03f131d commit 8b876a6
Show file tree
Hide file tree
Showing 59 changed files with 207 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.eclipse.core.resources.IFolder;
Expand Down Expand Up @@ -72,7 +73,8 @@ public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception
}
if(!buildContext.hasDelta(mavenProjectFacade.getPomFile())) {

IPath[] sources = "compile".equals(mojoExecution.getGoal()) ? mavenProjectFacade.getCompileSourceLocations()
List<IPath> sources = "compile".equals(mojoExecution.getGoal()) //
? mavenProjectFacade.getCompileSourceLocations()
: mavenProjectFacade.getTestCompileSourceLocations();

boolean hasSourceChanged = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.m2e.core.ui.internal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

Expand All @@ -36,7 +37,7 @@

public class UpdateMavenProjectJob extends WorkspaceJob {

private final IProject[] projects;
private final Collection<IProject> projects;

private final boolean offline;

Expand All @@ -48,12 +49,12 @@ public class UpdateMavenProjectJob extends WorkspaceJob {

private final boolean refreshFromLocal;

public UpdateMavenProjectJob(IProject[] projects) {
public UpdateMavenProjectJob(Collection<IProject> projects) {
this(projects, MavenPlugin.getMavenConfiguration().isOffline(), false /*forceUpdateDependencies*/,
true /*updateConfiguration*/, true /*rebuild*/, true /*refreshFromLocal*/);
}

public UpdateMavenProjectJob(IProject[] projects, boolean offline, boolean forceUpdateDependencies,
public UpdateMavenProjectJob(Collection<IProject> projects, boolean offline, boolean forceUpdateDependencies,
boolean updateConfiguration, boolean cleanProjects, boolean refreshFromLocal) {

super(Messages.UpdateSourcesAction_job_update_conf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static IWorkingSet getOrCreateWorkingSet(String workingSetName) {
*
* @since 1.5
*/
public static void addToWorkingSet(IProject[] projects, String workingSetName) {
public static void addToWorkingSet(List<IProject> projects, String workingSetName) {
IWorkingSet[] workingSets = new IWorkingSet[] {getOrCreateWorkingSet(workingSetName)};
IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
for(IProject project : projects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ public IStatus runInWorkspace(IProgressMonitor monitor) {

boolean offline = mavenConfiguration.isOffline();
boolean updateSnapshots = false;
projectManager.refresh(new MavenUpdateRequest(projects.toArray(new IProject[projects.size()]), //
offline, updateSnapshots));
projectManager.refresh(new MavenUpdateRequest(projects, offline, updateSnapshots));

return status != null ? status : Status.OK_STATUS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -81,7 +82,7 @@ public class NestedProjectsComposite extends Composite implements IMenuListener

Collection<IProject> projects;

IProject[] selectedProjects;
List<IProject> selectedProjects;

private Link includeOutDateProjectslink;

Expand Down Expand Up @@ -466,17 +467,13 @@ public IProject getSelection() {
return null;
}

public IProject[] getSelectedProjects() {
public List<IProject> getSelectedProjects() {
return selectedProjects;
}

IProject[] internalGetSelectedProjects() {
List<IProject> internalGetSelectedProjects() {
Object[] obj = codebaseViewer.getCheckedElements();
IProject[] projects = new IProject[obj.length];
for(int i = 0; i < obj.length; i++ ) {
projects[i] = (IProject) obj[i];
}
return projects;
return Arrays.stream(obj).map(IProject.class::cast).toList();
}

public void refresh() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package org.eclipse.m2e.core.ui.internal.dialogs;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -136,10 +136,10 @@ protected boolean isInteresting(IProject project) throws CoreException {
}

public void assignWorkingSets() {
IProject[] projects = selectedProjects.getSelectedProjects();
if(projects != null && projects.length > 0 && workingSetName != null && !workingSetName.isEmpty()) {
List<IProject> projects = selectedProjects.getSelectedProjects();
if(projects != null && !projects.isEmpty() && workingSetName != null && !workingSetName.isEmpty()) {
WorkingSets.addToWorkingSet(projects, workingSetName);
allWorkingSetProjects.addAll(Arrays.asList(projects));
allWorkingSetProjects.addAll(projects);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package org.eclipse.m2e.core.ui.internal.dialogs;

import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
Expand All @@ -39,7 +41,7 @@ public class UpdateMavenProjectsDialog extends TitleAreaDialog {

private final IProject[] initialSelection;

private IProject[] selectedProjects;
private List<IProject> selectedProjects;

private boolean offlineMode;

Expand Down Expand Up @@ -161,7 +163,7 @@ protected void okPressed() {
super.okPressed();
}

public IProject[] getSelectedProjects() {
public List<IProject> getSelectedProjects() {
return selectedProjects;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public boolean isSingleton() {
@Override
public void fix(IMarker[] markers, IDocument doc, IProgressMonitor monitor) {
final Set<IProject> projects = getProjects(Stream.of(markers));
new UpdateMavenProjectJob(projects.toArray(new IProject[projects.size()])).schedule();
new UpdateMavenProjectJob(projects).schedule();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.eclipse.m2e.core.ui.internal.preferences;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.jface.dialogs.MessageDialog;
Expand Down Expand Up @@ -137,18 +138,17 @@ private void updateProjects() {
String newChecksumPolicy = getPreferenceStore().getString(MavenPreferenceConstants.P_GLOBAL_CHECKSUM_POLICY);
boolean updateRequired = !originalChecksumPolicy.equals(newChecksumPolicy);
if(updateRequired) {
IMavenProjectFacade[] facades = MavenPlugin.getMavenProjectRegistry().getProjects();
if(facades != null && facades.length > 0) {
List<IMavenProjectFacade> facades = MavenPlugin.getMavenProjectRegistry().getProjects();
if(facades != null && !facades.isEmpty()) {
boolean proceed = MessageDialog.openQuestion(getShell(),
Messages.MavenPreferencePage_updateProjectRequired_title,
Messages.MavenPreferencePage_changingPreferencesRequiresProjectUpdate);
if(proceed) {
ArrayList<IProject> allProjects = new ArrayList<>(facades.length);
ArrayList<IProject> allProjects = new ArrayList<>(facades.size());
for(IMavenProjectFacade facade : facades) {
allProjects.add(facade.getProject());
}
new UpdateMavenProjectJob(
allProjects.toArray(new IProject[allProjects.size()]), //
new UpdateMavenProjectJob(allProjects, //
MavenPlugin.getMavenConfiguration().isOffline(), true /*forceUpdateDependencies*/,
false /*updateConfiguration*/, true /*rebuild*/, true /*refreshFromLocal*/).schedule();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ protected void updateSettings(boolean updateMavenDependencies) {
Boolean[] updateProjects = new Boolean[1];
updateProjects[0] = updateMavenDependencies;
if(updateMavenDependencies) {
IMavenProjectFacade[] projects = MavenPlugin.getMavenProjectRegistry().getProjects();
if(projects != null && projects.length > 0) {
List<IMavenProjectFacade> projects = MavenPlugin.getMavenProjectRegistry().getProjects();
if(projects != null && !projects.isEmpty()) {
updateProjects[0] = MessageDialog.openQuestion(getShell(),
Messages.MavenPreferencePage_updateProjectRequired_title,
Messages.MavenProjectPreferencePage_dialog_message);
Expand All @@ -143,19 +143,19 @@ protected void updateSettings(boolean updateMavenDependencies) {
mavenConfiguration.setUserSettingsFile(userSettings);

if(Boolean.TRUE.equals(updateProjects[0])) {
IMavenProjectFacade[] projects = MavenPlugin.getMavenProjectRegistry().getProjects();
List<IProject> allProjects = new ArrayList<>();
if(projects != null && projects.length > 0) {
List<IMavenProjectFacade> projects = MavenPlugin.getMavenProjectRegistry().getProjects();
if(projects != null && !projects.isEmpty()) {
MavenPlugin.getMaven().reloadSettings();

SubMonitor subMonitor = SubMonitor.convert(monitor, projects.length);
List<IProject> allProjects = new ArrayList<>();
SubMonitor subMonitor = SubMonitor.convert(monitor, projects.size());
for(IMavenProjectFacade project : projects) {
subMonitor.split(1).beginTask(
NLS.bind(Messages.MavenSettingsPreferencePage_task_updating, project.getProject().getName()), 1);
allProjects.add(project.getProject());
}
MavenPlugin.getMavenProjectRegistry().refresh(
new MavenUpdateRequest(allProjects.toArray(IProject[]::new), mavenConfiguration.isOffline(), true));
MavenPlugin.getMavenProjectRegistry()
.refresh(new MavenUpdateRequest(allProjects, mavenConfiguration.isOffline(), true));
subMonitor.done();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,17 @@ public boolean performOk() {
private void updateProjects() {
//Update projects if problem severities changed
if(isDirty()) {
IMavenProjectFacade[] facades = MavenPlugin.getMavenProjectRegistry().getProjects();
if(facades != null && facades.length > 0) {
List<IMavenProjectFacade> facades = MavenPlugin.getMavenProjectRegistry().getProjects();
if(facades != null && !facades.isEmpty()) {
boolean proceed = MessageDialog.openQuestion(getShell(),
Messages.MavenPreferencePage_updateProjectRequired_title,
Messages.MavenWarningsPreferencePage_changingProblemSeveritiesRequiresProjectUpdate);
if(proceed) {
ArrayList<IProject> allProjects = new ArrayList<>(facades.length);
ArrayList<IProject> allProjects = new ArrayList<>(facades.size());
for(IMavenProjectFacade facade : facades) {
allProjects.add(facade.getProject());
}
new UpdateMavenProjectJob(
allProjects.toArray(new IProject[allProjects.size()]), //
new UpdateMavenProjectJob(allProjects, //
MavenPlugin.getMavenConfiguration().isOffline(), true /*forceUpdateDependencies*/,
false /*updateConfiguration*/, true /*rebuild*/, true /*refreshFromLocal*/).schedule();
initOriginalValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ public IStatus run(IProgressMonitor monitor) {
CumulativeMappingDiscoveryJob.getInstance().addProjects(toProcessNow);
ProjectConfigurationManager configurationManager = (ProjectConfigurationManager) MavenPlugin
.getProjectConfigurationManager();
MavenUpdateRequest request = new MavenUpdateRequest(
toProcessNow.toArray(new IProject[toProcessNow.size()]), false, false);
MavenUpdateRequest request = new MavenUpdateRequest(toProcessNow, false, false);
configurationManager.updateProjectConfiguration(request, true,
false, false, monitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.jobs.Job;

import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob;
Expand Down Expand Up @@ -63,8 +62,7 @@ private boolean isDisabled() {
protected void updateProjectConfiguration(List<IProject> outOfDateProjects) {
if(outOfDateProjects != null && !outOfDateProjects.isEmpty()) {
LOG.debug("Automatic update of {}", outOfDateProjects);
Job updateJob = new UpdateMavenProjectJob(outOfDateProjects.toArray(new IProject[outOfDateProjects.size()]));
updateJob.schedule();
new UpdateMavenProjectJob(outOfDateProjects).schedule();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package org.eclipse.m2e.core.ui.internal.wizards;

import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
Expand Down Expand Up @@ -216,9 +218,9 @@ public void setVersion(String version) {
versionCombo.setText(version);
}

public void setPackagingTypes(String[] packagingTypes) {
public void setPackagingTypes(List<String> packagingTypes) {
if(packagingCombo != null) {
packagingCombo.setItems(packagingTypes);
packagingCombo.setItems(packagingTypes.toArray(String[]::new));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void run(IProgressMonitor monitor) {
}
}

new UpdateMavenProjectJob(changed.toArray(new IProject[changed.size()])).schedule();
new UpdateMavenProjectJob(changed).schedule();
}

private Collection<IProject> getProject(Collection<MavenProject> projects) {
Expand Down Expand Up @@ -201,7 +201,7 @@ private void ignoreAtDefinition(MojoExecutionKey key, Collection<MavenProject> p
private void ignoreWorkspace(MojoExecutionKey key) {
LifecycleMappingMetadataSource mapping = LifecycleMappingFactory.getWorkspaceMetadata(true);
LifecycleMappingFactory.addLifecyclePluginExecution(mapping, key.groupId(), key.artifactId(),
key.version(), new String[] {key.goal()}, PluginExecutionAction.ignore);
key.version(), List.of(key.goal()), PluginExecutionAction.ignore);
LifecycleMappingFactory.writeWorkspaceMetadata(mapping);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public boolean performFinish() {
}
}

final String[] folders = artifactPage.getFolders();
final List<String> folders = artifactPage.getFolders();

job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreatingProject, moduleName)) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

package org.eclipse.m2e.core.ui.internal.wizards;

import java.util.Arrays;
import java.util.List;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Expand Down Expand Up @@ -95,7 +98,7 @@ public void createControl(Composite parent) {
*/
private void initialize() {
String packagingToUse = MavenArtifactComponent.DEFAULT_PACKAGING;
String[] availablePackagingTypes = MavenArtifactComponent.PACKAGING_OPTIONS;
List<String> availablePackagingTypes = Arrays.asList(MavenArtifactComponent.PACKAGING_OPTIONS);
if(selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection ssel) {
if(ssel.size() > 1) {
return;
Expand All @@ -111,7 +114,7 @@ private void initialize() {
projectConversionEnabler = pcm.getConversionEnablerForProject(project);
if(projectConversionEnabler != null) {
availablePackagingTypes = projectConversionEnabler.getPackagingTypes(project);
packagingToUse = availablePackagingTypes[0];
packagingToUse = availablePackagingTypes.get(0);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public boolean performFinish() {
final AbstractCreateMavenProjectJob job;

if(simpleProject.getSelection()) {
final String[] folders = artifactPage.getFolders();
final List<String> folders = artifactPage.getFolders();

job = new AbstractCreateMavenProjectJob(NLS.bind(Messages.wizardProjectJobCreatingProject, projectName)) {
@Override
Expand Down
Loading

0 comments on commit 8b876a6

Please sign in to comment.