Search in sources :

Example 26 with ModuleDescriptor

use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.

the class IvyDeliverTest method testWithResolveIdInAnotherBuild.

@Test
public void testWithResolveIdInAnotherBuild() throws Exception {
    // create a new build
    Project other = TestHelper.newProject();
    other.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml");
    other.setProperty("build", "build/test/deliver");
    // do a resolve in the new build
    IvyResolve resolve = new IvyResolve();
    resolve.setProject(other);
    resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml"));
    resolve.setResolveId("withResolveId");
    resolve.execute();
    // resolve another ivy file
    resolve = new IvyResolve();
    resolve.setProject(project);
    resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml"));
    resolve.execute();
    deliver.setResolveId("withResolveId");
    deliver.setPubrevision("1.2");
    deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml");
    deliver.execute();
    // should have done the ivy delivering
    File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml");
    assertTrue(deliveredIvyFile.exists());
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), deliveredIvyFile.toURI().toURL(), true);
    assertEquals(ModuleRevisionId.newInstance("apache", "resolve-simple", "1.2"), md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), dds[0].getDependencyRevisionId());
}
Also used : Project(org.apache.tools.ant.Project) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) IvySettings(org.apache.ivy.core.settings.IvySettings) File(java.io.File) Test(org.junit.Test)

Example 27 with ModuleDescriptor

use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.

the class IvyDeliverTest method testWithExtraAttributes.

/**
 * Test case for IVY-415.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-415">IVY-415</a>
 */
@Test
public void testWithExtraAttributes() throws Exception {
    project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest-extra.xml");
    IvyResolve res = new IvyResolve();
    res.setValidate(false);
    res.setProject(project);
    res.execute();
    deliver.setPubrevision("1.2");
    deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml");
    deliver.setValidate(false);
    deliver.execute();
    // should have done the ivy delivering
    File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml");
    assertTrue(deliveredIvyFile.exists());
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), deliveredIvyFile.toURI().toURL(), false);
    assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"), md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertEquals(1, dds.length);
    Map<String, String> extraAtt = new HashMap<>();
    extraAtt.put("myExtraAtt", "myValue");
    assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.2", extraAtt), dds[0].getDependencyRevisionId());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) HashMap(java.util.HashMap) IvySettings(org.apache.ivy.core.settings.IvySettings) File(java.io.File) Test(org.junit.Test)

Example 28 with ModuleDescriptor

use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.

the class TestHelper method fillRepository.

/**
 * Fills a repository with a set of module, using empty files for published artifacts.
 *
 * @param resolver
 *            the resolver to use to publish the modules
 * @param mds
 *            the descriptors of the modules to put in the repository
 * @throws IOException
 *             if an IO problem occurs while filling the repository
 */
public static void fillRepository(DependencyResolver resolver, Collection<ModuleDescriptor> mds) throws IOException {
    File tmp = File.createTempFile("ivy", "tmp");
    try {
        for (ModuleDescriptor md : mds) {
            boolean overwrite = false;
            resolver.beginPublishTransaction(md.getModuleRevisionId(), overwrite);
            boolean published = false;
            try {
                XmlModuleDescriptorWriter.write(md, tmp);
                resolver.publish(md.getMetadataArtifact(), tmp, overwrite);
                tmp.delete();
                tmp.createNewFile();
                for (Artifact artifact : md.getAllArtifacts()) {
                    resolver.publish(artifact, tmp, overwrite);
                }
                resolver.commitPublishTransaction();
                published = true;
            } finally {
                if (!published) {
                    resolver.abortPublishTransaction();
                }
            }
        }
    } finally {
        tmp.delete();
    }
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact)

Example 29 with ModuleDescriptor

use of org.apache.ivy.core.module.descriptor.ModuleDescriptor 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;
}
Also used : IvySettings(org.apache.ivy.core.settings.IvySettings) RetrieveOptions(org.apache.ivy.core.retrieve.RetrieveOptions) PublishOptions(org.apache.ivy.core.publish.PublishOptions) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolveReport(org.apache.ivy.core.report.ResolveReport) ResolveProcessException(org.apache.ivy.core.resolve.ResolveProcessException) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) PropertiesFile(org.apache.ivy.util.PropertiesFile) File(java.io.File) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) PomWriterOptions(org.apache.ivy.plugins.parser.m2.PomWriterOptions)

Example 30 with ModuleDescriptor

use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.

the class FixDepsTask method doExecute.

@Override
public void doExecute() throws BuildException {
    prepareAndCheck();
    if (dest == null) {
        throw new BuildException("Missing required parameter 'tofile'");
    }
    if (dest.exists() && dest.isDirectory()) {
        throw new BuildException("The destination file '" + dest.getAbsolutePath() + "' already exist and is a folder");
    }
    ResolveReport report = getResolvedReport();
    List<ModuleId> midToKeep = new ArrayList<>();
    for (Keep keep : keeps) {
        midToKeep.add(ModuleId.newInstance(keep.org, keep.module));
    }
    ModuleDescriptor md = report.toFixedModuleDescriptor(getSettings(), midToKeep);
    try {
        XmlModuleDescriptorWriter.write(md, dest);
    } catch (IOException e) {
        throw new BuildException("Failed to write into the file " + dest.getAbsolutePath() + " (" + e.getMessage() + ")", e);
    }
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolveReport(org.apache.ivy.core.report.ResolveReport) ArrayList(java.util.ArrayList) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException)

Aggregations

ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)284 Test (org.junit.Test)233 File (java.io.File)143 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)114 ResolveReport (org.apache.ivy.core.report.ResolveReport)94 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)80 JarFile (java.util.jar.JarFile)76 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)76 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)69 IvySettings (org.apache.ivy.core.settings.IvySettings)60 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)44 Configuration (org.apache.ivy.core.module.descriptor.Configuration)30 Artifact (org.apache.ivy.core.module.descriptor.Artifact)28 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)27 IOException (java.io.IOException)24 ParseException (java.text.ParseException)23 Ivy (org.apache.ivy.Ivy)23 BufferedReader (java.io.BufferedReader)19 FileReader (java.io.FileReader)19 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)17