Skip to content

Commit

Permalink
Moved IvyBackedArtifactPublisher into a separate package
Browse files Browse the repository at this point in the history
- Moved associated types
- Extracted separate wrapper type for Ivy context setting
  • Loading branch information
bigdaz committed May 17, 2016
1 parent bbc7990 commit 108f54b
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 66 deletions.
Expand Up @@ -17,22 +17,39 @@

import org.gradle.StartParameter;
import org.gradle.api.artifacts.PublishArtifact;
import org.gradle.api.artifacts.dsl.*;
import org.gradle.api.artifacts.dsl.ArtifactHandler;
import org.gradle.api.artifacts.dsl.ComponentMetadataHandler;
import org.gradle.api.artifacts.dsl.ComponentModuleMetadataHandler;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.artifacts.dsl.RepositoryHandler;
import org.gradle.api.internal.DomainObjectContext;
import org.gradle.api.internal.artifacts.component.ComponentIdentifierFactory;
import org.gradle.api.internal.artifacts.configurations.ConfigurationContainerInternal;
import org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer;
import org.gradle.api.internal.artifacts.configurations.DependencyMetaDataProvider;
import org.gradle.api.internal.artifacts.dsl.*;
import org.gradle.api.internal.artifacts.dsl.DefaultArtifactHandler;
import org.gradle.api.internal.artifacts.dsl.DefaultComponentMetadataHandler;
import org.gradle.api.internal.artifacts.dsl.DefaultComponentModuleMetadataHandler;
import org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler;
import org.gradle.api.internal.artifacts.dsl.PublishArtifactNotationParserFactory;
import org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler;
import org.gradle.api.internal.artifacts.dsl.dependencies.DependencyFactory;
import org.gradle.api.internal.artifacts.dsl.dependencies.ProjectFinder;
import org.gradle.api.internal.artifacts.ivyservice.*;
import org.gradle.api.internal.artifacts.ivyservice.CacheLockingManager;
import org.gradle.api.internal.artifacts.ivyservice.DefaultConfigurationResolver;
import org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingConfigurationResolver;
import org.gradle.api.internal.artifacts.ivyservice.IvyContextManager;
import org.gradle.api.internal.artifacts.ivyservice.IvyContextualArtifactPublisher;
import org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyConfigurationResolver;
import org.gradle.api.internal.artifacts.ivyservice.ShortCircuitEmptyConfigurationResolver;
import org.gradle.api.internal.artifacts.ivyservice.dependencysubstitution.DependencySubstitutionRuleProvider;
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ResolveIvyFactory;
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.GradlePomModuleDescriptorParser;
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelectorScheme;
import org.gradle.api.internal.artifacts.ivyservice.moduleconverter.ConfigurationComponentMetaDataBuilder;
import org.gradle.api.internal.artifacts.ivyservice.publisher.DefaultIvyDependencyPublisher;
import org.gradle.api.internal.artifacts.ivyservice.publisher.IvyBackedArtifactPublisher;
import org.gradle.api.internal.artifacts.ivyservice.publisher.IvyXmlModuleDescriptorWriter;
import org.gradle.api.internal.artifacts.ivyservice.resolveengine.store.ResolutionResultsStoreFactory;
import org.gradle.api.internal.artifacts.mvnsettings.LocalMavenRepositoryLocator;
import org.gradle.api.internal.artifacts.query.ArtifactResolutionQueryFactory;
Expand Down Expand Up @@ -212,12 +229,12 @@ public RepositoryHandler createRepositoryHandler() {
}

public ArtifactPublisher createArtifactPublisher() {
return new IvyBackedArtifactPublisher(
services.get(ConfigurationComponentMetaDataBuilder.class),
services.get(IvyContextManager.class),
new DefaultIvyDependencyPublisher(),
new IvyXmlModuleDescriptorWriter()
IvyBackedArtifactPublisher publisher = new IvyBackedArtifactPublisher(
services.get(ConfigurationComponentMetaDataBuilder.class),
new DefaultIvyDependencyPublisher(),
new IvyXmlModuleDescriptorWriter()
);
return new IvyContextualArtifactPublisher(services.get(IvyContextManager.class), publisher);
}
}
}
Expand Up @@ -25,6 +25,7 @@
import org.gradle.api.internal.artifacts.ivyservice.CacheLockingManager;
import org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager;
import org.gradle.api.internal.artifacts.ivyservice.IvyContextManager;
import org.gradle.api.internal.artifacts.ivyservice.IvyContextualArtifactDependencyResolver;
import org.gradle.api.internal.artifacts.ivyservice.dynamicversions.ModuleVersionsCache;
import org.gradle.api.internal.artifacts.ivyservice.dynamicversions.SingleFileBackedModuleVersionsCache;
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ComponentResolvers;
Expand Down Expand Up @@ -237,14 +238,15 @@ ArtifactDependencyResolver createArtifactDependencyResolver(ResolveIvyFactory re
IvyContextManager ivyContextManager,
VersionComparator versionComparator,
ServiceRegistry serviceRegistry) {
DefaultArtifactDependencyResolver resolver = new DefaultArtifactDependencyResolver(
ArtifactDependencyResolver resolver = new DefaultArtifactDependencyResolver(
serviceRegistry,
resolveIvyFactory,
dependencyDescriptorFactory,
cacheLockingManager,
ivyContextManager,
versionComparator
);
resolver = new IvyContextualArtifactDependencyResolver(ivyContextManager, resolver);
return new CacheLockingArtifactDependencyResolver(cacheLockingManager, resolver);
}

Expand Down
Expand Up @@ -28,7 +28,7 @@ public class CacheLockingArtifactResolver implements ArtifactResolver {
private final CacheLockingManager lockingManager;
private final ArtifactResolver delegate;

public CacheLockingArtifactResolver(CacheLockingManager lockingManager, IvyContextManager ivyContextManager, ArtifactResolver delegate) {
public CacheLockingArtifactResolver(CacheLockingManager lockingManager, ArtifactResolver delegate) {
this.lockingManager = lockingManager;
this.delegate = delegate;
}
Expand Down
@@ -0,0 +1,49 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.api.internal.artifacts.ivyservice;

import org.apache.ivy.Ivy;
import org.gradle.api.Action;
import org.gradle.api.internal.artifacts.ArtifactDependencyResolver;
import org.gradle.api.internal.artifacts.GlobalDependencyResolutionRules;
import org.gradle.api.internal.artifacts.ResolveContext;
import org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.DependencyArtifactsVisitor;
import org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphVisitor;
import org.gradle.api.internal.artifacts.repositories.ResolutionAwareRepository;

import java.util.List;

public class IvyContextualArtifactDependencyResolver implements ArtifactDependencyResolver {
private final ArtifactDependencyResolver delegate;
private final IvyContextManager ivyContextManager;

public IvyContextualArtifactDependencyResolver(IvyContextManager ivyContextManager, ArtifactDependencyResolver delegate) {
this.delegate = delegate;
this.ivyContextManager = ivyContextManager;
}

@Override
public void resolve(final ResolveContext resolveContext, final List<? extends ResolutionAwareRepository> repositories, final GlobalDependencyResolutionRules metadataHandler,
final DependencyGraphVisitor graphVisitor, final DependencyArtifactsVisitor artifactsVisitor) {
ivyContextManager.withIvy(new Action<Ivy>() {
@Override
public void execute(Ivy ivy) {
delegate.resolve(resolveContext, repositories, metadataHandler, graphVisitor, artifactsVisitor);
}
});
}
}
@@ -0,0 +1,47 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.api.internal.artifacts.ivyservice;

import org.apache.ivy.Ivy;
import org.gradle.api.Action;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.PublishException;
import org.gradle.api.internal.artifacts.ArtifactPublisher;
import org.gradle.api.internal.artifacts.ModuleInternal;
import org.gradle.api.internal.artifacts.repositories.PublicationAwareRepository;

import java.io.File;

public class IvyContextualArtifactPublisher implements ArtifactPublisher {
private final ArtifactPublisher delegate;
private final IvyContextManager ivyContextManager;

public IvyContextualArtifactPublisher(IvyContextManager ivyContextManager, ArtifactPublisher delegate) {
this.delegate = delegate;
this.ivyContextManager = ivyContextManager;
}

@Override
public void publish(final Iterable<? extends PublicationAwareRepository> repositories, final ModuleInternal module, final Configuration configuration, final File descriptor) throws PublishException {
ivyContextManager.withIvy(new Action<Ivy>() {
@Override
public void execute(Ivy ivy) {
delegate.publish(repositories, module, configuration, descriptor);
}
});
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2009 the original author or authors.
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.internal.artifacts.ivyservice;
package org.gradle.api.internal.artifacts.ivyservice.publisher;

import org.gradle.api.UncheckedIOException;
import org.gradle.api.artifacts.PublishException;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2007-2008 the original author or authors.
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,10 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.internal.artifacts.ivyservice;
package org.gradle.api.internal.artifacts.ivyservice.publisher;

import org.apache.ivy.Ivy;
import org.gradle.api.Action;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.PublishException;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
Expand All @@ -39,47 +37,41 @@

public class IvyBackedArtifactPublisher implements ArtifactPublisher {
private final ConfigurationComponentMetaDataBuilder configurationComponentMetaDataBuilder;
private final IvyContextManager ivyContextManager;
private final IvyDependencyPublisher dependencyPublisher;
private final IvyModuleDescriptorWriter ivyModuleDescriptorWriter;

public IvyBackedArtifactPublisher(ConfigurationComponentMetaDataBuilder configurationComponentMetaDataBuilder, IvyContextManager ivyContextManager,
public IvyBackedArtifactPublisher(ConfigurationComponentMetaDataBuilder configurationComponentMetaDataBuilder,
IvyDependencyPublisher dependencyPublisher,
IvyModuleDescriptorWriter ivyModuleDescriptorWriter) {
this.configurationComponentMetaDataBuilder = configurationComponentMetaDataBuilder;
this.ivyContextManager = ivyContextManager;
this.dependencyPublisher = dependencyPublisher;
this.ivyModuleDescriptorWriter = ivyModuleDescriptorWriter;
}

public void publish(final Iterable<? extends PublicationAwareRepository> repositories, final ModuleInternal module, final Configuration configuration, final File descriptor) throws PublishException {
ivyContextManager.withIvy(new Action<Ivy>() {
public void execute(Ivy ivy) {
Set<Configuration> allConfigurations = configuration.getAll();
Set<Configuration> configurationsToPublish = configuration.getHierarchy();
Set<Configuration> allConfigurations = configuration.getAll();
Set<Configuration> configurationsToPublish = configuration.getHierarchy();

if (descriptor != null) {
// Convert once, in order to write the Ivy descriptor with _all_ configurations
IvyModulePublishMetaData publishMetaData = toPublishMetaData(module, allConfigurations);
ivyModuleDescriptorWriter.write(publishMetaData.getModuleDescriptor(), publishMetaData.getArtifacts(), descriptor);
}
if (descriptor != null) {
// Convert once, in order to write the Ivy descriptor with _all_ configurations
IvyModulePublishMetaData publishMetaData = toPublishMetaData(module, allConfigurations);
ivyModuleDescriptorWriter.write(publishMetaData.getModuleDescriptor(), publishMetaData.getArtifacts(), descriptor);
}

// Convert a second time with only the published configurations: this ensures that the correct artifacts are included
BuildableIvyModulePublishMetaData publishMetaData = toPublishMetaData(module, configurationsToPublish);
if (descriptor != null) {
IvyArtifactName artifact = new DefaultIvyArtifactName("ivy", "ivy", "xml");
publishMetaData.addArtifact(artifact, descriptor);
}
// Convert a second time with only the published configurations: this ensures that the correct artifacts are included
BuildableIvyModulePublishMetaData publishMetaData = toPublishMetaData(module, configurationsToPublish);
if (descriptor != null) {
IvyArtifactName artifact = new DefaultIvyArtifactName("ivy", "ivy", "xml");
publishMetaData.addArtifact(artifact, descriptor);
}

List<ModuleVersionPublisher> publishResolvers = new ArrayList<ModuleVersionPublisher>();
for (PublicationAwareRepository repository : repositories) {
ModuleVersionPublisher publisher = repository.createPublisher();
publishResolvers.add(publisher);
}
List<ModuleVersionPublisher> publishResolvers = new ArrayList<ModuleVersionPublisher>();
for (PublicationAwareRepository repository : repositories) {
ModuleVersionPublisher publisher = repository.createPublisher();
publishResolvers.add(publisher);
}

dependencyPublisher.publish(publishResolvers, publishMetaData);
}
});
dependencyPublisher.publish(publishResolvers, publishMetaData);
}

private BuildableIvyModulePublishMetaData toPublishMetaData(ModuleInternal module, Set<? extends Configuration> configurations) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2007-2008 the original author or authors.
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.internal.artifacts.ivyservice;
package org.gradle.api.internal.artifacts.ivyservice.publisher;

import org.gradle.internal.component.external.model.IvyModulePublishMetaData;
import org.gradle.api.internal.artifacts.ModuleVersionPublisher;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.gradle.api.internal.artifacts.ivyservice;
package org.gradle.api.internal.artifacts.ivyservice.publisher;

import org.gradle.internal.component.external.model.IvyModuleArtifactPublishMetaData;
import org.gradle.internal.component.external.descriptor.ModuleDescriptorState;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,14 +14,15 @@
* limitations under the License.
*/

package org.gradle.api.internal.artifacts.ivyservice;
package org.gradle.api.internal.artifacts.ivyservice.publisher;

import com.google.common.base.Joiner;
import com.google.common.collect.Sets;
import org.gradle.api.Transformer;
import org.gradle.api.UncheckedIOException;
import org.gradle.api.artifacts.ModuleVersionSelector;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.api.internal.artifacts.ivyservice.NamespaceId;
import org.gradle.internal.component.external.descriptor.Artifact;
import org.gradle.internal.component.external.descriptor.Configuration;
import org.gradle.internal.component.external.descriptor.Dependency;
Expand Down

0 comments on commit 108f54b

Please sign in to comment.