def test_type_test_jar(self):
    with temporary_dir() as tmpdir:
      with open(os.path.join(tmpdir, 'pom.xml') , 'w') as pomfile:
        pomfile.write(dedent('''<?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
             http://maven.apache.org/xsd/maven-4.0.0.xsd">

          <groupId>com.example</groupId>
          <artifactId>base</artifactId>
          <description>A generic Square module.</description>
          <version>HEAD-SNAPSHOT</version>
          <dependencies>
            <dependency>
              <groupId>com.example</groupId>
              <artifactId>dep1</artifactId>
              <type>foo</type>
              <version>1.0</version>
            </dependency>
            <dependency>
              <groupId>com.example</groupId>
              <artifactId>dep2</artifactId>
              <type>test-jar</type>
              <version>1.2.3</version>
            </dependency>
          </dependencies>
        </project>
      '''))

      # TODO(Eric Ayers): Right now, our builds expect a file in <rootdir>/parents/base/pom.xml
      os.makedirs(os.path.join(tmpdir, 'parents', 'base'))
      with open(os.path.join(tmpdir, 'parents', 'base', 'pom.xml'), 'w') as dep_mgmt_pom:
        dep_mgmt_pom.write(DEPENDENCY_MANAGEMENT_POM)

      df = squarepants.pom_handlers.DependencyInfo('pom.xml', rootdir=tmpdir)
      self.assertEquals({u'groupId' : 'com.example',
                         u'artifactId' : 'dep1',
                         u'type' : 'foo',
                         u'exclusions' : [],
                         u'version' : '1.0'
                         }, df.dependencies[0])
      self.assertEquals({u'groupId' : 'com.example',
                         u'artifactId' : 'dep2',
                         u'type' : 'test-jar',
                         u'exclusions' : [],
                         u'version' : '1.2.3'
                         }, df.dependencies[1])
      self.assertEquals(2, len(df.dependencies))

      deps_from_pom = squarepants.pom_handlers.DepsFromPom(PomUtils.pom_provides_target(),
                                                           rootdir=tmpdir)
      refs = deps_from_pom.build_pants_refs(df.dependencies)
      self.assertEquals("sjar(org='com.example', name='dep1', rev='1.0', ext='foo',)", refs[0])
      # type test-jar gets transformed into a 'tests' classifier
      self.assertEquals("sjar(org='com.example', name='dep2', rev='1.2.3', classifier='tests',)", refs[1])
      self.assertEquals(2, len(refs))
 def test_pom_provides_target(self):
   ppt = PomUtils.pom_provides_target()
   self.assertIsNotNone(ppt)
   self.assertIs(ppt, PomUtils.pom_provides_target()) # should be a singleton
Exemple #3
0
    def test_type_test_jar(self):
        with temporary_dir() as tmpdir:
            with open(os.path.join(tmpdir, 'pom.xml'), 'w') as pomfile:
                pomfile.write(
                    dedent('''<?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
             http://maven.apache.org/xsd/maven-4.0.0.xsd">

          <groupId>com.example</groupId>
          <artifactId>base</artifactId>
          <description>A generic Square module.</description>
          <version>HEAD-SNAPSHOT</version>
          <dependencies>
            <dependency>
              <groupId>com.example</groupId>
              <artifactId>dep1</artifactId>
              <type>foo</type>
              <version>1.0</version>
            </dependency>
            <dependency>
              <groupId>com.example</groupId>
              <artifactId>dep2</artifactId>
              <type>test-jar</type>
              <version>1.2.3</version>
            </dependency>
          </dependencies>
        </project>
      '''))

            # TODO(Eric Ayers): Right now, our builds expect a file in <rootdir>/parents/base/pom.xml
            os.makedirs(os.path.join(tmpdir, 'parents', 'base'))
            with open(os.path.join(tmpdir, 'parents', 'base', 'pom.xml'),
                      'w') as dep_mgmt_pom:
                dep_mgmt_pom.write(DEPENDENCY_MANAGEMENT_POM)

            df = squarepants.pom_handlers.DependencyInfo('pom.xml',
                                                         rootdir=tmpdir)
            self.assertEquals(
                {
                    u'groupId': 'com.example',
                    u'artifactId': 'dep1',
                    u'type': 'foo',
                    u'exclusions': [],
                    u'version': '1.0'
                }, df.dependencies[0])
            self.assertEquals(
                {
                    u'groupId': 'com.example',
                    u'artifactId': 'dep2',
                    u'type': 'test-jar',
                    u'exclusions': [],
                    u'version': '1.2.3'
                }, df.dependencies[1])
            self.assertEquals(2, len(df.dependencies))

            deps_from_pom = squarepants.pom_handlers.DepsFromPom(
                PomUtils.pom_provides_target(), rootdir=tmpdir)
            refs = deps_from_pom.build_pants_refs(df.dependencies)
            self.assertEquals(
                "sjar(org='com.example', name='dep1', rev='1.0', ext='foo',)",
                refs[0])
            # type test-jar gets transformed into a 'tests' classifier
            self.assertEquals(
                "sjar(org='com.example', name='dep2', rev='1.2.3', classifier='tests',)",
                refs[1])
            self.assertEquals(2, len(refs))
 def test_pom_provides_target(self):
     ppt = PomUtils.pom_provides_target()
     self.assertIsNotNone(ppt)
     self.assertIs(ppt,
                   PomUtils.pom_provides_target())  # should be a singleton