Author: xavier
Date: Sun Mar 2 09:35:32 2008
New Revision: 632798
URL: http://svn.apache.org/viewvc?rev=632798&view=rev
Log:
fix style: refactor: introduce InstallOptions to reduce the number of
parameters for install methods
Added:
ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallOptions.java
(with props)
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java
ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyInstall.java
ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java
ant/ivy/core/trunk/test/java/org/apache/ivy/core/install/InstallTest.java
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java?rev=632798&r1=632797&r2=632798&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java Sun Mar 2 09:35:32 2008
@@ -37,6 +37,7 @@
import org.apache.ivy.core.deliver.DeliverOptions;
import org.apache.ivy.core.event.EventManager;
import org.apache.ivy.core.install.InstallEngine;
+import org.apache.ivy.core.install.InstallOptions;
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
import org.apache.ivy.core.module.id.ModuleId;
import org.apache.ivy.core.module.id.ModuleRevisionId;
@@ -66,7 +67,6 @@
import org.apache.ivy.util.HostUtil;
import org.apache.ivy.util.Message;
import org.apache.ivy.util.MessageLoggerEngine;
-import org.apache.ivy.util.filter.Filter;
/**
* <a href="http://incubator.apache.org/ivy/">Ivy</a> is a free java based
dependency manager.
@@ -521,13 +521,11 @@
// INSTALL
// ///////////////////////////////////////////////////////////////////////
- public ResolveReport install(ModuleRevisionId mrid, String from, String
to, boolean transitive,
- boolean validate, boolean overwrite, Filter artifactFilter, String
matcherName)
- throws IOException {
+ public ResolveReport install(ModuleRevisionId mrid, String from, String
to,
+ InstallOptions options) throws IOException {
pushContext();
try {
- return installEngine.install(mrid, from, to, transitive, validate,
overwrite,
- artifactFilter, matcherName);
+ return installEngine.install(mrid, from, to, options);
} finally {
popContext();
}
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java?rev=632798&r1=632797&r2=632798&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java Sun Mar 2 09:35:32
2008
@@ -29,6 +29,7 @@
import org.apache.ivy.core.deliver.DeliverOptions;
import org.apache.ivy.core.deliver.PublishingDependencyRevisionResolver;
+import org.apache.ivy.core.install.InstallOptions;
import org.apache.ivy.core.module.descriptor.Artifact;
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
import org.apache.ivy.core.module.id.ModuleId;
@@ -180,8 +181,13 @@
public ResolveReport install(ModuleRevisionId mrid, String from, String
to, boolean transitive,
boolean validate, boolean overwrite, Filter artifactFilter, File
cache,
String matcherName) throws IOException {
- return ivy.install(mrid, from, to, transitive, validate, overwrite,
artifactFilter,
- matcherName);
+ return ivy.install(mrid, from, to,
+ new InstallOptions()
+ .setTransitive(transitive)
+ .setValidate(validate)
+ .setOverwrite(overwrite)
+ .setArtifactFilter(artifactFilter)
+ .setMatcherName(matcherName));
}
public void interrupt() {
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyInstall.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyInstall.java?rev=632798&r1=632797&r2=632798&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyInstall.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyInstall.java Sun Mar 2
09:35:32 2008
@@ -20,6 +20,7 @@
import java.io.File;
import org.apache.ivy.Ivy;
+import org.apache.ivy.core.install.InstallOptions;
import org.apache.ivy.core.module.id.ModuleId;
import org.apache.ivy.core.module.id.ModuleRevisionId;
import org.apache.ivy.core.report.ResolveReport;
@@ -97,8 +98,13 @@
ResolveReport report;
try {
- report = ivy.install(mrid, from, to, transitive,
doValidate(settings), overwrite,
- FilterHelper.getArtifactTypeFilter(type), matcher);
+ report = ivy.install(mrid, from, to,
+ new InstallOptions()
+ .setTransitive(transitive)
+ .setValidate(doValidate(settings))
+ .setOverwrite(overwrite)
+
.setArtifactFilter(FilterHelper.getArtifactTypeFilter(type))
+ .setMatcherName(matcher));
} catch (Exception e) {
throw new BuildException("impossible to install " + mrid + ": " +
e, e);
}
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java?rev=632798&r1=632797&r2=632798&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java
Sun Mar 2 09:35:32 2008
@@ -44,8 +44,6 @@
import org.apache.ivy.plugins.matcher.PatternMatcher;
import org.apache.ivy.plugins.resolver.DependencyResolver;
import org.apache.ivy.util.Message;
-import org.apache.ivy.util.filter.Filter;
-import org.apache.ivy.util.filter.FilterHelper;
public class InstallEngine {
private InstallEngineSettings settings;
@@ -64,12 +62,8 @@
this.publishEngine = publishEngine;
}
- public ResolveReport install(ModuleRevisionId mrid, String from, String
to, boolean transitive,
- boolean validate, boolean overwrite, Filter artifactFilter,
- String matcherName) throws IOException {
- if (artifactFilter == null) {
- artifactFilter = FilterHelper.NO_FILTER;
- }
+ public ResolveReport install(ModuleRevisionId mrid, String from, String
to,
+ InstallOptions options) throws IOException {
DependencyResolver fromResolver = settings.getResolver(from);
DependencyResolver toResolver = settings.getResolver(to);
if (fromResolver == null) {
@@ -80,9 +74,9 @@
throw new IllegalArgumentException("unknown resolver " + to
+ ". Available resolvers are: " +
settings.getResolverNames());
}
- PatternMatcher matcher = settings.getMatcher(matcherName);
+ PatternMatcher matcher = settings.getMatcher(options.getMatcherName());
if (matcher == null) {
- throw new IllegalArgumentException("unknown matcher " + matcherName
+ throw new IllegalArgumentException("unknown matcher " +
options.getMatcherName()
+ ". Available matchers are: " +
settings.getMatcherNames());
}
@@ -105,7 +99,7 @@
if (MatcherHelper.isExact(matcher, mrid)) {
DefaultDependencyDescriptor dd = new
DefaultDependencyDescriptor(md, mrid, false,
- false, transitive);
+ false, options.isTransitive());
dd.addDependencyConfiguration("default", "*");
md.addDependency(dd);
} else {
@@ -115,7 +109,7 @@
ModuleRevisionId foundMrid = (ModuleRevisionId)
iter.next();
Message.info("\tfound " + foundMrid + " to install: adding
to the list");
DefaultDependencyDescriptor dd = new
DefaultDependencyDescriptor(md, foundMrid,
- false, false, transitive);
+ false, false, options.isTransitive());
dd.addDependencyConfiguration("default", "*");
md.addDependency(dd);
}
@@ -125,15 +119,16 @@
ResolveReport report = new ResolveReport(md, resolveId);
Message.info(":: resolving dependencies ::");
- ResolveOptions options = new ResolveOptions()
+ ResolveOptions resolveOptions = new ResolveOptions()
.setResolveId(resolveId)
.setConfs(new String[] {"default"})
- .setValidate(validate);
- IvyNode[] dependencies = resolveEngine.getDependencies(md,
options, report);
- report.setDependencies(Arrays.asList(dependencies),
artifactFilter);
+ .setValidate(options.isValidate());
+ IvyNode[] dependencies = resolveEngine.getDependencies(md,
resolveOptions, report);
+ report.setDependencies(Arrays.asList(dependencies),
options.getArtifactFilter());
Message.info(":: downloading artifacts to cache ::");
- resolveEngine.downloadArtifacts(report, artifactFilter, new
DownloadOptions());
+ resolveEngine.downloadArtifacts(
+ report, options.getArtifactFilter(), new DownloadOptions());
// now that everything is in cache, we can publish all these
modules
Message.info(":: installing in " + to + " ::");
@@ -144,7 +139,7 @@
Message.verbose("installing " + depMrid);
boolean successfullyPublished = false;
try {
- toResolver.beginPublishTransaction(depMrid, overwrite);
+ toResolver.beginPublishTransaction(depMrid,
options.isOverwrite());
// publish artifacts
ArtifactDownloadReport[] artifacts =
@@ -152,14 +147,15 @@
for (int j = 0; j < artifacts.length; j++) {
if (artifacts[j].getLocalFile() != null) {
toResolver.publish(artifacts[j].getArtifact(),
- artifacts[j].getLocalFile(), overwrite);
+ artifacts[j].getLocalFile(),
options.isOverwrite());
}
}
// publish metadata
File localIvyFile = dependencies[i]
.getModuleRevision().getReport().getLocalFile();
- toResolver.publish(depmd.getMetadataArtifact(),
localIvyFile, overwrite);
+ toResolver.publish(
+ depmd.getMetadataArtifact(), localIvyFile,
options.isOverwrite());
// end module publish
toResolver.commitPublishTransaction();
@@ -175,7 +171,8 @@
Message.info(":: install resolution report ::");
// output report
- resolveEngine.outputReport(report,
settings.getResolutionCacheManager(), options);
+ resolveEngine.outputReport(
+ report, settings.getResolutionCacheManager(), resolveOptions);
return report;
} finally {
Added:
ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallOptions.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallOptions.java?rev=632798&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallOptions.java
(added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallOptions.java
Sun Mar 2 09:35:32 2008
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.ivy.core.install;
+
+import org.apache.ivy.plugins.matcher.PatternMatcher;
+import org.apache.ivy.util.filter.Filter;
+import org.apache.ivy.util.filter.FilterHelper;
+
+public class InstallOptions {
+ private boolean transitive = true;
+ private boolean validate = true;
+ private boolean overwrite = false;
+ private Filter artifactFilter = FilterHelper.NO_FILTER;
+ private String matcherName = PatternMatcher.EXACT;
+
+ public boolean isTransitive() {
+ return transitive;
+ }
+ public InstallOptions setTransitive(boolean transitive) {
+ this.transitive = transitive;
+ return this;
+ }
+ public boolean isValidate() {
+ return validate;
+ }
+ public InstallOptions setValidate(boolean validate) {
+ this.validate = validate;
+ return this;
+ }
+ public boolean isOverwrite() {
+ return overwrite;
+ }
+ public InstallOptions setOverwrite(boolean overwrite) {
+ this.overwrite = overwrite;
+ return this;
+ }
+ public Filter getArtifactFilter() {
+ return artifactFilter;
+ }
+ public InstallOptions setArtifactFilter(Filter artifactFilter) {
+ this.artifactFilter = artifactFilter == null ? FilterHelper.NO_FILTER
: artifactFilter;
+ return this;
+ }
+ public String getMatcherName() {
+ return matcherName;
+ }
+ public InstallOptions setMatcherName(String matcherName) {
+ this.matcherName = matcherName;
+ return this;
+ }
+}
Propchange:
ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallOptions.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ant/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallOptions.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
ant/ivy/core/trunk/test/java/org/apache/ivy/core/install/InstallTest.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/install/InstallTest.java?rev=632798&r1=632797&r2=632798&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/install/InstallTest.java
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/install/InstallTest.java
Sun Mar 2 09:35:32 2008
@@ -34,20 +34,19 @@
ivy.configure(new File("test/repositories/ivysettings.xml"));
ivy.install(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"),
ivy.getSettings()
- .getDefaultResolver().getName(), "install", true, true, true,
null,
- PatternMatcher.EXACT);
+ .getDefaultResolver().getName(), "install",
+ new InstallOptions());
assertTrue(new
File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
assertTrue(new
File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists());
}
-
+
public void testValidate() throws Exception {
Ivy ivy = Ivy.newInstance();
ivy.configure(new File("test/repositories/ivysettings.xml"));
ivy.install(ModuleRevisionId.newInstance("orgfailure", "modfailure",
"1.0"), ivy.getSettings()
- .getDefaultResolver().getName(), "install", true, true, true,
null,
- PatternMatcher.EXACT);
+ .getDefaultResolver().getName(), "install", new
InstallOptions());
assertFalse(new
File("build/test/install/orgfailure/modfailure/ivy-1.0.xml").exists());
assertFalse(new
File("build/test/install/orgfailure/modfailure/modfailure-1.0.jar").exists());
@@ -58,8 +57,7 @@
ivy.configure(new File("test/repositories/ivysettings.xml"));
ivy.install(ModuleRevisionId.newInstance("orgfailure", "modfailure",
"1.0"), ivy.getSettings()
- .getDefaultResolver().getName(), "install", true, false, true,
null,
- PatternMatcher.EXACT);
+ .getDefaultResolver().getName(), "install", new
InstallOptions().setValidate(false));
assertTrue(new
File("build/test/install/orgfailure/modfailure/ivy-1.0.xml").exists());
assertTrue(new
File("build/test/install/orgfailure/modfailure/modfailure-1.0.jar").exists());
@@ -69,8 +67,8 @@
Ivy ivy = Ivy.newInstance();
ivy.configure(new
File("test/repositories/ivysettings-nodefaultresolver.xml"));
- ivy.install(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"),
"test", "install", true,
- true, true, null, PatternMatcher.EXACT);
+ ivy.install(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"),
"test", "install",
+ new InstallOptions());
assertTrue(new
File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
assertTrue(new
File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists());
@@ -81,8 +79,7 @@
ivy.configure(new File("test/repositories/ivysettings.xml"));
ivy.install(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),
ivy.getSettings()
- .getDefaultResolver().getName(), "install", true, true, true,
null,
- PatternMatcher.EXACT);
+ .getDefaultResolver().getName(), "install", new
InstallOptions());
assertTrue(new
File("build/test/install/org1/mod1.1/ivy-1.0.xml").exists());
assertTrue(new
File("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists());
@@ -96,8 +93,8 @@
ivy.configure(new File("test/repositories/ivysettings.xml"));
ivy.install(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),
ivy.getSettings()
- .getDefaultResolver().getName(), "install", false, true, true,
null,
- PatternMatcher.EXACT);
+ .getDefaultResolver().getName(), "install",
+ new InstallOptions().setTransitive(false));
assertTrue(new
File("build/test/install/org1/mod1.1/ivy-1.0.xml").exists());
assertTrue(new
File("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists());
@@ -110,8 +107,8 @@
Ivy ivy = Ivy.newInstance();
ivy.configure(new File("test/repositories/ivysettings.xml"));
- ivy.install(ModuleRevisionId.newInstance("org1", ".*", ".*"), "1",
"install", false, true,
- true, null, PatternMatcher.REGEXP);
+ ivy.install(ModuleRevisionId.newInstance("org1", ".*", ".*"), "1",
"install",
+ new
InstallOptions().setMatcherName(PatternMatcher.REGEXP).setOverwrite(true));
assertTrue(new
File("build/test/install/org1/mod1.1/ivy-1.0.xml").exists());
assertTrue(new
File("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists());