Skip to content

Commit

Permalink
ROO-2644: Operations that manage the POM are slow under windows, sinc…
Browse files Browse the repository at this point in the history
…e flushin UAA preferences takes long
  • Loading branch information
Alan Stewart committed Aug 15, 2011
1 parent 7989e6e commit 8083852
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class DefaultMetadataService extends AbstractMetadataCache implements Met
private Map<String, MetadataProvider> providerMap = new HashMap<String, MetadataProvider>();

// Mutex
private Boolean lock = new Boolean(true);
private Object lock = new Object();

// Request control
private List<String> activeRequests = new ArrayList<String>(); // List to assist output "stacks" which show the order of requests
Expand Down Expand Up @@ -172,6 +172,7 @@ public MetadataItem getInternal(String metadataIdentificationString, boolean evi
if (metadataLogger.getTraceLevel() > 0) {
metadataLogger.log("Returning " + metadataIdentificationString);
}

return result;
} catch (Exception e) {
activeRequests.remove(metadataIdentificationString);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.springframework.roo.metadata;


/**
* Indicates a service which is aware of all {@link MetadataProvider}s in the system and
* can provide access to their respective capabilities.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public MetadataItem get(String metadataIdentificationString) {
}
Dependency dependency = new Dependency(productInfo.getGroupId(), productInfo.getArtifactId(), "version_is_ignored_for_searching");
Set<Dependency> dependenciesExcludingVersion = result.getDependenciesExcludingVersion(dependency);
if (dependenciesExcludingVersion.size() > 0) {
if (!dependenciesExcludingVersion.isEmpty()) {
// This dependency was detected
Dependency first = dependenciesExcludingVersion.iterator().next();
// Convert the detected dependency into a Product as best we can
Expand All @@ -162,7 +162,7 @@ public MetadataItem get(String metadataIdentificationString) {
// Strip the ${ } from the version sequence
String propertyName = versionSequence.replace("${", "").replace("}", "");
Set<Property> prop = result.getPropertiesExcludingValue(new Property(propertyName));
if (prop.size() > 0) {
if (!prop.isEmpty()) {
// Take the first one's value and treat that as the version sequence
versionSequence = prop.iterator().next().getValue();
}
Expand All @@ -176,7 +176,7 @@ public MetadataItem get(String metadataIdentificationString) {
uaaRegistrationService.registerProject(product, topLevelPackage.getFullyQualifiedPackageName());
}
}

return result;
}

Expand Down Expand Up @@ -206,7 +206,7 @@ public void addDependencies(List<Dependency> dependencies) {
if (dependencies.isEmpty()) {
return;
}
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so dependency addition is unavailable");
if (projectMetadata.isAllDependenciesRegistered(dependencies)) {
return;
Expand Down Expand Up @@ -237,7 +237,7 @@ public void addDependencies(List<Dependency> dependencies) {

public void addDependency(Dependency dependency) {
Assert.notNull(dependency, "Dependency to add required");
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so dependency addition is unavailable");
if (projectMetadata.isDependencyRegistered(dependency)) {
return;
Expand All @@ -259,7 +259,7 @@ public void removeDependencies(List<Dependency> dependencies) {
if (dependencies.isEmpty()) {
return;
}
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so dependency removal is unavailable");
if (!projectMetadata.isAnyDependenciesRegistered(dependencies)) {
return;
Expand Down Expand Up @@ -303,7 +303,7 @@ public void addBuildPlugins(List<Plugin> plugins) {
if (plugins.isEmpty()) {
return;
}
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so plugin addition is unavailable");
if (projectMetadata.isAllPluginsRegistered(plugins)) {
return;
Expand Down Expand Up @@ -334,7 +334,7 @@ public void addBuildPlugins(List<Plugin> plugins) {

public void addBuildPlugin(Plugin plugin) {
Assert.notNull(plugin, "Plugin to add required");
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so build plugin addition is unavailable");
if (projectMetadata.isBuildPluginRegistered(plugin)) {
return;
Expand All @@ -356,7 +356,7 @@ public void removeBuildPlugins(List<Plugin> plugins) {
if (plugins.isEmpty()) {
return;
}
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so plugin removal is unavailable");
if (!projectMetadata.isAnyPluginsRegistered(plugins)) {
return;
Expand Down Expand Up @@ -421,7 +421,7 @@ public void removePluginRepository(Repository repository) {

public void updateProjectType(ProjectType projectType) {
Assert.notNull(projectType, "Project type required");
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so dependency addition is unavailable");

Document document = XmlUtils.readXml(fileManager.getInputStream(pom));
Expand All @@ -446,7 +446,7 @@ private void addRepositories(List<Repository> repositories, String containingPat
if (repositories.isEmpty()) {
return;
}
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so repository addition is unavailable");
if (path.equals("pluginRepository")) {
if (projectMetadata.isAllPluginRepositoriesRegistered(repositories)) {
Expand Down Expand Up @@ -566,7 +566,7 @@ private Element createRepositoryElement(Document document, Repository repository

private void addRepository(Repository repository, String containingPath, String path) {
Assert.notNull(repository, "Repository required");
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so repository addition is unavailable");
if (path.equals("pluginRepository")) {
if (projectMetadata.isPluginRepositoryRegistered(repository)) {
Expand All @@ -593,7 +593,7 @@ private void addRepository(Repository repository, String containingPath, String

private void removeRepository(Repository repository, String path) {
Assert.notNull(repository, "Repository required");
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so plugin repository removal is unavailable");
if (path.equals("pluginRepository")) {
if (!projectMetadata.isPluginRepositoryRegistered(repository)) {
Expand Down Expand Up @@ -688,7 +688,7 @@ private Element getPluginElement(Plugin plugin, Document document) {

public void addProperty(Property property) {
Assert.notNull(property, "Property to add required");
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so property addition is unavailable");
if (projectMetadata.isPropertyRegistered(property)) {
return;
Expand Down Expand Up @@ -716,7 +716,7 @@ public void addProperty(Property property) {

public void removeProperty(Property property) {
Assert.notNull(property, "Property to remove required");
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so property removal is unavailable");
if (!projectMetadata.isPropertyRegistered(property)) {
return;
Expand All @@ -742,7 +742,7 @@ public void removeProperty(Property property) {

public void addFilter(Filter filter) {
Assert.notNull(filter, "Filter to add required");
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so filter addition is unavailable");
if (projectMetadata.isFilterRegistered(filter)) {
return;
Expand Down Expand Up @@ -775,7 +775,7 @@ public void addFilter(Filter filter) {

public void removeFilter(Filter filter) {
Assert.notNull(filter, "Filter required");
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so filter removal is unavailable");
if (!projectMetadata.isFilterRegistered(filter)) {
return;
Expand Down Expand Up @@ -810,7 +810,7 @@ public void removeFilter(Filter filter) {

public void addResource(Resource resource) {
Assert.notNull(resource, "Resource to add required");
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so resource addition is unavailable");
if (projectMetadata.isResourceRegistered(resource)) {
return;
Expand Down Expand Up @@ -857,7 +857,7 @@ public void addResource(Resource resource) {

public void removeResource(Resource resource) {
Assert.notNull(resource, "Resource required");
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so resource removal is unavailable");
if (!projectMetadata.isResourceRegistered(resource)) {
return;
Expand Down Expand Up @@ -892,7 +892,7 @@ public void removeResource(Resource resource) {
// Remove an element identified by dependency, whenever it occurs at path
private void removeDependency(Dependency dependency, String containingPath, String path) {
Assert.notNull(dependency, "Dependency to remove required");
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so dependency removal is unavailable");
if (!projectMetadata.isDependencyRegistered(dependency)) {
return;
Expand All @@ -919,7 +919,7 @@ private void removeDependency(Dependency dependency, String containingPath, Stri
// Remove an element identified by plugin, whenever it occurs at path
private void removeBuildPlugin(Plugin plugin, String containingPath, String path) {
Assert.notNull(plugin, "Plugin to remove required");
ProjectMetadata projectMetadata = (ProjectMetadata) get(ProjectMetadata.getProjectIdentifier());
ProjectMetadata projectMetadata = (ProjectMetadata) metadataService.get(ProjectMetadata.getProjectIdentifier());
Assert.notNull(projectMetadata, "Project metadata is not yet available, so dependency addition is unavailable");
if (!projectMetadata.isBuildPluginRegistered(plugin)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,18 @@
import org.springframework.uaa.client.TransmissionEventListener;
import org.springframework.uaa.client.UaaService;
import org.springframework.uaa.client.protobuf.UaaClient.FeatureUse;
import org.springframework.uaa.client.protobuf.UaaClient.Product;
import org.springframework.uaa.client.protobuf.UaaClient.FeatureUse.Builder;
import org.springframework.uaa.client.protobuf.UaaClient.Product;

/**
* Default implementation of {@link UaaRegistrationService}.
*
* @author Ben Alex
* @since 1.1.1
*
*/
@Service
@Component
public class UaaRegistrationServiceImpl implements UaaRegistrationService, TransmissionEventListener {

@Reference private UaaService uaaService;
@Reference private PublicFeatureResolver publicFeatureResolver;
/** key: bundleSymbolicName, value: customJson */
Expand All @@ -50,15 +48,15 @@ protected void activate(ComponentContext context) {
String bundleSymbolicName = BundleFindingUtils.findFirstBundleForTypeName(context.getBundleContext(), UaaRegistrationServiceImpl.class.getName());
registerBundleSymbolicNameUse(bundleSymbolicName, null);
if (uaaService instanceof TransmissionAwareUaaService) {
((TransmissionAwareUaaService)uaaService).addTransmissionEventListener(this);
((TransmissionAwareUaaService) uaaService).addTransmissionEventListener(this);
}
}

protected void deactivate(ComponentContext context) {
// Last effort to store the data given we're shutting down
flushIfPossible();
if (uaaService instanceof TransmissionAwareUaaService) {
((TransmissionAwareUaaService)uaaService).removeTransmissionEventListener(this);
((TransmissionAwareUaaService) uaaService).removeTransmissionEventListener(this);
}
}

Expand Down Expand Up @@ -240,5 +238,4 @@ private void populateVersionInfoIfPossible(Builder featureUseBuilder, String bun
featureUseBuilder.setSourceControlIdentifier(commitHash);
}
}

}

0 comments on commit 8083852

Please sign in to comment.