@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));
  }
Esempio n. 2
0
 private void configureEclipse() {
   eclipseWtp.setDeployName("name");
   eclipseWtp.setOutputDirectory("bin");
   eclipseWtp.setWarLibs(WrapUtil.<Object>toList("lib\\b.jar", "lib/a.jar"));
   eclipseWtp.setProjectDependencies(WrapUtil.toList(projectDependencyMock));
   eclipseWtp.setWarResourceMappings(
       WrapUtil.<String, List<Object>>toMap(
           "WEB-INF/lib",
           WrapUtil.<Object>toList(
               new File(getProject().getProjectDir(), "conf1"), "conf2/child")));
 }
 @Test
 public void testResolveStrategy() {
   PublishArtifact publishArtifact = createNamedPublishArtifact("someName");
   Map<String, String> expectedExtraAttributes =
       WrapUtil.toMap(
           DefaultIvyDependencyPublisher.FILE_PATH_EXTRA_ATTRIBUTE,
           publishArtifact.getFile().getAbsolutePath());
   assertThat(
       DefaultArtifactsToModuleDescriptorConverter.RESOLVE_STRATEGY.createExtraAttributes(
           publishArtifact),
       equalTo(expectedExtraAttributes));
 }
Esempio n. 4
0
 private File downloadTimestampedVersion(Artifact artifact, String timestampedVersion)
     throws IOException {
   final ModuleRevisionId artifactModuleRevisionId = artifact.getModuleRevisionId();
   final ModuleRevisionId moduleRevisionId =
       ModuleRevisionId.newInstance(
           artifactModuleRevisionId.getOrganisation(),
           artifactModuleRevisionId.getName(),
           artifactModuleRevisionId.getRevision(),
           WrapUtil.toMap("timestamp", timestampedVersion));
   final Artifact artifactWithResolvedModuleRevisionId =
       DefaultArtifact.cloneWithAnotherMrid(artifact, moduleRevisionId);
   return download(artifactWithResolvedModuleRevisionId);
 }
Esempio n. 5
0
  @Test
  public void createSettings() {
    final File expectedSettingsDir = new File("settingsDir");
    ScriptSource expectedScriptSource = context.mock(ScriptSource.class);
    Map<String, String> expectedGradleProperties = WrapUtil.toMap("key", "myvalue");
    IProjectDescriptorRegistry expectedProjectDescriptorRegistry =
        new DefaultProjectDescriptorRegistry();
    StartParameter expectedStartParameter = new StartParameter();
    final ServiceRegistryFactory serviceRegistryFactory =
        context.mock(ServiceRegistryFactory.class);
    final SettingsInternallServiceRegistry settingsInternallServiceRegistry =
        context.mock(SettingsInternallServiceRegistry.class);
    context.checking(
        new Expectations() {
          {
            one(serviceRegistryFactory).createFor(with(any(Settings.class)));
            will(returnValue(settingsInternallServiceRegistry));
          }
        });

    SettingsFactory settingsFactory =
        new SettingsFactory(
            expectedProjectDescriptorRegistry,
            ThreadGlobalInstantiator.getOrCreate(),
            serviceRegistryFactory);
    final URLClassLoader urlClassLoader = new URLClassLoader(new URL[0]);
    GradleInternal gradle = context.mock(GradleInternal.class);

    DefaultSettings settings =
        (DefaultSettings)
            settingsFactory.createSettings(
                gradle,
                expectedSettingsDir,
                expectedScriptSource,
                expectedGradleProperties,
                expectedStartParameter,
                urlClassLoader);

    assertSame(gradle, settings.getGradle());
    assertSame(expectedProjectDescriptorRegistry, settings.getProjectDescriptorRegistry());
    for (Map.Entry<String, String> entry : expectedGradleProperties.entrySet()) {
      assertEquals(
          entry.getValue(),
          ((DynamicObjectAware) settings).getAsDynamicObject().getProperty(entry.getKey()));
    }

    assertSame(expectedSettingsDir, settings.getSettingsDir());
    assertSame(expectedScriptSource, settings.getSettingsScript());
    assertSame(expectedStartParameter, settings.getStartParameter());
  }
 private Artifact expectedIvyArtifact(
     Configuration configuration,
     ModuleDescriptor moduleDescriptor,
     Map<String, String> additionalExtraAttributes) {
   PublishArtifact publishArtifact = configuration.getArtifacts().iterator().next();
   Map<String, String> extraAttributes =
       WrapUtil.toMap(Dependency.CLASSIFIER, publishArtifact.getClassifier());
   extraAttributes.putAll(additionalExtraAttributes);
   return new DefaultArtifact(
       moduleDescriptor.getModuleRevisionId(),
       publishArtifact.getDate(),
       publishArtifact.getName(),
       publishArtifact.getType(),
       publishArtifact.getExtension(),
       extraAttributes);
 }