使用 Maven 设置 Drupal PHP 项目

发布于 2024-07-24 16:08:06 字数 3002 浏览 7 评论 0 原文

我想实现什么目标?

我们目前正在开发一个使用 Drupal 的 PHP 项目。

我非常想了解如何为整个项目创建一步构建。 最好使用看起来非常强大的新东西(对我来说): Maven

基本上我想自动化以下过程:

  1. 从官方 CVS 存储库
  2. 从各自的 CVS 存储库中检查官方第 3 方模块。
  3. 从我们的 Mercurial 存储库中查看我们的自定义模块。
  4. 将所有模块复制/移动到 Drupal 中的适当目录。
  5. 检查并安装我们的自定义主题。
  6. 添加自定义 drupal 安装配置文件。
  7. 创建新的 MySQL 数据库架构。
  8. 如果可能的话,自动化 drupal 数据库连接设置。

将来我想在 Hudson(或任何其他)持续集成服务器上运行此构建。

为什么是马文? (为什么不使用 Ant 或 Phing?)

除了学习新东西的愿望(我以前使用过 Ant)之外,我认为Maven 的依赖管理可能适用于 drupal 模块。

您认为这是使用 Maven 的充分理由吗,尽管 Maven 最初并不是为 PHP 项目设计的? 我知道 Ant 最初也不是用于 PHP,但是人们同时使用 Ant 和 PHP 的例子要多得多。

顺便说一句,如果我不能很快让 Maven 工作,我想我会切换到 Ant。 Ant 的程序风格对我来说更容易理解。

到目前为止我有什么?

我有一个 pom.xml 文件,它使用 SCM 插件来检查 drupal 源代码。 当我运行时:

mvn scm:checkout

源被检出到新目录中:

target/checkout

当我尝试时:

mvn scm:bootstrap

它抱怨安装目标未定义。

这是 pom.xml:

<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>

  <groupId>com.example</groupId>
  <artifactId>drupal</artifactId>
  <version>1.0</version>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-scm-plugin</artifactId>
          <version>1.1</version>
          <configuration>
            <username>anonymous</username>
            <password>anonymous</password>
          </configuration>
      </plugin>
    </plugins>
  </build>
  <scm>
    <connection>scm:cvs:pserver:cvs.drupal.org:/cvs/drupal:drupal</connection>
    <developerConnection>scm:cvs:pserver:cvs.drupal.org:/cvs/drupal:drupal</developerConnection>
    <tag>DRUPAL-6-12</tag>
    <url>http://cvs.drupal.org/viewvc.py/drupal/drupal/?pathrev=DRUPAL-6</url>
  </scm>
</project>

最后,我的问题是什么?

  • Maven 是否是一个错误的工具?

如果不是,

  • 你会怎么做?
  • 这是我应该使用的 scm:bootstrap 目标吗?
  • Maven 在文件系统上移动目录的方式是什么?
  • 是否应该使用 install 目标将模块移动到 drupal 目录中?
  • 目前,我们所有的自定义模块都位于一个 Mercurial 存储库中。 是否可以创建 pom.xml 并单独签出每个模块?
  • 任何一般性建议将不胜感激。

谢谢你的时间!

What do I want to achieve?

We are currently working on a PHP project that uses Drupal.

I desperately want to learn how to create a One-step build for the whole project.
Preferably by using something new (for me) that seems very powerful: Maven

Basically I want to automate the following process:

  1. Checkout Drupal from the official CVS repository.
  2. Checkout official 3rd party modules from their respective CVS repositories.
  3. Checkout our custom modules from our mercurial repository.
  4. Copy/move all the modules to the appropriate directory within Drupal.
  5. Checkout and install our custom theme.
  6. Add a custom drupal installation profile.
  7. Create a new MySQL database schema.
  8. If possible, automate the drupal db connection setup.

In the future I would like to run this build on a Hudson (or any other) continues integration server.

Why Maven? (why not Ant or Phing?)

Other than the desire to learn something new (I have used Ant before) I think the dependency management of Maven might work well for the drupal modules.

Do you think this is enough reason to use Maven, even though Maven was not originally intended for PHP projects? I know Ant was not originally used for PHP either, but there are far more examples of people using Ant and PHP together.

BTW I think I will switch to Ant if I can't get Maven to work soon. The procedural style of Ant is just easier for me to understand.

What do I have so far?

I have a pom.xml file, that uses the SCM plugin, to checkout the drupal source.
When I run:

mvn scm:checkout

the source is checked out into a new directory:

target/checkout

When I try:

mvn scm:bootstrap

it complains about the install goal not being defined.

Here is the pom.xml:

<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>

  <groupId>com.example</groupId>
  <artifactId>drupal</artifactId>
  <version>1.0</version>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-scm-plugin</artifactId>
          <version>1.1</version>
          <configuration>
            <username>anonymous</username>
            <password>anonymous</password>
          </configuration>
      </plugin>
    </plugins>
  </build>
  <scm>
    <connection>scm:cvs:pserver:cvs.drupal.org:/cvs/drupal:drupal</connection>
    <developerConnection>scm:cvs:pserver:cvs.drupal.org:/cvs/drupal:drupal</developerConnection>
    <tag>DRUPAL-6-12</tag>
    <url>http://cvs.drupal.org/viewvc.py/drupal/drupal/?pathrev=DRUPAL-6</url>
  </scm>
</project>

Finally, what are my questions?

  • Is Maven the wrong tool for this?

If no,

  • How would you do this?
  • Is it the scm:bootstrap goal that I should be using?
  • What is the Maven way of moving directories around on the file system?
  • Should the install goal be used to move the modules into the drupal directory?
  • Currently all our custom modules are in one mercurial repository. Is it possible to create a pom.xml and checkout each module individually?
  • Any general advice would be appreciated.

Thanks for your time!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

堇年纸鸢 2024-07-31 16:08:07

我 98% 确定您真正需要的是 Drush Make,它可以递归构建 Drupal 项目,前提是他们提供自己的 .make 文件,列出了它们的依赖项。 它可以从多个 SCM、Web、补丁文件下载,并且您可以控制它们的下载位置。 它还支持外部库,例如所见即所得、PHP 文件或 JS 库。

请参阅开放 Atrium make 文件以获取其功能的示例。

I'm 98% certain that what you really need is Drush Make, which can recursively build Drupal projects, provided they provide their own .make file listing their dependencies. It can download from multiple SCMs, web, patch files, and you can control where they get downloaded. It also support external libs, such as wysiwyg, PHP files, or JS libraries.

See the Open Atrium make file for a sample of what it can do.

倦话 2024-07-31 16:08:07

当然你没有使用 Maven,这里有一些想法:

  • Maven 是一个 Java 构建工具和依赖管理软件,具有明确定义的生命周期,如下所示:验证、编译、测试、打包、集成测试、验证、安装、部署。 您使用的是 scm 插件,它可以坚持此处定义的任何阶段并执行一些操作,但除非您在 POM 中进行复杂的更改(我没有听说有人这样做)生命周期将继续执行。
  • Maven 还被设计用于打包 JAR、WAR,并使用一些插件 EAR、SAR、RAR(不是那个 RAR)和其他一些文件; 您可能需要编写一个新插件来获取您期望的包类型,或者使用程序集插件,这将使事情变得更加复杂。

由于前面的几点,Maven 没有命令将文件移动到特定目录(不是本机目录),并且您不应该调用安装阶段将文件复制到本地存储库之外的任何其他位置。 您所做的就像将洗衣机改造成搅拌机

在阅读了您想要对项目执行的操作后,我建议您创建一个脚本(shell 脚本或批处理脚本,具体取决于您的操作系统)来完成这项工作。 SVN 和 CVS 具有可以从构建脚本内部调用的命令行工具。 我猜您选择 Maven 的原因之一是,Hudson 和许多其他持续集成软件与它很好地集成,但您也可以将它们与脚本一起使用。

如果您习惯使用 Ant 并且您认为使用它会缩短应用程序的构建时间,我认为还不错;)(除 Java 项目外,我没有将 Ant 用于其他目的)

Definitely you're not using Maven, here some thoughts:

  • Maven is a Java build tool and dependency management software with a well-defined lifecycle which goes like this: validate, compile, test, package, integration-test, verify, install, deploy. What you are using is the scm plugin which can stick to any of the phases defined here and perform some actions but unless you make complicated changes in the POM (I haven't heard of anyone doing this) the lifecycle will continue being executed.
  • Maven also is designed to package JARs, WARs and with the use of some plugins EARs, SARs, RARs (not that RARs) and some other files; you might have to program a new plugin to get the type of packages you expect or use the assembly plugin which will make things more complicated.

Because of the previous points, there is no command for Maven to move the files into an specific directory (not a native one) and you shouldn't invoke install phase to copy the files to any other location than the local repository. What you're doing is like taking a laundry machine and converting it into a blender.

After reading what you want to do with your project I'd suggest you to create a script (shell script or batch script depending on your OS) for doing the job. SVN and CVS has command line tools which can be invoked from inside your build scripts. I guess you opted for Maven, among other reasons, because Hudson and many other Continuous Integration software are well integrated with it but you can use them with scripts too.

If you are comfortable using Ant and you consider using it will ease the building time of your app I think is not as bad ;) (I haven't used Ant for other purposes than Java projects)

何以畏孤独 2024-07-31 16:08:07

Drush 'module' 是在 Drupal 中编写脚本的绝佳工具。 但是,除此之外,我认为你为每个“构建”进行 CVS 检查的方法有点偏离基础 - 除非你有 - 非常 - 充分的理由将项目的每个块放在单独的存储库中,否则你最好的选择是修复了 Drupal 核心和的结账问题 贡献的模块已提交到您的项目存储库。 这不仅消除了对网络连接和外部服务器稳定性的依赖,而且还允许您对贡献的模块进行本地修改(不幸的是,您可能最终会在某处执行此操作)。

一旦您取消了从多个存储库进行签出的要求,您可能会注意到您的任务变得更加容易,只需要进行一些简单的 MySQL 操作并编写 settings.php 即可。

The Drush 'module' is a great tool for scripting out things in Drupal. But, beyond that, I think your approach of doing CVS checkouts for each 'build' is a little off base - unless you have -really- good reasons to have every chunk of the project in a separate repository, your best bet is to have fixed checkouts of Drupal core & contributed modules committed to your project's repository. Not only does this take out a dependency on a network connection and the stability of an external server but it allows you to have local modifications of the contributed modules (unfortunately, you're probably going to end up doing this somewhere down the line).

Once you take out the requirement to do checkouts from multiple repositories, you'll probably notice that your task becomes -much- easier, leaving you with some simple MySQL manipulation and writing out a settings.php.

潦草背影 2024-07-31 16:08:07

http://www.php-maven.org 知道该项目带有一个构建插件,支持 php 世界到maven(或者php项目的maven世界)。 版本 2 快照可以在我们的 google 群组中找到(新闻线索可在 https://groups.google.com/group/maven-for-php/t/e055e49c89ccb8c5?hl=de)。

然而,这使您可以完全控制项目并尊重默认的 Maven 生命周期,以便 Maven 命令:

  • mvn clean
  • mvn package
  • mvn deploy
  • mvn site

将正常工作。

Drupal 支持可能在 2.1 版本中启用,其中我们专注于框架(zend、flow3...)和项目类型(web、cli、libs...)。 如果要弄清楚 maven 是什么以及它如何在 php 开发过程中为您提供帮助,那就太费劲了。 正如 Vistor Hugo 在他的早期评论中所说,Maven 的好处不仅在于手动执行特定命令,还在于通过 Maven 嵌入整个项目结构和整个项目生命周期。
由于大多数 php 人员尚未接触过 java,尤其是 Maven,因此我们正在创建教程,以便每个人都能相当简单地进入 Maven 世界。

The project http://www.php-maven.org know comes with a build plugin enabling the php world to maven (or the maven world for php projects). Version 2 snapshot can be found in our google groups (news thread available at https://groups.google.com/group/maven-for-php/t/e055e49c89ccb8c5?hl=de).

However this gives you a full control over the project and respects the default maven lifecycle so that the maven commands:

  • mvn clean
  • mvn package
  • mvn deploy
  • mvn site

will work correctly.

Drupal support may be enabled in version 2.1 where we are focused on frameworks (zend, flow3...) and project types (web, cli, libs...). It would be to much to clearify wha maven is and how it can help you during php development. As Vistor Hugo stated on his early comment Mavens benefits are not only to execute a specific command manually but to embed the whole project structure and the whole project lifecycle via maven.
Since the most php guys did not yet have contact to java and especially maven we are creating tutorials so that everyone has a fairly simple entry in the maven world.

莫相离 2024-07-31 16:08:07

我喜欢 Maven,尽管我认为它是 Java 特定的,如上所述。

我成功地用 phing 处理可重复的任务。 我在 Zend 项目中使用它来准备构建或只是紧固正常的可重复任务(例如清理数据库、加载数据库转储)。

Phing不会像maven一样为您提供完整的生命周期管理,但您可以自己手动编写。 您可以将 shell 脚本命令嵌入到 build.xml 中,这样您就可以使用在普通 shell 脚本中使用的所有内容。
与普通的 shell 脚本相比,我更喜欢 phing,因为它可以处理依赖的目标,因此如果您的 build.xml 包含相互依赖的精心设计的目标,您将获得非常有用的链来实现指定的目标。

这个对我有用。

drupal 的另一个很棒的工具是 drush,它使 drupal 管理可以编写脚本。 您可以从控制台执行许多 Drupal 特定操作。 我认为您可以从 phing 脚本调用 drush 命令。

I love maven, although I think it is very java specific as mentioned above.

I had success to handle repeable task with phing. I used in a Zend project to prepare a build or just fasten the normal repetable tasks (eg. clean up db, load db dump).

Phing won't provide you complete lifecycle management as maven, but you can write yourself by hand. You can embed shell script commands to build.xml so you can use everything that you would use in a normal shell script.
I prefer phing over normal shell script because it can handle dependent targets, so if your build.xml contains well designed targets that depend each other, you'll get very useful chains to achive specified goals.

It works for me.

Another great tool for drupal is drush which makes drupal administration scriptable. You can do lots of drupal specific things from console. I think you can call drush commands from phing scripts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文