org.apache.ivy.Ivy Java Examples

The following examples show how to use org.apache.ivy.Ivy. 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: InstallTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testLatestDependenciesDummyDefaultResolver() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings-dummydefaultresolver.xml"));

    ivy.install(ModuleRevisionId.newInstance("org1", "mod1.4", "1.0.1"), "test", "install",
        new InstallOptions());

    assertTrue(new File("build/test/install/org1/mod1.4/ivy-1.0.1.xml").exists());

    assertTrue(new File("build/test/install/org1/mod1.1/ivy-2.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-2.0.jar").exists());

    assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.2.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.2.jar").exists());
}
 
Example #2
Source File: IvyConfigureTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testOverrideTrue() {
    configure.setFile(new File("test/repositories/ivysettings.xml"));
    configure.execute();

    Ivy ivy = getIvyInstance();
    assertNotNull(ivy);

    configure = new IvyConfigure();
    configure.setProject(project);
    configure.setOverride("true");
    configure.setFile(new File("test/repositories/ivysettings.xml"));
    configure.execute();
    assertNotNull(getIvyInstance());

    assertNotSame(ivy, getIvyInstance());
}
 
Example #3
Source File: ModuleRevisionId.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private ModuleRevisionId(ModuleId moduleId, String branch, String revision,
        Map<String, String> extraAttributes, boolean replaceNullBranchWithDefault) {
    super(null, extraAttributes);
    this.moduleId = moduleId;
    IvyContext context = IvyContext.getContext();
    this.branch = (replaceNullBranchWithDefault && branch == null)
    // we test if there's already an Ivy instance loaded, to avoid loading a default one
    // just to get the default branch
    ? (context.peekIvy() == null ? null : context.getSettings().getDefaultBranch(moduleId))
            : branch;
    this.revision = revision == null ? Ivy.getWorkingRevision() : normalizeRevision(revision);
    setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY, this.moduleId.getOrganisation());
    setStandardAttribute(IvyPatternHelper.MODULE_KEY, this.moduleId.getName());
    setStandardAttribute(IvyPatternHelper.BRANCH_KEY, this.branch);
    setStandardAttribute(IvyPatternHelper.REVISION_KEY, this.revision);
}
 
Example #4
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimple() throws Exception {
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-simple.xml"), true);
    assertNotNull(md);
    assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
    assertEquals("mymodule", md.getModuleRevisionId().getName());
    assertEquals(Ivy.getWorkingRevision(), md.getModuleRevisionId().getRevision());
    assertEquals("integration", md.getStatus());

    assertNotNull(md.getConfigurations());
    assertEquals(Collections.singletonList(new Configuration("default")),
        Arrays.asList(md.getConfigurations()));

    assertNotNull(md.getArtifacts("default"));
    assertEquals(1, md.getArtifacts("default").length);
    assertEquals("mymodule", md.getArtifacts("default")[0].getName());
    assertEquals("jar", md.getArtifacts("default")[0].getType());

    assertNotNull(md.getDependencies());
    assertEquals(0, md.getDependencies().length);
}
 
Example #5
Source File: IvySettingsTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testChangeDefaultResolver() throws ParseException, IOException {
    Ivy ivy = new Ivy();
    ivy.configureDefault();

    IvySettings settings = ivy.getSettings();
    DependencyResolver defaultResolver = settings.getDefaultResolver();

    assertNotNull(defaultResolver);
    assertEquals("default", defaultResolver.getName());
    assertSame("default resolver cached", defaultResolver, settings.getDefaultResolver());

    settings.setDefaultResolver("public");
    DependencyResolver newDefault = settings.getDefaultResolver();
    assertNotNull(newDefault);
    assertNotSame("default resolver has changed", defaultResolver, newDefault);
    assertEquals("resolver changed successfully", "public", newDefault.getName());
}
 
Example #6
Source File: GradleVersion.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public String prettyPrint() {
    final StringBuilder sb = new StringBuilder();
    sb.append("\n------------------------------------------------------------\nGradle ");
    sb.append(getVersion());
    sb.append("\n------------------------------------------------------------\n\nBuild time:   ");
    sb.append(getBuildTime());
    sb.append("\nBuild number: ");
    sb.append(buildNumber);
    sb.append("\nRevision:     ");
    sb.append(commitId);
    sb.append("\n\nGroovy:       ");
    sb.append(GroovySystem.getVersion());
    sb.append("\nAnt:          ");
    sb.append(Main.getAntVersion());
    sb.append("\nIvy:          ");
    sb.append(Ivy.getIvyVersion());
    sb.append("\nJVM:          ");
    sb.append(Jvm.current());
    sb.append("\nOS:           ");
    sb.append(OperatingSystem.current());
    sb.append("\n");
    return sb.toString();
}
 
Example #7
Source File: LibVersionsCheckTask.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void setupIvy() {
  IvySettings ivySettings = new IvySettings();
  try {
    ivySettings.setVariable("common.build.dir", commonBuildDir.getAbsolutePath());
    ivySettings.setVariable("ivy.exclude.types", "source|javadoc");
    ivySettings.setVariable("ivy.resolution-cache.dir", ivyResolutionCacheDir.getAbsolutePath());
    ivySettings.setVariable("ivy.lock-strategy", ivyLockStrategy);
    ivySettings.setVariable("ivysettings.xml", getProject().getProperty("ivysettings.xml")); // nested settings file
    ivySettings.setBaseDir(commonBuildDir);
    ivySettings.setDefaultConflictManager(new NoConflictManager());
    ivy = Ivy.newInstance(ivySettings);
    ivy.configure(topLevelIvySettingsFile);
  } catch (Exception e) {
    throw new BuildException("Exception reading " + topLevelIvySettingsFile.getPath() + ": " + e.toString(), e);
  }
}
 
Example #8
Source File: IvyConfigureTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testFile() throws Exception {
    configure.setFile(new File("test/repositories/ivysettings.xml"));

    configure.execute();

    Ivy ivy = getIvyInstance();
    assertNotNull(ivy);
    IvySettings settings = ivy.getSettings();
    assertNotNull(settings);

    assertEquals(new File("build/cache").getAbsoluteFile(), settings.getDefaultCache());
    assertEquals(new File("test/repositories/ivysettings.xml").getAbsolutePath(), settings
            .getVariables().getVariable("ivy.settings.file"));
    assertEquals(
        new File("test/repositories/ivysettings.xml").toURI().toURL().toExternalForm(),
        settings.getVariables().getVariable("ivy.settings.url"));
    assertEquals(new File("test/repositories").getAbsolutePath(), settings.getVariables()
            .getVariable("ivy.settings.dir"));
    assertEquals("myvalue", settings.getVariables().getVariable("myproperty"));
}
 
Example #9
Source File: IvyConfigureTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testOverrideFalse() {
    configure.setFile(new File("test/repositories/ivysettings.xml"));
    configure.execute();

    Ivy ivy = getIvyInstance();
    assertNotNull(ivy);

    IvyConfigure newAntSettings = new IvyConfigure();
    newAntSettings.setProject(project);
    newAntSettings.setOverride("false");
    newAntSettings.setFile(new File("test/repositories/ivysettings.xml"));
    newAntSettings.execute();

    assertSame(ivy, getIvyInstance());
}
 
Example #10
Source File: CredentialsUtil.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public static Credentials promptCredentials(Credentials c, File passfile) {
    c = loadPassfile(c, passfile);
    if (c.getUserName() != null && c.getPasswd() != null) {
        return c;
    }
    CredentialPanel credentialPanel = new CredentialPanel(c, passfile);
    if (JOptionPane.showOptionDialog(null, credentialPanel, c.getHost() + " credentials",
        JOptionPane.OK_CANCEL_OPTION, 0, new ImageIcon(Ivy.class.getResource("logo.png")),
        null, JOptionPane.OK_OPTION) == JOptionPane.OK_OPTION) {
        String username = credentialPanel.userNameField.getText();
        String passwd = credentialPanel.passwordField.getText();
        if (credentialPanel.rememberDataCB.isSelected()) {
            Properties props = new EncryptedProperties();
            props.setProperty("username", username);
            props.setProperty("passwd", passwd);
            try (FileOutputStream fos = new FileOutputStream(passfile)) {
                props.store(fos, "");
            } catch (Exception e) {
                Message.warn("error occurred while saving password file " + passfile, e);
            }
        }
        c = new Credentials(c.getRealm(), c.getHost(), username, passwd);
    }
    return c;
}
 
Example #11
Source File: InstallTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDependencies() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings.xml"));

    ivy.install(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), ivy.getSettings()
            .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());

    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());
}
 
Example #12
Source File: LatestCompatibleConflictManagerTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testInitFromSettings() throws Exception {
    Ivy ivy = new Ivy();
    ivy.configure(LatestCompatibleConflictManagerTest.class
            .getResource("ivysettings-latest-compatible.xml"));
    ConflictManager cm = ivy.getSettings().getDefaultConflictManager();
    assertTrue(cm instanceof LatestCompatibleConflictManager);
}
 
Example #13
Source File: XmlModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private static String mergeRevisionValue(String inherited, String override) {
    if (override == null || override.equals(Ivy.getWorkingRevision())) {
        return inherited;
    } else {
        return override;
    }
}
 
Example #14
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtendsDescription() throws Exception {
    // descriptor specifies that only parent description should be included
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-extends-description.xml"), true);
    assertNotNull(md);

    assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
    assertEquals("mymodule", md.getModuleRevisionId().getName());
    assertEquals(Ivy.getWorkingRevision(), md.getModuleRevisionId().getRevision());
    assertEquals("integration", md.getStatus());

    // verify that the parent description was merged.
    assertEquals("Parent module description.", md.getDescription());

    // verify that the parent configurations were ignored.
    final Configuration[] expectedConfs = {new Configuration("default")};
    assertNotNull(md.getConfigurations());
    assertEquals(Arrays.asList(expectedConfs), Arrays.asList(md.getConfigurations()));

    // verify parent dependencies were ignored.
    DependencyDescriptor[] deps = md.getDependencies();
    assertNotNull(deps);
    assertEquals(1, deps.length);

    assertEquals(Collections.singletonList("default"),
        Arrays.asList(deps[0].getModuleConfigurations()));
    ModuleRevisionId dep = deps[0].getDependencyRevisionId();
    assertEquals("myorg", dep.getModuleId().getOrganisation());
    assertEquals("mymodule2", dep.getModuleId().getName());
    assertEquals("2.0", dep.getRevision());

    // verify only child publications are present
    Artifact[] artifacts = md.getAllArtifacts();
    assertNotNull(artifacts);
    assertEquals(1, artifacts.length);
    assertEquals("mymodule", artifacts[0].getName());
    assertEquals("jar", artifacts[0].getType());
}
 
Example #15
Source File: InstallTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoValidate() 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",
        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());
}
 
Example #16
Source File: IvyTask.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Called when task starts its execution.
 */
protected void prepareTask() {
    getProject().setProperty("ivy.version", Ivy.getIvyVersion());

    // push current project and Ivy on the stack in context
    IvyContext.pushNewCopyContext();
    IvyContext.getContext().setIvy(getIvyInstance());
    IvyContext.getContext().push(ANT_PROJECT_CONTEXT_KEY, getProject());
}
 
Example #17
Source File: IvyVarTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimple() {
    IvyVar task = new IvyVar();
    task.setProject(TestHelper.newProject());
    task.setName("mytest");
    task.setValue("myvalue");
    task.execute();
    Ivy ivy = task.getIvyInstance();
    assertNotNull(ivy);
    assertEquals("myvalue", ivy.getVariable("mytest"));
}
 
Example #18
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings.xml"));
    TestHelper.createCache();
    Message.setDefaultLogger(new DefaultMessageLogger(Message.MSG_INFO));
}
 
Example #19
Source File: ContextualArtifactResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void resolveModuleArtifacts(final ComponentMetaData component, final ArtifactResolveContext context, final BuildableArtifactSetResolveResult result) {
    lockingManager.useCache(String.format("Resolve %s for %s", context.getDescription(), component), new Runnable() {
        public void run() {
            ivyContextManager.withIvy(new Action<Ivy>() {
                public void execute(Ivy ivy) {
                    delegate.resolveModuleArtifacts(component, context, result);
                }
            });
        }
    });
}
 
Example #20
Source File: DefaultIvyContextManager.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void releaseIvy(Ivy ivy) {
    // cleanup
    ivy.getSettings().getResolvers().clear();
    ivy.getSettings().setDefaultResolver(null);

    lock.lock();
    try {
        if (cached.size() < MAX_CACHED_IVY_INSTANCES) {
            cached.add(ivy);
        }
        // else, throw it away
    } finally {
        lock.unlock();
    }
}
 
Example #21
Source File: DefaultIvyContextManager.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Ivy getIvy() {
    lock.lock();
    try {
        if (!cached.isEmpty()) {
            return cached.removeFirst();
        }
        if (!messageAdapterAttached) {
            Message.setDefaultLogger(new IvyLoggingAdaper());
            messageAdapterAttached = true;
        }
    } finally {
        lock.unlock();
    }
    return Ivy.newInstance(new IvySettings());
}
 
Example #22
Source File: DefaultIvyContextManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Ivy getIvy() {
    lock.lock();
    try {
        if (!cached.isEmpty()) {
            return cached.removeFirst();
        }
        if (!messageAdapterAttached) {
            Message.setDefaultLogger(new IvyLoggingAdaper());
            messageAdapterAttached = true;
        }
    } finally {
        lock.unlock();
    }
    return Ivy.newInstance(new IvySettings());
}
 
Example #23
Source File: SearchTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testListInMavenRepo() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/m2/ivysettings.xml").toURI().toURL());

    Map<String, Object> otherTokenValues = new HashMap<>();
    otherTokenValues.put(IvyPatternHelper.ORGANISATION_KEY, "org.apache");
    otherTokenValues.put(IvyPatternHelper.MODULE_KEY, "test-metadata");
    String[] revs = ivy.listTokenValues(IvyPatternHelper.REVISION_KEY, otherTokenValues);

    assertEquals(new HashSet<>(Arrays.asList("1.0", "1.1")),
            new HashSet<>(Arrays.asList(revs)));
}
 
Example #24
Source File: ContextualizingIvyPublisher.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void publish(final IvyNormalizedPublication publication, final PublicationAwareRepository repository) {
    ivyContextManager.withIvy(new Action<Ivy>() {
        public void execute(Ivy ivy) {
            ivyPublisher.publish(publication, repository);
        }
    });
}
 
Example #25
Source File: GradlePomModuleDescriptorBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GradlePomModuleDescriptorBuilder(PomReader pomReader) {
    ivyModuleDescriptor = new DefaultModuleDescriptor(XmlModuleDescriptorParser.getInstance(), null);
    ivyModuleDescriptor.setResolvedPublicationDate(new Date());
    for (Configuration maven2Configuration : MAVEN2_CONFIGURATIONS) {
        ivyModuleDescriptor.addConfiguration(maven2Configuration);
    }
    ivyModuleDescriptor.setMappingOverride(true);
    ivyModuleDescriptor.addExtraAttributeNamespace("m", Ivy.getIvyHomeURL() + "maven");
    this.pomReader = pomReader;
}
 
Example #26
Source File: ConfigureTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefault14() throws ParseException, IOException {
    Ivy ivy = new Ivy();
    ivy.configureDefault14();

    IvySettings settings = ivy.getSettings();
    assertNotNull(settings.getDefaultResolver());

    DependencyResolver publicResolver = settings.getResolver("public");
    assertTrue(publicResolver instanceof IvyRepResolver);
}
 
Example #27
Source File: ContextualArtifactResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void executeInContext(String description, final Action<Ivy> action) {
    lockingManager.useCache(description, new Runnable() {
        public void run() {
            ivyContextManager.withIvy(action);
        }
    });
}
 
Example #28
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtendsDescriptionWithOverride() throws Exception {
    // descriptor specifies that only parent description should be included
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-extends-description-override.xml"), true);
    assertNotNull(md);

    assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
    assertEquals("mymodule", md.getModuleRevisionId().getName());
    assertEquals(Ivy.getWorkingRevision(), md.getModuleRevisionId().getRevision());
    assertEquals("integration", md.getStatus());

    // child description should always be preferred, even if extendType="description"
    assertEquals("Child description overrides parent.", md.getDescription());

    // verify that the parent configurations were ignored.
    final Configuration[] expectedConfs = {new Configuration("default")};
    assertNotNull(md.getConfigurations());
    assertEquals(Arrays.asList(expectedConfs), Arrays.asList(md.getConfigurations()));

    // verify parent dependencies were ignored.
    DependencyDescriptor[] deps = md.getDependencies();
    assertNotNull(deps);
    assertEquals(1, deps.length);

    assertEquals(Collections.singletonList("default"),
        Arrays.asList(deps[0].getModuleConfigurations()));
    ModuleRevisionId dep = deps[0].getDependencyRevisionId();
    assertEquals("myorg", dep.getModuleId().getOrganisation());
    assertEquals("mymodule2", dep.getModuleId().getName());
    assertEquals("2.0", dep.getRevision());

    // verify only child publications are present
    Artifact[] artifacts = md.getAllArtifacts();
    assertNotNull(artifacts);
    assertEquals(1, artifacts.length);
    assertEquals("mymodule", artifacts[0].getName());
    assertEquals("jar", artifacts[0].getType());
}
 
Example #29
Source File: ContextualArtifactResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void resolveModuleArtifacts(final ComponentResolveMetaData component, final ArtifactType artifactType, final BuildableArtifactSetResolveResult result) {
    executeInContext(String.format("Resolve %s for %s", artifactType, component), new Action<Ivy>() {
        public void execute(Ivy ivy) {
            delegate.resolveModuleArtifacts(component, artifactType, result);
        }
    });
}
 
Example #30
Source File: ModuleInSort.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Return true if this module match the DependencyDescriptor with the given versionMatcher. If
 * this module has no version defined, then true is always returned.
 */
public boolean match(DependencyDescriptor descriptor, VersionMatcher versionMatcher) {
    ModuleDescriptor md = module;
    return md.getResolvedModuleRevisionId().getRevision() == null
            || md.getResolvedModuleRevisionId().getRevision().equals(Ivy.getWorkingRevision())
            || versionMatcher.accept(descriptor.getDependencyRevisionId(), md);
    // Checking md.getResolvedModuleRevisionId().getRevision().equals(Ivy.getWorkingRevision()
    // allow to consider any local non resolved ivy.xml
    // as a valid module.
}