Exemplo n.º 1
0
    def test_build_with_targets(self):
        env_vars = (("http_proxy", None), ("https_proxy", None))
        for v in env_vars:
            self.useFixture(fixtures.EnvironmentVariable(v[0], v[1]))

        opts = self.options
        opts.maven_targets = ["child1", "child2"]
        plugin = maven.MavenPlugin("test-part", opts, self.project)

        self.create_assets(plugin)

        def side(l, **kwargs):
            os.makedirs(os.path.join(plugin.builddir, "child1", "target"))
            os.makedirs(os.path.join(plugin.builddir, "child2", "target"))
            open(
                os.path.join(plugin.builddir, "child1", "target", "child1.jar"), "w"
            ).close()
            open(
                os.path.join(plugin.builddir, "child2", "target", "child2.jar"), "w"
            ).close()

        self.run_mock.side_effect = side

        plugin.build()

        self.run_mock.assert_called_once_with(
            ["mvn", "package"], cwd=plugin.builddir, env=mock.ANY
        )
Exemplo n.º 2
0
    def test_build_with_targets(self, run_mock):
        env_vars = (
            ('http_proxy', None),
            ('https_proxy', None),
        )
        for v in env_vars:
            self.useFixture(fixtures.EnvironmentVariable(v[0], v[1]))

        opts = self.options
        opts.maven_targets = ['child1', 'child2']
        plugin = maven.MavenPlugin('test-part', opts, self.project_options)

        def side(l):
            os.makedirs(os.path.join(plugin.builddir, 'child1', 'target'))
            os.makedirs(os.path.join(plugin.builddir, 'child2', 'target'))
            open(
                os.path.join(plugin.builddir, 'child1', 'target',
                             'child1.jar'), 'w').close()
            open(
                os.path.join(plugin.builddir, 'child2', 'target',
                             'child2.jar'), 'w').close()

        run_mock.side_effect = side
        os.makedirs(plugin.sourcedir)

        plugin.build()

        run_mock.assert_has_calls([
            mock.call(['mvn', 'package']),
        ])
Exemplo n.º 3
0
    def test_get_non_defaul_openjdk(self):
        self.options.maven_openjdk_version = "8"

        plugin = maven.MavenPlugin("test-part", self.options, self.project)

        self.assertThat(plugin.stage_packages, Equals(["openjdk-8-jre-headless"]))
        self.assertThat(plugin.build_packages, Equals(["openjdk-8-jdk-headless"]))
Exemplo n.º 4
0
    def test_build_with_http_and_https_proxy(self, run_mock):
        env_vars = (
            ('http_proxy', 'http://localhost:3132'),
            ('https_proxy', 'http://localhost:3133'),
            ('no_proxy', None),
        )
        for v in env_vars:
            self.useFixture(fixtures.EnvironmentVariable(v[0], v[1]))

        plugin = maven.MavenPlugin('test-part', self.options,
                                   self.project_options)

        def side(l):
            os.makedirs(os.path.join(plugin.builddir, 'target'))
            open(os.path.join(plugin.builddir,
                 'target', 'dummy.jar'), 'w').close()

        run_mock.side_effect = side
        settings_path = os.path.join(plugin.partdir, 'm2', 'settings.xml')
        os.makedirs(plugin.sourcedir)

        plugin.build()

        run_mock.assert_has_calls([
            mock.call(['mvn', 'package', '-s', settings_path]),
        ])

        self.assertTrue(
            os.path.exists(settings_path),
            'expected {!r} to exist'.format(settings_path))

        with open(settings_path) as f:
            settings_contents = f.read()

        expected_contents = (
            '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"\n'
            '          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n'
            '          xsi:schemaLocation="http://maven.apache.org/SETTINGS/'
            '1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">\n'
            '  <interactiveMode>false</interactiveMode>\n'
            '  <proxies>\n'
            '    <proxy>\n'
            '      <id>http_proxy</id>\n'
            '      <active>true</active>\n'
            '      <protocol>http</protocol>\n'
            '      <host>localhost</host>\n'
            '      <port>3132</port>\n'
            '      <nonProxyHosts>localhost</nonProxyHosts>\n'
            '    </proxy>\n'
            '    <proxy>\n'
            '      <id>https_proxy</id>\n'
            '      <active>true</active>\n'
            '      <protocol>https</protocol>\n'
            '      <host>localhost</host>\n'
            '      <port>3133</port>\n'
            '      <nonProxyHosts>localhost</nonProxyHosts>\n'
            '    </proxy>\n'
            '  </proxies>\n'
            '</settings>\n')
        self.assertSettingsEqual(expected_contents, settings_contents)
Exemplo n.º 5
0
    def test_build_with_http_and_https_proxy(self, run_mock):
        env_vars = (
            ("http_proxy", "http://localhost:3132"),
            ("https_proxy", "http://localhost:3133"),
            ("no_proxy", None),
        )
        for v in env_vars:
            self.useFixture(fixtures.EnvironmentVariable(v[0], v[1]))

        plugin = maven.MavenPlugin("test-part", self.options,
                                   self.project_options)

        def side(l):
            os.makedirs(os.path.join(plugin.builddir, "target"))
            open(os.path.join(plugin.builddir, "target", "dummy.jar"),
                 "w").close()

        run_mock.side_effect = side
        settings_path = os.path.join(plugin.partdir, "m2", "settings.xml")
        os.makedirs(plugin.sourcedir)

        plugin.build()

        run_mock.assert_has_calls(
            [mock.call(["mvn", "package", "-s", settings_path])])

        self.assertTrue(
            os.path.exists(settings_path),
            "expected {!r} to exist".format(settings_path),
        )

        with open(settings_path) as f:
            settings_contents = f.read()

        expected_contents = (
            '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"\n'
            '          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n'
            '          xsi:schemaLocation="http://maven.apache.org/SETTINGS/'
            '1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">\n'
            "  <interactiveMode>false</interactiveMode>\n"
            "  <proxies>\n"
            "    <proxy>\n"
            "      <id>http_proxy</id>\n"
            "      <active>true</active>\n"
            "      <protocol>http</protocol>\n"
            "      <host>localhost</host>\n"
            "      <port>3132</port>\n"
            "      <nonProxyHosts>localhost</nonProxyHosts>\n"
            "    </proxy>\n"
            "    <proxy>\n"
            "      <id>https_proxy</id>\n"
            "      <active>true</active>\n"
            "      <protocol>https</protocol>\n"
            "      <host>localhost</host>\n"
            "      <port>3133</port>\n"
            "      <nonProxyHosts>localhost</nonProxyHosts>\n"
            "    </proxy>\n"
            "  </proxies>\n"
            "</settings>\n")
        self.assertSettingsEqual(expected_contents, settings_contents)
Exemplo n.º 6
0
    def test_build_with_targets(self, run_mock):
        env_vars = (("http_proxy", None), ("https_proxy", None))
        for v in env_vars:
            self.useFixture(fixtures.EnvironmentVariable(v[0], v[1]))

        opts = self.options
        opts.maven_targets = ["child1", "child2"]
        plugin = maven.MavenPlugin("test-part", opts, self.project_options)

        def side(l):
            os.makedirs(os.path.join(plugin.builddir, "child1", "target"))
            os.makedirs(os.path.join(plugin.builddir, "child2", "target"))
            open(
                os.path.join(plugin.builddir, "child1", "target",
                             "child1.jar"), "w").close()
            open(
                os.path.join(plugin.builddir, "child2", "target",
                             "child2.jar"), "w").close()

        run_mock.side_effect = side
        os.makedirs(plugin.sourcedir)

        plugin.build()

        run_mock.assert_has_calls([mock.call(["mvn", "package"])])
Exemplo n.º 7
0
    def test_build_with_authenticated_proxies(self):
        env_vars = (
            ("http_proxy", "http://*****:*****@localhost:3132"),
            ("https_proxy", "http://*****:*****@localhost:3133"),
            ("no_proxy", None),
        )
        for v in env_vars:
            self.useFixture(fixtures.EnvironmentVariable(v[0], v[1]))

        plugin = maven.MavenPlugin("test-part", self.options, self.project)

        self.create_assets(plugin)

        def side(l, **kwargs):
            os.makedirs(os.path.join(plugin.builddir, "target"))
            open(os.path.join(plugin.builddir, "target", "dummy.jar"), "w").close()

        self.run_mock.side_effect = side

        plugin.build()

        settings_path = os.path.join(plugin.partdir, "m2", "settings.xml")
        self.run_mock.assert_called_once_with(
            ["mvn", "package", "-s", settings_path], cwd=plugin.builddir, env=mock.ANY
        )
        self.assertThat(settings_path, FileExists())
        expected_content = dedent(
            """\
            <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
              <interactiveMode>false</interactiveMode>
              <proxies>
                <proxy>
                  <id>http_proxy</id>
                  <active>true</active>
                  <protocol>http</protocol>
                  <host>localhost</host>
                  <port>3132</port>
                  <username>user1</username>
                  <password>pass1</password>
                  <nonProxyHosts>localhost</nonProxyHosts>
                </proxy>
                <proxy>
                  <id>https_proxy</id>
                  <active>true</active>
                  <protocol>https</protocol>
                  <host>localhost</host>
                  <port>3133</port>
                  <username>user2</username>
                  <password>pass2</password>
                  <nonProxyHosts>localhost</nonProxyHosts>
                </proxy>
              </proxies>
            </settings>
            """
        )
        self.assertSettingsEqual(expected_content, settings_path)
Exemplo n.º 8
0
    def test_build(self, glob_mock, run_mock):
        plugin = maven.MavenPlugin('test-part', self.options,
                                   self.project_options)
        os.makedirs(plugin.sourcedir)
        glob_mock.return_value = [
            os.path.join(plugin.builddir, 'target', 'dummy')
        ]

        plugin.build()

        run_mock.assert_has_calls([
            mock.call(['mvn', 'package']),
        ])
Exemplo n.º 9
0
    def test_build_fail(self, run_mock):
        env_vars = (("http_proxy", None), ("https_proxy", None))
        for v in env_vars:
            self.useFixture(fixtures.EnvironmentVariable(v[0], v[1]))

        plugin = maven.MavenPlugin("test-part", self.options,
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        self.assertRaises(RuntimeError, plugin.build)

        run_mock.assert_has_calls([mock.call(["mvn", "package"])])
Exemplo n.º 10
0
    def test_build_with_proxy_and_no_proxies(self, glob_mock, run_mock):
        env_vars = (
            (
                'SNAPCRAFT_SETUP_PROXIES',
                '1',
            ),
            ('http_proxy', 'http://localhost:3132'),
            ('no_proxy', 'internal, pseudo-dmz'),
        )
        for v in env_vars:
            self.useFixture(fixtures.EnvironmentVariable(v[0], v[1]))

        plugin = maven.MavenPlugin('test-part', self.options,
                                   self.project_options)

        settings_path = os.path.join(plugin.partdir, 'm2', 'settings.xml')
        os.makedirs(plugin.sourcedir)
        glob_mock.return_value = [
            os.path.join(plugin.builddir, 'target', 'dummy')
        ]

        plugin.build()

        run_mock.assert_has_calls([
            mock.call(['mvn', 'package', '-s', settings_path]),
        ])

        self.assertTrue(os.path.exists(settings_path),
                        'expected {!r} to exist'.format(settings_path))

        with open(settings_path) as f:
            settings_contents = f.read()

        expected_contents = (
            '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"\n'
            '          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n'
            '          xsi:schemaLocation="http://maven.apache.org/SETTINGS/'
            '1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">\n'
            '  <interactiveMode>false</interactiveMode>\n'
            '  <proxies>\n'
            '    <proxy>\n'
            '      <id>proxy</id>\n'
            '      <active>true</active>\n'
            '      <protocol>http</protocol>\n'
            '      <host>localhost</host>\n'
            '      <port>3132</port>\n'
            '      <nonProxyHosts>internal|pseudo-dmz</nonProxyHosts>\n'
            '    </proxy>\n'
            '  </proxies>\n'
            '</settings>\n')
        self.assertEqual(settings_contents, expected_contents)
Exemplo n.º 11
0
    def test_build_fail(self):
        env_vars = (("http_proxy", None), ("https_proxy", None))
        for v in env_vars:
            self.useFixture(fixtures.EnvironmentVariable(v[0], v[1]))

        plugin = maven.MavenPlugin("test-part", self.options, self.project)

        self.create_assets(plugin)

        self.assertRaises(RuntimeError, plugin.build)

        self.run_mock.assert_called_once_with(
            ["mvn", "package"], cwd=plugin.builddir, env=mock.ANY
        )
Exemplo n.º 12
0
    def test_stage_and_build_packages(self):
        plugin = maven.MavenPlugin("test-part", self.options, self.project)

        self.assertThat(
            plugin.stage_packages,
            Equals([
                "openjdk-{}-jre-headless".format(self.expected_java_version)
            ]),
        )
        self.assertThat(
            plugin.build_packages,
            Equals([
                "openjdk-{}-jdk-headless".format(self.expected_java_version)
            ]),
        )
    def test_build_fail(self, run_mock):
        env_vars = (
            ('http_proxy', None),
            ('https_proxy', None),
        )
        for v in env_vars:
            self.useFixture(fixtures.EnvironmentVariable(v[0], v[1]))

        plugin = maven.MavenPlugin('test-part', self.options,
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        with self.assertRaises(RuntimeError):
            plugin.build()

        run_mock.assert_has_calls([
            mock.call(['mvn', 'package']),
        ])