@Test
  public void testAddArtifacts() {
    final PublishArtifact publishArtifactConf1 = createNamedPublishArtifact("conf1");
    Configuration configurationStub1 = createConfigurationStub(publishArtifactConf1);
    final PublishArtifact publishArtifactConf2 = createNamedPublishArtifact("conf2");
    Configuration configurationStub2 = createConfigurationStub(publishArtifactConf2);
    final ArtifactsExtraAttributesStrategy artifactsExtraAttributesStrategyMock =
        context.mock(ArtifactsExtraAttributesStrategy.class);
    final Map<String, String> extraAttributesArtifact1 =
        WrapUtil.toMap("name", publishArtifactConf1.getName());
    final Map<String, String> extraAttributesArtifact2 =
        WrapUtil.toMap("name", publishArtifactConf2.getName());
    context.checking(
        new Expectations() {
          {
            one(artifactsExtraAttributesStrategyMock).createExtraAttributes(publishArtifactConf1);
            will(returnValue(extraAttributesArtifact1));
            one(artifactsExtraAttributesStrategyMock).createExtraAttributes(publishArtifactConf2);
            will(returnValue(extraAttributesArtifact2));
          }
        });
    DefaultModuleDescriptor moduleDescriptor =
        HelperUtil.createModuleDescriptor(
            WrapUtil.toSet(configurationStub1.getName(), configurationStub2.getName()));

    DefaultArtifactsToModuleDescriptorConverter artifactsToModuleDescriptorConverter =
        new DefaultArtifactsToModuleDescriptorConverter(artifactsExtraAttributesStrategyMock);

    artifactsToModuleDescriptorConverter.addArtifacts(
        moduleDescriptor, WrapUtil.toSet(configurationStub1, configurationStub2));

    assertArtifactIsAdded(configurationStub1, moduleDescriptor, extraAttributesArtifact1);
    assertArtifactIsAdded(configurationStub2, moduleDescriptor, extraAttributesArtifact2);
    assertThat(moduleDescriptor.getAllArtifacts().length, equalTo(2));
  }
 @Override
 public ModuleDescriptor parseDescriptor(
     ParserSettings ivySettings, URL xmlURL, Resource res, boolean validate)
     throws ParseException, IOException {
   DefaultModuleDescriptor descriptor =
       (DefaultModuleDescriptor) super.parseDescriptor(ivySettings, xmlURL, res, validate);
   descriptor.setDefault(false);
   return descriptor;
 }
 public ModuleDescriptor createModuleDescriptor(
     ModuleRevisionId moduleRevisionId, Set<ModuleDependency> dependencies) {
   DefaultModuleDescriptor moduleDescriptor =
       new DefaultModuleDescriptor(moduleRevisionId, "release", null);
   moduleDescriptor.addConfiguration(new Configuration(Dependency.DEFAULT_CONFIGURATION));
   addDependencyDescriptors(moduleDescriptor, dependencies, dependencyDescriptorFactory);
   moduleDescriptor.addArtifact(
       Dependency.DEFAULT_CONFIGURATION,
       new DefaultArtifact(moduleRevisionId, null, moduleRevisionId.getName(), "jar", "jar"));
   return moduleDescriptor;
 }
 private void assertArtifactIsAdded(
     Configuration configuration,
     DefaultModuleDescriptor moduleDescriptor,
     Map<String, String> extraAttributes) {
   assertThat(
       moduleDescriptor.getArtifacts(configuration.getName()),
       equalTo(
           WrapUtil.toArray(
               expectedIvyArtifact(configuration, moduleDescriptor, extraAttributes))));
 }
Beispiel #5
0
 private void checkNotConvertedExclusionRule(
     ModuleDescriptor systemMd, ResolvedResource ivyRef, ResolveData data) {
   if (!getNamespace().equals(Namespace.SYSTEM_NAMESPACE)
       && !systemMd.isDefault()
       && data.getSettings().logNotConvertedExclusionRule()
       && systemMd instanceof DefaultModuleDescriptor) {
     DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) systemMd;
     if (dmd.isNamespaceUseful()) {
       Message.warn(
           "the module descriptor "
               + ivyRef.getResource()
               + " has information which can't be converted into "
               + "the system namespace. "
               + "It will require the availability of the namespace '"
               + getNamespace().getName()
               + "' to be fully usable.");
     }
   }
 }
 private ModuleDescriptor createAnonymousModuleDescriptor() {
   return DefaultModuleDescriptor.newDefaultInstance(
       ModuleRevisionId.newInstance("org", "name", "1.0", new HashMap()));
 }
Beispiel #7
0
  public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
      throws ParseException {
    IvyContext context = IvyContext.pushNewCopyContext();
    try {
      ResolvedModuleRevision mr = data.getCurrentResolvedModuleRevision();
      if (mr != null) {
        if (shouldReturnResolvedModule(dd, mr)) {
          return mr;
        }
      }

      if (isForce()) {
        dd =
            dd.clone(
                ModuleRevisionId.newInstance(dd.getDependencyRevisionId(), "latest.integration"));
      }
      DependencyDescriptor systemDd = dd;
      DependencyDescriptor nsDd = fromSystem(dd);
      context.setDependencyDescriptor(systemDd);
      context.setResolveData(data);

      clearIvyAttempts();
      clearArtifactAttempts();
      ModuleRevisionId systemMrid = systemDd.getDependencyRevisionId();
      ModuleRevisionId nsMrid = nsDd.getDependencyRevisionId();

      checkRevision(systemMrid);

      boolean isDynamic = getAndCheckIsDynamic(systemMrid);

      // we first search for the dependency in cache
      ResolvedModuleRevision rmr = null;
      rmr = findModuleInCache(systemDd, data);
      if (rmr != null) {
        if (rmr.getDescriptor().isDefault() && rmr.getResolver() != this) {
          Message.verbose(
              "\t"
                  + getName()
                  + ": found revision in cache: "
                  + systemMrid
                  + " (resolved by "
                  + rmr.getResolver().getName()
                  + "): but it's a default one, maybe we can find a better one");
        } else if (isForce() && rmr.getResolver() != this) {
          Message.verbose(
              "\t"
                  + getName()
                  + ": found revision in cache: "
                  + systemMrid
                  + " (resolved by "
                  + rmr.getResolver().getName()
                  + "): but we are in force mode, let's try to find one ourself");
        } else {
          Message.verbose("\t" + getName() + ": revision in cache: " + systemMrid);
          return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
        }
      }
      if (data.getOptions().isUseCacheOnly()) {
        throw new UnresolvedDependencyException(
            "\t" + getName() + " (useCacheOnly) : no ivy file found for " + systemMrid, false);
      }

      checkInterrupted();

      ResolvedResource ivyRef = findIvyFileRef(nsDd, data);
      checkInterrupted();

      // get module descriptor
      ModuleDescriptor nsMd;
      ModuleDescriptor systemMd = null;
      if (ivyRef == null) {
        if (!isAllownomd()) {
          throw new UnresolvedDependencyException(
              "\t" + getName() + ": no ivy file found for " + systemMrid, false);
        }
        nsMd = DefaultModuleDescriptor.newDefaultInstance(nsMrid, nsDd.getAllDependencyArtifacts());
        ResolvedResource artifactRef = findFirstArtifactRef(nsMd, nsDd, data);
        checkInterrupted();
        if (artifactRef == null) {
          throw new UnresolvedDependencyException(
              "\t" + getName() + ": no ivy file nor artifact found for " + systemMrid, false);
        } else {
          long lastModified = artifactRef.getLastModified();
          if (lastModified != 0 && nsMd instanceof DefaultModuleDescriptor) {
            ((DefaultModuleDescriptor) nsMd).setLastModified(lastModified);
          }
          Message.verbose(
              "\t" + getName() + ": no ivy file found for " + systemMrid + ": using default data");
          if (isDynamic) {
            nsMd.setResolvedModuleRevisionId(
                ModuleRevisionId.newInstance(nsMrid, artifactRef.getRevision()));
          }
          systemMd = toSystem(nsMd);
          MetadataArtifactDownloadReport madr =
              new MetadataArtifactDownloadReport(systemMd.getMetadataArtifact());
          madr.setDownloadStatus(DownloadStatus.NO);
          madr.setSearched(true);
          rmr = new ResolvedModuleRevision(this, this, systemMd, madr, isForce());
          getRepositoryCacheManager()
              .cacheModuleDescriptor(
                  this,
                  artifactRef,
                  toSystem(dd),
                  systemMd.getAllArtifacts()[0],
                  null,
                  getCacheOptions(data));
        }
      } else {
        if (ivyRef instanceof MDResolvedResource) {
          rmr = ((MDResolvedResource) ivyRef).getResolvedModuleRevision();
        }
        if (rmr == null) {
          rmr = parse(ivyRef, systemDd, data);
          if (rmr == null) {
            throw new UnresolvedDependencyException();
          }
        }
        if (!rmr.getReport().isDownloaded() && rmr.getReport().getLocalFile() != null) {
          return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
        } else {
          nsMd = rmr.getDescriptor();

          // check descriptor data is in sync with resource revision and names
          systemMd = toSystem(nsMd);
          if (isCheckconsistency()) {
            checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
            checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
          } else {
            if (systemMd instanceof DefaultModuleDescriptor) {
              DefaultModuleDescriptor defaultMd = (DefaultModuleDescriptor) systemMd;
              ModuleRevisionId revision = getRevision(ivyRef, systemMrid, systemMd);
              defaultMd.setModuleRevisionId(revision);
              defaultMd.setResolvedModuleRevisionId(revision);
            } else {
              Message.warn(
                  "consistency disabled with instance of non DefaultModuleDescriptor..."
                      + " module info can't be updated, so consistency check will be done");
              checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
              checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
            }
          }
          rmr =
              new ResolvedModuleRevision(
                  this, this, systemMd, toSystem(rmr.getReport()), isForce());
        }
      }

      resolveAndCheckRevision(systemMd, systemMrid, ivyRef, isDynamic);
      resolveAndCheckPublicationDate(systemDd, systemMd, systemMrid, data);
      checkNotConvertedExclusionRule(systemMd, ivyRef, data);

      if (ivyRef == null || ivyRef.getResource() != null) {
        cacheModuleDescriptor(systemMd, systemMrid, ivyRef, rmr);
      }

      return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
    } catch (UnresolvedDependencyException ex) {
      if (ex.getMessage().length() > 0) {
        if (ex.isError()) {
          Message.error(ex.getMessage());
        } else {
          Message.verbose(ex.getMessage());
        }
      }
      return data.getCurrentResolvedModuleRevision();
    } finally {
      IvyContext.popContext();
    }
  }