Skip to content

Commit 6cf04f9

Browse files
committed
cli execution copied from phpmaven-plugin
1 parent 026b3ee commit 6cf04f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2509
-20
lines changed

generic-parent/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

generic-parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<groupId>org.phpmaven.build.phpexec-java</groupId>
1717
<artifactId>generic-parent</artifactId>
18-
<version>0.1.7</version>
18+
<version>0.1.8-SNAPSHOT</version>
1919
<packaging>pom</packaging>
2020

2121
<name>generic-parent:${project.version}</name>

java-parent/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

java-parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<groupId>org.phpmaven.build.phpexec-java</groupId>
1717
<artifactId>generic-java-parent</artifactId>
18-
<version>0.1.7</version>
18+
<version>0.1.8-SNAPSHOT</version>
1919
<packaging>pom</packaging>
2020

2121
<name>java-parent:${project.version}</name>

phpexec-api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

phpexec-api/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<parent>
99
<groupId>org.phpmaven.build.phpexec-java</groupId>
1010
<artifactId>generic-java-parent</artifactId>
11-
<version>0.1.7</version>
11+
<version>0.1.8-SNAPSHOT</version>
1212
<relativePath>../java-parent/pom.xml</relativePath>
1313
</parent>
1414

@@ -33,6 +33,12 @@
3333
</distributionManagement>
3434

3535
<dependencies>
36+
<dependency>
37+
<groupId>org.codehaus.plexus</groupId>
38+
<artifactId>plexus-utils</artifactId>
39+
<version>3.0.4</version>
40+
<scope>compile</scope>
41+
</dependency>
3642
<dependency>
3743
<groupId>junit</groupId>
3844
<artifactId>junit</artifactId>

phpexec-api/src/main/java/org/phpmaven/phpexec/library/IPhpExecutable.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.io.File;
2323
import java.io.OutputStream;
2424

25+
import org.codehaus.plexus.util.cli.StreamConsumer;
26+
2527
/**
2628
* An interface representing a php executable.
2729
*
@@ -105,6 +107,31 @@ public interface IPhpExecutable {
105107
*/
106108
int execute(String arguments, OutputStream stdout, OutputStream stderr) throws PhpException;
107109

110+
/**
111+
* Executes PHP with the given arguments and throws an IllegalStateException if the
112+
* execution fails.
113+
*
114+
* @param arguments string of arguments for PHP (including the file-path and filename)
115+
* @param file a hint which file will be processed
116+
* @param stdout handler for stdout lines
117+
* @return the returncode of PHP
118+
* @throws PhpException if the execution failed
119+
* @since 0.1.8
120+
*/
121+
int execute(String arguments, File file, final StreamConsumer stdout) throws PhpException;
122+
123+
/**
124+
* Executes PHP with the given arguments.
125+
*
126+
* @param arguments string of arguments for PHP (including the file-path and filename)
127+
* @param stdout handler for stdout lines
128+
* @param stderr handler for stderr lines
129+
* @return the return code of PHP
130+
* @throws PhpException if the executions fails
131+
* @since 0.1.8
132+
*/
133+
int execute(String arguments, StreamConsumer stdout, StreamConsumer stderr) throws PhpException;
134+
108135
/**
109136
* Returns the version of this php executable.
110137
* @return php executable version.

phpexec-api/src/main/java/org/phpmaven/phpexec/library/IPhpExecutableConfiguration.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,6 @@ public interface IPhpExecutableConfiguration {
5151
*/
5252
void setExecutable(String executable);
5353

54-
/**
55-
* Returns the interpreter that will be used.
56-
*
57-
* @return The php interpreter.
58-
*/
59-
String getInterpreter();
60-
61-
/**
62-
* Sets the php interpreter to be used.
63-
*
64-
* @param interpreter the php interpreter.
65-
*/
66-
void setInterpreter(String interpreter);
67-
6854
/**
6955
* Returns true if the php information cache can be used.
7056
*
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Copyright 2010-2012 by PHP-maven.org
3+
*
4+
* This file is part of phpexec-java.
5+
*
6+
* phpexec-java is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* phpexec-java is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with phpexec-java. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
package org.phpmaven.phpexec.library.test;
21+
22+
import java.io.File;
23+
24+
import junit.framework.Assert;
25+
26+
import org.junit.Test;
27+
import org.phpmaven.phpexec.library.PhpCoreException;
28+
import org.phpmaven.phpexec.library.PhpExecutionException;
29+
30+
/**
31+
* test cases for PHP support.
32+
*
33+
* @author Martin Eisengardt <Martin.Eisengardt@googlemail.com>
34+
* @since 0.1.8
35+
*/
36+
public class Exception2Test {
37+
38+
/**
39+
* Tests some things on php execution exception.
40+
*
41+
* @throws Exception thrown on errors
42+
*/
43+
@Test
44+
public void testExecException() throws Exception {
45+
PhpExecutionException ex = new PhpExecutionException(null, "FOO");
46+
Assert.assertEquals("\nFOO", ex.getMessage());
47+
final File fooFile = new File("foo.php");
48+
ex = new PhpExecutionException(fooFile, "FOO");
49+
Assert.assertTrue(ex.getMessage().contains("FOO"));
50+
Assert.assertTrue(ex.getMessage().contains(fooFile.getAbsolutePath()));
51+
}
52+
53+
/**
54+
* Tests some things on php core exception.
55+
*
56+
* @throws Exception thrown on errors
57+
*/
58+
@Test
59+
public void testCoreException() throws Exception {
60+
// constructors for code coverage
61+
PhpCoreException ex = new PhpCoreException();
62+
ex = new PhpCoreException("FOO", new Exception());
63+
ex = new PhpCoreException(new Exception());
64+
65+
ex = new PhpCoreException("some meaningful error");
66+
Assert.assertNull(ex.getAppendedOutput());
67+
Assert.assertEquals("some meaningful error", ex.getMessage());
68+
ex.appendOutput("FOOBAR");
69+
Assert.assertEquals("FOOBAR", ex.getAppendedOutput());
70+
Assert.assertTrue(ex.getMessage().contains("FOOBAR"));
71+
Assert.assertTrue(ex.getMessage().contains("some meaningful error"));
72+
ex.appendOutput("BAZ");
73+
Assert.assertEquals("BAZ", ex.getAppendedOutput());
74+
Assert.assertFalse(ex.getMessage().contains("FOOBAR"));
75+
Assert.assertTrue(ex.getMessage().contains("BAZ"));
76+
Assert.assertTrue(ex.getMessage().contains("some meaningful error"));
77+
}
78+
79+
}

phpexec-cli/.classpath

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
10+
<attributes>
11+
<attribute name="optional" value="true"/>
12+
<attribute name="maven.pomderived" value="true"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
16+
<attributes>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
26+
<attributes>
27+
<attribute name="maven.pomderived" value="true"/>
28+
</attributes>
29+
</classpathentry>
30+
<classpathentry kind="output" path="target/classes"/>
31+
</classpath>

0 commit comments

Comments
 (0)