예제 #1
0
  def _setup_single_module(self, module_name, module_pom_contents, touch_files=None):
    with temporary_dir() as tempdir:
      current_dir = os.path.abspath('.')
      os.chdir(tempdir)

      self.make_file('pom.xml', dedent('''
        <?xml version="1.0" encoding="UTF-8"?>
        <project>
          <groupId>com.example</groupId>
          <artifactId>parent</artifactId>
          <version>HEAD-SNAPSHOT</version>

          <modules>
            <module>{module_name}</module>
          </modules>
        </project>
      '''.format(module_name=module_name)).strip())

      self.make_file(os.path.join('parents', 'base', 'pom.xml'), dedent('''
        <?xml version="1.0" encoding="UTF-8"?>
        <project>
          <groupId>com.example</groupId>
          <artifactId>the-parent-pom</artifactId>
          <version>HEAD-SNAPSHOT</version>

          <dependencyManagement>
          </dependencyManagement>
        </project>
      '''.strip()))

      self.make_file(os.path.join(module_name, 'pom.xml'), 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">
          <modelVersion>4.0.0</modelVersion>

          <parent>
            <groupId>com.example</groupId>
            <artifactId>the-parent-pom</artifactId>
            <version>HEAD-SNAPSHOT</version>
            <relativePath>../parents/base/pom.xml</relativePath>
          </parent>

          <groupId>com.example.project</groupId>
          <artifactId>{module_name}</artifactId>
          <version>HEAD-SNAPSHOT</version>

          {module_pom_contents}
        </project>
      ''').format(module_name=module_name,
                  module_pom_contents=module_pom_contents).strip())

      for path in (touch_files or ()):
        touch(path, makedirs=True)

      yield os.path.join(module_name, 'pom.xml')

      os.chdir(current_dir)
예제 #2
0
    def test_file_pattern_exists_in_subdir(self):
        pattern = re.compile(r".*Test.java")
        with temporary_dir() as tmpdir:
            self.assertFalse(file_pattern_exists_in_subdir(tmpdir, pattern))
            touch(os.path.join(tmpdir, "foo.java"))
            self.assertFalse(file_pattern_exists_in_subdir(tmpdir, pattern))
            touch(os.path.join(tmpdir, "ExampleTest.java"))
            self.assertTrue(file_pattern_exists_in_subdir(tmpdir, pattern))

        with temporary_dir() as tmpdir:
            nested_dir = os.path.join(tmpdir, "src", "main", "java", "com", "squareup", "foo")
            os.makedirs(nested_dir)
            self.assertFalse(file_pattern_exists_in_subdir(tmpdir, pattern))
            touch(os.path.join(tmpdir, "bogus.java"))
            touch(os.path.join(nested_dir, "bogus.java"))
            touch(os.path.join(nested_dir, "AnotherTest.java"))
            self.assertTrue(file_pattern_exists_in_subdir(tmpdir, pattern))
예제 #3
0
    def test_file_pattern_exists_in_subdir(self):
        pattern = re.compile(r'.*Test.java')
        with temporary_dir() as tmpdir:
            self.assertFalse(file_pattern_exists_in_subdir(tmpdir, pattern))
            touch(os.path.join(tmpdir, 'foo.java'))
            self.assertFalse(file_pattern_exists_in_subdir(tmpdir, pattern))
            touch(os.path.join(tmpdir, 'ExampleTest.java'))
            self.assertTrue(file_pattern_exists_in_subdir(tmpdir, pattern))

        with temporary_dir() as tmpdir:
            nested_dir = os.path.join(tmpdir, 'src', 'main', 'java', 'com',
                                      'squareup', 'foo')
            os.makedirs(nested_dir)
            self.assertFalse(file_pattern_exists_in_subdir(tmpdir, pattern))
            touch(os.path.join(tmpdir, 'bogus.java'))
            touch(os.path.join(nested_dir, 'bogus.java'))
            touch(os.path.join(nested_dir, 'AnotherTest.java'))
            self.assertTrue(file_pattern_exists_in_subdir(tmpdir, pattern))
예제 #4
0
    def test_find_target_directories(self):
        with temporary_dir() as outdir:
            project_name = "foobar"
            self.set_options(
                project_dir=outdir,
                project_name=project_name,
                loose_files=True,
                merge=False,
                libraries=False,
                open=False,
            )
            with open(os.path.join(get_buildroot(), "pom.xml"), "w+") as f:
                f.write('<?xml version="1.0" encoding="UTF-8"?>' "<project><modules/></project>")
            task = self.create_task(self.context())
            project = task._create_idea_project(outdir, None)
            with temporary_dir() as repo:
                poms = {
                    os.path.join(repo, pom)
                    for pom in (
                        "pom.xml",
                        "foobar/pom.xml",
                        "foobar/child1/pom.xml",
                        "foobar/child1/sub/sub/pom.xml",
                        "foobar/child1/sub/marine/foo.txt",
                        "foobar/child1/sub/mersible/pom.xml",
                        "foobar/child2/foo.txt",
                        "foobar/child3/pom.xml",
                        "orange/pom.xml",
                        "yellow/foo.txt",
                    )
                }
                for pom in poms:
                    touch(pom, makedirs=True)

                excludes = project._maven_excludes(os.path.join(repo, "foobar/child1"))
                expected = {
                    os.path.join(repo, target)
                    for target in (
                        "target",
                        "foobar/target",
                        "foobar/child1/target",
                        "foobar/child1/sub/sub/target",
                        "foobar/child1/sub/mersible/target",
                    )
                }

                self.assertEqual(expected, set(excludes))

                excludes = project._maven_excludes(os.path.join(repo, "foobar"))
                expected = {
                    os.path.join(repo, target)
                    for target in (
                        "target",
                        "foobar/target",
                        "foobar/child1/target",
                        "foobar/child1/sub/sub/target",
                        "foobar/child1/sub/mersible/target",
                        "foobar/child3/target",
                    )
                }

                self.assertEqual(expected, set(excludes))

                excludes = project._maven_excludes(os.path.join(repo))
                expected = {
                    os.path.join(repo, target)
                    for target in (
                        "target",
                        "foobar/target",
                        "foobar/child1/target",
                        "foobar/child1/sub/sub/target",
                        "foobar/child1/sub/mersible/target",
                        "foobar/child3/target",
                        "orange/target",
                    )
                }

                self.assertEqual(expected, set(excludes))
예제 #5
0
    def _setup_single_module(self,
                             module_name,
                             module_pom_contents,
                             touch_files=None):
        with temporary_dir() as tempdir:
            current_dir = os.path.abspath('.')
            os.chdir(tempdir)

            self.make_file(
                'pom.xml',
                dedent('''
        <?xml version="1.0" encoding="UTF-8"?>
        <project>
          <groupId>com.example</groupId>
          <artifactId>parent</artifactId>
          <version>HEAD-SNAPSHOT</version>

          <modules>
            <module>{module_name}</module>
          </modules>
        </project>
      '''.format(module_name=module_name)).strip())

            self.make_file(
                os.path.join('parents', 'base', 'pom.xml'),
                dedent('''
        <?xml version="1.0" encoding="UTF-8"?>
        <project>
          <groupId>com.example</groupId>
          <artifactId>the-parent-pom</artifactId>
          <version>HEAD-SNAPSHOT</version>

          <dependencyManagement>
          </dependencyManagement>
        </project>
      '''.strip()))

            self.make_file(
                os.path.join(module_name, 'pom.xml'),
                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">
          <modelVersion>4.0.0</modelVersion>

          <parent>
            <groupId>com.example</groupId>
            <artifactId>the-parent-pom</artifactId>
            <version>HEAD-SNAPSHOT</version>
            <relativePath>../parents/base/pom.xml</relativePath>
          </parent>

          <groupId>com.example.project</groupId>
          <artifactId>{module_name}</artifactId>
          <version>HEAD-SNAPSHOT</version>

          {module_pom_contents}
        </project>
      ''').format(module_name=module_name,
                  module_pom_contents=module_pom_contents).strip())

            for path in (touch_files or ()):
                touch(path, makedirs=True)

            yield os.path.join(module_name, 'pom.xml')

            os.chdir(current_dir)
예제 #6
0
    def test_find_target_directories(self):
        with temporary_dir() as outdir:
            project_name = 'foobar'
            self.set_options(project_dir=outdir,
                             project_name=project_name,
                             loose_files=True,
                             merge=False,
                             libraries=False,
                             open=False)
            with open(os.path.join(get_buildroot(), 'pom.xml'), 'w+') as f:
                f.write('<?xml version="1.0" encoding="UTF-8"?>'
                        '<project><modules/></project>')
            task = self.create_task(self.context())
            project = task._create_idea_project(outdir, None)
            with temporary_dir() as repo:
                poms = {
                    os.path.join(repo, pom)
                    for pom in (
                        'pom.xml',
                        'foobar/pom.xml',
                        'foobar/child1/pom.xml',
                        'foobar/child1/sub/sub/pom.xml',
                        'foobar/child1/sub/marine/foo.txt',
                        'foobar/child1/sub/mersible/pom.xml',
                        'foobar/child2/foo.txt',
                        'foobar/child3/pom.xml',
                        'orange/pom.xml',
                        'yellow/foo.txt',
                    )
                }
                for pom in poms:
                    touch(pom, makedirs=True)

                excludes = project._maven_excludes(
                    os.path.join(repo, 'foobar/child1'))
                expected = {
                    os.path.join(repo, target)
                    for target in (
                        'target',
                        'foobar/target',
                        'foobar/child1/target',
                        'foobar/child1/sub/sub/target',
                        'foobar/child1/sub/mersible/target',
                    )
                }

                self.assertEqual(expected, set(excludes))

                excludes = project._maven_excludes(os.path.join(
                    repo, 'foobar'))
                expected = {
                    os.path.join(repo, target)
                    for target in ('target', 'foobar/target',
                                   'foobar/child1/target',
                                   'foobar/child1/sub/sub/target',
                                   'foobar/child1/sub/mersible/target',
                                   'foobar/child3/target')
                }

                self.assertEqual(expected, set(excludes))

                excludes = project._maven_excludes(os.path.join(repo))
                expected = {
                    os.path.join(repo, target)
                    for target in (
                        'target',
                        'foobar/target',
                        'foobar/child1/target',
                        'foobar/child1/sub/sub/target',
                        'foobar/child1/sub/mersible/target',
                        'foobar/child3/target',
                        'orange/target',
                    )
                }

                self.assertEqual(expected, set(excludes))