use of org.apache.ivy.core.publish.PublishOptions in project ant-ivy by apache.
the class Main method run.
@SuppressWarnings("deprecation")
private static ResolveReport run(CommandLine line, boolean isCli) throws Exception {
if (line.hasOption("version")) {
System.out.println("Apache Ivy " + Ivy.getIvyVersion() + " - " + Ivy.getIvyDate() + " :: " + Ivy.getIvyHomeURL());
return null;
}
boolean validate = !line.hasOption("novalidate");
Ivy ivy = Ivy.newInstance();
initMessage(line, ivy);
IvySettings settings = initSettings(line, ivy);
ivy.pushContext();
File cache = new File(settings.substitute(line.getOptionValue("cache", settings.getDefaultCache().getAbsolutePath())));
if (line.hasOption("cache")) {
// override default cache path with user supplied cache path
settings.setDefaultCache(cache);
}
if (!cache.exists()) {
cache.mkdirs();
} else if (!cache.isDirectory()) {
error(cache + " is not a directory");
}
String[] confs;
if (line.hasOption("confs")) {
confs = line.getOptionValues("confs");
} else {
confs = new String[] { "*" };
}
File ivyfile;
if (line.hasOption("dependency")) {
String[] dep = line.getOptionValues("dependency");
ivyfile = File.createTempFile("ivy", ".xml");
ivyfile.deleteOnExit();
DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance(dep[0], dep[1] + "-caller", "working"));
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(dep[0], dep[1], dep[2]), false, false, true);
for (String conf : confs) {
dd.addDependencyConfiguration("default", conf);
}
md.addDependency(dd);
XmlModuleDescriptorWriter.write(md, ivyfile);
confs = new String[] { "default" };
} else {
ivyfile = new File(settings.substitute(line.getOptionValue("ivy", "ivy.xml")));
if (!ivyfile.exists()) {
error("ivy file not found: " + ivyfile);
} else if (ivyfile.isDirectory()) {
error("ivy file is not a file: " + ivyfile);
}
}
if (line.hasOption("useOrigin")) {
ivy.getSettings().useDeprecatedUseOrigin();
}
ResolveOptions resolveOptions = new ResolveOptions().setConfs(confs).setValidate(validate).setResolveMode(line.getOptionValue("mode")).setArtifactFilter(FilterHelper.getArtifactTypeFilter(line.getOptionValues("types")));
if (line.hasOption("notransitive")) {
resolveOptions.setTransitive(false);
}
if (line.hasOption("refresh")) {
resolveOptions.setRefresh(true);
}
ResolveReport report = ivy.resolve(ivyfile.toURI().toURL(), resolveOptions);
if (report.hasError()) {
if (isCli) {
System.exit(1);
}
StringBuilder sb = new StringBuilder();
for (String problem : report.getAllProblemMessages()) {
if (sb.length() > 0) {
sb.append("\n");
}
sb.append(problem);
}
throw new ResolveProcessException(sb.toString());
}
ModuleDescriptor md = report.getModuleDescriptor();
if (confs.length == 1 && "*".equals(confs[0])) {
confs = md.getConfigurationsNames();
}
if (line.hasOption("retrieve")) {
String retrievePattern = settings.substitute(line.getOptionValue("retrieve"));
if (!retrievePattern.contains("[")) {
retrievePattern += "/lib/[conf]/[artifact].[ext]";
}
String ivyPattern = settings.substitute(line.getOptionValue("ivypattern"));
ivy.retrieve(md.getModuleRevisionId(), new RetrieveOptions().setConfs(confs).setSync(line.hasOption("sync")).setUseOrigin(line.hasOption("useOrigin")).setDestArtifactPattern(retrievePattern).setDestIvyPattern(ivyPattern).setOverwriteMode(line.getOptionValue("overwriteMode")).setArtifactFilter(FilterHelper.getArtifactTypeFilter(line.getOptionValues("types"))).setMakeSymlinks(line.hasOption("symlink")).setMakeSymlinksInMass(line.hasOption("symlinkmass")));
}
if (line.hasOption("cachepath")) {
outputCachePath(ivy, cache, md, confs, line.getOptionValue("cachepath", "ivycachepath.txt"));
}
if (line.hasOption("revision")) {
ivy.deliver(md.getResolvedModuleRevisionId(), settings.substitute(line.getOptionValue("revision")), settings.substitute(line.getOptionValue("deliverto", "ivy-[revision].xml")), DeliverOptions.newInstance(settings).setStatus(settings.substitute(line.getOptionValue("status", "release"))).setValidate(validate));
if (line.hasOption("publish")) {
ivy.publish(md.getResolvedModuleRevisionId(), Collections.singleton(settings.substitute(line.getOptionValue("publishpattern", "distrib/[type]s/[artifact]-[revision].[ext]"))), line.getOptionValue("publish"), new PublishOptions().setPubrevision(settings.substitute(line.getOptionValue("revision"))).setValidate(validate).setSrcIvyPattern(settings.substitute(line.getOptionValue("deliverto", "ivy-[revision].xml"))).setOverwrite(line.hasOption("overwrite")));
}
}
if (line.hasOption("makepom")) {
final String pomFilePath = line.getOptionValue("makepom", "pom.xml");
final File pomFile = new File(pomFilePath);
PomModuleDescriptorWriter.write(md, pomFile, new PomWriterOptions());
Message.debug("Generated a pom file for module at " + pomFile);
}
if (line.hasOption("main")) {
// check if the option cp has been set
List<File> fileList = getExtraClasspathFileList(line);
// merge -args and left over args
String[] fargs = line.getOptionValues("args");
if (fargs == null) {
fargs = new String[0];
}
String[] extra = line.getLeftOverArgs();
if (extra == null) {
extra = new String[0];
}
String[] params = new String[fargs.length + extra.length];
System.arraycopy(fargs, 0, params, 0, fargs.length);
System.arraycopy(extra, 0, params, fargs.length, extra.length);
// invoke with given main class and merged params
invoke(ivy, cache, md, confs, fileList, line.getOptionValue("main"), params);
}
ivy.getLoggerEngine().popLogger();
ivy.popContext();
return report;
}
use of org.apache.ivy.core.publish.PublishOptions in project ant-ivy by apache.
the class IvyPublish method doExecute.
@Override
public void doExecute() throws BuildException {
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
organisation = getProperty(organisation, settings, "ivy.organisation");
module = getProperty(module, settings, "ivy.module");
revision = getProperty(revision, settings, "ivy.revision");
pubBranch = getProperty(pubBranch, settings, "ivy.deliver.branch");
pubRevision = getProperty(pubRevision, settings, "ivy.deliver.revision");
if (artifactspattern.isEmpty()) {
String p = getProperty(null, settings, "ivy.publish.src.artifacts.pattern");
if (p != null) {
artifactspattern.add(p);
}
}
if (srcivypattern == null) {
srcivypattern = getArtifactspattern();
}
status = getProperty(status, settings, "ivy.status");
if (organisation == null) {
throw new BuildException("no organisation provided for ivy publish task: " + "It can either be set explicitly via the attribute 'organisation' " + "or via 'ivy.organisation' property or a prior call to <resolve/>");
}
if (module == null) {
throw new BuildException("no module name provided for ivy publish task: " + "It can either be set explicitly via the attribute 'module' " + "or via 'ivy.module' property or a prior call to <resolve/>");
}
if (revision == null) {
throw new BuildException("no module revision provided for ivy publish task: " + "It can either be set explicitly via the attribute 'revision' " + "or via 'ivy.revision' property or a prior call to <resolve/>");
}
if (artifactspattern.isEmpty()) {
throw new BuildException("no artifacts pattern: either provide it through parameter or " + "through ivy.publish.src.artifacts.pattern property");
}
if (publishResolverName == null) {
throw new BuildException("no publish deliver name: please provide it through parameter 'resolver'");
}
if ("working".equals(revision)) {
revision = Ivy.getWorkingRevision();
}
Date pubdate = getPubDate(this.pubdate, new Date());
if (pubRevision == null) {
if (revision.startsWith("working@")) {
pubRevision = DateUtil.format(pubdate);
} else {
pubRevision = revision;
}
}
if (status == null) {
throw new BuildException("no status provided: either provide it as parameter " + "or through the ivy.status.default property");
}
ModuleRevisionId mrid = ModuleRevisionId.newInstance(organisation, module, revision);
try {
File ivyFile = getProject().resolveFile(IvyPatternHelper.substitute(srcivypattern, organisation, module, pubRevision, "ivy", "ivy", "xml"));
if (publishivy && (!ivyFile.exists() || forcedeliver)) {
IvyDeliver deliver = new IvyDeliver();
deliver.setSettingsRef(getSettingsRef());
deliver.setTaskName(getTaskName());
deliver.setProject(getProject());
deliver.setDeliverpattern(getSrcivypattern());
deliver.setDelivertarget(deliverTarget);
deliver.setDeliveryList(deliveryList);
deliver.setModule(getModule());
deliver.setOrganisation(getOrganisation());
deliver.setPubdate(DateUtil.format(pubdate));
deliver.setPubrevision(getPubrevision());
deliver.setPubbranch(getPubbranch());
deliver.setRevision(getRevision());
deliver.setStatus(getStatus());
deliver.setValidate(doValidate(settings));
deliver.setReplacedynamicrev(isReplacedynamicrev());
deliver.setMerge(merge);
deliver.setConf(conf);
deliver.execute();
}
ivy.publish(mrid, artifactspattern, publishResolverName, new PublishOptions().setPubrevision(getPubrevision()).setPubbranch(getPubbranch()).setSrcIvyPattern(publishivy ? srcivypattern : null).setStatus(getStatus()).setPubdate(pubdate).setExtraArtifacts(artifacts.toArray(new Artifact[artifacts.size()])).setValidate(doValidate(settings)).setOverwrite(overwrite).setUpdate(update).setMerge(merge).setWarnOnMissing(warnonmissing).setHaltOnMissing(haltonmissing).setConfs(splitToArray(conf)));
} catch (Exception e) {
if (e instanceof BuildException) {
throw (BuildException) e;
}
throw new BuildException("impossible to publish artifacts for " + mrid + ": " + e, e);
}
}
Aggregations