diff options
author | Alexander Kurtakov | 2021-01-14 10:41:47 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2021-01-14 11:07:17 +0000 |
commit | e61940e1197f2958bb54c65940c754a11b25b5a2 (patch) | |
tree | 34ca395625a9ca4b7345654ae34519e9a899ffbb | |
parent | c173ee728bbb877ffc25790f2019d6dabd06aed2 (diff) | |
download | rt.equinox.p2-e61940e1197f2958bb54c65940c754a11b25b5a2.tar.gz rt.equinox.p2-e61940e1197f2958bb54c65940c754a11b25b5a2.tar.xz rt.equinox.p2-e61940e1197f2958bb54c65940c754a11b25b5a2.zip |
Use generic IProvisioningAgent.getService method.
Enable save action to auto remove no longer needed casts and other
useless constructs.
Change-Id: Ib17419d9d72fcb162af058f17f15afca12418699
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
4 files changed, 127 insertions, 45 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.equinox.p2.repository.tools/.settings/org.eclipse.jdt.ui.prefs index 9a640320c..b0c22ad5e 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/.settings/org.eclipse.jdt.ui.prefs +++ b/bundles/org.eclipse.equinox.p2.repository.tools/.settings/org.eclipse.jdt.ui.prefs @@ -7,36 +7,80 @@ org.eclipse.jdt.ui.importorder=; org.eclipse.jdt.ui.ondemandthreshold=3 org.eclipse.jdt.ui.staticondemandthreshold=3 org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates/> +sp_cleanup.add_all=false sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_generated_serial_version_id=false sp_cleanup.add_missing_annotations=true sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false sp_cleanup.add_missing_nls_tags=false sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true sp_cleanup.add_serial_version_id=false sp_cleanup.always_use_blocks=true sp_cleanup.always_use_parentheses_in_expressions=false sp_cleanup.always_use_this_for_non_static_field_access=false sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.arrays_fill=false +sp_cleanup.bitwise_conditional_expression=false +sp_cleanup.boolean_literal=false +sp_cleanup.break_loop=false +sp_cleanup.collection_cloning=false +sp_cleanup.comparison_statement=false +sp_cleanup.controlflow_merge=false +sp_cleanup.convert_functional_interfaces=false sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.convert_to_enhanced_for_loop_if_loop_var_used=false +sp_cleanup.convert_to_switch_expressions=false +sp_cleanup.correct_indentation=false +sp_cleanup.double_negation=false +sp_cleanup.else_if=false +sp_cleanup.embedded_if=false +sp_cleanup.evaluate_nullable=false +sp_cleanup.extract_increment=false sp_cleanup.format_source_code=true +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.hash=false +sp_cleanup.if_condition=false +sp_cleanup.insert_inferred_type_arguments=false +sp_cleanup.instanceof=false +sp_cleanup.join=false +sp_cleanup.lazy_logical_operator=false sp_cleanup.make_local_variable_final=false sp_cleanup.make_parameters_final=false sp_cleanup.make_private_fields_final=true -sp_cleanup.make_variable_declarations_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=false +sp_cleanup.map_cloning=false +sp_cleanup.merge_conditional_blocks=false +sp_cleanup.multi_catch=false sp_cleanup.never_use_blocks=false sp_cleanup.never_use_parentheses_in_expressions=true -sp_cleanup.on_save_use_additional_actions=false +sp_cleanup.no_string_creation=false +sp_cleanup.no_super=false +sp_cleanup.number_suffix=false +sp_cleanup.objects_equals=false +sp_cleanup.on_save_use_additional_actions=true sp_cleanup.organize_imports=true +sp_cleanup.overridden_assignment=false +sp_cleanup.precompile_regex=false +sp_cleanup.primitive_serialization=false +sp_cleanup.pull_up_assignment=false +sp_cleanup.push_down_negation=false sp_cleanup.qualify_static_field_accesses_with_declaring_class=false sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true sp_cleanup.qualify_static_member_accesses_with_declaring_class=false sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.redundant_falling_through_block_end=false sp_cleanup.remove_private_constructors=true -sp_cleanup.remove_trailing_whitespaces=false +sp_cleanup.remove_redundant_modifiers=false +sp_cleanup.remove_redundant_semicolons=true +sp_cleanup.remove_redundant_type_arguments=false +sp_cleanup.remove_trailing_whitespaces=true sp_cleanup.remove_trailing_whitespaces_all=true sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_array_creation=true sp_cleanup.remove_unnecessary_casts=true sp_cleanup.remove_unnecessary_nls_tags=false sp_cleanup.remove_unused_imports=false @@ -45,12 +89,27 @@ sp_cleanup.remove_unused_private_fields=true sp_cleanup.remove_unused_private_members=false sp_cleanup.remove_unused_private_methods=true sp_cleanup.remove_unused_private_types=true +sp_cleanup.simplify_lambda_expression_and_method_ref=true sp_cleanup.sort_members=false sp_cleanup.sort_members_all=false +sp_cleanup.static_inner_class=false +sp_cleanup.strictly_equal_or_different=false +sp_cleanup.stringbuilder=false +sp_cleanup.switch=false +sp_cleanup.ternary_operator=false +sp_cleanup.try_with_resource=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false sp_cleanup.use_blocks=false sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=false +sp_cleanup.use_lambda=false sp_cleanup.use_parentheses_in_expressions=false sp_cleanup.use_this_for_non_static_field_access=false sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true sp_cleanup.use_this_for_non_static_method_access=false sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true +sp_cleanup.use_unboxing=false +sp_cleanup.use_var=false +sp_cleanup.useless_continue=false +sp_cleanup.useless_return=false diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java index 90d958ea0..e2848334e 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 IBM Corporation and others. + * Copyright (c) 2009, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -35,7 +35,7 @@ import org.osgi.framework.ServiceReference; public abstract class AbstractApplication { protected boolean removeAddedRepositories = true; - protected List<RepositoryDescriptor> sourceRepositories = new ArrayList<>(); //List of repository descriptors + protected List<RepositoryDescriptor> sourceRepositories = new ArrayList<>(); // List of repository descriptors protected List<URI> artifactReposToRemove = new ArrayList<>(); protected List<URI> metadataReposToRemove = new ArrayList<>(); protected List<IInstallableUnit> sourceIUs = new ArrayList<>(); @@ -59,22 +59,24 @@ public abstract class AbstractApplication { } private void setupAgent() throws ProvisionException { - //note if we ever wanted these applications to act on a different agent than - //the currently running system we would need to set it here - ServiceReference<IProvisioningAgent> agentRef = Activator.getBundleContext().getServiceReference(IProvisioningAgent.class); + // note if we ever wanted these applications to act on a different agent than + // the currently running system we would need to set it here + ServiceReference<IProvisioningAgent> agentRef = Activator.getBundleContext() + .getServiceReference(IProvisioningAgent.class); if (agentRef != null) { agent = Activator.getBundleContext().getService(agentRef); if (agent != null) return; } - //there is no agent around so we need to create one - ServiceReference<IProvisioningAgentProvider> providerRef = Activator.getBundleContext().getServiceReference(IProvisioningAgentProvider.class); + // there is no agent around so we need to create one + ServiceReference<IProvisioningAgentProvider> providerRef = Activator.getBundleContext() + .getServiceReference(IProvisioningAgentProvider.class); if (providerRef == null) throw new RuntimeException("No provisioning agent provider is available"); //$NON-NLS-1$ IProvisioningAgentProvider provider = Activator.getBundleContext().getService(providerRef); if (provider == null) throw new RuntimeException("No provisioning agent provider is available"); //$NON-NLS-1$ - //obtain agent for currently running system + // obtain agent for currently running system agent = provider.createAgent(null); Activator.getBundleContext().ungetService(providerRef); } @@ -101,11 +103,11 @@ public abstract class AbstractApplication { } protected IMetadataRepositoryManager getMetadataRepositoryManager() { - return (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME); + return agent.getService(IMetadataRepositoryManager.class); } protected IArtifactRepositoryManager getArtifactRepositoryManager() { - return (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); + return agent.getService(IArtifactRepositoryManager.class); } public void initializeRepos(IProgressMonitor progress) throws ProvisionException { @@ -136,21 +138,26 @@ public abstract class AbstractApplication { processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager); } - //Helper to add a repository. It takes care of adding the repos to the deletion list and loading it - protected IMetadataRepository addRepository(IMetadataRepositoryManager manager, URI location, int flags, IProgressMonitor monitor) throws ProvisionException { + // Helper to add a repository. It takes care of adding the repos to the deletion + // list and loading it + protected IMetadataRepository addRepository(IMetadataRepositoryManager manager, URI location, int flags, + IProgressMonitor monitor) throws ProvisionException { if (!manager.contains(location)) metadataReposToRemove.add(location); return manager.loadRepository(location, flags, monitor); } - //Helper to add a repository. It takes care of adding the repos to the deletion list and loading it - protected IArtifactRepository addRepository(IArtifactRepositoryManager manager, URI location, int flags, IProgressMonitor monitor) throws ProvisionException { + // Helper to add a repository. It takes care of adding the repos to the deletion + // list and loading it + protected IArtifactRepository addRepository(IArtifactRepositoryManager manager, URI location, int flags, + IProgressMonitor monitor) throws ProvisionException { if (!manager.contains(location)) artifactReposToRemove.add(location); return manager.loadRepository(location, flags, monitor); } - private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException { + private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, + IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException { RepositoryDescriptor artifactRepoDescriptor = null; RepositoryDescriptor metadataRepoDescriptor = null; @@ -180,13 +187,15 @@ public abstract class AbstractApplication { return destinationArtifactRepository; } - protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException { + protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) + throws ProvisionException { try { - IMetadataRepository repository = addRepository(mgr, toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); + IMetadataRepository repository = addRepository(mgr, toInit.getRepoLocation(), + IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); if (initDestinationRepository(repository, toInit)) return repository; } catch (ProvisionException e) { - //fall through and create a new repository below + // fall through and create a new repository below } IMetadataRepository source = null; @@ -194,45 +203,57 @@ public abstract class AbstractApplication { if (toInit.getFormat() != null) source = mgr.loadRepository(toInit.getFormat(), 0, null); } catch (ProvisionException e) { - //Ignore. + // Ignore. } - //This code assumes source has been successfully loaded before this point - //No existing repository; create a new repository at destinationLocation but with source's attributes. + // This code assumes source has been successfully loaded before this point + // No existing repository; create a new repository at destinationLocation but + // with source's attributes. try { - IMetadataRepository result = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : toInit.getRepoLocation().toString()), IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null); + IMetadataRepository result = mgr.createRepository(toInit.getRepoLocation(), + toInit.getName() != null ? toInit.getName() + : (source != null ? source.getName() : toInit.getRepoLocation().toString()), + IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null); if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED)) result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$ return (IMetadataRepository) RepositoryHelper.validDestinationRepository(result); } catch (UnsupportedOperationException e) { - throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause()); + throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), + e.getCause()); } } - protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException { + protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) + throws ProvisionException { try { - IArtifactRepository repository = addRepository(mgr, toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); + IArtifactRepository repository = addRepository(mgr, toInit.getRepoLocation(), + IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); if (initDestinationRepository(repository, toInit)) return repository; } catch (ProvisionException e) { - //fall through and create a new repository below + // fall through and create a new repository below } IArtifactRepository source = null; try { if (toInit.getFormat() != null) source = mgr.loadRepository(toInit.getFormat(), 0, null); } catch (ProvisionException e) { - //Ignore. + // Ignore. } - //This code assumes source has been successfully loaded before this point - //No existing repository; create a new repository at destinationLocation but with source's attributes. + // This code assumes source has been successfully loaded before this point + // No existing repository; create a new repository at destinationLocation but + // with source's attributes. // TODO for now create a Simple repo by default. try { - IArtifactRepository result = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : toInit.getRepoLocation().toString()), IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null); + IArtifactRepository result = mgr.createRepository(toInit.getRepoLocation(), + toInit.getName() != null ? toInit.getName() + : (source != null ? source.getName() : toInit.getRepoLocation().toString()), + IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null); if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED)) result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$ return (IArtifactRepository) RepositoryHelper.validDestinationRepository(result); } catch (UnsupportedOperationException e) { - throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause()); + throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), + e.getCause()); } } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Activator.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Activator.java index 0a449ecd7..567e2ccf7 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Activator.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Activator.java @@ -1,13 +1,13 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 IBM Corporation and others. + * Copyright (c) 2009, 2021 IBM Corporation and others. * - * This program and the accompanying materials + * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation * Red Hat Inc. - Bug 460967 @@ -51,8 +51,8 @@ public class Activator implements BundleActivator { } /* - * Construct and return a URI from the given String. Log - * and return null if there was a problem. + * Construct and return a URI from the given String. Log and return null if + * there was a problem. */ public static URI getURI(String spec) { if (spec == null) @@ -76,10 +76,11 @@ public class Activator implements BundleActivator { } /* - * Return the artifact repository manager. Throw an exception if it cannot be obtained. + * Return the artifact repository manager. Throw an exception if it cannot be + * obtained. */ public static IArtifactRepositoryManager getArtifactRepositoryManager() throws ProvisionException { - IArtifactRepositoryManager manager = (IArtifactRepositoryManager) getAgent().getService(IArtifactRepositoryManager.SERVICE_NAME); + IArtifactRepositoryManager manager = getAgent().getService(IArtifactRepositoryManager.class); if (manager == null) throw new ProvisionException(Messages.no_artifactRepo_manager); return manager; @@ -89,17 +90,18 @@ public class Activator implements BundleActivator { * Return the profile registry. Throw an exception if it cannot be found. */ static IProfileRegistry getProfileRegistry() throws ProvisionException { - IProfileRegistry registry = (IProfileRegistry) getAgent().getService(IProfileRegistry.SERVICE_NAME); + IProfileRegistry registry = getAgent().getService(IProfileRegistry.class); if (registry == null) throw new ProvisionException(Messages.no_profile_registry); return registry; } /* - * Return the metadata repository manager. Throw an exception if it cannot be obtained. + * Return the metadata repository manager. Throw an exception if it cannot be + * obtained. */ public static IMetadataRepositoryManager getMetadataRepositoryManager() throws ProvisionException { - IMetadataRepositoryManager manager = (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME); + IMetadataRepositoryManager manager = getAgent().getService(IMetadataRepositoryManager.class); if (manager == null) throw new ProvisionException(Messages.no_metadataRepo_manager); return manager; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java index ec704804d..21b99553d 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java @@ -353,7 +353,7 @@ public class MirrorApplication extends AbstractApplication implements IApplicati IProfileRegistry registry = Activator.getProfileRegistry(); String profileId = "MirrorApplication-" + System.currentTimeMillis(); //$NON-NLS-1$ IProfile profile = registry.addProfile(profileId, slicingOptions.getFilter()); - IPlanner planner = (IPlanner) Activator.getAgent().getService(IPlanner.SERVICE_NAME); + IPlanner planner = Activator.getAgent().getService(IPlanner.class); if (planner == null) throw new IllegalStateException(); IProfileChangeRequest pcr = planner.createChangeRequest(profile); |