私は、mySQL データベース ダンプをロードするモジュールを含む Mavenized ビルド (maven3) を持っています。これは Windows では正常に機能しますが、Linux では機能しません。
-X スイッチを指定して maven を実行すると、次の出力が生成されます。
[DEBUG] Using mysql at /usr/bin/mysql
[DEBUG] Command to execute: mysql -uMYUSER --password=**** -hlocalhost --quick --max_allowed_packet=16M --default-character-set=utf8 -e "source /this/path/to/my/database/dump/is/longer/than/70/characters/the_dump.sql"
[ERROR] ERROR 1102 (42000): Incorrect database name '/this/path/to/my/database/dump/is/longer/than/70/characters/the_dump.'
コマンドラインでデバッグ出力を直接実行すると、the_dump.sql スクリプトは正常に動作します。私の推測では、Maven がパラメーターを正しく認識していない、および/またはそれらを切り捨てている (エラー メッセージで 2 番目のパラメーターが 70 文字で切り捨てられていることに注意してください)。Windows でビルドが失敗するわけにはいきません。データベース スクリプトの特定のコマンドが原因で、"<" パイプを使用して mysql に渡しても正しく実行できません。
関連する pom スニペットは次のとおりです。
<build>
<resources>
<resource>
<directory>META-INF</directory>
<targetPath>META-INF</targetPath>
</resource>
<resource>
<directory>${dumps.target.dir}</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>my.maven.plugin</groupId>
<artifactId>db-dumps-maven-plugin</artifactId>
<configuration>
<databasesToDump>${db.schemas.to.dump}</databasesToDump>
<documentStoreFolder>${documentstore.location}</documentStoreFolder>
<outputDirectory>${project.build.directory}/../${dumps.target.dir}</outputDirectory>
</configuration>
<executions>
<execution>
<id>dump-database</id>
<phase>prepare-package</phase>
<goals>
<goal>dump-db</goal>
</goals>
<inherited>false</inherited>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>build</id>
<build>
<plugins>
<plugin>
<groupId>my.maven.plugin</groupId>
<artifactId>db-dumps-maven-plugin</artifactId>
<executions>
<execution>
<id>create-database</id>
<phase>initialize</phase>
<goals>
<goal>create-db</goal>
</goals>
<inherited>false</inherited>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
そして、db-dumps-maven-plugin からの実行スニペット:
@Override
public void execute() throws MojoExecutionException {
final Set<String> dumpsToInsertLowerCase = evaluateDumpsToInsert();
final List<File> sqlFiles = findFiles(folderWithDumps, ".sql", dumpsToInsertLowerCase);
getLog().info("Inserting dumps: " + sqlFiles);
for (final File sqlFile : sqlFiles) {
String createCommand = "mysql -u%s --password=%s -h%s --quick --max_allowed_packet=16M --default-character-set=utf8 -e \"source %s\"";
Object[] createArgs = {username, password, hostname, sqlFile.getAbsolutePath().replace("\\", "/")};
executeCommand(createCommand, createArgs);
}
}
public void executeCommand(final String command, final Object[] arguments) {
final String commandToExecute = String.format(command, arguments);
mavenPlugin.getLog().debug("Command to execute: " + commandToExecute);
try {
final Process child = Runtime.getRuntime().exec(commandToExecute);
final InputStream inputStream = child.getInputStream();
readAndCloseStream(inputStream, false);
final InputStream errorStream = child.getErrorStream();
readAndCloseStream(errorStream, true);
// prevent leaking file descriptors, close stream
try {
child.getOutputStream().close();
} catch (final IOException ioe) {
mavenPlugin.getLog().warn("Unable to close stream. " + ioe);
}
// check return value
// 0 means a normal program termination
final int exitValue = child.exitValue();
if (exitValue != 0) {
throw new RuntimeException("Executing command failed. Exit code: " + exitValue);
}
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
これが発生する理由と、maven に source コマンドを正しく解釈させる方法はありますか?