Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use static Status factories in p2.director #339

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public int orderValue() {
public IStatus toStatus() {
MultiStatus result = new MultiStatus(DirectorActivator.PI_DIRECTOR, 1, Messages.Explanation_unsatisfied, null);
final String fromString = patch.toString() + ' ' + getUserReadableName(iu);
result.add(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_fromPatch, fromString)));
result.add(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_to, req)));
result.add(Status.error(NLS.bind(Messages.Explanation_fromPatch, fromString)));
result.add(Status.error(NLS.bind(Messages.Explanation_to, req)));
return result;
}

Expand Down Expand Up @@ -82,8 +82,8 @@ public int orderValue() {
@Override
public IStatus toStatus() {
MultiStatus result = new MultiStatus(DirectorActivator.PI_DIRECTOR, 1, Messages.Explanation_unsatisfied, null);
result.add(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_from, getUserReadableName(iu))));
result.add(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_to, req)));
result.add(Status.error(NLS.bind(Messages.Explanation_from, getUserReadableName(iu))));
result.add(Status.error(NLS.bind(Messages.Explanation_to, req)));
return result;
}

Expand Down Expand Up @@ -118,7 +118,7 @@ public String toString() {

@Override
public IStatus toStatus() {
return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_alreadyInstalled, getUserReadableName(iu)));
return Status.error(NLS.bind(Messages.Explanation_alreadyInstalled, getUserReadableName(iu)));
}

@Override
Expand Down Expand Up @@ -146,7 +146,7 @@ public String toString() {

@Override
public IStatus toStatus() {
return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_toInstall, getUserReadableName(iu)));
return Status.error(NLS.bind(Messages.Explanation_toInstall, getUserReadableName(iu)));
}

@Override
Expand All @@ -169,7 +169,7 @@ public String toString() {

@Override
public IStatus toStatus() {
return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_missingRootFilter, req));
return Status.error(NLS.bind(Messages.Explanation_missingRootFilter, req));
}

@Override
Expand Down Expand Up @@ -218,12 +218,13 @@ public String toString() {
@Override
public IStatus toStatus() {
if (isEntryPoint) {
return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_missingRootRequired, req));
return Status.error(NLS.bind(Messages.Explanation_missingRootRequired, req));
}
if (req.getFilter() == null) {
return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_missingRequired, getUserReadableName(iu), req));
return Status.error(NLS.bind(Messages.Explanation_missingRequired, getUserReadableName(iu), req));
}
return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_missingRequiredFilter, new Object[] {req.getFilter(), getUserReadableName(iu), req}));
return Status.error(NLS.bind(Messages.Explanation_missingRequiredFilter,
new Object[] { req.getFilter(), getUserReadableName(iu), req }));
}
}

Expand Down Expand Up @@ -251,7 +252,7 @@ public String toString() {

@Override
public IStatus toStatus() {
return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_missingNonGreedyRequired, getUserReadableName(iu)));
return Status.error(NLS.bind(Messages.Explanation_missingNonGreedyRequired, getUserReadableName(iu)));
}
}

Expand All @@ -276,7 +277,7 @@ public int shortAnswer() {
public IStatus toStatus() {
MultiStatus result = new MultiStatus(DirectorActivator.PI_DIRECTOR, 1, NLS.bind(Messages.Explanation_singleton, ""), null); //$NON-NLS-1$
for (IInstallableUnit iu : ius)
result.add(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, getUserReadableName(iu)));
result.add(Status.error(getUserReadableName(iu)));
return result;
}

Expand Down Expand Up @@ -334,7 +335,7 @@ public int compareTo(Explanation exp) {
* Returns a representation of this explanation as a status object.
*/
public IStatus toStatus() {
return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, toString());
return Status.error(toString());
}

protected static String getUserReadableName(IInstallableUnit iu) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ public void encode(IInstallableUnit entryPointIU, IInstallableUnit[] alreadyExis
System.out.println(solver.toString());
}
} catch (IllegalStateException e) {
result.add(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, e.getMessage(), e));
result.add(Status.error(e.getMessage(), e));
} catch (ContradictionException e) {
result.add(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, Messages.Planner_Unsatisfiable_problem));
result.add(Status.error(Messages.Planner_Unsatisfiable_problem));
}
}

Expand Down Expand Up @@ -798,7 +798,7 @@ private void expandLifeCycle(IInstallableUnit iu, boolean isRootIu) throws Contr
}

private void missingRequirement(IInstallableUnit iu, IRequirement req) throws ContradictionException {
result.add(new Status(IStatus.WARNING, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Planner_Unsatisfied_dependency, iu, req)));
result.add(Status.warning(NLS.bind(Messages.Planner_Unsatisfied_dependency, iu, req)));
createNegation(iu, req);
}

Expand Down Expand Up @@ -986,9 +986,9 @@ public IStatus invokeSolver(IProgressMonitor monitor) {
result.merge(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, SimplePlanner.UNSATISFIABLE, Messages.Planner_Unsatisfiable_problem, null));
}
} catch (TimeoutException e) {
result.merge(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, Messages.Planner_Timeout));
result.merge(Status.error(Messages.Planner_Timeout));
} catch (Exception e) {
result.merge(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, Messages.Planner_Unexpected_problem, e));
result.merge(Status.error(Messages.Planner_Unexpected_problem, e));
}
if (DEBUG)
System.out.println();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ private static IStatus convertExplanationToStatus(Set<Explanation> explanations)
&& "A.PDE.Target.Platform".equals(((IRequiredCapability) missingIU.req).getNamespace())) {//$NON-NLS-1$
// This IU requires the PDE target platform IU and it is missing.
// I.e. this IU is intended only for the PDE target platform.
forTargets.add(new Status(ERROR, PI_DIRECTOR, Explanation.getUserReadableName(missingIU.iu)));
forTargets.add(Status.error(Explanation.getUserReadableName(missingIU.iu)));
}
}
}
if (!forTargets.isEmpty()) {
// The following line could be removed if Bug 309863 is fixed
forTargets.add(new Status(ERROR, PI_DIRECTOR, Messages.Director_For_Target_Unselect_Required));
forTargets.add(Status.error(Messages.Director_For_Target_Unselect_Required));
// Return a multi status with all the IUs that require A.PDE.Target.Platform
return new MultiStatus(PI_DIRECTOR, 1, forTargets.stream().toArray(IStatus[]::new),
Messages.Director_For_Target, null);
Expand Down Expand Up @@ -625,7 +625,7 @@ private IProvisioningPlan createInstallerPlan(IProfile profile, ProfileChangeReq
sub.setTaskName(Messages.Director_Task_installer_plan);
if (profileRegistry == null) {
IProvisioningPlan plan = engine.createPlan(initialRequest.getProfile(), initialContext);
plan.setStatus(new Status(ERROR, PI_DIRECTOR, Messages.Planner_no_profile_registry));
plan.setStatus(Status.error(Messages.Planner_no_profile_registry));
return plan;
}

Expand All @@ -646,8 +646,8 @@ private IProvisioningPlan createInstallerPlan(IProfile profile, ProfileChangeReq
if (profile.getProfileId().equals(installerProfile.getProfileId())) {
if (profile.getTimestamp() != installerProfile.getTimestamp()) {
IProvisioningPlan plan = engine.createPlan(initialRequest.getProfile(), initialContext);
plan.setStatus(new Status(ERROR, PI_DIRECTOR,
NLS.bind(Messages.Planner_profile_out_of_sync, profile.getProfileId())));
plan.setStatus(
Status.error(NLS.bind(Messages.Planner_profile_out_of_sync, profile.getProfileId())));
return plan;
}
return createInstallerPlanForCohostedCase(profile, initialRequest, initialPlan, unattachedState,
Expand Down Expand Up @@ -803,7 +803,7 @@ private IProvisioningPlan createInstallerPlanForCohostedCase(IProfile profile, P
new ProfileChangeRequest(new EverythingOptionalProfile(initialRequest.getProfile())), noRepoContext,
new NullProgressMonitor());
if (initialSolution instanceof IProvisioningPlan) {
LogHelper.log(new Status(ERROR, PI_DIRECTOR, "The resolution of the previous state contained in profile " //$NON-NLS-1$
LogHelper.log(Status.error("The resolution of the previous state contained in profile " //$NON-NLS-1$
+ initialRequest.getProfile().getProfileId() + " version " //$NON-NLS-1$
+ initialRequest.getProfile().getTimestamp() + " failed.")); //$NON-NLS-1$
return (IProvisioningPlan) initialSolution;
Expand Down Expand Up @@ -836,7 +836,7 @@ private IProvisioningPlan generatePlan(Projector newSolution, Collection<IInstal
new ProfileChangeRequest(new EverythingOptionalProfile(request.getProfile())), noRepoContext,
new NullProgressMonitor());
if (initialSolution instanceof IProvisioningPlan) {
LogHelper.log(new Status(ERROR, PI_DIRECTOR,
LogHelper.log(Status.error(
"The resolution of the previous state contained in profile " + request.getProfile().getProfileId() //$NON-NLS-1$
+ " version " + request.getProfile().getTimestamp() + " failed.")); //$NON-NLS-1$//$NON-NLS-2$
return (IProvisioningPlan) initialSolution;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public IQueryable<IInstallableUnit> slice(IInstallableUnit[] ius, IProgressMonit
System.out.println("Slicing complete: " + (stop - start)); //$NON-NLS-1$
}
} catch (IllegalStateException e) {
result.add(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, e.getMessage(), e));
result.add(Status.error(e.getMessage(), e));
}
if (Tracing.DEBUG && result.getSeverity() != IStatus.OK)
LogHelper.log(result);
Expand Down Expand Up @@ -211,7 +211,7 @@ private void expandRequirement(IInstallableUnit iu, IRequirement req) {
if (DEBUG)
System.out.println("No IU found to satisfy optional dependency of " + iu + " on req " + req); //$NON-NLS-1$//$NON-NLS-2$
} else {
result.add(new Status(IStatus.WARNING, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Planner_Unsatisfied_dependency, iu, req)));
result.add(Status.warning(NLS.bind(Messages.Planner_Unsatisfied_dependency, iu, req)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static IStatus executePlan(IProvisioningPlan result, IEngine engine, IPha
try {
configChanger.applyConfiguration();
} catch (IOException e) {
return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, Messages.Director_error_applying_configuration, e);
return Status.error(Messages.Director_error_applying_configuration, e);
}
}
return engine.perform(result, phaseSet, progress);
Expand Down