You are viewing a plain text version of this content. The canonical link for it is here.
Posted to easyant-commits@incubator.apache.org by jl...@apache.org on 2012/08/13 18:50:55 UTC
svn commit: r1372548 - in
/incubator/easyant/core/trunk/src/main/java/org/apache/easyant:
core/ant/MetaBuildExecutor.java tasks/ConfigureBuildScopedRepository.java
Author: jlboudart
Date: Mon Aug 13 18:50:55 2012
New Revision: 1372548
URL: http://svn.apache.org/viewvc?rev=1372548&view=rev
Log:
Refactor ConfigureBuildScopedRepository to support multiple buildscoperepository
Modified:
incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/MetaBuildExecutor.java
incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ConfigureBuildScopedRepository.java
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/MetaBuildExecutor.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/MetaBuildExecutor.java?rev=1372548&r1=1372547&r2=1372548&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/MetaBuildExecutor.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/MetaBuildExecutor.java Mon Aug 13 18:50:55 2012
@@ -29,6 +29,7 @@ import org.apache.easyant.core.ant.liste
import org.apache.easyant.core.ant.listerners.BuildExecutionTimer.ExecutionResult;
import org.apache.easyant.core.ant.listerners.SubBuildExecutionTimer;
import org.apache.easyant.core.ivy.IvyInstanceHelper;
+import org.apache.easyant.tasks.ConfigureBuildScopedRepository;
import org.apache.easyant.tasks.SubModule;
import org.apache.easyant.tasks.SubModule.TargetList;
import org.apache.ivy.ant.IvyAntSettings;
@@ -63,8 +64,7 @@ public class MetaBuildExecutor extends D
// repository, so that it can
// be used by submodules if needed
File moduleFile = new File(project.getBaseDir(), "module.ivy");
- String buildRepo = project
- .getProperty(EasyAntMagicNames.EASYANT_BUILD_REPOSITORY);
+ String buildRepo = ConfigureBuildScopedRepository.getProjectBuildScopeRepositoryName(project);
if (moduleFile.isFile() && buildRepo != null) {
project.log("Publishing module descriptor " + moduleFile.getPath()
@@ -75,10 +75,10 @@ public class MetaBuildExecutor extends D
IvySettings ivy = projectSettings.getConfiguredIvyInstance(null).getSettings();
try {
- URL ivyUrl = moduleFile.toURL();
+ URL ivyUrl = moduleFile.toURI().toURL();
ModuleDescriptorParser mdp = ModuleDescriptorParserRegistry
.getInstance().getParser(
- new URLResource(moduleFile.toURL()));
+ new URLResource(moduleFile.toURI().toURL()));
ModuleDescriptor descriptor = mdp.parseDescriptor(ivy, ivyUrl,
true);
Artifact artifact = MDArtifact.newIvyArtifact(descriptor);
Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ConfigureBuildScopedRepository.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ConfigureBuildScopedRepository.java?rev=1372548&r1=1372547&r2=1372548&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ConfigureBuildScopedRepository.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ConfigureBuildScopedRepository.java Mon Aug 13 18:50:55 2012
@@ -20,7 +20,7 @@ package org.apache.easyant.tasks;
import java.io.File;
import org.apache.easyant.core.EasyAntMagicNames;
-import org.apache.ivy.Ivy;
+import org.apache.easyant.core.ivy.IvyInstanceHelper;
import org.apache.ivy.ant.IvyTask;
import org.apache.ivy.core.cache.DefaultRepositoryCacheManager;
import org.apache.ivy.core.settings.IvySettings;
@@ -37,27 +37,65 @@ import org.apache.tools.ant.Project;
*/
public class ConfigureBuildScopedRepository extends IvyTask {
- private String buildScopedRepositoryPrefix = "build";
+ private String name;
private String target;
+ private boolean dictator = false;
+ private String ivyPattern = "/[organisation]/[module]/[revision]/[module].ivy";
+ private String artifactPattern = "/[organisation]/[module]/[revision]/[artifact](-[classifier]).[ext]";
/**
- * Get the build scoped repository prefix
+ * Specify if this repository should be used in place of any specified resolver in {@link IvySettings}
*
- * @return a build scoped repository prefix
+ * @return true if acts as dictator resolver
*/
- public String getBuildScopedRepositoryPrefix() {
- return buildScopedRepositoryPrefix;
+ public boolean isDictator() {
+ return dictator;
}
/**
- * Set the build scoped repository prefix
+ * Specify if this repository should be used in place of any specified resolver in {@link IvySettings}
*
- * @param buildScopedRepositoryPrefix
- * a build scoped repository prefix
+ * @param dictator
+ * true if acts as dictator resolver
*/
- public void setBuildScopedRepositoryPrefix(String buildScopedRepositoryPrefix) {
- this.buildScopedRepositoryPrefix = buildScopedRepositoryPrefix;
+ public void setDictator(boolean dictator) {
+ this.dictator = dictator;
+ }
+
+ public String getIvyPattern() {
+ return ivyPattern;
+ }
+
+ public void setIvyPattern(String ivyPattern) {
+ this.ivyPattern = ivyPattern;
+ }
+
+ public String getArtifactPattern() {
+ return artifactPattern;
+ }
+
+ public void setArtifactPattern(String artifactPattern) {
+ this.artifactPattern = artifactPattern;
+ }
+
+ /**
+ * Get repository name. By default equals to "build." + ivyInstanceName
+ *
+ * @return repository name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Set repository name
+ *
+ * @param name
+ * repository name
+ */
+ public void setName(String name) {
+ this.name = name;
}
/**
@@ -92,24 +130,24 @@ public class ConfigureBuildScopedReposit
@Override
public void doExecute() throws BuildException {
String target = getTarget();
+ if (getName() == null) {
+ buildRepositoryName();
+ }
+
// be sure that we have an absolute path
File targetDir = new File(target);
target = targetDir.getAbsolutePath();
- final String DEFAULT_BUILD_SCOPED_REPOSITORY_DIR = target + "/repository";
- final String DEFAULT_CACHE_BUILD_SCOPED_REPO = target + "/cache";
+ String buildScopeRepositoryName = getName();
+
+ final String DEFAULT_BUILD_SCOPED_REPOSITORY_DIR = target + "/repository/" + buildScopeRepositoryName;
+ final String DEFAULT_CACHE_BUILD_SCOPED_REPO = target + "/cache/" + buildScopeRepositoryName;
getProject().log("Registering build scoped repository in " + DEFAULT_BUILD_SCOPED_REPOSITORY_DIR,
Project.MSG_DEBUG);
- final String CACHENAME = "build-scoped-cache";
+ final String CACHENAME = "build-scoped-cache-" + buildScopeRepositoryName;
// Get the project ivy instance
IvySettings settings = getSettings();
- // Search the default resolver after the build-scoped repo
- DependencyResolver dr = settings.getDefaultResolver();
- if (dr == null) {
- throw new BuildException("Unable to find a default resolver");
- }
-
// Create a cache for build scoped repository
File cacheDir = new File(DEFAULT_CACHE_BUILD_SCOPED_REPO);
DefaultRepositoryCacheManager rcm = new DefaultRepositoryCacheManager(CACHENAME, settings, cacheDir);
@@ -120,30 +158,60 @@ public class ConfigureBuildScopedReposit
// Create the build scoped repository
FileSystemResolver buildRepository = new FileSystemResolver();
- buildRepository.setName(buildScopedRepositoryPrefix + dr.getName());
- buildRepository.addArtifactPattern(DEFAULT_BUILD_SCOPED_REPOSITORY_DIR
- + "/[organisation]/[module]/[revision]/[artifact](-[classifier]).[ext]");
- buildRepository.addIvyPattern(DEFAULT_BUILD_SCOPED_REPOSITORY_DIR
- + "/[organisation]/[module]/[revision]/[module].ivy");
+ buildRepository.addArtifactPattern(DEFAULT_BUILD_SCOPED_REPOSITORY_DIR + getArtifactPattern());
+ buildRepository.addIvyPattern(DEFAULT_BUILD_SCOPED_REPOSITORY_DIR + getIvyPattern());
+
// bind to the repocache
buildRepository.setCache(CACHENAME);
+ buildRepository.setName(buildScopeRepositoryName);
+ if (isDictator()) {
+ settings.setDictatorResolver(buildRepository);
+ } else {
+
+ // Search the default resolver after the build-scoped repo
+ DependencyResolver dr = settings.getDefaultResolver();
+ if (dr == null) {
+ throw new BuildException("Unable to find a default resolver");
+ }
- getProject().setProperty(EasyAntMagicNames.EASYANT_BUILD_REPOSITORY, buildRepository.getName());
+ // replace the default resolver with a chain resolver, which first
+ // searches
+ // in the build repository, then in the old default.
+ ChainResolver resolver = new ChainResolver();
+ resolver.setName(dr.getName()); // same name as old default
+ resolver.setReturnFirst(true);
+ resolver.add(buildRepository);
+ resolver.add(dr);
+ dr.setName("delegate." + dr.getName()); // give old default a new name
+
+ settings.addResolver(buildRepository);
+ settings.addResolver(dr);
+ settings.addResolver(resolver);
+ }
+ getProject().setProperty(getProjectBuildScopeRepositoryName(getProject()), buildRepository.getName());
- // replace the default resolver with a chain resolver, which first
- // searches
- // in the build repository, then in the old default.
- ChainResolver resolver = new ChainResolver();
- resolver.setName(dr.getName()); // same name as old default
- resolver.setReturnFirst(true);
- resolver.add(buildRepository);
- resolver.add(dr);
- dr.setName("delegate." + dr.getName()); // give old default a new name
-
- settings.addResolver(buildRepository);
- settings.addResolver(dr);
- settings.addResolver(resolver);
+ }
+
+ /**
+ * Build default repository name
+ * @return repository name
+ */
+ private String buildRepositoryName() {
+ return "build." + IvyInstanceHelper.getProjectIvyInstanceName(getProject());
+ }
+ /**
+ * Get project build scope repository name
+ * @param project {@link Project} where build scope is registered
+ * @return repository name
+ */
+ public static String getProjectBuildScopeRepositoryName(Project project) {
+ String repoName = project.getProperty(EasyAntMagicNames.EASYANT_BUILD_REPOSITORY);
+ if (repoName == null) {
+ repoName = EasyAntMagicNames.EASYANT_BUILD_REPOSITORY + "."
+ + IvyInstanceHelper.getProjectIvyInstanceName(project);
+ }
+ return repoName;
}
}