Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed creating the phar ( ... cannot be overloaded with ...) #15

Open
lcotonea opened this issue Oct 16, 2012 · 2 comments
Open

Failed creating the phar ( ... cannot be overloaded with ...) #15

lcotonea opened this issue Oct 16, 2012 · 2 comments

Comments

@lcotonea
Copy link

Hi!

On linux and cygwin platforms, I've this issue during a "mvn clean install".
On linux (centos 6), I've installed PHP 5.3.3. On cygwin (windows 7), I've installed PHP 5.3.13.

Here the stack trace:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.phpmaven:maven-php-plugin:2.0.2:phar (default-phar) on project proj: failed creating the phar.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.jvnet.hudson.maven3.launcher.Maven3Launcher.main(Maven3Launcher.java:79)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:329)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:239)
    at org.jvnet.hudson.maven3.agent.Maven3Main.launch(Maven3Main.java:158)
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:98)
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:64)
    at hudson.remoting.UserRequest.perform(UserRequest.java:118)
    at hudson.remoting.UserRequest.perform(UserRequest.java:48)
    at hudson.remoting.Request$2.run(Request.java:326)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.maven.plugin.MojoExecutionException: failed creating the phar.
    at org.phpmaven.plugin.build.AbstractPharMojo.execute(AbstractPharMojo.java:268)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 27 more
Caused by: org.phpmaven.exec.PhpErrorException: 
Failed to execute PHP with arguments '"/var/lib/jenkins/jobs/MYJOB/workspace/target/snippet.php"' [Return: 255]:
PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'alias "proj-2.0.1-xxx-SNAPSHOT.phar" is already used for archive "/data/var/lib/jenkins/jobs/MYJOB/workspace/target/proj-2.0.1-xxx-SNAPSHOT.phar" cannot be overloaded with "/var/lib/jenkins/jobs/MYJOB/workspace/target/proj-2.0.1-xxx-SNAPSHOT.phar"' in /data/var/lib/jenkins/jobs/MYJOB/workspace/target/snippet.php:22
Stack trace:
#0 /data/var/lib/jenkins/jobs/MYJOB/workspace/target/snippet.php(22): Phar->__construct('/var/lib/jenkin...', 0, 'proj-2.0.1-...')
#1 {main}
  thrown in /data/var/lib/jenkins/jobs/MYJOB/workspace/target/snippet.php on line 22

in file: /var/lib/jenkins/jobs/MYJOB/workspace/target/snippet.php
    at org.phpmaven.exec.PhpExecutable.execute(PhpExecutable.java:294)
    at org.phpmaven.exec.PhpExecutable.execute(PhpExecutable.java:308)
    at org.phpmaven.exec.PhpExecutable.executeCode(PhpExecutable.java:423)
    at org.phpmaven.exec.PhpExecutable.executeCode(PhpExecutable.java:390)
    at org.phpmaven.exec.PhpExecutableConfiguration$CachedExecutable.executeCode(PhpExecutableConfiguration.java:358)
    at org.phpmaven.phar.PharPackager.packagePhar(PharPackager.java:157)
    at org.phpmaven.plugin.build.AbstractPharMojo.execute(AbstractPharMojo.java:258)
    ... 29 more

This is the line 22 of the snippet.php that causes the build failure.

So, here the snippet.php file automatically generated by the php-maven plugin:

<?php 
class RecursiveDirectoryIterator2 extends RecursiveDirectoryIterator {
  function getChildren() {
    try {
      return parent::getChildren();
    } catch(UnexpectedValueException $e) {
      return new RecursiveArrayIterator(array());
    }
  }
}
if (file_exists('/var/lib/jenkins/jobs/MYJOB/workspace/target'.DIRECTORY_SEPARATOR.'proj-2.0.1-xxx-SNAPSHOT.phar')) unlink('/var/lib/jenkins/jobs/MYJOB/workspace/target'.DIRECTORY_SEPARATOR.'proj-2.0.1-xxx-SNAPSHOT.phar');
$phar = new Phar('/var/lib/jenkins/jobs/MYJOB/workspace/target'.DIRECTORY_SEPARATOR.'proj-2.0.1-xxx-SNAPSHOT.phar', 0, 'proj-2.0.1-xxx-SNAPSHOT.phar');
$phar->startBuffering();
$base = realpath('/var/lib/jenkins/jobs/MYJOB/workspace/target/classes');
$ite = new RecursiveDirectoryIterator2($base, FilesystemIterator::SKIP_DOTS);
$len = strlen($base);
foreach (new RecursiveIteratorIterator($ite) as $filename=>$cur) {
  if (substr(realpath($filename), 0, $len) == $base) {
    $phar->addFile($filename, str_replace('\\', '/', ''.substr($filename, $len + 1)));  }
}
$phar->stopBuffering();
$phar = new Phar('/var/lib/jenkins/jobs/MYJOB/workspace/target'.DIRECTORY_SEPARATOR.'proj-2.0.1-xxx-SNAPSHOT.phar', 0, 'proj-2.0.1-xxx-SNAPSHOT.phar');
$phar->startBuffering();
foreach (new RecursiveIteratorIterator($phar) as $file) { if (!$file->isDir()) $file->compress(Phar::GZ); }
$phar->setStub('<?php die(\'Unable to execute this phar\'); __HALT_COMPILER(); ?>');
$phar->stopBuffering();

At line 22, It seems that the "new phar..." causes an access violation on the previous phar file (this is the same file). If I comment this line, everything is fine and I can launch a mvn install.

I think that the code generation of the snippet.php file must not create new phar if a a previous phar object has been instanciated and uses the same target phar file.

So, Is there a way to workaround this problem until the bug fix release?

@lcotonea
Copy link
Author

Hi (again ;) ),

After reading your code I saw that the problematic snippet's code is only added when the compression is active (that is the default behaviour):

PharPackager.java (l137):

        String compression = "";
        if (request.isCompressed()) {
            if (request.isLargePhar()) {
                compression =
                    "$phar->stopBuffering();\n" +
                    "$phar = new Phar('$:{pharfilepath}'.DIRECTORY_SEPARATOR.'" +
                    "$:{pharfilename}', 0, '$:{pharfilename}');\n" +
                    "$phar->startBuffering();\n" +
                    "foreach (new RecursiveIteratorIterator($phar) as $file) {" +
                    " if (!$file->isDir()) $file->compress(Phar::GZ); }\n";
            } else {
                compression = "$phar->compressFiles(Phar::GZ);\n";
            }
        }

Then the workaround is to disable the phar compression under cygwin/linux: in the project pom.xml file:

           <plugin>
                <groupId>org.phpmaven</groupId>
                <artifactId>maven-php-phar</artifactId>
                <configuration>
                    <pharConfig>
                        <compressed>false</compressed>
                    </pharConfig>
                </configuration>
            </plugin>

@jpeffer
Copy link

jpeffer commented Feb 24, 2013

I've run into this issue on freebsd, but oddly enough, it works properly under OSX. Is this targeted to be fixed? Having to keep compression off indefinitely would be unfortunate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants