Java Code Examples for org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor#newDefaultInstance()

The following examples show how to use org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor#newDefaultInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IvyConfigurationProvider.java    From walkmod-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void addArtifact(String groupId, String artifactId, String version) throws Exception {

		artifacts.add(groupId+":"+artifactId+":"+version);

		String[] dep = null;
		dep = new String[] { groupId, artifactId, version };
		if (md == null) {
			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);
		md.addDependency(dd);
		ExcludeRule er = new DefaultExcludeRule(new ArtifactId(new ModuleId("org.walkmod", "walkmod-core"),
				PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION),
				ExactPatternMatcher.INSTANCE, null);
		dd.addExcludeRule(null, er);
	}
 
Example 2
Source File: IvyConfigurationProvider.java    From walkmod-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void addArtifact(String groupId, String artifactId, String version) throws Exception {

		artifacts.add(groupId+":"+artifactId+":"+version);

		String[] dep = null;
		dep = new String[] { groupId, artifactId, version };
		if (md == null) {
			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);
		md.addDependency(dd);
		ExcludeRule er = new DefaultExcludeRule(new ArtifactId(new ModuleId("org.walkmod", "walkmod-core"),
				PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION),
				ExactPatternMatcher.INSTANCE, null);
		dd.addExcludeRule(null, er);
	}
 
Example 3
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
protected ResourceMDParser getDefaultRMDParser(final ModuleId mid) {
    return new ResourceMDParser() {
        public MDResolvedResource parse(Resource resource, String rev) {
            DefaultModuleDescriptor md = DefaultModuleDescriptor
                    .newDefaultInstance(new ModuleRevisionId(mid, rev));
            MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(
                    md.getMetadataArtifact());
            madr.setDownloadStatus(DownloadStatus.NO);
            madr.setSearched(true);
            return new MDResolvedResource(resource, rev, new ResolvedModuleRevision(
                    BasicResolver.this, BasicResolver.this, md, madr, isForce()));
        }
    };
}
 
Example 4
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private IvySettings createIvySettingsForParentLicenseTesting(final String parentPomFileName, final String parentOrgName,
                                                             final String parentModuleName) throws Exception {
    final URL parentPomURL = this.getClass().getResource(parentPomFileName);
    assertNotNull("Could not find " + parentPomFileName, parentPomURL);
    final PomReader parentPomReader = new PomReader(parentPomURL, new URLResource(parentPomURL));
    final License[] parentLicenses = parentPomReader.getLicenses();
    assertNotNull("Missing licenses in parent pom " + parentPomFileName, parentLicenses);
    assertEquals("Unexpected number of licenses in parent pom " + parentPomFileName, 1, parentLicenses.length);
    final DependencyResolver dependencyResolver = new MockedDependencyResolver() {
        @Override
        protected ModuleDescriptor getModuleDescriptor(DependencyDescriptor dependencyDescriptor) {
            final String depOrg = dependencyDescriptor.getDependencyId().getOrganisation();
            final String depModuleName = dependencyDescriptor.getDependencyId().getName();
            if (depOrg.equals(parentOrgName) && depModuleName.equals(parentModuleName)) {
                final DefaultModuleDescriptor moduleDescriptor = DefaultModuleDescriptor.newDefaultInstance(dependencyDescriptor.getDependencyRevisionId());
                for (final License license : parentLicenses) {
                    moduleDescriptor.addLicense(license);
                }
                return moduleDescriptor;
            } else {
                return super.getModuleDescriptor(dependencyDescriptor);
            }
        }
    };
    final IvySettings ivySettings = new IvySettings();
    ivySettings.setDictatorResolver(dependencyResolver);

    return ivySettings;
}
 
Example 5
Source File: LatestVersionMatcherTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void assertAccept(String askedVersion, String foundStatus, boolean b) {
    ModuleRevisionId askedMrid = ModuleRevisionId.newInstance("org", "name", askedVersion);
    DefaultModuleDescriptor foundMD = DefaultModuleDescriptor
            .newDefaultInstance(ModuleRevisionId.newInstance("org", "name", null));
    foundMD.setStatus(foundStatus);
    assertEquals(b, vm.accept(askedMrid, foundMD));
}
 
Example 6
Source File: LatestVersionMatcherTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void assertAccept(String askedVersion, String askedBranch, String foundStatus,
        String foundBranch, boolean b) {
    ModuleRevisionId askedMrid = ModuleRevisionId.newInstance("org", "name", askedBranch,
        askedVersion);
    DefaultModuleDescriptor foundMD = DefaultModuleDescriptor.newDefaultInstance(
        ModuleRevisionId.newInstance("org", "name", foundBranch, (String) null));
    foundMD.setStatus(foundStatus);
    assertEquals(b, vm.accept(askedMrid, foundMD));
}
 
Example 7
Source File: TestClassWithDependencyRunner.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
private static List<URL> resolveArtifacts(List<String> dependencies) throws Exception {
    //creates clear ivy settings
    IvySettings ivySettings = new IvySettings();
    //url resolver for configuration of maven repo
    URLResolver resolver = new URLResolver();
    resolver.setM2compatible(true);
    resolver.setName("central");
    //you can specify the url resolution pattern strategy
    resolver.addArtifactPattern(
        "https://repo1.maven.org/maven2/"
            + "[organisation]/[module]/[revision]/[artifact](-[revision]).[ext]");
    //adding maven repo resolver
    ivySettings.addResolver(resolver);
    //set to the default resolver
    ivySettings.setDefaultResolver(resolver.getName());
    //creates an Ivy instance with settings
    Ivy ivy = Ivy.newInstance(ivySettings);

    File ivyfile = File.createTempFile("ivy", ".xml");
    ivyfile.deleteOnExit();

    DefaultModuleDescriptor md =
        DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance("foo", "foo" + "-caller", "working"));
    for (String dependency : dependencies) {
        String[] split = dependency.split(":");

        DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md,
            ModuleRevisionId.newInstance(split[0], split[1], split[2]), false, false, true);
        md.addDependency(dd);
    }

    //creates an ivy configuration file
    XmlModuleDescriptorWriter.write(md, ivyfile);

    String[] confs = new String[]{"default"};
    ResolveOptions resolveOptions = new ResolveOptions().setConfs(confs);

    //init resolve report
    ResolveReport report = ivy.resolve(ivyfile.toURL(), resolveOptions);

    List<URL> resolvedDependencies = new ArrayList<>();
    ArtifactDownloadReport[] allArtifactsReports = report.getAllArtifactsReports();
    for (ArtifactDownloadReport allArtifactsReport : allArtifactsReports) {
        resolvedDependencies.add(allArtifactsReport.getLocalFile().toURI().toURL());
    }
    assertThat(resolvedDependencies).hasSizeGreaterThanOrEqualTo(dependencies.size());
    return resolvedDependencies;
}
 
Example 8
Source File: IvyUtil.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static DefaultModuleDescriptor createModuleDescriptor(DependencyDescriptor dependencyDescriptor) {
    DefaultModuleDescriptor moduleDescriptor = DefaultModuleDescriptor.newDefaultInstance(dependencyDescriptor.getDependencyRevisionId(), dependencyDescriptor.getAllDependencyArtifacts());
    moduleDescriptor.setStatus("integration");
    return moduleDescriptor;
}
 
Example 9
Source File: IvyUtil.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static DefaultModuleDescriptor createModuleDescriptor(DependencyDescriptor dependencyDescriptor) {
    DefaultModuleDescriptor moduleDescriptor = DefaultModuleDescriptor.newDefaultInstance(dependencyDescriptor.getDependencyRevisionId(), dependencyDescriptor.getAllDependencyArtifacts());
    moduleDescriptor.setStatus("integration");
    return moduleDescriptor;
}
 
Example 10
Source File: SampleIvyRunner.java    From jeka with Apache License 2.0 4 votes vote down vote up
public void retrieve() {
    final IBiblioResolver dependencyResolver = new IBiblioResolver();
    dependencyResolver
    .setRoot("http://i-net1102e-prod:8081/nexus/content/groups/bnppf-secured");
    dependencyResolver.setM2compatible(true);
    dependencyResolver.setUseMavenMetadata(true);
    dependencyResolver.setName("nexus"); // Name is necessary to avoid NPE

    final IvySettings ivySettings = new IvySettings();
    ivySettings.addResolver(dependencyResolver);
    ivySettings.setDefaultResolver("nexus"); // Setting a default resolver
    // is necessary

    final Ivy ivy = Ivy.newInstance(ivySettings);
    ivy.getLoggerEngine().setDefaultLogger(new DefaultMessageLogger(Message.MSG_DEBUG));

    final ModuleRevisionId thisModuleRevisionId = ModuleRevisionId.newInstance("mygroupId",
            "myartifactId-envelope", "myversion");

    final ModuleRevisionId dependee = ModuleRevisionId.newInstance("org.springframework",
            "spring-jdbc", "3.0.0.RELEASE");
    // final ModuleRevisionId dependee =
    // ModuleRevisionId.newInstance("org.hibernate",
    // "hibernate-core", "3.6.10.Final");

    // 1st create an ivy module (this always(!) has a "default"
    // configuration already)
    final DefaultModuleDescriptor moduleDescriptor = DefaultModuleDescriptor
            .newDefaultInstance(thisModuleRevisionId);

    // don't go transitive here, if you want the single artifact
    final boolean transitive = true;
    final DefaultDependencyDescriptor dependencyDescriptor = new DefaultDependencyDescriptor(
            moduleDescriptor, dependee, false, false, transitive);

    // map to master to just get the code jar. See generated ivy module xmls
    // from maven repo
    // on how configurations are mapped into ivy. Or check
    // e.g.
    // http://lightguard-jp.blogspot.de/2009/04/ivy-configurations-when-pulling-from.html
    // dependencyDescriptor.addDependencyConfiguration("default", "master");

    // To get more than 1 artifact i need to declare "compile" and not
    // "master"
    dependencyDescriptor.addDependencyConfiguration("default", "compile");

    moduleDescriptor.addDependency(dependencyDescriptor);

    // now resolve
    final ResolveOptions resolveOptions = new ResolveOptions()
    .setConfs(new String[] { "default" });
    resolveOptions.setTransitive(transitive);
    ResolveReport reportResolver;
    try {
        reportResolver = ivy.resolve(moduleDescriptor, resolveOptions);
    } catch (final Exception e1) {
        throw new RuntimeException(e1);
    }
    if (reportResolver.hasError()) {
        System.out
        .println("*************************************************************************");
        System.out.println(reportResolver);

        throw new RuntimeException(reportResolver.getAllProblemMessages().toString());
    }
    for (final ArtifactDownloadReport artifactDownloadReport : reportResolver
            .getAllArtifactsReports()) {
        System.out.println("*********************************"
                + artifactDownloadReport.getLocalFile());

    }

    final String filePattern = new File("jeka/output/downloaded-libs").getAbsolutePath()
            + "/[artifact](-[classifier]).[ext]";
    final RetrieveOptions retrieveOptions = new RetrieveOptions()
    .setConfs(new String[] { "default" });
    try {
        ivy.retrieve(moduleDescriptor.getModuleRevisionId(), filePattern, retrieveOptions);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }

}
 
Example 11
Source File: PublishEngineTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Test
public void testAtomicity() throws Exception {
    IvySettings settings = new IvySettings();
    final PublishEngine engine = new PublishEngine(settings, new EventManager());
    final int[] counter = new int[] {0};

    final DefaultModuleDescriptor md = DefaultModuleDescriptor
            .newDefaultInstance(ModuleRevisionId.parse("#A;1.0"));
    final FileSystemResolver resolver = new FileSystemResolver() {
        public void publish(Artifact artifact, File src, boolean overwrite) throws IOException {
            super.publish(artifact, src, overwrite);
            synchronized (PublishEngineTest.this) {
                counter[0]++;
            }
            sleepSilently(50);
            synchronized (PublishEngineTest.this) {
                counter[0]++;
            }
        }
    };
    resolver.setName("test");
    resolver.setSettings(settings);
    String publishRepoDir = new File("build/test/publish/repo").getAbsolutePath();
    resolver.addIvyPattern(publishRepoDir + "/[module]/[revision]/[artifact].[ext]");
    resolver.addArtifactPattern(publishRepoDir + "/[module]/[revision]/[artifact].[ext]");

    FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), new File(
            "build/test/publish/module/A.jar"), null);
    XmlModuleDescriptorWriter.write(md, new File("build/test/publish/module/ivy.xml"));

    resolveAndAssertNotFound(settings, resolver, "#A;latest.integration", "before publishing");

    // run publish asynchronously
    new Thread() {
        public void run() {
            try {
                engine.publish(md, Collections.singletonList("build/test/publish/module/[artifact].[ext]"),
                    resolver, new PublishOptions().setSrcIvyPattern("build/test/publish/module/[artifact].[ext]"));
                synchronized (PublishEngineTest.this) {
                    counter[0]++;
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }.start();

    while (true) {
        sleepSilently(5);
        synchronized (this) {
            if (counter[0] == 5) {
                break;
            } else if (counter[0] < 4) {
                resolveAndAssertNotFound(settings, resolver, "#A;latest.integration", "after "
                        + (counter[0] / 2) + " artifacts published");
            }
        }
    }
    resolveAndAssertFound(settings, resolver, "#A;1.0");
}
 
Example 12
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
protected ModuleDescriptor getModuleDescriptor(final DependencyDescriptor dependencyDescriptor) {
    return DefaultModuleDescriptor.newDefaultInstance(dependencyDescriptor.getDependencyRevisionId());
}
 
Example 13
Source File: ModuleDescriptorParserRegistryTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public ModuleDescriptor parseDescriptor(ParserSettings ivy, URL descriptorURL,
        Resource res, boolean validate) throws ParseException, IOException {
    return DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance("test",
        "parser", "1.0"));
}